Skip to content

Commit

Permalink
Use constant in wram for hidden item flags (#445)
Browse files Browse the repository at this point in the history
Prevents defining more hidden items than the flag array has room for
  • Loading branch information
Vortyne authored May 5, 2024
1 parent d870ad6 commit 5f7b444
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 2 deletions.
3 changes: 3 additions & 0 deletions constants/item_constants.asm
Original file line number Diff line number Diff line change
Expand Up @@ -215,3 +215,6 @@ DEF NUM_TM_HM EQU NUM_TMS + NUM_HMS
; These fit in 7 bytes, with one unused bit left over.
DEF __tmhm_value__ = NUM_TM_HM + 1
DEF UNUSED_TMNUM EQU __tmhm_value__

DEF MAX_HIDDEN_ITEMS EQU 112
DEF MAX_HIDDEN_COINS EQU 16
2 changes: 2 additions & 0 deletions data/events/hidden_coins.asm
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ MACRO hidden_coin
ENDM

HiddenCoinCoords:
table_width 3, HiddenCoinCoords
; map id, x, y
hidden_coin GAME_CORNER, 0, 8
hidden_coin GAME_CORNER, 1, 16
Expand All @@ -16,4 +17,5 @@ HiddenCoinCoords:
hidden_coin GAME_CORNER, 11, 7
hidden_coin GAME_CORNER, 15, 8
hidden_coin GAME_CORNER, 12, 15
assert_max_table_length MAX_HIDDEN_COINS
db -1 ; end
2 changes: 2 additions & 0 deletions data/events/hidden_item_coords.asm
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ MACRO hidden_item
ENDM

HiddenItemCoords:
table_width 3, HiddenItemCoords
; map id, x, y
hidden_item VIRIDIAN_FOREST, 1, 18
hidden_item VIRIDIAN_FOREST, 16, 42
Expand Down Expand Up @@ -58,4 +59,5 @@ HiddenItemCoords:
hidden_item VERMILION_CITY, 14, 11
hidden_item CERULEAN_CITY, 15, 8
hidden_item ROUTE_4, 40, 3
assert_max_table_length MAX_HIDDEN_ITEMS
db -1 ; end
6 changes: 6 additions & 0 deletions macros/asserts.asm
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ MACRO assert_table_length
"{CURRENT_TABLE_START}: expected {d:x} entries, each {d:CURRENT_TABLE_WIDTH} bytes"
ENDM

MACRO assert_max_table_length
DEF x = \1
ASSERT x * CURRENT_TABLE_WIDTH >= @ - {CURRENT_TABLE_START}, \
"{CURRENT_TABLE_START}: expected a maximum of {d:x} entries, each {d:CURRENT_TABLE_WIDTH} bytes"
ENDM

MACRO list_start
DEF list_index = 0
IF _NARG == 1
Expand Down
4 changes: 2 additions & 2 deletions ram/wram.asm
Original file line number Diff line number Diff line change
Expand Up @@ -2042,9 +2042,9 @@ wGameProgressFlagsEnd::

ds 56

wObtainedHiddenItemsFlags:: flag_array 112
wObtainedHiddenItemsFlags:: flag_array MAX_HIDDEN_ITEMS

wObtainedHiddenCoinsFlags:: flag_array 16
wObtainedHiddenCoinsFlags:: flag_array MAX_HIDDEN_COINS

; $00 = walking
; $01 = biking
Expand Down

0 comments on commit 5f7b444

Please sign in to comment.