Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/libsnes/bsnes/snes/alt/ppu-performance/background/mode7.cpp
2 views
1
#ifdef PPU_CPP
2
3
#define Clip(x) (((x) & 0x2000) ? ((x) | ~0x03ff) : ((x) & 0x03ff))
4
5
void PPU::Background::render_mode7() {
6
signed px, py;
7
signed tx, ty, tile, palette;
8
9
signed a = sclip<16>(self.regs.m7a);
10
signed b = sclip<16>(self.regs.m7b);
11
signed c = sclip<16>(self.regs.m7c);
12
signed d = sclip<16>(self.regs.m7d);
13
14
signed cx = sclip<13>(self.regs.m7x);
15
signed cy = sclip<13>(self.regs.m7y);
16
signed hofs = sclip<13>(self.regs.mode7_hoffset);
17
signed vofs = sclip<13>(self.regs.mode7_voffset);
18
19
signed y = (self.regs.mode7_vflip == false ? self.vcounter() : 255 - self.vcounter());
20
21
uint16 *mosaic_x, *mosaic_y;
22
if(id == ID::BG1) {
23
mosaic_x = mosaic_table[self.bg1.regs.mosaic];
24
mosaic_y = mosaic_table[self.bg1.regs.mosaic];
25
} else {
26
mosaic_x = mosaic_table[self.bg2.regs.mosaic];
27
mosaic_y = mosaic_table[self.bg1.regs.mosaic];
28
}
29
30
unsigned priority0 = (priority0_enable ? regs.priority0 : 0);
31
unsigned priority1 = (priority1_enable ? regs.priority1 : 0);
32
if(priority0 + priority1 == 0) return;
33
34
signed psx = ((a * Clip(hofs - cx)) & ~63) + ((b * Clip(vofs - cy)) & ~63) + ((b * mosaic_y[y]) & ~63) + (cx << 8);
35
signed psy = ((c * Clip(hofs - cx)) & ~63) + ((d * Clip(vofs - cy)) & ~63) + ((d * mosaic_y[y]) & ~63) + (cy << 8);
36
for(signed x = 0; x < 256; x++) {
37
px = (psx + (a * mosaic_x[x])) >> 8;
38
py = (psy + (c * mosaic_x[x])) >> 8;
39
40
switch(self.regs.mode7_repeat) {
41
case 0: case 1: {
42
px &= 1023;
43
py &= 1023;
44
tx = ((px >> 3) & 127);
45
ty = ((py >> 3) & 127);
46
tile = ppu.vram[(ty * 128 + tx) << 1];
47
palette = ppu.vram[(((tile << 6) + ((py & 7) << 3) + (px & 7)) << 1) + 1];
48
break;
49
}
50
51
case 2: {
52
if((px | py) & ~1023) {
53
palette = 0;
54
} else {
55
px &= 1023;
56
py &= 1023;
57
tx = ((px >> 3) & 127);
58
ty = ((py >> 3) & 127);
59
tile = ppu.vram[(ty * 128 + tx) << 1];
60
palette = ppu.vram[(((tile << 6) + ((py & 7) << 3) + (px & 7)) << 1) + 1];
61
}
62
break;
63
}
64
65
case 3: {
66
if((px | py) & ~1023) {
67
tile = 0;
68
} else {
69
px &= 1023;
70
py &= 1023;
71
tx = ((px >> 3) & 127);
72
ty = ((py >> 3) & 127);
73
tile = ppu.vram[(ty * 128 + tx) << 1];
74
}
75
palette = ppu.vram[(((tile << 6) + ((py & 7) << 3) + (px & 7)) << 1) + 1];
76
break;
77
}
78
}
79
80
unsigned priority;
81
if(id == ID::BG1) {
82
priority = priority0;
83
} else {
84
priority = (palette & 0x80 ? priority1 : priority0);
85
palette &= 0x7f;
86
}
87
88
if(palette == 0) continue;
89
unsigned plot_x = (self.regs.mode7_hflip == false ? x : 255 - x);
90
91
unsigned color;
92
if(self.screen.regs.direct_color && id == ID::BG1) {
93
color = self.screen.get_direct_color(0, palette);
94
} else {
95
color = self.screen.get_palette(palette);
96
}
97
98
if(regs.main_enable && !window.main[plot_x]) self.screen.output.plot_main(plot_x, color, priority, id);
99
if(regs.sub_enable && !window.sub[plot_x]) self.screen.output.plot_sub(plot_x, color, priority, id);
100
}
101
}
102
103
#undef Clip
104
105
#endif
106
107