summaryrefslogtreecommitdiff
path: root/source/main.cpp
blob: 21d1c26065a31a75d620f3c34eab3deec31e16c6 (plain)
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
#include "types.hpp"
#include "util.hpp"
#include "input.hpp"

void bad_vsync() {
	while (*REG_VCOUNT >= 160);
	while (*REG_VCOUNT < 160);
}

int main() {
	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);

	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]);

	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));

	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);
		}
	}

	set_display_control(Mode0, BG0);

	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;
}