Subversion Repositories freemyipod

Rev

Rev 835 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
760 user890104 1
//
2
//
3
//    Copyright 2011 user890104
4
//
5
//
6
//    This file is part of emCORE.
7
//
8
//    emCORE is free software: you can redistribute it and/or
9
//    modify it under the terms of the GNU General Public License as
10
//    published by the Free Software Foundation, either version 2 of the
11
//    License, or (at your option) any later version.
12
//
13
//    emCORE is distributed in the hope that it will be useful,
14
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
15
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
//    See the GNU General Public License for more details.
17
//
18
//    You should have received a copy of the GNU General Public License along
19
//    with emCORE.  If not, see <http://www.gnu.org/licenses/>.
20
//
21
//
22
 
23
 
24
#include "emcoreapp.h"
25
 
26
#define BALL_W 5
27
#define BALL_H 5
28
 
762 user890104 29
// 24-bit FB (rgb888)
30
#define DBPP 3
760 user890104 31
 
835 theseven 32
static void main(int argc, const char** argv)
760 user890104 33
{
762 user890104 34
    unsigned int run_cycles = 5000,
35
    dw = lcd_get_width(),
760 user890104 36
    dh = lcd_get_height();
37
 
907 user890104 38
    cprintf(3, "Display width: %d\n", dw);
39
    cprintf(3, "Display height: %d\n", dh);
40
 
762 user890104 41
    unsigned int fb_size = DBPP * dw * dh;
42
    void* fb = malloc(fb_size);
760 user890104 43
 
44
    if (fb == NULL)
45
    {
46
        panic(PANIC_KILLTHREAD, "Unable to allocate framebuffer!");
47
    }
48
 
49
    unsigned int i, x = 0, y = 0,
50
    old_x, old_y, bx, by,
51
    size = BALL_W * BALL_H;
762 user890104 52
    unsigned char shape[BALL_H][BALL_W][DBPP];
760 user890104 53
    int vx = 1, vy = 1;
54
 
762 user890104 55
    // generate our shape
56
    memset(&shape, 0xff, sizeof(shape));
57
 
58
    // skip the first and the last pixel
59
    // then skip the ones in top-right and bottom-left
60
    // to create a rounded square
61
    for (i = 1; i < size - 1; ++i)
62
    {
63
        if (i == BALL_W - 1 || i == size - BALL_W) continue;
64
 
65
        memset(((void *)&shape) + i * DBPP, 0, DBPP);
66
    }
67
 
760 user890104 68
    //filllcd(0, 0, dw, dh, 0xffffff); // broken on Nano 4G?
69
    memset(fb, 0xff, fb_size);
70
    displaylcd(0, 0, dw, dh, fb, 0, 0, dw);
71
 
72
    while (run_cycles > 0)
73
    {
74
        memset(fb, 0xff, fb_size);
75
 
76
        // check if we hit a wall
77
        if ((x >= dw - BALL_W && vx > 0) || (x == 0 && vx < 0))
78
        {
79
            vx = -vx;
80
        }
81
 
82
        if ((y >= dh - BALL_H && vy > 0) || (y == 0 && vy < 1))
83
        {
84
            vy = -vy;
85
        }
86
 
87
        // store old x and y
88
        // needed for redrawing later
89
        old_x = x; old_y = y;
90
 
91
        x += vx; y += vy;
92
 
762 user890104 93
        // copy the shape to the framebuffer
94
        for (i = 0; i < BALL_H; ++i)
760 user890104 95
        {
762 user890104 96
            memcpy(fb + x * DBPP + (y + i) * dw * DBPP, &shape[i], sizeof(shape[i]));
760 user890104 97
        }
98
 
99
        // offset to redraw from
100
        bx = vx > 0 ? old_x : x;
101
        by = vy > 0 ? old_y : y;
102
 
103
        displaylcd(bx, by, BALL_W + ABS(vx), BALL_H + ABS(vy), fb, bx, by, dw);
104
 
105
        sleep(1000);
106
 
107
        --run_cycles;
108
    }
109
 
761 user890104 110
    free(fb);
111
 
760 user890104 112
    cputs(3, "Application terminated\n");
113
}
114
 
115
 
116
EMCORE_APP_HEADER("Ball", main, 127)