summaryrefslogtreecommitdiffstats
path: root/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c62
1 files changed, 53 insertions, 9 deletions
diff --git a/src/main.c b/src/main.c
index b8f2334..793baa8 100644
--- a/src/main.c
+++ b/src/main.c
@@ -10,23 +10,58 @@
10// 10//
11 11
12// TODO: Cleanup OBJ/OAM memory copying and access. 12// TODO: Cleanup OBJ/OAM memory copying and access.
13//
14#define CBB_0 0
15#define SBB_0 28
13 16
14int main(void) { 17#define CROSS_TX 15
15 // Load background palette. 18#define CROSS_TY 10
16 memcpy(&PAL_BUFFER_BG[0], &bg_palette, 512); 19
17 memcpy(&TILE_MEM[0][0], bg_data, 3168); 20u16 *bg0_map = SCREENBLOCK_MEM[SBB_0];
18 memcpy(&SCREENBLOCK_MEM[30][0], bg_map, 2048); 21
19 22void
20 // Configure BG0 to use 4bpp, 64x32 tile map in charblock 0 and screenblock 23init_map() {
21 // 31. 24 // initialize a background
22 BG_CTRL_0 = BG_CHARBLOCK(0) | BG_SCREENBLOCK(30) | BG_SIZE(0); 25 BG_CTRL_0 = BG_CHARBLOCK(CBB_0) | BG_SCREENBLOCK(SBB_0) | BG_SIZE(3);
23 BG_H_SCROLL_0 = 0; 26 BG_H_SCROLL_0 = 0;
24 BG_V_SCROLL_0 = 0; 27 BG_V_SCROLL_0 = 0;
25 28
29 // (1) create the tiles: basic tile and a cross
30 const Tile tiles[2] = {
31 {{0x11111111, 0x01111111, 0x01111111, 0x01111111,
32 0x01111111, 0x01111111, 0x01111111, 0x00000001}},
33 {{0x00000000, 0x00100100, 0x01100110, 0x00011000,
34 0x00011000, 0x01100110, 0x00100100, 0x00000000}},
35 };
36 TILE_MEM[CBB_0][0] = tiles[0];
37 TILE_MEM[CBB_0][1] = tiles[1];
38
39 // (2) create a palette
40 PAL_BANK_BG[0][1] = rgb15(31, 0, 0);
41 PAL_BANK_BG[1][1] = rgb15( 0, 31, 0);
42 PAL_BANK_BG[2][1] = rgb15( 0, 0, 31);
43 PAL_BANK_BG[3][1] = rgb15(16, 16, 16);
44
45 // (3) Create a map: four contingent blocks of
46 // 0x0000, 0x1000, 0x2000, 0x3000.
47 u16 *pse = bg0_map;
48 for(int i = 0; i < 4; i++) {
49 for(int j = 0; j < 32 * 32; j++) {
50 *pse++ = SCREENBLOCK_ENTRY_PAL(i) | 0;
51 }
52 }
53}
54
55int main(void) {
56 init_map();
26 // Configure the display in mode 0 to show OBJs, where tile memory is 57 // Configure the display in mode 0 to show OBJs, where tile memory is
27 // sequential. 58 // sequential.
28 DISP_CTRL = DISP_ENABLE_SPRITES | DISP_MODE_0 | DISP_BG_0; 59 DISP_CTRL = DISP_ENABLE_SPRITES | DISP_MODE_0 | DISP_BG_0;
29 60
61 u32 tx, ty, se_curr, se_prev= CROSS_TY * 32 + CROSS_TX;
62
63 bg0_map[se_prev]++; // initial position of cross
64
30 // Initialize sprite button overlay. 65 // Initialize sprite button overlay.
31 init_sprite_pal(0, COLOR_WHITE); 66 init_sprite_pal(0, COLOR_WHITE);
32 init_sprites(0); 67 init_sprites(0);
@@ -51,6 +86,15 @@ int main(void) {
51 if (key_hold(KEY_RIGHT)) { 86 if (key_hold(KEY_RIGHT)) {
52 x += 3; 87 x += 3;
53 } 88 }
89 tx = ((x >> 3) + CROSS_TX) & 0x3F;
90 ty = ((y >> 3) + CROSS_TY) & 0x3F;
91
92 se_curr = se_index(tx, ty, 64);
93 if(se_curr != se_prev) {
94 bg0_map[se_prev]--;
95 bg0_map[se_curr]++;
96 se_prev= se_curr;
97 }
54 98
55 frame_counter++; 99 frame_counter++;
56 BG_H_SCROLL_0 = x; 100 BG_H_SCROLL_0 = x;