Compare commits
5 Commits
853efd9bac
...
2988fb9059
Author | SHA1 | Date | |
---|---|---|---|
2988fb9059
|
|||
2b23634bb8
|
|||
53add429a9
|
|||
a019c37755
|
|||
6bb29fe7ff
|
77
src/serial.s
77
src/serial.s
@@ -30,41 +30,11 @@ INITUART
|
||||
stb UART_LCR ; Write LCR
|
||||
lda #(UARTF_FCR_FE|UARTF_FCR_RFR|UARTF_FCR_XFR) ; FIFO disable and clear
|
||||
sta UART_FCR
|
||||
lda #0
|
||||
clra
|
||||
sta UART_IER ; Polled mode
|
||||
sta UART_MCR ; Reset DTR, RTS
|
||||
rts
|
||||
|
||||
; Prints a character in polled non-FIFO mode (INITUART state).
|
||||
; ACCA: char to write
|
||||
POUTCHAR
|
||||
pshs a ; Preserve char
|
||||
NOTREADY@
|
||||
lda UART_LSR ; Wait until LSR.THRE == 1 then write char
|
||||
bita UARTF_LSR_THRE
|
||||
beq NOTREADY@
|
||||
puls a ; Restore char
|
||||
sta UART_THR ; Write char
|
||||
rts
|
||||
|
||||
; Prints a null terminated string in polled non-FIFO mode (INITUART state).
|
||||
; X: start of zstring
|
||||
POUTZSTR
|
||||
pshs a,b ; Preserve A and B
|
||||
NEXTC@
|
||||
ldb ,x+ ; Get next char from X and increment X for next time
|
||||
cmpb #$00 ; Make sure that we aren't at a terminator
|
||||
beq END@
|
||||
NOTREADY@
|
||||
lda UART_LSR ; Wait until LSR.THRE == 1 then write char
|
||||
bita UARTF_LSR_THRE
|
||||
beq NOTREADY@
|
||||
stb UART_THR ; Write char
|
||||
bra NEXTC@ ; Iter to next char
|
||||
END@
|
||||
puls b,a ; Restore A and B
|
||||
rts
|
||||
|
||||
; UART baud rate divisors
|
||||
DIVISORS
|
||||
fdb $0900 ; 50 baud
|
||||
@@ -82,3 +52,48 @@ DIVISORS
|
||||
fdb $0010 ; 7200 baud
|
||||
fdb $000C ; 9600 baud
|
||||
fdb $0006 ; 19200 baud
|
||||
|
||||
; Prints a character in polled non-FIFO mode (INITUART state).
|
||||
; ACCA: char to write
|
||||
POUTCHAR
|
||||
pshs a ; Preserve char
|
||||
NOTREADY@
|
||||
lda UART_LSR ; Wait until LSR.THRE == 1 then write char
|
||||
bita #UARTF_LSR_THRE
|
||||
beq NOTREADY@
|
||||
puls a ; Restore char
|
||||
sta UART_THR ; Write char
|
||||
rts
|
||||
|
||||
; Prints a null terminated string in polled non-FIFO mode (INITUART state).
|
||||
; X: start of zstring
|
||||
POUTZSTR
|
||||
pshs a,b ; Preserve A and B
|
||||
NEXTC@
|
||||
ldb ,x+ ; Get next char from X and increment X for next time
|
||||
cmpb #$00 ; Make sure that we aren't at a terminator
|
||||
beq END@
|
||||
NOTREADY@
|
||||
lda UART_LSR ; Wait until LSR.THRE == 1 then write char
|
||||
bita #UARTF_LSR_THRE
|
||||
beq NOTREADY@
|
||||
stb UART_THR ; Write char
|
||||
bra NEXTC@ ; Iter to next char
|
||||
END@
|
||||
puls b,a ; Restore A and B
|
||||
rts
|
||||
|
||||
; Reads a char in polled mode non-FIFO mode (INITUART state).
|
||||
; A: Filled with char from RX buffer or NUL ($00) if no char is ready
|
||||
; B: Filled with LSR status codes masked with $9F
|
||||
PINCHAR
|
||||
ldb UART_LSR ; See if a char is ready
|
||||
; Mask of possible UART error codes | data ready flag ($9F)
|
||||
andb #(UARTF_LSR_DR|UARTF_LSR_OE|UARTF_LSR_PE|UARTF_LSR_FE|UARTF_LSR_BI|UARTF_LSR_FIFO)
|
||||
bitb #UARTF_LSR_DR ; Check for char
|
||||
beq NOCHAR@
|
||||
lda UART_RBR ; Pull char from RX buffer
|
||||
rts
|
||||
NOCHAR@
|
||||
clra ; Fill A with '\0'.
|
||||
rts
|
||||
|
@@ -13,7 +13,7 @@
|
||||
SECTION VECTORS
|
||||
|
||||
VECTORS
|
||||
fdb $0000 ; Reserved
|
||||
fdb $0000 ; Exception
|
||||
fdb $0000 ; SWI3
|
||||
fdb $0000 ; SWI2
|
||||
fdb $0000 ; FIRQ
|
||||
|
Reference in New Issue
Block a user