Skip to content

Commit

Permalink
beta6
Browse files Browse the repository at this point in the history
  • Loading branch information
DerKoun committed May 26, 2019
1 parent 6736243 commit ee7b978
Show file tree
Hide file tree
Showing 14 changed files with 208 additions and 157 deletions.
3 changes: 2 additions & 1 deletion bsnes/sfc/interface/configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ auto Configuration::process(Markup::Node document, bool load) -> void {
bind(natural, "Hacks/PPU/Mode7/Wsbg3", hacks.ppu.mode7.wsbg3);
bind(natural, "Hacks/PPU/Mode7/Wsbg4", hacks.ppu.mode7.wsbg4);
bind(boolean, "Hacks/PPU/Mode7/Wsobj", hacks.ppu.mode7.wsobj);
bind(boolean, "Hacks/PPU/Mode7/Supersample", hacks.ppu.mode7.supersample);
bind(boolean, "Hacks/PPU/Mode7/Igwin", hacks.ppu.mode7.igwin);
bind(natural, "Hacks/PPU/Mode7/Supersample", hacks.ppu.mode7.supersample);
bind(boolean, "Hacks/PPU/Mode7/Mosaic", hacks.ppu.mode7.mosaic);
bind(boolean, "Hacks/DSP/Fast", hacks.dsp.fast);
bind(boolean, "Hacks/DSP/Cubic", hacks.dsp.cubic);
Expand Down
11 changes: 6 additions & 5 deletions bsnes/sfc/interface/configuration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,19 @@ struct Configuration {
struct Hacks {
struct PPU {
bool fast = true;
bool noSpriteLimit = false;
bool noSpriteLimit = true;
struct Mode7 {
uint scale = 1;
uint scale = 2;
bool perspective = true;
uint widescreen = 64;
uint widescreen = 72;
uint wsbg1 = 1;
uint wsbg2 = 1;
uint wsbg3 = 1;
uint wsbg4 = 1;
bool wsobj = false;
bool supersample = false;
bool mosaic = true;
bool igwin = false;
uint supersample = 1;
bool mosaic = false;
} mode7;
} ppu;
struct DSP {
Expand Down
19 changes: 8 additions & 11 deletions bsnes/sfc/ppu-fast/background.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ auto PPUfast::Line::renderBackground(PPUfast::IO::Background& self, uint source)
int ws = (int)ppufast.widescreen();
if(ws > 0) {
uint wsConf = ppufast.wsbg(source);
if(((wsConf % 2) != 0) == (y < (((int)(wsConf / 2)) * 40))) {
if(wsConf == 0 || (wsConf != 1 && (((wsConf % 2) != 0) == (y < (((int)(wsConf / 2)) * 40))))) {
ws = 0;
}
}
Expand Down Expand Up @@ -105,22 +105,19 @@ auto PPUfast::Line::renderBackground(PPUfast::IO::Background& self, uint source)
if(!mosaicPalette) continue;

if(!hires) {
int wx = x;
if (wx < 0) wx = 0;
if (wx > 255) wx = 255;
if(self.aboveEnable && !windowAbove[wx]) plotAbove(x, source, mosaicPriority, mosaicColor);
if(self.belowEnable && !windowBelow[wx]) plotBelow(x, source, mosaicPriority, mosaicColor);
if(self.aboveEnable && !windowAbove[ppufast.winXad(x, false)]) plotAbove(x, source, mosaicPriority, mosaicColor);
if(self.belowEnable && !windowBelow[ppufast.winXad(x, true)]) plotBelow(x, source, mosaicPriority, mosaicColor);
} else {
uint X = x >> 1;
int X = x / 2;
if(!ppufast.hd()) {
if(x & 1) {
if(self.aboveEnable && !windowAbove[X]) plotAbove(X, source, mosaicPriority, mosaicColor);
if(self.aboveEnable && !windowAbove[ppufast.winXad(X, false)]) plotAbove(X, source, mosaicPriority, mosaicColor);
} else {
if(self.belowEnable && !windowBelow[X]) plotBelow(X, source, mosaicPriority, mosaicColor);
if(self.belowEnable && !windowBelow[ppufast.winXad(X, true)]) plotBelow(X, source, mosaicPriority, mosaicColor);
}
} else {
if(self.aboveEnable && !windowAbove[X]) plotHD(above, X, source, mosaicPriority, mosaicColor, true, x & 1);
if(self.belowEnable && !windowBelow[X]) plotHD(below, X, source, mosaicPriority, mosaicColor, true, x & 1);
if(self.aboveEnable && !windowAbove[ppufast.winXad(X, false)]) plotHD(above, X, source, mosaicPriority, mosaicColor, true, x & 1);
if(self.belowEnable && !windowBelow[ppufast.winXad(X, true)]) plotHD(below, X, source, mosaicPriority, mosaicColor, true, x & 1);
}
}
}
Expand Down
46 changes: 37 additions & 9 deletions bsnes/sfc/ppu-fast/line.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,36 @@ uint PPUfast::Line::start = 0;
uint PPUfast::Line::count = 0;

auto PPUfast::Line::flush() -> void {
if(ppufast.hdPerspective()) {
#define isLineMode7(l) (l.io.bg1.tileMode == TileMode::Mode7 \
&& !l.io.displayDisable && (l.io.bg1.aboveEnable || l.io.bg1.belowEnable))
ppufast.ind = 0;
bool state = false;
uint y;
for(y = 0; y < Line::count; y++) {
if(state != isLineMode7(ppufast.lines[Line::start + y])) {
state = !state;
if(state) {
ppufast.starts[ppufast.ind] = ppufast.lines[Line::start + y].y;
} else {
ppufast.ends[ppufast.ind] = ppufast.lines[Line::start + y].y - 1;
int offs = (ppufast.ends[ppufast.ind] - ppufast.starts[ppufast.ind]) / 8;
ppufast.startsp[ppufast.ind] = ppufast.starts[ppufast.ind] + offs;
ppufast.endsp[ppufast.ind] = ppufast.ends[ppufast.ind] - offs;
ppufast.ind++;
}
}
}
#undef isLineMode7
if(state) {
ppufast.ends[ppufast.ind] = ppufast.lines[Line::start + y].y - 1;
int offs = (ppufast.ends[ppufast.ind] - ppufast.starts[ppufast.ind]) / 8;
ppufast.startsp[ppufast.ind] = ppufast.starts[ppufast.ind] + offs;
ppufast.endsp[ppufast.ind] = ppufast.ends[ppufast.ind] - offs;
ppufast.ind++;
}
}

if(Line::count) {
#pragma omp parallel for if(Line::count >= 8)
for(uint y = 0; y < Line::count; y++) {
Expand All @@ -22,7 +52,7 @@ auto PPUfast::Line::render() -> void {
);
auto width = (!hd
? (!ppufast.hires() ? 256 : 512)
: (256 * scale * scale));
: ((256+2*ppufast.widescreen()) * scale * scale));

if(io.displayDisable) {
memory::fill<uint32>(output, width);
Expand Down Expand Up @@ -63,13 +93,11 @@ auto PPUfast::Line::render() -> void {
}

auto PPUfast::Line::pixel(uint x, Pixel above, Pixel below) const -> uint15 {
if (x < 0) x = 0;
if (x > 255) x = 255;
if(!windowAbove[x]) above.color = 0x0000;
if(!windowBelow[x]) return above.color;
if(!windowAbove[ppufast.winXad(x, false)]) above.color = 0x0000;
if(!windowBelow[ppufast.winXad(x, true)]) return above.color;
if(!io.col.enable[above.source]) return above.color;
if(!io.col.blendMode) return blend(above.color, io.col.fixedColor, io.col.halve && windowAbove[x]);
return blend(above.color, below.color, io.col.halve && windowAbove[x] && below.source != Source::COL);
if(!io.col.blendMode) return blend(above.color, io.col.fixedColor, io.col.halve && windowAbove[ppufast.winXad(x, false)]);
return blend(above.color, below.color, io.col.halve && windowAbove[ppufast.winXad(x, false)] && below.source != Source::COL);
}

auto PPUfast::Line::blend(uint x, uint y, bool halve) const -> uint15 {
Expand Down Expand Up @@ -102,12 +130,12 @@ auto PPUfast::Line::directColor(uint paletteIndex, uint paletteColor) const -> u
}

auto PPUfast::Line::plotAbove(int x, uint source, uint priority, uint color) -> void {
if(ppufast.hd()) return plotHD(above, x, source, priority, color, false, false);
if(ppufast.hd() || ppufast.ss()) return plotHD(above, x, source, priority, color, false, false);
if(priority > above[x].priority) above[x] = {source, priority, color};
}

auto PPUfast::Line::plotBelow(int x, uint source, uint priority, uint color) -> void {
if(ppufast.hd()) return plotHD(below, x, source, priority, color, false, false);
if(ppufast.hd() || ppufast.ss()) return plotHD(below, x, source, priority, color, false, false);
if(priority > below[x].priority) below[x] = {source, priority, color};
}

Expand Down
6 changes: 3 additions & 3 deletions bsnes/sfc/ppu-fast/mode7.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ auto PPUfast::Line::renderMode7(PPUfast::IO::Background& self, uint source) -> v

//HD mode 7 support
if(!ppufast.hdMosaic() || !self.mosaicEnable || !io.mosaicSize) {
if(ppufast.hdScale() > 1) return renderMode7HD(self, source);
if(ppufast.hdScale() > 0) return renderMode7HD(self, source);
}

int Y = this->y - (self.mosaicEnable ? this->y % (1 + io.mosaicSize) : 0);
Expand Down Expand Up @@ -66,7 +66,7 @@ auto PPUfast::Line::renderMode7(PPUfast::IO::Background& self, uint source) -> v
}
if(!mosaicPalette) continue;

if(self.aboveEnable && !windowAbove[X]) plotAbove(X, source, mosaicPriority, mosaicColor);
if(self.belowEnable && !windowBelow[X]) plotBelow(X, source, mosaicPriority, mosaicColor);
if(self.aboveEnable && !windowAbove[ppufast.winXad(X, false)]) plotAbove(X, source, mosaicPriority, mosaicColor);
if(self.belowEnable && !windowBelow[ppufast.winXad(X, true)]) plotBelow(X, source, mosaicPriority, mosaicColor);
}
}
157 changes: 71 additions & 86 deletions bsnes/sfc/ppu-fast/mode7hd.cpp
Original file line number Diff line number Diff line change
@@ -1,57 +1,48 @@
auto PPUfast::Line::renderMode7HD(PPUfast::IO::Background& self, uint source) -> void {
const bool extbg = source == Source::BG2;
const uint scale = ppufast.hdScale();
const uint sampScale = ppufast.hdSupersample();
const uint scale = ppufast.hdScale() * sampScale;

uint sampTmp[(256+2*ppufast.widescreen()) * 4 * scale/sampScale] = {};

Pixel pixel;
Pixel* above = &this->above[-1];
Pixel* below = &this->below[-1];
Pixel* above = &this->above[0];
Pixel* below = &this->below[0];

//find the first and last scanline for interpolation
int y_a = y;
int y_b = y;
int y_a = -1;
int y_b = -1;
#define isLineMode7(n) (ppufast.lines[n].io.bg1.tileMode == TileMode::Mode7 && !ppufast.lines[n].io.displayDisable && ( \
(ppufast.lines[n].io.bg1.aboveEnable || ppufast.lines[n].io.bg1.belowEnable) \
))
if(ppufast.hdPerspective()) {
while(y_a > 1 && isLineMode7(y_a)) y_a--; y_a++;
while(y_b < 239 && isLineMode7(y_b)) y_b++; y_b--;
} else {
for(int i = 0; i < ppufast.ind; i++) {
if(y >= ppufast.starts[i] && y <= ppufast.ends[i]) {
y_a = ppufast.startsp[i];
y_b = ppufast.endsp[i];
break;
}
}
}
if(y_a == -1 || y_b == -1) {
y_a = y;
y_b = y;
if(y_a > 1 && isLineMode7(y_a)) y_a--;
if(y_b < 239 && isLineMode7(y_b)) y_b++;
}
#undef isLineMode7

float a_a;
float b_a;
float c_a;
float d_a;
y_a--;
do {
y_a++;
Line line_a = ppufast.lines[y_a];
a_a = (int16)line_a.io.mode7.a;
b_a = (int16)line_a.io.mode7.b;
c_a = (int16)line_a.io.mode7.c;
d_a = (int16)line_a.io.mode7.d;
} while(ppufast.hdPerspective() && y_a < y
&& b_a == 0 && c_a == 0
&& b_a != (int16)io.mode7.b && c_a != (int16)io.mode7.c);

float a_b;
float b_b;
float c_b;
float d_b;
y_b++;
do {
y_b--;
Line line_b = ppufast.lines[y_b];
a_b = (int16)line_b.io.mode7.a;
b_b = (int16)line_b.io.mode7.b;
c_b = (int16)line_b.io.mode7.c;
d_b = (int16)line_b.io.mode7.d;
} while(ppufast.hdPerspective() && y_b > y
&& b_b == 0 && c_b == 0
&& b_b != (int16)io.mode7.b && c_a != (int16)io.mode7.b);
Line line_a = ppufast.lines[y_a];
float a_a = (int16)line_a.io.mode7.a;
float b_a = (int16)line_a.io.mode7.b;
float c_a = (int16)line_a.io.mode7.c;
float d_a = (int16)line_a.io.mode7.d;

Line line_b = ppufast.lines[y_b];
float a_b = (int16)line_b.io.mode7.a;
float b_b = (int16)line_b.io.mode7.b;
float c_b = (int16)line_b.io.mode7.c;
float d_b = (int16)line_b.io.mode7.d;

int hcenter = (int13)io.mode7.x;
int vcenter = (int13)io.mode7.y;
Expand Down Expand Up @@ -86,11 +77,8 @@ auto PPUfast::Line::renderMode7HD(PPUfast::IO::Background& self, uint source) ->
int pixelXp = INT_MIN;
for(int x : range(256+2*ppufast.widescreen())) {
x -= ppufast.widescreen();
int wx = x;
if (wx < 0) wx = 0;
if (wx > 255) wx = 255;
bool doAbove = self.aboveEnable && !windowAbove[wx];
bool doBelow = self.belowEnable && !windowBelow[wx];
bool doAbove = self.aboveEnable && !windowAbove[ppufast.winXad(x, false)];
bool doBelow = self.belowEnable && !windowBelow[ppufast.winXad(x, true)];

for(int xs : range(scale)) {
float xf = x + xs * 1.0 / scale - 0.5;
Expand All @@ -99,9 +87,7 @@ auto PPUfast::Line::renderMode7HD(PPUfast::IO::Background& self, uint source) ->
int pixelX = (originX + a * xf) / 256;
int pixelY = (originY + c * xf) / 256;

above++;
below++;

bool skip = false;
//only compute color again when coordinates have changed
if(pixelX != pixelXp || pixelY != pixelYp) {
uint tile = io.mode7.repeat == 3 && ((pixelX | pixelY) & ~1023) ? 0 : ppufast.vram[(pixelY >> 3 & 127) * 128 + (pixelX >> 3 & 127)].byte(0);
Expand All @@ -114,50 +100,49 @@ auto PPUfast::Line::renderMode7HD(PPUfast::IO::Background& self, uint source) ->
priority = self.priority[palette >> 7];
palette &= 0x7f;
}
if(!palette) continue;

uint color;
if(io.col.directColor && !extbg) {
color = directColor(0, palette);
} else {
color = cgram[palette];
skip = !palette;

if(!skip) {
uint color;
if(io.col.directColor && !extbg) {
color = directColor(0, palette);
} else {
color = cgram[palette];
}

pixel = {source, priority, color};
pixelXp = pixelX;
pixelYp = pixelY;
}

pixel = {source, priority, color};
pixelXp = pixelX;
pixelYp = pixelY;
}

if(doAbove && (!extbg || pixel.priority > above->priority)) *above = pixel;
if(doBelow && (!extbg || pixel.priority > below->priority)) *below = pixel;
}
}
}

if(ppufast.ss()) {
uint divisor = scale * scale;
for(uint p : range(256)) {
uint ab = 0, bb = 0;
uint ag = 0, bg = 0;
uint ar = 0, br = 0;
for(uint y : range(scale)) {
auto above = &this->above[p * scale];
auto below = &this->below[p * scale];
for(uint x : range(scale)) {
uint a = above[x].color;
uint b = below[x].color;
ab += a >> 0 & 31;
ag += a >> 5 & 31;
ar += a >> 10 & 31;
bb += b >> 0 & 31;
bg += b >> 5 & 31;
br += b >> 10 & 31;
if(sampScale == 1) {
if(!skip && doAbove && (!extbg || pixel.priority > above->priority)) *above = pixel;
if(!skip && doBelow && (!extbg || pixel.priority > below->priority)) *below = pixel;
above++;
below++;
} else {
int p = ((((x+ppufast.widescreen())*(scale/sampScale)) + (xs/sampScale))) * 4;
sampTmp[p] += pixel.priority;
sampTmp[p+1] += (pixel.color >> 10) & 31;
sampTmp[p+2] += (pixel.color >> 5) & 31;
sampTmp[p+3] += (pixel.color >> 0) & 31;
if((ys+1) % sampScale == 0 && (xs+1) % sampScale == 0) {
uint priority = sampTmp[p] / sampScale / sampScale;
uint color = ((sampTmp[p+1] / sampScale / sampScale) << 10)
+ ((sampTmp[p+2] / sampScale / sampScale) << 5)
+ ((sampTmp[p+3] / sampScale / sampScale) << 0);
if(!skip && doAbove && (!extbg || priority > above->priority)) *above = {source, priority, color};
if(!skip && doBelow && (!extbg || priority > below->priority)) *below = {source, priority, color};
above++;
below++;
sampTmp[p] = 0;
sampTmp[p+1] = 0;
sampTmp[p+2] = 0;
sampTmp[p+3] = 0;
}
}
}
uint aboveColor = ab / divisor << 0 | ag / divisor << 5 | ar / divisor << 10;
uint belowColor = bb / divisor << 0 | bg / divisor << 5 | br / divisor << 10;
this->above[p] = {source, this->above[p * scale].priority, aboveColor};
this->below[p] = {source, this->below[p * scale].priority, belowColor};
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions bsnes/sfc/ppu-fast/object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ auto PPUfast::Line::renderObject(PPUfast::IO::Object& self) -> void {
}

if(!ppufast.wsobj()
&& object.x > 256 && object.x + item.width - 1 < 512) continue; //!! //#config
&& object.x > 256 && object.x + item.width - 1 < 512) continue;
uint height = item.height >> self.interlace;
if((y >= object.y && y < object.y + height)
|| (object.y + height >= 256 && y < (object.y + height & 255))
Expand Down Expand Up @@ -124,8 +124,8 @@ auto PPUfast::Line::renderObject(PPUfast::IO::Object& self) -> void {
int xc = x;//
if(xc > 384) xc -= 512; // 256+256/2
if(xc < wsl || xc >= wsr) continue;
if(self.aboveEnable && !windowAbove[x]) plotAbove(xc, source, priority[x], cgram[palette[x]]);//
if(self.belowEnable && !windowBelow[x]) plotBelow(xc, source, priority[x], cgram[palette[x]]);//
if(self.aboveEnable && !windowAbove[ppufast.winXad(x, false)]) plotAbove(xc, source, priority[x], cgram[palette[x]]);
if(self.belowEnable && !windowBelow[ppufast.winXad(x, true)]) plotBelow(xc, source, priority[x], cgram[palette[x]]);
}
}

Expand Down
Loading

0 comments on commit ee7b978

Please sign in to comment.