#include <unistd.h>
#endif // __GCCUNIX__
+#include <dirent.h> // POSIX, but should compile with linux & mingw...
#include <time.h>
#include <SDL.h>
#include "jaguar.h"
char jaguar_boot_dir[1024];
SDL_Surface * surface, * mainSurface;
+int16 * backbuffer = NULL;
SDL_Joystick * joystick;
Uint32 mainSurfaceFlags = SDL_SWSURFACE;
bool useJoystick = false;
bool showGUI = false;
-
// Added/changed by SDLEMU http://sdlemu.ngemu.com
-uint32 totalFrames;//so we can grab this from elsewhere...
+uint32 totalFrames;//temp, so we can grab this from elsewhere...
int main(int argc, char * argv[])
{
uint32 startTime;//, totalFrames;//, endTime;//, w, h;
SET32(jaguar_mainRam, 0, 0x00200000); // Set top of stack...
- // Get the cartridge ROM (if passed in)
- if (haveCart)
- JaguarLoadCart(jaguar_mainRom, argv[1]);
-
+//This is done here, so that we get valid numbers from TOM... !!! FIX !!!
jaguar_reset();
-
+
// Set up the backbuffer
- int16 * backbuffer = (int16 *)malloc(845 * 525 * sizeof(int16));
- memset(backbuffer, 0xAA, tom_getVideoModeWidth() * tom_getVideoModeHeight() * sizeof(int16));
+// int16 * backbuffer = (int16 *)malloc(845 * 525 * sizeof(int16));
+ backbuffer = (int16 *)malloc(845 * 525 * sizeof(int16));
+ memset(backbuffer, 0x22, tom_getVideoModeWidth() * tom_getVideoModeHeight() * sizeof(int16));
// Set up SDL library
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_AUDIO | SDL_INIT_TIMER | SDL_INIT_NOPARACHUTE) < 0)
if (fullscreen)
mainSurfaceFlags |= SDL_FULLSCREEN;
- // Note: mainSurface is *never* used again!
- //Not true--had to look at what's what here... It's the primary surface...
mainSurface = SDL_SetVideoMode(tom_getVideoModeWidth(), tom_getVideoModeHeight(), 16, mainSurfaceFlags);
if (mainSurface == NULL)
}
}
+ // Get the cartridge ROM (if passed in)
+// if (haveCart)
+// JaguarLoadCart(jaguar_mainRom, argv[1]);
+ // Now with crunchy GUI goodness!
+ JaguarLoadCart(jaguar_mainRom, (haveCart ? argv[1] : (char *)""));
+
+//Do this again??? Hmm... This is not very nice.
+//Maybe it's not necessary??? Seems to be, at least for PD ROMs... !!! FIX !!!
+ jaguar_reset();
+
totalFrames = 0;
startTime = clock();
nNormalLast = 0; // Last value of timeGetTime()
// GUI stuff here...
if (showGUI)
{
- extern uint32 gpu_pc;
- extern uint32 dsp_pc;
- DrawText(backbuffer, 8, 0, "Friendly GUI brought to you by JLH ;-)");
- DrawText(backbuffer, 8, 8, "GPU PC: %08X", gpu_pc);
- DrawText(backbuffer, 8, 16, "DSP PC: %08X", dsp_pc);
+ extern uint32 gpu_pc, dsp_pc;
+ DrawText(backbuffer, 8, 8, false, "GPU PC: %08X", gpu_pc);
+ DrawText(backbuffer, 8, 16, false, "DSP PC: %08X", dsp_pc);
}
// Simple frameskip
if (nFrame == nFrameskip)
{
- if (SDL_MUSTLOCK(surface))
- while (SDL_LockSurface(surface) < 0)
- SDL_Delay(10);
-
- memcpy(surface->pixels, backbuffer, tom_width * tom_height * 2);
-
- if (SDL_MUSTLOCK(surface))
- SDL_UnlockSurface(surface);
-
- SDL_Rect srcrect, dstrect;
- srcrect.x = srcrect.y = 0, srcrect.w = surface->w, srcrect.h = surface->h;
- dstrect.x = dstrect.y = 0, dstrect.w = surface->w, dstrect.h = surface->h;
- SDL_BlitSurface(surface, &srcrect, mainSurface, &dstrect);
- SDL_Flip(mainSurface);
+ BlitBackbuffer();
nFrame = 0;
}
else
//
uint32 JaguarLoadROM(uint8 * rom, char * path)
{
- uint32 romSize;
-
- WriteLog("JagEm: Loading %s...", path);
+ uint32 romSize = 0;
char * ext = strrchr(path, '.');
- if (strcmpi(ext, ".zip") == 0)
+ if (ext != NULL)
{
- // Handle ZIP file loading here...
- WriteLog("(ZIPped)...");
+ WriteLog("VJ: Loading %s...", path);
- if (load_zipped_file(0, 0, path, NULL, &rom, &romSize) == -1)
+ if (stricmp(ext, ".zip") == 0)
{
- WriteLog("Failed!\n");
- log_done();
- exit(0);
- }
- }
- else
- {
- FILE * fp = fopen(path, "rb");
+ // Handle ZIP file loading here...
+ WriteLog("(ZIPped)...");
- if (fp == NULL)
+ if (load_zipped_file(0, 0, path, NULL, &rom, &romSize) == -1)
+ {
+ WriteLog("Failed!\n");
+ return 0;
+ }
+ }
+ else
{
- WriteLog("Failed!\n");
- log_done();
- exit(0);
+ FILE * fp = fopen(path, "rb");
+
+ if (fp == NULL)
+ {
+ WriteLog("Failed!\n");
+ return 0;
+ }
+
+ fseek(fp, 0, SEEK_END);
+ romSize = ftell(fp);
+ fseek(fp, 0, SEEK_SET);
+ fread(rom, 1, romSize, fp);
+ fclose(fp);
}
- fseek(fp, 0, SEEK_END);
- romSize = ftell(fp);
- fseek(fp, 0, SEEK_SET);
- fread(rom, 1, romSize, fp);
- fclose(fp);
+ WriteLog("OK (%i bytes)\n", romSize);
}
- WriteLog("OK (%i bytes)\n", romSize);
return romSize;
}
//
void JaguarLoadCart(uint8 * mem, char * path)
{
- uint32 romsize = JaguarLoadROM(mem, path);
- jaguar_mainRom_crc32 = crc32_calcCheckSum(jaguar_mainRom, romsize);
- WriteLog( "CRC: %08X\n", (unsigned int)jaguar_mainRom_crc32);
+ uint32 romSize = JaguarLoadROM(mem, path);
+
+ if (romSize == 0)
+ {
+ char newPath[2048];
+ WriteLog("VJ: Trying GUI...\n");
+
+//This is not *nix friendly for some reason...
+// if (!UserSelectFile(path, newPath))
+ if (!UserSelectFile((path == "" ? (char *)"." : path), newPath))
+ {
+ WriteLog("VJ: Could not find valid ROM in directory \"%s\"...\nAborting!\n", path);
+ log_done();
+ exit(0);
+ }
+
+ romSize = JaguarLoadROM(mem, newPath);
+
+ if (romSize == 0)
+ {
+ WriteLog("VJ: Could not load ROM from file \"%s\"...\nAborting!\n", newPath);
+ log_done();
+ exit(0);
+ }
+ }
+
+ jaguar_mainRom_crc32 = crc32_calcCheckSum(jaguar_mainRom, romSize);
+ WriteLog("CRC: %08X\n", (unsigned int)jaguar_mainRom_crc32);
eeprom_init();
}