basic: add run command
This commit is contained in:
parent
9d1003e7a2
commit
9c9484fb88
@ -19,39 +19,47 @@ basStart:
|
|||||||
call printcrlf
|
call printcrlf
|
||||||
ld hl, .welcome+2 ; points to a zero word
|
ld hl, .welcome+2 ; points to a zero word
|
||||||
ld (BAS_PCURLN), hl
|
ld (BAS_PCURLN), hl
|
||||||
jr basPrompt
|
jr basLoop
|
||||||
|
|
||||||
.welcome:
|
.welcome:
|
||||||
.db "OK", 0, 0
|
.db "OK", 0, 0
|
||||||
|
|
||||||
basPrompt:
|
basLoop:
|
||||||
ld hl, .sPrompt
|
ld hl, .sPrompt
|
||||||
call printstr
|
call printstr
|
||||||
call stdioReadLine
|
call stdioReadLine
|
||||||
|
call printcrlf
|
||||||
call parseDecimal
|
call parseDecimal
|
||||||
jr z, .number
|
jr z, .number
|
||||||
call basDirect
|
ld de, basCmds1
|
||||||
jr basPrompt
|
call basCallCmd
|
||||||
|
jr z, basLoop
|
||||||
|
; Error
|
||||||
|
call basERR
|
||||||
|
jr basLoop
|
||||||
.number:
|
.number:
|
||||||
push ix \ pop de
|
push ix \ pop de
|
||||||
call toWS
|
call toWS
|
||||||
call rdWS
|
call rdWS
|
||||||
call bufAdd
|
call bufAdd
|
||||||
jp nz, basERR
|
jp nz, basERR
|
||||||
call printcrlf
|
jr basLoop
|
||||||
jr basPrompt
|
|
||||||
.sPrompt:
|
.sPrompt:
|
||||||
.db "> ", 0
|
.db "> ", 0
|
||||||
|
|
||||||
basDirect:
|
; Call command in (HL) after having looked for it in cmd table in (DE).
|
||||||
|
; If found, jump to it. If not found, unset Z. We expect commands to set Z
|
||||||
|
; on success. Therefore, when calling basCallCmd results in NZ, we're not sure
|
||||||
|
; where the error come from, but well...
|
||||||
|
basCallCmd:
|
||||||
; First, get cmd length
|
; First, get cmd length
|
||||||
call fnWSIdx
|
call fnWSIdx
|
||||||
cp 7
|
cp 7
|
||||||
jr nc, .unknown ; Too long, can't possibly fit anything.
|
jp nc, unsetZ ; Too long, can't possibly fit anything.
|
||||||
; A contains whitespace IDX, save it in B
|
; A contains whitespace IDX, save it in B
|
||||||
ld b, a
|
ld b, a
|
||||||
ex de, hl
|
ex de, hl
|
||||||
ld hl, basCmds1+2
|
inc hl \ inc hl
|
||||||
.loop:
|
.loop:
|
||||||
ld a, b ; whitespace IDX
|
ld a, b ; whitespace IDX
|
||||||
call strncmp
|
call strncmp
|
||||||
@ -61,10 +69,8 @@ basDirect:
|
|||||||
ld a, (hl)
|
ld a, (hl)
|
||||||
cp 0xff
|
cp 0xff
|
||||||
jr nz, .loop
|
jr nz, .loop
|
||||||
.unknown:
|
; not found
|
||||||
ld hl, .sUnknown
|
jp unsetZ
|
||||||
jr basPrintLn
|
|
||||||
|
|
||||||
.found:
|
.found:
|
||||||
dec hl \ dec hl
|
dec hl \ dec hl
|
||||||
call intoHL
|
call intoHL
|
||||||
@ -76,11 +82,8 @@ basDirect:
|
|||||||
call rdWS
|
call rdWS
|
||||||
jp (ix)
|
jp (ix)
|
||||||
|
|
||||||
.sUnknown:
|
|
||||||
.db "Unknown command", 0
|
|
||||||
|
|
||||||
basPrintLn:
|
basPrintLn:
|
||||||
call printcrlf
|
|
||||||
call printstr
|
call printstr
|
||||||
jp printcrlf
|
jp printcrlf
|
||||||
|
|
||||||
@ -95,6 +98,8 @@ basERR:
|
|||||||
; either:
|
; either:
|
||||||
; 1 - the end of the string if the command has no arg.
|
; 1 - the end of the string if the command has no arg.
|
||||||
; 2 - the beginning of the arg, with whitespace properly skipped.
|
; 2 - the beginning of the arg, with whitespace properly skipped.
|
||||||
|
;
|
||||||
|
; Commands are expected to set Z on success.
|
||||||
basBYE:
|
basBYE:
|
||||||
ld hl, .sBye
|
ld hl, .sBye
|
||||||
call basPrintLn
|
call basPrintLn
|
||||||
@ -107,7 +112,6 @@ basBYE:
|
|||||||
.db "Goodbye!", 0
|
.db "Goodbye!", 0
|
||||||
|
|
||||||
basLIST:
|
basLIST:
|
||||||
call printcrlf
|
|
||||||
call bufFirst
|
call bufFirst
|
||||||
ret nz
|
ret nz
|
||||||
.loop:
|
.loop:
|
||||||
@ -123,15 +127,44 @@ basLIST:
|
|||||||
call printcrlf
|
call printcrlf
|
||||||
call bufNext
|
call bufNext
|
||||||
jr z, .loop
|
jr z, .loop
|
||||||
|
cp a ; ensure Z
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
|
||||||
|
basRUN:
|
||||||
|
call bufFirst
|
||||||
|
ret nz
|
||||||
|
.loop:
|
||||||
|
call bufStr
|
||||||
|
ld de, basCmds2
|
||||||
|
push ix ; --> lvl 1
|
||||||
|
call basCallCmd
|
||||||
|
pop ix ; <-- lvl 1
|
||||||
|
jp nz, .err
|
||||||
|
call bufNext
|
||||||
|
jr z, .loop
|
||||||
|
cp a ; ensure Z
|
||||||
|
ret
|
||||||
|
.err:
|
||||||
|
; Print line number, then return NZ (which will print ERR)
|
||||||
|
ld e, (ix)
|
||||||
|
ld d, (ix+1)
|
||||||
|
ld hl, BAS_SCRATCHPAD
|
||||||
|
call fmtDecimal
|
||||||
|
call printstr
|
||||||
|
ld a, ' '
|
||||||
|
call stdioPutC
|
||||||
|
jp unsetZ
|
||||||
|
|
||||||
|
.runline:
|
||||||
|
|
||||||
basPRINT:
|
basPRINT:
|
||||||
call parseExpr
|
call parseExpr
|
||||||
jp nz, basERR
|
ret nz
|
||||||
push ix \ pop de
|
push ix \ pop de
|
||||||
ld hl, BAS_SCRATCHPAD
|
ld hl, BAS_SCRATCHPAD
|
||||||
call fmtDecimal
|
call fmtDecimal
|
||||||
|
cp a ; ensure Z
|
||||||
jp basPrintLn
|
jp basPrintLn
|
||||||
|
|
||||||
; direct only
|
; direct only
|
||||||
@ -140,6 +173,8 @@ basCmds1:
|
|||||||
.db "bye", 0, 0, 0
|
.db "bye", 0, 0, 0
|
||||||
.dw basLIST
|
.dw basLIST
|
||||||
.db "list", 0, 0
|
.db "list", 0, 0
|
||||||
|
.dw basRUN
|
||||||
|
.db "run", 0, 0, 0
|
||||||
; statements
|
; statements
|
||||||
basCmds2:
|
basCmds2:
|
||||||
.dw basPRINT
|
.dw basPRINT
|
||||||
|
Loading…
Reference in New Issue
Block a user