From 7bfbadc5687a1eb297db0ff5956478a8bd38178f Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Sun, 22 Sep 2013 01:10:46 -0500 Subject: 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. --- pokemontools/vba/vba.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'pokemontools/vba/vba.py') 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. -- cgit v1.2.3