]> github.com/historicalsource and other repositories - defender-1.git/commitdiff
Add original files and updated readme
authorRobert Hogan <robhogan@gmail.com>
Sun, 11 Jul 2021 12:31:28 +0000 (13:31 +0100)
committerRobert Hogan <robhogan@gmail.com>
Sun, 11 Jul 2021 12:31:28 +0000 (13:31 +0100)
62 files changed:
Makefile
README.md
orig/D8572.jpg [new file with mode: 0644]
orig/RedLabelROMBoardSchema.png [new file with mode: 0644]
orig/RedLabelROMChart.png [new file with mode: 0644]
orig/WilliamsArcadeClassics/DEFENDER.EXE [new file with mode: 0644]
orig/WilliamsArcadeClassics/defender.rom [moved from orig/defender.rom with 100% similarity]
orig/WilliamsArcadeClassics/romgrab [new file with mode: 0755]
orig/WilliamsArcadeClassics/romgrab.c [new file with mode: 0644]
orig/defender-bluelabel/.defeng02.bin.swp [new file with mode: 0644]
orig/defender-bluelabel/defeng02.bin [new file with mode: 0644]
orig/defender-bluelabel/defeng06.bin [new file with mode: 0644]
orig/defender-bluelabel/defeng07.bin [new file with mode: 0644]
orig/defender-bluelabel/defeng08.bin [new file with mode: 0644]
orig/defender-bluelabel/defeng09.bin [new file with mode: 0644]
orig/defender-bluelabel/defeng10.bin [new file with mode: 0644]
orig/defender-bluelabel/defeng11.bin [new file with mode: 0644]
orig/defender-bluelabel/defeng12.bin [new file with mode: 0644]
orig/defender-bluelabel/wb01.bin [new file with mode: 0644]
orig/defender-bluelabel/wb03.bin [new file with mode: 0644]
orig/defender-greenlabel/decoder.1 [new file with mode: 0644]
orig/defender-greenlabel/defend.snd [new file with mode: 0644]
orig/defender-greenlabel/defeng01.bin [new file with mode: 0644]
orig/defender-greenlabel/defeng02.bin [new file with mode: 0644]
orig/defender-greenlabel/defeng03.bin [new file with mode: 0644]
orig/defender-greenlabel/defeng04.bin [new file with mode: 0644]
orig/defender-greenlabel/defeng06.bin [new file with mode: 0644]
orig/defender-greenlabel/defeng07.bin [new file with mode: 0644]
orig/defender-greenlabel/defeng08.bin [new file with mode: 0644]
orig/defender-greenlabel/defeng09.bin [new file with mode: 0644]
orig/defender-greenlabel/defeng10.bin [new file with mode: 0644]
orig/defender-greenlabel/defeng11.bin [new file with mode: 0644]
orig/defender-greenlabel/defeng12.bin [new file with mode: 0644]
orig/defender-redlabel/decoder.2 [new file with mode: 0644]
orig/defender-redlabel/decoder.3 [new file with mode: 0644]
orig/defender-redlabel/defend.1 [new file with mode: 0644]
orig/defender-redlabel/defend.10 [new file with mode: 0644]
orig/defender-redlabel/defend.11 [new file with mode: 0644]
orig/defender-redlabel/defend.12 [new file with mode: 0644]
orig/defender-redlabel/defend.2 [new file with mode: 0644]
orig/defender-redlabel/defend.3 [new file with mode: 0644]
orig/defender-redlabel/defend.4 [new file with mode: 0644]
orig/defender-redlabel/defend.6 [new file with mode: 0644]
orig/defender-redlabel/defend.7 [new file with mode: 0644]
orig/defender-redlabel/defend.8 [new file with mode: 0644]
orig/defender-redlabel/defend.9 [new file with mode: 0644]
orig/defender-redlabel/defend.snd [new file with mode: 0644]
orig/defender-whitelabel/decoder.1 [new file with mode: 0644]
orig/defender-whitelabel/rom1.bin [new file with mode: 0644]
orig/defender-whitelabel/rom10.bin [new file with mode: 0644]
orig/defender-whitelabel/rom11.bin [new file with mode: 0644]
orig/defender-whitelabel/rom12.bin [new file with mode: 0644]
orig/defender-whitelabel/rom2.bin [new file with mode: 0644]
orig/defender-whitelabel/rom3.bin [new file with mode: 0644]
orig/defender-whitelabel/rom6.bin [new file with mode: 0644]
orig/defender-whitelabel/rom7.bin [new file with mode: 0644]
orig/defender-whitelabel/rom8.bin [new file with mode: 0644]
orig/defender-whitelabel/rom9.bin [new file with mode: 0644]
orig/dfndr_l4/ic14.532 [new file with mode: 0644]
orig/dfndr_l4/ic17.532 [new file with mode: 0644]
orig/dfndr_l4/ic20.532 [new file with mode: 0644]
orig/dfndr_l4/sound12.716 [new file with mode: 0644]

index 313847be624a4ae9910e54caa3a5c1588588300d..299c76143d6c21ec12fb76f8806a8a1950ef5051 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -21,8 +21,7 @@ defender:
 
        $(shell mkdir -p $(DIRS))
        #
-       # Build amode1
-       # The equivalent of: RASM PHR2,DEFA2,DEFB2,AMODE0;-X (ELSE CREF SYMBOL OVERFLOW)
+       # Build amode1 # The equivalent of: RASM PHR2,DEFA2,DEFB2,AMODE0;-X (ELSE CREF SYMBOL OVERFLOW)
        ./asm6809/src/asm6809 -B src/phr6.src src/defa7.src src/defb6.src src/amode1.src\
                        -l bin/defa7-defb6-amode1.lst  -o bin/defa7-defb6-amode1.o
        #
@@ -43,18 +42,19 @@ defender:
        ./asm6809/src/asm6809 -B src/mess0.src src/romf8.src src/romc0.src src/romc8.src\
                        -l bin/roms.lst -o bin/roms.o
 
+defender.rom: defender
        ./ChainFilesToRom.py defender.rom\
                bin/defa7-defb6-amode1.o,0x0001,0x8000,0x1000,"amode"\
                bin/defa7-defb6-amode1.o,0xaeea,0x8ee9,0x0117,"amode tail"\
                bin/roms.o,0x0001,0x9000,0x0c50,"mess0"\
-               orig/defender.rom,0x9c51,0x9c50,0x03b0,"rom without source"\
+               orig/WilliamsArcadeClassics/defender.rom,0x9c51,0x9c50,0x03b0,"rom without source"\
                bin/roms.o,0xa000,0x9fff,0x1000,"romf8 romc0 romc8"\
-               orig/defender.rom,0xaff1,0xaff0,0x0010,"16 stray bytes"\
+               orig/WilliamsArcadeClassics/defender.rom,0xaff1,0xaff0,0x0010,"16 stray bytes"\
                bin/blk71.o,0x0001,0xb000,0x1000,"blk71"\
-               orig/defender.rom,0xb773,0xb772,0x0006,"6 stray bytes"\
+               orig/WilliamsArcadeClassics/defender.rom,0xb773,0xb772,0x0006,"6 stray bytes"\
                bin/roms.o,0xa779,0xb778,0x0088,"romc0"\
-               orig/defender.rom,0xb7f1,0xb7f0,0x0001,"1 stray byte"\
-               orig/defender.rom,0xc1e1,0xc1e0,0x0e20,"rom without source"\
+               orig/WilliamsArcadeClassics/defender.rom,0xb7f1,0xb7f0,0x0001,"1 stray byte"\
+               orig/WilliamsArcadeClassics/defender.rom,0xc1e1,0xc1e0,0x0e20,"rom without source"\
                bin/defa7-defb6.o,0x0371,0xd000,0x2c60,"defa7 defb6"\
                bin/samexap7.o,0x0001,0xfc60,0x02f8,"samexap7"\
                bin/defa7-defb6.o,0x32c9,0xff58,0x0230,"defa7 defb6 2"
@@ -64,4 +64,5 @@ defender:
 clean:
        -rm bin/*.o
        -rm bin/*.lst
-       -rm bin/*.asm
+       -rm defender.rom
+       -rm defend*.bin
index f5bae05b13bc07f6cca4df4fb5a7526e9937d579..e0a2ca08e442c327688f7b0e5869278093fd0606 100644 (file)
--- a/README.md
+++ b/README.md
@@ -1,11 +1,11 @@
 # Defender (1981) by Eugene Jarvis and Sam Dicker
 <img src="https://user-images.githubusercontent.com/58846/125094063-d8c90380-e0ca-11eb-91b1-a3e80ef0e377.png" height=250><img src="https://user-images.githubusercontent.com/58846/125094574-4aa14d00-e0cb-11eb-9cf9-6dec489585f4.gif" height=250>
 
-[<img src="https://img.shields.io/badge/Lastest%20Release-Jaguar-blue.svg">](https://github.com/mwenge/vlm/releases/download/v0.1/VirtualLightMachine.jag)
+[<img src="https://img.shields.io/badge/Lastest%20Release-Defender-blue.svg">](https://github.com/mwenge/defender/releases/download/v0.1/defender.rom)
 
 This is the source code for the Williams arcade game Defender.
 
-The source code can be compiled into an executable that you can run in Windows or Linux.
+The source code can be compiled into an executable that you can run it in Windows or Linux.
 
 
 <!-- vim-markdown-toc GFM -->
@@ -27,7 +27,7 @@ sudo apt install build-essentials wine python3
 
 ### Build the assembler toolchain
 
-We use `asm6809` to assembler the source code. 
+We use [`asm6809`](https://www.6809.org.uk/asm6809/) to assembler the source code. 
 
 First you must run the following to set up the git submodules containing the assembler toolchain:
 
@@ -55,14 +55,147 @@ make defender
 
 ## Play Defender
 
-You can run the VLM as follows using `t2k.exe`:
+Coming soon.
+
+## Notes on the Source Code
+
+The source code in [src](src) was originally retrieved from https://github.com/historical-source/defender. It is
+the code for the 'Red Label' version of the game. There were four versions of the game released: White Label, Blue Label,
+Green Label, and Red Label; in that order. Each release was a circuit board with the compiled code split across a 
+number of different ROM chip. This image of the Red Label ROM board from [Scott Tunstall's site](https://www.robotron-2084.co.uk/techwilliamshardwareid.html)
+gives you an idea of what such a board looks like:
+
+<img src="orig/D8572.jpg" size=250>
+
+If you compare this image to [the file listing for the Red Label roms](orig/defender-redlabel) you'll notice that the missing chip on the board corresponds
+to a missing file `defend.5`:
 ```sh
-wine ./utils/t2k.exe
+[robert@mwenge-desktop defender-redlabel (master)]$ ls -al
+total 64
+drwxrwxr-x 2 robert robert 4096 Jul 11 10:32 .
+drwxrwxr-x 8 robert robert 4096 Jul 11 11:02 ..
+-rw-rw-r-- 1 robert robert 2048 Dec 24  1996 defend.1
+-rw-rw-r-- 1 robert robert 2048 Dec 24  1996 defend.10
+-rw-rw-r-- 1 robert robert 2048 Dec 24  1996 defend.11
+-rw-rw-r-- 1 robert robert 2048 Dec 24  1996 defend.12
+-rw-rw-r-- 1 robert robert 4096 Dec 24  1996 defend.2
+-rw-rw-r-- 1 robert robert 4096 Dec 24  1996 defend.3
+-rw-rw-r-- 1 robert robert 2048 Dec 24  1996 defend.4
+-rw-rw-r-- 1 robert robert 2048 Dec 24  1996 defend.6
+-rw-rw-r-- 1 robert robert 2048 Dec 24  1996 defend.7
+-rw-rw-r-- 1 robert robert 2048 Dec 24  1996 defend.8
+-rw-rw-r-- 1 robert robert 2048 Dec 24  1996 defend.9
 ```
 
+So each filed `defend.[x]` corresponds to a matching chip on the board and
+because there is a missing chip in slot 5 we have no `defend.5` in the rom dump
+listing.
 
-## Notes on the Source Code
+In the [Defender product documentation](https://www.robotron-2084.co.uk/manuals/defender/defender_later_pcb_drawing_set.pdf) a 
+chart lists the part numbers for each chip and confirms that IC5 (i.e. `defend.5`) is unused:
+
+<img src="orig/RedLabelRomChart.png" size="300">
+
+When we assemble the Defender source with `make roms` we create a bunch of
+object files and then split them across the 11 files to match the 11 in the Red
+Label ROM dump listing above.
+
+Eugene Jarvis left a slightly cryptic note to how we assemble the source in [`info.src`](src/info.src):
+
+```
+ TO ASSEMBLE THE DEFENDER MESS
+
+RASM PHR2,DEFA2,DEFB2,AMODE0;-X (ELSE CREF SYMBOL OVERFLOW)
+RASM PHR2,SAMEXPA7
+RASM PHR2,DEFA2,DEFB2
+TO GET THE DIAGS, CHAIN ALL.CF
+LOAD IT ALL AND THEN PRAY IT WORKS
+(NOTE: BEWARE OF ORDER OF LOADING
+       LOOK OUT FOR THE SELECTED BLOCK SHIT
+
+DR J. 1/21/81
+
+```
+
+Since the `RASM` assembler is no longer available to us we use [`asm6809`](asm6809) instead. Fortunately this
+does a good job of assembling the source faithfully and [only very minor modifications to the source files are
+required to produce binaries](src). We recreate the steps in Eugene's notes as follows:
+
+```
+       # Build amode1 # The equivalent of: RASM PHR2,DEFA2,DEFB2,AMODE0;-X (ELSE CREF SYMBOL OVERFLOW)
+       ./asm6809/src/asm6809 -B src/phr6.src src/defa7.src src/defb6.src src/amode1.src\
+                       -l bin/defa7-defb6-amode1.lst  -o bin/defa7-defb6-amode1.o
+```
+This is the main game code with the attract mode module compiled in. `phr6.src` is a file containing definitions,
+while `defa7.src` and `defb6/src` contain the main game code; `amode1.src` contains the attract mode code.
+
+We also have to build a version of this game code without the attract mode module:
+
+```
+
+       # Build defa7 and defb6
+       # The equivalent of: RASM PHR2,DEFA2,DEFB2
+       ./asm6809/src/asm6809 -B src/phr6.src src/defa7.src src/defb6.src\
+                       -l bin/defa7-defb6.lst -o bin/defa7-defb6.o
+```
+
+The final module the notes mention is `samexpa7` a bunch of explosion routines added by Sam Dicker:
+
+```
+       # Build samexamp
+       # The equivalent of: RASM PHR2,SAMEXPA7
+       ./asm6809/src/asm6809 -B src/phr6.src src/samexap7.src\
+           -l bin/samexap7.lst -o bin/samexap7.o
+```
+
+Eugene's notes are much less clear on how we go about assembling the reamining source files:
+
+```
+mess0.src
+blk71.src
+romf8.src
+romc0.src
+romc8.src
+```
+
+However the way he lists them in the notes turns out to provide a clue to the order in which they
+shoud be assembled:
+
+```
+PHR6.SRC         636 LINES
+DEFA7.SRC      3,375 LINES
+DEFB6.SRC      2,252 LINES
+AMODE1.SRC     1,310 LINES
+BLK71.SRC        723 LINES
+SAMEXAP7.SRC     382 LINES
+MESS0.SRC        955 LINES
+ROMF8.SRC        692 LINES
+ROMC0.SRC        925 LINES
+ROMC8.SRC        839 LINES
+```
+
+We assemble the last four together in the order that they appear above:
+
+```
+       # Build roms
+       ./asm6809/src/asm6809 -B src/mess0.src src/romf8.src src/romc0.src src/romc8.src\
+                       -l bin/roms.lst -o bin/roms.o
+```
+
+And we assemble `blk71.src` by itself:
+
+```
+       # Build blk71
+       ./asm6809/src/asm6809 -B src/blk71.src -l bin/blk71.lst -o bin/blk71.o
+```
 
-The source code for Defender was originally retrieved from https://github.com/historical-source/defender
+There were a few modifications to the source required along the way to get this to work, mainly
+to work around the fact that `RASM` seems to have allowed you to assemble code sections into overlapping
+memory segments. For example both `amode1.src` and `defa7.src` want to assemble into position `$C000` in
+the ROM, meaning that one will overwrite the other. This explains why the main game files get assembled
+twice, once with attract mode (`amode1.src`) and once without: they wanted a binary with some segments
+overwritten with attract mode features and one without. We achieve this ourselves by modifying the source
+to compile and place the attract mode code to position `$2000` in memory, and when we later split the
+object files into the `defend[x].bin` files pick the chunk of code we're interested in.
 
 
diff --git a/orig/D8572.jpg b/orig/D8572.jpg
new file mode 100644 (file)
index 0000000..c6bd356
Binary files /dev/null and b/orig/D8572.jpg differ
diff --git a/orig/RedLabelROMBoardSchema.png b/orig/RedLabelROMBoardSchema.png
new file mode 100644 (file)
index 0000000..4be5caa
Binary files /dev/null and b/orig/RedLabelROMBoardSchema.png differ
diff --git a/orig/RedLabelROMChart.png b/orig/RedLabelROMChart.png
new file mode 100644 (file)
index 0000000..dd9299c
Binary files /dev/null and b/orig/RedLabelROMChart.png differ
diff --git a/orig/WilliamsArcadeClassics/DEFENDER.EXE b/orig/WilliamsArcadeClassics/DEFENDER.EXE
new file mode 100644 (file)
index 0000000..44c12c4
Binary files /dev/null and b/orig/WilliamsArcadeClassics/DEFENDER.EXE differ
diff --git a/orig/WilliamsArcadeClassics/romgrab b/orig/WilliamsArcadeClassics/romgrab
new file mode 100755 (executable)
index 0000000..8525616
Binary files /dev/null and b/orig/WilliamsArcadeClassics/romgrab differ
diff --git a/orig/WilliamsArcadeClassics/romgrab.c b/orig/WilliamsArcadeClassics/romgrab.c
new file mode 100644 (file)
index 0000000..7f14d94
--- /dev/null
@@ -0,0 +1,476 @@
+
+/*
+ * PROJECT: romgrab - Utility to grab the ROM files from the Williams
+Arcade executables
+ * FILE: romgrab.c
+ * AUTHOR: Jonathan Wolff
+ * LAST UPDATE: 29/1/96 12:21:45 pm
+   SKR - 1/2/96 removed & from memmap assignments
+ */
+
+#include <stddef.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdarg.h>
+#ifdef applec
+#include <CursorCtl.h>
+#endif
+
+/*
+ * packet types for RLE
+ */
+enum {
+  RLE_REPEAT = 0xb0,
+  RLE_REPEAT_END = 0xb1,
+  RLE_COPY = 0xb2,
+  RLE_COPY_END = 0xb3
+};
+
+/*
+ * Entries for memory map
+ */
+typedef struct MemMapEntry {
+
+  long int size;        // 0 is last entry
+  long int position;      // -1 is discarded section
+
+} MemMapEntry;
+
+MemMapEntry default_memmap[] = {
+  0x9000, 0x0,
+  0x3e20,  0xc1e0,
+  0
+};
+
+MemMapEntry defender_memmap[] = {
+  0x3800, 0x8000,
+  0x3000, 0xD000,
+  0x4800, -1,
+  0xe20,  0xc1e0,
+  0
+};
+
+MemMapEntry sinistar_memmap[] = {
+  0x9000, 0x0,
+  0xe20,  0xc1e0,
+  0x2000,  0xe000,
+  0
+};
+
+
+/*
+ * Parameters
+ */
+char *inputname = NULL;
+char *outputname = NULL;
+MemMapEntry *memmap = default_memmap;
+int verbose = 0;
+
+/*
+ * Global variables
+ */
+char *appname = NULL;
+int errlevel = 0;
+FILE *inputfile = NULL;
+FILE *outputfile = NULL;
+
+unsigned char *inputdata = NULL;
+unsigned char *outputdata = NULL;
+  
+long int inputsize, inputpos;
+long int outputsize, outputpos;
+
+int memmappos;
+
+MemMapEntry *custom_memmap;
+
+void error(int, char *, ...);
+void usage(void);
+void init(void);
+void process(void);
+void cleanup(void);
+
+int main(int argc, char *argv[])
+{
+  char *arg, *temp, *entry, *pos;
+  int i, entries;
+
+  /*
+   * Parse arguments
+   */
+  appname = argv[0];
+
+  while(argv++,--argc)
+
+    if (**argv == '-') {
+      /*
+       * Got one or more flags
+       */
+      for(arg = *argv+1; *arg; arg++) {
+
+        if (strchr("iom",*arg) && ((--argc == 0) || **(++argv) == '-')) {
+          error(5, "the %c option requires an argument\n", *arg);
+          usage();
+        }
+        switch (*arg) {
+        case '?':
+          usage();
+
+        case 'i':
+          if (inputname != NULL) {
+            error(5, "too many input files specified\n");
+            usage();
+          }
+          inputname = *argv;
+          break;
+          
+        case 'o':
+          if (outputname != NULL) {
+            error(5, "too many output files specified\n");
+            usage();
+          }
+          outputname = *argv;
+          break;
+          
+        case 'v':
+          verbose = 1;
+          break;
+          
+        case 'd':
+          memmap = defender_memmap;
+          break;
+          
+        case 's':
+          memmap = sinistar_memmap;
+          break;
+          
+        case 'm':
+          
+          for (entries = 1, pos = *argv; *pos != '\0'; pos++)
+            if (*pos == ',')
+              entries++;
+          
+          if (custom_memmap != NULL)
+            free(custom_memmap);
+            
+          custom_memmap = calloc(entries + 1, sizeof(MemMapEntry));
+          if (custom_memmap == NULL)
+            error(10, "couldn't allocate buffer for memory map\n");
+
+          temp = strcpy(malloc(strlen(*argv) + 1), *argv);
+
+          for (i = 0, entry = strtok(temp, ","); i < entries; i++, entry = strtok(NULL, ",")) {
+            switch (sscanf(entry, "%lx@%lx", &custom_memmap[i].size, &custom_memmap[i].position)) {
+            case 1:
+              custom_memmap[i].position = -1;
+              break;
+
+            case 2:
+              break;
+
+            default:
+              error(5, "malformed memory map definition\n");
+            }              
+          }
+          
+          free(temp);
+
+          memmap = custom_memmap;
+          break;
+          
+        default:
+          error(5, "unknown option '%c'\n", *arg);
+          usage();
+        }
+      }
+    } else
+      if (inputname == NULL)
+        inputname = *argv;
+      else if (outputname == NULL)
+        outputname = *argv;
+      else {
+        error(5, "too many parameters\n");
+        usage();
+      }
+
+  init();
+  process();
+  cleanup();
+
+  error(0, "done!\n");
+  return errlevel;
+}
+
+void usage(void)
+{
+  fprintf(stderr,
+"Usage: %s [-i] inputfile [[-o] outputfile] [-v] [-d|-s|-m size[@pos][,size[@pos]]...]\n"
+"\t-v\tenables verbose output\n"
+"\t-d\tuse Defender memory map (3800@8000,3000@d000,4800,9e20@c1e0)\n"
+"\t-s\tuse Sinistar memory map (9000@0,e20@c1e0,1000@e000)\n"
+"\t-m\tuse custom memory map\n"
+"\n"
+"\tdefault output filename is williams.rom\n"
+"\tdefault memory map is 9000@0,3e20@c1e0\n"
+"\n", appname
+  );
+
+  cleanup();
+  exit(errlevel);
+}
+
+void error(int level, char *format, ...)
+{
+  va_list arg;
+
+  fprintf(stderr, "# %s: ", appname);
+
+  va_start(arg, format);
+  vfprintf(stderr, format, arg);
+  va_end(arg);
+  
+  if (level > errlevel) {
+    errlevel = level;
+    if (level >= 10) {
+      cleanup();
+      exit(level);
+    }
+  }
+}
+
+void init(void)
+{
+  long int i;
+
+  if (inputname)
+    inputfile = fopen(inputname, "rb");
+
+  if (inputfile == NULL)
+    error(10, "couldn't open input file\n");
+
+  fseek(inputfile, 0, SEEK_END);
+  inputsize = ftell(inputfile);
+  fseek(inputfile, 0, SEEK_SET);
+  
+  inputdata = malloc(inputsize);
+  if (inputdata == NULL)
+    error(10, "couldn't allocate buffer for input file\n");
+  
+  if (fread(inputdata, inputsize, 1, inputfile) != 1)
+    error(10, "couldn't read input file\n");
+  
+  inputpos = inputsize;
+
+  if (!outputname)
+    outputname = "williams.rom";
+
+  outputfile = fopen(outputname, "wb");
+  if (outputfile == NULL)
+    error(10, "couldn't open output file\n");
+
+  memmappos = 0;
+  outputsize = 0;
+  while (memmap[memmappos].size > 0) {
+    outputpos = memmap[memmappos].position + memmap[memmappos].size;
+    if (memmap[memmappos].position >= 0 && outputpos > outputsize)
+      outputsize = outputpos;
+    memmappos++;
+  }
+  memmappos--;
+
+  outputdata = malloc(outputsize);
+  if (outputdata == NULL)
+    error(10, "couldn't allocate buffer for output file\n");
+
+  for (i = 0; i < outputsize; i++)
+    outputdata[i] = 0xff;
+}
+
+unsigned char cur_byte(void)
+{
+  if (inputpos < 1)
+    error(10, "unexpected start of file\n");
+
+  return inputdata[inputpos - 1];
+}
+
+unsigned char get_byte(void)
+{
+  if (inputpos < 1)
+    error(10, "unexpected start of file\n");
+
+  return inputdata[--inputpos];
+}
+
+unsigned int get_word(void)
+{
+  if (inputpos < 2)
+    error(10, "unexpected start of file\n");
+
+  inputpos -= 2;
+  return ((unsigned)(inputdata[inputpos + 1] << 8) + inputdata[inputpos]);
+}
+
+void put_byte(unsigned char b)
+{
+  if (memmappos < 0) {
+    if (verbose && outputpos-- == 0)
+      printf("EXE...");
+    return;
+  }
+  
+  if (verbose && memmap[memmappos].position >= 0 && outputpos ==
+memmap[memmappos].position + memmap[memmappos].size)
+    printf("%04X... ", outputpos - 1);
+
+  outputpos--;
+  if (memmap[memmappos].position >= 0)
+    outputdata[outputpos] = b;
+  
+  if (outputpos == memmap[memmappos].position) {
+
+    if (verbose && memmap[memmappos].position >= 0)
+      printf("...%04X ", outputpos);
+
+    memmappos--;
+    if (memmappos < 0)
+      outputpos = 0;
+    else
+      outputpos = memmap[memmappos].position + memmap[memmappos].size;
+  }
+}
+
+void process(void)
+{
+  unsigned int count;
+  unsigned char byte;
+  int finished = 0;
+  
+  /*
+   * Locate end of compressed image - this seems to be a bit bodgy
+   */
+  while (1) {
+    while (cur_byte() != 0x00)
+      get_byte();
+    get_byte();
+    if (cur_byte() == 0x40) {
+      get_byte();
+      break;
+    }
+  }
+
+  if (verbose) {
+    printf("%05x-%05x: ..            crap\n", inputpos + 2, inputsize - 1);
+    printf("%05x-%05x: 40 00         marks end of compressed image\n",
+inputpos, inputpos + 1);
+  }
+
+  /*
+   * Skip the checksum/size/whatever it is & the padding
+   */
+  get_word();
+  if (verbose)
+    printf("%05x-%05x: %02x %02x         ?\n", inputpos, inputpos + 1,
+inputdata[inputpos], inputdata[inputpos + 1]);
+
+  if (cur_byte() == 0xff) {
+
+    count = 0;
+    while (cur_byte() == 0xff) {
+      count++;
+      get_byte();
+    }
+  
+    if (verbose)
+      printf("%05x-%05x: ff ..         padding\n", inputpos, inputpos + count
+- 1);
+  }
+
+  while (!finished) {
+
+    switch(get_byte()) {
+    
+      case RLE_REPEAT_END:
+      
+         finished=1;
+         
+      case RLE_COPY_END:
+      
+         finished=1;
+      
+         
+    case RLE_REPEAT:
+      count = get_word();
+      byte = get_byte();
+      
+      if (verbose)
+        printf("%05x-%05x: %02x %02x %02x %02x   repeat   ", inputpos,
+inputpos + 4, inputdata[inputpos], inputdata[inputpos + 1],
+inputdata[inputpos + 2], inputdata[inputpos + 3]);
+
+      while (count-- > 0)
+        put_byte(byte);
+
+      if (verbose)
+        printf("\n");
+
+      break;
+
+    case RLE_COPY:
+
+      count = get_word();
+      
+      if (verbose)
+        printf("%05x-%05x: .. %02x %02x %02x   copy     ", inputpos - count,
+inputpos + 2, inputdata[inputpos], inputdata[inputpos + 1],
+inputdata[inputpos + 2]);
+
+      while (count-- > 0)
+        put_byte(get_byte());
+
+      if (verbose)
+        printf("\n");
+
+      break;
+
+    default:
+      error(10, "unexpected RLE packet 0x%02x\n", inputdata[inputpos]);
+    }
+
+    /*
+     * Spin the beachball from time to time...
+     */
+#ifdef applec
+    SpinCursor(32);
+#endif
+  }
+  
+  if (verbose)
+    printf("00000-%05x: ..            crap\n", inputpos);
+
+  if (fwrite(outputdata, outputsize, 1, outputfile) != 1)
+    error(10, "couldn't write output file\n");
+  
+  error(0, "written ROM image to '%s'\n", outputname);
+}
+
+void cleanup(void)
+{
+  if (inputfile != NULL)
+    fclose(inputfile);
+
+  if (outputfile != NULL)
+    fclose(outputfile);
+
+  if (inputdata != NULL)
+    free(inputdata);
+
+  if (outputdata != NULL)
+    free(outputdata);
+
+  if (custom_memmap != NULL)
+    free(custom_memmap);
+}
+
+
diff --git a/orig/defender-bluelabel/.defeng02.bin.swp b/orig/defender-bluelabel/.defeng02.bin.swp
new file mode 100644 (file)
index 0000000..09d81a7
Binary files /dev/null and b/orig/defender-bluelabel/.defeng02.bin.swp differ
diff --git a/orig/defender-bluelabel/defeng02.bin b/orig/defender-bluelabel/defeng02.bin
new file mode 100644 (file)
index 0000000..0b18ad9
Binary files /dev/null and b/orig/defender-bluelabel/defeng02.bin differ
diff --git a/orig/defender-bluelabel/defeng06.bin b/orig/defender-bluelabel/defeng06.bin
new file mode 100644 (file)
index 0000000..f7af3c4
Binary files /dev/null and b/orig/defender-bluelabel/defeng06.bin differ
diff --git a/orig/defender-bluelabel/defeng07.bin b/orig/defender-bluelabel/defeng07.bin
new file mode 100644 (file)
index 0000000..40ac692
Binary files /dev/null and b/orig/defender-bluelabel/defeng07.bin differ
diff --git a/orig/defender-bluelabel/defeng08.bin b/orig/defender-bluelabel/defeng08.bin
new file mode 100644 (file)
index 0000000..aef7e5f
Binary files /dev/null and b/orig/defender-bluelabel/defeng08.bin differ
diff --git a/orig/defender-bluelabel/defeng09.bin b/orig/defender-bluelabel/defeng09.bin
new file mode 100644 (file)
index 0000000..0f13d39
Binary files /dev/null and b/orig/defender-bluelabel/defeng09.bin differ
diff --git a/orig/defender-bluelabel/defeng10.bin b/orig/defender-bluelabel/defeng10.bin
new file mode 100644 (file)
index 0000000..9cdad3b
Binary files /dev/null and b/orig/defender-bluelabel/defeng10.bin differ
diff --git a/orig/defender-bluelabel/defeng11.bin b/orig/defender-bluelabel/defeng11.bin
new file mode 100644 (file)
index 0000000..d04edb0
Binary files /dev/null and b/orig/defender-bluelabel/defeng11.bin differ
diff --git a/orig/defender-bluelabel/defeng12.bin b/orig/defender-bluelabel/defeng12.bin
new file mode 100644 (file)
index 0000000..4720aa9
Binary files /dev/null and b/orig/defender-bluelabel/defeng12.bin differ
diff --git a/orig/defender-bluelabel/wb01.bin b/orig/defender-bluelabel/wb01.bin
new file mode 100644 (file)
index 0000000..2f8b6e7
Binary files /dev/null and b/orig/defender-bluelabel/wb01.bin differ
diff --git a/orig/defender-bluelabel/wb03.bin b/orig/defender-bluelabel/wb03.bin
new file mode 100644 (file)
index 0000000..0f124c2
Binary files /dev/null and b/orig/defender-bluelabel/wb03.bin differ
diff --git a/orig/defender-greenlabel/decoder.1 b/orig/defender-greenlabel/decoder.1
new file mode 100644 (file)
index 0000000..4e684cf
Binary files /dev/null and b/orig/defender-greenlabel/decoder.1 differ
diff --git a/orig/defender-greenlabel/defend.snd b/orig/defender-greenlabel/defend.snd
new file mode 100644 (file)
index 0000000..76a93cc
Binary files /dev/null and b/orig/defender-greenlabel/defend.snd differ
diff --git a/orig/defender-greenlabel/defeng01.bin b/orig/defender-greenlabel/defeng01.bin
new file mode 100644 (file)
index 0000000..a25fed8
Binary files /dev/null and b/orig/defender-greenlabel/defeng01.bin differ
diff --git a/orig/defender-greenlabel/defeng02.bin b/orig/defender-greenlabel/defeng02.bin
new file mode 100644 (file)
index 0000000..0b18ad9
Binary files /dev/null and b/orig/defender-greenlabel/defeng02.bin differ
diff --git a/orig/defender-greenlabel/defeng03.bin b/orig/defender-greenlabel/defeng03.bin
new file mode 100644 (file)
index 0000000..cbe1189
Binary files /dev/null and b/orig/defender-greenlabel/defeng03.bin differ
diff --git a/orig/defender-greenlabel/defeng04.bin b/orig/defender-greenlabel/defeng04.bin
new file mode 100644 (file)
index 0000000..ff16b6f
Binary files /dev/null and b/orig/defender-greenlabel/defeng04.bin differ
diff --git a/orig/defender-greenlabel/defeng06.bin b/orig/defender-greenlabel/defeng06.bin
new file mode 100644 (file)
index 0000000..f7af3c4
Binary files /dev/null and b/orig/defender-greenlabel/defeng06.bin differ
diff --git a/orig/defender-greenlabel/defeng07.bin b/orig/defender-greenlabel/defeng07.bin
new file mode 100644 (file)
index 0000000..40ac692
Binary files /dev/null and b/orig/defender-greenlabel/defeng07.bin differ
diff --git a/orig/defender-greenlabel/defeng08.bin b/orig/defender-greenlabel/defeng08.bin
new file mode 100644 (file)
index 0000000..aef7e5f
Binary files /dev/null and b/orig/defender-greenlabel/defeng08.bin differ
diff --git a/orig/defender-greenlabel/defeng09.bin b/orig/defender-greenlabel/defeng09.bin
new file mode 100644 (file)
index 0000000..0f13d39
Binary files /dev/null and b/orig/defender-greenlabel/defeng09.bin differ
diff --git a/orig/defender-greenlabel/defeng10.bin b/orig/defender-greenlabel/defeng10.bin
new file mode 100644 (file)
index 0000000..9cdad3b
Binary files /dev/null and b/orig/defender-greenlabel/defeng10.bin differ
diff --git a/orig/defender-greenlabel/defeng11.bin b/orig/defender-greenlabel/defeng11.bin
new file mode 100644 (file)
index 0000000..d04edb0
Binary files /dev/null and b/orig/defender-greenlabel/defeng11.bin differ
diff --git a/orig/defender-greenlabel/defeng12.bin b/orig/defender-greenlabel/defeng12.bin
new file mode 100644 (file)
index 0000000..4720aa9
Binary files /dev/null and b/orig/defender-greenlabel/defeng12.bin differ
diff --git a/orig/defender-redlabel/decoder.2 b/orig/defender-redlabel/decoder.2
new file mode 100644 (file)
index 0000000..4e684cf
Binary files /dev/null and b/orig/defender-redlabel/decoder.2 differ
diff --git a/orig/defender-redlabel/decoder.3 b/orig/defender-redlabel/decoder.3
new file mode 100644 (file)
index 0000000..f1bfe79
Binary files /dev/null and b/orig/defender-redlabel/decoder.3 differ
diff --git a/orig/defender-redlabel/defend.1 b/orig/defender-redlabel/defend.1
new file mode 100644 (file)
index 0000000..3ce77f7
Binary files /dev/null and b/orig/defender-redlabel/defend.1 differ
diff --git a/orig/defender-redlabel/defend.10 b/orig/defender-redlabel/defend.10
new file mode 100644 (file)
index 0000000..494fc0f
Binary files /dev/null and b/orig/defender-redlabel/defend.10 differ
diff --git a/orig/defender-redlabel/defend.11 b/orig/defender-redlabel/defend.11
new file mode 100644 (file)
index 0000000..d7372d0
Binary files /dev/null and b/orig/defender-redlabel/defend.11 differ
diff --git a/orig/defender-redlabel/defend.12 b/orig/defender-redlabel/defend.12
new file mode 100644 (file)
index 0000000..543f942
Binary files /dev/null and b/orig/defender-redlabel/defend.12 differ
diff --git a/orig/defender-redlabel/defend.2 b/orig/defender-redlabel/defend.2
new file mode 100644 (file)
index 0000000..2391e27
Binary files /dev/null and b/orig/defender-redlabel/defend.2 differ
diff --git a/orig/defender-redlabel/defend.3 b/orig/defender-redlabel/defend.3
new file mode 100644 (file)
index 0000000..d808360
Binary files /dev/null and b/orig/defender-redlabel/defend.3 differ
diff --git a/orig/defender-redlabel/defend.4 b/orig/defender-redlabel/defend.4
new file mode 100644 (file)
index 0000000..21ca90a
Binary files /dev/null and b/orig/defender-redlabel/defend.4 differ
diff --git a/orig/defender-redlabel/defend.6 b/orig/defender-redlabel/defend.6
new file mode 100644 (file)
index 0000000..d407e0c
Binary files /dev/null and b/orig/defender-redlabel/defend.6 differ
diff --git a/orig/defender-redlabel/defend.7 b/orig/defender-redlabel/defend.7
new file mode 100644 (file)
index 0000000..b7b3dc2
Binary files /dev/null and b/orig/defender-redlabel/defend.7 differ
diff --git a/orig/defender-redlabel/defend.8 b/orig/defender-redlabel/defend.8
new file mode 100644 (file)
index 0000000..cc85b06
Binary files /dev/null and b/orig/defender-redlabel/defend.8 differ
diff --git a/orig/defender-redlabel/defend.9 b/orig/defender-redlabel/defend.9
new file mode 100644 (file)
index 0000000..cecc345
Binary files /dev/null and b/orig/defender-redlabel/defend.9 differ
diff --git a/orig/defender-redlabel/defend.snd b/orig/defender-redlabel/defend.snd
new file mode 100644 (file)
index 0000000..76a93cc
Binary files /dev/null and b/orig/defender-redlabel/defend.snd differ
diff --git a/orig/defender-whitelabel/decoder.1 b/orig/defender-whitelabel/decoder.1
new file mode 100644 (file)
index 0000000..4e684cf
Binary files /dev/null and b/orig/defender-whitelabel/decoder.1 differ
diff --git a/orig/defender-whitelabel/rom1.bin b/orig/defender-whitelabel/rom1.bin
new file mode 100644 (file)
index 0000000..8049307
Binary files /dev/null and b/orig/defender-whitelabel/rom1.bin differ
diff --git a/orig/defender-whitelabel/rom10.bin b/orig/defender-whitelabel/rom10.bin
new file mode 100644 (file)
index 0000000..cd4ec82
Binary files /dev/null and b/orig/defender-whitelabel/rom10.bin differ
diff --git a/orig/defender-whitelabel/rom11.bin b/orig/defender-whitelabel/rom11.bin
new file mode 100644 (file)
index 0000000..178c136
Binary files /dev/null and b/orig/defender-whitelabel/rom11.bin differ
diff --git a/orig/defender-whitelabel/rom12.bin b/orig/defender-whitelabel/rom12.bin
new file mode 100644 (file)
index 0000000..6e5db84
Binary files /dev/null and b/orig/defender-whitelabel/rom12.bin differ
diff --git a/orig/defender-whitelabel/rom2.bin b/orig/defender-whitelabel/rom2.bin
new file mode 100644 (file)
index 0000000..d526d8f
Binary files /dev/null and b/orig/defender-whitelabel/rom2.bin differ
diff --git a/orig/defender-whitelabel/rom3.bin b/orig/defender-whitelabel/rom3.bin
new file mode 100644 (file)
index 0000000..7e066c4
Binary files /dev/null and b/orig/defender-whitelabel/rom3.bin differ
diff --git a/orig/defender-whitelabel/rom6.bin b/orig/defender-whitelabel/rom6.bin
new file mode 100644 (file)
index 0000000..b0d0ad9
Binary files /dev/null and b/orig/defender-whitelabel/rom6.bin differ
diff --git a/orig/defender-whitelabel/rom7.bin b/orig/defender-whitelabel/rom7.bin
new file mode 100644 (file)
index 0000000..46d713d
Binary files /dev/null and b/orig/defender-whitelabel/rom7.bin differ
diff --git a/orig/defender-whitelabel/rom8.bin b/orig/defender-whitelabel/rom8.bin
new file mode 100644 (file)
index 0000000..f597402
Binary files /dev/null and b/orig/defender-whitelabel/rom8.bin differ
diff --git a/orig/defender-whitelabel/rom9.bin b/orig/defender-whitelabel/rom9.bin
new file mode 100644 (file)
index 0000000..3cbbdd2
Binary files /dev/null and b/orig/defender-whitelabel/rom9.bin differ
diff --git a/orig/dfndr_l4/ic14.532 b/orig/dfndr_l4/ic14.532
new file mode 100644 (file)
index 0000000..247aa2f
Binary files /dev/null and b/orig/dfndr_l4/ic14.532 differ
diff --git a/orig/dfndr_l4/ic17.532 b/orig/dfndr_l4/ic17.532
new file mode 100644 (file)
index 0000000..d3b83f7
Binary files /dev/null and b/orig/dfndr_l4/ic17.532 differ
diff --git a/orig/dfndr_l4/ic20.532 b/orig/dfndr_l4/ic20.532
new file mode 100644 (file)
index 0000000..6d4e71b
Binary files /dev/null and b/orig/dfndr_l4/ic20.532 differ
diff --git a/orig/dfndr_l4/sound12.716 b/orig/dfndr_l4/sound12.716
new file mode 100644 (file)
index 0000000..080ecd5
Binary files /dev/null and b/orig/dfndr_l4/sound12.716 differ