| Index: apps/ball/main.c | 
| — | — | @@ -26,29 +26,17 @@ | 
| 27 | 27 | #define BALL_W 5 | 
| 28 | 28 | #define BALL_H 5 | 
| 29 | 29 |  | 
| 30 |  | -unsigned int dw, dh, dbpp;
 | 
| 31 |  | -void* fb;
 | 
|  | 30 | +// 24-bit FB (rgb888) | 
|  | 31 | +#define DBPP 3 | 
| 32 | 32 |  | 
| 33 |  | -static inline void drawat(unsigned int x, unsigned int y, unsigned char color)
 | 
| 34 |  | -{
 | 
| 35 |  | -    if (x >= dw || y >= dh) return;
 | 
| 36 |  | -    
 | 
| 37 |  | -    // TODO: is there a better way?
 | 
| 38 |  | -    *((char *)(fb + dbpp * x + dbpp * dw * y)) = color;
 | 
| 39 |  | -    *((char *)(fb + dbpp * x + dbpp * dw * y + 1)) = color;
 | 
| 40 |  | -    *((char *)(fb + dbpp * x + dbpp * dw * y + 2)) = color;
 | 
| 41 |  | -}
 | 
| 42 |  | -
 | 
| 43 | 33 | static void main() | 
| 44 | 34 | { | 
| 45 |  | -    unsigned int run_cycles = 5000;
 | 
| 46 |  | -    
 | 
| 47 |  | -    dw = lcd_get_width();
 | 
|  | 35 | +    unsigned int run_cycles = 5000, | 
|  | 36 | +    dw = lcd_get_width(), | 
| 48 | 37 | dh = lcd_get_height(); | 
| 49 |  | -    dbpp = 3; // 24-bit FB (rgb888)
 | 
| 50 | 38 |  | 
| 51 |  | -    unsigned int fb_size = dbpp * dw * dh;
 | 
| 52 |  | -    fb = malloc(fb_size);
 | 
|  | 39 | +    unsigned int fb_size = DBPP * dw * dh; | 
|  | 40 | +    void* fb = malloc(fb_size); | 
| 53 | 41 |  | 
| 54 | 42 | if (fb == NULL) | 
| 55 | 43 | { | 
| — | — | @@ -58,8 +46,22 @@ | 
| 59 | 47 | unsigned int i, x = 0, y = 0, | 
| 60 | 48 | old_x, old_y, bx, by, | 
| 61 | 49 | size = BALL_W * BALL_H; | 
|  | 50 | +    unsigned char shape[BALL_H][BALL_W][DBPP]; | 
| 62 | 51 | int vx = 1, vy = 1; | 
| 63 | 52 |  | 
|  | 53 | +    // generate our shape | 
|  | 54 | +    memset(&shape, 0xff, sizeof(shape)); | 
|  | 55 | + | 
|  | 56 | +    // skip the first and the last pixel | 
|  | 57 | +    // then skip the ones in top-right and bottom-left | 
|  | 58 | +    // to create a rounded square | 
|  | 59 | +    for (i = 1; i < size - 1; ++i) | 
|  | 60 | +    { | 
|  | 61 | +        if (i == BALL_W - 1 || i == size - BALL_W) continue; | 
|  | 62 | + | 
|  | 63 | +        memset(((void *)&shape) + i * DBPP, 0, DBPP); | 
|  | 64 | +    } | 
|  | 65 | + | 
| 64 | 66 | //filllcd(0, 0, dw, dh, 0xffffff); // broken on Nano 4G? | 
| 65 | 67 | memset(fb, 0xff, fb_size); | 
| 66 | 68 | displaylcd(0, 0, dw, dh, fb, 0, 0, dw); | 
| — | — | @@ -85,24 +87,12 @@ | 
| 86 | 88 |  | 
| 87 | 89 | x += vx; y += vy; | 
| 88 | 90 |  | 
| 89 |  | -        // draw our ball-like object
 | 
| 90 |  | -        // a circle-like actually, since we
 | 
| 91 |  | -        // don't have a 3D engine yet :)
 | 
| 92 |  | -        for (i = 1; i < BALL_W - 1; ++i)
 | 
|  | 91 | +        // copy the shape to the framebuffer | 
|  | 92 | +        for (i = 0; i < BALL_H; ++i) | 
| 93 | 93 | { | 
| 94 |  | -            drawat(x + i, y, 0);
 | 
|  | 94 | +            memcpy(fb + x * DBPP + (y + i) * dw * DBPP, &shape[i], sizeof(shape[i])); | 
| 95 | 95 | } | 
| 96 | 96 |  | 
| 97 |  | -        for (i = BALL_W; i < size - BALL_W; ++i)
 | 
| 98 |  | -        {
 | 
| 99 |  | -            drawat(x + i % BALL_W, y + i / BALL_W, 0);
 | 
| 100 |  | -        }
 | 
| 101 |  | -        
 | 
| 102 |  | -        for (i = 1; i < BALL_W - 1; ++i)
 | 
| 103 |  | -        {
 | 
| 104 |  | -            drawat(x + i, y + BALL_H - 1, 0);
 | 
| 105 |  | -        }
 | 
| 106 |  | -        
 | 
| 107 | 97 | // offset to redraw from | 
| 108 | 98 | bx = vx > 0 ? old_x : x; | 
| 109 | 99 | by = vy > 0 ? old_y : y; |