aboutsummaryrefslogtreecommitdiff
path: root/src/ppu/ppu.c
blob: e2fccb9657c0534e47a9652d96d70464debaf0e2 (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
#include <stdlib.h>

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

void hh_ppu_update_foreground(unsigned index, hh_s_ppu_loc_fam_entry e) {
	hh_s_ppu_vram_data s = hh_ppu_2nat_fam(e);
	s.offset = HH_PPU_VRAM_FAM_OFFSET + HH_PPU_VRAM_FAM_ENTRY_SIZE * index;
	hh_ppu_vram_write(s);
	free(s.data);
}

void hh_ppu_update_background(unsigned index, hh_s_ppu_loc_bam_entry e) {
	hh_s_ppu_vram_data s = hh_ppu_2nat_bam(e);
	s.offset = HH_PPU_VRAM_BAM_OFFSET + HH_PPU_VRAM_BAM_ENTRY_SIZE * index;
	hh_ppu_vram_write(s);
	free(s.data);
}

void hh_ppu_update_sprite(unsigned tilemap_index, hh_s_ppu_loc_sprite sprite) {
	hh_s_ppu_vram_data s = hh_ppu_2nat_sprite(sprite);
	s.offset = HH_PPU_VRAM_TMM_OFFSET + HH_PPU_VRAM_TMM_SPRITE_SIZE * tilemap_index;
	hh_ppu_vram_write(s);
	free(s.data);
}

void hh_ppu_update_aux(hh_s_ppu_loc_aux aux) {
	hh_s_ppu_vram_data a = hh_ppu_2nat_aux(aux);
	a.offset = HH_PPU_VRAM_AUX_OFFSET;
	hh_ppu_vram_write(a);
	free(a.data);
}

void hh_ppu_update_palette_table(hh_ppu_loc_palette_table_t table) {
	for(unsigned i = 0; i < HH_PPU_PALETTE_COUNT; i++)
		hh_ppu_update_palette(i, table[i]);
}

void hh_ppu_update_palette(unsigned palette_index, hh_ppu_loc_palette_data_t palette) {
	for(unsigned i = 0; i < HH_PPU_PALETTE_COLOR_COUNT; i++)
		hh_ppu_update_color(palette_index, i, palette[i]);
}

void hh_ppu_update_color(unsigned palette_index, unsigned color_index, hh_ppu_rgb_color_t color) {
	hh_s_ppu_vram_data c = hh_ppu_2nat_color(color);
	c.offset = HH_PPU_VRAM_PAL_OFFSET +
		palette_index * HH_PPU_VRAM_PAL_ENTRY_SIZE * HH_PPU_PALETTE_COLOR_COUNT +
		color_index * HH_PPU_VRAM_PAL_ENTRY_SIZE;
	hh_ppu_vram_write(c);
	free(c.data);
}