216 lines
5.8 KiB
ArmAsm
216 lines
5.8 KiB
ArmAsm
; CHIBI PC-09 Machine Language Monitor -- BUZBEE
|
|
; Copyright (c) 2025 Gale Faraday
|
|
; Licensed under MIT
|
|
|
|
INCLUDE "bbhash.inc"
|
|
INCLUDE "buzbee.inc"
|
|
INCLUDE "hardware.inc"
|
|
INCLUDE "serial.inc"
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
;;
|
|
;; BUZBEE Machine Language Monitor for CHIBI PC-09
|
|
;;
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
SECTION BUZBEE
|
|
|
|
EXPORT BUZBEE
|
|
|
|
BUZBEE
|
|
bsr NEWLINE ; Setup the new input line and handle display.
|
|
bsr INPLOOP ; Fill input buffer.
|
|
cmpy #$0000 ; No data?
|
|
beq BUZBEE ; Try again...
|
|
; TODO: Parse the input buffer into tokens
|
|
; TODO: Execute the token buffer
|
|
bra BUZBEE
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
;;
|
|
;; BUZBEE Input Buffering and Handling Routines
|
|
;;
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
; Handle new lines; prints a new prompt and then clears the input buffer
|
|
NEWLINE
|
|
PZSTR PROMPTLINE ; Print prompt line
|
|
CLRIN ; Label to just clear input buffer without newline
|
|
clra ; Init A and X
|
|
ldx #$0000
|
|
NEXT@
|
|
sta BBIN_BASE,x ; Clear input buffer
|
|
leax 1,x
|
|
cmpx #BBIN_DEPTH
|
|
blo NEXT@
|
|
ldy #$0000 ; Reset buffer fill pointer
|
|
rts
|
|
|
|
; Fills input buffer with characters from the serial console. Sets Y to the
|
|
; offset in the input buffer of the last char read.
|
|
INPLOOP
|
|
jsr PINCHAR ; Try to read a char
|
|
cmpd #$0000 ; If no char keep waitin'
|
|
beq INPLOOP
|
|
bitb #UARTF_LSR_DR ; Is there a char in A?
|
|
beq NOCHAR@
|
|
cmpa #$1B ; ESC?
|
|
beq HESC@ ; Handle ESC
|
|
cmpa #$08 ; BS?
|
|
beq HBACKSPC@ ; Backup a char
|
|
cmpa #$0D ; CR?
|
|
beq EXIT@ ; Then parse input buffer
|
|
cmpy #BBIN_DEPTH ; Are we at the end of the input buffer?
|
|
beq FULLBUF@ ; Handle the buffer being full
|
|
ECHO@
|
|
jsr POUTCHAR ; Echo char back, this includes BS chars
|
|
sta BBIN_BASE,y ; Add it to the input buffer
|
|
leay 1,y
|
|
NOCHAR@
|
|
; Check for error condition, work based on The Serial Port release 19
|
|
bitb #(UARTF_LSR_FIFO|UARTF_LSR_BI|UARTF_LSR_FE|UARTF_LSR_PE|UARTF_LSR_OE)
|
|
beq INPLOOP
|
|
bitb #UARTF_LSR_OE ; Check for overrun error
|
|
beq NOOVER@
|
|
PZSTR EM_OVERRUN
|
|
NOOVER@
|
|
bitb #UARTF_LSR_PE ; Check for parity error
|
|
beq NOPARITY@
|
|
PZSTR EM_PARITY
|
|
NOPARITY@
|
|
bitb #UARTF_LSR_FE ; Check for framing error
|
|
beq NOFRAM@
|
|
PZSTR EM_FRAMING
|
|
NOFRAM@
|
|
bitb #UARTF_LSR_FIFO ; Check for FIFO error
|
|
beq INPLOOP
|
|
PZSTR EM_FIFO
|
|
bra INPLOOP
|
|
EXIT@
|
|
rts
|
|
HESC@
|
|
lda #'^ ; Print a char that signifies that ESC was pressed
|
|
jsr POUTCHAR
|
|
ldy #$0000 ; On return we cmpy #$0000 and if eq then newline.
|
|
rts
|
|
HBACKSPC@
|
|
clrb ; Clear last char
|
|
leay -1,y
|
|
stb BBIN_BASE
|
|
bra ECHO@ ; Echo the char in A
|
|
FULLBUF@
|
|
lda #$07 ; ASCII BEL
|
|
jsr POUTCHAR
|
|
bra INPLOOP
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
;;
|
|
;; BUZBEE Command Hashing Routines
|
|
;;
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
; Makes a hash of four chars in BBIN starting at offset X.
|
|
; @param X: offset in BBIN to read the four chars from
|
|
; @return A: resulting hash
|
|
MKCMDSUM
|
|
pshs b
|
|
ldb #4 ; Loop over four chars
|
|
clra ; Initialize accumulator
|
|
NEXTC@
|
|
suba BBIN_BASE,x ; Subtract current char from accumulator
|
|
leax 1,x ; Next char
|
|
decb ; Reduce count
|
|
cmpb #0 ; Are we at the end?
|
|
bne NEXTC@ ; No? loop
|
|
rts
|
|
|
|
; Maps a command hash to a command index, and executes it
|
|
; @corrupts B
|
|
; @param A: input hash
|
|
; @return X: command data table index
|
|
CALLFROMHASH
|
|
ldx #0 ; Counting up from zero
|
|
NEXTHASH@
|
|
cmpa BBCHT,x ; Is this hash our hash?
|
|
beq CALCPTR@ ; Yes? skip to next step to put ptr in x
|
|
leax 1,x ; Begin considering next hash
|
|
cmpx BBCHTC ; Is this the last byte?
|
|
blo NEXTHASH@ ; No? try next hash, Yes? fall through
|
|
PZSTR EM_BADCMD ; Print an error message
|
|
lbra IFHELP ; Proceed to call "HELP"
|
|
CALCPTR@
|
|
tfr x,d ; Swap into d to do a cheap multiply
|
|
asld ; Cheaply << to get *2, pointer size
|
|
tfr d,x ; Restore x from d and jump to function at index
|
|
jmp [BBCMDPTRTBL,x]
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
;;
|
|
;; BUZBEE Internal Command Functions
|
|
;;
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
; Print out a help message
|
|
IFHELP
|
|
PZSTR HELP_MSG
|
|
rts
|
|
|
|
; Placeholder function labels to make assembler happy before git commit
|
|
IFCALL
|
|
IFEXEC
|
|
IFPEEK
|
|
IFPOKE
|
|
IFSREC
|
|
rts
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
;;
|
|
;; BUZBEE Strings and Tables
|
|
;;
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
HELP_MSG
|
|
fcc "-- BUZBEE HELP --"
|
|
fcb $0D,$0A
|
|
fcc "Available Commands:"
|
|
fcb $0D,$0A
|
|
fcc "CALL <PTR> - Call the pointer given in <PTR> as a subroutine."
|
|
fcb $0D,$0A
|
|
fcc "EXEC <PTR> - Start program at <PTR>."
|
|
fcb $0D,$0A
|
|
fcc "HELP [CMD] - Display help, command optional."
|
|
fcb $0D,$0A
|
|
fcc "PEEK <BASE> [<HIGH>] - Read memory at <BASE> to <HIGH>."
|
|
fcb $0D,$0A
|
|
fcc "POKE <ADDR> <BYTES> - Overwrite memory with <BYTES> starting at <BASE>."
|
|
fcb $0D,$0A
|
|
fcc "SREC - Enter Motorola S-Record entry mode."
|
|
fcb $00
|
|
|
|
BBCMDPTRTBL
|
|
fdb IFCALL
|
|
fdb IFEXEC
|
|
fdb IFHELP
|
|
fdb IFPEEK
|
|
fdb IFPOKE
|
|
fdb IFSREC
|
|
|
|
PROMPTLINE
|
|
fcb $0D,$0A,$25,$00 ; CR LF '%' NUL
|
|
|
|
EM_OVERRUN
|
|
fcc "!!! Overrun Error !!!"
|
|
fcb $0D,$0A,$00
|
|
EM_PARITY
|
|
fcc "!!! Parity Error !!!"
|
|
fcb $0D,$0A,$00
|
|
EM_FRAMING
|
|
fcc "!!! Framing Error !!!"
|
|
fcb $0D,$0A,$00
|
|
EM_FIFO
|
|
fcc "!!! FIFO Error !!!"
|
|
fcb $0D,$0A,$00
|
|
EM_BADCMD
|
|
fcc "!!! Bad Command Hash !!!"
|
|
fcb $0D,$0A,$00
|