2 // Virtual Jaguar Emulator
5 // GCC/SDL port by Niels Wagenaar (Linux/WIN32) and Caz (BeOS)
6 // Cleanups/fixes by James L. Hammons
13 // GPU/DSP/video clock rate 26.590906 26.593900
14 // 68000 clock rate 13.295453 13.296950
15 // (clock rates in MHz)
18 // Added by SDLEMU (http://sdlemu.ngemu.com)
19 // Added for GCC UNIX compatibility
31 // Uncomment this for speed control
32 //#define SPEED_CONTROL
35 // Private function prototypes
38 uint32 JaguarLoadROM(uint8 *, char *);
39 void JaguarLoadCart(uint8 *, char *);
45 //static char *jaguar_bootRom_path="c:/jaguarEmu/newload.img";
46 static char * jaguar_bootRom_path = "./bios/jagboot.rom";
47 //static char *jaguar_bootRom_path="./bios/JagOS.bin";
48 char * jaguar_eeproms_path = "./eeproms/";
49 char jaguar_boot_dir[1024];
50 //static char romLoadDialog_filePath[1024];
55 Format format(16, 0x007C00, 0x00003E0, 0x0000001F);
56 bool finished = false;
57 bool fullscreen = false;
58 bool hardwareTypeNTSC = true; // Set to false for PAL
64 extern bool jaguar_use_bios;
65 extern bool dsp_enabled;
66 extern uint8 * jaguar_mainRam;
67 extern uint8 * jaguar_bootRom;
68 extern uint8 * jaguar_mainRom;
71 void main_screen_switch(void)
73 fullscreen = !fullscreen;
75 console.option("fullscreen output");
77 console.option("windowed output");
79 console.open("Virtual Jaguar", tom_width, tom_height, format);
82 // Added/changed by SDLEMU http://sdlemu.ngemu.com
84 uint32 totalFrames;//so we can grab this from somewhere else...
85 int main(int argc, char * argv[])
87 uint32 startTime;//, totalFrames;//, endTime;//, w, h;
89 uint32 nNormalLast = 0;
90 int32 nNormalFrac = 0;
92 //unused int32 nTime = 0;
93 //unused int32 nCount = 0;
94 int32 nFrameskip = 0; // Default: Show every frame
95 int32 nFrame = 0; // No. of Frame
96 int32 nJoyport = 0; // Joystick port
98 printf("Virtual Jaguar/SDL v1.0.5 (GCC/SDL Port)\n");
99 printf("Based upon Virtual Jaguar core v1.0.0 by cal2 of Potato emulation.\n");
100 printf("Written by Niels Wagenaar (Linux/WIN32) and Caz (BeOS)\n");
101 printf("Portions massaged by James L. Hammons (WIN32)\n");
102 printf("Contact: http://sdlemu.ngemu.com/ | sdlemu@ngemu.com\n");
104 console.option("windowed output");
106 // BIOS is now ON by default--use the -nobios switch to turn it off!
107 jaguar_use_bios = true;
108 bool haveCart = false; // Assume there is no cartridge...!
110 // Checking the switches ;)
112 for(int i=1; i<argc || argv[i]!=NULL; i++)
114 // This would be the most likely place to do the cart loading...
115 if (argv[i][0] != '-')
116 haveCart = true; // It looks like we have a cartridge!
118 if (!strcmp(argv[i], "-fullscreen"))
121 console.option("fullscreen output");
124 if (!strcmp(argv[i], "-window"))
125 console.option("windowed output");
127 if (!strcmp(argv[i], "-joystick"))
128 console.option("joystick enabled");
130 if (!strcmp(argv[i], "-joyport"))
132 nJoyport = atoi(argv[++i]) + 1;
137 if (!strcmp(argv[i], "-frameskip"))
139 nFrameskip = atoi(argv[++i]) + 1;
147 if (!strcmp(argv[i], "-nobios"))
148 jaguar_use_bios = false;
150 if (!strcmp(argv[i], "-dspon"))
153 if (!strcmp(argv[i], "-pal"))
154 hardwareTypeNTSC = false;
156 if (!strcmp(argv[i], "-help") || !strcmp(argv[i], "-?"))
158 printf("Usage: \n\n");
159 printf("vj [romfile] [switches]\n");
160 printf(" -? or -help : Display usage and switches \n");
161 printf(" -fullscreen : Enable fullscreen mode \n");
162 printf(" -window : Enable windowed mode (default) \n");
163 printf(" -frameskip 1-10 : Enable frameskip 1 (default) - 10 \n");
164 printf(" -joystick : Enable joystick/gamepad \n");
165 printf(" -joyport 0-3 : Select desired joystick port \n");
166 printf(" -nobios : Boot cart without using Jaguar BIOS ROM \n");
167 printf(" -dspon : Force VJ to use the DSP \n");
168 printf(" -pal : Force VJ to PAL mode (default is NTSC) \n");
169 printf("\nInvoking Virtual Jagaur with no ROM file will cause it to boot up\n");
170 printf("with the Jaguar BIOS.\n");
175 getcwd(jaguar_boot_dir, 1024);
179 version_display(log_get());
184 JaguarLoadROM(jaguar_bootRom, jaguar_bootRom_path);
186 SET32(jaguar_mainRam, 0, 0x00200000); // Set top of stack...
188 // Get the cartridge ROM (if passed in)
191 JaguarLoadCart(jaguar_mainRom, argv[1]);
197 // Setting up the backbuffer
198 int16 * backbuffer = (int16 *)malloc(845 * 525 * sizeof(int16));
199 memset(backbuffer, 0xAA, tom_getVideoModeWidth() * tom_getVideoModeHeight() * sizeof(int16));
201 // Setting up the primary SDL display
202 surface = new Surface(tom_getVideoModeWidth(), tom_getVideoModeHeight(), format);
204 // Initialize Joystick support under SDL
205 if (console.JoyEnabled() == 1)
207 if (SDL_NumJoysticks() <= 0)
209 console.option("joystick disabled");
210 printf("No joystick(s) or joypad(s) detected on your system. Using keyboard...\n");
214 if ((console.joystick = SDL_JoystickOpen(nJoyport)) == 0)
216 console.option("joystick disabled");
217 printf("Unable to open a Joystick on port: %d\n", (int)nJoyport);
220 printf("Using: %s\n", SDL_JoystickName(nJoyport));
224 // Open the display and start emulating some 3l337 Atari Jaguar games :P
225 console.open("Virtual Jaguar", tom_getVideoModeWidth(), tom_getVideoModeHeight(), format);
229 nNormalLast = 0; // Last value of timeGetTime()
230 nNormalFrac = 0; // Extra fraction we did
231 nNormalLast = SDL_GetTicks(); //timeGetTime();
236 nTime = SDL_GetTicks() - nNormalLast; // calcule le temps écoulé depuis le dernier affichage
237 // nTime est en mili-secondes.
238 // détermine le nombre de trames à passer + 1
239 nCount = (nTime * 600 - nNormalFrac) / 10000;
241 // si le nombre de trames à passer + 1 est nul ou négatif,
242 // ne rien faire pendant 2 ms
247 } // No need to do anything for a bit
250 nNormalFrac += nCount * 10000; //
251 nNormalLast += nNormalFrac / 600; // add the duration of nNormalFrac frames
252 nNormalFrac %= 600; //
254 // Pas plus de 9 (10-1) trames non affichées
257 for(int i=0; i<nCount-1; i++)
258 jaguar_exec(backbuffer, false);
260 // Setting up new backbuffer with new pixels and data
261 // jaguar_exec(backbuffer, true);
262 JaguarExecute(backbuffer, true);
266 if (nFrame == nFrameskip)
268 int32 * vs = (int32 *)surface->lock();
269 memcpy(vs, backbuffer, tom_width * tom_height * 2);
271 surface->copy(console);
285 int elapsedTime = clock() - startTime;
286 int fps = (1000 * totalFrames) / elapsedTime;
287 fprintf(log_get(), "Statistics: %i FPS\n", fps);
289 if (console.JoyEnabled() == 1) {}
295 console.close(); // Close SDL items as last!
301 // Generic ROM loading
303 uint32 JaguarLoadROM(uint8 * rom, char * path)
307 WriteLog("JagEm: Loading %s...", path);
309 char * ext = strrchr(path, '.');
310 if (strcmpi(ext, ".zip") == 0)
312 // Handle ZIP file loading here...
313 WriteLog("(ZIPped)...");
315 if (load_zipped_file(0, 0, path, NULL, &rom, &romSize) == -1)
317 WriteLog("Failed!\n");
324 FILE * fp = fopen(path, "rb");
328 WriteLog("Failed!\n");
333 fseek(fp, 0, SEEK_END);
335 fseek(fp, 0, SEEK_SET);
336 fread(rom, 1, romSize, fp);
340 WriteLog("OK (%i bytes)\n", romSize);
345 // Jaguar cartridge ROM loading
347 void JaguarLoadCart(uint8 * mem, char * path)
349 uint32 romsize = JaguarLoadROM(mem, path);
350 jaguar_mainRom_crc32 = crc32_calcCheckSum(jaguar_mainRom, romsize);
351 WriteLog( "CRC: %08X\n", (unsigned int)jaguar_mainRom_crc32);