#include #include #include main (int argc, char *argv[]) { FILE *input_file, *output_file; char address[7], n; int c, c1, c2; fputs("usage: s19toasm \n", stdout); input_file = fopen(argv[1], "r"); if (input_file == NULL) { fputs("*** Can't open input file ***", stdout); exit(0); } output_file = fopen(argv[2], "w"); if (output_file == NULL) { fputs("*** Can't open output file ***", stdout); exit(0); } while ((c = getc(input_file)) != EOF) { if (c == 'S') { n = 4; while (n-- > 0) { c = getc(input_file); } address[0] = ('0'); address[1] = ('x'); address[2] = c; address[3] = getc(input_file); address[4] = getc(input_file); address[5] = getc(input_file); address[6] = ('\0'); c = getc(input_file); // fputs(address, stdout); // fputs("\n", stdout); } // if ( (strncmp(address, argv[3], 6) > 0) // && (strncmp(address, argv[4], 6) < 0) ) if ( (strtol(address, NULL, 0) >= strtol(argv[3], NULL, 0) ) && (strtol(address, NULL, 0) <= strtol(argv[4], NULL, 0) ) ) { fputs("\t.org\t", output_file); fputs(address, output_file); fputs("\n", output_file); while (c != '\n') { c2 = c; c1 = getc(input_file); c = getc(input_file); if (c != '\n') { fputs("\t.byte\t0x", output_file); putc(c2, output_file); putc(c1, output_file); fputs("\n", output_file); } else { fputs("\t\t; checksum = 0x", output_file); putc(c2, output_file); putc(c1, output_file); fputs("\n", output_file); } } } } fputs("Success!", stdout); }