Eliminate enum: use const instead, with case-by-case parallel const implementations

This commit is contained in:
Rangi 2020-07-09 12:43:26 -04:00
parent 54d76dec38
commit 676a35f76f
5 changed files with 75 additions and 92 deletions

View File

@ -115,9 +115,9 @@ add_hm: MACRO
; The first usage also defines HM01 as the first HM item id.
IF !DEF(HM01)
HM01 EQU const_value
enum_start NUM_TMS + 1
__tmhm_value__ = NUM_TMS + 1
ENDC
HM_VALUE EQU __enum__ - NUM_TMS
HM_VALUE EQU __tmhm_value__ - NUM_TMS
IF HM_VALUE < 10
MOVE_FOR_HM EQUS "HM0{d:HM_VALUE}_MOVE"
ELSE
@ -127,7 +127,8 @@ MOVE_FOR_HM = \1
PURGE MOVE_FOR_HM
PURGE HM_VALUE
const HM_\1
enum \1_TMNUM
\1_TMNUM EQU __tmhm_value__
__tmhm_value__ = __tmhm_value__ + 1
ENDM
add_hm CUT ; $C4
@ -145,17 +146,18 @@ add_tm: MACRO
; The first usage also defines TM01 as the first TM item id.
IF !DEF(TM01)
TM01 EQU const_value
enum_start 1
__tmhm_value__ = 1
ENDC
IF __enum__ < 10
MOVE_FOR_TM EQUS "TM0{d:__enum__}_MOVE"
IF __tmhm_value__ < 10
MOVE_FOR_TM EQUS "TM0{d:__tmhm_value__}_MOVE"
ELSE
MOVE_FOR_TM EQUS "TM{d:__enum__}_MOVE"
MOVE_FOR_TM EQUS "TM{d:__tmhm_value__}_MOVE"
ENDC
MOVE_FOR_TM = \1
PURGE MOVE_FOR_TM
const TM_\1
enum \1_TMNUM
\1_TMNUM EQU __tmhm_value__
__tmhm_value__ = __tmhm_value__ + 1
ENDM
add_tm MEGA_PUNCH ; $C9
@ -212,5 +214,5 @@ assert NUM_TMS == const_value - TM01, "NUM_TMS ({d:NUM_TMS}) does not match the
; 50 TMs + 5 HMs = 55 learnable TM/HM flags per Pokémon.
; These fit in 7 bytes, with one unused bit left over.
enum_start NUM_TMS + NUM_HMS + 1
enum UNUSED_TMNUM
__tmhm_value__ = NUM_TMS + NUM_HMS + 1
UNUSED_TMNUM EQU __tmhm_value__

View File

@ -1,4 +1,4 @@
INCLUDE "macros/enum.asm"
INCLUDE "macros/const.asm"
INCLUDE "macros/predef.asm"
INCLUDE "macros/farcall.asm"
INCLUDE "macros/data.asm"

24
macros/const.asm Normal file
View File

@ -0,0 +1,24 @@
; Enumerate constants
const_def: MACRO
IF _NARG >= 1
const_value = \1
ELSE
const_value = 0
ENDC
IF _NARG >= 2
const_inc = \2
ELSE
const_inc = 1
ENDC
ENDM
const: MACRO
\1 EQU const_value
const_value = const_value + const_inc
ENDM
shift_const: MACRO
\1 EQU (1 << const_value)
const_value = const_value + const_inc
ENDM

View File

@ -1,43 +0,0 @@
; Enumerate variables
enum_start: MACRO
IF _NARG >= 1
__enum__ = \1
ELSE
__enum__ = 0
ENDC
IF _NARG >= 2
__enumdir__ = \2
ELSE
__enumdir__ = 1
ENDC
ENDM
enum: MACRO
\1 EQU __enum__
__enum__ = __enum__ + __enumdir__
ENDM
enum_set: MACRO
__enum__ = \1
ENDM
; Enumerate constants
const_def: MACRO
IF _NARG >= 1
const_value = \1
ELSE
const_value = 0
ENDC
ENDM
const: MACRO
\1 EQU const_value
const_value = const_value + 1
ENDM
shift_const: MACRO
\1 EQU (1 << const_value)
const_value = const_value + 1
ENDM

View File

@ -11,33 +11,33 @@ dex EQUS "db \"<DEXEND>\", \"@\"" ; End a Pokédex entry.
; TextCommandJumpTable indexes (see home/text.asm)
enum_start
const_def
enum TX_START ; $00
const TX_START ; $00
text_start: MACRO
db TX_START
ENDM
enum TX_RAM ; $01
const TX_RAM ; $01
text_ram: MACRO
db TX_RAM
dw \1 ; address to read from
ENDM
enum TX_BCD ; $02
const TX_BCD ; $02
text_bcd: MACRO
db TX_BCD
dw \1 ; address to read from
db \2 ; number of bytes + print flags
ENDM
enum TX_MOVE ; $03
const TX_MOVE ; $03
text_move: MACRO
db TX_MOVE
dw \1 ; address of the new location
ENDM
enum TX_BOX ; $04
const TX_BOX ; $04
text_box: MACRO
; draw box
db TX_BOX
@ -45,27 +45,27 @@ text_box: MACRO
db \2, \3 ; height, width
ENDM
enum TX_LOW ; $05
const TX_LOW ; $05
text_low: MACRO
db TX_LOW
ENDM
enum TX_PROMPT_BUTTON ; $06
const TX_PROMPT_BUTTON ; $06
text_promptbutton: MACRO
db TX_PROMPT_BUTTON
ENDM
enum TX_SCROLL ; $07
const TX_SCROLL ; $07
text_scroll: MACRO
db TX_SCROLL
ENDM
enum TX_START_ASM ; $08
const TX_START_ASM ; $08
text_asm: MACRO
db TX_START_ASM
ENDM
enum TX_NUM ; $09
const TX_NUM ; $09
text_decimal: MACRO
; print a big-endian decimal number.
db TX_NUM
@ -73,12 +73,12 @@ text_decimal: MACRO
dn \2, \3 ; number of bytes to read, number of digits to display
ENDM
enum TX_PAUSE ; $0a
const TX_PAUSE ; $0a
text_pause: MACRO
db TX_PAUSE
ENDM
enum TX_SOUND_GET_ITEM_1 ; $0b
const TX_SOUND_GET_ITEM_1 ; $0b
sound_get_item_1: MACRO
db TX_SOUND_GET_ITEM_1
ENDM
@ -86,115 +86,115 @@ ENDM
TX_SOUND_LEVEL_UP EQU TX_SOUND_GET_ITEM_1
sound_level_up EQUS "sound_get_item_1"
enum TX_DOTS ; $0c
const TX_DOTS ; $0c
text_dots: MACRO
db TX_DOTS
db \1 ; number of ellipses to draw
ENDM
enum TX_WAIT_BUTTON ; $0d
const TX_WAIT_BUTTON ; $0d
text_waitbutton: MACRO
db TX_WAIT_BUTTON
ENDM
enum TX_SOUND_POKEDEX_RATING ; $0e
const TX_SOUND_POKEDEX_RATING ; $0e
sound_pokedex_rating: MACRO
db TX_SOUND_POKEDEX_RATING
ENDM
enum TX_SOUND_GET_ITEM_1_DUPLICATE ; $0f
const TX_SOUND_GET_ITEM_1_DUPLICATE ; $0f
sound_get_item_1_duplicate: MACRO
db TX_SOUND_GET_ITEM_1_DUPLICATE
ENDM
enum TX_SOUND_GET_ITEM_2 ; $10
const TX_SOUND_GET_ITEM_2 ; $10
sound_get_item_2: MACRO
db TX_SOUND_GET_ITEM_2
ENDM
enum TX_SOUND_GET_KEY_ITEM ; $11
const TX_SOUND_GET_KEY_ITEM ; $11
sound_get_key_item: MACRO
db TX_SOUND_GET_KEY_ITEM
ENDM
enum TX_SOUND_CAUGHT_MON ; $12
const TX_SOUND_CAUGHT_MON ; $12
sound_caught_mon: MACRO
db TX_SOUND_CAUGHT_MON
ENDM
enum TX_SOUND_DEX_PAGE_ADDED ; $13
const TX_SOUND_DEX_PAGE_ADDED ; $13
sound_dex_page_added: MACRO
db TX_SOUND_DEX_PAGE_ADDED
ENDM
enum TX_SOUND_CRY_NIDORINA ; $14
const TX_SOUND_CRY_NIDORINA ; $14
sound_cry_nidorina: MACRO
db TX_SOUND_CRY_NIDORINA
ENDM
enum TX_SOUND_CRY_PIDGEOT ; $15
const TX_SOUND_CRY_PIDGEOT ; $15
sound_cry_pidgeot: MACRO
db TX_SOUND_CRY_PIDGEOT
ENDM
enum TX_SOUND_CRY_DEWGONG ; $16
const TX_SOUND_CRY_DEWGONG ; $16
sound_cry_dewgong: MACRO
db TX_SOUND_CRY_DEWGONG
ENDM
enum TX_FAR ; $17
const TX_FAR ; $17
text_far: MACRO
db TX_FAR
dab \1 ; address of text commands
ENDM
enum_set $50
const_def $50
enum TX_END ; $50
const TX_END ; $50
text_end: MACRO
db TX_END
ENDM
; Text script IDs (see home/text_script.asm)
enum_set $f5
const_def $f5
enum TX_SCRIPT_VENDING_MACHINE ; $f5
const TX_SCRIPT_VENDING_MACHINE ; $f5
script_vending_machine: MACRO
db TX_SCRIPT_VENDING_MACHINE
ENDM
enum TX_SCRIPT_CABLE_CLUB_RECEPTIONIST ; $f6
const TX_SCRIPT_CABLE_CLUB_RECEPTIONIST ; $f6
script_cable_club_receptionist: MACRO
db TX_SCRIPT_CABLE_CLUB_RECEPTIONIST
ENDM
enum TX_SCRIPT_PRIZE_VENDOR ; $f7
const TX_SCRIPT_PRIZE_VENDOR ; $f7
script_prize_vendor: MACRO
db TX_SCRIPT_PRIZE_VENDOR
ENDM
enum_set $f9
const_def $f9
enum TX_SCRIPT_POKECENTER_PC ; $f9
const TX_SCRIPT_POKECENTER_PC ; $f9
script_pokecenter_pc: MACRO
db TX_SCRIPT_POKECENTER_PC
ENDM
enum_set $fc
const_def $fc
enum TX_SCRIPT_PLAYERS_PC ; $fc
const TX_SCRIPT_PLAYERS_PC ; $fc
script_players_pc: MACRO
db TX_SCRIPT_PLAYERS_PC
ENDM
enum TX_SCRIPT_BILLS_PC ; $fd
const TX_SCRIPT_BILLS_PC ; $fd
script_bills_pc: MACRO
db TX_SCRIPT_BILLS_PC
ENDM
enum TX_SCRIPT_MART ; $fe
const TX_SCRIPT_MART ; $fe
script_mart: MACRO
db TX_SCRIPT_MART
db _NARG ; number of items
@ -205,7 +205,7 @@ ENDR
db -1 ; end
ENDM
enum TX_SCRIPT_POKECENTER_NURSE ; $ff
const TX_SCRIPT_POKECENTER_NURSE ; $ff
script_pokecenter_nurse: MACRO
db TX_SCRIPT_POKECENTER_NURSE
ENDM