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
This commit is contained in:
blondie7575 2023-07-17 16:53:19 -07:00
parent c14a6fbc28
commit f613e7460c
1 changed files with 9 additions and 3 deletions

View File

@ -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