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 // Private function prototypes
28 extern uint8 * jaguar_mainRam;
29 extern uint8 * jaguar_mainRom;
30 extern uint8 * jaguar_bootRom;
31 extern uint8 * jaguar_CDBootROM;
33 // Global variables (export capable)
34 //should these even be here anymore?
36 bool finished = false;
38 bool showMessage = false;
39 uint32 showMessageTimeout;
40 char messageBuffer[200];
41 bool BIOSLoaded = false;
42 bool CDBIOSLoaded = false;
45 // The main emulator loop (what else?)
47 //Maybe we should move the video stuff to TOM? Makes more sense to put it there...
48 //Actually, it would probably be better served in VIDEO.CPP... !!! FIX !!! [DONE]
49 uint32 totalFrames;//temp, so we can grab this from elsewhere...
50 int main(int argc, char * argv[])
52 // uint32 startTime;//, totalFrames;//, endTime;//, w, h;
53 // uint32 nNormalLast = 0;
54 // int32 nNormalFrac = 0;
55 int32 nFrameskip = 0; // Default: Show every frame
56 // int32 nFrame = 0; // No. of Frame
58 printf("Virtual Jaguar GCC/SDL Portable Jaguar Emulator v1.0.7\n");
59 printf("Based upon Virtual Jaguar core v1.0.0 by David Raingeard.\n");
60 printf("Written by Niels Wagenaar (Linux/WIN32), Carwin Jones (BeOS),\n");
61 printf("James L. Hammons (WIN32) and Adam Green (MacOS)\n");
62 printf("Contact: http://sdlemu.ngemu.com/ | sdlemu@ngemu.com\n");
64 bool haveCart = false; // Assume there is no cartridge...!
67 LoadVJSettings(); // Get config file settings...
69 // Check the switches... ;-)
70 // NOTE: Command line switches can override any config file settings, thus the
71 // proliferation of the noXXX switches. ;-)
73 for(int i=1; i<argc || argv[i]!=NULL; i++)
75 // This would be the most likely place to do the cart loading...
76 if (argv[i][0] != '-')
77 haveCart = true; // It looks like we have a cartridge!
79 if (!strcmp(argv[i], "-joystick"))
80 vjs.useJoystick = true;
82 if (!strcmp(argv[i], "-joyport"))
84 vjs.joyport = atoi(argv[++i]) + 1;
89 if (!strcmp(argv[i], "-frameskip"))
91 nFrameskip = atoi(argv[++i]) + 1;
99 if (!strcmp(argv[i], "-bios"))
100 vjs.useJaguarBIOS = true;
102 if (!strcmp(argv[i], "-nobios"))
103 vjs.useJaguarBIOS = false;
105 if (!strcmp(argv[i], "-dsp"))
106 vjs.DSPEnabled = true;
108 if (!strcmp(argv[i], "-nodsp"))
109 vjs.DSPEnabled = false;
111 if (!strcmp(argv[i], "-pipeline"))
112 vjs.usePipelinedDSP = true;
114 if (!strcmp(argv[i], "-nopipeline"))
115 vjs.usePipelinedDSP = false;
117 if (!strcmp(argv[i], "-gl"))
118 vjs.useOpenGL = true;
120 if (!strcmp(argv[i], "-nogl"))
121 vjs.useOpenGL = false;
123 if (!strcmp(argv[i], "-fullscreen"))
124 vjs.fullscreen = true;
126 if (!strcmp(argv[i], "-window"))
127 vjs.fullscreen = false;
129 if (!strcmp(argv[i], "-pal"))
130 vjs.hardwareTypeNTSC = false;
132 if (!strcmp(argv[i], "-ntsc"))
133 vjs.hardwareTypeNTSC = true;
135 if (!strcmp(argv[i], "-help") || !strcmp(argv[i], "-?"))
137 printf("Usage: \n\n");
138 printf("vj [romfile] [switches]\n");
139 printf(" -? or -help : Display usage and switches \n");
140 printf(" -frameskip 1-10 : Enable frameskip 1 - 10 (default: none) \n");
141 printf(" -joystick : Enable joystick/gamepad \n");
142 printf(" -joyport 0-3 : Select desired joystick port \n");
143 printf(" -bios : Boot cart using Jaguar BIOS ROM \n");
144 printf(" -nobios : Boot cart without using Jaguar BIOS ROM \n");
145 printf(" -dsp : Force VJ to use the DSP \n");
146 printf(" -nodsp : Force VJ to run without the DSP \n");
147 printf(" -pipeline : Use the DSP pipelined core \n");
148 printf(" -nopipeline : Use the DSP non-pipelined core \n");
149 printf(" -gl : Use OpenGL rendering \n");
150 printf(" -nogl : Use old non-OpenGL rendering \n");
151 printf(" -fullscreen : Enable fullscreen mode (default: windowed)\n");
152 printf(" -window : Enable windowed mode \n");
153 printf(" -pal : Force VJ to PAL mode (default: NTSC) \n");
154 printf(" -ntsc : Force VJ to NTSC mode \n");
155 printf("\nInvoking Virtual Jagaur with no ROM file will cause it to boot up\n");
156 printf("with the VJ GUI.\n");
161 // Set up SDL library
162 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_AUDIO | SDL_INIT_TIMER) < 0)
163 // | SDL_INIT_CDROM) < 0)
164 // | SDL_INIT_CDROM | SDL_INIT_NOPARACHUTE) < 0)
166 WriteLog("VJ: Could not initialize the SDL library: %s\n", SDL_GetError());
169 WriteLog("VJ: SDL successfully initialized.\n");
171 WriteLog("Initializing memory subsystem...\n");
173 WriteLog("Initializing version...\n");
175 version_display(log_get());
176 WriteLog("Initializing jaguar subsystem...\n");
180 // if (vjs.useJaguarBIOS)
181 // What would be nice here would be a way to check if the BIOS was loaded so that we
182 // could disable the pushbutton on the Misc Options menu... !!! FIX !!! [DONE here, but needs to be fixed in GUI as well!]
183 WriteLog("About to attempt to load BIOSes...\n");
184 BIOSLoaded = (JaguarLoadROM(jaguar_bootRom, vjs.jagBootPath) == 0x20000 ? true : false);
185 WriteLog("VJ: BIOS is %savailable...\n", (BIOSLoaded ? "" : "not "));
186 CDBIOSLoaded = (JaguarLoadROM(jaguar_CDBootROM, vjs.CDBootPath) == 0x40000 ? true : false);
187 WriteLog("VJ: CD BIOS is %savailable...\n", (CDBIOSLoaded ? "" : "not "));
189 SET32(jaguar_mainRam, 0, 0x00200000); // Set top of stack...
191 WriteLog("Initializing video subsystem...\n");
193 WriteLog("Initializing GUI subsystem...\n");
196 // Get the cartridge ROM (if passed in)
197 // Now with crunchy GUI goodness!
198 // JaguarLoadCart(jaguar_mainRom, (haveCart ? argv[1] : vjs.ROMPath));
199 //Need to find a better way to handle this crap...
200 WriteLog("About to start GUI...\n");
202 GUIMain(haveCart ? argv[1] : NULL);
208 nNormalLast = 0; // Last value of timeGetTime()
209 nNormalFrac = 0; // Extra fraction we did
210 nNormalLast = SDL_GetTicks(); //timeGetTime();
215 nTime = SDL_GetTicks() - nNormalLast; // calcule le temps écoulé depuis le dernier affichage
216 // nTime est en mili-secondes.
217 // détermine le nombre de trames à passer + 1
218 nCount = (nTime * 600 - nNormalFrac) / 10000;
220 // si le nombre de trames à passer + 1 est nul ou négatif,
221 // ne rien faire pendant 2 ms
226 } // No need to do anything for a bit
229 nNormalFrac += nCount * 10000; //
230 nNormalLast += nNormalFrac / 600; // add the duration of nNormalFrac frames
231 nNormalFrac %= 600; //
233 // Pas plus de 9 (10-1) trames non affichées
236 for(int i=0; i<nCount-1; i++)
237 jaguar_exec(backbuffer, false);
239 // Set up new backbuffer with new pixels and data
240 JaguarExecute(backbuffer, true);
242 //WriteLog("Frame #%u...\n", totalFrames);
243 //extern bool doDSPDis;
244 //if (totalFrames == 373)
247 // Some QnD GUI stuff here...
250 extern uint32 gpu_pc, dsp_pc;
251 DrawString(backbuffer, 8, 8, false, "GPU PC: %08X", gpu_pc);
252 DrawString(backbuffer, 8, 16, false, "DSP PC: %08X", dsp_pc);
256 if (nFrame == nFrameskip)
271 //This is no longer accurate...!
272 // int elapsedTime = clock() - startTime;
273 // int fps = (1000 * totalFrames) / elapsedTime;
274 // WriteLog("VJ: Ran at an average of %i FPS.\n", fps);
282 // Free SDL components last...!
283 // SDL_QuitSubSystem(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_AUDIO | SDL_INIT_TIMER | SDL_INIT_CDROM);
284 SDL_QuitSubSystem(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_AUDIO | SDL_INIT_TIMER);