apps: add binman support and produce FUZIX executables
authorAlexander Tsidaev <a.tsidaev@gmail.com>
Mon, 24 Nov 2014 17:15:12 +0000 (12:15 -0500)
committerAlexander Tsidaev <a.tsidaev@gmail.com>
Mon, 24 Nov 2014 18:18:56 +0000 (13:18 -0500)
Applications/util/Makefile
Library/Makefile
Library/libs/crt0.s
Library/tools/binman.c

index 8c1ac13..f96f5a9 100644 (file)
@@ -3,13 +3,14 @@ ASM = sdasz80
 AR = sdar
 LINKER = sdcc
 
-CODELOC= 0xC000
+PROGLOAD=`(cat ../../Kernel/platform/config.h; echo PROGLOAD) | cpp -E | tail -n1`
 
 #CC_OPT = -mz80 -c --opt-code-size --std-c89 --max-allocs-per-node 2000000 -I../../Library/include
 CC_OPT = -mz80 --std-c99 -c --opt-code-size --max-allocs-per-node 20000 -I../../Library/include
 #--oldralloc
 ASM_OPT = -l -o -s
-LINKER_OPT = -mz80 --nostdlib --no-std-crt0 --code-loc $(CODELOC) --data-loc  0
+LINKER_OPT = -mz80 --nostdlib --no-std-crt0 --code-loc $(PROGLOAD) --data-loc  0
+BINMAN = ../../Library/tools/binman
 
 .SUFFIXES: .c .rel
 
@@ -86,10 +87,12 @@ $(OBJS): $(SRCS)
 
 %: %.rel
        $(LINKER) $(LINKER_OPT) ../../Library/libs/crt0.rel $< $(LIBS) -o $@.ihx
-       hex2bin  $@.ihx
+       makebin -s 65536 $@.ihx $@.tmp
+       $(BINMAN) $(PROGLOAD) $@.tmp $@.map $@
+       chmod +x $@
 
 clean:
-       rm -f $(OBJS) $(APPS) core *~ *.asm *.lst *.sym *.map *.noi *.lk *.ihx *.bin
+       rm -f $(OBJS) $(APPS) $(SRCS:.c=) core *~ *.asm *.lst *.sym *.map *.noi *.lk *.ihx *.tmp
 
 rmbak:
        rm -f *~ core
index 0025278..8ad77ae 100644 (file)
@@ -1,5 +1,9 @@
 # Top level makefile for library
 
+CFLAGS += -I../Kernel/include
+
+all: tools/syscall tools/binman
+
 tools/syscall: tools/syscall.c ../Kernel/include/syscall_name.h
-       $(CC) $(CFLAGS) -I../Kernel/include tools/syscall.c -o tools/syscall
 
+tools/binman: tools/binman.c
index 74e61f4..b094e1d 100644 (file)
@@ -27,7 +27,6 @@
 
                .area _CODE
 
-               .ds 0x100
 ; start at 0x100
 start:         jp start2
                .db 'F'
index 1e4d73f..c2cb69f 100644 (file)
@@ -16,6 +16,7 @@ static unsigned int l__INITIALIZER;
 
 static unsigned int s__DATA;
 
+static unsigned int progload = 0x100;
                       
 
 static void ProcessMap(FILE *fp)
@@ -47,39 +48,47 @@ static void ProcessMap(FILE *fp)
 int main(int argc, char *argv[])
 {
   FILE *map, *bin;
+  int argp = 1;
 
-  if (argc != 4) {
-    fprintf(stderr, "%s: [binary] [map] [output]\n", argv[0]);
+  if (argc != 4 && argc != 5) {
+    fprintf(stderr, "%s: [PROGLOAD address] <binary> <map> <output>\n", argv[0]);
     exit(1);
   }
-  bin = fopen(argv[1], "r");
+
+  if (argc == 5 && sscanf(argv[argp++], "%x", &progload) != 1)
+  {
+    fprintf(stderr, "%s: PROGLOAD parse error: %s\n", argv[0], argv[argp - 1]);
+    exit(1);
+  }
+
+  bin = fopen(argv[argp++], "r");
   if (bin == NULL) {
-    perror(argv[1]);
+    perror(argv[argp - 1]);
     exit(1);
   }
   if (fread(buf, 1, 65536, bin) == 0) {
-    fprintf(stderr, "%s: read error on %s\n", argv[0], argv[1]);
+    fprintf(stderr, "%s: read error on %s\n", argv[0], argv[argp - 1]);
     exit(1);
   }
   fclose(bin);
-  map = fopen(argv[2], "r");
+  map = fopen(argv[argp++], "r");
   if (map == NULL) {
-    perror(argv[2]);
+    perror(argv[argp - 1]);
     exit(1);
   }
   ProcessMap(map);
   fclose(map);
   
-  bin = fopen(argv[3], "w");
+  bin = fopen(argv[argp++], "w");
   if (bin == NULL) {
-    perror(argv[3]);
+    perror(argv[argp - 1]);
     exit(1);
   }
   memcpy(buf + s__INITIALIZED, buf + s__INITIALIZER, l__INITIALIZER);
   /* Write out everything that is data, omit everything that will 
      be zapped */
-  if (fwrite(buf + 0x100, s__DATA - 0x100, 1, bin) != 1) {
-   perror(argv[3]);
+  if (fwrite(buf + progload, s__DATA - progload, 1, bin) != 1) {
+   perror(argv[argp - 1]);
    exit(1);
   }
   fclose(bin);