1
0
mirror of https://github.com/hsoft/collapseos.git synced 2024-11-27 20:58:07 +11:00

basic: add goto

Things are getting super cereal...
This commit is contained in:
Virgil Dupras 2019-11-20 15:44:13 -05:00
parent 9d6cbe577c
commit 9c400ca642

View File

@ -4,8 +4,11 @@
; Value of `SP` when basic was first invoked. This is where SP is going back to ; Value of `SP` when basic was first invoked. This is where SP is going back to
; on restarts. ; on restarts.
.equ BAS_INITSP BAS_RAMSTART .equ BAS_INITSP BAS_RAMSTART
; **Pointer** to current line number ; Pointer to next line to run. If nonzero, it means that the next line is
.equ BAS_PCURLN @+2 ; the first of the list. This is used by GOTO to indicate where to jump next.
; Important note: this is **not** a line number, it's a pointer to a line index
; in buffer. If it's not zero, its a valid pointer.
.equ BAS_PNEXTLN @+2
.equ BAS_SCRATCHPAD @+2 .equ BAS_SCRATCHPAD @+2
.equ BAS_RAMEND @+BAS_SCRATCHPAD_SIZE .equ BAS_RAMEND @+BAS_SCRATCHPAD_SIZE
@ -18,12 +21,12 @@ basStart:
ld hl, .welcome ld hl, .welcome
call printstr call printstr
call printcrlf call printcrlf
ld hl, .welcome+2 ; points to a zero word ld hl, 0 ; points to a zero word
ld (BAS_PCURLN), hl ld (BAS_PNEXTLN), hl
jr basLoop jr basLoop
.welcome: .welcome:
.db "OK", 0, 0 .db "OK", 0
basLoop: basLoop:
ld hl, .sPrompt ld hl, .sPrompt
@ -145,6 +148,8 @@ basLIST:
basRUN: basRUN:
call .maybeGOTO
jr nz, .loop ; IX already set
call bufFirst call bufFirst
ret nz ret nz
.loop: .loop:
@ -154,6 +159,8 @@ basRUN:
call basCallCmd call basCallCmd
pop ix ; <-- lvl 1 pop ix ; <-- lvl 1
jp nz, .err jp nz, .err
call .maybeGOTO
jr nz, .loop ; IX already set
call bufNext call bufNext
jr z, .loop jr z, .loop
cp a ; ensure Z cp a ; ensure Z
@ -169,7 +176,19 @@ basRUN:
call stdioPutC call stdioPutC
jp unsetZ jp unsetZ
.runline: ; This returns the opposite Z result as the one we usually see: Z is set if
; we **don't** goto, unset if we do. If we do, IX is properly set.
.maybeGOTO:
ld de, (BAS_PNEXTLN)
ld a, d
or e
ret z
; we goto
push de \ pop ix
; we need to reset our goto marker
ld de, 0
ld (BAS_PNEXTLN), de
ret
basPRINT: basPRINT:
call parseExpr call parseExpr
@ -180,6 +199,22 @@ basPRINT:
cp a ; ensure Z cp a ; ensure Z
jp basPrintLn jp basPrintLn
basGOTO:
call parseExpr
ret nz
push ix \ pop de
call bufFind
jr nz, .notFound
push ix \ pop de
; Z already set
jr .end
.notFound:
ld de, 0
; Z already unset
.end:
ld (BAS_PNEXTLN), de
ret
; direct only ; direct only
basCmds1: basCmds1:
.dw basBYE .dw basBYE
@ -192,4 +227,6 @@ basCmds1:
basCmds2: basCmds2:
.dw basPRINT .dw basPRINT
.db "print", 0 .db "print", 0
.dw basGOTO
.db "goto", 0, 0
.db 0xff, 0xff, 0xff ; end of table .db 0xff, 0xff, 0xff ; end of table