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

View File

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

View File

@@ -2,6 +2,7 @@
; Copyright (c) 2025 Gale Faraday
; Licensed under MIT
INCLUDE "bbhash.inc"
INCLUDE "buzbee.inc"
INCLUDE "hardware.inc"
INCLUDE "serial.inc"
@@ -21,9 +22,16 @@ BUZBEE
bsr INPLOOP ; Fill input buffer.
cmpy #$0000 ; No data?
beq BUZBEE ; Try again...
; TODO: Parse the input buffer
; 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
@@ -95,6 +103,12 @@ FULLBUF@
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
@@ -110,34 +124,92 @@ NEXTC@
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 Strings and Fixed Data
;; BUZBEE Internal Command Functions
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; BUZBEE command hashes resolvable with MKCMDSUM.
BBCCALL
fcb $E4
BBCEXEC
fcb $DB
BBCHELP
fcb $D7
BBCPEEK
fcb $DB
BBCPOKE
fcb $D1
BBCSREC
fcb $D3
; 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
fcn "!!! Overrun Error !!!"
fcc "!!! Overrun Error !!!"
fcb $0D,$0A,$00
EM_PARITY
fcn "!!! Parity Error !!!"
fcc "!!! Parity Error !!!"
fcb $0D,$0A,$00
EM_FRAMING
fcn "!!! Framing Error !!!"
fcc "!!! Framing Error !!!"
fcb $0D,$0A,$00
EM_FIFO
fcn "!!! FIFO Error !!!"
fcc "!!! FIFO Error !!!"
fcb $0D,$0A,$00
EM_BADCMD
fcc "!!! Bad Command Hash !!!"
fcb $0D,$0A,$00