aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAsh Ketchum <no-reply@sl0p.foo>2026-07-15 11:56:20 +0200
committerAsh Ketchum <no-reply@sl0p.foo>2026-07-15 11:56:20 +0200
commit89259e35e7d2105f5e85d3f813dc2cb522a7d277 (patch)
treecaefbe3df5b505fbc8623e0e8082d46ebc066c20
parentexplore (P1): direction markers for legit connections (diff)
downloadpokeyellow-89259e35e7d2105f5e85d3f813dc2cb522a7d277.tar.gz
pokeyellow-89259e35e7d2105f5e85d3f813dc2cb522a7d277.tar.xz
pokeyellow-89259e35e7d2105f5e85d3f813dc2cb522a7d277.zip
explore: fix map rendering (compute the view pointer ourselves)
Root cause of the 'maps look wrong' bug: LoadMapData renders the view from wCurrentTileBlockMapViewPointer, which the engine ONLY ever sets from warp / connection / walk data (LoadDestinationWarpPosition, the connected-map handler, advance_player_sprite) -- never from wXCoord/wYCoord. My old code set coords and called LoadMapData, so every map was drawn from a STALE pointer left over from the previous map: arbitrary, inconsistent windows. Fix: after LoadMapData loads the block map into wOverworldMap, compute a centered pointer directly -- stride = wCurMapWidth + MAP_BORDER*2 ptr = wOverworldMap + (height/2 + 1)*stride + width/2 -- clear wYBlockCoord/wXBlockCoord, and call LoadCurrentMapView to redraw. On exit, save/restore the origin's real view pointer (+ block coords) before reloading so the overworld comes back correctly. Verified by DFS-traversing the whole connection graph and stitching 36 centered maps into a coherent Kanto overworld image.
-rw-r--r--engine/slop_menu.asm63
1 files changed, 51 insertions, 12 deletions
diff --git a/engine/slop_menu.asm b/engine/slop_menu.asm
index 69ec2142..fcac7d10 100644
--- a/engine/slop_menu.asm
+++ b/engine/slop_menu.asm
@@ -227,21 +227,51 @@ SlopExplore:
ld b, a
ld a, [wXCoord]
ld c, a
- push bc
+ push bc ; origin Y,X
+ ld a, [wCurrentTileBlockMapViewPointer]
+ ld b, a
+ ld a, [wCurrentTileBlockMapViewPointer + 1]
+ ld c, a
+ push bc ; origin view pointer
ld a, [wCurMap]
- push af
+ push af ; origin map
.render
-; seed safe coords (0,0 is in-bounds for any map), load the map to get its real
-; dimensions + connections, then re-render centered on the map.
- xor a
- ld [wYCoord], a
- ld [wXCoord], a
+; LoadMapData loads the map header + block map into wOverworldMap, but it renders
+; using a STALE wCurrentTileBlockMapViewPointer -- the game only ever sets that
+; from warp / connection / walk data, never from wXCoord/wYCoord. So load the
+; map, then compute a centered view pointer ourselves and redraw the view.
call LoadMapData
+; stride = wCurMapWidth + MAP_BORDER*2 ; bufRow = height/2 + 1 ; bufCol = width/2
+; wCurrentTileBlockMapViewPointer = wOverworldMap + bufRow*stride + bufCol
+ ld a, [wCurMapWidth]
+ add MAP_BORDER * 2
+ ld c, a
+ ld b, 0 ; bc = row stride (blocks)
+ ld hl, 0
ld a, [wCurMapHeight]
- ld [wYCoord], a
+ srl a
+ inc a ; bufRow (>= 1)
+.viewRowLoop
+ add hl, bc
+ dec a
+ jr nz, .viewRowLoop
ld a, [wCurMapWidth]
- ld [wXCoord], a
- call LoadMapData ; render centered
+ srl a ; bufCol = width/2
+ add l
+ ld l, a
+ jr nc, .viewNoCarry
+ inc h
+.viewNoCarry
+ ld bc, wOverworldMap
+ add hl, bc
+ ld a, l
+ ld [wCurrentTileBlockMapViewPointer], a
+ ld a, h
+ ld [wCurrentTileBlockMapViewPointer + 1], a
+ xor a
+ ld [wYBlockCoord], a
+ ld [wXBlockCoord], a
+ call LoadCurrentMapView ; redraw wTileMap centered on the map
ldh a, [rLCDC] ; hide ALL sprites (player + actors) via LCDC
res B_LCDC_OBJS, a
ldh [rLCDC], a
@@ -318,12 +348,21 @@ SlopExplore:
.exit
pop af
ld [wCurMap], a ; restore origin map
- pop bc
+ pop bc ; restore origin view pointer
+ ld a, b
+ ld [wCurrentTileBlockMapViewPointer], a
+ ld a, c
+ ld [wCurrentTileBlockMapViewPointer + 1], a
+ pop bc ; restore origin Y,X
ld a, b
ld [wYCoord], a
+ and $1
+ ld [wYBlockCoord], a
ld a, c
ld [wXCoord], a
- call LoadMapData ; reload the origin map
+ and $1
+ ld [wXBlockCoord], a
+ call LoadMapData ; reload origin, rendered from the restored pointer
and a ; carry clear -> back to SL0P menu
ret