diff options
author | Bryan Bishop <kanzure@gmail.com> | 2013-11-10 16:29:23 -0600 |
---|---|---|
committer | Bryan Bishop <kanzure@gmail.com> | 2013-11-10 16:29:23 -0600 |
commit | 6b0d8ee855af252b48709c88a46c748c956af740 (patch) | |
tree | b4ed53f6157c5b14d9e6ca465a5cd3db522bab96 | |
parent | b71fbf3852fb1274b13b548e13b27303e155658c (diff) |
implement call_script to call CallScript
This is the entry point for calling in-game scripts.
-rw-r--r-- | pokemontools/vba/vba.py | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/pokemontools/vba/vba.py b/pokemontools/vba/vba.py index f69595b..42f5e5b 100644 --- a/pokemontools/vba/vba.py +++ b/pokemontools/vba/vba.py @@ -340,6 +340,54 @@ class crystal(object): ) ) + def call_script(self, address, bank=None, wram=False, force=False): + """ + Sets wram values so that the engine plays a script. + + :param address: address of the map script + :param bank: override for bank calculation (based on address) + :param wram: force bank to 0 + :param force: override an already-running script + """ + + ScriptFlags = 0xd434 + ScriptMode = 0xd437 + ScriptRunning = 0xd438 + ScriptBank = 0xd439 + ScriptPos = 0xd43a + NumScriptParents = 0xd43c + ScriptParents = 0xd43d + + num_possible_parents = 4 + len_parent = 3 + + mem = list(self.vba.memory) + + if mem[ScriptRunning] == 0xff: + if force: + # wipe the parent routine array + mem[NumScriptParents] = 0 + for i in xrange(num_possible_parents * len_parent): + mem[ScriptParents + i] = 0 + else: + raise Exception("a script is already running, use force=True") + + if wram: + bank = 0 + elif not bank: + bank = calculate_bank(address) + address = address % 0x4000 + 0x4000 * bool(bank) + + mem[ScriptFlags] |= 4 + mem[ScriptMode] = 1 + mem[ScriptRunning] = 0xff + + mem[ScriptBank] = bank + mem[ScriptPos] = address % 0x100 + mem[ScriptPos+1] = address / 0x100 + + self.vba.memory = mem + def text_wait(self, step_size=1, max_wait=200, sfx_limit=0, debug=False, callback=None): """ Presses the "A" button when text is done being drawn to screen. |