Skip to content

Commit 440e373

Browse files
authored
fix: DIM a(255) zero-element array and scroll-up off-by-one fill (#143)
Two bug fixes found during a code audit. ## `DIM a(255)` allocated a zero-element array The array-size guard in `_DCGetSize` (`dim.asm`) rejected 254 and allowed 255. Since the element count is computed as `size+1`, a size of 255 wraps to 0: `DIM a(255)` allocated no memory yet registered the array as valid with max index 255, so any element access silently corrupted the heap. The fix rejects 255 and allows 254. Verified in the emulator: before, `DIM a(255)` was accepted and `a(0)=42 : PRINT a(0)` printed `0` (write lost); after, `DIM a(255)` raises "Array size", `DIM a(254)` works and stores/reads correctly, and existing sizes are unaffected. ## Scroll-up bottom-row fill wrote one byte past the screen The bottom-line blank loop in `scroll.asm` used `bpl`, which also branches when Y reaches 0, doing one extra `dey` (Y wraps to $FF) and storing the fill byte 255 bytes past the row start. Every scroll fills both the text and colour pages, so each scroll did two stray writes into RAM beyond the visible screen. Switched to `bne`, matching the scroll-down fill loop. Verified in the emulator: scrolling 200 lines renders cleanly with the bottom row correctly blanked. --------- Signed-off-by: Matthias Brukner <mbrukner@gmail.com>
1 parent 3bc9b76 commit 440e373

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

source/common/commands/dim.asm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ _DCGetSize:
125125
ldx #0 ; get first index.
126126
jsr Evaluate8BitInteger ; get array dimension (Z set by lda)
127127
beq _DCSize ; must be 1-254
128-
cmp #254
128+
cmp #255 ; reject 255: size+1 wraps to 0 elements
129129
beq _DCSize
130130
rts
131131

source/modules/hardware/scroll.asm

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ _EXSFCopy1: ; do one page
5050

5151
ldy EXTScreenWidth ; blank the bottom line.
5252
txa
53-
_EXSFFill1:
54-
dey
55-
sta (EXTAddress),y
53+
_EXSFFill1:
54+
dey
55+
sta (EXTAddress),y
5656
cpy #0
57-
bpl _EXSFFill1
57+
bne _EXSFFill1
5858

5959
pla
6060
sta zTemp1+1

0 commit comments

Comments
 (0)