Skip to content

Commit 338fdb1

Browse files
mbrukneragurtovoy
authored andcommitted
fix: SPC() infinite loop and direct command loop after break
SPC(0) caused an infinite loop because bra always branched back regardless of Y reaching zero. Changed to bne to exit when count reaches zero. Direct commands (typed at console) looped endlessly after a break because codePtr+2 was left at 0, making DoCheckEnd think there were more pages to process. Set codePtr+2 = pageCount-1 so the end-of-program check terminates correctly.
1 parent a6a98b5 commit 338fdb1

3 files changed

Lines changed: 6 additions & 3 deletions

File tree

source/common/cli/warmstart.asm

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ _WSNotSlash:
5353
; Run code in token buffer
5454
;
5555
stz tokenOffset ; zero the "offset", meaning it only runs one line.
56+
lda pageCount ; set page index to last page so DoCheckEnd
57+
dec a ; sees end-of-program (CPX pageCount sets Z=1
58+
sta codePtr+2 ; when codePtr+2 = pageCount-1, after INX).
5659
.csetcodepointer tokenOffset ; set up the code pointer.
5760
lda tokenBuffer ; nothing to run
5861
cmp #KWC_EOL

source/common/commands/run.asm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ _CRIncMainLoop:
7373
.breakcheck ; break check
7474
bne _CRBreak
7575
.tickcheck TickHandler ; if time elapsed call the tick handler.
76-
_CRNoBreakCheck:
77-
;
76+
_CRNoBreakCheck:
77+
;
7878
iny ; next token
7979
_CRMainLoop:
8080
stz stringInitialised ; clear the temporary string initialised flag.

source/common/expressions/unary/string/spc.asm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ _SpcLoop:
3131
lda #32
3232
jsr StringTempWrite
3333
dey
34-
bra _SpcLoop
34+
bne _SpcLoop
3535
_SpcExit:
3636
ply
3737
jmp CheckRightBracket

0 commit comments

Comments
 (0)