0eeaa5aea2c944057bbe59281e526add73e27d20
[gba_blender] / src / main.c
1 /*
2 blender for the Gameboy Advance
3 Copyright (C) 2021  John Tsiombikas <nuclear@member.fsf.org>
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program.  If not, see <https://www.gnu.org/licenses/>.
17 */
18 #include <string.h>
19 #include "gbaregs.h"
20 #include "timer.h"
21 #include "keyb.h"
22 #include "intr.h"
23 #include "gfx.h"
24
25 static void handle_keys(void);
26
27 extern struct { unsigned char r, g, b; } bgimg_cmap[];
28 extern unsigned char bgimg_pixels[];
29
30 int main(void)
31 {
32         int i;
33         uint16_t *cptr;
34         unsigned char r, g, b;
35
36         intr_init();
37         reset_msec_timer();
38         set_intr();
39
40         /* mode 4: 240x160 8bpp */
41         REG_DISPCNT = DISPCNT_BG2 | 4;
42
43         cptr = (uint16_t*)CRAM_BG_ADDR;
44         for(i=0; i<128; i++) {
45                 r = bgimg_cmap[i].r >> 3;
46                 g = bgimg_cmap[i].g >> 3;
47                 b = bgimg_cmap[i].b >> 3;
48                 *cptr++ = r | (g << 5) | (b << 10);
49         }
50         memcpy((void*)VRAM_LFB_FB0_ADDR, bgimg_pixels, 240 * 160);
51         memcpy((void*)VRAM_LFB_FB1_ADDR, bgimg_pixels, 240 * 160);
52
53         /*key_repeat(500, 75, KEY_LEFT | KEY_RIGHT | KEY_DOWN | KEY_UP);*/
54
55         for(;;) {
56                 wait_vblank();
57                 swap_buffers();
58         }
59
60         return 0;
61 }
62
63 static void handle_keys(void)
64 {
65         update_keyb();
66
67         if(KEYPRESS(KEY_UP)) {
68         }
69         if(KEYPRESS(KEY_DOWN)) {
70         }
71         if(KEYPRESS(KEY_LEFT)) {
72         }
73         if(KEYPRESS(KEY_RIGHT)) {
74         }
75 }