Skip to content

Commit

Permalink
Correct wTileMapBackup declared space (#487)
Browse files Browse the repository at this point in the history
  • Loading branch information
Engezerstorung authored Jan 28, 2025
1 parent f023c68 commit 96fc617
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 32 deletions.
7 changes: 7 additions & 0 deletions constants/gfx_constants.asm
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ DEF SCREEN_HEIGHT_PX EQU SCREEN_HEIGHT * TILE_WIDTH ; pixels
DEF BG_MAP_WIDTH EQU 32 ; tiles
DEF BG_MAP_HEIGHT EQU 32 ; tiles

DEF BLOCK_WIDTH EQU 4 ; tiles
DEF BLOCK_HEIGHT EQU BLOCK_WIDTH ; tiles
DEF SCREEN_BLOCK_WIDTH EQU 6 ; blocks
DEF SCREEN_BLOCK_HEIGHT EQU 5 ; blocks
DEF SURROUNDING_WIDTH EQU SCREEN_BLOCK_WIDTH * BLOCK_WIDTH ; tiles
DEF SURROUNDING_HEIGHT EQU SCREEN_BLOCK_HEIGHT * BLOCK_HEIGHT ; tiles

DEF SPRITEBUFFERSIZE EQU 7 * 7 * LEN_1BPP_TILE

; HP bar
Expand Down
24 changes: 12 additions & 12 deletions engine/items/town_map.asm
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ DisplayTownMap:
hlcoord 1, 0
ld de, wNameBuffer
call PlaceString
ld hl, wShadowOAM
ld de, wTileMapBackup
ld bc, $10
ld hl, wShadowOAMSprite00
ld de, wShadowOAMBackupSprite00
ld bc, 4 * 4
call CopyData
ld hl, vSprites tile BIRD_BASE_TILE
ld de, TownMapCursor
Expand Down Expand Up @@ -63,8 +63,8 @@ DisplayTownMap:
ld de, wNameBuffer
call PlaceString
ld hl, wShadowOAMSprite04
ld de, wTileMapBackup + 16
ld bc, $10
ld de, wShadowOAMBackupSprite04
ld bc, 4 * 4
call CopyData
.inputLoop
call TownMapSpriteBlinkingAnimation
Expand Down Expand Up @@ -366,8 +366,8 @@ DrawPlayerOrBirdSprite:
cp "@"
jr nz, .loop
ld hl, wShadowOAM
ld de, wTileMapBackup
ld bc, $a0
ld de, wShadowOAMBackup
ld bc, NUM_SPRITE_OAM_STRUCTS * 4
jp CopyData

DisplayWildLocations:
Expand Down Expand Up @@ -414,8 +414,8 @@ DisplayWildLocations:
call DrawPlayerOrBirdSprite
.done
ld hl, wShadowOAM
ld de, wTileMapBackup
ld bc, $a0
ld de, wShadowOAMBackup
ld bc, NUM_SPRITE_OAM_STRUCTS * 4
jp CopyData

AreaUnknownText:
Expand Down Expand Up @@ -602,15 +602,15 @@ TownMapSpriteBlinkingAnimation::
cp 50
jr nz, .done
; show sprites when the counter reaches 50
ld hl, wTileMapBackup
ld hl, wShadowOAMBackup
ld de, wShadowOAM
ld bc, $90
ld bc, (NUM_SPRITE_OAM_STRUCTS - 4) * 4
call CopyData
xor a
jr .done
.hideSprites
ld hl, wShadowOAM
ld b, $24
ld b, NUM_SPRITE_OAM_STRUCTS - 4
ld de, $4
.hideSpritesLoop
ld [hl], $a0
Expand Down
32 changes: 14 additions & 18 deletions home/overworld.asm
Original file line number Diff line number Diff line change
Expand Up @@ -1357,12 +1357,12 @@ LoadCurrentMapView::
ld e, a
ld a, [wCurrentTileBlockMapViewPointer + 1]
ld d, a
ld hl, wTileMapBackup
ld b, $05
ld hl, wSurroundingTiles
ld b, SCREEN_BLOCK_HEIGHT
.rowLoop ; each loop iteration fills in one row of tile blocks
push hl
push de
ld c, $06
ld c, SCREEN_BLOCK_WIDTH
.rowInnerLoop ; loop to draw each tile block of the current row
push bc
push de
Expand Down Expand Up @@ -1391,27 +1391,27 @@ LoadCurrentMapView::
.noCarry
; update tile map pointer to next row's address
pop hl
ld a, $60
ld a, SURROUNDING_WIDTH * BLOCK_HEIGHT
add l
ld l, a
jr nc, .noCarry2
inc h
.noCarry2
dec b
jr nz, .rowLoop
ld hl, wTileMapBackup
ld bc, $0
ld hl, wSurroundingTiles
ld bc, 0
.adjustForYCoordWithinTileBlock
ld a, [wYBlockCoord]
and a
jr z, .adjustForXCoordWithinTileBlock
ld bc, $30
ld bc, SURROUNDING_WIDTH * 2
add hl, bc
.adjustForXCoordWithinTileBlock
ld a, [wXBlockCoord]
and a
jr z, .copyToVisibleAreaBuffer
ld bc, $2
ld bc, BLOCK_WIDTH / 2
add hl, bc
.copyToVisibleAreaBuffer
decoord 0, 0 ; base address for the tiles that are directly transferred to VRAM during V-blank
Expand All @@ -1424,7 +1424,7 @@ LoadCurrentMapView::
inc de
dec c
jr nz, .rowInnerLoop2
ld a, $04
ld a, SURROUNDING_WIDTH - SCREEN_WIDTH
add l
ld l, a
jr nc, .noCarry3
Expand Down Expand Up @@ -1755,7 +1755,7 @@ ScheduleColumnRedrawHelper::
ld a, [hl]
ld [de], a
inc de
ld a, 19
ld a, SCREEN_WIDTH - 1
add l
ld l, a
jr nc, .noCarry
Expand Down Expand Up @@ -1796,22 +1796,18 @@ DrawTileBlock::
ld d, h
ld e, l ; de = address of the tile block's tiles
pop hl
ld c, $04 ; 4 loop iterations
ld c, BLOCK_HEIGHT ; 4 loop iterations
.loop ; each loop iteration, write 4 tile numbers
push bc
REPT BLOCK_WIDTH - 1
ld a, [de]
ld [hli], a
inc de
ld a, [de]
ld [hli], a
inc de
ld a, [de]
ld [hli], a
inc de
ENDR
ld a, [de]
ld [hl], a
inc de
ld bc, $15
ld bc, SURROUNDING_WIDTH - (BLOCK_WIDTH - 1)
add hl, bc
pop bc
dec c
Expand Down
15 changes: 13 additions & 2 deletions ram/wram.asm
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,19 @@ UNION
; (e.g. if menus are drawn on top)
wTileMapBackup:: ds SCREEN_WIDTH * SCREEN_HEIGHT

NEXTU
; buffer for the blocks surrounding the player (6 columns by 5 rows of 4x4-tile blocks)
wSurroundingTiles:: ds SURROUNDING_WIDTH * SURROUNDING_HEIGHT

NEXTU
; buffer for temporarily saving and restoring shadow OAM
wShadowOAMBackup::
; wShadowOAMBackupSprite00 - wShadowOAMBackupSprite39
FOR n, NUM_SPRITE_OAM_STRUCTS
wShadowOAMBackupSprite{02d:n}:: sprite_oam_struct wShadowOAMBackupSprite{02d:n}
ENDR
wShadowOAMBackupEnd::

NEXTU
; list of indexes to patch with SERIAL_NO_DATA_BYTE after transfer
wSerialPartyMonsPatchList:: ds 200
Expand All @@ -169,8 +182,6 @@ wSerialPartyMonsPatchList:: ds 200
wSerialEnemyMonsPatchList:: ds 200
ENDU

ds 80


SECTION "Overworld Map", WRAM0

Expand Down

0 comments on commit 96fc617

Please sign in to comment.