summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Arnold <amiconn@rockbox.org>2009-11-22 13:35:41 +0000
committerJens Arnold <amiconn@rockbox.org>2009-11-22 13:35:41 +0000
commit0c52374a3d9aba02a0743892767678491710a367 (patch)
treed887768461d93eef6c56a649888b549dbc933f21
parent98755fd49362a0f9ae0f732b1575b484f75cf8d8 (diff)
downloadrockbox-0c52374a3d9aba02a0743892767678491710a367.zip
rockbox-0c52374a3d9aba02a0743892767678491710a367.tar.gz
rockbox-0c52374a3d9aba02a0743892767678491710a367.tar.bz2
rockbox-0c52374a3d9aba02a0743892767678491710a367.tar.xz
Plasma demo: (1) small speed optimisation. (2) Limit speed to 33fps. (3) Boost if running too slow on targets with variable CPU frequency.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@23696 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/plugins/plasma.c36
1 files changed, 31 insertions, 5 deletions
diff --git a/apps/plugins/plasma.c b/apps/plugins/plasma.c
index 450b09f..aadeb18 100644
--- a/apps/plugins/plasma.c
+++ b/apps/plugins/plasma.c
@@ -53,6 +53,9 @@ static size_t gbuf_size = 0;
#endif
static unsigned char sp1, sp2, sp3, sp4; /* Speed of plasma */
static int plasma_frequency;
+#ifdef HAVE_ADJUSTABLE_CPU_FREQ
+static bool boosted = false;
+#endif
/* Key assignement, all bitmapped models */
#if (CONFIG_KEYPAD == IPOD_4G_PAD) || (CONFIG_KEYPAD == IPOD_3G_PAD) || \
@@ -260,6 +263,10 @@ void cleanup(void *parameter)
{
(void)parameter;
+#ifdef HAVE_ADJUSTABLE_CPU_FREQ
+ if (boosted)
+ rb->cpu_boost(false);
+#endif
#ifndef HAVE_LCD_COLOR
grey_release();
#endif
@@ -275,8 +282,12 @@ void cleanup(void *parameter)
int main(void)
{
plasma_frequency = 1;
- int button, x, y;
- unsigned char p1,p2,p3,p4,t1,t2,t3,t4, z;
+ int button, delay, x, y;
+ unsigned char p1,p2,p3,p4,t1,t2,t3,t4, z,z0;
+ long last_tick = *rb->current_tick;
+#ifdef HAVE_ADJUSTABLE_CPU_FREQ
+ int cumulated_lag = 0;
+#endif
#ifdef HAVE_LCD_COLOR
#if defined(HAVE_LCD_MODES) && (HAVE_LCD_MODES & LCD_MODE_PAL256)
unsigned char *ptr;
@@ -325,10 +336,10 @@ int main(void)
{
t3=p3;
t4=p4;
+ z0 = wave_array[t1] + wave_array[t2];
for(x = 0; x < LCD_WIDTH; ++x)
{
- z = wave_array[t1] + wave_array[t2] + wave_array[t3]
- + wave_array[t4];
+ z = z0 + wave_array[t3] + wave_array[t4];
#if defined(HAVE_LCD_MODES) && (HAVE_LCD_MODES & LCD_MODE_PAL256)
*ptr++ = z;
#else
@@ -356,7 +367,22 @@ int main(void)
grey_ub_gray_bitmap(greybuffer, 0, 0, LCD_WIDTH, LCD_HEIGHT);
#endif
- button = rb->button_get(false);
+ delay = last_tick - *rb->current_tick + HZ/33;
+#ifdef HAVE_ADJUSTABLE_CPU_FREQ
+ if (!boosted && delay < 0)
+ {
+ cumulated_lag -= delay; /* proportional increase */
+ if (cumulated_lag >= HZ)
+ rb->cpu_boost(boosted = true);
+ }
+ else if (boosted && delay > 1) /* account for jitter */
+ {
+ if (--cumulated_lag <= 0) /* slow decrease */
+ rb->cpu_boost(boosted = false);
+ }
+#endif
+ button = rb->button_get_w_tmo(MAX(0, delay));
+ last_tick = *rb->current_tick;
switch(button)
{