X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fvj.cpp;h=132c7a705e06745c6203d7e72ef5f6ec64166446;hb=1c6628e5d7f732e1bfac22ce81f5a79e20dfbb8e;hp=58589ac1dc7c4b131a42292a96638c6a196d292e;hpb=67a5f1a40072983cf87ae2093ca95c271d14e706;p=virtualjaguar diff --git a/src/vj.cpp b/src/vj.cpp index 58589ac..132c7a7 100644 --- a/src/vj.cpp +++ b/src/vj.cpp @@ -12,6 +12,7 @@ #include #endif // __GCCUNIX__ +#include // POSIX, but should compile with linux & mingw... #include #include #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,13 @@ 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]); - +//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) @@ -190,8 +189,6 @@ int main(int argc, char * argv[]) 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) @@ -232,6 +229,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 +279,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 +322,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 (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; } @@ -374,8 +368,33 @@ 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"); + +//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(); }