git.y1.nz

gbdk-2020

GameBoy Development Kit
download: https://git.y1.nz/archives/gbdk.tar.gz
README | Files | Log | Refs | LICENSE

gbdk-lib/libc/targets/sm83/serial.s

      1 	.include	"global.s"
      2 
      3 	.module serial
      4 
      5 	.globl	.int, .add_SIO
      6 
      7 	.area	_HEADER_SIO (ABS)
      8 
      9 	.area	_GSINIT
     10 
     11 	;; initialize SIO
     12 	LD	DE,#.serial_IO
     13 	CALL	.add_SIO
     14 
     15 	XOR	A
     16 	LDH	(.IFL),A
     17 
     18 	LDH	A,(.IE)
     19 	OR	A,#0b00001000	; Serial I/O	=   On
     20 	LDH	(.IE),A
     21 
     22 	LDH	(.SC),A		; Use external clock
     23 	LD	A,#.DT_IDLE
     24 	LDH	(.SB),A		; Send IDLE byte
     25 	LD	A,#0x80
     26 	LDH	(.SC),A		; Use external clock
     27 
     28 	.area	_HOME
     29 
     30 	;; Serial interrupt
     31 .serial_IO::
     32 	LD	A,(__io_status) ; Get status
     33 
     34 	CP	#.IO_RECEIVING
     35 	JR	NZ, 1$
     36 
     37 	;; Receiving data
     38 	LDH	A,(.SB)		; Get data byte
     39 	LD	(__io_in),A	; Store it
     40 
     41 2$:
     42 	LD	A,#.IO_IDLE
     43 3$:
     44 	LD	(__io_status),A ; Store status
     45 
     46 	XOR	A
     47 	LDH	(.SC),A		; Use external clock
     48 	LD	A,#.DT_IDLE
     49 	LDH	(.SB),A		; Reply with IDLE byte
     50 4$:
     51 	LD	A,#0x80
     52 	LDH	(.SC),A		; Enable transfer with external clock
     53 	RET
     54 
     55 1$:
     56 	CP	#.IO_SENDING
     57 	JR	NZ, 4$
     58 
     59 	;; Sending data
     60 	LDH	A,(.SB)		; Get data byte
     61 	CP	#.DT_RECEIVING
     62 	JR	Z, 2$
     63 	LD	A,#.IO_ERROR
     64 	JR	3$
     65 
     66 	.area	_DATA
     67 
     68 __io_out::
     69 	.ds	0x01		; Byte to send
     70 __io_in::
     71 	.ds	0x01		; Received byte
     72 __io_status::
     73 	.ds	0x01		; Status of serial IO
     74 
     75 	.area	_CODE
     76 
     77 	;; Send byte in __io_out to the serial port
     78 .send_byte:
     79 _send_byte::			; Banked
     80 	LD	A,#.IO_SENDING
     81 	LD	(__io_status),A ; Store status
     82 	LD	A,#0x01
     83 	LDH	(.SC),A		; Use internal clock
     84 	LD	A,(__io_out)
     85 	LDH	(.SB),A		; Send data byte
     86 	LD	A,#0x81
     87 	LDH	(.SC),A		; Use internal clock
     88 	RET
     89 
     90 	;; Receive byte from the serial port in __io_in
     91 .receive_byte:
     92 _receive_byte::			; Banked
     93 	LD	A,#.IO_RECEIVING
     94 	LD	(__io_status),A ; Store status
     95 	XOR	A
     96 	LDH	(.SC),A		; Use external clock
     97 	LD	A,#.DT_RECEIVING
     98 	LDH	(.SB),A		; Send RECEIVING byte
     99 	LD	A,#0x80
    100 	LDH	(.SC),A		; Use external clock
    101 	RET

This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.