Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/libsnes/bsnes/snes/alt/ppu-compatibility/render/windows.cpp
2 views
1
#ifdef PPU_CPP
2
3
//screen: 0 = main, 1 = sub
4
void PPU::build_window_table(uint8 bg, bool screen) {
5
bool set = 1, clr = 0;
6
uint8 *table = (screen == 0 ? window[bg].main : window[bg].sub);
7
8
if(bg != COL) {
9
if(screen == 0 && regs.window_enabled[bg] == false) {
10
memset(table, 0, 256);
11
return;
12
}
13
if(screen == 1 && regs.sub_window_enabled[bg] == false) {
14
memset(table, 0, 256);
15
return;
16
}
17
} else {
18
switch(screen == 0 ? regs.color_mask : regs.colorsub_mask) {
19
case 0: memset(table, 1, 256); return; //always
20
case 3: memset(table, 0, 256); return; //never
21
case 1: set = 1, clr = 0; break; //inside window only
22
case 2: set = 0, clr = 1; break; //outside window only
23
}
24
}
25
26
const uint16 window1_left = regs.window1_left;
27
const uint16 window1_right = regs.window1_right;
28
const uint16 window2_left = regs.window2_left;
29
const uint16 window2_right = regs.window2_right;
30
31
if(regs.window1_enabled[bg] == false && regs.window2_enabled[bg] == false) {
32
memset(table, clr, 256);
33
return;
34
}
35
36
if(regs.window1_enabled[bg] == true && regs.window2_enabled[bg] == false) {
37
if(regs.window1_invert[bg] == true) set ^= clr ^= set ^= clr;
38
for(unsigned x = 0; x < 256; x++) {
39
table[x] = (x >= window1_left && x <= window1_right) ? set : clr;
40
}
41
return;
42
}
43
44
if(regs.window1_enabled[bg] == false && regs.window2_enabled[bg] == true) {
45
if(regs.window2_invert[bg] == true) set ^= clr ^= set ^= clr;
46
for(unsigned x = 0; x < 256; x++) {
47
table[x] = (x >= window2_left && x <= window2_right) ? set : clr;
48
}
49
return;
50
}
51
52
for(unsigned x = 0; x < 256; x++) {
53
bool w1_mask = (x >= window1_left && x <= window1_right) ^ regs.window1_invert[bg];
54
bool w2_mask = (x >= window2_left && x <= window2_right) ^ regs.window2_invert[bg];
55
56
switch(regs.window_mask[bg]) {
57
case 0: table[x] = (w1_mask | w2_mask) == 1 ? set : clr; break; //or
58
case 1: table[x] = (w1_mask & w2_mask) == 1 ? set : clr; break; //and
59
case 2: table[x] = (w1_mask ^ w2_mask) == 1 ? set : clr; break; //xor
60
case 3: table[x] = (w1_mask ^ w2_mask) == 0 ? set : clr; break; //xnor
61
}
62
}
63
}
64
65
void PPU::build_window_tables(uint8 bg) {
66
build_window_table(bg, 0);
67
build_window_table(bg, 1);
68
}
69
70
#endif
71
72