2 blender for the Gameboy Advance
3 Copyright (C) 2021 John Tsiombikas <nuclear@member.fsf.org>
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.
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.
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/>.
29 #define MENU_HEIGHT 17
30 #define TRACK_HEIGHT 18
31 #define VP_HEIGHT (160 - MENU_HEIGHT - TRACK_HEIGHT)
33 static void handle_keys(void);
35 extern struct { unsigned char r, g, b; } bgimg_cmap[];
36 extern unsigned char bgimg_pixels[];
38 struct xvertex varr[] = {
47 unsigned int nframes = 0, backbuf;
48 unsigned long tm0, tm;
50 unsigned char r, g, b;
51 unsigned char *fbptr[2], *fb;
52 struct pvertex benchv[3] = {
62 /* mode 4: 240x160 8bpp */
63 REG_DISPCNT = DISPCNT_BG2 | 4;
65 fbptr[0] = (unsigned char*)VRAM_LFB_FB0_ADDR;
66 fbptr[1] = (unsigned char*)VRAM_LFB_FB1_ADDR;
68 set_bg_color(0xff, 31, 31, 31);
70 cptr = (uint16_t*)CRAM_BG_ADDR;
71 for(i=0; i<128; i++) {
72 r = bgimg_cmap[i].r >> 3;
73 g = bgimg_cmap[i].g >> 3;
74 b = bgimg_cmap[i].b >> 3;
75 *cptr++ = r | (g << 5) | (b << 10);
77 for(i=0; i<128; i++) {
78 r = (rand() & 0xf) + 8;
79 g = (rand() & 0xf) + 8;
80 b = (rand() & 0xf) + 8;
81 *cptr++ = r | (g << 5) | (b << 10);
83 memcpy(fbptr[0], bgimg_pixels, 240 * 160);
84 memcpy(fbptr[1], bgimg_pixels, 240 * 160);
87 xgl_viewport(0, MENU_HEIGHT, 240, VP_HEIGHT);
90 polyfill_framebuffer(fbptr[0] + 240 * MENU_HEIGHT, 240, VP_HEIGHT);
92 for(i=0; i<2048; i++) {
93 polyfill_flat(benchv, 3, 128 + (i & 0x7f));
95 tm = timer_msec - tm0;
96 emuprint("benchmark: %lu ms\n", tm);
98 /*key_repeat(500, 75, KEY_LEFT | KEY_RIGHT | KEY_DOWN | KEY_UP);*/
101 backbuf = ++nframes & 1;
103 fb = fbptr[backbuf] + 240 * MENU_HEIGHT;
104 polyfill_framebuffer(fb, 240, VP_HEIGHT);
105 memset(fb, 14, 240 * VP_HEIGHT);
108 xgl_rotate_z(nframes << 8);
109 xgl_draw(XGL_TRIANGLES, varr, 3);
118 static void handle_keys(void)
122 if(KEYPRESS(KEY_UP)) {
124 if(KEYPRESS(KEY_DOWN)) {
126 if(KEYPRESS(KEY_LEFT)) {
128 if(KEYPRESS(KEY_RIGHT)) {