From 8db1146c5ded68b2d3356e19c3475b43a97de6f5 Mon Sep 17 00:00:00 2001 From: recompileorg Date: Mon, 13 Apr 2020 05:57:49 -0400 Subject: [PATCH] Fixes #40 - Intellicart roms w/o A8 Detects Intellicart roms using a different method for files that don't begin with 0xA8 --- src/cart.c | 74 ++++++++++++++++++++++++++++++++++++++---------------- src/intv.c | 12 ++++----- 2 files changed, 59 insertions(+), 27 deletions(-) diff --git a/src/cart.c b/src/cart.c index 4c10d5e..4da6512 100644 --- a/src/cart.c +++ b/src/cart.c @@ -16,9 +16,13 @@ */ #include +#include #include "memory.h" #include "cart.h" +#include "osd.h" +int isIntellicart(void); +int loadIntellicart(void); int isROM(void); int loadROM(void); int getLoadMethod(void); @@ -65,33 +69,50 @@ int LoadCart(const char *path) if (ferror(fp)) { printf("[ERROR] [FREEINTV] Cartridge load error indicator set\n"); + return 0; } - if(isROM()) // intellicart format + char buffer[8] = {0,0,0,0,0,0,0,0}; + itoa(size, buffer, 10); + OSD_drawText(8, 4, "SIZE:"); + OSD_drawText(14, 4, buffer); + + if(isIntellicart()) // intellicart format { + OSD_drawText(8, 4, "INTELLICART"); printf("[INFO] [FREEINTV] Intellicart cartridge format detected\n"); - return loadROM(); + return loadIntellicart(); } else { - // check cartinfo database for load method - printf("[INFO] [FREEINTV] Intelllicart format not detected. Determining load method via database.\n"); - switch(getLoadMethod()) - { - case 0: load0(); break; - case 1: load1(); break; - case 2: load2(); break; - case 3: load3(); break; - case 4: load4(); break; - case 5: load5(); break; - case 6: load6(); break; - case 7: load7(); break; - case 8: load8(); break; - case 9: load9(); break; - default: printf("[INFO] [FREEINTV] No database match. Using default cartridge memory map.\n"); load0(); - } + if(isROM()) + { + OSD_drawText(8, 4, "INTELLICART"); + OSD_drawText(8, 5, "MISSING A8!"); + printf("[INFO] [FREEINTV] Possible Intellicart cartridge format detected\n"); + return loadROM(); + } + else + { + // check cartinfo database for load method + printf("[INFO] [FREEINTV] Raw ROM image. Determining load method via database.\n"); + switch(getLoadMethod()) + { + case 0: load0(); break; + case 1: load1(); break; + case 2: load2(); break; + case 3: load3(); break; + case 4: load4(); break; + case 5: load5(); break; + case 6: load6(); break; + case 7: load7(); break; + case 8: load8(); break; + case 9: load9(); break; + default: printf("[INFO] [FREEINTV] No database match. Using default cartridge memory map.\n"); load0(); + } + } } - return 1; + return 1; // loaded okay } else { @@ -120,13 +141,19 @@ void loadRange(int start, int stop) } // http://spatula-city.org/~im14u2c/intv/jzintv-1.0-beta3/doc/rom_fmt/IntellicartManual.booklet.pdf -int isROM() // check for intellicart format rom +int isIntellicart() // check for intellicart format rom { // check magic number (used for intellicart baud rate detection) return (data[0]==0xA8); } -int loadROM() // load intellicart format rom +int isROM() // some Intellicart roms don't start with A8 for no apparent reason +{ + // the third byte should be the 1's compliment of the second byte + return data[1] == (data[2]^0xFF); +} + +int loadIntellicart() // load intellicart format rom { int start; int stop; @@ -149,6 +176,11 @@ int loadROM() // load intellicart format rom return 1; } +int loadROM() // load ROM formatted cart +{ + return loadIntellicart(); +} + // http://atariage.com/forums/topic/203179-config-files-to-use-with-various-intellivision-titles/ void load0() // default - handles majority of carts diff --git a/src/intv.c b/src/intv.c index cd0e2a7..ff2dabe 100644 --- a/src/intv.c +++ b/src/intv.c @@ -33,11 +33,11 @@ void LoadGame(const char* path) // load cart rom // { if(LoadCart(path)) { - OSD_drawText(3, 3, "Load Cart: OKAY"); + OSD_drawText(3, 3, "LOAD CART: OKAY"); } else { - OSD_drawText(3, 3, "Load Cart: FAIL"); + OSD_drawText(3, 3, "LOAD CART: FAIL"); } } @@ -56,12 +56,12 @@ void loadExec(const char* path) } fclose(fp); - OSD_drawText(3, 1, "Load EXEC: OKAY"); + OSD_drawText(3, 1, "LOAD EXEC: OKAY"); printf("[INFO] [FREEINTV] Succeeded loading Executive BIOS from: %s\n", path); } else { - OSD_drawText(3, 1, "Load EXEC: FAIL"); + OSD_drawText(3, 1, "LOAD EXEC: FAIL"); printf("[ERROR] [FREEINTV] Failed loading Executive BIOS from: %s\n", path); } } @@ -81,13 +81,13 @@ void loadGrom(const char* path) } fclose(fp); - OSD_drawText(3, 2, "Load GROM: OKAY"); + OSD_drawText(3, 2, "LOAD GROM: OKAY"); printf("[INFO] [FREEINTV] Succeeded loading Graphics BIOS from: %s\n", path); } else { - OSD_drawText(3, 2, "Load GROM: FAIL"); + OSD_drawText(3, 2, "LOAD GROM: FAIL"); printf("[ERROR] [FREEINTV] Failed loading Graphics BIOS from: %s\n", path); } }