shithub: pokered

Download patch

ref: 120ba9664992cada4781e4d524304e4499e9083f
parent: bacc4594c0772dab004e4f97e21529a523918a89
author: yenatch <yenatch@gmail.com>
date: Fri Dec 6 17:40:46 EST 2013

handle preprocessing in one python procress; export asm labels

instead of running a process for each file, one process handles all files
rgbasm requires label EXPORT definitions for cross-object compiling. this is handled by globals.asm

--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,6 @@
+# global label defs are generated
+globals.asm
+
 # precompiled python
 *.pyc
 
--- a/Makefile
+++ b/Makefile
@@ -4,6 +4,8 @@
 .SECONDEXPANSION:
 
 
+TEXTQUEUE :=
+
 RED_OBJS  := pokered.o
 BLUE_OBJS := pokeblue.o
 
@@ -13,10 +15,12 @@
 
 # generate dependencies for each object
 $(shell $(foreach obj, $(OBJS), \
-	$(eval $(obj:.o=)_DEPENDENCIES := $(shell $(PYTHON) extras/pokemontools/scan_includes.py $(obj:.o=.asm))) \
+	$(eval $(obj:.o=)_DEPENDENCIES := $(shell $(PYTHON) extras/pokemontools/scan_includes.py $(obj:.o=.asm) | sed s/globals.asm//g)) \
 ))
+$(shell $(foreach obj, $(OBJS), \
+	$(eval ALL_DEPENDENCIES := $(ALL_DEPENDENCIES) $($(obj:.o=)_DEPENDENCIES)) \
+))
 
-
 all: $(ROMS)
 red:  pokered.gbc
 blue: pokeblue.gbc
@@ -27,6 +31,7 @@
 clean:
 	rm -f $(ROMS)
 	rm -f $(OBJS)
+	rm -f globals.asm
 	find -iname '*.tx' -delete
 	rm -f redrle
 
@@ -35,20 +40,26 @@
 	@echo "Wait! Need baserom.gbc first. Check README and INSTALL for details." && false
 
 %.asm: ;
-
 .asm.tx:
-	$(PYTHON) preprocessor.py < $< > $@
+	$(eval TEXTQUEUE := $(TEXTQUEUE) $<)
+	@rm -f $@
 
-$(OBJS): $$*.tx $$(patsubst %.asm, %.tx, $$($$*_DEPENDENCIES))
-	rgbasm -o $@ $(@:.o=.tx)
+globals.asm: $(ALL_DEPENDENCIES:.asm=.tx) $(OBJS:.o=.tx)
+	@touch $@
+	@$(PYTHON) prequeue.py $(TEXTQUEUE)
+globals.tx: globals.asm
+	@cp $< $@
 
-pokered.gbc: $(RED_OBJS)
-	rgblink -n $*.sym -m $*.map -o $@ $^
+$(OBJS): $$*.tx $$($$*_DEPENDENCIES$:.asm=.tx)
+	rgbasm -o $@ $*.tx
+
+pokered.gbc: globals.tx $(RED_OBJS)
+	rgblink -n $*.sym -m $*.map -o $@ $(RED_OBJS)
 	rgbfix -jsv -k 01 -l 0x33 -m 0x13 -p 0 -r 03 -t "POKEMON RED" $@
 	cmp baserom.gbc $@
 
-pokeblue.gbc: $(BLUE_OBJS)
-	rgblink -n $*.sym -m $*.map -o $@ $^
+pokeblue.gbc: globals.tx $(BLUE_OBJS)
+	rgblink -n $*.sym -m $*.map -o $@ $(BLUE_OBJS)
 	rgbfix -jsv -k 01 -l 0x33 -m 0x13 -p 0 -r 03 -t "POKEMON BLUE" $@
 	cmp blue.gbc $@
 
--- a/preprocessor.py
+++ b/preprocessor.py
@@ -1,10 +1,17 @@
 # -*- coding: utf-8 -*-
 
 import extras.pokemontools.preprocessor as preprocessor
+
 import extras.pokemontools.configuration as configuration
+config = configuration.Config()
 
 import sys
 
+from extras.pokemontools.crystal import (
+    callchannel,
+    loopchannel,
+)
+
 chars = {
 "ガ": 0x05,
 "ギ": 0x06,
@@ -260,14 +267,19 @@
 "9": 0xFF,
 }
 
-preprocessor.chars = chars
+def load_pokered_macros():
+    macros = [callchannel, loopchannel]
+    return macros
 
-from extras.pokemontools.crystal import (
-	callchannel,
-	loopchannel,
-)
+def setup_processor():
+    preprocessor.chars = chars
+    macros = load_pokered_macros()
+    processor = preprocessor.Preprocessor(config, macros)
+    return processor
 
-config = configuration.Config()
-macros = [callchannel, loopchannel]
-processor = preprocessor.Preprocessor(config, macros)
-processor.preprocess()
+def main():
+    processor = setup_processor()
+    processor.preprocess()
+
+if __name__ == '__main__':
+    main()
--- /dev/null
+++ b/prequeue.py
@@ -1,0 +1,29 @@
+# coding: utf-8
+"""
+Starting a new python process to preprocess each source file creates too much
+overhead. Instead, a list of files to preprocess is fed into a script run from
+a single process.
+"""
+
+import os
+import sys
+
+import preprocessor
+
+def main():
+    processor = preprocessor.setup_processor()
+
+    for source in sys.argv[1:]:
+        dest = os.path.splitext(source)[0] + '.tx'
+
+        stdout = sys.stdout
+
+        sys.stdin  = open(source, 'r')
+        sys.stdout = open(dest, 'w')
+
+        processor.preprocess()
+
+        sys.stdout = stdout
+
+if __name__ == '__main__':
+    main()