/* unz80.c: turn a Z80 object file into asl source on stdout */ /* ats@offog.org */ #include #include #include #include "disz80.c" int main(int argc, char **argv) { FILE *f; unsigned char mem[65536], *p, *oldp; char line[256]; int l, d, labno[65536], x, labc, flag; for (x=0; x<65536; x++) labno[x] = mem[x] = 0; if ((f = fopen(argv[1],"r"))==NULL) { printf("Couldn't open \"%s\".\n", argv[1]); printf("Syntax: unz80 []\n"); exit(20); } if (argc > 2) { d = atoi(argv[2]); } else { d = 0; } l = 0; while (!feof(f)) *(mem+d+(l++)) = fgetc(f); fclose(f); l--; printf("; unz80: loaded %d bytes from %s at %d\n", l, argv[1], d); printf("\n\tCPU Z80\n"); printf("\tORG %05xh\n\n",d); /* first pass: find addresses that could, conceivably, be labels */ p = mem + d; while ((p-(mem+d))0) { printf("Label%04d:",labno[oldp-mem]); } else { printf("\t"); } if (flag) { line[strlen(line)-5] = '\0'; printf("\t%sLabel%04d",line,labno[x]); } else { printf("\t%s",line); } if (labno[oldp-mem]>0) printf("\t\t; %04x\n",oldp-mem); else printf("\n"); } /* fourth pass: produce a dump file on stderr */ p = mem+d; while(p<(mem+d+l)) { if (labno[p-mem]>0) fprintf(stderr, "Label%04d:", labno[p-mem]); else fprintf(stderr, "\t"); fprintf(stderr, "\tDB %03xh\t\t; %04x\n", *p, p-mem); p++; } return 0; }