2 // Virtual Jaguar Emulator
4 // Original codebase by David Raingeard (Cal2)
5 // GCC/SDL port by Niels Wagenaar (Linux/WIN32) and Caz (BeOS)
6 // Cleanups/fixes/enhancements by James L. Hammons and Adam Green
10 #include <unistd.h> // Is this necessary anymore?
18 #include "sdlemu_opengl.h"
19 #include "settings.h" // Pull in "vjs" struct
21 // Uncomment this for speed control (?)
22 //#define SPEED_CONTROL
24 // Uncomment this to use built-in BIOS/CD-ROM BIOS
25 // You'll need a copy of jagboot.h & jagcd.h for this to work...!
26 //#define USE_BUILT_IN_BIOS
28 #ifdef USE_BUILT_IN_BIOS
33 // Private function prototypes
37 extern uint8 * jaguar_mainRam;
38 extern uint8 * jaguar_mainRom;
39 extern uint8 * jaguar_bootRom;
40 extern uint8 * jaguar_CDBootROM;
42 // Global variables (export capable)
43 //should these even be here anymore?
45 bool finished = false;
47 bool showMessage = false;
48 uint32 showMessageTimeout;
49 char messageBuffer[200];
50 bool BIOSLoaded = false;
51 bool CDBIOSLoaded = false;
54 // The main emulator loop (what else?)
56 //Maybe we should move the video stuff to TOM? Makes more sense to put it there...
57 //Actually, it would probably be better served in VIDEO.CPP... !!! FIX !!! [DONE]
58 uint32 totalFrames;//temp, so we can grab this from elsewhere...
59 int main(int argc, char * argv[])
61 // uint32 startTime;//, totalFrames;//, endTime;//, w, h;
62 // uint32 nNormalLast = 0;
63 // int32 nNormalFrac = 0;
64 int32 nFrameskip = 0; // Default: Show every frame
65 // int32 nFrame = 0; // No. of Frame
67 printf("Virtual Jaguar GCC/SDL Portable Jaguar Emulator v1.0.8\n");
68 printf("Based upon Virtual Jaguar core v1.0.0 by David Raingeard.\n");
69 printf("Written by Niels Wagenaar (Linux/WIN32), Carwin Jones (BeOS),\n");
70 printf("James L. Hammons (WIN32) and Adam Green (MacOS)\n");
71 printf("Contact: http://sdlemu.ngemu.com/ | sdlemu@ngemu.com\n");
73 bool haveCart = false; // Assume there is no cartridge...!
76 LoadVJSettings(); // Get config file settings...
78 // Check the switches... ;-)
79 // NOTE: Command line switches can override any config file settings, thus the
80 // proliferation of the noXXX switches. ;-)
82 for(int i=1; i<argc || argv[i]!=NULL; i++)
84 // This would be the most likely place to do the cart loading...
85 if (argv[i][0] != '-')
86 haveCart = true; // It looks like we have a cartridge!
88 if (!strcmp(argv[i], "-joystick"))
89 vjs.useJoystick = true;
91 if (!strcmp(argv[i], "-joyport"))
93 vjs.joyport = atoi(argv[++i]) + 1;
98 if (!strcmp(argv[i], "-frameskip"))
100 nFrameskip = atoi(argv[++i]) + 1;
108 if (!strcmp(argv[i], "-bios"))
109 vjs.useJaguarBIOS = true;
111 if (!strcmp(argv[i], "-nobios"))
112 vjs.useJaguarBIOS = false;
114 if (!strcmp(argv[i], "-dsp"))
115 vjs.DSPEnabled = true;
117 if (!strcmp(argv[i], "-nodsp"))
118 vjs.DSPEnabled = false;
120 if (!strcmp(argv[i], "-pipeline"))
121 vjs.usePipelinedDSP = true;
123 if (!strcmp(argv[i], "-nopipeline"))
124 vjs.usePipelinedDSP = false;
126 if (!strcmp(argv[i], "-gl"))
127 vjs.useOpenGL = true;
129 if (!strcmp(argv[i], "-nogl"))
130 vjs.useOpenGL = false;
132 if (!strcmp(argv[i], "-fullscreen"))
133 vjs.fullscreen = true;
135 if (!strcmp(argv[i], "-window"))
136 vjs.fullscreen = false;
138 if (!strcmp(argv[i], "-pal"))
139 vjs.hardwareTypeNTSC = false;
141 if (!strcmp(argv[i], "-ntsc"))
142 vjs.hardwareTypeNTSC = true;
144 if (!strcmp(argv[i], "-help") || !strcmp(argv[i], "-?"))
146 printf("Usage: \n\n");
147 printf("vj [romfile] [switches]\n");
148 printf(" -? or -help : Display usage and switches \n");
149 printf(" -frameskip 1-10 : Enable frameskip 1 - 10 (default: none) \n");
150 printf(" -joystick : Enable joystick/gamepad \n");
151 printf(" -joyport 0-3 : Select desired joystick port \n");
152 printf(" -bios : Boot cart using Jaguar BIOS ROM \n");
153 printf(" -nobios : Boot cart without using Jaguar BIOS ROM \n");
154 printf(" -dsp : Force VJ to use the DSP \n");
155 printf(" -nodsp : Force VJ to run without the DSP \n");
156 printf(" -pipeline : Use the DSP pipelined core \n");
157 printf(" -nopipeline : Use the DSP non-pipelined core \n");
158 printf(" -gl : Use OpenGL rendering \n");
159 printf(" -nogl : Use old non-OpenGL rendering \n");
160 printf(" -fullscreen : Enable fullscreen mode (default: windowed)\n");
161 printf(" -window : Enable windowed mode \n");
162 printf(" -pal : Force VJ to PAL mode (default: NTSC) \n");
163 printf(" -ntsc : Force VJ to NTSC mode \n");
164 printf("\nInvoking Virtual Jagaur with no ROM file will cause it to boot up\n");
165 printf("with the VJ GUI.\n");
170 // Set up SDL library
171 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_AUDIO | SDL_INIT_TIMER) < 0)
172 // | SDL_INIT_CDROM) < 0)
173 // | SDL_INIT_CDROM | SDL_INIT_NOPARACHUTE) < 0)
175 WriteLog("VJ: Could not initialize the SDL library: %s\n", SDL_GetError());
179 WriteLog("VJ: SDL successfully initialized.\n");
181 WriteLog("Initializing memory subsystem...\n");
183 WriteLog("Initializing version...\n");
185 version_display(log_get());
186 WriteLog("Initializing jaguar subsystem...\n");
190 #ifdef USE_BUILT_IN_BIOS
191 WriteLog("VJ: Using built in BIOS/CD BIOS...\n");
192 memcpy(jaguar_bootRom, jagBootROM, 0x20000);
193 memcpy(jaguar_CDBootROM, jagCDROM, 0x40000);
194 BIOSLoaded = CDBIOSLoaded = true;
196 // if (vjs.useJaguarBIOS)
197 // What would be nice here would be a way to check if the BIOS was loaded so that we
198 // could disable the pushbutton on the Misc Options menu... !!! FIX !!! [DONE here, but needs to be fixed in GUI as well!]
199 WriteLog("About to attempt to load BIOSes...\n");
200 BIOSLoaded = (JaguarLoadROM(jaguar_bootRom, vjs.jagBootPath) == 0x20000 ? true : false);
201 WriteLog("VJ: BIOS is %savailable...\n", (BIOSLoaded ? "" : "not "));
202 CDBIOSLoaded = (JaguarLoadROM(jaguar_CDBootROM, vjs.CDBootPath) == 0x40000 ? true : false);
203 WriteLog("VJ: CD BIOS is %savailable...\n", (CDBIOSLoaded ? "" : "not "));
206 SET32(jaguar_mainRam, 0, 0x00200000); // Set top of stack...
208 WriteLog("Initializing video subsystem...\n");
210 WriteLog("Initializing GUI subsystem...\n");
213 // Get the cartridge ROM (if passed in)
214 // Now with crunchy GUI goodness!
215 // JaguarLoadCart(jaguar_mainRom, (haveCart ? argv[1] : vjs.ROMPath));
216 //Need to find a better way to handle this crap...
217 WriteLog("About to start GUI...\n");
219 GUIMain(haveCart ? argv[1] : NULL);
225 nNormalLast = 0; // Last value of timeGetTime()
226 nNormalFrac = 0; // Extra fraction we did
227 nNormalLast = SDL_GetTicks(); //timeGetTime();
232 nTime = SDL_GetTicks() - nNormalLast; // calcule le temps écoulé depuis le dernier affichage
233 // nTime est en mili-secondes.
234 // détermine le nombre de trames à passer + 1
235 nCount = (nTime * 600 - nNormalFrac) / 10000;
237 // si le nombre de trames à passer + 1 est nul ou négatif,
238 // ne rien faire pendant 2 ms
243 } // No need to do anything for a bit
246 nNormalFrac += nCount * 10000; //
247 nNormalLast += nNormalFrac / 600; // add the duration of nNormalFrac frames
248 nNormalFrac %= 600; //
250 // Pas plus de 9 (10-1) trames non affichées
253 for(int i=0; i<nCount-1; i++)
254 jaguar_exec(backbuffer, false);
256 // Set up new backbuffer with new pixels and data
257 JaguarExecute(backbuffer, true);
259 //WriteLog("Frame #%u...\n", totalFrames);
260 //extern bool doDSPDis;
261 //if (totalFrames == 373)
264 // Some QnD GUI stuff here...
267 extern uint32 gpu_pc, dsp_pc;
268 DrawString(backbuffer, 8, 8, false, "GPU PC: %08X", gpu_pc);
269 DrawString(backbuffer, 8, 16, false, "DSP PC: %08X", dsp_pc);
273 if (nFrame == nFrameskip)
288 //This is no longer accurate...!
289 // int elapsedTime = clock() - startTime;
290 // int fps = (1000 * totalFrames) / elapsedTime;
291 // WriteLog("VJ: Ran at an average of %i FPS.\n", fps);
299 // Free SDL components last...!
300 // SDL_QuitSubSystem(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_AUDIO | SDL_INIT_TIMER | SDL_INIT_CDROM);
301 SDL_QuitSubSystem(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_AUDIO | SDL_INIT_TIMER);