aboutsummaryrefslogtreecommitdiffstats
path: root/home
diff options
context:
space:
mode:
authorNarishma-gb <194818981+Narishma-gb@users.noreply.github.com>2025-11-18 21:17:31 +0100
committerGitHub <noreply@github.com>2025-11-18 15:17:31 -0500
commitf3326786259f4e53c06b7565369add7605bea8ba (patch)
tree1e09025ed19a6403fa74c408aa195662178cc0ca /home
parentAdd `_vc` patch targets to `.PHONY` (diff)
downloadpokeyellow-f3326786259f4e53c06b7565369add7605bea8ba.tar.gz
pokeyellow-f3326786259f4e53c06b7565369add7605bea8ba.tar.xz
pokeyellow-f3326786259f4e53c06b7565369add7605bea8ba.zip
Use more hardware and graphics constants (#532)
- Use `OBJ_SIZE` and `TILE_SIZE` from hardware.inc. - `SPRITESTATEDATA1_LENGTH`, `NUM_SPRITESTATEDATA_STRUCTS` and `TILE_1BPP_SIZE` are used in some places. - Highlight an oversight in `OakSpeech` where several direct MBC bank switches are requested. - Remove redundant comments in home/overworld.asm. - Add unreferenced `FillBgMap` function to avoid a byte of dead code. - Some constants added in wram.asm. - Correctly separate the commented code in `SaveMainData`.
Diffstat (limited to 'home')
-rw-r--r--home/clear_sprites.asm8
-rw-r--r--home/load_font.asm6
-rw-r--r--home/overworld.asm38
-rw-r--r--home/pics.asm10
-rw-r--r--home/reset_player_sprite.asm3
-rw-r--r--home/text_script.asm4
-rw-r--r--home/vcopy.asm29
7 files changed, 52 insertions, 46 deletions
diff --git a/home/clear_sprites.asm b/home/clear_sprites.asm
index 6d1066fa..c18b1ff3 100644
--- a/home/clear_sprites.asm
+++ b/home/clear_sprites.asm
@@ -9,10 +9,10 @@ ClearSprites::
ret
HideSprites::
- ld a, 160
- ld hl, wShadowOAM
- ld de, 4
- ld b, 40
+ ld a, SCREEN_HEIGHT_PX + OAM_Y_OFS
+ ld hl, wShadowOAMSprite00YCoord
+ ld de, OBJ_SIZE
+ ld b, OAM_COUNT
.loop
ld [hl], a
add hl, de
diff --git a/home/load_font.asm b/home/load_font.asm
index e886f76e..47ad60f1 100644
--- a/home/load_font.asm
+++ b/home/load_font.asm
@@ -11,7 +11,7 @@ LoadFontTilePatterns::
.on
ld de, FontGraphics
ld hl, vFont
- lb bc, BANK(FontGraphics), (FontGraphicsEnd - FontGraphics) / $8
+ lb bc, BANK(FontGraphics), (FontGraphicsEnd - FontGraphics) / TILE_1BPP_SIZE
jp CopyVideoDataDouble ; if LCD is on, transfer during V-blank
LoadTextBoxTilePatterns::
@@ -27,7 +27,7 @@ LoadTextBoxTilePatterns::
.on
ld de, TextBoxGraphics
ld hl, vChars2 tile $60
- lb bc, BANK(TextBoxGraphics), (TextBoxGraphicsEnd - TextBoxGraphics) / $10
+ lb bc, BANK(TextBoxGraphics), (TextBoxGraphicsEnd - TextBoxGraphics) / TILE_SIZE
jp CopyVideoData ; if LCD is on, transfer during V-blank
LoadHpBarAndStatusTilePatterns::
@@ -43,5 +43,5 @@ LoadHpBarAndStatusTilePatterns::
.on
ld de, HpBarAndStatusGraphics
ld hl, vChars2 tile $62
- lb bc, BANK(HpBarAndStatusGraphics), (HpBarAndStatusGraphicsEnd - HpBarAndStatusGraphics) / $10
+ lb bc, BANK(HpBarAndStatusGraphics), (HpBarAndStatusGraphicsEnd - HpBarAndStatusGraphics) / TILE_SIZE
jp CopyVideoData ; if LCD is on, transfer during V-blank
diff --git a/home/overworld.asm b/home/overworld.asm
index 5af527c0..f837815b 100644
--- a/home/overworld.asm
+++ b/home/overworld.asm
@@ -119,7 +119,7 @@ OverworldLoopLessDelay::
ld [wDestinationMap], a
call PrepareForSpecialWarp
ld a, [wCurMap]
- call SwitchToMapRomBank ; switch to the ROM bank of the current map
+ call SwitchToMapRomBank
ld hl, wCurMapTileset
set BIT_NO_PREVIOUS_MAP, [hl]
.changeMap
@@ -506,7 +506,7 @@ WarpFound2::
; for maps that can have the 0xFF destination map, which means to return to the outside map
; not all these maps are necessarily indoors, though
.indoorMaps
- ldh a, [hWarpDestinationMap] ; destination map
+ ldh a, [hWarpDestinationMap]
cp LAST_MAP
jr z, .goBackOutside
; if not going back to the previous map
@@ -567,7 +567,7 @@ CheckMapConnections::
srl c
jr z, .savePointer1
.pointerAdjustmentLoop1
- ld a, [wWestConnectedMapWidth] ; width of connected map
+ ld a, [wWestConnectedMapWidth]
add MAP_BORDER * 2
ld e, a
ld d, 0
@@ -584,7 +584,7 @@ CheckMapConnections::
.checkEastMap
ld b, a
- ld a, [wCurrentMapWidth2] ; map width
+ ld a, [wCurrentMapWidth2]
cp b
jr nz, .checkNorthMap
ld a, [wEastConnectedMap]
@@ -1171,7 +1171,7 @@ IsSpriteInFrontOfPlayer2::
ld a, PLAYER_DIR_LEFT
.doneCheckingDirection
ld [wPlayerDirection], a
- ld a, [wNumSprites] ; number of sprites
+ ld a, [wNumSprites]
and a
ret z
; if there are sprites
@@ -1198,7 +1198,7 @@ IsSpriteInFrontOfPlayer2::
.nextSprite
pop hl
ld a, l
- add $10
+ add SPRITESTATEDATA1_LENGTH
ld l, a
inc e
dec d
@@ -1258,8 +1258,8 @@ CollisionCheckOnLand::
; function that checks if the tile in front of the player is passable
; clears carry if it is, sets carry if not
CheckTilePassable::
- predef GetTileAndCoordsInFrontOfPlayer ; get tile in front of player
- ld a, [wTileInFrontOfPlayer] ; tile in front of player
+ predef GetTileAndCoordsInFrontOfPlayer
+ ld a, [wTileInFrontOfPlayer]
ld c, a
ld hl, wTilesetCollisionPtr ; pointer to list of passable tiles
ld a, [hli]
@@ -1282,7 +1282,7 @@ CheckTilePassable::
; sets carry if there is a collision and unsets carry if not
CheckForJumpingAndTilePairCollisions::
push hl
- predef GetTileAndCoordsInFrontOfPlayer ; get the tile in front of the player
+ predef GetTileAndCoordsInFrontOfPlayer
push de
push bc
farcall HandleLedges ; check if the player is trying to jump a ledge
@@ -1315,7 +1315,7 @@ CheckForTilePairCollisions::
inc hl
jr .tilePairCollisionLoop
.tilesetMatches
- ld a, [wTilePlayerStandingOn] ; tile the player is on
+ ld a, [wTilePlayerStandingOn]
ld b, a
ld a, [hl]
cp b
@@ -1350,9 +1350,9 @@ INCLUDE "data/tilesets/pair_collision_tile_ids.asm"
LoadCurrentMapView::
ldh a, [hLoadedROMBank]
push af
- ld a, [wTilesetBank] ; tile data ROM bank
+ ld a, [wTilesetBank]
ldh [hLoadedROMBank], a
- ld [rROMB], a ; switch to ROM bank that contains tile data
+ ld [rROMB], a
ld a, [wCurrentTileBlockMapViewPointer] ; address of upper left corner of current map view
ld e, a
ld a, [wCurrentTileBlockMapViewPointer + 1]
@@ -1434,7 +1434,7 @@ LoadCurrentMapView::
jr nz, .rowLoop2
pop af
ldh [hLoadedROMBank], a
- ld [rROMB], a ; restore previous ROM bank
+ ld [rROMB], a
ret
AdvancePlayerSprite::
@@ -1442,7 +1442,7 @@ AdvancePlayerSprite::
ld b, a
ld a, [wSpritePlayerStateData1XStepVector]
ld c, a
- ld hl, wWalkCounter ; walking animation counter
+ ld hl, wWalkCounter
dec [hl]
jr nz, .afterUpdateMapCoords
; if it's the end of the animation, update the player's map coordinates
@@ -1453,7 +1453,7 @@ AdvancePlayerSprite::
add c
ld [wXCoord], a
.afterUpdateMapCoords
- ld a, [wWalkCounter] ; walking animation counter
+ ld a, [wWalkCounter]
cp $07
jp nz, .scrollBackgroundAndSprites
; if this is the first iteration of the animation
@@ -1612,7 +1612,7 @@ AdvancePlayerSprite::
; shift all the sprites in the direction opposite of the player's motion
; so that the player appears to move relative to them
ld hl, wSprite01StateData1YPixels
- ld a, [wNumSprites] ; number of sprites
+ ld a, [wNumSprites]
and a ; are there any sprites?
jr z, .done
ld e, a
@@ -2151,8 +2151,8 @@ LoadMapHeader::
jr nz, .zeroSpriteDataLoop
; disable SPRITESTATEDATA1_IMAGEINDEX (set to $ff) for sprites 01-15
ld hl, wSprite01StateData1ImageIndex
- ld de, $10
- ld c, $0f
+ ld de, SPRITESTATEDATA1_LENGTH
+ ld c, NUM_SPRITESTATEDATA_STRUCTS - 1
.disableSpriteEntriesLoop
ld [hl], $ff
add hl, de
@@ -2296,7 +2296,7 @@ LoadMapData::
ldh a, [hLoadedROMBank]
push af
call DisableLCD
- ld a, $98
+ ld a, HIGH(vBGMap0)
ld [wMapViewVRAMPointer + 1], a
xor a
ld [wMapViewVRAMPointer], a
diff --git a/home/pics.asm b/home/pics.asm
index ea34e3d5..475e834d 100644
--- a/home/pics.asm
+++ b/home/pics.asm
@@ -127,8 +127,8 @@ AlignSpriteDataCentered::
dec c
jr nz, .columnInnerLoop
pop hl
- ld bc, 7*8 ; 7 tiles
- add hl, bc ; advance one full column
+ ld bc, 7 * TILE_1BPP_SIZE
+ add hl, bc ; advance one full column
pop af
dec a
jr nz, .columnLoop
@@ -156,7 +156,7 @@ InterlaceMergeSpriteBuffers::
ld hl, sSpriteBuffer2 + (SPRITEBUFFERSIZE - 1) ; destination: end of buffer 2
ld de, sSpriteBuffer1 + (SPRITEBUFFERSIZE - 1) ; source 2: end of buffer 1
ld bc, sSpriteBuffer0 + (SPRITEBUFFERSIZE - 1) ; source 1: end of buffer 0
- ld a, SPRITEBUFFERSIZE/2 ; $c4
+ ld a, SPRITEBUFFERSIZE / 2
ldh [hSpriteInterlaceCounter], a
.interlaceLoop
ld a, [de]
@@ -178,7 +178,7 @@ InterlaceMergeSpriteBuffers::
ld a, [wSpriteFlipped]
and a
jr z, .notFlipped
- ld bc, 2*SPRITEBUFFERSIZE
+ ld bc, 2 * SPRITEBUFFERSIZE
ld hl, sSpriteBuffer1
.swapLoop
swap [hl] ; if flipped swap nybbles in all bytes
@@ -190,7 +190,7 @@ InterlaceMergeSpriteBuffers::
.notFlipped
pop hl
ld de, sSpriteBuffer1
- ld c, (2*SPRITEBUFFERSIZE)/16 ; $31, number of 16 byte chunks to be copied
+ ld c, (2 * SPRITEBUFFERSIZE) / TILE_SIZE ; $31, number of 16 byte chunks to be copied
ldh a, [hLoadedROMBank]
ld b, a
jp CopyVideoData
diff --git a/home/reset_player_sprite.asm b/home/reset_player_sprite.asm
index 72df31a1..6ce4a6fa 100644
--- a/home/reset_player_sprite.asm
+++ b/home/reset_player_sprite.asm
@@ -15,6 +15,7 @@ ResetPlayerSpriteData::
; overwrites sprite data with zeroes
ResetPlayerSpriteData_ClearSpriteData::
- ld bc, $10
+ ld bc, SPRITESTATEDATA1_LENGTH
+ ASSERT SPRITESTATEDATA2_LENGTH == SPRITESTATEDATA1_LENGTH
xor a
jp FillMemory
diff --git a/home/text_script.asm b/home/text_script.asm
index 389f2499..36f6338b 100644
--- a/home/text_script.asm
+++ b/home/text_script.asm
@@ -113,8 +113,8 @@ CloseTextDisplay::
ldh [hAutoBGTransferEnabled], a ; disable continuous WRAM to VRAM transfer each V-blank
; loop to make sprites face the directions they originally faced before the dialogue
ld hl, wSprite01StateData2OrigFacingDirection
- ld c, $0f
- ld de, $10
+ ld c, NUM_SPRITESTATEDATA_STRUCTS - 1
+ ld de, SPRITESTATEDATA1_LENGTH
.restoreSpriteFacingDirectionLoop
ld a, [hl] ; x#SPRITESTATEDATA2_ORIGFACINGDIRECTION
dec h
diff --git a/home/vcopy.asm b/home/vcopy.asm
index 8ae9484a..cf4c3e6c 100644
--- a/home/vcopy.asm
+++ b/home/vcopy.asm
@@ -20,9 +20,14 @@ GetRowColAddressBgMap::
; INPUT: h - high byte of background tile map address in VRAM
ClearBgMap::
ld a, ' '
- jr .next
+ jr FillBgMapCommon
+
+; fills a VRAM background map with tile index in register l
+; INPUT: h - high byte of background tile map address in VRAM
+FillBgMap:: ; unreferenced
ld a, l
-.next
+
+FillBgMapCommon:
ld de, TILEMAP_AREA
ld l, e
.loop
@@ -69,8 +74,8 @@ RedrawRowOrColumn::
.noCarry
; the following 4 lines wrap us from bottom to top if necessary
ld a, d
- and $3
- or $98
+ and HIGH(TILEMAP_AREA - 1)
+ or HIGH(vBGMap0)
ld d, a
dec c
jr nz, .loop1
@@ -86,7 +91,7 @@ RedrawRowOrColumn::
push de
call .DrawHalf ; draw upper half
pop de
- ld a, TILEMAP_WIDTH ; width of VRAM background map
+ ld a, TILEMAP_WIDTH
add e
ld e, a
; fall through and draw lower half
@@ -102,10 +107,10 @@ RedrawRowOrColumn::
ld a, e
inc a
; the following 6 lines wrap us from the right edge to the left edge if necessary
- and $1f
+ and %11111
ld b, a
ld a, e
- and $e0
+ and %11100000
or b
ld e, a
dec c
@@ -134,7 +139,7 @@ AutoBgMapTransfer::
dec a
jr z, .transferMiddleThird
.transferBottomThird
- hlcoord 0, 12
+ hlcoord 0, 2 * SCREEN_HEIGHT / 3
ld sp, hl
ldh a, [hAutoBGTransferDest + 1]
ld h, a
@@ -154,7 +159,7 @@ AutoBgMapTransfer::
ld a, TRANSFERMIDDLE
jr .doTransfer
.transferMiddleThird
- hlcoord 0, 6
+ hlcoord 0, SCREEN_HEIGHT / 3
ld sp, hl
ldh a, [hAutoBGTransferDest + 1]
ld h, a
@@ -165,7 +170,7 @@ AutoBgMapTransfer::
ld a, TRANSFERBOTTOM
.doTransfer
ldh [hAutoBGTransferPortion], a ; store next portion
- ld b, 6
+ ld b, SCREEN_HEIGHT / 3
TransferBgRows::
; unrolled loop and using pop for speed
@@ -390,7 +395,7 @@ UpdateMovingBgTiles::
; water
ld hl, vTileset tile $14
- ld c, $10
+ ld c, TILE_SIZE
ld a, [wMovingBGTilesCounter2]
inc a
@@ -435,7 +440,7 @@ UpdateMovingBgTiles::
ld hl, FlowerTile3
.copy
ld de, vTileset tile $03
- ld c, $10
+ ld c, TILE_SIZE
.loop
ld a, [hli]
ld [de], a