1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
#include "types.hpp"
#include "util.hpp"
#include "input.hpp"
void bad_vsync() {
while (*REG_VCOUNT >= 160);
while (*REG_VCOUNT < 160);
}
int main() {
// background control
auto bg_flags = BGControlFlags()
.set_charblock_base(0)
.set_screenblock_base(28)
.set_size(BGControlSize::Regular_64x64);
set_bg_control(0, bg_flags);
set_bg_offsets(0, 0, 0);
// background tiles
const Tile4 tiles[2] = {
{{0x11111111, 0x01111111, 0x01111111, 0x01111111, 0x01111111, 0x01111111, 0x01111111, 0x00000001}},
{{0x00000000, 0x00100100, 0x01100110, 0x00011000, 0x00011000, 0x01100110, 0x00100100, 0x00000000}},
};
set_tile(0, 0, tiles[0]);
set_tile(0, 1, tiles[1]);
// background tiles
set_bg_palette(0, 1, Color::from_rgb(31, 0, 0));
set_bg_palette(1, 1, Color::from_rgb( 0, 31, 0));
set_bg_palette(2, 1, Color::from_rgb( 0, 0, 31));
set_bg_palette(3, 1, Color::from_rgb(16, 16, 16));
// background screen entries
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 32*32; j++) {
auto screen_entry = ScreenEntry()
.set_tile_index(i % 2)
.set_palette_bank(i);
set_screen_entry(28+i, j, screen_entry);
}
}
// object palettes
set_obj_palette(0, 1, Color::from_rgb(0, 0, 0));
set_obj_palette(0, 2, Color::from_rgb(31, 31, 0));
// object attributes
auto obj_attr = ObjectAttributes()
.set_size(ObjectAttributes::Size_16x16)
.set_tile_index(0)
.set_palette_bank(0)
.set_x(50).set_y(50);
set_obj_attributes(0, obj_attr);
Tile4 obj_tile = {0x01230123, 0x01230123, 0x01230123, 0x01230123, 0x01230123, 0x01230123, 0x01230123, 0x01230123};
for (u32 i = 0; i < 4; i++) {
set_tile(4, i, obj_tile);
}
auto display_control_flags = DisplayControlFlags()
.set_mode(0)
.enable_layer(BG0)
.enable_layer(Obj)
.set_1d_object_mapping(1);
set_display_control(display_control_flags);
s16 x = 0, y = 0;
while (1) {
bad_vsync();
keyflags_poll();
if (key_is_down(Key::Left)) x -= 1;
if (key_is_down(Key::Right)) x += 1;
if (key_is_down(Key::Up)) y -= 1;
if (key_is_down(Key::Down)) y += 1;
set_bg_offsets(0, x, y);
}
return 0;
}
|