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/>.
23 extern unsigned char sprites_pixels[];
24 extern struct { unsigned char r, g, b; } sprites_cmap[];
26 void init_sprites(void)
32 /* copy from cartridge to OBJ RAM */
33 dst = (uint16_t*)VRAM_LFB_OBJ_ADDR;
34 src = (uint16_t*)sprites_pixels;
35 for(i=0; i<320; i++) { /* 320 tiles */
38 *dst++ = src[j * 64 + 1];
44 src += 7 * 64; /* skip to the next row of tiles */
49 /* setup OBJ colormaps */
50 cptr = (uint16_t*)CRAM_OBJ_ADDR;
51 for(i=0; i<80; i++) { /* 5 colormaps of 16 colors each */
52 unsigned char r = sprites_cmap[i].r >> 3;
53 unsigned char g = sprites_cmap[i].g >> 3;
54 unsigned char b = sprites_cmap[i].b >> 3;
55 *cptr++ = r | (g << 5) | (b << 10);
59 void set_sprite(uint16_t *oam, int idx, int spr, int x, int y, int pal, unsigned int flags)
61 if(!oam) oam = (uint16_t*)OAM_ADDR;
65 oam[0] = (y & 0xff) | (flags & 0xff00);
66 oam[1] = (x & 0x1ff) | ((flags >> 8) & 0xfe00);
67 oam[2] = (spr & 0x3ff) | ((flags & 3) << 10) | ((pal & 0xf) << 12);