2 // Virtual Jaguar Emulator
4 // Original codebase by Cal2
5 // GCC/SDL port by Niels Wagenaar (Linux/WIN32) and Caz (BeOS)
6 // Cleanups/fixes/enhancements by James L. Hammons and Adam Green
13 //#include <dirent.h> // POSIX, but should compile with linux & mingw...
22 #include "sdlemu_opengl.h"
23 #include "settings.h" // Pull in "vjs" struct
25 // Uncomment this for speed control (?)
26 //#define SPEED_CONTROL
28 // Private function prototypes
30 //uint32 JaguarLoadROM(uint8 *, char *);
31 //void JaguarLoadCart(uint8 *, char *);
32 //int gzfilelength(gzFile gd);
36 extern uint8 * jaguar_mainRam;
37 extern uint8 * jaguar_bootRom;
38 extern uint8 * jaguar_mainRom;
42 //static char * jaguar_bootRom_path = "./bios/jagboot.rom";
43 //static char *jaguar_bootRom_path="c:/jaguarEmu/newload.img";
44 //static char *jaguar_bootRom_path="./bios/JagOS.bin";
45 //char * jaguar_eeproms_path = "./eeproms/";
46 //char jaguar_boot_dir[MAX_PATH];
48 //These should go into video.cpp...
50 //SDL_Surface * surface, * mainSurface;
51 //int16 * backbuffer = NULL;
52 //SDL_Joystick * joystick;
53 //Uint32 mainSurfaceFlags = SDL_SWSURFACE;
55 bool finished = false;
57 bool showMessage = false;
58 uint32 showMessageTimeout;
59 char messageBuffer[200];
62 // The main emulator loop (what else?)
64 //Maybe we should move the video stuff to TOM? Makes more sense to put it there...
65 //Actually, it would probably be better served in VIDEO.CPP... !!! FIX !!! [DONE]
66 uint32 totalFrames;//temp, so we can grab this from elsewhere...
67 int main(int argc, char * argv[])
69 uint32 startTime;//, totalFrames;//, endTime;//, w, h;
70 uint32 nNormalLast = 0;
71 int32 nNormalFrac = 0;
72 int32 nFrameskip = 0; // Default: Show every frame
73 int32 nFrame = 0; // No. of Frame
75 printf("Virtual Jaguar GCC/SDL Portable Jaguar Emulator v1.0.7\n");
76 printf("Based upon Virtual Jaguar core v1.0.0 by Cal2 of Potato emulation.\n");
77 printf("Written by Niels Wagenaar (Linux/WIN32), Carwin Jones (BeOS),\n");
78 printf("James L. Hammons (WIN32) and Adam Green (MacOS)\n");
79 printf("Contact: http://sdlemu.ngemu.com/ | sdlemu@ngemu.com\n");
81 bool haveCart = false; // Assume there is no cartridge...!
84 LoadVJSettings(); // Get config file settings...
86 // Check the switches... ;-)
87 // NOTE: Command line switches can override any config file settings, thus the
88 // proliferation of the noXXX switches. ;-)
90 for(int i=1; i<argc || argv[i]!=NULL; i++)
92 // This would be the most likely place to do the cart loading...
93 if (argv[i][0] != '-')
94 haveCart = true; // It looks like we have a cartridge!
96 if (!strcmp(argv[i], "-joystick"))
97 vjs.useJoystick = true;
99 if (!strcmp(argv[i], "-joyport"))
101 vjs.joyport = atoi(argv[++i]) + 1;
106 if (!strcmp(argv[i], "-frameskip"))
108 nFrameskip = atoi(argv[++i]) + 1;
116 if (!strcmp(argv[i], "-bios"))
117 vjs.useJaguarBIOS = true;
119 if (!strcmp(argv[i], "-nobios"))
120 vjs.useJaguarBIOS = false;
122 if (!strcmp(argv[i], "-dsp"))
123 vjs.DSPEnabled = true;
125 if (!strcmp(argv[i], "-nodsp"))
126 vjs.DSPEnabled = false;
128 if (!strcmp(argv[i], "-pipeline"))
129 vjs.usePipelinedDSP = true;
131 if (!strcmp(argv[i], "-nopipeline"))
132 vjs.usePipelinedDSP = false;
134 if (!strcmp(argv[i], "-gl"))
135 vjs.useOpenGL = true;
137 if (!strcmp(argv[i], "-nogl"))
138 vjs.useOpenGL = false;
140 if (!strcmp(argv[i], "-fullscreen"))
141 vjs.fullscreen = true;
143 if (!strcmp(argv[i], "-window"))
144 vjs.fullscreen = false;
146 if (!strcmp(argv[i], "-pal"))
147 vjs.hardwareTypeNTSC = false;
149 if (!strcmp(argv[i], "-ntsc"))
150 vjs.hardwareTypeNTSC = true;
152 if (!strcmp(argv[i], "-help") || !strcmp(argv[i], "-?"))
154 printf("Usage: \n\n");
155 printf("vj [romfile] [switches]\n");
156 printf(" -? or -help : Display usage and switches \n");
157 printf(" -frameskip 1-10 : Enable frameskip 1 - 10 (default: none) \n");
158 printf(" -joystick : Enable joystick/gamepad \n");
159 printf(" -joyport 0-3 : Select desired joystick port \n");
160 printf(" -bios : Boot cart using Jaguar BIOS ROM \n");
161 printf(" -nobios : Boot cart without using Jaguar BIOS ROM \n");
162 printf(" -dsp : Force VJ to use the DSP \n");
163 printf(" -nodsp : Force VJ to run without the DSP \n");
164 printf(" -pipeline : Use the DSP pipelined core \n");
165 printf(" -nopipeline : Use the DSP non-pipelined core \n");
166 printf(" -gl : Use OpenGL rendering \n");
167 printf(" -nogl : Use old non-OpenGL rendering \n");
168 printf(" -fullscreen : Enable fullscreen mode (default: windowed)\n");
169 printf(" -window : Enable windowed mode \n");
170 printf(" -pal : Force VJ to PAL mode (default: NTSC) \n");
171 printf(" -ntsc : Force VJ to NTSC mode \n");
172 printf("\nInvoking Virtual Jagaur with no ROM file will cause it to boot up\n");
173 printf("with the VJ GUI.\n");
180 version_display(log_get());
184 if (vjs.useJaguarBIOS)
185 JaguarLoadROM(jaguar_bootRom, vjs.jagBootPath);
187 SET32(jaguar_mainRam, 0, 0x00200000); // Set top of stack...
192 // Get the cartridge ROM (if passed in)
193 // Now with crunchy GUI goodness!
194 // JaguarLoadCart(jaguar_mainRom, (haveCart ? argv[1] : vjs.ROMPath));
195 //Need to find a better way to handle this crap...
202 nNormalLast = 0; // Last value of timeGetTime()
203 nNormalFrac = 0; // Extra fraction we did
204 nNormalLast = SDL_GetTicks(); //timeGetTime();
209 nTime = SDL_GetTicks() - nNormalLast; // calcule le temps écoulé depuis le dernier affichage
210 // nTime est en mili-secondes.
211 // détermine le nombre de trames à passer + 1
212 nCount = (nTime * 600 - nNormalFrac) / 10000;
214 // si le nombre de trames à passer + 1 est nul ou négatif,
215 // ne rien faire pendant 2 ms
220 } // No need to do anything for a bit
223 nNormalFrac += nCount * 10000; //
224 nNormalLast += nNormalFrac / 600; // add the duration of nNormalFrac frames
225 nNormalFrac %= 600; //
227 // Pas plus de 9 (10-1) trames non affichées
230 for(int i=0; i<nCount-1; i++)
231 jaguar_exec(backbuffer, false);
233 // Set up new backbuffer with new pixels and data
234 JaguarExecute(backbuffer, true);
236 //WriteLog("Frame #%u...\n", totalFrames);
237 //extern bool doDSPDis;
238 //if (totalFrames == 373)
241 // Some QnD GUI stuff here...
244 extern uint32 gpu_pc, dsp_pc;
245 DrawString(backbuffer, 8, 8, false, "GPU PC: %08X", gpu_pc);
246 DrawString(backbuffer, 8, 16, false, "DSP PC: %08X", dsp_pc);
250 if (nFrame == nFrameskip)
265 int elapsedTime = clock() - startTime;
266 int fps = (1000 * totalFrames) / elapsedTime;
267 WriteLog("VJ: Ran at an average of %i FPS.\n", fps);
272 VideoDone(); // Free SDL components last...!