Populate repository from old progress; massive cleanup and fixes

This commit is contained in:
2025-09-09 17:56:47 -05:00
parent 2695e5bb29
commit a0b654f160
15 changed files with 503 additions and 2 deletions

83
src/serial.s Normal file
View File

@@ -0,0 +1,83 @@
; CHIBI PC-09 Prototype #1 Boot ROM -- Serial Driver
; Copyright (c) 2024-2025 Amber Zeller, Gale Faraday
; Licensed under MIT
INCLUDE "hardware.inc"
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; Serial UART Driver
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
SECTION SERIAL
EXPORT INITUART
EXPORT POUTCHAR
EXPORT POUTZSTR
; Initializes the UART with LCR settings and a BAUD rate from DIVISORS.
; ACCA: Index of the divsor to use in DIVISORS
; ACCB: Settings for LCR
INITUART
ldx #DIVISORS ; Get DIVISORS base addr
asla ; Shift left to *2 the index in order to iter over words.
pshs b ; Save B
ldd a,x ; Get divisor into D
sta UART_DLM ; Write divisor MSB
stb UART_DLL ; Write divisor LSB
lda UARTF_FCR_FE|UARTF_FCR_RFR|UARTF_FCR_XFR ; FIFO disable and clear
sta UART_FCR
lda #0
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
NEXTC@
lda UART_LSR ; Wait until LSR.THRE == 1 then write char
bita UARTF_LSR_THRE
beq NEXTC@
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 0,x ; Get next char from X
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@
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
DIVISORS
fdb $0900 ; 50 baud
fdb $0600 ; 75 baud
fdb $0417 ; 110 baud
fdb $0359 ; 134.5 baud
fdb $0300 ; 150 baud
fdb $0180 ; 300 baud
fdb $00C0 ; 600 baud
fdb $0060 ; 1200 baud
fdb $0040 ; 1800 baud
fdb $0030 ; 2400 baud
fdb $0020 ; 3600 baud
fdb $0018 ; 4800 baud
fdb $0010 ; 7200 baud
fdb $000C ; 9600 baud
fdb $0006 ; 19200 baud