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/>.
30 #define MENU_HEIGHT 17
31 #define TRACK_HEIGHT 18
32 #define VP_HEIGHT (160 - MENU_HEIGHT - TRACK_HEIGHT)
34 static void handle_keys(void);
36 extern struct { unsigned char r, g, b; } bgimg_cmap[];
37 extern unsigned char bgimg_pixels[];
39 static int32_t cam_theta = 0x10000, cam_phi = -0x8000;
44 unsigned int nframes = 0, backbuf;
46 unsigned char r, g, b;
47 unsigned char *fbptr[2], *fb;
53 /* mode 4: 240x160 8bpp */
54 REG_DISPCNT = DISPCNT_BG2 | 4;
56 fbptr[0] = (unsigned char*)VRAM_LFB_FB0_ADDR;
57 fbptr[1] = (unsigned char*)VRAM_LFB_FB1_ADDR;
59 set_bg_color(0xff, 31, 31, 31);
61 cptr = (uint16_t*)CRAM_BG_ADDR;
62 for(i=0; i<128; i++) {
63 r = bgimg_cmap[i].r >> 3;
64 g = bgimg_cmap[i].g >> 3;
65 b = bgimg_cmap[i].b >> 3;
66 *cptr++ = r | (g << 5) | (b << 10);
68 for(i=0; i<128; i++) {
70 *cptr++ = r | (r << 5) | (r << 10);
72 memcpy(fbptr[0], bgimg_pixels, 240 * 160);
73 memcpy(fbptr[1], bgimg_pixels, 240 * 160);
76 xgl_viewport(0, 0, 240, VP_HEIGHT);
77 xgl_enable(XGL_LIGHTING);
79 key_repeat(75, 75, KEY_LEFT | KEY_RIGHT | KEY_DOWN | KEY_UP);
84 backbuf = ++nframes & 1;
86 fb = fbptr[backbuf] + 240 * MENU_HEIGHT;
87 polyfill_framebuffer(fb, 240, VP_HEIGHT);
88 memset(fb, 14, 240 * VP_HEIGHT);
91 xgl_translate(0, 0, 8 << 16);
92 xgl_rotate_x(cam_phi);
93 xgl_rotate_y(cam_theta);
94 // xgl_draw(XGL_QUADS, cube, sizeof cube / sizeof *cube);
95 xgl_draw(XGL_TRIANGLES, suzanne, sizeof suzanne / sizeof *suzanne);
104 static void handle_keys(void)
108 if(KEYPRESS(KEY_UP)) {
110 if(cam_phi > X_HPI) cam_phi = X_HPI;
112 if(KEYPRESS(KEY_DOWN)) {
114 if(cam_phi < -X_HPI) cam_phi = -X_HPI;
116 if(KEYPRESS(KEY_LEFT)) {
119 if(KEYPRESS(KEY_RIGHT)) {