summaryrefslogtreecommitdiff
path: root/apps/plugins
diff options
context:
space:
mode:
authorDave Chapman <dave@dchapman.com>2006-03-20 23:01:28 +0000
committerDave Chapman <dave@dchapman.com>2006-03-20 23:01:28 +0000
commit1a0e885ba02b9158e357fec0a96ffb7a4a7c7d19 (patch)
tree4a1ea2dfea912c59133478fbbd004056fa91f195 /apps/plugins
parent7e7423373e1913ff48744adc6236634459610cb6 (diff)
downloadrockbox-1a0e885ba02b9158e357fec0a96ffb7a4a7c7d19.zip
rockbox-1a0e885ba02b9158e357fec0a96ffb7a4a7c7d19.tar.gz
rockbox-1a0e885ba02b9158e357fec0a96ffb7a4a7c7d19.tar.bz2
rockbox-1a0e885ba02b9158e357fec0a96ffb7a4a7c7d19.tar.xz
Patch #4870 from Fredrik Öhrn - Call yield() less often (gives a 3-4fps speed increase on H300) plus some minor code reorganisation
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@9140 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins')
-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 097e207..7b524a7 100644
--- a/apps/plugins/pacbox/pacbox.c
+++ b/apps/plugins/pacbox/pacbox.c
@@ -40,8 +40,6 @@ extern char iend[];
struct plugin_api* rb;
-static unsigned long frame_counter = 0;
-
struct pacman_settings {
int difficulty;
int numlives;
@@ -272,92 +270,101 @@ static int gameProc( void )
char str[80];
int status;
long end_time;
+ int frame_counter = 0;
+ int yield_counter = 0;
- /* Run the machine for one frame (1/60th second) */
- run();
-
- frame_counter++;
+ while (1)
+ {
+ /* Run the machine for one frame (1/60th second) */
+ run();
- rb->yield();
+ frame_counter++;
- /* Check the button status */
- status = rb->button_status();
+ /* Check the button status */
+ status = rb->button_status();
- if ((status & PACMAN_MENU) == PACMAN_MENU
+ if ((status & PACMAN_MENU) == PACMAN_MENU
#ifdef PACMAN_RC_MENU
- || status == PACMAN_RC_MENU
+ || status == PACMAN_RC_MENU
#endif
- ) {
- end_time = *rb->current_tick;
- x = pacbox_menu();
- rb->lcd_clear_display();
+ ) {
+ end_time = *rb->current_tick;
+ x = pacbox_menu();
+ rb->lcd_clear_display();
#ifdef HAVE_REMOTE_LCD
- rb->lcd_remote_clear_display();
- rb->lcd_remote_update();
+ rb->lcd_remote_clear_display();
+ rb->lcd_remote_update();
#endif
- if (x == 1) { return 1; }
- start_time += *rb->current_tick-end_time;
- }
+ if (x == 1) { return 1; }
+ start_time += *rb->current_tick-end_time;
+ }
#ifdef PACMAN_HAS_REMOTE
- setDeviceMode( Joy1_Left, (status & PACMAN_LEFT || status == PACMAN_RC_LEFT) ? DeviceOn : DeviceOff);
- setDeviceMode( Joy1_Right, (status & PACMAN_RIGHT || status == PACMAN_RC_RIGHT) ? DeviceOn : DeviceOff);
- setDeviceMode( Joy1_Up, (status & PACMAN_UP || status == PACMAN_RC_UP) ? DeviceOn : DeviceOff);
- setDeviceMode( Joy1_Down, (status & PACMAN_DOWN || status == PACMAN_RC_DOWN) ? DeviceOn : DeviceOff);
- setDeviceMode( CoinSlot_1, (status & PACMAN_COIN || status == PACMAN_RC_COIN) ? DeviceOn : DeviceOff);
- setDeviceMode( Key_OnePlayer, (status & PACMAN_1UP || status == PACMAN_RC_1UP) ? DeviceOn : DeviceOff);
- setDeviceMode( Key_TwoPlayers, (status & PACMAN_2UP || status == PACMAN_RC_2UP) ? DeviceOn : DeviceOff);
+ setDeviceMode( Joy1_Left, (status & PACMAN_LEFT || status == PACMAN_RC_LEFT) ? DeviceOn : DeviceOff);
+ setDeviceMode( Joy1_Right, (status & PACMAN_RIGHT || status == PACMAN_RC_RIGHT) ? DeviceOn : DeviceOff);
+ setDeviceMode( Joy1_Up, (status & PACMAN_UP || status == PACMAN_RC_UP) ? DeviceOn : DeviceOff);
+ setDeviceMode( Joy1_Down, (status & PACMAN_DOWN || status == PACMAN_RC_DOWN) ? DeviceOn : DeviceOff);
+ setDeviceMode( CoinSlot_1, (status & PACMAN_COIN || status == PACMAN_RC_COIN) ? DeviceOn : DeviceOff);
+ setDeviceMode( Key_OnePlayer, (status & PACMAN_1UP || status == PACMAN_RC_1UP) ? DeviceOn : DeviceOff);
+ setDeviceMode( Key_TwoPlayers, (status & PACMAN_2UP || status == PACMAN_RC_2UP) ? DeviceOn : DeviceOff);
#else
- setDeviceMode( Joy1_Left, (status & PACMAN_LEFT) ? DeviceOn : DeviceOff);
- setDeviceMode( Joy1_Right, (status & PACMAN_RIGHT) ? DeviceOn : DeviceOff);
- setDeviceMode( Joy1_Up, (status & PACMAN_UP) ? DeviceOn : DeviceOff);
- setDeviceMode( Joy1_Down, (status & PACMAN_DOWN) ? DeviceOn : DeviceOff);
- setDeviceMode( CoinSlot_1, (status & PACMAN_COIN) ? DeviceOn : DeviceOff);
- setDeviceMode( Key_OnePlayer, (status & PACMAN_1UP) ? DeviceOn : DeviceOff);
+ setDeviceMode( Joy1_Left, (status & PACMAN_LEFT) ? DeviceOn : DeviceOff);
+ setDeviceMode( Joy1_Right, (status & PACMAN_RIGHT) ? DeviceOn : DeviceOff);
+ setDeviceMode( Joy1_Up, (status & PACMAN_UP) ? DeviceOn : DeviceOff);
+ setDeviceMode( Joy1_Down, (status & PACMAN_DOWN) ? DeviceOn : DeviceOff);
+ setDeviceMode( CoinSlot_1, (status & PACMAN_COIN) ? DeviceOn : DeviceOff);
+ setDeviceMode( Key_OnePlayer, (status & PACMAN_1UP) ? DeviceOn : DeviceOff);
#ifdef PACMAN_2UP
- setDeviceMode( Key_TwoPlayers, (status & PACMAN_2UP) ? DeviceOn : DeviceOff);
+ setDeviceMode( Key_TwoPlayers, (status & PACMAN_2UP) ? DeviceOn : DeviceOff);
#endif
#endif
- /* We only update the screen every third frame - Pacman's native
- framerate is 60fps, so we are attempting to display 20fps */
- if( (frame_counter % (60/FPS)) == 0) {
+ /* We only update the screen every third frame - Pacman's native
+ framerate is 60fps, so we are attempting to display 20fps */
+ if (frame_counter == 60 / FPS) {
- video_frames++;
+ frame_counter = 0;
+ video_frames++;
- /* The following functions render the Pacman screen from the contents
- of the video and color ram. We first update the background, and
- then draw the Sprites on top.
- */
+ yield_counter ++;
- renderBackground( video_buffer );
- renderSprites( video_buffer );
+ if (yield_counter == FPS) {
+ yield_counter = 0;
+ rb->yield ();
+ }
+
+ /* The following functions render the Pacman screen from the
+ contents of the video and color ram. We first update the
+ background, and then draw the Sprites on top.
+ */
- blit_display(rb->lcd_framebuffer,video_buffer);
+ renderBackground( video_buffer );
+ renderSprites( video_buffer );
- if (settings.showfps) {
- fps = (video_frames*HZ*100) / (*rb->current_tick-start_time);
- rb->snprintf(str,sizeof(str),"%d.%02d / %d fps ",fps/100,fps%100,
- FPS);
- rb->lcd_putsxy(0,0,str);
- }
+ blit_display(rb->lcd_framebuffer,video_buffer);
+
+ if (settings.showfps) {
+ fps = (video_frames*HZ*100) / (*rb->current_tick-start_time);
+ rb->snprintf(str,sizeof(str),"%d.%02d / %d fps ",
+ fps/100,fps%100,FPS);
+ rb->lcd_putsxy(0,0,str);
+ }
- rb->lcd_update();
+ rb->lcd_update();
- /* Keep the framerate at Pacman's 60fps */
- end_time = start_time + (video_frames*HZ)/FPS;
- while (TIME_BEFORE(*rb->current_tick,end_time)) {
- rb->sleep(1);
+ /* Keep the framerate at Pacman's 60fps */
+ end_time = start_time + (video_frames*HZ)/FPS;
+ while (TIME_BEFORE(*rb->current_tick,end_time)) {
+ rb->sleep(1);
+ }
}
}
-
return 0;
}
enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
{
(void)parameter;
- int status;
#ifdef USE_IRAM
void* audiobuf;
int audiosize;
@@ -414,9 +421,8 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
/* Load the romset */
if (loadROMS()) {
start_time = *rb->current_tick-1;
- do {
- status = gameProc();
- } while (!status);
+
+ gameProc();
/* Save the user settings if they have changed */
if (rb->memcmp(&settings,&old_settings,sizeof(settings))!=0) {