diff options
Diffstat (limited to 'rom2cart.c')
-rw-r--r-- | rom2cart.c | 43 |
1 files changed, 34 insertions, 9 deletions
@@ -70,6 +70,7 @@ char *usage = " -T type Like -t, but forces the type. Numeric type only.\n" " -C sum Force the checksum to sum. Not very useful.\n" " -U data Set 'unused' bytes in CART header to data.\n" + " -H Test code heuristics (developer option).\n" "\n" "infile may be either a raw dump or a CART image, and may be '-' to read\n" "from standard input. outfile may be omitted, in which case output will\n" @@ -77,7 +78,7 @@ char *usage = ".car (or .rom, if -r given). outfile may be '-' to write to standard\n" "output.\n"; -#define OPTIONS "vchlm:nT:t:C:rU:" +#define OPTIONS "vchlm:nT:t:C:rU:H" void print_type_table(int *set) { /* print a nicely-formatted type table. If set is NULL, print all types, @@ -87,7 +88,7 @@ void print_type_table(int *set) { "Type", "Machine", "SizeKB", "Name"); fprintf(stderr, "------|----------|--------|------------------------\n"); for(i=1; i<=MAX_CART_TYPE; i++) { - if(set == NULL || set[i]) + if(cart_types[i].machine != M_INVALID && (set == NULL || set[i])) fprintf(stderr, "%5d | %8s | %6d | %s\n", i, (cart_types[i].machine == M_5200 ? "5200" : "8-bit"), @@ -184,10 +185,15 @@ machine_t code_heuristics(unsigned char *rom, int size, int verbose) { SELF ": found %d probable 5200 POKEY writes\n", a52); } - if(a8 >= 3 && a52 <= 1) + if(a8 >= 3 && a52 <= 1) { machine = M_ATARI8; - else if(a52 >= 3 && a8 <= 1) + fprintf(stderr, SELF ": code_heuristics() returning M_ATARI8\n"); + } else if(a52 >= 3 && a8 <= 1) { machine = M_5200; + fprintf(stderr, SELF ": code_heuristics() returning M_5200\n"); + } else { + fprintf(stderr, SELF ": code_heuristics() returning M_INVALID\n"); + } return machine; } @@ -277,7 +283,7 @@ int determine_type( else return 0; /* bogus -T */ } else { - if(!type || type > MAX_CART_TYPE) { + if(!type || type > MAX_CART_TYPE || cart_types[type].machine == M_INVALID) { fprintf(stderr, "Invalid numeric type '%d' for -t (valid types " "are 1 to %d; use -l for list)\n", type, MAX_CART_TYPE); return 0; @@ -307,7 +313,7 @@ int determine_type( fprintf(stderr, SELF ": trying to match '%s'\n", type_param); for(i=1; i<=MAX_CART_TYPE; i++) { - if(string_match(cart_types[i].name, type_param)) { + if(cart_types[i].machine != M_INVALID && string_match(cart_types[i].name, type_param)) { if(verbose > 1) fprintf(stderr, SELF ": matched type %d (%s)\n", i, cart_types[i].name); @@ -439,7 +445,7 @@ int main(int argc, char **argv) { int check_only = 0, type = 0, type_override = 0, allow_guess = 1, verbose = 0, raw_output = 0; machine_t machine = M_INVALID; - int c, size; + int c, size, test_heuristics = 0, raw_input = 0; unsigned int cksum = 0, cksum_override = 0, unused_data = 0; unsigned char *buffer; unsigned char **bufp = &buffer; @@ -508,6 +514,11 @@ int main(int argc, char **argv) { raw_output++; break; + case 'H': + test_heuristics++; + verbose = 2; + break; + default: fputs(BANNER, stderr); fprintf(stderr, usage); @@ -555,6 +566,7 @@ int main(int argc, char **argv) { } else { rom = buffer; if(verbose) fprintf(stderr, SELF ": input is raw dump, %d bytes\n", size); + raw_input++; } if(size <= 0) { @@ -587,12 +599,25 @@ int main(int argc, char **argv) { when there's only 8K of actual ROM. */ memcpy(cart, CART_SIGNATURE, 4); set_cart_type(cart, type); - if(!cksum_override) + if(!cksum_override) { cksum = calc_rom_checksum(buffer, size); + if(!raw_input) { + int oldsum = get_cart_checksum(buffer); + if(oldsum != cksum) { + fprintf(stderr, SELF ": stored checksum %08x doesn't match calculated %08x, fixing.\n", oldsum, cksum); + } + } + } set_cart_checksum(cart, cksum); set_cart_unused(cart, unused_data); - if(verbose > 1) cart_dump_header(cart, 0); + if(verbose > 1 && !(check_only && raw_input)) cart_dump_header(cart, 0); + + if(test_heuristics) { + fprintf(stderr, SELF ": testing code_heuristics() and exiting.\n"); + (void)code_heuristics(buffer, size, verbose); + exit(0); + } if(!check_only) { if(optind < argc) { |