fix(serial): fixed loop logic in POUTZSTR and some formatting
This commit is contained in:
12
src/serial.s
12
src/serial.s
@@ -20,13 +20,13 @@
|
|||||||
; ACCA: Index of the divsor to use in DIVISORS
|
; ACCA: Index of the divsor to use in DIVISORS
|
||||||
; ACCB: Settings for LCR
|
; ACCB: Settings for LCR
|
||||||
INITUART
|
INITUART
|
||||||
|
pshs b ; Preserve LCR while we set up divisors
|
||||||
ldx #DIVISORS ; Get DIVISORS base addr
|
ldx #DIVISORS ; Get DIVISORS base addr
|
||||||
asla ; Shift left to *2 the index in order to iter over words.
|
asla ; Shift left to *2 the index in order to iter over words.
|
||||||
pshs b ; Save B
|
|
||||||
ldd a,x ; Get divisor into D
|
ldd a,x ; Get divisor into D
|
||||||
sta UART_DLM ; Write divisor MSB
|
sta UART_DLM ; Write divisor MSB
|
||||||
stb UART_DLL ; Write divisor LSB
|
stb UART_DLL ; Write divisor LSB
|
||||||
puls b ; Restore B
|
puls b
|
||||||
stb UART_LCR ; Write LCR
|
stb UART_LCR ; Write LCR
|
||||||
lda UARTF_FCR_FE|UARTF_FCR_RFR|UARTF_FCR_XFR ; FIFO disable and clear
|
lda UARTF_FCR_FE|UARTF_FCR_RFR|UARTF_FCR_XFR ; FIFO disable and clear
|
||||||
sta UART_FCR
|
sta UART_FCR
|
||||||
@@ -39,10 +39,10 @@ INITUART
|
|||||||
; ACCA: char to write
|
; ACCA: char to write
|
||||||
POUTCHAR
|
POUTCHAR
|
||||||
pshs a ; Preserve char
|
pshs a ; Preserve char
|
||||||
NEXTC@
|
NOTREADY@
|
||||||
lda UART_LSR ; Wait until LSR.THRE == 1 then write char
|
lda UART_LSR ; Wait until LSR.THRE == 1 then write char
|
||||||
bita UARTF_LSR_THRE
|
bita UARTF_LSR_THRE
|
||||||
beq NEXTC@
|
beq NOTREADY@
|
||||||
puls a ; Restore char
|
puls a ; Restore char
|
||||||
sta UART_THR ; Write char
|
sta UART_THR ; Write char
|
||||||
rts
|
rts
|
||||||
@@ -54,19 +54,19 @@ POUTZSTR
|
|||||||
NEXTC@
|
NEXTC@
|
||||||
ldb 0,x ; Get next char from X
|
ldb 0,x ; Get next char from X
|
||||||
cmpb #$00 ; Make sure that we aren't at a terminator
|
cmpb #$00 ; Make sure that we aren't at a terminator
|
||||||
leax 1,x ; Increment X for next char. we inc here to save bytes if the
|
|
||||||
; next string is adjacent.
|
|
||||||
beq END@
|
beq END@
|
||||||
NOTREADY@
|
NOTREADY@
|
||||||
lda UART_LSR ; Wait until LSR.THRE == 1 then write char
|
lda UART_LSR ; Wait until LSR.THRE == 1 then write char
|
||||||
bita UARTF_LSR_THRE
|
bita UARTF_LSR_THRE
|
||||||
beq NOTREADY@
|
beq NOTREADY@
|
||||||
stb UART_THR ; Write char
|
stb UART_THR ; Write char
|
||||||
|
leax 1,x ; Iter to next char. We X++ here because leax modifies CC.Z
|
||||||
bra NEXTC@ ; Iter to next char
|
bra NEXTC@ ; Iter to next char
|
||||||
END@
|
END@
|
||||||
puls b,a ; Restore A and B
|
puls b,a ; Restore A and B
|
||||||
rts
|
rts
|
||||||
|
|
||||||
|
; UART baud rate divisors
|
||||||
DIVISORS
|
DIVISORS
|
||||||
fdb $0900 ; 50 baud
|
fdb $0900 ; 50 baud
|
||||||
fdb $0600 ; 75 baud
|
fdb $0600 ; 75 baud
|
||||||
|
Reference in New Issue
Block a user