summaryrefslogtreecommitdiff
path: root/pokemontools/vba
diff options
context:
space:
mode:
Diffstat (limited to 'pokemontools/vba')
-rw-r--r--pokemontools/vba/autoplayer.py12
-rw-r--r--pokemontools/vba/keyboard.py5
-rw-r--r--pokemontools/vba/vba.py36
3 files changed, 29 insertions, 24 deletions
diff --git a/pokemontools/vba/autoplayer.py b/pokemontools/vba/autoplayer.py
index af14d47..2d2e8af 100644
--- a/pokemontools/vba/autoplayer.py
+++ b/pokemontools/vba/autoplayer.py
@@ -2,12 +2,14 @@
"""
Programmatic speedrun of Pokémon Crystal
"""
+from __future__ import print_function
+from __future__ import absolute_import
import os
import pokemontools.configuration as configuration
# bring in the emulator and basic tools
-import vba as _vba
+from . import vba as _vba
def skippable(func):
"""
@@ -394,13 +396,13 @@ class SpeedRunner(Runner):
self.cry.text_wait()
hp = self.cry.get_enemy_hp()
- print "enemy hp is: " + str(hp)
+ print("enemy hp is: " + str(hp))
if hp == 0:
- print "enemy hp is zero, exiting"
+ print("enemy hp is zero, exiting")
break
else:
- print "enemy hp is: " + str(hp)
+ print("enemy hp is: " + str(hp))
attacks = attacks - 1
@@ -417,7 +419,7 @@ class SpeedRunner(Runner):
# happens.
self.cry.text_wait(max_wait=30, debug=True)
- print "okay, back in the overworld"
+ print("okay, back in the overworld")
cur_hp = ((self.cry.vba.memory[0xdd01] << 8) | self.cry.vba.memory[0xdd02])
move_pp = self.cry.vba.memory[0xdcf6] # move 1 pp
diff --git a/pokemontools/vba/keyboard.py b/pokemontools/vba/keyboard.py
index 4a07e57..a3d7611 100644
--- a/pokemontools/vba/keyboard.py
+++ b/pokemontools/vba/keyboard.py
@@ -3,6 +3,7 @@
This file constructs a networkx.DiGraph object called graph, which can be used
to find the shortest path of keypresses on the keyboard to type a word.
"""
+from __future__ import print_function
import os
import itertools
@@ -44,7 +45,7 @@ def convert_nodes_to_button_press(node1, node2):
"""
Determines the button necessary to switch from node1 to node2.
"""
- print "getting button press for state transition: " + node1 + " -> " + node2
+ print("getting button press for state transition: " + node1 + " -> " + node2)
return graph.get_edge_data(node1, node2)["key"]
def plan_typing(text, current="A"):
@@ -56,7 +57,7 @@ def plan_typing(text, current="A"):
if target == current:
buttons.append("a")
else:
- print "Finding the shortest path between " + current + " and " + target
+ print("Finding the shortest path between " + current + " and " + target)
more_buttons = shortest_path(current, target)
buttons.extend(more_buttons)
buttons.append("a")
diff --git a/pokemontools/vba/vba.py b/pokemontools/vba/vba.py
index 204e102..3ec347c 100644
--- a/pokemontools/vba/vba.py
+++ b/pokemontools/vba/vba.py
@@ -2,6 +2,8 @@
"""
VBA automation
"""
+from __future__ import print_function
+from __future__ import absolute_import
import os
import sys
@@ -18,7 +20,7 @@ from pokemontools.map_names import (
map_names,
)
-import keyboard
+from . import keyboard
# just use a default config for now until the globals are removed completely
import pokemontools.configuration as configuration
@@ -183,9 +185,9 @@ class crystal(object):
self.vba.write_memory_at(self.registers.sp + 1, value >> 8)
self.vba.write_memory_at(self.registers.sp, value & 0xFF)
if list(self.vba.memory[self.registers.sp : self.registers.sp + 2]) != [value & 0xFF, value >> 8]:
- print "desired memory values: " + str([value & 0xFF, value >> 8] )
- print "actual memory values: " + str(list(self.vba.memory[self.registers.sp : self.registers.sp + 2]))
- print "wrong value at " + hex(self.registers.sp) + " expected " + hex(value) + " but got " + hex(self.vba.read_memory_at(self.registers.sp))
+ print("desired memory values: " + str([value & 0xFF, value >> 8] ))
+ print("actual memory values: " + str(list(self.vba.memory[self.registers.sp : self.registers.sp + 2])))
+ print("wrong value at " + hex(self.registers.sp) + " expected " + hex(value) + " but got " + hex(self.vba.read_memory_at(self.registers.sp)))
def get_stack(self):
"""
@@ -426,7 +428,7 @@ class crystal(object):
address = ((hi << 8) | lo)
if address in range(0xa1b, 0xa46) + range(0xaaf, 0xaf5): # 0xaef:
- print "pressing, then breaking.. address is: " + str(hex(address))
+ print("pressing, then breaking.. address is: " + str(hex(address)))
# set CurSFX
self.vba.write_memory_at(0xc2bf, 0)
@@ -436,19 +438,19 @@ class crystal(object):
# check if CurSFX is SFX_READ_TEXT_2
if self.vba.read_memory_at(0xc2bf) == 0x8:
if "CANCEL Which" in self.get_text():
- print "probably the 'switch pokemon' menu"
+ print("probably the 'switch pokemon' menu")
return
else:
- print "cursfx is set to SFX_READ_TEXT_2, looping.."
- print self.get_text()
+ print("cursfx is set to SFX_READ_TEXT_2, looping..")
+ print(self.get_text())
return self.text_wait(step_size=step_size, max_wait=max_wait, debug=debug, callback=callback, sfx_limit=sfx_limit)
else:
if sfx_limit > 0:
sfx_limit = sfx_limit - 1
- print "decreasing sfx_limit"
+ print("decreasing sfx_limit")
else:
# probably the last textbox in a sequence
- print "cursfx is not set to SFX_READ_TEXT_2, so: breaking"
+ print("cursfx is not set to SFX_READ_TEXT_2, so: breaking")
break
else:
@@ -456,19 +458,19 @@ class crystal(object):
# yes/no box or the name selection box
if address in range(0xa46, 0xaaf):
- print "probably at a yes/no box.. exiting."
+ print("probably at a yes/no box.. exiting.")
break
# date/time box (day choice)
# 0x47ab is the one from the intro, 0x49ab is the one from mom.
elif 0x47ab in stack or 0x49ab in stack: # was any([x in stack for x in range(0x46EE, 0x47AB)])
if not self.is_in_battle():
- print "probably at a date/time box ? exiting."
+ print("probably at a date/time box ? exiting.")
break
# "How many minutes?" selection box
elif 0x4826 in stack:
- print "probably at a \"How many minutes?\" box ? exiting."
+ print("probably at a \"How many minutes?\" box ? exiting.")
break
self.vba.step(count=step_size)
@@ -482,7 +484,7 @@ class crystal(object):
if callback != None:
result = callback()
if result == True:
- print "callback returned True, exiting"
+ print("callback returned True, exiting")
return
# only useful when debugging. When this is left on, text that
@@ -492,7 +494,7 @@ class crystal(object):
max_wait = max_wait - 1
if max_wait == 0:
- print "max_wait was hit"
+ print("max_wait was hit")
def walk_through_walls_slow(self):
memory = self.vba.memory
@@ -852,7 +854,7 @@ class crystal(object):
"""
while limit > 0:
if self.vba.read_memory_at(0xd438) != 255:
- print "script is done executing"
+ print("script is done executing")
return
else:
self.vba.step()
@@ -861,7 +863,7 @@ class crystal(object):
limit = limit - 1
if limit == 0:
- print "limit ran out"
+ print("limit ran out")
def move(self, cmd):
"""