+//
+// Jaguar file loading (second stab at it...)
+// We do a more intelligent file analysis here instead of relying on (possible false)
+// file extensions which people don't seem to give two shits about anyway. :-(
+//
+bool JaguarLoadFile(char * path)
+{
+// NOTE: We can further clean this up by fixing JaguarLoadROM to load to a buffer
+// instead of assuming it goes into our ROM space.
+ jaguarROMSize = JaguarLoadROM(jaguarMainROM, path);
+
+ if (jaguarROMSize == 0)
+ {
+// WriteLog("VJ: Could not load ROM from file \"%s\"...\nAborting!\n", newPath);
+ WriteLog("GUI: Could not load ROM from file \"%s\"...\nAborting load!\n", path);
+#warning "!!! Need error dialog here !!!"
+// Need to do something else here, like throw up an error dialog instead of aborting. !!! FIX !!!
+ return false; // This is a start...
+ }
+
+ jaguarMainROMCRC32 = crc32_calcCheckSum(jaguarMainROM, jaguarROMSize);
+ WriteLog("CRC: %08X\n", (unsigned int)jaguarMainROMCRC32);
+// TODO: Check for EEPROM file in ZIP file. If there is no EEPROM in the user's EEPROM
+// directory, copy the one from the ZIP file, if it exists.
+ EepromInit();
+ jaguarRunAddress = 0x802000; // For non-BIOS runs, this is true
+ int fileType = ParseFileType(jaguarMainROM[0], jaguarMainROM[1], jaguarROMSize);
+
+ if (fileType == JST_ROM)
+ return true;
+ else if (fileType == JST_ALPINE)
+ {
+ // File extension ".ROM": Alpine image that loads/runs at $802000
+ WriteLog("GUI: Setting up Alpine ROM... Run address: 00802000, length: %08X\n", jaguarROMSize);
+
+ for(int i=jaguarROMSize-1; i>=0; i--)
+ jaguarMainROM[0x2000 + i] = jaguarMainROM[i];
+
+ memset(jaguarMainROM, 0xFF, 0x2000);
+
+// Maybe instead of this, we could try requiring the STUBULATOR ROM? Just a thought...
+ // Try setting the vector to say, $1000 and putting an instruction there that loops forever:
+ // This kludge works! Yeah!
+ SET32(jaguarMainRAM, 0x10, 0x00001000);
+ SET16(jaguarMainRAM, 0x1000, 0x60FE); // Here: bra Here
+ return true;
+ }
+ else if (fileType == JST_ABS_TYPE1)
+ {
+ uint32 loadAddress = GET32(jaguarMainROM, 0x16),
+ codeSize = GET32(jaguarMainROM, 0x02) + GET32(jaguarMainROM, 0x06);
+ WriteLog("GUI: Setting up homebrew (ABS-1)... Run address: %08X, length: %08X\n", loadAddress, codeSize);
+
+ if (loadAddress < 0x800000)
+ memcpy(jaguarMainRAM + loadAddress, jaguarMainROM + 0x24, codeSize);
+ else
+ {
+ for(int i=codeSize-1; i>=0; i--)
+ jaguarMainROM[(loadAddress - 0x800000) + i] = jaguarMainROM[i + 0x24];
+ }
+
+ jaguarRunAddress = loadAddress;
+ return true;
+ }
+ else if (fileType == JST_ABS_TYPE2)
+ {
+ uint32 loadAddress = GET32(jaguarMainROM, 0x28), runAddress = GET32(jaguarMainROM, 0x24),
+ codeSize = GET32(jaguarMainROM, 0x18) + GET32(jaguarMainROM, 0x1C);
+ WriteLog("GUI: Setting up homebrew (ABS-2)... Run address: %08X, length: %08X\n", runAddress, codeSize);
+
+ if (loadAddress < 0x800000)
+ memcpy(jaguarMainRAM + loadAddress, jaguarMainROM + 0xA8, codeSize);
+ else
+ {
+ for(int i=codeSize-1; i>=0; i--)
+ jaguarMainROM[(loadAddress - 0x800000) + i] = jaguarMainROM[i + 0xA8];
+ }
+
+ jaguarRunAddress = runAddress;
+ return true;
+ }
+ else if (fileType == JST_JAGSERVER)
+ {
+ uint32 loadAddress = GET32(jaguarMainROM, 0x22), runAddress = GET32(jaguarMainROM, 0x2A);
+ WriteLog("GUI: Setting up homebrew (Jag Server)... Run address: %08X, length: %08X\n", runAddress, jaguarROMSize - 0x2E);
+ memcpy(jaguarMainRAM + loadAddress, jaguarMainROM + 0x2E, jaguarROMSize - 0x2E);
+ jaguarRunAddress = runAddress;
+ return true;
+ }
+
+ // We can assume we have JST_NONE at this point. :-P
+ // TODO: Add a dialog box that tells the user that they're trying to feed VJ a bogus file.
+ return false;
+}
+