feat(buzbee): Implemented CALL, PEEK, POKE IFs
This commit is contained in:
168
src/buzbee.s
168
src/buzbee.s
@@ -29,7 +29,7 @@ BBVAR tagbbvar
|
|||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;;
|
;;
|
||||||
;; BUZBEE Machine Language Monitor for CHIBI PC-09
|
;; BUZBEE Main Loop
|
||||||
;;
|
;;
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
@@ -43,7 +43,7 @@ BUZBEE
|
|||||||
cmpy #$0000 ; No data?
|
cmpy #$0000 ; No data?
|
||||||
beq BUZBEE ; Try again...
|
beq BUZBEE ; Try again...
|
||||||
; TODO: Parse the input buffer into tokens
|
; TODO: Parse the input buffer into tokens
|
||||||
; TODO: Execute the token buffer
|
lbsr RUNIF
|
||||||
bra BUZBEE
|
bra BUZBEE
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
@@ -125,7 +125,43 @@ FULLBUF@
|
|||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;;
|
;;
|
||||||
;; BUZBEE Command Hashing Routines
|
;; Hex Conversion and Printing Routines
|
||||||
|
;;
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
|
; Prints a byte in A
|
||||||
|
; @param a: byte to print
|
||||||
|
PBYTE
|
||||||
|
pshs b
|
||||||
|
tfr a,b ; Transfer lower nybble into B
|
||||||
|
andd #$F00F ; Mask and adjsut
|
||||||
|
asra
|
||||||
|
asra
|
||||||
|
asra
|
||||||
|
asra
|
||||||
|
bsr NYB2HEX ; Print A
|
||||||
|
jsr POUTCHAR
|
||||||
|
tfr b,a ; Print B next
|
||||||
|
bsr NYB2HEX ; Print B
|
||||||
|
jsr POUTCHAR
|
||||||
|
puls b
|
||||||
|
rts
|
||||||
|
|
||||||
|
; Converts a nybble into a valid hex digit
|
||||||
|
; @param a: nybble to convert to a char
|
||||||
|
; @return a: resulting char
|
||||||
|
NYB2HEX
|
||||||
|
anda #$0F
|
||||||
|
ora #'0 ; Add "0"
|
||||||
|
cmpa #$3A ; ":" "9"+1
|
||||||
|
bcc SKIP@
|
||||||
|
adca #6 ; Add offset to "A" in ascii
|
||||||
|
SKIP@
|
||||||
|
rts
|
||||||
|
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
;;
|
||||||
|
;; BUZBEE Tokenizing Routines
|
||||||
;;
|
;;
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
@@ -144,44 +180,126 @@ NEXTC@
|
|||||||
bne NEXTC@ ; No? loop
|
bne NEXTC@ ; No? loop
|
||||||
rts
|
rts
|
||||||
|
|
||||||
; Maps a command hash to a command index, and executes it
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
;;
|
||||||
|
;; BUZBEE IF Handling Functions
|
||||||
|
;;
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
|
; Executes a command based on the initial token
|
||||||
; @corrupts B
|
; @corrupts B
|
||||||
; @param A: input hash
|
|
||||||
; @return X: command data table index
|
; @return X: command data table index
|
||||||
CALLFROMHASH
|
RUNIF
|
||||||
ldx #0 ; Counting up from zero
|
ldx #0 ; Counting up from zero
|
||||||
|
lda BBVAR.tokens ; Load token
|
||||||
NEXTHASH@
|
NEXTHASH@
|
||||||
cmpa BBCHT,x ; Is this hash our hash?
|
cmpa BBCHT,x ; Is this hash our hash?
|
||||||
beq CALCPTR@ ; Yes? skip to next step to put ptr in x
|
beq CALCPTR@ ; Yes? skip to next step to put ptr in x
|
||||||
leax 1,x ; Begin considering next hash
|
leax 1,x ; Begin considering next hash
|
||||||
cmpx BBCHTC ; Is this the last byte?
|
cmpx BBCHTC ; Is this the last byte?
|
||||||
blo NEXTHASH@ ; No? try next hash, Yes? fall through
|
blo NEXTHASH@ ; No? try next hash, Yes? fall through
|
||||||
PZSTR EM_BADCMD ; Print an error message
|
PZSTR EM_BADCMD ; Print an error message
|
||||||
lbra IFHELP ; Proceed to call "HELP"
|
lbra IFHELP ; Proceed to call "HELP"
|
||||||
CALCPTR@
|
CALCPTR@
|
||||||
tfr x,d ; Swap into d to do a cheap multiply
|
tfr x,d ; Swap into d to do a cheap multiply
|
||||||
asld ; Cheaply << to get *2, pointer size
|
asld ; Cheaply << to get *2, pointer size
|
||||||
tfr d,x ; Restore x from d and jump to function at index
|
tfr d,x ; Restore x from d and jump to function at index
|
||||||
jmp [BBCMDPTRTBL,x]
|
jmp [BBCMDPTRTBL,x]
|
||||||
|
|
||||||
|
; IF pointer table
|
||||||
|
BBCMDPTRTBL
|
||||||
|
fdb IFCALL
|
||||||
|
fdb IFHELP
|
||||||
|
fdb IFPEEK
|
||||||
|
fdb IFPOKE
|
||||||
|
fdb IFSREC
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;;
|
;;
|
||||||
;; BUZBEE Internal Command Functions
|
;; BUZBEE Internal Command Functions
|
||||||
;;
|
;;
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
|
; Call a pointer
|
||||||
|
IFCALL
|
||||||
|
ldd BBVAR.cbtokens ; Only jump if three tokens given
|
||||||
|
cmpd #3
|
||||||
|
lbne INVALIDARG
|
||||||
|
jsr [BBVAR.tokens+1] ; Make our jump (doesn't implicitly return)
|
||||||
|
rts
|
||||||
|
|
||||||
; Print out a help message
|
; Print out a help message
|
||||||
IFHELP
|
IFHELP
|
||||||
PZSTR HELP_MSG
|
PZSTR HELP_MSG
|
||||||
rts
|
rts
|
||||||
|
|
||||||
; Placeholder function labels to make assembler happy before git commit
|
; Peek memory
|
||||||
IFCALL
|
|
||||||
IFPEEK
|
IFPEEK
|
||||||
|
ldd BBVAR.cbtokens ; One 16-bit token given, single peek
|
||||||
|
cmpd #3
|
||||||
|
lblo INVALIDARG ; Not enough args given
|
||||||
|
bhi SELFORBAC@ ; Select forward or backward peek
|
||||||
|
SINGLE@
|
||||||
|
lda [BBVAR.tokens+1] ; Get byte
|
||||||
|
lbsr PBYTE ; Print peek byte
|
||||||
|
rts
|
||||||
|
SELFORBAC@
|
||||||
|
ldd BBVAR.cbtokens ; Have enough tokens?
|
||||||
|
cmpd #5
|
||||||
|
lbne INVALIDARG ; No? bounce out
|
||||||
|
ldd BBVAR.tokens+1 ; Are we forwards (BASE < HIGH)?
|
||||||
|
cmpd BBVAR.tokens+3
|
||||||
|
beq SINGLE@ ; Gracefully handle BASE == HIGH
|
||||||
|
blo PEEKFWD
|
||||||
|
bhi PEEKBACK
|
||||||
|
|
||||||
|
; Peek forward
|
||||||
|
PEEKFWD
|
||||||
|
ldx BBVAR.tokens+1 ; Get BASE
|
||||||
|
NEXT@
|
||||||
|
lda ,x+ ; Get the next byte
|
||||||
|
lbsr PBYTE ; Print our byte
|
||||||
|
cmpx BBVAR.tokens+3 ; Are we at <HIGH> yet?
|
||||||
|
bne NEXT@ ; No? loop
|
||||||
|
rts
|
||||||
|
|
||||||
|
; Peek backwards
|
||||||
|
PEEKBACK
|
||||||
|
ldx BBVAR.tokens+1 ; Get BASE
|
||||||
|
PREV@
|
||||||
|
lda 0,x ; Get current byte
|
||||||
|
leax -1,x ; Prep for next byte
|
||||||
|
lbsr PBYTE ; Print our byte
|
||||||
|
cmpx BBVAR.tokens+3 ; Are we at <HIGH> yet?
|
||||||
|
bne PREV@ ; No? loop
|
||||||
|
rts
|
||||||
|
|
||||||
|
; Poke bytes into memory
|
||||||
|
; NOTE: Blocks could also use 6309 TFM instruction
|
||||||
IFPOKE
|
IFPOKE
|
||||||
|
ldx BBVAR.cbtokens ; Make sure we have enough tokens
|
||||||
|
cmpx #4
|
||||||
|
lblo INVALIDARG
|
||||||
|
leax -3,x ; Get count of bytes to write into X
|
||||||
|
ldy #0 ; Setup Y for indexing
|
||||||
|
NEXTB@
|
||||||
|
lda BBVAR.tokens+3,y ; Get source byte to copy
|
||||||
|
sta [BBVAR.tokens+1,y] ; Copy byte
|
||||||
|
leay +1,y ; Increment memory indexer
|
||||||
|
leax -1,x ; Decement byte count
|
||||||
|
cmpx #0 ; Are we at our last byte?
|
||||||
|
bhi NEXTB@ ; No? loop
|
||||||
|
rts
|
||||||
|
|
||||||
|
; Placeholder function labels to make assembler happy before git commit
|
||||||
IFSREC
|
IFSREC
|
||||||
rts
|
rts
|
||||||
|
|
||||||
|
; Invalid argument IF tail
|
||||||
|
INVALIDARG
|
||||||
|
PZSTR EM_MISSINGARG
|
||||||
|
rts
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;;
|
;;
|
||||||
;; BUZBEE Strings and Tables
|
;; BUZBEE Strings and Tables
|
||||||
@@ -195,8 +313,6 @@ HELP_MSG
|
|||||||
fcb $0D,$0A
|
fcb $0D,$0A
|
||||||
fcc "CALL <PTR> - Call the pointer given in <PTR> as a subroutine."
|
fcc "CALL <PTR> - Call the pointer given in <PTR> as a subroutine."
|
||||||
fcb $0D,$0A
|
fcb $0D,$0A
|
||||||
fcc "EXEC <PTR> - Start program at <PTR>."
|
|
||||||
fcb $0D,$0A
|
|
||||||
fcc "HELP [CMD] - Display help, command optional."
|
fcc "HELP [CMD] - Display help, command optional."
|
||||||
fcb $0D,$0A
|
fcb $0D,$0A
|
||||||
fcc "PEEK <BASE> [<HIGH>] - Read memory at <BASE> to <HIGH>."
|
fcc "PEEK <BASE> [<HIGH>] - Read memory at <BASE> to <HIGH>."
|
||||||
@@ -207,13 +323,6 @@ HELP_MSG
|
|||||||
fcb $0D,$0A
|
fcb $0D,$0A
|
||||||
fcb $00
|
fcb $00
|
||||||
|
|
||||||
BBCMDPTRTBL
|
|
||||||
fdb IFCALL
|
|
||||||
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
|
||||||
|
|
||||||
@@ -232,3 +341,6 @@ EM_FIFO
|
|||||||
EM_BADCMD
|
EM_BADCMD
|
||||||
fcc "!!! Bad Command Hash !!!"
|
fcc "!!! Bad Command Hash !!!"
|
||||||
fcb $0D,$0A,$00
|
fcb $0D,$0A,$00
|
||||||
|
EM_MISSINGARG
|
||||||
|
fcc "!!! Missing Arguments !!!"
|
||||||
|
fcb $0D,$0A,$00
|
||||||
|
Reference in New Issue
Block a user