summaryrefslogtreecommitdiff
path: root/pokemontools/vba/vba.py
diff options
context:
space:
mode:
authorBryan Bishop <kanzure@gmail.com>2013-09-22 00:49:44 -0500
committerBryan Bishop <kanzure@gmail.com>2013-09-22 00:49:44 -0500
commitdc63d8d51dd451b13fb5e1386edfc7bac0874ee6 (patch)
tree15fcbac6e604d6a68163d20c3f525bc6d1599a7f /pokemontools/vba/vba.py
parent6b56969ccf00262187071e95568cee89f637692b (diff)
re-implement save_state
This can be used to dump state to a file based on the current configuration of the running instance.
Diffstat (limited to 'pokemontools/vba/vba.py')
-rw-r--r--pokemontools/vba/vba.py21
1 files changed, 21 insertions, 0 deletions
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.