From 92a3a9040e9e606a24bd73ef3ad197e9b5fcbba2 Mon Sep 17 00:00:00 2001 From: blondie7575 Date: Fri, 4 Aug 2023 19:37:09 -0700 Subject: [PATCH] Better clamping for terrain chunk compiling --- projectile.s | 2 +- terrain.s | 21 ++++++++++++++++----- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/projectile.s b/projectile.s index 710e86b..67cb1c7 100644 --- a/projectile.s +++ b/projectile.s @@ -939,7 +939,7 @@ processTerrainImpactStoreContinue: adc projectileTypes+PT_RADIUS,y adc #GAMEOBJECTWIDTH sta compileTerrainRowEnd -;don't forget to clamp these to terrain edges' + lda projectileTypes+PT_RADIUS,y tay phy ; We'll need the radius in a moment diff --git a/terrain.s b/terrain.s index dce122e..b500cca 100644 --- a/terrain.s +++ b/terrain.s @@ -295,12 +295,19 @@ compileTerrainDone: ; Trashes A,Y, SCRATCHL, PARAML0, PARAML1 ; compileTerrainChunk: - ldy #0 - tya ; Be extra safe and make sure Y is never negative or we'll spray RAM with terrain data + + ; Clamp chunk to left and right terrain edges + lda compileTerrainRowStart bmi compileTerrainChunkClampZero - ldx #MAXTERRAINHEIGHT-1 + +compileTerrainChunkClampResume: + lda compileTerrainRowEnd + cmp #TERRAINWIDTH + bcs compileTerrainChunkClampHigh compileTerrainChunkResume: + ldy #0 + ldx #MAXTERRAINHEIGHT-1 stx SCRATCHL sty PARAML0 @@ -329,9 +336,13 @@ compileTerrainChunkDone: rts compileTerrainChunkClampZero: - ldy #0 - bra compileTerrainChunkResume + stz compileTerrainRowStart + bra compileTerrainChunkClampResume +compileTerrainChunkClampHigh: + lda #TERRAINWIDTH-1 + sta compileTerrainRowEnd + bra compileTerrainChunkResume ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; compileTerrainRow