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
%: %.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
static unsigned int s__DATA;
+static unsigned int progload = 0x100;
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);