diff options
author | Bryan Bishop <kanzure@gmail.com> | 2013-09-22 01:10:46 -0500 |
---|---|---|
committer | Bryan Bishop <kanzure@gmail.com> | 2013-09-22 01:10:46 -0500 |
commit | 7bfbadc5687a1eb297db0ff5956478a8bd38178f (patch) | |
tree | 4e89a2d976fbc12f19d9ce1b1d6d099ace9f7b8a | |
parent | f83fc26b499a55d5611e16726a356981b682dd63 (diff) |
implement a vba helper func for state loading
This re-implements the load_state method that previously existed. I
forget why it was removed, but basically a similar function is needed
again, and it doesn't entirely belong in the emulator or in the emulator
wrapper because these save states are game-specific.
-rw-r--r-- | pokemontools/vba/vba.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/pokemontools/vba/vba.py b/pokemontools/vba/vba.py index 0818b93..7dc0d8f 100644 --- a/pokemontools/vba/vba.py +++ b/pokemontools/vba/vba.py @@ -77,6 +77,30 @@ class crystal(object): with open(save_path, "wb") as file_handler: file_handler.write(state) + def load_state(self, name, loadit=True): + """ + Read a state from file based on the name of the state. + + Looks in save_state_path for a file with this name (".sav" is + optional). + + @param loadit: whether or not to set the emulator to this state + """ + save_path = os.path.join(self.config.save_state_path, name) + + if not os.path.exists(save_path): + if len(name) < 4 or name[-4:] != ".sav": + name += ".sav" + save_path = os.path.join(save_state_path, name) + + with open(save_path, "rb") as file_handler: + state = file_handler.read() + + if loadit: + self.vba.state = state + + return state + def call(self, bank, address): """ Jumps into a function at a certain address. |