2 // Virtual Jaguar Emulator
5 // GCC/SDL port by Niels Wagenaar (Linux/WIN32) and Caz (BeOS)
6 // Cleanups by James L. Hammons
13 #endif // #ifndef __PORT__
16 /* Added by SDLEMU (http://sdlemu.ngemu.com) */
17 /* Added for GCC UNIX compatibility */
20 #endif // #ifdef __GCCUNIX__
26 /* Enable this (uncomment) for speed control */
27 //#define SPEED_CONTROL
30 Format format(16, 0x007C00, 0x00003E0, 0x0000001F);
35 char * jaguar_boot_dir;
37 void main_screen_switch(void)
39 fullscreen = !fullscreen;
41 console.option("fullscreen output");
43 console.option("windowed output");
45 console.open("WIP VERSION", tom_width, tom_height, format);
50 /* Added/changed by SDLEMU http://sdlemu.ngemu.com */
52 int main(int argc, char * argv[])
54 uint32 startTime, totalFrames;//, endTime;//, w, h;
56 uint32 nNormalLast = 0;
57 int32 nNormalFrac = 0;
59 //unused int32 nTime = 0;
60 //unused int32 nCount = 0;
61 int32 nFrameskip = 1; // Frameskip
62 int32 nFrame = 0; // No. of Frame
63 int32 nJoyport = 0; // Joystick port
65 printf("Virtual Jaguar/SDL v1.0.1 (GCC/SDL Port)\n");
66 printf("Based upon Virtual Jaguar core v1.0.0 by Potato emulation.\n");
67 printf("Written by Niels Wagenaar (Linux/WIN32) and Caz (BeOS)\n");
68 printf("Portions massaged by James L. Hammons (WIN32)\n");
69 printf("Contact: http://sdlemu.ngemu.com/ | sdlemu@ngemu.com\n");
73 printf("Usage : \n\n");
74 printf("jag_em <romfile> [switches]\n");
75 printf(" -fullscreen : Enable fullscreen mode \n");
76 printf(" -window : Enable windowed mode (default) \n");
77 printf(" -frameskip 1-10 : Enable frameskip 1 (default) - 10\n");
78 printf(" -joystick : Enable joystick/gamepad \n");
79 printf(" -joyport 0-3 : Select desired joystick port \n");
83 jaguar_boot_dir = (char *)malloc(1024);
84 getcwd(jaguar_boot_dir, 1024);
86 log_init("jag_em.log");
90 version_display(log_get());
94 /* Setting up the backbuffer */
95 int16 * backbuffer = (int16 *)malloc(845 * 525 * sizeof(int16));
96 memset(backbuffer, 0xAA, tom_getVideoModeWidth() * tom_getVideoModeHeight() * sizeof(int16));
98 /* Setting up the primary SDL display */
99 //Already defined! Format format(16, 0x007C00, 0x00003E0, 0x0000001F);
100 surface = new Surface(tom_getVideoModeWidth(), tom_getVideoModeHeight(), format);
101 console.option("windowed output");
103 /* Checking the switches ;) */
104 for(int i=0; (i<argc || argv[i]!=NULL); i++)
106 if (!strcmp(argv[i], "-fullscreen"))
107 console.option("fullscreen output");
109 if (!strcmp(argv[i], "-window"))
110 console.option("windowed output");
112 if (!strcmp(argv[i], "-joystick"))
113 console.option("joystick enabled");
115 if (!strcmp(argv[i], "-joyport"))
117 nJoyport = atoi(argv[++i]) + 1;
122 if (!strcmp(argv[i], "-frameskip"))
124 nFrameskip = atoi(argv[++i]) + 1;
133 /* Initialize Joystick support under SDL */
134 if (console.JoyEnabled() == 1)
136 if (SDL_NumJoysticks() <= 0)
138 console.option("joystick disabled");
139 printf("No joystick(s) or joypad(s) detected on your system. Using keyboards....\n");
143 if ((console.joystick = SDL_JoystickOpen(nJoyport)) == 0)
145 console.option("joystick disabled");
146 printf("Unable to open a Joystick on port : %d\n", (int)nJoyport);
149 printf("Using: %s\n", SDL_JoystickName(nJoyport));
153 /* Open the display and start emulating some l337 Atari Jaguar games :P */
154 console.open("Virtual Jaguar", tom_getVideoModeWidth(), tom_getVideoModeHeight(), format);
158 nNormalLast = 0; // Last value of timeGetTime()
159 nNormalFrac = 0; // Extra fraction we did
160 nNormalLast = SDL_GetTicks(); //timeGetTime();
165 nTime = SDL_GetTicks() - nNormalLast; // calcule le temps écoulé depuis le dernier affichage
166 // nTime est en mili-secondes.
167 // détermine le nombre de trames à passer + 1
168 nCount = (nTime * 600 - nNormalFrac) / 10000;
170 // si le nombre de trames à passer + 1 est nul ou négatif,
171 // ne rien faire pendant 2 ms
176 } // No need to do anything for a bit
179 nNormalFrac += nCount * 10000; //
180 nNormalLast += nNormalFrac / 600; // add the duration of nNormalFrac frames
181 nNormalFrac %= 600; //
183 // Pas plus de 9 (10-1) trames non affichées
186 for(int i=0; i<nCount-1; i++)
187 jaguar_exec(backbuffer, 0);
189 /* Setting up new backbuffer with new pixels and data */
190 jaguar_exec(backbuffer, 1);
193 /* Simple frameskip */
194 if (nFrame == nFrameskip)
196 int32 * vs = (int32 *)surface->lock();
197 memcpy(vs, backbuffer, tom_width * tom_height * 2);
199 surface->copy(console);
213 int elapsedTime = clock() - startTime;
214 int fps = (1000 * totalFrames) / elapsedTime;
215 fprintf(log_get(), "Statistics: %i fps\n", fps);
217 if (console.JoyEnabled() == 1) {}
223 console.close(); // Close SDL items as last!
229 int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
231 uint32 startTime, endTime, totalFrames;
232 unsigned int nNormalLast=0;
234 int nTime=0,nCount=0; int i=0;
236 jaguar_boot_dir=(char*)malloc(1024);
237 _getcwd(jaguar_boot_dir,1024);
239 log_init("jagem.log");
241 SDL_Event app_input_event;
245 version_display(log_get());
250 int16 * backbuffer = (int16 *)malloc(845 * 525 * sizeof(int16));
251 memset(backbuffer, 0xAA, tom_getVideoModeWidth() * tom_getVideoModeHeight() * sizeof(int16));
252 surface=new Surface(tom_getVideoModeWidth(),tom_getVideoModeHeight(),format);
253 console.option("DirectX");
254 console.option("windowed output");
255 // console.option("fullscreen output");
256 console.option("center window");
257 console.open("WIP VERSION",tom_getVideoModeWidth(),tom_getVideoModeHeight(),format);
258 uint32 surfacePitch=(surface->pitch()>>1);
262 nNormalLast=0;// Last value of timeGetTime()
263 nNormalFrac=0; // Extra fraction we did
264 nNormalLast=timeGetTime();
267 while ( SDL_PollEvent(&app_input_event) )
269 if ( app_input_event.type == SDL_QUIT )
275 #define SPEED_CONTROL
277 nTime=timeGetTime()-nNormalLast; // calcule le temps écoulé depuis le dernier affichage
278 // nTime est en mili-secondes.
279 // détermine le nombre de trames à passer + 1
280 nCount=(nTime*600 - nNormalFrac) /10000;
282 // si le nombre de trames à passer + 1 est nul ou négatif,
283 // ne rien faire pendant 2 ms
287 } // No need to do anything for a bit
290 nNormalFrac+=nCount*10000; //
291 nNormalLast+=nNormalFrac/600; // add the duration of nNormalFrac frames
294 // Pas plus de 9 (10-1) trames non affichées
297 for (i=0;i<nCount-1;i++)
298 jaguar_exec(backbuffer,0);
300 jaguar_exec(backbuffer,1);
303 int32 *vs = (int32 *)surface->lock();
308 memcpy(vs,backbuffer,w*h*2);
310 surface->copy(console);
317 int elapsedTime=clock()-startTime;
318 int fps=(1000*totalFrames)/elapsedTime;
319 fprintf(log_get(),"statistics: %i fps\n",fps);