aboutsummaryrefslogtreecommitdiff
path: root/src/main.c
blob: b61f124ebea6b7f3ecb77d134fa4d8e63a38a487 (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
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include <stdlib.h>
#include <math.h>
#ifdef HH_TARGET_DESKTOP
#include <stdio.h>
#endif

#include "main.h"
#include "ppu/ppu.h"
#include "ppu/consts.h"

bool g_hh_run = true;

int main() {
	hh_setup();
	hh_loop();
	hh_exit();
	return 0;
}

void hh_ppu_vblank_interrupt() {
	static unsigned long frame = 0;
	frame++;

#ifdef HH_TARGET_DESKTOP
	// printf("frame %lu\n", frame);
#endif

	unsigned shift = (double) sin((double) frame / 20) * 10 + 10;
	hh_ppu_update_aux((hh_s_ppu_loc_aux) {
		.bg_shift_x = shift,
		.bg_shift_y = 0,
		.fg_fetch = 0,
		.sysreset = 0,
	});
}

void hh_setup() {
	hh_ppu_init();

	hh_s_ppu_loc_sprite sprite = {
		0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
		0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 
		0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 
		0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 
		0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 
		0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
		0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
		0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
		0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
		0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
		0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 
		0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 
		0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
		0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 
		0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 
		0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0
	};

	for (int x = 0; x < HH_PPU_SPRITE_WIDTH; x++) {
		for (int y = 0; y < HH_PPU_SPRITE_HEIGHT; y++) {
			// sprite[y * HH_PPU_SPRITE_WIDTH + x] = (pow(x - 8, 2) + pow(y - 8, 2) < 64) ? 1 : 0;
			uint8_t p = sprite[y * HH_PPU_SPRITE_WIDTH + x];
			printf("%c%c%c", p ? 'X' : ' ', p ? 'X' : ' ', p ? 'X' : ' ');
		}
		printf("\n");
	}

	hh_ppu_update_sprite(0, sprite);

	// hh_ppu_update_foreground(0, (hh_s_ppu_loc_fam_entry) {
	// 	.horizontal_flip = false,
	// 	.vertical_flip = false,
	// 	.palette_index = 1,
	// 	.tilemap_index = 0,
	// 	.position_x = 30,
	// 	.position_y = 40,
	// });

	hh_ppu_update_background(3, (hh_s_ppu_loc_bam_entry) {
		.horizontal_flip = false,
		.vertical_flip = false,
		.palette_index = 1,
		.tilemap_index = 0,
	});
	hh_ppu_update_background(4, (hh_s_ppu_loc_bam_entry) {
		.horizontal_flip = true,
		.vertical_flip = false,
		.palette_index = 2,
		.tilemap_index = 0,
	});
	hh_ppu_update_background(5, (hh_s_ppu_loc_bam_entry) {
		.horizontal_flip = false,
		.vertical_flip = false,
		.palette_index = 3,
		.tilemap_index = 0,
	});
	hh_ppu_update_background(6, (hh_s_ppu_loc_bam_entry) {
		.horizontal_flip = false,
		.vertical_flip = true,
		.palette_index = 4,
		.tilemap_index = 0,
	});
	hh_ppu_update_background(7, (hh_s_ppu_loc_bam_entry) {
		.horizontal_flip = true,
		.vertical_flip = true,
		.palette_index = 5,
		.tilemap_index = 0,
	});

	hh_ppu_update_color(1, 1, (hh_ppu_rgb_color_t) {0xf, 0x0, 0xf});
	hh_ppu_update_color(2, 1, (hh_ppu_rgb_color_t) {0xf, 0xf, 0xf});
	hh_ppu_update_color(3, 1, (hh_ppu_rgb_color_t) {0xf, 0x0, 0x0});
	hh_ppu_update_color(4, 1, (hh_ppu_rgb_color_t) {0x0, 0xf, 0xf});
	hh_ppu_update_color(5, 1, (hh_ppu_rgb_color_t) {0x0, 0x0, 0xf});
}

void hh_exit() {
	g_hh_run = false;

	hh_ppu_deinit();
}