diff --git a/bbmkhash.c b/bbmkhash.c index 8b9c6e9..1d34ee3 100644 --- a/bbmkhash.c +++ b/bbmkhash.c @@ -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); diff --git a/src/bbhash.inc b/src/bbhash.inc index f83382c..e99ff30 100644 --- a/src/bbhash.inc +++ b/src/bbhash.inc @@ -4,5 +4,5 @@ ; vim: ft=asm -BBHASHLEN IMPORT -BBHASHES IMPORT +BBCHTC IMPORT +BBCHT IMPORT diff --git a/src/buzbee.s b/src/buzbee.s index 9e4006a..543a851 100644 --- a/src/buzbee.s +++ b/src/buzbee.s @@ -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 - Call the pointer given in as a subroutine." + fcb $0D,$0A + fcc "EXEC - Start program at ." + fcb $0D,$0A + fcc "HELP [CMD] - Display help, command optional." + fcb $0D,$0A + fcc "PEEK [] - Read memory at to ." + fcb $0D,$0A + fcc "POKE - Overwrite memory with starting at ." + 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