From dc63d8d51dd451b13fb5e1386edfc7bac0874ee6 Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Sun, 22 Sep 2013 00:49:44 -0500 Subject: re-implement save_state This can be used to dump state to a file based on the current configuration of the running instance. --- pokemontools/vba/vba.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'pokemontools/vba/vba.py') diff --git a/pokemontools/vba/vba.py b/pokemontools/vba/vba.py index d821999..d8ceebb 100644 --- a/pokemontools/vba/vba.py +++ b/pokemontools/vba/vba.py @@ -56,6 +56,27 @@ class crystal(object): if not os.path.exists(self.config.rom_path): raise Exception("rom_path is not configured properly; edit vba_config.py? " + str(rom_path)) + def save_state(self, name, state=None, override=False): + """ + Saves the given state to save_state_path. + + The file format must be ".sav", and this will be appended to your + string if necessary. + """ + if state == None: + state = self.vba.state + + if len(name) < 4 or name[-4:] != ".sav": + name += ".sav" + + save_path = os.path.join(self.config.save_state_path, name) + + if not override and os.path.exists(save_path): + raise Exception("oops, save state path already exists: {0}".format(save_path)) + + with open(save_path, "wb") as file_handler: + file_handler.write(state) + def call(self, bank, address): """ Jumps into a function at a certain address. -- cgit v1.2.3