From f613e7460c675573230982fd9008c3ceabfab009 Mon Sep 17 00:00:00 2001 From: blondie7575 Date: Mon, 17 Jul 2023 16:53:19 -0700 Subject: [PATCH] Fixed a nasty memory overwrite in terrain compiler If a bomb landed just right near screen bottom, terrain chunk compiler would spray RAM with terrain data --- terrain.s | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/terrain.s b/terrain.s index ed71bb8..df1803b 100644 --- a/terrain.s +++ b/terrain.s @@ -120,6 +120,7 @@ craterTerrainLoop: sta craterTerrainAccumulator lda SCRATCHL2 ; Replace terrain height with cratered value + bmi craterTerrainZero ; Don't let it be negative sta (PARAML0),y bra craterTerrainLoop @@ -131,7 +132,6 @@ craterTerrainZero: ; Circle went negative so clip to 0 craterTerrainDone: lda #1 sta terrainDirty - RESTORE_AX rts @@ -288,12 +288,14 @@ compileTerrainDone: ; ; Y = First row to compile (bottom-relative) ; X = Last row to compile (bottom-relative) -; A = |X-Y| ; ; Trashes A,Y, SCRATCHL, PARAML0, PARAML1 ; compileTerrainChunk: -;HARDBRK + tya ; Be extra safe and make sure Y is never negative or we'll spray RAM with terrain data + bmi compileTerrainChunkClampZero + +compileTerrainChunkResume: stx SCRATCHL sty PARAML0 @@ -322,6 +324,10 @@ compileTerrainChunkLoop: compileTerrainChunkDone: rts +compileTerrainChunkClampZero: + ldy #0 + bra compileTerrainChunkResume + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; compileTerrainRow