Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/libsnes/bsnes/snes/alt/ppu-compatibility/render/line.cpp
2 views
1
#ifdef PPU_CPP
2
3
inline uint16 PPU::get_palette(uint8 index) {
4
const unsigned addr = index << 1;
5
return cgram[addr] + (cgram[addr + 1] << 8);
6
}
7
8
//p = 00000bgr <palette data>
9
//t = BBGGGRRR <tilemap data>
10
//r = 0BBb00GGGg0RRRr0 <return data>
11
inline uint16 PPU::get_direct_color(uint8 p, uint8 t) {
12
return ((t & 7) << 2) | ((p & 1) << 1) |
13
(((t >> 3) & 7) << 7) | (((p >> 1) & 1) << 6) |
14
((t >> 6) << 13) | ((p >> 2) << 12);
15
}
16
17
inline uint16 PPU::get_pixel_normal(uint32 x) {
18
pixel_t &p = pixel_cache[x];
19
uint16 src_main, src_sub;
20
uint8 bg_sub;
21
src_main = p.src_main;
22
23
if(!regs.addsub_mode) {
24
bg_sub = BACK;
25
src_sub = regs.color_rgb;
26
} else {
27
bg_sub = p.bg_sub;
28
src_sub = p.src_sub;
29
}
30
31
if(!window[COL].main[x]) {
32
if(!window[COL].sub[x]) {
33
return 0x0000;
34
}
35
src_main = 0x0000;
36
}
37
38
if(!p.ce_main && regs.color_enabled[p.bg_main] && window[COL].sub[x]) {
39
bool halve = false;
40
if(regs.color_halve && window[COL].main[x]) {
41
if(regs.addsub_mode && bg_sub == BACK);
42
else {
43
halve = true;
44
}
45
}
46
return addsub(src_main, src_sub, halve);
47
}
48
49
return src_main;
50
}
51
52
inline uint16 PPU::get_pixel_swap(uint32 x) {
53
pixel_t &p = pixel_cache[x];
54
uint16 src_main, src_sub;
55
uint8 bg_sub;
56
src_main = p.src_sub;
57
58
if(!regs.addsub_mode) {
59
bg_sub = BACK;
60
src_sub = regs.color_rgb;
61
} else {
62
bg_sub = p.bg_main;
63
src_sub = p.src_main;
64
}
65
66
if(!window[COL].main[x]) {
67
if(!window[COL].sub[x]) {
68
return 0x0000;
69
}
70
src_main = 0x0000;
71
}
72
73
if(!p.ce_sub && regs.color_enabled[p.bg_sub] && window[COL].sub[x]) {
74
bool halve = false;
75
if(regs.color_halve && window[COL].main[x]) {
76
if(regs.addsub_mode && bg_sub == BACK);
77
else {
78
halve = true;
79
}
80
}
81
return addsub(src_main, src_sub, halve);
82
}
83
84
return src_main;
85
}
86
87
inline void PPU::render_line_output() {
88
uint32 *ptr = (uint32*)output + (line * 1024) + ((interlace() && field()) ? 512 : 0);
89
uint32 curr, prev;
90
91
if(!regs.pseudo_hires && regs.bg_mode != 5 && regs.bg_mode != 6) {
92
for(unsigned x = 0; x < 256; x++) {
93
curr = (regs.display_brightness << 15) | get_pixel_normal(x);
94
*ptr++ = curr;
95
}
96
} else {
97
for(unsigned x = 0, prev = 0; x < 256; x++) {
98
//blending is disabled below, as this should be done via video filtering
99
//blending code is left for reference purposes
100
101
curr = (regs.display_brightness << 15) | get_pixel_swap(x);
102
*ptr++ = curr; //(prev + curr - ((prev ^ curr) & 0x0421)) >> 1;
103
//prev = curr;
104
105
curr = (regs.display_brightness << 15) | get_pixel_normal(x);
106
*ptr++ = curr; //(prev + curr - ((prev ^ curr) & 0x0421)) >> 1;
107
//prev = curr;
108
}
109
}
110
}
111
112
inline void PPU::render_line_clear() {
113
uint32 *ptr = (uint32*)output + (line * 1024) + ((interlace() && field()) ? 512 : 0);
114
unsigned width = (!regs.pseudo_hires && regs.bg_mode != 5 && regs.bg_mode != 6) ? 256 : 512;
115
memset(ptr, 0, width * 2 * sizeof(uint32));
116
}
117
118
#endif
119
120