summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSanqui <gsanky@gmail.com>2018-05-27 00:09:14 +0200
committerSanqui <gsanky@gmail.com>2018-05-27 00:11:32 +0200
commit775d9f7ef0f8436039567e9071cd39c405e998b5 (patch)
tree73799d68cdf822e41093bc123f3a29827e46c7be
Initial commit
-rw-r--r--.gitignore19
-rw-r--r--Makefile51
-rw-r--r--README.md3
-rw-r--r--main.asm4
-rw-r--r--tools/Makefile17
-rw-r--r--tools/scan_includes.c123
-rw-r--r--wram.asm0
7 files changed, 217 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..9f59b1b
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,19 @@
+*.gb
+*.sgb
+*.gbc
+*.sav
+*.sn1
+*.rtc
+
+*.o
+*.2bpp
+*.1bpp
+*.pcm
+*.map
+*.sym
+
+*~
+
+; binaries
+tools/scan_includes
+pret/
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..6b95aa7
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,51 @@
+.PHONY: all compare clean text
+
+.SUFFIXES:
+.SUFFIXES: .asm .o .gbc .png
+.SECONDEXPANSION:
+
+ROMS := pokegold-spaceworld.gb
+BASEROM := baserom.gb
+OBJS := main.o wram.o
+
+# Link objects together to build a rom.
+all: $(ROMS) compare
+
+tools:
+ $(MAKE) -C tools/
+
+define DEP
+$1: $2 $$(shell tools/scan_includes $2)
+ rgbasm -E -o $$@ $$<
+endef
+
+ifeq (,$(filter clean tools,$(MAKECMDGOALS)))
+$(info $(shell $(MAKE) -C tools))
+
+$(foreach obj, $(OBJS), $(eval $(call DEP,$(obj),$(obj:.o=.asm))))
+
+endif
+
+$(ROMS): $(OBJS)
+ rgblink -n $(ROMS:.gb=.sym) -m $(ROMS:.gb=.map) -O $(BASEROM) -o $@ $^
+ rgbfix -f -v -k 01 -l 0x33 -m 0x03 -p 0 -r 3 -t "POKEMON2GOLD" $@
+
+compare: $(ROMS) $(BASEROM)
+ cmp $^
+
+# Remove files generated by the build process.
+clean:
+ rm -rf $(ROMS) $(OBJS) $(ROMS:.gbc=.sym) build/*
+ find . \( -iname '*.1bpp' -o -iname '*.2bpp' -o -iname '*.pcm' \) -exec rm {} +
+
+%.2bpp: %.png
+ rgbgfx -o $@ $<
+
+%.1bpp: %.png
+ rgbgfx -d1 -o $@ $<
+
+%.tilemap: %.png
+ rgbgfx -t $@ $<
+%.gbcpal: %.png
+ rgbgfx -p $@ $<
+
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..f4922b1
--- /dev/null
+++ b/README.md
@@ -0,0 +1,3 @@
+baserom.gb is Gold_debug.sgb
+
+md5sum `2eadbed83b775c097ff79e5128d1184f`
diff --git a/main.asm b/main.asm
new file mode 100644
index 0000000..2e71857
--- /dev/null
+++ b/main.asm
@@ -0,0 +1,4 @@
+SECTION "Init", ROM0[$100]
+ nop
+ jp $52f
+
diff --git a/tools/Makefile b/tools/Makefile
new file mode 100644
index 0000000..b11babe
--- /dev/null
+++ b/tools/Makefile
@@ -0,0 +1,17 @@
+.PHONY: all clean
+
+CC := gcc
+CFLAGS := -O3 -std=c99 -Wall -Wextra
+
+tools := \
+ scan_includes \
+
+all: $(tools)
+ @:
+
+clean:
+ rm -f $(tools)
+
+%: %.c
+ $(CC) $(CFLAGS) -o $@ $<
+
diff --git a/tools/scan_includes.c b/tools/scan_includes.c
new file mode 100644
index 0000000..2babdcf
--- /dev/null
+++ b/tools/scan_includes.c
@@ -0,0 +1,123 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdbool.h>
+#include <getopt.h>
+
+void usage(void) {
+ printf("Usage: scan_includes [-h] [-s] filename\n"
+ "-h, --help\n"
+ " Print usage and exit\n"
+ "-s, --strict\n"
+ " Fail if a file cannot be read\n");
+}
+
+struct Options {
+ bool help;
+ bool strict;
+};
+
+struct Options Options = {0};
+
+void scan_file(char* filename) {
+ FILE *f = fopen(filename, "rb");
+ if (!f) {
+ if (Options.strict) {
+ fprintf(stderr, "Could not open file: '%s'\n", filename);
+ exit(1);
+ } else {
+ return;
+ }
+ }
+
+ fseek(f, 0, SEEK_END);
+ long size = ftell(f);
+ rewind(f);
+
+ char *buffer = malloc(size + 1);
+ char *orig = buffer;
+ size = fread(buffer, 1, size, f);
+ buffer[size] = '\0';
+ fclose(f);
+
+ for (; buffer && (buffer - orig < size); buffer++) {
+ bool is_include = false;
+ bool is_incbin = false;
+ switch (*buffer) {
+ case ';':
+ buffer = strchr(buffer, '\n');
+ if (!buffer) {
+ fprintf(stderr, "%s: no newline at end of file\n", filename);
+ }
+ break;
+
+ case 'i':
+ case 'I':
+ if ((strncmp(buffer, "INCBIN", 6) == 0) || (strncmp(buffer, "incbin", 6) == 0)) {
+ is_incbin = true;
+ } else if ((strncmp(buffer, "INCLUDE", 7) == 0) || (strncmp(buffer, "include", 7) == 0)) {
+ is_include = true;
+ }
+ if (is_incbin || is_include) {
+ buffer = strchr(buffer, '"');
+ if (!buffer++) {
+ break;
+ }
+ int length = strcspn(buffer, "\"");
+ char *include = malloc(length + 1);
+ strncpy(include, buffer, length);
+ include[length] = '\0';
+ printf("%s ", include);
+ if (is_include) {
+ scan_file(include);
+ }
+ free(include);
+ buffer = strchr(buffer, '"');
+ }
+ break;
+
+ }
+ if (!buffer) {
+ break;
+ }
+
+ }
+
+ free(orig);
+}
+
+int main(int argc, char* argv[]) {
+ int i = 0;
+ struct option long_options[] = {
+ {"strict", no_argument, 0, 's'},
+ {"help", no_argument, 0, 'h'},
+ {0}
+ };
+ int opt = -1;
+ while ((opt = getopt_long(argc, argv, "sh", long_options, &i)) != -1) {
+ switch (opt) {
+ case 's':
+ Options.strict = true;
+ break;
+ case 'h':
+ Options.help = true;
+ break;
+ default:
+ usage();
+ exit(1);
+ break;
+ }
+ }
+ argc -= optind;
+ argv += optind;
+ if (Options.help) {
+ usage();
+ return 0;
+ }
+ if (argc < 1) {
+ usage();
+ exit(1);
+ }
+ scan_file(argv[0]);
+ return 0;
+}
diff --git a/wram.asm b/wram.asm
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/wram.asm