2 // Virtual Jaguar Emulator
5 // GCC/SDL port by Niels Wagenaar (Linux/WIN32) and Caz (BeOS)
6 // Cleanups/fixes by James L. Hammons
9 // Added by SDLEMU (http://sdlemu.ngemu.com)
10 // Added for GCC UNIX compatibility
22 // Uncomment this for speed control
23 //#define SPEED_CONTROL
26 // Private function prototypes
29 uint32 JaguarLoadROM(uint8 *, char *);
30 void JaguarLoadCart(uint8 *, char *);
36 //static char *jaguar_bootRom_path="c:/jaguarEmu/newload.img";
37 static char * jaguar_bootRom_path = "./bios/jagboot.rom";
38 //static char *jaguar_bootRom_path="./bios/JagOS.bin";
39 char * jaguar_eeproms_path = "./eeproms/";
40 char jaguar_boot_dir[1024];
41 //static char romLoadDialog_filePath[1024];
46 Format format(16, 0x007C00, 0x00003E0, 0x0000001F);
47 bool finished = false;
48 bool fullscreen = false;
49 bool hardwareTypeNTSC = true; // Set to false for PAL
55 extern bool jaguar_use_bios;
56 extern bool dsp_enabled;
57 extern uint8 * jaguar_mainRam;
58 extern uint8 * jaguar_bootRom;
59 extern uint8 * jaguar_mainRom;
62 void main_screen_switch(void)
64 fullscreen = !fullscreen;
66 console.option("fullscreen output");
68 console.option("windowed output");
70 console.open("Virtual Jaguar", tom_width, tom_height, format);
73 // Added/changed by SDLEMU http://sdlemu.ngemu.com
75 int main(int argc, char * argv[])
77 uint32 startTime, totalFrames;//, endTime;//, w, h;
79 uint32 nNormalLast = 0;
80 int32 nNormalFrac = 0;
82 //unused int32 nTime = 0;
83 //unused int32 nCount = 0;
84 int32 nFrameskip = 0; // Default: Show every frame
85 int32 nFrame = 0; // No. of Frame
86 int32 nJoyport = 0; // Joystick port
88 printf("Virtual Jaguar/SDL v1.0.4 (GCC/SDL Port)\n");
89 printf("Based upon Virtual Jaguar core v1.0.0 by cal2 of Potato emulation.\n");
90 printf("Written by Niels Wagenaar (Linux/WIN32) and Caz (BeOS)\n");
91 printf("Portions massaged by James L. Hammons (WIN32)\n");
92 printf("Contact: http://sdlemu.ngemu.com/ | sdlemu@ngemu.com\n");
94 console.option("windowed output");
96 // BIOS is now ON by default--use the -nobios switch to turn it off!
97 jaguar_use_bios = true;
98 bool haveCart = false; // Assume there is no cartridge...!
100 // Checking the switches ;)
102 for(int i=1; i<argc || argv[i]!=NULL; i++)
104 // This would be the most likely place to do the cart loading...
105 if (argv[i][0] != '-')
106 haveCart = true; // It looks like we have a cartridge!
108 if (!strcmp(argv[i], "-fullscreen"))
111 console.option("fullscreen output");
114 if (!strcmp(argv[i], "-window"))
115 console.option("windowed output");
117 if (!strcmp(argv[i], "-joystick"))
118 console.option("joystick enabled");
120 if (!strcmp(argv[i], "-joyport"))
122 nJoyport = atoi(argv[++i]) + 1;
127 if (!strcmp(argv[i], "-frameskip"))
129 nFrameskip = atoi(argv[++i]) + 1;
137 if (!strcmp(argv[i], "-nobios"))
138 jaguar_use_bios = false;
140 if (!strcmp(argv[i], "-dspon"))
143 if (!strcmp(argv[i], "-pal"))
144 hardwareTypeNTSC = false;
146 if (!strcmp(argv[i], "-help") || !strcmp(argv[i], "-?"))
148 printf("Usage: \n\n");
149 printf("vj [romfile] [switches]\n");
150 printf(" -? or -help : Display usage and switches \n");
151 printf(" -fullscreen : Enable fullscreen mode \n");
152 printf(" -window : Enable windowed mode (default) \n");
153 printf(" -frameskip 1-10 : Enable frameskip 1 (default) - 10 \n");
154 printf(" -joystick : Enable joystick/gamepad \n");
155 printf(" -joyport 0-3 : Select desired joystick port \n");
156 printf(" -nobios : Boot cart without using Jaguar BIOS ROM \n");
157 printf(" -dspon : Force VJ to use the DSP \n");
158 printf(" -pal : Force VJ to PAL mode (default is NTSC) \n");
159 printf("\nInvoking Virtual Jagaur with no ROM file will cause it to boot up\n");
160 printf("with the Jaguar BIOS.\n");
165 getcwd(jaguar_boot_dir, 1024);
169 version_display(log_get());
174 JaguarLoadROM(jaguar_bootRom, jaguar_bootRom_path);
176 SET32(jaguar_mainRam, 0, 0x00200000); // Set top of stack...
178 // Get the cartridge ROM (if passed in)
181 JaguarLoadCart(jaguar_mainRom, argv[1]);
187 // Setting up the backbuffer
188 int16 * backbuffer = (int16 *)malloc(845 * 525 * sizeof(int16));
189 memset(backbuffer, 0xAA, tom_getVideoModeWidth() * tom_getVideoModeHeight() * sizeof(int16));
191 // Setting up the primary SDL display
192 surface = new Surface(tom_getVideoModeWidth(), tom_getVideoModeHeight(), format);
194 // Initialize Joystick support under SDL
195 if (console.JoyEnabled() == 1)
197 if (SDL_NumJoysticks() <= 0)
199 console.option("joystick disabled");
200 printf("No joystick(s) or joypad(s) detected on your system. Using keyboard...\n");
204 if ((console.joystick = SDL_JoystickOpen(nJoyport)) == 0)
206 console.option("joystick disabled");
207 printf("Unable to open a Joystick on port: %d\n", (int)nJoyport);
210 printf("Using: %s\n", SDL_JoystickName(nJoyport));
214 // Open the display and start emulating some 3l337 Atari Jaguar games :P
215 console.open("Virtual Jaguar", tom_getVideoModeWidth(), tom_getVideoModeHeight(), format);
219 nNormalLast = 0; // Last value of timeGetTime()
220 nNormalFrac = 0; // Extra fraction we did
221 nNormalLast = SDL_GetTicks(); //timeGetTime();
226 nTime = SDL_GetTicks() - nNormalLast; // calcule le temps écoulé depuis le dernier affichage
227 // nTime est en mili-secondes.
228 // détermine le nombre de trames à passer + 1
229 nCount = (nTime * 600 - nNormalFrac) / 10000;
231 // si le nombre de trames à passer + 1 est nul ou négatif,
232 // ne rien faire pendant 2 ms
237 } // No need to do anything for a bit
240 nNormalFrac += nCount * 10000; //
241 nNormalLast += nNormalFrac / 600; // add the duration of nNormalFrac frames
242 nNormalFrac %= 600; //
244 // Pas plus de 9 (10-1) trames non affichées
247 for(int i=0; i<nCount-1; i++)
248 jaguar_exec(backbuffer, false);
250 // Setting up new backbuffer with new pixels and data
251 jaguar_exec(backbuffer, true);
255 if (nFrame == nFrameskip)
257 int32 * vs = (int32 *)surface->lock();
258 memcpy(vs, backbuffer, tom_width * tom_height * 2);
260 surface->copy(console);
274 int elapsedTime = clock() - startTime;
275 int fps = (1000 * totalFrames) / elapsedTime;
276 fprintf(log_get(), "Statistics: %i FPS\n", fps);
278 if (console.JoyEnabled() == 1) {}
284 console.close(); // Close SDL items as last!
290 // Generic ROM loading
292 uint32 JaguarLoadROM(uint8 * rom, char * path)
296 WriteLog("JagEm: Loading %s...", path);
298 char * ext = strrchr(path, '.');
299 if (strcmpi(ext, ".zip") == 0)
301 // Handle ZIP file loading here...
302 WriteLog("(ZIPped)...");
304 if (load_zipped_file(0, 0, path, NULL, &rom, &romSize) == -1)
306 WriteLog("Failed!\n");
313 FILE * fp = fopen(path, "rb");
317 WriteLog("Failed!\n");
322 fseek(fp, 0, SEEK_END);
324 fseek(fp, 0, SEEK_SET);
325 fread(rom, 1, romSize, fp);
329 WriteLog("OK (%i bytes)\n", romSize);
334 // Jaguar cartridge ROM loading
336 void JaguarLoadCart(uint8 * mem, char * path)
338 uint32 romsize = JaguarLoadROM(mem, path);
339 jaguar_mainRom_crc32 = crc32_calcCheckSum(jaguar_mainRom, romsize);
340 WriteLog( "CRC: %08X\n", (unsigned int)jaguar_mainRom_crc32);