Identify more labels, and use the jumptable macro when possible

This commit is contained in:
Rangi 2020-07-01 13:13:49 -04:00
parent e171c84c29
commit fce6243b43
26 changed files with 41 additions and 253 deletions

View File

@ -25,3 +25,5 @@ MomItems_2:
momitem 50000, 8000, MOM_DOLL, DECO_PIKACHU_DOLL momitem 50000, 8000, MOM_DOLL, DECO_PIKACHU_DOLL
momitem 100000, 22800, MOM_DOLL, DECO_BIG_SNORLAX_DOLL momitem 100000, 22800, MOM_DOLL, DECO_BIG_SNORLAX_DOLL
.End .End
dt 0 ; unused

View File

@ -204,16 +204,7 @@ _BattleTowerBattle:
ret ret
.do_dw .do_dw
ld a, [wBattleTowerBattleEnded] jumptable .dw, wBattleTowerBattleEnded
ld e, a
ld d, 0
ld hl, .dw
add hl, de
add hl, de
ld a, [hli]
ld h, [hl]
ld l, a
jp hl
.dw .dw
dw RunBattleTowerTrainer dw RunBattleTowerTrainer
@ -625,16 +616,7 @@ Function1704e1:
ret ret
.DoJumptable: .DoJumptable:
ld a, [wJumptableIndex] jumptable .dw, wJumptableIndex
ld e, a
ld d, 0
ld hl, .dw
add hl, de
add hl, de
ld a, [hli]
ld h, [hl]
ld l, a
jp hl
.dw .dw
dw .Jumptable_0 dw .Jumptable_0
@ -869,16 +851,7 @@ Function1704e1:
db "れきだいりーダーいちらん@" db "れきだいりーダーいちらん@"
BattleTowerAction: BattleTowerAction:
ld a, [wScriptVar] jumptable .dw, wScriptVar
ld e, a
ld d, 0
ld hl, .dw
add hl, de
add hl, de
ld a, [hli]
ld h, [hl]
ld l, a
jp hl
.dw .dw
dw BattleTowerAction_CheckExplanationRead dw BattleTowerAction_CheckExplanationRead

View File

@ -154,16 +154,7 @@ CutGrassGFX:
INCBIN "gfx/overworld/cut_grass.2bpp" INCBIN "gfx/overworld/cut_grass.2bpp"
OWCutJumptable: OWCutJumptable:
ld a, [wJumptableIndex] jumptable .dw, wJumptableIndex
ld e, a
ld d, 0
ld hl, .dw
add hl, de
add hl, de
ld a, [hli]
ld h, [hl]
ld l, a
jp hl
.dw .dw
dw Cut_SpawnAnimateTree dw Cut_SpawnAnimateTree

View File

@ -272,16 +272,7 @@ SetMagnetTrainPals:
ret ret
MagnetTrain_Jumptable: MagnetTrain_Jumptable:
ld a, [wJumptableIndex] jumptable .Jumptable, wJumptableIndex
ld e, a
ld d, 0
ld hl, .Jumptable
add hl, de
add hl, de
ld a, [hli]
ld h, [hl]
ld l, a
jp hl
.Jumptable: .Jumptable:
dw .InitPlayerSpriteAnim dw .InitPlayerSpriteAnim

View File

@ -18,19 +18,9 @@ BankOfMom:
ret ret
.RunJumptable: .RunJumptable:
ld a, [wJumptableIndex] jumptable .dw, wJumptableIndex
ld e, a
ld d, 0
ld hl, .dw
add hl, de
add hl, de
ld a, [hli]
ld h, [hl]
ld l, a
jp hl
.dw .dw
dw .CheckIfBankInitialized dw .CheckIfBankInitialized
dw .InitializeBank dw .InitializeBank
dw .IsThisAboutYourMoney dw .IsThisAboutYourMoney
@ -98,7 +88,7 @@ BankOfMom:
ld hl, MomBankWhatDoYouWantToDoText ld hl, MomBankWhatDoYouWantToDoText
call PrintText call PrintText
call LoadStandardMenuHeader call LoadStandardMenuHeader
ld hl, MenuHeader_0x166b5 ld hl, BankOfMom_MenuHeader
call CopyMenuHeader call CopyMenuHeader
call VerticalMenu call VerticalMenu
call CloseWindow call CloseWindow
@ -659,13 +649,13 @@ Mom_DepositString:
Mom_HeldString: Mom_HeldString:
db "HELD@" db "HELD@"
MenuHeader_0x166b5: BankOfMom_MenuHeader:
db MENU_BACKUP_TILES ; flags db MENU_BACKUP_TILES ; flags
menu_coords 0, 0, 10, 10 menu_coords 0, 0, 10, 10
dw MenuData_0x166bd dw .MenuData
db 1 ; default option db 1 ; default option
MenuData_0x166bd: .MenuData:
db STATICMENU_CURSOR ; flags db STATICMENU_CURSOR ; flags
db 4 ; items db 4 ; items
db "GET@" db "GET@"

View File

@ -204,8 +204,6 @@ endr
INCLUDE "data/items/mom_phone.asm" INCLUDE "data/items/mom_phone.asm"
db 0, 0, 0 ; unused
MomHiHowAreYouText: MomHiHowAreYouText:
text_far _MomHiHowAreYouText text_far _MomHiHowAreYouText
text_end text_end

View File

@ -75,16 +75,7 @@ _CardFlip:
ret ret
.CardFlip: .CardFlip:
ld a, [wJumptableIndex] jumptable .Jumptable, wJumptableIndex
ld e, a
ld d, 0
ld hl, .Jumptable
add hl, de
add hl, de
ld a, [hli]
ld h, [hl]
ld l, a
jp hl
.Jumptable: .Jumptable:
dw .AskPlayWithThree dw .AskPlayWithThree

View File

@ -169,16 +169,7 @@ PlaceStartCancelBoxBorder:
ret ret
UnownPuzzleJumptable: UnownPuzzleJumptable:
ld a, [wJumptableIndex] jumptable .Jumptable, wJumptableIndex
ld e, a
ld d, 0
ld hl, .Jumptable
add hl, de
add hl, de
ld a, [hli]
ld h, [hl]
ld l, a
jp hl
.Jumptable: .Jumptable:
dw .Function dw .Function

View File

@ -230,16 +230,7 @@ Function81a74:
jr nz, .asm_81aab jr nz, .asm_81aab
.asm_81a8b .asm_81a8b
ld a, [wJumptableIndex] jumptable Jumptable_81acf, wJumptableIndex
ld e, a
ld d, 0
ld hl, Jumptable_81acf
add hl, de
add hl, de
ld a, [hli]
ld h, [hl]
ld l, a
jp hl
.asm_81a9a .asm_81a9a
call Function81eca call Function81eca

View File

@ -363,16 +363,7 @@ NamingScreenJoypadLoop:
ret ret
.RunJumptable: .RunJumptable:
ld a, [wJumptableIndex] jumptable .Jumptable, wJumptableIndex
ld e, a
ld d, $0
ld hl, .Jumptable
add hl, de
add hl, de
ld a, [hli]
ld h, [hl]
ld l, a
jp hl
.Jumptable: .Jumptable:
dw .InitCursor dw .InitCursor
@ -1050,16 +1041,7 @@ INCBIN "gfx/icons/mail_big.2bpp"
ret ret
.DoJumptable: .DoJumptable:
ld a, [wJumptableIndex] jumptable .Jumptable, wJumptableIndex
ld e, a
ld d, 0
ld hl, .Jumptable
add hl, de
add hl, de
ld a, [hli]
ld h, [hl]
ld l, a
jp hl
.Jumptable: .Jumptable:
dw .init_blinking_cursor dw .init_blinking_cursor

View File

@ -91,16 +91,7 @@ StringOptions:
db "CANCEL@" db "CANCEL@"
GetOptionPointer: GetOptionPointer:
ld a, [wJumptableIndex] jumptable .Pointers, wJumptableIndex
ld e, a
ld d, 0
ld hl, .Pointers
add hl, de
add hl, de
ld a, [hli]
ld h, [hl]
ld l, a
jp hl
.Pointers: .Pointers:
; entries correspond to OPT_* constants ; entries correspond to OPT_* constants

View File

@ -384,16 +384,7 @@ CrystalIntro:
ret ret
IntroSceneJumper: IntroSceneJumper:
ld a, [wJumptableIndex] jumptable IntroScenes, wJumptableIndex
ld e, a
ld d, 0
ld hl, IntroScenes
add hl, de
add hl, de
ld a, [hli]
ld h, [hl]
ld l, a
jp hl
IntroScenes: IntroScenes:
dw IntroScene1 dw IntroScene1

View File

@ -228,16 +228,7 @@ DoTradeAnimation:
ret ret
.DoTradeAnimCommand: .DoTradeAnimCommand:
ld a, [wJumptableIndex] jumptable .JumpTable, wJumptableIndex
ld e, a
ld d, 0
ld hl, .JumpTable
add hl, de
add hl, de
ld a, [hli]
ld h, [hl]
ld l, a
jp hl
.JumpTable: .JumpTable:
; entries correspond to macros/scripts/trade_anims.asm enumeration ; entries correspond to macros/scripts/trade_anims.asm enumeration

View File

@ -432,16 +432,7 @@ Pokegear_FinishTilemap:
ret ret
PokegearJumptable: PokegearJumptable:
ld a, [wJumptableIndex] jumptable .Jumptable, wJumptableIndex
ld e, a
ld d, 0
ld hl, .Jumptable
add hl, de
add hl, de
ld a, [hli]
ld h, [hl]
ld l, a
jp hl
.Jumptable: .Jumptable:
; entries correspond to POKEGEARSTATE_* constants ; entries correspond to POKEGEARSTATE_* constants

View File

@ -16,16 +16,7 @@ PlayRadioShow:
ld [wCurRadioLine], a ld [wCurRadioLine], a
.ok .ok
; Jump to the currently loaded station. The index to which we need to jump is in wCurRadioLine. ; Jump to the currently loaded station. The index to which we need to jump is in wCurRadioLine.
ld a, [wCurRadioLine] jumptable RadioJumptable, wCurRadioLine
ld e, a
ld d, 0
ld hl, RadioJumptable
add hl, de
add hl, de
ld a, [hli]
ld h, [hl]
ld l, a
jp hl
RadioJumptable: RadioJumptable:
; entries correspond to constants/radio_constants.asm ; entries correspond to constants/radio_constants.asm

View File

@ -16,16 +16,7 @@ Printer_StartTransmission:
ret ret
PrinterJumptableIteration: PrinterJumptableIteration:
ld a, [wJumptableIndex] jumptable .Jumptable, wJumptableIndex
ld e, a
ld d, 0
ld hl, .Jumptable
add hl, de
add hl, de
ld a, [hli]
ld h, [hl]
ld l, a
jp hl
.Jumptable: .Jumptable:
dw Print_InitPrinterHandshake ; 00 dw Print_InitPrinterHandshake ; 00

View File

@ -224,16 +224,7 @@ ReplaceTimeOfDayPals:
dc 3, 2, 1, 0 dc 3, 2, 1, 0
GetTimePalette: GetTimePalette:
ld a, [wTimeOfDay] jumptable .TimePalettes, wTimeOfDay
ld e, a
ld d, 0
ld hl, .TimePalettes
add hl, de
add hl, de
ld a, [hli]
ld h, [hl]
ld l, a
jp hl
.TimePalettes: .TimePalettes:
dw .MorningPalette dw .MorningPalette

View File

@ -50,7 +50,7 @@ Init::
ldh [rOBP1], a ldh [rOBP1], a
ldh [rTMA], a ldh [rTMA], a
ldh [rTAC], a ldh [rTAC], a
ld [WRAM1_Begin], a ld [wd000], a
ld a, %100 ; Start timer at 4096Hz ld a, %100 ; Start timer at 4096Hz
ldh [rTAC], a ldh [rTAC], a

View File

@ -237,7 +237,7 @@ CheckObjectTime::
ld a, [hl] ld a, [hl]
cp -1 cp -1
jr z, .timeofday_always jr z, .timeofday_always
ld hl, .TimeOfDayValues_191e ld hl, .TimesOfDay
ld a, [wTimeOfDay] ld a, [wTimeOfDay]
add l add l
ld l, a ld l, a
@ -257,7 +257,7 @@ CheckObjectTime::
and a and a
ret ret
.TimeOfDayValues_191e: .TimesOfDay:
; entries correspond to TimeOfDay values ; entries correspond to TimeOfDay values
db MORN db MORN
db DAY db DAY
@ -362,7 +362,7 @@ CopyPlayerObjectTemplate::
call CopyBytes call CopyBytes
ret ret
Function19b8: ; unreferenced DeleteFollowerMapObject: ; unreferenced
call GetMapObject call GetMapObject
ld hl, MAPOBJECT_OBJECT_STRUCT_ID ld hl, MAPOBJECT_OBJECT_STRUCT_ID
add hl, bc add hl, bc
@ -376,7 +376,7 @@ Function19b8: ; unreferenced
pop af pop af
cp -1 cp -1
ret z ret z
cp $d cp NUM_OBJECT_STRUCTS
ret nc ret nc
ld b, a ld b, a
ld a, [wObjectFollow_Leader] ld a, [wObjectFollow_Leader]

View File

@ -11,7 +11,11 @@ ENDM
; Design patterns ; Design patterns
jumptable: MACRO jumptable: MACRO
if "\2" == "hl"
ld a, [hl]
else
ld a, [\2] ld a, [\2]
endc
ld e, a ld e, a
ld d, 0 ld d, 0
ld hl, \1 ld hl, \1

View File

@ -2455,16 +2455,7 @@ Function11d035:
AnimateEZChatCursor: AnimateEZChatCursor:
ld hl, SPRITEANIMSTRUCT_0C ld hl, SPRITEANIMSTRUCT_0C
add hl, bc add hl, bc
ld a, [hl] jumptable .Jumptable, hl
ld e, a
ld d, 0
ld hl, .Jumptable
add hl, de
add hl, de
ld a, [hli]
ld h, [hl]
ld l, a
jp hl
.Jumptable: .Jumptable:
dw .zero dw .zero

View File

@ -351,16 +351,7 @@ MobileTradeAnim_JumptableLoop:
ret ret
.ExecuteMobileTradeAnimCommand: .ExecuteMobileTradeAnimCommand:
ld a, [wJumptableIndex] jumptable .Jumptable, wJumptableIndex
ld e, a
ld d, 0
ld hl, .Jumptable
add hl, de
add hl, de
ld a, [hli]
ld h, [hl]
ld l, a
jp hl
.Jumptable: .Jumptable:
dw GetMobileTradeAnimByte ; 00 dw GetMobileTradeAnimByte ; 00

View File

@ -354,16 +354,7 @@ Function11619d:
ret ret
Function1161b8: Function1161b8:
ld a, [wc319] jumptable .Jumptable, wc319
ld e, a
ld d, 0
ld hl, .Jumptable
add hl, de
add hl, de
ld a, [hli]
ld h, [hl]
ld l, a
jp hl
.Jumptable: .Jumptable:
dw Function1161d5 dw Function1161d5

View File

@ -81,16 +81,7 @@ Function1176ee:
ret ret
Function117719: Function117719:
ld a, [wcd49] jumptable Jumptable_117728, wcd49
ld e, a
ld d, 0
ld hl, Jumptable_117728
add hl, de
add hl, de
ld a, [hli]
ld h, [hl]
ld l, a
jp hl
Jumptable_117728: Jumptable_117728:
dw Function117738 dw Function117738
@ -553,16 +544,7 @@ Function117acd:
ret ret
Function117ae9: Function117ae9:
ld a, [wJumptableIndex] jumptable .Jumptable, wJumptableIndex
ld e, a
ld d, $0
ld hl, .Jumptable
add hl, de
add hl, de
ld a, [hli]
ld h, [hl]
ld l, a
jp hl
.Jumptable: .Jumptable:
dw Function117b06 dw Function117b06

View File

@ -346,16 +346,7 @@ Function171a11:
ret ret
Function171a36: Function171a36:
ld a, [wcd49] jumptable Jumptable_171a45, wcd49
ld e, a
ld d, 0
ld hl, Jumptable_171a45
add hl, de
add hl, de
ld a, [hli]
ld h, [hl]
ld l, a
jp hl
Jumptable_171a45: Jumptable_171a45:
dw Function171a95 dw Function171a95

View File

@ -1661,8 +1661,9 @@ wDaysSince:: db
SECTION "WRAM 1", WRAMX SECTION "WRAM 1", WRAMX
wGBCOnlyDecompressBuffer:: ds 1 ; also uses the next $53f bytes for $540 total wGBCOnlyDecompressBuffer:: ; a $540-byte buffer that continues past this SECTION
wd000:: db
wDefaultSpawnpoint:: db wDefaultSpawnpoint:: db
UNION UNION