Specify a max item length for list_start (#552)

This commit is contained in:
Rangi 2025-12-15 15:16:40 -05:00 committed by GitHub
parent e9d3324bc0
commit d79c578abd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 38 additions and 23 deletions

View File

@ -1,9 +1,11 @@
DEF PLAYER_NAME_LENGTH EQU 8 DEF PLAYER_NAME_LENGTH EQU 8
DEF NAME_LENGTH EQU 11 DEF STAT_NAME_LENGTH EQU 10
DEF ITEM_NAME_LENGTH EQU 13 DEF NAME_LENGTH EQU 11
DEF MOVE_NAME_LENGTH EQU 14 DEF ITEM_NAME_LENGTH EQU 13
DEF NAME_BUFFER_LENGTH EQU 20 DEF TRAINER_NAME_LENGTH EQU 13
DEF GYM_CITY_LENGTH EQU 17 DEF MOVE_NAME_LENGTH EQU 14
DEF GYM_CITY_LENGTH EQU 17
DEF NAME_BUFFER_LENGTH EQU 20
; PrintNumber, PrintBCDNumber ; PrintNumber, PrintBCDNumber
const_def 5 const_def 5

View File

@ -2,7 +2,7 @@
; The relevant move effect IDs correspond to the stats ; The relevant move effect IDs correspond to the stats
StatModTextStrings: StatModTextStrings:
list_start list_start STAT_NAME_LENGTH - 1
li "ATTACK" li "ATTACK"
li "DEFENSE" li "DEFENSE"
li "SPEED" li "SPEED"

View File

@ -1,7 +1,7 @@
; Stats that vitamins can raise or lower ; Stats that vitamins can raise or lower
VitaminStats: VitaminStats:
list_start list_start STAT_NAME_LENGTH - 1
li "HEALTH" li "HEALTH"
li "ATTACK" li "ATTACK"
li "DEFENSE" li "DEFENSE"

View File

@ -1,5 +1,5 @@
ItemNames:: ItemNames::
list_start list_start ITEM_NAME_LENGTH - 1
li "MASTER BALL" li "MASTER BALL"
li "ULTRA BALL" li "ULTRA BALL"
li "GREAT BALL" li "GREAT BALL"

View File

@ -1,5 +1,6 @@
MoveNames:: MoveNames::
list_start ; in-battle "used <move name>!" text can only fit 12 (MOVE_NAME_LENGTH - 2) characters
list_start MOVE_NAME_LENGTH - 2
li "POUND" li "POUND"
li "KARATE CHOP" li "KARATE CHOP"
li "DOUBLESLAP" li "DOUBLESLAP"

View File

@ -2,7 +2,7 @@
DefaultNamesPlayerList: DefaultNamesPlayerList:
db "NEW NAME@" db "NEW NAME@"
list_start list_start PLAYER_NAME_LENGTH - 1
FOR n, 1, NUM_PLAYER_NAMES + 1 FOR n, 1, NUM_PLAYER_NAMES + 1
li #PLAYERNAME{d:n} li #PLAYERNAME{d:n}
ENDR ENDR
@ -10,7 +10,7 @@ ENDR
DefaultNamesRivalList: DefaultNamesRivalList:
db "NEW NAME@" db "NEW NAME@"
list_start list_start PLAYER_NAME_LENGTH - 1
FOR n, 1, NUM_PLAYER_NAMES + 1 FOR n, 1, NUM_PLAYER_NAMES + 1
li #RIVALNAME{d:n} li #RIVALNAME{d:n}
ENDR ENDR

View File

@ -1,14 +1,15 @@
DEF __move_choices__ = 0
MACRO move_choices MACRO move_choices
IF _NARG IF _NARG
db \# ; all args db \# ; all args
ENDC ENDC
db 0 ; end db 0 ; end
DEF list_index += 1 DEF __move_choices__ += 1
ENDM ENDM
; move choice modification methods that are applied for each trainer class ; move choice modification methods that are applied for each trainer class
TrainerClassMoveChoiceModifications: TrainerClassMoveChoiceModifications:
list_start
move_choices ; YOUNGSTER move_choices ; YOUNGSTER
move_choices 1 ; BUG CATCHER move_choices 1 ; BUG CATCHER
move_choices 1 ; LASS move_choices 1 ; LASS
@ -56,4 +57,5 @@ TrainerClassMoveChoiceModifications:
move_choices 1 ; CHANNELER move_choices 1 ; CHANNELER
move_choices 1 ; AGATHA move_choices 1 ; AGATHA
move_choices 1, 3 ; LANCE move_choices 1, 3 ; LANCE
assert_list_length NUM_TRAINERS assert __move_choices__ == NUM_TRAINERS, \
"TrainerClassMoveChoiceModifications: expected {d:NUM_TRAINERS} entries, got {d:__move_choices__}"

View File

@ -1,5 +1,5 @@
TrainerNames:: TrainerNames::
list_start list_start TRAINER_NAME_LENGTH - 1
li "YOUNGSTER" li "YOUNGSTER"
li "BUG CATCHER" li "BUG CATCHER"
li "LASS" li "LASS"

View File

@ -754,7 +754,7 @@ PrintStatText:
jr .findStatName_inner jr .findStatName_inner
.foundStatName .foundStatName
ld de, wStringBuffer ld de, wStringBuffer
ld bc, NAME_LENGTH - 1 ; all StatModTextStrings are at most 10 bytes ld bc, STAT_NAME_LENGTH
jp CopyData jp CopyData
INCLUDE "data/battle/stat_mod_names.asm" INCLUDE "data/battle/stat_mod_names.asm"

View File

@ -20,5 +20,5 @@ GetTrainerName_::
ld hl, wNameBuffer ld hl, wNameBuffer
.foundName .foundName
ld de, wTrainerName ld de, wTrainerName
ld bc, ITEM_NAME_LENGTH ld bc, TRAINER_NAME_LENGTH
jp CopyData jp CopyData

View File

@ -1308,7 +1308,7 @@ ItemUseMedicine:
jr .statNameLoop jr .statNameLoop
.gotStatName .gotStatName
ld de, wStringBuffer ld de, wStringBuffer
ld bc, NAME_LENGTH - 1 ; all VitaminStats are at most 10 bytes ld bc, STAT_NAME_LENGTH
call CopyData ; copy the stat's name to wStringBuffer call CopyData ; copy the stat's name to wStringBuffer
ld a, SFX_HEAL_AILMENT ld a, SFX_HEAL_AILMENT
call PlaySound call PlaySound

View File

@ -4,8 +4,8 @@ MACRO? _redef_current_label
IF DEF(\1) IF DEF(\1)
PURGE \1 PURGE \1
ENDC ENDC
IF _NARG == 3 + (\3) IF _NARG > 2
DEF \1 EQUS "\<_NARG>" DEF \1 EQUS "\3"
ELIF STRLEN(#__SCOPE__) ELIF STRLEN(#__SCOPE__)
IF {{__SCOPE__}} - @ == 0 IF {{__SCOPE__}} - @ == 0
DEF \1 EQUS #{__SCOPE__} DEF \1 EQUS #{__SCOPE__}
@ -19,7 +19,8 @@ ENDM
MACRO? table_width MACRO? table_width
DEF CURRENT_TABLE_WIDTH = \1 DEF CURRENT_TABLE_WIDTH = \1
_redef_current_label CURRENT_TABLE_START, "._table_width\@", 2, \# SHIFT
_redef_current_label CURRENT_TABLE_START, "._table_width\@", \#
ENDM ENDM
MACRO? assert_table_length MACRO? assert_table_length
@ -40,11 +41,20 @@ ENDM
MACRO? list_start MACRO? list_start
DEF list_index = 0 DEF list_index = 0
_redef_current_label CURRENT_LIST_START, "._list_start\@", 1, \# DEF list_item_length = 0
IF _NARG > 0
DEF list_item_length = \1
SHIFT
ENDC
_redef_current_label CURRENT_LIST_START, "._list_start\@", \#
ENDM ENDM
MACRO? li MACRO? li
ASSERT STRFIND(\1, "@") == -1, "String terminator \"@\" in list entry: \1" ASSERT STRFIND(\1, "@") == -1, "String terminator \"@\" in list entry: \1"
IF list_item_length
ASSERT CHARLEN(\1) <= list_item_length, \
"List entry longer than {d:list_item_length} characters: \1"
ENDC
db \1, "@" db \1, "@"
DEF list_index += 1 DEF list_index += 1
ENDM ENDM