summaryrefslogtreecommitdiff
path: root/vba.py
diff options
context:
space:
mode:
authorBryan Bishop <kanzure@gmail.com>2013-06-16 11:34:30 -0500
committerBryan Bishop <kanzure@gmail.com>2013-06-16 11:34:30 -0500
commit9155ace6fd1a789a08e1a6acc4f2f3a51dbd950a (patch)
treee7d02ebe4a2edd14bbaa4cc3b950de11380bf39f /vba.py
parent9d4e21cabe1c1e18a7ded4dc3ce6061bfdf96c2f (diff)
make vba emulator wait until text is done drawing
Also, this fixes some bugs related to how button presses are handled. original-commit-id: 6c5ccae8078fd753314b5c63ba7c4a4b9e2ae402
Diffstat (limited to 'vba.py')
-rw-r--r--vba.py41
1 files changed, 36 insertions, 5 deletions
diff --git a/vba.py b/vba.py
index 317f705..f85f838 100644
--- a/vba.py
+++ b/vba.py
@@ -159,15 +159,21 @@ def button_combiner(buttons):
# recognized as "s" and "t" etc..
if isinstance(buttons, str):
if "restart" in buttons:
- buttons.replace("restart", "")
+ buttons = buttons.replace("restart", "")
result |= button_masks["restart"]
if "start" in buttons:
- buttons.replace("start", "")
+ buttons = buttons.replace("start", "")
result |= button_masks["start"]
if "select" in buttons:
- buttons.replace("select", "")
+ buttons = buttons.replace("select", "")
result |= button_masks["select"]
+ # allow for the "a, b" and "a b" formats
+ if ", " in buttons:
+ buttons = buttons.split(", ")
+ elif " " in buttons:
+ buttons = buttons.split(" ")
+
if isinstance(buttons, list):
if len(buttons) > 9:
raise Exception("can't combine more than 9 buttons at a time")
@@ -429,7 +435,7 @@ def set_memory_at(address, value):
"""
Gb.setMemoryAt(address, value)
-def press(buttons, steplimit=1):
+def press(buttons, holdsteps=1, aftersteps=1):
"""
Press a button. Use steplimit to say for how many steps you want to press
the button (try leaving it at the default, 1).
@@ -440,9 +446,14 @@ def press(buttons, steplimit=1):
number = buttons
else:
number = buttons
- for step_counter in range(0, steplimit):
+ for step_counter in range(0, holdsteps):
Gb.step(number)
+ # clear the button press
+ if aftersteps > 0:
+ for step_counter in range(0, aftersteps):
+ Gb.step(0)
+
def get_buttons():
"""
Returns the currentButtons[0] value (an integer with bits set for which
@@ -702,6 +713,26 @@ class crystal:
"""
@staticmethod
+ def text_wait(step_size=10, max_wait=500):
+ """
+ Watches for a sign that text is done being drawn to screen, then
+ presses the "A" button.
+
+ :param step_size: number of steps per wait loop
+ :param max_wait: number of wait loops to perform
+ """
+ for x in range(0, max_wait):
+ hi = get_memory_at(registers.sp + 1)
+ lo = get_memory_at(registers.sp)
+ address = ((hi << 8) | lo)
+ if address == 0xaef:
+ break
+ else:
+ nstep(step_size)
+
+ press("a", holdsteps=50, aftersteps=1)
+
+ @staticmethod
def walk_through_walls_slow():
memory = get_memory()
memory[0xC2FA] = 0