summaryrefslogtreecommitdiff
path: root/apps/recorder/bounce.c
blob: 6b500964f0528798ce6269b29b85f751fe678e56 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/***************************************************************************
 *             __________               __   ___.
 *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
 *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
 *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
 *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
 *                     \/            \/     \/    \/            \/
 * $Id$
 *
 * Copyright (C) 2002 Daniel Stenberg
 *
 * All files in this archive are subject to the GNU General Public License.
 * See the file COPYING in the source tree root for full license agreement.
 *
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
 * KIND, either express or implied.
 *
 ****************************************************************************/

#include "config.h"

#ifdef HAVE_LCD_BITMAP

#include "lcd.h"
#include "button.h"
#include "kernel.h"

#ifdef SIMULATOR
#include <stdio.h>
#endif
#include <string.h>

#define SS_TITLE       "Bouncer"
#define SS_TITLE_FONT  2

unsigned char table[]={
26,28,30,33,35,37,39,40,42,43,45,46,46,47,47,47,47,47,46,46,45,43,42,40,39,37,35,33,30,28,26,24,21,19,17,14,12,10,8,7,5,4,2,1,1,0,0,0,0,0,1,1,2,4,5,7,8,10,12,14,17,19,21,23,
};

unsigned char xtable[]={
54,59,64,69,73,77,81,85,88,91,94,96,97,99,99,99,99,99,97,96,94,91,88,85,81,77,73,69,64,59,54,50,45,40,35,30,26,22,18,14,11,8,5,3,2,0,0,0,0,0,2,3,5,8,11,14,18,22,26,30,35,40,45,49,
};

#define XDIFF -4
#define YDIFF -6

extern const unsigned char char_gen_12x16[][22];

static void loopit(void)
{
    int b;
    int y=0;
    int x=16;
    int yy,xx;
    unsigned int i;

    char rock[]="ROCKbox";

    lcd_clear_display();
    while(1)
    {
        b = button_get(false);
        if ( b & BUTTON_OFF )
            return;

        lcd_clear_display();
        y++;
        y += (y%13)?1:2;

        x++;
        x += (x%17)?0:1;

        yy=y;
        xx=x;
        for(i=0; i<sizeof(rock)-1; i++, yy+=YDIFF, xx+=XDIFF)
          lcd_bitmap((char *)char_gen_12x16[rock[i]-0x20],
                     xtable[xx&63], table[yy&63],
                     11, 16, false);
        lcd_update();

        sleep(HZ/10);
    }
}


void bounce(void)
{
    int w, h;
    char *off = "[Off] to stop";
    int len = strlen(SS_TITLE);

    lcd_getfontsize(SS_TITLE_FONT, &w, &h);

    /* Get horizontel centering for text */
    len *= w;
    if (len%2 != 0)
        len = ((len+1)/2)+(w/2);
    else
        len /= 2;

    if (h%2 != 0)
        h = (h/2)+1;
    else
        h /= 2;

    lcd_clear_display();
    lcd_putsxy(LCD_WIDTH/2-len, (LCD_HEIGHT/2)-h, SS_TITLE, SS_TITLE_FONT);

    len = strlen(off);
    lcd_getfontsize(0, &w, &h);

    /* Get horizontel centering for text */
    len *= w;
    if (len%2 != 0)
        len = ((len+1)/2)+(w/2);
    else
        len /= 2;

    if (h%2 != 0)
        h = (h/2)+1;
    else
        h /= 2;

    lcd_putsxy(LCD_WIDTH/2-len, LCD_HEIGHT-(2*h), off,0);

    lcd_update();
    sleep(HZ);
    loopit();
}

#endif