]> Shamusworld >> Repos - virtualjaguar/blobdiff - src/vj.cpp
More changes for upcoming 1.0.5 release ;-)
[virtualjaguar] / src / vj.cpp
index 58589ac1dc7c4b131a42292a96638c6a196d292e..9dbfe023f6077b66a4129694e70e331b53fda5f0 100644 (file)
@@ -12,6 +12,7 @@
 #include <unistd.h>
 #endif // __GCCUNIX__
 
+#include <dirent.h>                                    // POSIX, but should compile with linux & mingw...
 #include <time.h>
 #include <SDL.h>
 #include "jaguar.h"
@@ -46,6 +47,7 @@ char * jaguar_eeproms_path = "./eeproms/";
 char jaguar_boot_dir[1024];
 
 SDL_Surface * surface, * mainSurface;
+int16 * backbuffer = NULL;
 SDL_Joystick * joystick;
 Uint32 mainSurfaceFlags = SDL_SWSURFACE;
 
@@ -56,10 +58,9 @@ bool hardwareTypeNTSC = true;                        // Set to false for PAL
 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;
@@ -155,15 +156,12 @@ int main(int argc, char * argv[])
 
        SET32(jaguar_mainRam, 0, 0x00200000);                   // Set top of stack...
 
-       // Get the cartridge ROM (if passed in)
-       if (haveCart)
-               JaguarLoadCart(jaguar_mainRom, argv[1]);
-
        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)
@@ -232,6 +230,16 @@ int main(int argc, char * argv[])
                }
        }
 
+       // 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()
@@ -272,30 +280,15 @@ int main(int argc, char * argv[])
                        // 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
@@ -330,42 +323,44 @@ int main(int argc, char * argv[])
 //
 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 (strcmpi(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;
 }
 
@@ -374,8 +369,31 @@ uint32 JaguarLoadROM(uint8 * rom, char * path)
 //
 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");
+
+               if (!UserSelectFile(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();
 }