feat(buzbee): add tokenizing routines, buzbee feature complete
This commit is contained in:
70
src/buzbee.s
70
src/buzbee.s
@@ -40,13 +40,13 @@ BBVAR tagbbvar
|
||||
EXPORT BUZBEE
|
||||
|
||||
BUZBEE
|
||||
lbsr NEWLINE ; Setup the new input line and handle display.
|
||||
bsr INPLOOP ; Fill input buffer.
|
||||
cmpy #0 ; No data?
|
||||
beq BUZBEE ; Try again...
|
||||
; TODO: Parse the input buffer into tokens
|
||||
lbsr RUNIF
|
||||
bra BUZBEE
|
||||
lbsr NEWLINE ; Setup the new input line and handle display.
|
||||
bsr INPLOOP ; Fill input buffer.
|
||||
cmpy #0 ; No data?
|
||||
beq BUZBEE ; Try again...
|
||||
lbsr TOKENIZE ; Try to tokenize the input buffer
|
||||
lbsr RUNIF ; Execute token buffer, handling any errors
|
||||
bra BUZBEE ; Repeat
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;;
|
||||
@@ -201,6 +201,62 @@ BADHEX@
|
||||
;;
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
; Attempts to parse the input buffer into tokens depending on the command
|
||||
TOKENIZE
|
||||
ldd BBVAR.cchinput ; Do we have input to work with?
|
||||
cmpd #4 ; Do we have even enough space for a string command
|
||||
blo TOKFAIL@ ; No? GTFO
|
||||
ldy #0 ; Initialize Y; used to track current position in BBVAR.input
|
||||
ldx #0 ; Initialize X; used to track position in BBVAR.tokens
|
||||
bsr SKIPTONEXTC ; Get the next non-whitespace char
|
||||
bsr MKCMDSUM ; Hash the first four non-whitespace chars
|
||||
bsr HASH2TOKEN ; Try to turn that hash into a proper token
|
||||
bcs TOKFAIL@
|
||||
bra STTOK@ ; Store token
|
||||
NEXTHEX@ ; Next hex token
|
||||
bsr SKIPTONEXTC ; Skip to next whitespace
|
||||
ldd BBVAR.input,y ; Get hex value (two digits)
|
||||
bsr HEX2BYT ; Convert hex value to byte value
|
||||
STTOK@
|
||||
sta BBVAR.tokens,x ; Store curent token
|
||||
leax 1,x ; Advance to next token
|
||||
cmpx #BBTOKENS_DEPTH ; Is this next token in bounds?
|
||||
beq FULLBUF@ ; No? handle a full buffer
|
||||
bra NEXTHEX@ ; Try to turn the next character into a hex value
|
||||
FULLBUF@
|
||||
PZSTR EM_FULLTOKBUF ; Print an error message
|
||||
clrd ; Say we wrote no tokens
|
||||
std BBVAR.cbtokens
|
||||
rts
|
||||
TOKFAIL@
|
||||
PZSTR EM_TOKFAIL ; Print tokenization fail
|
||||
clrd ; Say we wrote no tokens
|
||||
std BBVAR.cbtokens
|
||||
rts
|
||||
|
||||
; Converts a runtime command hash into a portable token. Command tokens are
|
||||
; indexes into BBCHT, which is generated at compile-time
|
||||
; @param A: runtime hash
|
||||
; @return A: output token
|
||||
; @return CC.C: set if error state, cleared otherwise
|
||||
HASH2TOKEN
|
||||
pshs x ; Preserve & init X; other routines in this group use it
|
||||
ldx #0
|
||||
NEXTHASH@
|
||||
cmpa BBCHT,x ; Is this hash our hash?
|
||||
beq THISHASH@ ; Yes? turn it into a token
|
||||
leax 1,x ; Begin considering next hash
|
||||
cmpx BBCHTC ; Is the next hash even in the table?
|
||||
blo NEXTHASH@ ; Yes? try this next hash, No? fall through
|
||||
PZSTR EM_BADHASH CALL; Print an error message to the user
|
||||
puls x
|
||||
orcc #1 ; Set CC.C to indicate error
|
||||
rts
|
||||
THISHASH@
|
||||
puls x
|
||||
andcc #$FE ; Clear CC.C to indicate success
|
||||
rts
|
||||
|
||||
; Makes a hash of four chars in BBIN starting at offset X
|
||||
; @param Y: offset in BBIN to read the four chars from
|
||||
; @return A: resulting hash
|
||||
|
Reference in New Issue
Block a user