summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
Diffstat (limited to 'apps')
-rw-r--r--apps/plugins/pacbox/pacbox.c128
1 files changed, 67 insertions, 61 deletions
diff --git a/apps/plugins/pacbox/pacbox.c b/apps/plugins/pacbox/pacbox.c
index 097e207ee6..7b524a7ee5 100644
--- a/apps/plugins/pacbox/pacbox.c
+++ b/apps/plugins/pacbox/pacbox.c
@@ -40,8 +40,6 @@ extern char iend[];
40 40
41struct plugin_api* rb; 41struct plugin_api* rb;
42 42
43static unsigned long frame_counter = 0;
44
45struct pacman_settings { 43struct pacman_settings {
46 int difficulty; 44 int difficulty;
47 int numlives; 45 int numlives;
@@ -272,92 +270,101 @@ static int gameProc( void )
272 char str[80]; 270 char str[80];
273 int status; 271 int status;
274 long end_time; 272 long end_time;
273 int frame_counter = 0;
274 int yield_counter = 0;
275 275
276 /* Run the machine for one frame (1/60th second) */ 276 while (1)
277 run(); 277 {
278 278 /* Run the machine for one frame (1/60th second) */
279 frame_counter++; 279 run();
280 280
281 rb->yield(); 281 frame_counter++;
282 282
283 /* Check the button status */ 283 /* Check the button status */
284 status = rb->button_status(); 284 status = rb->button_status();
285 285
286 if ((status & PACMAN_MENU) == PACMAN_MENU 286 if ((status & PACMAN_MENU) == PACMAN_MENU
287#ifdef PACMAN_RC_MENU 287#ifdef PACMAN_RC_MENU
288 || status == PACMAN_RC_MENU 288 || status == PACMAN_RC_MENU
289#endif 289#endif
290 ) { 290 ) {
291 end_time = *rb->current_tick; 291 end_time = *rb->current_tick;
292 x = pacbox_menu(); 292 x = pacbox_menu();
293 rb->lcd_clear_display(); 293 rb->lcd_clear_display();
294#ifdef HAVE_REMOTE_LCD 294#ifdef HAVE_REMOTE_LCD
295 rb->lcd_remote_clear_display(); 295 rb->lcd_remote_clear_display();
296 rb->lcd_remote_update(); 296 rb->lcd_remote_update();
297#endif 297#endif
298 if (x == 1) { return 1; } 298 if (x == 1) { return 1; }
299 start_time += *rb->current_tick-end_time; 299 start_time += *rb->current_tick-end_time;
300 } 300 }
301 301
302#ifdef PACMAN_HAS_REMOTE 302#ifdef PACMAN_HAS_REMOTE
303 setDeviceMode( Joy1_Left, (status & PACMAN_LEFT || status == PACMAN_RC_LEFT) ? DeviceOn : DeviceOff); 303 setDeviceMode( Joy1_Left, (status & PACMAN_LEFT || status == PACMAN_RC_LEFT) ? DeviceOn : DeviceOff);
304 setDeviceMode( Joy1_Right, (status & PACMAN_RIGHT || status == PACMAN_RC_RIGHT) ? DeviceOn : DeviceOff); 304 setDeviceMode( Joy1_Right, (status & PACMAN_RIGHT || status == PACMAN_RC_RIGHT) ? DeviceOn : DeviceOff);
305 setDeviceMode( Joy1_Up, (status & PACMAN_UP || status == PACMAN_RC_UP) ? DeviceOn : DeviceOff); 305 setDeviceMode( Joy1_Up, (status & PACMAN_UP || status == PACMAN_RC_UP) ? DeviceOn : DeviceOff);
306 setDeviceMode( Joy1_Down, (status & PACMAN_DOWN || status == PACMAN_RC_DOWN) ? DeviceOn : DeviceOff); 306 setDeviceMode( Joy1_Down, (status & PACMAN_DOWN || status == PACMAN_RC_DOWN) ? DeviceOn : DeviceOff);
307 setDeviceMode( CoinSlot_1, (status & PACMAN_COIN || status == PACMAN_RC_COIN) ? DeviceOn : DeviceOff); 307 setDeviceMode( CoinSlot_1, (status & PACMAN_COIN || status == PACMAN_RC_COIN) ? DeviceOn : DeviceOff);
308 setDeviceMode( Key_OnePlayer, (status & PACMAN_1UP || status == PACMAN_RC_1UP) ? DeviceOn : DeviceOff); 308 setDeviceMode( Key_OnePlayer, (status & PACMAN_1UP || status == PACMAN_RC_1UP) ? DeviceOn : DeviceOff);
309 setDeviceMode( Key_TwoPlayers, (status & PACMAN_2UP || status == PACMAN_RC_2UP) ? DeviceOn : DeviceOff); 309 setDeviceMode( Key_TwoPlayers, (status & PACMAN_2UP || status == PACMAN_RC_2UP) ? DeviceOn : DeviceOff);
310#else 310#else
311 setDeviceMode( Joy1_Left, (status & PACMAN_LEFT) ? DeviceOn : DeviceOff); 311 setDeviceMode( Joy1_Left, (status & PACMAN_LEFT) ? DeviceOn : DeviceOff);
312 setDeviceMode( Joy1_Right, (status & PACMAN_RIGHT) ? DeviceOn : DeviceOff); 312 setDeviceMode( Joy1_Right, (status & PACMAN_RIGHT) ? DeviceOn : DeviceOff);
313 setDeviceMode( Joy1_Up, (status & PACMAN_UP) ? DeviceOn : DeviceOff); 313 setDeviceMode( Joy1_Up, (status & PACMAN_UP) ? DeviceOn : DeviceOff);
314 setDeviceMode( Joy1_Down, (status & PACMAN_DOWN) ? DeviceOn : DeviceOff); 314 setDeviceMode( Joy1_Down, (status & PACMAN_DOWN) ? DeviceOn : DeviceOff);
315 setDeviceMode( CoinSlot_1, (status & PACMAN_COIN) ? DeviceOn : DeviceOff); 315 setDeviceMode( CoinSlot_1, (status & PACMAN_COIN) ? DeviceOn : DeviceOff);
316 setDeviceMode( Key_OnePlayer, (status & PACMAN_1UP) ? DeviceOn : DeviceOff); 316 setDeviceMode( Key_OnePlayer, (status & PACMAN_1UP) ? DeviceOn : DeviceOff);
317#ifdef PACMAN_2UP 317#ifdef PACMAN_2UP
318 setDeviceMode( Key_TwoPlayers, (status & PACMAN_2UP) ? DeviceOn : DeviceOff); 318 setDeviceMode( Key_TwoPlayers, (status & PACMAN_2UP) ? DeviceOn : DeviceOff);
319#endif 319#endif
320#endif 320#endif
321 321
322 /* We only update the screen every third frame - Pacman's native 322 /* We only update the screen every third frame - Pacman's native
323 framerate is 60fps, so we are attempting to display 20fps */ 323 framerate is 60fps, so we are attempting to display 20fps */
324 if( (frame_counter % (60/FPS)) == 0) { 324 if (frame_counter == 60 / FPS) {
325 325
326 video_frames++; 326 frame_counter = 0;
327 video_frames++;
327 328
328 /* The following functions render the Pacman screen from the contents 329 yield_counter ++;
329 of the video and color ram. We first update the background, and
330 then draw the Sprites on top.
331 */
332 330
333 renderBackground( video_buffer ); 331 if (yield_counter == FPS) {
334 renderSprites( video_buffer ); 332 yield_counter = 0;
333 rb->yield ();
334 }
335
336 /* The following functions render the Pacman screen from the
337 contents of the video and color ram. We first update the
338 background, and then draw the Sprites on top.
339 */
335 340
336 blit_display(rb->lcd_framebuffer,video_buffer); 341 renderBackground( video_buffer );
342 renderSprites( video_buffer );
337 343
338 if (settings.showfps) { 344 blit_display(rb->lcd_framebuffer,video_buffer);
339 fps = (video_frames*HZ*100) / (*rb->current_tick-start_time); 345
340 rb->snprintf(str,sizeof(str),"%d.%02d / %d fps ",fps/100,fps%100, 346 if (settings.showfps) {
341 FPS); 347 fps = (video_frames*HZ*100) / (*rb->current_tick-start_time);
342 rb->lcd_putsxy(0,0,str); 348 rb->snprintf(str,sizeof(str),"%d.%02d / %d fps ",
343 } 349 fps/100,fps%100,FPS);
350 rb->lcd_putsxy(0,0,str);
351 }
344 352
345 rb->lcd_update(); 353 rb->lcd_update();
346 354
347 /* Keep the framerate at Pacman's 60fps */ 355 /* Keep the framerate at Pacman's 60fps */
348 end_time = start_time + (video_frames*HZ)/FPS; 356 end_time = start_time + (video_frames*HZ)/FPS;
349 while (TIME_BEFORE(*rb->current_tick,end_time)) { 357 while (TIME_BEFORE(*rb->current_tick,end_time)) {
350 rb->sleep(1); 358 rb->sleep(1);
359 }
351 } 360 }
352 } 361 }
353
354 return 0; 362 return 0;
355} 363}
356 364
357enum plugin_status plugin_start(struct plugin_api* api, void* parameter) 365enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
358{ 366{
359 (void)parameter; 367 (void)parameter;
360 int status;
361#ifdef USE_IRAM 368#ifdef USE_IRAM
362 void* audiobuf; 369 void* audiobuf;
363 int audiosize; 370 int audiosize;
@@ -414,9 +421,8 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
414 /* Load the romset */ 421 /* Load the romset */
415 if (loadROMS()) { 422 if (loadROMS()) {
416 start_time = *rb->current_tick-1; 423 start_time = *rb->current_tick-1;
417 do { 424
418 status = gameProc(); 425 gameProc();
419 } while (!status);
420 426
421 /* Save the user settings if they have changed */ 427 /* Save the user settings if they have changed */
422 if (rb->memcmp(&settings,&old_settings,sizeof(settings))!=0) { 428 if (rb->memcmp(&settings,&old_settings,sizeof(settings))!=0) {