Commit 440e373
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
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
125 | 125 | | |
126 | 126 | | |
127 | 127 | | |
128 | | - | |
| 128 | + | |
129 | 129 | | |
130 | 130 | | |
131 | 131 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
53 | | - | |
54 | | - | |
55 | | - | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
56 | 56 | | |
57 | | - | |
| 57 | + | |
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
| |||
0 commit comments