summaryrefslogtreecommitdiff
path: root/src/home/effect_commands.asm
diff options
context:
space:
mode:
authorDaniel Harding <33dannye@gmail.com>2021-09-19 00:21:14 -0500
committerGitHub <noreply@github.com>2021-09-19 00:21:14 -0500
commitdf67aac83b466dadf5f74c881bf84dd9ef19bdfc (patch)
tree47501aced2d256052b8f78bc97328d5af5703add /src/home/effect_commands.asm
parente4bce9b7ee5e89f8edfd921de2379f0fa06af206 (diff)
parent8dee6b7a11e85d6d4b9f8ec9fb9d53a499fd37dc (diff)
Merge pull request #110 from ElectroDeoxys/master
Split Home bank
Diffstat (limited to 'src/home/effect_commands.asm')
-rw-r--r--src/home/effect_commands.asm85
1 files changed, 85 insertions, 0 deletions
diff --git a/src/home/effect_commands.asm b/src/home/effect_commands.asm
new file mode 100644
index 0000000..9446d33
--- /dev/null
+++ b/src/home/effect_commands.asm
@@ -0,0 +1,85 @@
+; Checks if the command type at a is one of the commands of the attack or
+; card effect currently in use, and executes its associated function if so.
+; input:
+ ; a = command type to check
+ ; [wLoadedAttackEffectCommands] = pointer to list of commands of current attack or trainer card
+TryExecuteEffectCommandFunction:
+ push af
+ ; grab pointer to command list from wLoadedAttackEffectCommands
+ ld hl, wLoadedAttackEffectCommands
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+ pop af
+ call CheckMatchingCommand
+ jr nc, .execute_function
+ ; return if no matching command was found
+ or a
+ ret
+
+.execute_function
+ ; execute the function at [wEffectFunctionsBank]:hl
+ ldh a, [hBankROM]
+ push af
+ ld a, [wEffectFunctionsBank]
+ call BankswitchROM
+ or a
+ call CallHL
+ push af
+ ; restore original bank and return
+ pop bc
+ pop af
+ call BankswitchROM
+ push bc
+ pop af
+ ret
+
+; input:
+ ; a = command type to check
+ ; hl = list of commands of current attack or trainer card
+; return nc if command type matching a is found, carry otherwise
+CheckMatchingCommand:
+ ld c, a
+ ld a, l
+ or h
+ jr nz, .not_null_pointer
+ ; return carry if pointer is NULL
+ scf
+ ret
+
+.not_null_pointer
+ ldh a, [hBankROM]
+ push af
+ ld a, BANK(EffectCommands)
+ call BankswitchROM
+ ; store the bank number of command functions ($b) in wEffectFunctionsBank
+ ld a, BANK("Effect Functions")
+ ld [wEffectFunctionsBank], a
+.check_command_loop
+ ld a, [hli]
+ or a
+ jr z, .no_more_commands
+ cp c
+ jr z, .matching_command_found
+ ; skip function pointer for this command and move to the next one
+ inc hl
+ inc hl
+ jr .check_command_loop
+
+.matching_command_found
+ ; load function pointer for this command
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+ ; restore bank and return nc
+ pop af
+ call BankswitchROM
+ or a
+ ret
+
+.no_more_commands
+ ; restore bank and return c
+ pop af
+ call BankswitchROM
+ scf
+ ret