-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathppu.c
117 lines (71 loc) · 1.92 KB
/
ppu.c
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
#include "nes.h"
struct _ppu ppu = { .read = &nes_ppu_read_address, .write = &nes_ppu_write_address };
uint8_t nes_ppu_read_null(uint16_t address) {
return 0;
}
void nes_ppu_write_null(uint16_t address, uint8_t value) {
}
uint8_t ppu_read_pattern_table(uint16_t address) {
printf("READ PATTERN\n");
return 0;
}
void ppu_write_pattern_table(uint16_t address, uint8_t value) {
printf("WROTE PATTERN\n");
}
uint8_t ppu_read_name_table(uint16_t address) {
printf("READ NAME\n");
return 0;
}
void ppu_write_name_table(uint16_t address, uint8_t value) {
printf("WROTE NAME\n");
}
uint8_t ppu_read_palette(uint16_t address) {
printf("READ PALETTE\n");
return 0;
}
void ppu_write_palette(uint16_t address, uint8_t value) {
printf("WROTE PALETTE\n");
}
uint8_t (* nes_ppu_read[0x10])(uint16_t address) = {
ppu_read_pattern_table,
ppu_read_pattern_table,
ppu_read_pattern_table,
ppu_read_pattern_table,
ppu_read_pattern_table,
ppu_read_pattern_table,
ppu_read_pattern_table,
ppu_read_pattern_table,
ppu_read_name_table,
ppu_read_name_table,
ppu_read_name_table,
ppu_read_name_table,
ppu_read_palette,
ppu_read_palette,
ppu_read_palette,
ppu_read_palette
};
void (* nes_ppu_write[0x10])(uint16_t address, uint8_t value) = {
nes_ppu_write_null,
nes_ppu_write_null,
nes_ppu_write_null,
nes_ppu_write_null,
nes_ppu_write_null,
nes_ppu_write_null,
nes_ppu_write_null,
nes_ppu_write_null,
ppu_write_name_table,
ppu_write_name_table,
ppu_write_name_table,
ppu_write_name_table,
ppu_write_palette,
ppu_write_palette,
ppu_write_palette,
ppu_write_palette
};
uint8_t nes_ppu_read_address(uint16_t address) {
return ppu.vram[address];//(nes_ppu_read[(address % NES_PPU_VRAM_SIZE) / 0x400])(address);
}
void nes_ppu_write_address(uint16_t address, uint8_t value) {
ppu.vram[address] = value;
(nes_ppu_write[(address % NES_PPU_VRAM_SIZE) / 0x400])(address, value);
}