Browse Source

automatically fix deprecated section name 'HOME'

master
Holly 3 years ago
parent
commit
ad3b974f91
2 changed files with 30 additions and 0 deletions
  1. +1
    -0
      compile.bat
  2. +29
    -0
      home2rom0.py

+ 1
- 0
compile.bat View File

@ -1,3 +1,4 @@
home2rom0.py %1
rgbasm -o%~n1.obj %1
rgblink -m%~n1.map -n%~n1.sym -o%~n1.gb %~n1.obj
rgbfix -p255 -v %~n1.gb

+ 29
- 0
home2rom0.py View File

@ -0,0 +1,29 @@
#!/usr/bin/env python3
import re
import sys
import os
def get_includes(code):
return re.findall(r'INCLUDE\s+"(.+\.z80)"', code, flags=re.IGNORECASE)
def fix_section_name(filename):
with open(filename, 'r+') as f:
fixed, n = re.subn(r'(SECTION\s+".+",\s+)HOME', r'\1ROM0', f.read(), flags=re.IGNORECASE)
if n: # don't touch unchanged files
f.seek(0)
f.write(fixed)
return n
def main(args):
with open(args[0]) as code:
filenames = get_includes(code.read())
subs = sum((fix_section_name(file) for file in filenames))
print("Fixed {} deprecated section name{}.".format(subs, '' if subs == 1 else 's'))
if __name__ == "__main__":
args = sys.argv[1:]
if not args:
sys.exit("Usage: {} main_game_file.z80".format(os.path.basename('./' + __file__)))
main(args)

Loading…
Cancel
Save