Index: misc/fix-inc.py
===================================================================
--- misc/fix-inc.py	(revision 6262b5c7974b08ad57f56d797cf7106c80531276)
+++ misc/fix-inc.py	(revision 6262b5c7974b08ad57f56d797cf7106c80531276)
@@ -0,0 +1,43 @@
+#!/usr/bin/env python3
+
+from sys import stdout
+
+with open("misc/c-files.txt", "r") as f:
+    for path in f:
+        path = path.rstrip()
+
+        if path == "ram/wdfield.c": # breaks pycparser
+            continue
+
+        if path[-2:] != ".c":
+            continue
+
+        stdout.write("fixing {}                    \r".format(path))
+        stdout.flush()
+
+        with open(path, "r") as f:
+            lines = f.read().split("\n")
+
+        beg = None
+        end = None
+        idx = 0
+
+        for line in lines:
+            if len(line) >= 8 and line[:8] == "#include":
+                if beg is None:
+                    beg = idx
+
+                end = idx
+
+            elif len(line) != 0 and beg is not None:
+                break
+
+            idx += 1
+
+        if beg is not None:
+            out = lines[0 : beg] + ["#include \"all.h\""] + lines[end + 1:] + [""]
+
+            with open(path, "w") as f:
+                f.write("\n".join(out))
+
+    print("")
Index: misc/gen-glob.py
===================================================================
--- misc/gen-glob.py	(revision 6262b5c7974b08ad57f56d797cf7106c80531276)
+++ misc/gen-glob.py	(revision 6262b5c7974b08ad57f56d797cf7106c80531276)
@@ -0,0 +1,139 @@
+#!/usr/bin/env python3
+
+from sys import stdout
+from pycparser import c_ast, parse_file, c_generator
+
+cross_gcc = "/opt/cross-m68k/bin/m68k-none-elf-gcc"
+gen = c_generator.CGenerator()
+
+inc_map = {
+    "int8_t": "stdint.h",
+    "uint8_t": "stdint.h",
+    "int16_t": "stdint.h",
+    "uint16_t": "stdint.h",
+    "int32_t": "stdint.h",
+    "uint32_t": "stdint.h"
+}
+
+with open("misc/c-files.txt", "r") as f:
+    for path in f:
+        path = path.rstrip()
+
+        if path == "ram/wdfield.c": # breaks pycparser
+            continue
+
+        stdout.write("reading {}                    \r".format(path))
+        stdout.flush()
+
+        ast = parse_file(path, use_cpp = True, cpp_path = cross_gcc,
+                         cpp_args = ["-E", "-I", "include", "-include", "predef.h"])
+        # ast.show()
+
+        funs = {}
+        vars = {}
+        incs = set()
+
+        for ext in ast.ext:
+            # assumes that includes come before .c files in c-files.txt, i.e.,
+            # that we've already seen the .h file, when its declarations are used
+            # by a .c file.
+
+            if ext.coord.file == path and path[-2:] == ".h":
+                if type(ext) is c_ast.Decl and \
+                   type(ext.type) is c_ast.Struct:
+                    inc_map[ext.type.name] = path.split("/")[-1]
+                    continue
+
+            if type(ext) is c_ast.Decl and \
+               (type(ext.type) is c_ast.TypeDecl or \
+                type(ext.type) is c_ast.PtrDecl or \
+                type(ext.type) is c_ast.ArrayDecl):
+                decl = ext
+                map = vars
+
+            elif type(ext) is c_ast.FuncDef:
+                decl = ext.decl
+                map = funs
+
+            else:
+                continue
+
+            if "extern" in decl.storage or \
+               "static" in decl.storage:
+                continue
+
+            decl.storage = ["extern"]
+            decl.init = None
+
+            toks = gen.visit(decl).split(" ")
+
+            for tok in toks:
+                if tok in inc_map:
+                    incs.add(inc_map[tok])
+
+            alig = ""
+
+            alig += toks[0] + "\t"
+            toks = toks[1:]
+
+            if toks[0] == "struct":
+                if len(toks[1]) > 7:
+                    raise Exception("identifier too long: {}".format(toks[1]))
+
+                alig += toks[0] + "\t" + toks[1] + "\t"
+                toks = toks[2:]
+
+            else:
+                alig += toks[0] + ("\t\t" if len(toks[0]) < 8 else "\t")
+                toks = toks[1:]
+ 
+            map[decl.name] = alig + " ".join(toks) + ";"
+
+        file = path.split("/")[-1]
+        glob = []
+
+        if len(vars) > 0:
+            glob.append("/*")
+            glob.append("   =============================================================================")
+            glob.append("\t" + file + " -- global variables")
+            glob.append("   =============================================================================")
+            glob.append("*/")
+            glob.append("")
+
+            for _, out in sorted(vars.items()):
+                glob.append(out)
+
+            glob.append("")
+
+        if len(funs) > 0:
+            glob.append("/*")
+            glob.append("   =============================================================================")
+            glob.append("\t" + file + " -- global functions")
+            glob.append("   =============================================================================")
+            glob.append("*/")
+            glob.append("")
+
+            for _, out in sorted(funs.items()):
+                glob.append(out)
+
+            glob.append("")
+
+        if len(glob) == 0:
+            continue
+
+        head = []
+        head.append("#pragma once")
+        head.append("")
+
+        if len(incs) > 0:
+            for inc in sorted(incs):
+                head.append("#include \"{}\"".format(inc))
+
+            head.append("")
+
+        glob = head + glob
+
+        with open(path[:-2] + ".x", "w") as f:
+            print("\n".join(glob), file = f)
+
+    print("")
Index: misc/proto.c
===================================================================
--- misc/proto.c	(revision e225e77aba20391e2188eb15a49190b1d473d368)
+++ misc/proto.c	(revision 6262b5c7974b08ad57f56d797cf7106c80531276)
@@ -1,2 +1,6 @@
+int8_t ac_code;
+int16_t errno;
+int16_t timers[1];
+
 // ---------- vvv ---------- wdfield.c
 
@@ -37,5 +41,5 @@
 }
 
-void wdnfld(int16_t k)
+int16_t wdnfld(int16_t k)
 {
 }
Index: misc/proto.x
===================================================================
--- misc/proto.x	(revision 6262b5c7974b08ad57f56d797cf7106c80531276)
+++ misc/proto.x	(revision 6262b5c7974b08ad57f56d797cf7106c80531276)
@@ -0,0 +1,89 @@
+#pragma once
+
+#include "score.h"
+#include "setjmp.h"
+#include "slice.h"
+#include "stdint.h"
+#include "vsdd.h"
+
+/*
+   =============================================================================
+	proto.c -- global variables
+   =============================================================================
+*/
+
+extern	int8_t		ac_code;
+extern	int16_t		errno;
+extern	int16_t		timers[];
+
+/*
+   =============================================================================
+	proto.c -- global functions
+   =============================================================================
+*/
+
+extern	void		GLCplot(uint16_t x, uint16_t y, uint16_t val);
+extern	void		Lo_RAM(void);
+extern	void		VIint(void);
+extern	void		_ptcl12(uint16_t *fat, uint16_t cl, uint16_t val);
+extern	void		clrvce(int16_t vce);
+extern	void		execins(int16_t vce, int16_t ins, int16_t tag);
+extern	void		execkey(int16_t trg, int16_t pch, int16_t vce, int16_t tag);
+extern	void		fpuclr(void);
+extern	void		fpuint(void);
+extern	uint16_t	fromfpu(uint16_t fputime);
+extern	void		halt(void);
+extern	void		hdvini(void);
+extern	void		jumpto(void *addr);
+extern	void		longjmp(struct JMP_BUF *env, int16_t val);
+extern	void		objclr(uint16_t obj);
+extern	void		objoff(uint16_t obj, uint16_t line, uint16_t num);
+extern	void		objon(uint16_t obj, uint16_t line, uint16_t num);
+extern	void		panic(void);
+extern	void		pntsup(void);
+extern	void		procpfl(uint16_t trig);
+extern	int32_t		rand24(void);
+extern	void		rjumpto(void *addr);
+extern	void		se_disp(struct s_entry *ep, int16_t sd, struct gdsel *gdstb[], int16_t cf);
+extern	struct	s_entry	*se_exec(struct s_entry *ep, int16_t sd);
+extern	uint16_t	setipl(uint16_t arg);
+extern	int16_t		setjmp(struct JMP_BUF *env);
+extern	void		setsio(void);
+extern	uint16_t	setsr(uint16_t sr);
+extern	void		sjumpto(void *addr, void *stack);
+extern	void		sreset(void);
+extern	uint16_t	tofpu(uint16_t time);
+extern	int32_t		trap13(int16_t fun, ...);
+extern	int32_t		trap14(int16_t fun, ...);
+extern	void		trap15(void);
+extern	void		tsetup(void);
+extern	void		tsplot4(int16_t *obase, int16_t nw, int16_t fg, int16_t row, int16_t col, int8_t *str, int16_t pitch);
+extern	int32_t		uldiv(int32_t divid, int32_t divis);
+extern	void		updfpu(void);
+extern	void		vbank(uint16_t b);
+extern	void		vclrav(uint16_t *adr, uint16_t row, uint16_t col, uint16_t atr, uint16_t len);
+extern	void		vcputs(int16_t *obase, int16_t nw, int16_t fg, int16_t bg, int16_t row, int16_t col, int8_t *str);
+extern	void		vcputsv(int16_t *obase, int16_t nw, int16_t fg, int16_t bg, int16_t row, int16_t col, int8_t *str, int16_t pitch);
+extern	void		vfwait(void);
+extern	void		vputa(uint16_t *sbase, uint16_t row, uint16_t col, uint16_t attrib);
+extern	void		vputc(uint16_t *sbase, uint16_t row, uint16_t col, uint16_t c, uint16_t attrib);
+extern	void		vputcv(uint16_t *adr, uint16_t row, uint16_t col, uint8_t chr, uint16_t atr, uint16_t cols);
+extern	void		vputp(struct octent *octad, int16_t xloc, int16_t yloc, int16_t val);
+extern	void		vsetav(uint16_t *adr, uint16_t row, uint16_t col, uint16_t atr, uint16_t len);
+extern	void		vsetcv(uint16_t *adr, uint16_t row, uint16_t col, uint16_t cfb, uint16_t len);
+extern	void		vsplot4(uint16_t *obase, uint16_t nw, uint16_t fg, uint16_t row, uint16_t col, int8_t *str, uint16_t pitch, uint16_t ht, int16_t cgtab[][256]);
+extern	void		vvputsv(uint16_t *obase, uint16_t nw, uint16_t fg, uint16_t bg, uint16_t row, uint16_t col, int8_t *str, uint16_t pitch, uint16_t ht, int16_t cgtab[][256]);
+extern	void		vwputp(struct octent *octad, int16_t xloc, int16_t yloc, int16_t val);
+extern	void		vwputs(int16_t *obase, int16_t nw, int16_t fg, int16_t bg, int16_t row, int16_t col, int8_t *str);
+extern	void		wdcxupd(void);
+extern	void		wdcyupd(void);
+extern	void		wdfield(void);
+extern	void		wdintp(void);
+extern	int16_t		wdnfld(int16_t k);
+extern	void		wdxkey(void);
+extern	void		wdykdn(void);
+extern	void		wdykup(void);
+extern	void		whupd(void);
+extern	void		wsupd(void);
+extern	void		xtrap15(void);
+
