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. ; The first usage also defines HM01 as the first HM item id.
IF !DEF(HM01) IF !DEF(HM01)
HM01 EQU const_value HM01 EQU const_value
enum_start NUM_TMS + 1 __tmhm_value__ = NUM_TMS + 1
ENDC ENDC
HM_VALUE EQU __enum__ - NUM_TMS HM_VALUE EQU __tmhm_value__ - NUM_TMS
IF HM_VALUE < 10 IF HM_VALUE < 10
MOVE_FOR_HM EQUS "HM0{d:HM_VALUE}_MOVE" MOVE_FOR_HM EQUS "HM0{d:HM_VALUE}_MOVE"
ELSE ELSE
@ -127,7 +127,8 @@ MOVE_FOR_HM = \1
PURGE MOVE_FOR_HM PURGE MOVE_FOR_HM
PURGE HM_VALUE PURGE HM_VALUE
const HM_\1 const HM_\1
enum \1_TMNUM \1_TMNUM EQU __tmhm_value__
__tmhm_value__ = __tmhm_value__ + 1
ENDM ENDM
add_hm CUT ; $C4 add_hm CUT ; $C4
@ -145,17 +146,18 @@ add_tm: MACRO
; The first usage also defines TM01 as the first TM item id. ; The first usage also defines TM01 as the first TM item id.
IF !DEF(TM01) IF !DEF(TM01)
TM01 EQU const_value TM01 EQU const_value
enum_start 1 __tmhm_value__ = 1
ENDC ENDC
IF __enum__ < 10 IF __tmhm_value__ < 10
MOVE_FOR_TM EQUS "TM0{d:__enum__}_MOVE" MOVE_FOR_TM EQUS "TM0{d:__tmhm_value__}_MOVE"
ELSE ELSE
MOVE_FOR_TM EQUS "TM{d:__enum__}_MOVE" MOVE_FOR_TM EQUS "TM{d:__tmhm_value__}_MOVE"
ENDC ENDC
MOVE_FOR_TM = \1 MOVE_FOR_TM = \1
PURGE MOVE_FOR_TM PURGE MOVE_FOR_TM
const TM_\1 const TM_\1
enum \1_TMNUM \1_TMNUM EQU __tmhm_value__
__tmhm_value__ = __tmhm_value__ + 1
ENDM ENDM
add_tm MEGA_PUNCH ; $C9 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. ; 50 TMs + 5 HMs = 55 learnable TM/HM flags per Pokémon.
; These fit in 7 bytes, with one unused bit left over. ; These fit in 7 bytes, with one unused bit left over.
enum_start NUM_TMS + NUM_HMS + 1 __tmhm_value__ = NUM_TMS + NUM_HMS + 1
enum UNUSED_TMNUM 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/predef.asm"
INCLUDE "macros/farcall.asm" INCLUDE "macros/farcall.asm"
INCLUDE "macros/data.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) ; TextCommandJumpTable indexes (see home/text.asm)
enum_start const_def
enum TX_START ; $00 const TX_START ; $00
text_start: MACRO text_start: MACRO
db TX_START db TX_START
ENDM ENDM
enum TX_RAM ; $01 const TX_RAM ; $01
text_ram: MACRO text_ram: MACRO
db TX_RAM db TX_RAM
dw \1 ; address to read from dw \1 ; address to read from
ENDM ENDM
enum TX_BCD ; $02 const TX_BCD ; $02
text_bcd: MACRO text_bcd: MACRO
db TX_BCD db TX_BCD
dw \1 ; address to read from dw \1 ; address to read from
db \2 ; number of bytes + print flags db \2 ; number of bytes + print flags
ENDM ENDM
enum TX_MOVE ; $03 const TX_MOVE ; $03
text_move: MACRO text_move: MACRO
db TX_MOVE db TX_MOVE
dw \1 ; address of the new location dw \1 ; address of the new location
ENDM ENDM
enum TX_BOX ; $04 const TX_BOX ; $04
text_box: MACRO text_box: MACRO
; draw box ; draw box
db TX_BOX db TX_BOX
@ -45,27 +45,27 @@ text_box: MACRO
db \2, \3 ; height, width db \2, \3 ; height, width
ENDM ENDM
enum TX_LOW ; $05 const TX_LOW ; $05
text_low: MACRO text_low: MACRO
db TX_LOW db TX_LOW
ENDM ENDM
enum TX_PROMPT_BUTTON ; $06 const TX_PROMPT_BUTTON ; $06
text_promptbutton: MACRO text_promptbutton: MACRO
db TX_PROMPT_BUTTON db TX_PROMPT_BUTTON
ENDM ENDM
enum TX_SCROLL ; $07 const TX_SCROLL ; $07
text_scroll: MACRO text_scroll: MACRO
db TX_SCROLL db TX_SCROLL
ENDM ENDM
enum TX_START_ASM ; $08 const TX_START_ASM ; $08
text_asm: MACRO text_asm: MACRO
db TX_START_ASM db TX_START_ASM
ENDM ENDM
enum TX_NUM ; $09 const TX_NUM ; $09
text_decimal: MACRO text_decimal: MACRO
; print a big-endian decimal number. ; print a big-endian decimal number.
db TX_NUM db TX_NUM
@ -73,12 +73,12 @@ text_decimal: MACRO
dn \2, \3 ; number of bytes to read, number of digits to display dn \2, \3 ; number of bytes to read, number of digits to display
ENDM ENDM
enum TX_PAUSE ; $0a const TX_PAUSE ; $0a
text_pause: MACRO text_pause: MACRO
db TX_PAUSE db TX_PAUSE
ENDM ENDM
enum TX_SOUND_GET_ITEM_1 ; $0b const TX_SOUND_GET_ITEM_1 ; $0b
sound_get_item_1: MACRO sound_get_item_1: MACRO
db TX_SOUND_GET_ITEM_1 db TX_SOUND_GET_ITEM_1
ENDM ENDM
@ -86,115 +86,115 @@ ENDM
TX_SOUND_LEVEL_UP EQU TX_SOUND_GET_ITEM_1 TX_SOUND_LEVEL_UP EQU TX_SOUND_GET_ITEM_1
sound_level_up EQUS "sound_get_item_1" sound_level_up EQUS "sound_get_item_1"
enum TX_DOTS ; $0c const TX_DOTS ; $0c
text_dots: MACRO text_dots: MACRO
db TX_DOTS db TX_DOTS
db \1 ; number of ellipses to draw db \1 ; number of ellipses to draw
ENDM ENDM
enum TX_WAIT_BUTTON ; $0d const TX_WAIT_BUTTON ; $0d
text_waitbutton: MACRO text_waitbutton: MACRO
db TX_WAIT_BUTTON db TX_WAIT_BUTTON
ENDM ENDM
enum TX_SOUND_POKEDEX_RATING ; $0e const TX_SOUND_POKEDEX_RATING ; $0e
sound_pokedex_rating: MACRO sound_pokedex_rating: MACRO
db TX_SOUND_POKEDEX_RATING db TX_SOUND_POKEDEX_RATING
ENDM ENDM
enum TX_SOUND_GET_ITEM_1_DUPLICATE ; $0f const TX_SOUND_GET_ITEM_1_DUPLICATE ; $0f
sound_get_item_1_duplicate: MACRO sound_get_item_1_duplicate: MACRO
db TX_SOUND_GET_ITEM_1_DUPLICATE db TX_SOUND_GET_ITEM_1_DUPLICATE
ENDM ENDM
enum TX_SOUND_GET_ITEM_2 ; $10 const TX_SOUND_GET_ITEM_2 ; $10
sound_get_item_2: MACRO sound_get_item_2: MACRO
db TX_SOUND_GET_ITEM_2 db TX_SOUND_GET_ITEM_2
ENDM ENDM
enum TX_SOUND_GET_KEY_ITEM ; $11 const TX_SOUND_GET_KEY_ITEM ; $11
sound_get_key_item: MACRO sound_get_key_item: MACRO
db TX_SOUND_GET_KEY_ITEM db TX_SOUND_GET_KEY_ITEM
ENDM ENDM
enum TX_SOUND_CAUGHT_MON ; $12 const TX_SOUND_CAUGHT_MON ; $12
sound_caught_mon: MACRO sound_caught_mon: MACRO
db TX_SOUND_CAUGHT_MON db TX_SOUND_CAUGHT_MON
ENDM ENDM
enum TX_SOUND_DEX_PAGE_ADDED ; $13 const TX_SOUND_DEX_PAGE_ADDED ; $13
sound_dex_page_added: MACRO sound_dex_page_added: MACRO
db TX_SOUND_DEX_PAGE_ADDED db TX_SOUND_DEX_PAGE_ADDED
ENDM ENDM
enum TX_SOUND_CRY_NIDORINA ; $14 const TX_SOUND_CRY_NIDORINA ; $14
sound_cry_nidorina: MACRO sound_cry_nidorina: MACRO
db TX_SOUND_CRY_NIDORINA db TX_SOUND_CRY_NIDORINA
ENDM ENDM
enum TX_SOUND_CRY_PIDGEOT ; $15 const TX_SOUND_CRY_PIDGEOT ; $15
sound_cry_pidgeot: MACRO sound_cry_pidgeot: MACRO
db TX_SOUND_CRY_PIDGEOT db TX_SOUND_CRY_PIDGEOT
ENDM ENDM
enum TX_SOUND_CRY_DEWGONG ; $16 const TX_SOUND_CRY_DEWGONG ; $16
sound_cry_dewgong: MACRO sound_cry_dewgong: MACRO
db TX_SOUND_CRY_DEWGONG db TX_SOUND_CRY_DEWGONG
ENDM ENDM
enum TX_FAR ; $17 const TX_FAR ; $17
text_far: MACRO text_far: MACRO
db TX_FAR db TX_FAR
dab \1 ; address of text commands dab \1 ; address of text commands
ENDM ENDM
enum_set $50 const_def $50
enum TX_END ; $50 const TX_END ; $50
text_end: MACRO text_end: MACRO
db TX_END db TX_END
ENDM ENDM
; Text script IDs (see home/text_script.asm) ; 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 script_vending_machine: MACRO
db TX_SCRIPT_VENDING_MACHINE db TX_SCRIPT_VENDING_MACHINE
ENDM ENDM
enum TX_SCRIPT_CABLE_CLUB_RECEPTIONIST ; $f6 const TX_SCRIPT_CABLE_CLUB_RECEPTIONIST ; $f6
script_cable_club_receptionist: MACRO script_cable_club_receptionist: MACRO
db TX_SCRIPT_CABLE_CLUB_RECEPTIONIST db TX_SCRIPT_CABLE_CLUB_RECEPTIONIST
ENDM ENDM
enum TX_SCRIPT_PRIZE_VENDOR ; $f7 const TX_SCRIPT_PRIZE_VENDOR ; $f7
script_prize_vendor: MACRO script_prize_vendor: MACRO
db TX_SCRIPT_PRIZE_VENDOR db TX_SCRIPT_PRIZE_VENDOR
ENDM ENDM
enum_set $f9 const_def $f9
enum TX_SCRIPT_POKECENTER_PC ; $f9 const TX_SCRIPT_POKECENTER_PC ; $f9
script_pokecenter_pc: MACRO script_pokecenter_pc: MACRO
db TX_SCRIPT_POKECENTER_PC db TX_SCRIPT_POKECENTER_PC
ENDM ENDM
enum_set $fc const_def $fc
enum TX_SCRIPT_PLAYERS_PC ; $fc const TX_SCRIPT_PLAYERS_PC ; $fc
script_players_pc: MACRO script_players_pc: MACRO
db TX_SCRIPT_PLAYERS_PC db TX_SCRIPT_PLAYERS_PC
ENDM ENDM
enum TX_SCRIPT_BILLS_PC ; $fd const TX_SCRIPT_BILLS_PC ; $fd
script_bills_pc: MACRO script_bills_pc: MACRO
db TX_SCRIPT_BILLS_PC db TX_SCRIPT_BILLS_PC
ENDM ENDM
enum TX_SCRIPT_MART ; $fe const TX_SCRIPT_MART ; $fe
script_mart: MACRO script_mart: MACRO
db TX_SCRIPT_MART db TX_SCRIPT_MART
db _NARG ; number of items db _NARG ; number of items
@ -205,7 +205,7 @@ ENDR
db -1 ; end db -1 ; end
ENDM ENDM
enum TX_SCRIPT_POKECENTER_NURSE ; $ff const TX_SCRIPT_POKECENTER_NURSE ; $ff
script_pokecenter_nurse: MACRO script_pokecenter_nurse: MACRO
db TX_SCRIPT_POKECENTER_NURSE db TX_SCRIPT_POKECENTER_NURSE
ENDM ENDM