feat(buzbee): add command token parsing interface, and help message, added newlines to messages

This commit is contained in:
2025-10-03 22:38:13 -05:00
parent eda7b3ac1f
commit 893753561c
3 changed files with 97 additions and 25 deletions

View File

@@ -36,18 +36,18 @@ int main(void) {
\n\ \n\
SECTION BBHASHES\n\ SECTION BBHASHES\n\
\n\ \n\
EXPORT BBHASHLEN\n\ EXPORT BBCHTC\n\
EXPORT BBHASHES\n"); EXPORT BBCHT\n");
/* Command count. /* Command count.
* NOTE: This is a u16 because it gets emitted into the output assembly. */ * NOTE: This is a u16 because it gets emitted into the output assembly. */
uint16_t cCmds = sizeof(s_ppszCmds) / sizeof(char *); uint16_t cCmds = sizeof(s_ppszCmds) / sizeof(char *);
/* Emit command count */ /* Emit command count */
printf("BBHASHLEN\n fdb $%.4X\n", cCmds); printf("BBCHTC\n fdb $%.4X\n", cCmds);
/* Emit table data */ /* Emit table data */
puts("\nBBHASHES"); puts("\nBBCHT");
for (int iCmd = 0; iCmd < cCmds; iCmd++) { for (int iCmd = 0; iCmd < cCmds; iCmd++) {
uint8_t uHash = mkHash(s_ppszCmds[iCmd]); uint8_t uHash = mkHash(s_ppszCmds[iCmd]);
printf(" fcb $%.2X\n", uHash); printf(" fcb $%.2X\n", uHash);

View File

@@ -4,5 +4,5 @@
; vim: ft=asm ; vim: ft=asm
BBHASHLEN IMPORT BBCHTC IMPORT
BBHASHES IMPORT BBCHT IMPORT

View File

@@ -2,6 +2,7 @@
; Copyright (c) 2025 Gale Faraday ; Copyright (c) 2025 Gale Faraday
; Licensed under MIT ; Licensed under MIT
INCLUDE "bbhash.inc"
INCLUDE "buzbee.inc" INCLUDE "buzbee.inc"
INCLUDE "hardware.inc" INCLUDE "hardware.inc"
INCLUDE "serial.inc" INCLUDE "serial.inc"
@@ -21,9 +22,16 @@ BUZBEE
bsr INPLOOP ; Fill input buffer. bsr INPLOOP ; Fill input buffer.
cmpy #$0000 ; No data? cmpy #$0000 ; No data?
beq BUZBEE ; Try again... beq BUZBEE ; Try again...
; TODO: Parse the input buffer ; TODO: Parse the input buffer into tokens
; TODO: Execute the token buffer
bra BUZBEE bra BUZBEE
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; BUZBEE Input Buffering and Handling Routines
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Handle new lines; prints a new prompt and then clears the input buffer ; Handle new lines; prints a new prompt and then clears the input buffer
NEWLINE NEWLINE
PZSTR PROMPTLINE ; Print prompt line PZSTR PROMPTLINE ; Print prompt line
@@ -95,6 +103,12 @@ FULLBUF@
jsr POUTCHAR jsr POUTCHAR
bra INPLOOP bra INPLOOP
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; BUZBEE Command Hashing Routines
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Makes a hash of four chars in BBIN starting at offset X. ; Makes a hash of four chars in BBIN starting at offset X.
; @param X: offset in BBIN to read the four chars from ; @param X: offset in BBIN to read the four chars from
; @return A: resulting hash ; @return A: resulting hash
@@ -110,34 +124,92 @@ NEXTC@
bne NEXTC@ ; No? loop bne NEXTC@ ; No? loop
rts 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 Strings and Fixed Data ;; BUZBEE Internal Command Functions
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; BUZBEE command hashes resolvable with MKCMDSUM. ; Print out a help message
BBCCALL IFHELP
fcb $E4 PZSTR HELP_MSG
BBCEXEC rts
fcb $DB
BBCHELP ; Placeholder function labels to make assembler happy before git commit
fcb $D7 IFCALL
BBCPEEK IFEXEC
fcb $DB IFPEEK
BBCPOKE IFPOKE
fcb $D1 IFSREC
BBCSREC rts
fcb $D3
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; 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 PROMPTLINE
fcb $0D,$0A,$25,$00 ; CR LF '%' NUL fcb $0D,$0A,$25,$00 ; CR LF '%' NUL
EM_OVERRUN EM_OVERRUN
fcn "!!! Overrun Error !!!" fcc "!!! Overrun Error !!!"
fcb $0D,$0A,$00
EM_PARITY EM_PARITY
fcn "!!! Parity Error !!!" fcc "!!! Parity Error !!!"
fcb $0D,$0A,$00
EM_FRAMING EM_FRAMING
fcn "!!! Framing Error !!!" fcc "!!! Framing Error !!!"
fcb $0D,$0A,$00
EM_FIFO EM_FIFO
fcn "!!! FIFO Error !!!" fcc "!!! FIFO Error !!!"
fcb $0D,$0A,$00
EM_BADCMD
fcc "!!! Bad Command Hash !!!"
fcb $0D,$0A,$00