diff options
| -rw-r--r-- | engine/slop_menu.asm | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/engine/slop_menu.asm b/engine/slop_menu.asm index 7e534015..4c93e2ed 100644 --- a/engine/slop_menu.asm +++ b/engine/slop_menu.asm @@ -275,6 +275,7 @@ SlopExploreShared: ld a, $ff ld [wUpdateSpritesEnabled], a call ClearSprites + call SlopClampCoords ; a cross can land outside the new map -> clamp call SlopExploreRenderBG ; fresh render to vBGMap0, hardware scroll reset .renderArrows call LoadFontTilePatterns ; arrow glyphs ($ed/$ee) into VRAM for the OBJ layer @@ -616,6 +617,38 @@ SlopExploreShared: and a ; carry clear -> back to SL0P menu ret +; Clamp wYCoord to [0,maxY] and wXCoord to [0,maxX] of the current map. Crossing a +; connection applies its alignment offset blindly, so at an edge position the +; connection doesn't span the camera can land outside the neighbour; rendering +; that reads past wOverworldMap into other WRAM = on-screen garbage. +SlopClampCoords: + ld a, [wCurrentMapHeight2] + dec a + ld b, a ; maxY + ld a, [wYCoord] + call .clamp + ld [wYCoord], a + ld a, [wCurrentMapWidth2] + dec a + ld b, a ; maxX + ld a, [wXCoord] + call .clamp + ld [wXCoord], a + ret +; a = coord, b = max -> a clamped to [0,max]. Out-of-range values >= $80 are +; treated as "past the near edge" (negative) and clamped to 0, otherwise to max. +.clamp + cp b + ret c + ret z + bit 7, a + jr nz, .zero + ld a, b + ret +.zero + xor a + ret + ; wCurrentTileBlockMapViewPointer = wOverworldMap + (wYCoord/2 + 1)*stride + wXCoord/2 SlopSetViewPtr: ld a, [wCurMapWidth] |
