1 ////////////////////////////////////////////////////////////////////////////////
3 ////////////////////////////////////////////////////////////////////////////////
11 ////////////////////////////////////////////////////////////////////////////////
16 #endif // #ifndef __PORT__
19 /* Added by SDLEMU (http://sdlemu.ngemu.com) */
20 /* Added for GCC UNIX compatibility */
23 #endif // #ifdef __GCCUNIX__
29 /* Enable this (uncomment) for speed control */
30 //#define SPEED_CONTROL
33 Format format(16, 0x007C00, 0x00003E0, 0x0000001F);
38 char * jaguar_boot_dir;
40 void main_screen_switch(void)
42 fullscreen = !fullscreen;
44 console.option("fullscreen output");
46 console.option("windowed output");
48 console.open("WIP VERSION", tom_width, tom_height, format);
53 /* Added/changed by SDLEMU http://sdlemu.ngemu.com */
55 int main(int argc, char * argv[])
58 uint32 startTime, totalFrames, endTime, w, h;
60 unsigned int nNormalLast = 0;
65 int nFrameskip = 1; /* Frameskip */
66 int nFrame = 0; /* No. of Frame */
67 int nJoyport = 0; /* Joystick port */
69 printf("Virtual Jaguar/SDL v1.0.1 (GCC/SDL Port)\n");
70 printf("Based upon Virtual Jaguar core v1.0.0 by Potato emulation.\n");
71 printf("Written by Niels Wagenaar (Linux/WIN32) and Caz (BeOS)\n");
72 printf("Portions massaged by James L. Hammons (WIN32)\n");
73 printf("Contact : http://sdlemu.ngemu.com/ | sdlemu@ngemu.com\n");
77 printf("Usage : \n\n");
78 printf("jag_em <romfile> [switches] ]\n");
79 printf(" -fullscreen : Enable fullscreen mode \n");
80 printf(" -window : Enable windowed mode (default) \n");
81 printf(" -frameskip 1-10 : Enable frameskip 1 (default) - 10\n");
82 printf(" -joystick : Enable joystick/gamepad \n");
83 printf(" -joyport 0-3 : Select desired joystick port \n");
87 jaguar_boot_dir=(char*)malloc(1024);
88 getcwd(jaguar_boot_dir,1024);
90 log_init("jag_em.log");
94 version_display(log_get());
98 /* Setting up the backbuffer */
99 int16 *backbuffer=(int16*)malloc(845*525*sizeof(int16));
100 memset(backbuffer,0xaa,tom_getVideoModeWidth()*tom_getVideoModeHeight()*sizeof(int16));
102 /* Setting up the primary SDL display */
103 Format format(16,0x007c00,0x00003e0,0x0000001f);
104 surface=new Surface(tom_getVideoModeWidth(),tom_getVideoModeHeight(), format);
105 console.option("windowed output");
107 /* Checking the switches ;) */
108 for(i = 0; (i < argc || argv[i] != NULL); i++)
110 if(!strcmp(argv[i], "-fullscreen"))
111 console.option("fullscreen output");
113 if(!strcmp(argv[i], "-window"))
114 console.option("windowed output");
116 if(!strcmp(argv[i], "-joystick"))
117 console.option("joystick enabled");
119 if(!strcmp(argv[i], "-joyport"))
121 nJoyport = atoi(argv[++i]) + 1;
122 if(nJoyport > 3) nJoyport = 3;
125 if(!strcmp(argv[i], "-frameskip"))
127 nFrameskip = atoi(argv[++i]) + 1;
128 if(nFrameskip > 10) nFrameskip = 10;
139 /* Initialize Joystick support under SDL */
140 if ( console.JoyEnabled() == 1 ) {
142 if(SDL_NumJoysticks() <= 0)
144 console.option("joystick disabled");
145 printf("No joystick(s) or joypad(s) detected on your system. Using keyboards....\n");
148 if((console.joystick = SDL_JoystickOpen(nJoyport)) == 0)
150 console.option("joystick disabled");
151 printf("Unable to open a Joystick on port : %d\n", nJoyport);
154 printf("Using: %s\n", SDL_JoystickName(nJoyport));
158 /* Open the display and start emulating some l337 Atari Jaguar games :P */
159 console.open("Virtual Jaguar",tom_getVideoModeWidth(),tom_getVideoModeHeight(),format);
164 nNormalLast=0;// Last value of timeGetTime()
165 nNormalFrac=0; // Extra fraction we did
167 nNormalLast=SDL_GetTicks();//timeGetTime();
171 nTime=SDL_GetTicks()-nNormalLast; // calcule le temps écoulé depuis le dernier affichage
172 // nTime est en mili-secondes.
173 // détermine le nombre de trames à passer + 1
174 nCount=(nTime*600 - nNormalFrac) /10000;
176 // si le nombre de trames à passer + 1 est nul ou négatif,
177 // ne rien faire pendant 2 ms
182 } // No need to do anything for a bit
185 nNormalFrac+=nCount*10000; //
186 nNormalLast+=nNormalFrac/600; // add the duration of nNormalFrac frames
189 // Pas plus de 9 (10-1) trames non affichées
192 for (i=0;i<nCount-1;i++)
193 jaguar_exec(backbuffer,0);
195 /* Setting up new backbuffer with new pixels and data */
196 jaguar_exec(backbuffer,1);
199 /* Simple frameskip */
200 if ( nFrame == nFrameskip ) {
203 vs = (int32 *)surface->lock();
204 memcpy(vs,backbuffer,w*h*2);
206 surface->copy(console);
218 int elapsedTime=clock()-startTime;
219 int fps=(1000*totalFrames)/elapsedTime;
220 printf("statistics: %i fps\n",fps);
222 if ( console.JoyEnabled() == 1 ) {}
228 console.close(); // Close SDL items as last!
234 int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
236 uint32 startTime, endTime, totalFrames;
237 unsigned int nNormalLast=0;
239 int nTime=0,nCount=0; int i=0;
241 jaguar_boot_dir=(char*)malloc(1024);
242 _getcwd(jaguar_boot_dir,1024);
244 log_init("jagem.log");
246 SDL_Event app_input_event;
250 version_display(log_get());
255 int16 * backbuffer = (int16 *)malloc(845 * 525 * sizeof(int16));
256 memset(backbuffer, 0xAA, tom_getVideoModeWidth() * tom_getVideoModeHeight() * sizeof(int16));
257 surface=new Surface(tom_getVideoModeWidth(),tom_getVideoModeHeight(),format);
258 console.option("DirectX");
259 console.option("windowed output");
260 // console.option("fullscreen output");
261 console.option("center window");
262 console.open("WIP VERSION",tom_getVideoModeWidth(),tom_getVideoModeHeight(),format);
263 uint32 surfacePitch=(surface->pitch()>>1);
267 nNormalLast=0;// Last value of timeGetTime()
268 nNormalFrac=0; // Extra fraction we did
269 nNormalLast=timeGetTime();
272 while ( SDL_PollEvent(&app_input_event) )
274 if ( app_input_event.type == SDL_QUIT )
280 #define SPEED_CONTROL
282 nTime=timeGetTime()-nNormalLast; // calcule le temps écoulé depuis le dernier affichage
283 // nTime est en mili-secondes.
284 // détermine le nombre de trames à passer + 1
285 nCount=(nTime*600 - nNormalFrac) /10000;
287 // si le nombre de trames à passer + 1 est nul ou négatif,
288 // ne rien faire pendant 2 ms
292 } // No need to do anything for a bit
295 nNormalFrac+=nCount*10000; //
296 nNormalLast+=nNormalFrac/600; // add the duration of nNormalFrac frames
299 // Pas plus de 9 (10-1) trames non affichées
302 for (i=0;i<nCount-1;i++)
303 jaguar_exec(backbuffer,0);
305 jaguar_exec(backbuffer,1);
308 int32 *vs = (int32 *)surface->lock();
313 memcpy(vs,backbuffer,w*h*2);
315 surface->copy(console);
322 int elapsedTime=clock()-startTime;
323 int fps=(1000*totalFrames)/elapsedTime;
324 fprintf(log_get(),"statistics: %i fps\n",fps);