Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/libsnes/bsnes/snes/alt/ppu-compatibility/render/cache.cpp
2 views
1
#ifdef PPU_CPP
2
3
#define render_bg_tile_line_2bpp(mask) \
4
col = !!(d0 & mask) << 0; \
5
col += !!(d1 & mask) << 1; \
6
*dest++ = col
7
8
#define render_bg_tile_line_4bpp(mask) \
9
col = !!(d0 & mask) << 0; \
10
col += !!(d1 & mask) << 1; \
11
col += !!(d2 & mask) << 2; \
12
col += !!(d3 & mask) << 3; \
13
*dest++ = col
14
15
#define render_bg_tile_line_8bpp(mask) \
16
col = !!(d0 & mask) << 0; \
17
col += !!(d1 & mask) << 1; \
18
col += !!(d2 & mask) << 2; \
19
col += !!(d3 & mask) << 3; \
20
col += !!(d4 & mask) << 4; \
21
col += !!(d5 & mask) << 5; \
22
col += !!(d6 & mask) << 6; \
23
col += !!(d7 & mask) << 7; \
24
*dest++ = col
25
26
template<unsigned color_depth>
27
void PPU::render_bg_tile(uint16 tile_num) {
28
uint8 col, d0, d1, d2, d3, d4, d5, d6, d7;
29
30
if(color_depth == COLORDEPTH_4) {
31
uint8 *dest = (uint8*)bg_tiledata[TILE_2BIT] + tile_num * 64;
32
unsigned pos = tile_num * 16;
33
unsigned y = 8;
34
while(y--) {
35
d0 = vram[pos ];
36
d1 = vram[pos + 1];
37
render_bg_tile_line_2bpp(0x80);
38
render_bg_tile_line_2bpp(0x40);
39
render_bg_tile_line_2bpp(0x20);
40
render_bg_tile_line_2bpp(0x10);
41
render_bg_tile_line_2bpp(0x08);
42
render_bg_tile_line_2bpp(0x04);
43
render_bg_tile_line_2bpp(0x02);
44
render_bg_tile_line_2bpp(0x01);
45
pos += 2;
46
}
47
bg_tiledata_state[TILE_2BIT][tile_num] = 0;
48
}
49
50
if(color_depth == COLORDEPTH_16) {
51
uint8 *dest = (uint8*)bg_tiledata[TILE_4BIT] + tile_num * 64;
52
unsigned pos = tile_num * 32;
53
unsigned y = 8;
54
while(y--) {
55
d0 = vram[pos ];
56
d1 = vram[pos + 1];
57
d2 = vram[pos + 16];
58
d3 = vram[pos + 17];
59
render_bg_tile_line_4bpp(0x80);
60
render_bg_tile_line_4bpp(0x40);
61
render_bg_tile_line_4bpp(0x20);
62
render_bg_tile_line_4bpp(0x10);
63
render_bg_tile_line_4bpp(0x08);
64
render_bg_tile_line_4bpp(0x04);
65
render_bg_tile_line_4bpp(0x02);
66
render_bg_tile_line_4bpp(0x01);
67
pos += 2;
68
}
69
bg_tiledata_state[TILE_4BIT][tile_num] = 0;
70
}
71
72
if(color_depth == COLORDEPTH_256) {
73
uint8 *dest = (uint8*)bg_tiledata[TILE_8BIT] + tile_num * 64;
74
unsigned pos = tile_num * 64;
75
unsigned y = 8;
76
while(y--) {
77
d0 = vram[pos ];
78
d1 = vram[pos + 1];
79
d2 = vram[pos + 16];
80
d3 = vram[pos + 17];
81
d4 = vram[pos + 32];
82
d5 = vram[pos + 33];
83
d6 = vram[pos + 48];
84
d7 = vram[pos + 49];
85
render_bg_tile_line_8bpp(0x80);
86
render_bg_tile_line_8bpp(0x40);
87
render_bg_tile_line_8bpp(0x20);
88
render_bg_tile_line_8bpp(0x10);
89
render_bg_tile_line_8bpp(0x08);
90
render_bg_tile_line_8bpp(0x04);
91
render_bg_tile_line_8bpp(0x02);
92
render_bg_tile_line_8bpp(0x01);
93
pos += 2;
94
}
95
bg_tiledata_state[TILE_8BIT][tile_num] = 0;
96
}
97
}
98
99
#undef render_bg_tile_line_2bpp
100
#undef render_bg_tile_line_4bpp
101
#undef render_bg_tile_line_8bpp
102
103
void PPU::flush_pixel_cache() {
104
105
uint16 main;
106
107
int backdropColor = interface()->getBackdropColor();
108
if(backdropColor == -1)
109
main = get_palette(0);
110
else main = backdropColor;
111
112
uint16 sub = (regs.pseudo_hires || regs.bg_mode == 5 || regs.bg_mode == 6)
113
? main
114
: regs.color_rgb;
115
116
unsigned i = 255;
117
do {
118
pixel_cache[i].src_main = main;
119
pixel_cache[i].src_sub = sub;
120
pixel_cache[i].bg_main = BACK;
121
pixel_cache[i].bg_sub = BACK;
122
pixel_cache[i].ce_main = false;
123
pixel_cache[i].ce_sub = false;
124
pixel_cache[i].pri_main = 0;
125
pixel_cache[i].pri_sub = 0;
126
} while(i--);
127
}
128
129
void PPU::alloc_tiledata_cache() {
130
bg_tiledata[TILE_2BIT] = new uint8_t[262144]();
131
bg_tiledata[TILE_4BIT] = new uint8_t[131072]();
132
bg_tiledata[TILE_8BIT] = new uint8_t[ 65536]();
133
bg_tiledata_state[TILE_2BIT] = new uint8_t[ 4096]();
134
bg_tiledata_state[TILE_4BIT] = new uint8_t[ 2048]();
135
bg_tiledata_state[TILE_8BIT] = new uint8_t[ 1024]();
136
}
137
138
//marks all tiledata cache entries as dirty
139
void PPU::flush_tiledata_cache() {
140
for(unsigned i = 0; i < 4096; i++) bg_tiledata_state[TILE_2BIT][i] = 1;
141
for(unsigned i = 0; i < 2048; i++) bg_tiledata_state[TILE_4BIT][i] = 1;
142
for(unsigned i = 0; i < 1024; i++) bg_tiledata_state[TILE_8BIT][i] = 1;
143
}
144
145
void PPU::free_tiledata_cache() {
146
delete[] bg_tiledata[TILE_2BIT];
147
delete[] bg_tiledata[TILE_4BIT];
148
delete[] bg_tiledata[TILE_8BIT];
149
delete[] bg_tiledata_state[TILE_2BIT];
150
delete[] bg_tiledata_state[TILE_4BIT];
151
delete[] bg_tiledata_state[TILE_8BIT];
152
}
153
154
#endif
155
156