ref: d2be79adf1c366b28821817cefaab9066668b205
parent: fa7d76f39ef2ca94f1b4a1ba01039f748664f523
author: Rangi <[email protected]>
date: Sat Sep 24 07:30:29 EDT 2022
Add constants and table macros for the map sprite sets (#392) Fixes #391
--- a/constants.asm
+++ b/constants.asm
@@ -28,6 +28,7 @@
INCLUDE "constants/map_data_constants.asm"
INCLUDE "constants/map_object_constants.asm"
INCLUDE "constants/hide_show_constants.asm"
+INCLUDE "constants/sprite_set_constants.asm"
INCLUDE "constants/credits_constants.asm"
INCLUDE "constants/audio_constants.asm"
INCLUDE "constants/music_constants.asm"
--- /dev/null
+++ b/constants/sprite_set_constants.asm
@@ -1,0 +1,38 @@
+; sprite set ids
+; indexes for SpriteSets (see data/maps/sprite_sets.asm)
+; values for MapSpriteSets and SplitMapSpriteSets (see data/maps/sprite_sets.asm)
+ const_def 1
+ const SPRITESET_PALLET_VIRIDIAN ; 01
+ const SPRITESET_PEWTER_CERULEAN ; 02
+ const SPRITESET_LAVENDER ; 03
+ const SPRITESET_VERMILION ; 04
+ const SPRITESET_CELADON ; 05
+ const SPRITESET_INDIGO ; 06
+ const SPRITESET_SAFFRON ; 07
+ const SPRITESET_SILENCE_BRIDGE ; 08
+ const SPRITESET_CYCLING_ROAD ; 09
+ const SPRITESET_FUCHSIA ; 0a
+DEF NUM_SPRITE_SETS EQU const_value - 1
+
+; split sprite set ids
+; indexes for SplitMapSpriteSets (see data/maps/sprite_sets.asm)
+; values for MapSpriteSets (see data/maps/sprite_sets.asm)
+ const_next $f1
+DEF FIRST_SPLIT_SET EQU const_value
+ const SPLITSET_ROUTE_2 ; f1
+ const SPLITSET_ROUTE_10 ; f2
+ const SPLITSET_ROUTE_11 ; f3
+ const SPLITSET_ROUTE_12 ; f4
+ const SPLITSET_ROUTE_15 ; f5
+ const SPLITSET_ROUTE_16 ; f6
+ const SPLITSET_ROUTE_18 ; f7
+ const SPLITSET_ROUTE_20 ; f8
+ const SPLITSET_ROUTE_5 ; f9
+ const SPLITSET_ROUTE_6 ; fa
+ const SPLITSET_ROUTE_7 ; fb
+ const SPLITSET_ROUTE_8 ; fc
+DEF NUM_SPLIT_SETS EQU const_value - FIRST_SPLIT_SET
+
+; split directions
+DEF EAST_WEST EQU 1
+DEF NORTH_SOUTH EQU 2
--- a/data/maps/sprite_sets.asm
+++ b/data/maps/sprite_sets.asm
@@ -1,73 +1,72 @@
+; Valid sprite IDs for each outdoor map.
+
MapSpriteSets:
table_width 1, MapSpriteSets
- db $01 ; PALLET_TOWN
- db $01 ; VIRIDIAN_CITY
- db $02 ; PEWTER_CITY
- db $02 ; CERULEAN_CITY
- db $03 ; LAVENDER_TOWN
- db $04 ; VERMILION_CITY
- db $05 ; CELADON_CITY
- db $0a ; FUCHSIA_CITY
- db $01 ; CINNABAR_ISLAND
- db $06 ; INDIGO_PLATEAU
- db $07 ; SAFFRON_CITY
- db $01 ; unused map ID
- db $01 ; ROUTE_1
- db $f1 ; ROUTE_2
- db $02 ; ROUTE_3
- db $02 ; ROUTE_4
- db $f9 ; ROUTE_5
- db $fa ; ROUTE_6
- db $fb ; ROUTE_7
- db $fc ; ROUTE_8
- db $02 ; ROUTE_9
- db $f2 ; ROUTE_10
- db $f3 ; ROUTE_11
- db $f4 ; ROUTE_12
- db $08 ; ROUTE_13
- db $08 ; ROUTE_14
- db $f5 ; ROUTE_15
- db $f6 ; ROUTE_16
- db $09 ; ROUTE_17
- db $f7 ; ROUTE_18
- db $0a ; ROUTE_19
- db $f8 ; ROUTE_20
- db $01 ; ROUTE_21
- db $01 ; ROUTE_22
- db $06 ; ROUTE_23
- db $02 ; ROUTE_24
- db $02 ; ROUTE_25
+ db SPRITESET_PALLET_VIRIDIAN ; PALLET_TOWN
+ db SPRITESET_PALLET_VIRIDIAN ; VIRIDIAN_CITY
+ db SPRITESET_PEWTER_CERULEAN ; PEWTER_CITY
+ db SPRITESET_PEWTER_CERULEAN ; CERULEAN_CITY
+ db SPRITESET_LAVENDER ; LAVENDER_TOWN
+ db SPRITESET_VERMILION ; VERMILION_CITY
+ db SPRITESET_CELADON ; CELADON_CITY
+ db SPRITESET_FUCHSIA ; FUCHSIA_CITY
+ db SPRITESET_PALLET_VIRIDIAN ; CINNABAR_ISLAND
+ db SPRITESET_INDIGO ; INDIGO_PLATEAU
+ db SPRITESET_SAFFRON ; SAFFRON_CITY
+ db SPRITESET_PALLET_VIRIDIAN ; UNUSED_MAP_0B
+ db SPRITESET_PALLET_VIRIDIAN ; ROUTE_1
+ db SPLITSET_ROUTE_2 ; ROUTE_2
+ db SPRITESET_PEWTER_CERULEAN ; ROUTE_3
+ db SPRITESET_PEWTER_CERULEAN ; ROUTE_4
+ db SPLITSET_ROUTE_5 ; ROUTE_5
+ db SPLITSET_ROUTE_6 ; ROUTE_6
+ db SPLITSET_ROUTE_7 ; ROUTE_7
+ db SPLITSET_ROUTE_8 ; ROUTE_8
+ db SPRITESET_PEWTER_CERULEAN ; ROUTE_9
+ db SPLITSET_ROUTE_10 ; ROUTE_10
+ db SPLITSET_ROUTE_11 ; ROUTE_11
+ db SPLITSET_ROUTE_12 ; ROUTE_12
+ db SPRITESET_SILENCE_BRIDGE ; ROUTE_13
+ db SPRITESET_SILENCE_BRIDGE ; ROUTE_14
+ db SPLITSET_ROUTE_15 ; ROUTE_15
+ db SPLITSET_ROUTE_16 ; ROUTE_16
+ db SPRITESET_CYCLING_ROAD ; ROUTE_17
+ db SPLITSET_ROUTE_18 ; ROUTE_18
+ db SPRITESET_FUCHSIA ; ROUTE_19
+ db SPLITSET_ROUTE_20 ; ROUTE_20
+ db SPRITESET_PALLET_VIRIDIAN ; ROUTE_21
+ db SPRITESET_PALLET_VIRIDIAN ; ROUTE_22
+ db SPRITESET_INDIGO ; ROUTE_23
+ db SPRITESET_PEWTER_CERULEAN ; ROUTE_24
+ db SPRITESET_PEWTER_CERULEAN ; ROUTE_25
assert_table_length FIRST_INDOOR_MAP
-DEF EAST_WEST EQU 1
-DEF NORTH_SOUTH EQU 2
-
; Format:
-; 00: determines whether the map is split EAST_WEST or NORTH_SOUTH
-; 01: coordinate of dividing line
-; 02: sprite set ID if in the West or North side
-; 03: sprite set ID if in the East or South side
+; #1: whether the map is split EAST_WEST or NORTH_SOUTH
+; #2: coordinate of dividing line
+; #3: sprite set ID if on the west or north side
+; #4: sprite set ID if on the east or south side
SplitMapSpriteSets:
- db NORTH_SOUTH, 37, $02, $01 ; $f1
- db NORTH_SOUTH, 50, $02, $03 ; $f2
- db EAST_WEST, 57, $04, $08 ; $f3
- db NORTH_SOUTH, 21, $03, $08 ; $f4
- db EAST_WEST, 8, $0A, $08 ; $f5
- db EAST_WEST, 24, $09, $05 ; $f6
- db EAST_WEST, 34, $09, $0A ; $f7
- db EAST_WEST, 53, $01, $0A ; $f8
- db NORTH_SOUTH, 33, $02, $07 ; $f9
- db NORTH_SOUTH, 2, $07, $04 ; $fa
- db EAST_WEST, 17, $05, $07 ; $fb
- db EAST_WEST, 3, $07, $03 ; $fc
+ table_width 4, SplitMapSpriteSets
+ db NORTH_SOUTH, 37, SPRITESET_PEWTER_CERULEAN, SPRITESET_PALLET_VIRIDIAN ; SPLITSET_ROUTE_2
+ db NORTH_SOUTH, 50, SPRITESET_PEWTER_CERULEAN, SPRITESET_LAVENDER ; SPLITSET_ROUTE_10
+ db EAST_WEST, 57, SPRITESET_VERMILION, SPRITESET_SILENCE_BRIDGE ; SPLITSET_ROUTE_11
+ db NORTH_SOUTH, 21, SPRITESET_LAVENDER, SPRITESET_SILENCE_BRIDGE ; SPLITSET_ROUTE_12
+ db EAST_WEST, 8, SPRITESET_FUCHSIA, SPRITESET_SILENCE_BRIDGE ; SPLITSET_ROUTE_15
+ db EAST_WEST, 24, SPRITESET_CYCLING_ROAD, SPRITESET_CELADON ; SPLITSET_ROUTE_16
+ db EAST_WEST, 34, SPRITESET_CYCLING_ROAD, SPRITESET_FUCHSIA ; SPLITSET_ROUTE_18
+ db EAST_WEST, 53, SPRITESET_PALLET_VIRIDIAN, SPRITESET_FUCHSIA ; SPLITSET_ROUTE_20
+ db NORTH_SOUTH, 33, SPRITESET_PEWTER_CERULEAN, SPRITESET_SAFFRON ; SPLITSET_ROUTE_5
+ db NORTH_SOUTH, 2, SPRITESET_SAFFRON, SPRITESET_VERMILION ; SPLITSET_ROUTE_6
+ db EAST_WEST, 17, SPRITESET_CELADON, SPRITESET_SAFFRON ; SPLITSET_ROUTE_7
+ db EAST_WEST, 3, SPRITESET_SAFFRON, SPRITESET_LAVENDER ; SPLITSET_ROUTE_8
+ assert_table_length NUM_SPLIT_SETS
SpriteSets:
+ ; each sprite set has 9 walking sprites and 2 still sprites
+ table_width 9 + 2, SpriteSets
-; each sprite set has 9 walking sprites and 2 still sprites
-DEF SPRITE_SET_LENGTH EQU 9 + 2
-
-; sprite set $01
- table_width 1
+; SPRITESET_PALLET_VIRIDIAN
db SPRITE_BLUE
db SPRITE_YOUNGSTER
db SPRITE_GIRL
@@ -79,10 +78,8 @@
db SPRITE_SWIMMER
db SPRITE_POKE_BALL
db SPRITE_GAMBLER_ASLEEP
- assert_table_length SPRITE_SET_LENGTH
-; sprite set $02
- table_width 1
+; SPRITESET_PEWTER_CERULEAN
db SPRITE_YOUNGSTER
db SPRITE_ROCKET
db SPRITE_SUPER_NERD
@@ -94,10 +91,8 @@
db SPRITE_COOLTRAINER_M
db SPRITE_POKE_BALL
db SPRITE_UNUSED_GAMBLER_ASLEEP_2
- assert_table_length SPRITE_SET_LENGTH
-; sprite set $03
- table_width 1
+; SPRITESET_LAVENDER
db SPRITE_LITTLE_GIRL
db SPRITE_GIRL
db SPRITE_SUPER_NERD
@@ -109,10 +104,8 @@
db SPRITE_GUARD
db SPRITE_POKE_BALL
db SPRITE_UNUSED_GAMBLER_ASLEEP_2
- assert_table_length SPRITE_SET_LENGTH
-; sprite set $04
- table_width 1
+; SPRITESET_VERMILION
db SPRITE_BEAUTY
db SPRITE_SUPER_NERD
db SPRITE_YOUNGSTER
@@ -124,10 +117,8 @@
db SPRITE_COOLTRAINER_M
db SPRITE_POKE_BALL
db SPRITE_UNUSED_GAMBLER_ASLEEP_2
- assert_table_length SPRITE_SET_LENGTH
-; sprite set $05
- table_width 1
+; SPRITESET_CELADON
db SPRITE_LITTLE_GIRL
db SPRITE_LITTLE_BOY
db SPRITE_GIRL
@@ -139,10 +130,8 @@
db SPRITE_ROCKET
db SPRITE_POKE_BALL
db SPRITE_SNORLAX
- assert_table_length SPRITE_SET_LENGTH
-; sprite set $06
- table_width 1
+; SPRITESET_INDIGO
db SPRITE_YOUNGSTER
db SPRITE_GYM_GUIDE
db SPRITE_MONSTER
@@ -154,10 +143,8 @@
db SPRITE_GAMBLER
db SPRITE_POKE_BALL
db SPRITE_UNUSED_GAMBLER_ASLEEP_2
- assert_table_length SPRITE_SET_LENGTH
-; sprite set $07
- table_width 1
+; SPRITESET_SAFFRON
db SPRITE_ROCKET
db SPRITE_SCIENTIST
db SPRITE_SILPH_WORKER
@@ -169,10 +156,8 @@
db SPRITE_MONSTER
db SPRITE_POKE_BALL
db SPRITE_UNUSED_GAMBLER_ASLEEP_2
- assert_table_length SPRITE_SET_LENGTH
-; sprite set $08
- table_width 1
+; SPRITESET_SILENCE_BRIDGE
db SPRITE_BIKER
db SPRITE_SUPER_NERD
db SPRITE_MIDDLE_AGED_MAN
@@ -184,10 +169,8 @@
db SPRITE_MONSTER
db SPRITE_POKE_BALL
db SPRITE_SNORLAX
- assert_table_length SPRITE_SET_LENGTH
-; sprite set $09
- table_width 1
+; SPRITESET_CYCLING_ROAD
db SPRITE_BIKER
db SPRITE_COOLTRAINER_M
db SPRITE_SILPH_WORKER
@@ -199,10 +182,8 @@
db SPRITE_SUPER_NERD
db SPRITE_POKE_BALL
db SPRITE_SNORLAX
- assert_table_length SPRITE_SET_LENGTH
-; sprite set $0a
- table_width 1
+; SPRITESET_FUCHSIA
db SPRITE_BIRD
db SPRITE_COOLTRAINER_M
db SPRITE_FAIRY
@@ -214,4 +195,5 @@
db SPRITE_YOUNGSTER
db SPRITE_POKE_BALL
db SPRITE_FOSSIL
- assert_table_length SPRITE_SET_LENGTH
+
+ assert_table_length NUM_SPRITE_SETS
--- a/engine/overworld/map_sprites.asm
+++ b/engine/overworld/map_sprites.asm
@@ -11,7 +11,7 @@
InitMapSprites::
call InitOutsideMapSprites
ret c ; return if the map is an outside map (already handled by above call)
-; if the map is an inside map (i.e. mapID >= $25)
+; if the map is an inside map (i.e. mapID >= FIRST_INDOOR_MAP)
ld hl, wSpritePlayerStateData1PictureID
ld de, wSpritePlayerStateData2PictureID
; Loop to copy picture IDs from [x#SPRITESTATEDATA1_PICTUREID]
@@ -19,10 +19,10 @@
.copyPictureIDLoop
ld a, [hl] ; a = [x#SPRITESTATEDATA1_PICTUREID]
ld [de], a ; [x#SPRITESTATEDATA2_PICTUREID] = a
- ld a, $10
+ ld a, SPRITESTATEDATA1_LENGTH
add e
ld e, a
- ld a, $10
+ ld a, SPRITESTATEDATA1_LENGTH
add l
ld l, a
jr nz, .copyPictureIDLoop
@@ -37,7 +37,7 @@
ret
.spritesExist
ld c, a ; c = [wNumSprites]
- ld b, $10 ; number of sprite slots
+ ld b, NUM_SPRITESTATEDATA_STRUCTS
ld hl, wSpritePlayerStateData2PictureID
xor a
ldh [hFourTileSpriteCount], a
@@ -47,7 +47,7 @@
ld a, [hli] ; a = [x#SPRITESTATEDATA2_PICTUREID]
ld [hld], a ; [x#SPRITESTATEDATA2_IMAGEBASEOFFSET] = a
ld a, l
- add $10
+ add SPRITESTATEDATA1_LENGTH
ld l, a
dec b
jr nz, .copyPictureIDLoop
@@ -69,17 +69,17 @@
cp [hl] ; do the picture ID's match?
jp z, .alreadyLoaded
ld a, e
- add $10
+ add SPRITESTATEDATA1_LENGTH
ld e, a
jr .checkIfAlreadyLoadedLoop
.notAlreadyLoaded
ld de, wSpritePlayerStateData2ImageBaseOffset
- ld b, $01
+ ld b, 1
; loop to find the highest tile pattern VRAM slot (among the first 10 slots) used by a previous sprite slot
; this is done in order to find the first free VRAM slot available
.findNextVRAMSlotLoop
ld a, e
- add $10
+ add SPRITESTATEDATA1_LENGTH
ld e, a
ld a, l
cp e ; reached current slot?
@@ -187,7 +187,7 @@
jr nz, .loadWhileLCDOn
pop af
pop hl
- set 3, h ; add $800 to hl
+ set 3, h ; add $80 tiles to hl
push hl
ld h, d
ld l, e
@@ -200,7 +200,7 @@
.loadWhileLCDOn
pop af
pop hl
- set 3, h ; add $800 to hl
+ set 3, h ; add $80 tiles to hl
ld b, a
swap c
call CopyVideoData ; load tile pattern data for sprite when walking
@@ -214,18 +214,18 @@
ld [hl], a ; [x#SPRITESTATEDATA2_IMAGEBASEOFFSET] = a
.nextSpriteSlot
ld a, l
- add $10
+ add SPRITESTATEDATA2_LENGTH
ld l, a
dec c
jp nz, .loadTilePatternLoop
ld hl, wSpritePlayerStateData2PictureID
- ld b, $10
+ ld b, NUM_SPRITESTATEDATA_STRUCTS
; the pictures IDs stored at [x#SPRITESTATEDATA2_PICTUREID] are no longer needed,
; so zero them
.zeroStoredPictureIDLoop
xor a
ld [hl], a ; [x#SPRITESTATEDATA2_PICTUREID]
- ld a, $10
+ ld a, SPRITESTATEDATA2_LENGTH
add l
ld l, a
dec b
@@ -264,7 +264,7 @@
inc h
.noCarry
ld a, [hl] ; a = spriteSetID
- cp $f0 ; does the map have 2 sprite sets?
+ cp FIRST_SPLIT_SET - 1 ; does the map have 2 sprite sets?
call nc, GetSplitMapSpriteSetID ; if so, choose the appropriate one
ld b, a ; b = spriteSetID
ld a, [wFontLoaded]
@@ -300,7 +300,7 @@
; with picture IDs. This is done so that LoadMapSpriteTilePatterns will
; load tile patterns for all sprite pictures in the sprite set.
.loadSpriteSetLoop
- ld a, $10
+ ld a, SPRITESTATEDATA2_LENGTH
add l
ld l, a
ld a, [de] ; sprite picture ID from sprite set
@@ -313,7 +313,7 @@
jr nz, .loadSpriteSetLoop
ld b, 4 ; 4 remaining sprite slots
.zeroRemainingSlotsLoop ; loop to zero the picture ID's of the remaining sprite slots
- ld a, $10
+ ld a, SPRITESTATEDATA2_LENGTH
add l
ld l, a
xor a
@@ -335,7 +335,7 @@
.zeroVRAMSlotsLoop
xor a
ld [hl], a ; [x#SPRITESTATEDATA2_IMAGEBASEOFFSET]
- ld a, $10
+ ld a, SPRITESTATEDATA2_LENGTH
add l
ld l, a
dec b
@@ -366,14 +366,14 @@
inc c
.skipGettingPictureIndex
push hl
- inc h
- ld a, $0e
+ inc h ; HIGH(wSpriteStateData2)
+ ld a, SPRITESTATEDATA2_IMAGEBASEOFFSET - SPRITESTATEDATA1_PICTUREID
add l
ld l, a
ld a, c ; a = VRAM slot (zero if sprite slot is not used)
ld [hl], a ; [x#SPRITESTATEDATA2_IMAGEBASEOFFSET]
pop hl
- ld a, $10
+ ld a, SPRITESTATEDATA1_LENGTH
add l
ld l, a
and a
@@ -384,7 +384,7 @@
; Chooses the correct sprite set ID depending on the player's position within
; the map for maps with two sprite sets.
GetSplitMapSpriteSetID:
- cp $f8
+ cp SPLITSET_ROUTE_20
jr z, .route20
ld hl, SplitMapSpriteSets
and $0f
@@ -396,8 +396,8 @@
jr nc, .noCarry
inc h
.noCarry
- ld a, [hli] ; determines whether the map is split East/West or North/South
- cp $01
+ ld a, [hli] ; whether the map is split EAST_WEST or NORTH_SOUTH
+ cp EAST_WEST
ld a, [hli] ; position of dividing line
ld b, a
jr z, .eastWestDivide
@@ -409,35 +409,39 @@
.compareCoord
cp b
jr c, .loadSpriteSetID
-; if in the East side or South side
+; if in the east side or south side
inc hl
.loadSpriteSetID
ld a, [hl]
ret
-; Uses sprite set $01 for West side and $0A for East side.
+; Uses sprite set SPRITESET_PALLET_VIRIDIAN for west side and SPRITESET_FUCHSIA for east side.
; Route 20 is a special case because the two map sections have a more complex
; shape instead of the map simply being split horizontally or vertically.
.route20
ld hl, wXCoord
+ ; Use SPRITESET_PALLET_VIRIDIAN if X < 43
ld a, [hl]
- cp $2b
- ld a, $01
+ cp 43
+ ld a, SPRITESET_PALLET_VIRIDIAN
ret c
+ ; Use SPRITESET_FUCHSIA if X >= 62.
ld a, [hl]
- cp $3e
- ld a, $0a
+ cp 62
+ ld a, SPRITESET_FUCHSIA
ret nc
+ ; If 55 <= X < 62, split Y at 8; else 43 <= X < 55, so split Y at 13
ld a, [hl]
- cp $37
- ld b, $08
+ cp 55
+ ld b, 8
jr nc, .next
- ld b, $0d
+ ld b, 13
.next
+ ; Use SPRITESET_FUCHSIA if Y < split; else use SPRITESET_PALLET_VIRIDIAN
ld a, [wYCoord]
cp b
- ld a, $0a
+ ld a, SPRITESET_FUCHSIA
ret c
- ld a, $01
+ ld a, SPRITESET_PALLET_VIRIDIAN
ret
INCLUDE "data/maps/sprite_sets.asm"
--- a/ram/wram.asm
+++ b/ram/wram.asm
@@ -101,7 +101,7 @@
; - E
; - F
wSpritePlayerStateData1:: spritestatedata1 wSpritePlayerStateData1 ; player is struct 0
-; wSprite02StateData1 - wSprite15StateData1
+; wSprite01StateData1 - wSprite15StateData1
FOR n, 1, NUM_SPRITESTATEDATA_STRUCTS
wSprite{02d:n}StateData1:: spritestatedata1 wSprite{02d:n}StateData1
ENDR
@@ -127,7 +127,7 @@
; - E: sprite image base offset (in video ram, player always has value 1, used to compute sprite image index)
; - F
wSpritePlayerStateData2:: spritestatedata2 wSpritePlayerStateData2 ; player is struct 0
-; wSprite02StateData2 - wSprite15StateData2
+; wSprite01StateData2 - wSprite15StateData2
FOR n, 1, NUM_SPRITESTATEDATA_STRUCTS
wSprite{02d:n}StateData2:: spritestatedata2 wSprite{02d:n}StateData2
ENDR