| 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 |
|
|
|
29 |
unsigned int dw, dh, dbpp;
|
|
|
30 |
void* fb;
|
|
|
31 |
|
|
|
32 |
static inline void drawat(unsigned int x, unsigned int y, unsigned char color)
|
|
|
33 |
{
|
|
|
34 |
if (x >= dw || y >= dh) return;
|
|
|
35 |
|
|
|
36 |
// TODO: is there a better way?
|
|
|
37 |
*((char *)(fb + dbpp * x + dbpp * dw * y)) = color;
|
|
|
38 |
*((char *)(fb + dbpp * x + dbpp * dw * y + 1)) = color;
|
|
|
39 |
*((char *)(fb + dbpp * x + dbpp * dw * y + 2)) = color;
|
|
|
40 |
}
|
|
|
41 |
|
|
|
42 |
static void main()
|
|
|
43 |
{
|
|
|
44 |
unsigned int run_cycles = 5000;
|
|
|
45 |
|
|
|
46 |
dw = lcd_get_width();
|
|
|
47 |
dh = lcd_get_height();
|
|
|
48 |
dbpp = 3; // 24-bit FB (rgb888)
|
|
|
49 |
|
|
|
50 |
unsigned int fb_size = dbpp * dw * dh;
|
|
|
51 |
fb = malloc(fb_size);
|
|
|
52 |
|
|
|
53 |
if (fb == NULL)
|
|
|
54 |
{
|
|
|
55 |
panic(PANIC_KILLTHREAD, "Unable to allocate framebuffer!");
|
|
|
56 |
}
|
|
|
57 |
|
|
|
58 |
unsigned int i, x = 0, y = 0,
|
|
|
59 |
old_x, old_y, bx, by,
|
|
|
60 |
size = BALL_W * BALL_H;
|
|
|
61 |
int vx = 1, vy = 1;
|
|
|
62 |
|
|
|
63 |
//filllcd(0, 0, dw, dh, 0xffffff); // broken on Nano 4G?
|
|
|
64 |
memset(fb, 0xff, fb_size);
|
|
|
65 |
displaylcd(0, 0, dw, dh, fb, 0, 0, dw);
|
|
|
66 |
|
|
|
67 |
while (run_cycles > 0)
|
|
|
68 |
{
|
|
|
69 |
memset(fb, 0xff, fb_size);
|
|
|
70 |
|
|
|
71 |
// check if we hit a wall
|
|
|
72 |
if ((x >= dw - BALL_W && vx > 0) || (x == 0 && vx < 0))
|
|
|
73 |
{
|
|
|
74 |
vx = -vx;
|
|
|
75 |
}
|
|
|
76 |
|
|
|
77 |
if ((y >= dh - BALL_H && vy > 0) || (y == 0 && vy < 1))
|
|
|
78 |
{
|
|
|
79 |
vy = -vy;
|
|
|
80 |
}
|
|
|
81 |
|
|
|
82 |
// store old x and y
|
|
|
83 |
// needed for redrawing later
|
|
|
84 |
old_x = x; old_y = y;
|
|
|
85 |
|
|
|
86 |
x += vx; y += vy;
|
|
|
87 |
|
|
|
88 |
// draw our ball-like object
|
|
|
89 |
// a circle-like actually, since we
|
|
|
90 |
// don't have a 3D engine yet :)
|
|
|
91 |
for (i = 1; i < BALL_W - 1; ++i)
|
|
|
92 |
{
|
|
|
93 |
drawat(x + i, y, 0);
|
|
|
94 |
}
|
|
|
95 |
|
|
|
96 |
for (i = BALL_W; i < size - BALL_W; ++i)
|
|
|
97 |
{
|
|
|
98 |
drawat(x + i % BALL_W, y + i / BALL_W, 0);
|
|
|
99 |
}
|
|
|
100 |
|
|
|
101 |
for (i = 1; i < BALL_W - 1; ++i)
|
|
|
102 |
{
|
|
|
103 |
drawat(x + i, y + BALL_H - 1, 0);
|
|
|
104 |
}
|
|
|
105 |
|
|
|
106 |
// offset to redraw from
|
|
|
107 |
bx = vx > 0 ? old_x : x;
|
|
|
108 |
by = vy > 0 ? old_y : y;
|
|
|
109 |
|
|
|
110 |
displaylcd(bx, by, BALL_W + ABS(vx), BALL_H + ABS(vy), fb, bx, by, dw);
|
|
|
111 |
|
|
|
112 |
sleep(1000);
|
|
|
113 |
|
|
|
114 |
--run_cycles;
|
|
|
115 |
}
|
|
|
116 |
|
|
|
117 |
cputs(3, "Application terminated\n");
|
|
|
118 |
}
|
|
|
119 |
|
|
|
120 |
|
|
|
121 |
EMCORE_APP_HEADER("Ball", main, 127)
|