Last active
December 23, 2015 03:29
-
-
Save jedie/6573808 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
import sys | |
# from: | |
# https://github.com/jedie/DragonPy/blob/master/Dragon32_mem_info.py | |
# https://github.com/jedie/DragonPy/blob/4dcacb77f7797e0056b380d4c530f6361b689746/Dragon32_mem_info.py | |
from Dragon32_mem_info import DragonMemInfo | |
class DragonMemInfo2(DragonMemInfo): | |
def __init__(self, max): | |
self.max = max | |
def get_info(self, addr): | |
mem_info = [] | |
for start, end, txt in self.MEM_INFO: | |
if end-start>=self.max: | |
continue | |
if start <= addr <= end: | |
mem_info.append( | |
(start, end, txt) | |
) | |
if not mem_info: | |
return | |
results = [] | |
for start, end, txt in mem_info: | |
if start == end: | |
results.append("$%x: %s" % (start, txt)) | |
else: | |
results.append("$%x-$%x: %s" % (start, end, txt)) | |
return ", ".join(results) | |
mem_info = DragonMemInfo2(max=4000) | |
in_file = file("d32.asm", "r") | |
out_file = file("d32_commended.asm", "w") | |
regex = re.compile("#\$|L_([0-9a-fA-F]+)") | |
for line in in_file: | |
m = regex.findall(line) | |
line = line.replace("\t", " ") | |
if not m: | |
continue | |
addr = m[0] | |
if not addr: | |
continue | |
#~ print " *** ", addr | |
try: | |
addr = int(addr,16) | |
except Exception, err: | |
print "Error converting %s: %s in line %s" % (repr(addr),err, line) | |
raise | |
info = mem_info.get_info(addr) | |
if info: | |
#~ print " *** ", addr | |
line = "%-33s; %s\n" % (line.rstrip(), info) | |
sys.stdout.write(line) | |
out_file.write(line) | |
in_file.close() | |
out_file.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment