1
0
mirror of https://github.com/hsoft/collapseos.git synced 2024-09-29 14:20:55 +10:00

basic: make cmd table more compact

This shaves off quite a few bytes from the binary.
This commit is contained in:
Virgil Dupras 2019-11-30 21:36:34 -05:00
parent 4ba84dac5c
commit 4c07639808
4 changed files with 55 additions and 40 deletions

View File

@ -38,12 +38,12 @@ basPUTB:
jp blkPutB jp blkPutB
basBLKCmds: basBLKCmds:
.db "bsel", 0
.dw basBSEL .dw basBSEL
.db "bsel", 0, 0
.dw basBSEEK
.db "bseek", 0 .db "bseek", 0
.dw basBSEEK
.db "getb", 0
.dw basGETB .dw basGETB
.db "getb", 0, 0 .db "putb", 0
.dw basPUTB .dw basPUTB
.db "putb", 0, 0 .db 0xff ; end of table
.db 0xff, 0xff, 0xff ; end of table

View File

@ -127,14 +127,14 @@ basPgmHook:
ret ret
basFSCmds: basFSCmds:
.db "fls", 0
.dw basFLS .dw basFLS
.db "fls", 0, 0, 0
.dw basLDBAS
.db "ldbas", 0 .db "ldbas", 0
.dw basFOPEN .dw basLDBAS
.db "fopen", 0 .db "fopen", 0
.dw basFOPEN
.db "fnew", 0
.dw basFNEW .dw basFNEW
.db "fnew", 0, 0 .db "fdel", 0
.dw basFDEL .dw basFDEL
.db "fdel", 0, 0 .db 0xff ; end of table
.db 0xff, 0xff, 0xff ; end of table

View File

@ -63,19 +63,18 @@ basLoop:
; Destroys HL. ; Destroys HL.
; Z is set if found, unset otherwise. ; Z is set if found, unset otherwise.
basFindCmd: basFindCmd:
; cmd table starts with routine pointer, skip
inc hl \ inc hl
.loop: .loop:
call strcmp call strcmp
jr z, .found call strskip
ld a, 8 inc hl ; point to routine
call addHL jr z, .found ; Z from strcmp
inc hl \ inc hl ; skip routine
ld a, (hl) ld a, (hl)
cp 0xff inc a ; was it 0xff?
jr nz, .loop jr nz, .loop ; no
jp unsetZ dec a ; unset Z
ret
.found: .found:
dec hl \ dec hl
call intoHL call intoHL
push hl \ pop ix push hl \ pop ix
ret ret
@ -436,46 +435,49 @@ basR2Var: ; Just send reg to vars. Used in basPgmHook
cp a ; USR never errors out cp a ; USR never errors out
ret ret
; Command table format: Null-terminated string followed by a 2-byte routine
; pointer.
; direct only ; direct only
basCmds1: basCmds1:
.db "bye", 0
.dw basBYE .dw basBYE
.db "bye", 0, 0, 0 .db "list", 0
.dw basLIST .dw basLIST
.db "list", 0, 0 .db "run", 0
.dw basRUN .dw basRUN
.db "run", 0, 0, 0
.dw bufInit
.db "clear", 0 .db "clear", 0
.dw bufInit
; statements ; statements
basCmds2: basCmds2:
.dw basPRINT
.db "print", 0 .db "print", 0
.dw basPRINT
.db "goto", 0
.dw basGOTO .dw basGOTO
.db "goto", 0, 0 .db "if", 0
.dw basIF .dw basIF
.db "if", 0, 0, 0, 0
.dw basINPUT
.db "input", 0 .db "input", 0
.dw basINPUT
.db "peek", 0
.dw basPEEK .dw basPEEK
.db "peek", 0, 0 .db "poke", 0
.dw basPOKE .dw basPOKE
.db "poke", 0, 0 .db "deek", 0
.dw basDEEK .dw basDEEK
.db "deek", 0, 0 .db "doke", 0
.dw basDOKE .dw basDOKE
.db "doke", 0, 0 .db "out", 0
.dw basOUT .dw basOUT
.db "out", 0, 0, 0 .db "in", 0
.dw basIN .dw basIN
.db "in", 0, 0, 0, 0 .db "getc", 0
.dw basGETC .dw basGETC
.db "getc", 0, 0 .db "putc", 0
.dw basPUTC .dw basPUTC
.db "putc", 0, 0
.dw basSLEEP
.db "sleep", 0 .db "sleep", 0
.dw basSLEEP
.db "addr", 0
.dw basADDR .dw basADDR
.db "addr", 0, 0 .db "usr", 0
.dw basUSR .dw basUSR
.db "usr", 0, 0, 0 .db 0xff ; end of table
.db 0xff, 0xff, 0xff ; end of table

View File

@ -52,6 +52,19 @@ strcmp:
; early, set otherwise) ; early, set otherwise)
ret ret
; Given a string at (HL), move HL until it points to the end of that string.
strskip:
push af
xor a ; look for null char
.loop:
cp (hl)
jp z, .found
inc hl
jr .loop
.found:
pop af
ret
; Returns length of string at (HL) in A. ; Returns length of string at (HL) in A.
; Doesn't include null termination. ; Doesn't include null termination.
strlen: strlen: