summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBryan Bishop <kanzure@gmail.com>2013-01-27 17:00:51 -0600
committerBryan Bishop <kanzure@gmail.com>2013-01-27 17:00:51 -0600
commite5a2fa217490600281a7884fa024e789f1ebf025 (patch)
treece089fc50f214b4276fdf574c2771734a3321591
parent01691e2659fbeb2221f1374c3e5495094b9e2822 (diff)
remove a duplication of load_rom and load_asm
original-commit-id: f22bbdd722bad8e2700b5801b45d935b631de6c8
-rw-r--r--comparator.py16
-rw-r--r--crystal.py10
2 files changed, 11 insertions, 15 deletions
diff --git a/comparator.py b/comparator.py
index 2abf5cd..6d981e4 100644
--- a/comparator.py
+++ b/comparator.py
@@ -7,6 +7,8 @@ from crystal import (
get_label_from_line,
get_address_from_line_comment,
AsmSection,
+ direct_load_rom,
+ direct_load_asm,
)
from romstr import (
@@ -17,22 +19,12 @@ from romstr import (
def load_rom(path):
""" Loads a ROM file into an abbreviated RomStr object.
"""
-
- fh = open(path, "r")
- x = RomStr(fh.read())
- fh.close()
-
- return x
+ return direct_load_rom(filename=path)
def load_asm(path):
""" Loads source ASM into an abbreviated AsmList object.
"""
-
- fh = open(path, "r")
- x = AsmList(fh.read().split("\n"))
- fh.close()
-
- return x
+ return direct_load_asm(filename=path)
def findall_iter(sub, string):
# url: http://stackoverflow.com/a/3874760/687783
diff --git a/crystal.py b/crystal.py
index 2077c37..4353ad5 100644
--- a/crystal.py
+++ b/crystal.py
@@ -145,12 +145,16 @@ def load_rom(filename="../baserom.gbc"):
elif os.lstat(filename).st_size != len(rom):
return direct_load_rom(filename)
+def direct_load_asm(filename="../main.asm"):
+ """returns asm source code (AsmList) from a file"""
+ asm = open(filename, "r").read().split("\n")
+ asm = AsmList(asm)
+ return asm
def load_asm(filename="../main.asm"):
- """loads the asm source code into memory"""
+ """returns asm source code (AsmList) from a file (uses a global)"""
global asm
- asm = open(filename, "r").read().split("\n")
- asm = AsmList(asm)
+ asm = direct_load_asm(filename=filename)
return asm
def grouper(some_list, count=2):