Fix refactoring regression and simplify dot PPU mode 7 code.

This commit is contained in:
byuu 2019-08-07 10:04:31 +09:00
parent 27b2d11839
commit 66ad62b79f
2 changed files with 14 additions and 45 deletions

View File

@ -183,7 +183,7 @@ auto PPU::readIO(uint addr, uint8 data) -> uint8 {
ppu2.mdr |= ppu2.version;
ppu2.mdr |= Region::PAL() << 4; //0 = NTSC, 1 = PAL
if(!(cpu.pio() & 0x80)) {
ppu2.mdr |= 1 << 6;;
ppu2.mdr |= 1 << 6;
} else {
ppu2.mdr |= latch.counters << 6;
latch.counters = 0;

View File

@ -15,8 +15,8 @@ auto PPU::Background::runMode7() -> void {
int c = (int16)ppu.io.m7c;
int d = (int16)ppu.io.m7d;
int cx = (int13)ppu.io.m7x;
int cy = (int13)ppu.io.m7y;
int hcenter = (int13)ppu.io.m7x;
int vcenter = (int13)ppu.io.m7y;
int hoffset = (int13)latch.hoffset;
int voffset = (int13)latch.voffset;
@ -32,52 +32,21 @@ auto PPU::Background::runMode7() -> void {
if(ppu.io.hflipMode7) x = 255 - x;
if(ppu.io.vflipMode7) y = 255 - y;
int psx = ((a * clip(hoffset - cx)) & ~63) + ((b * clip(voffset - cy)) & ~63) + ((b * y) & ~63) + (cx << 8);
int psy = ((c * clip(hoffset - cx)) & ~63) + ((d * clip(voffset - cy)) & ~63) + ((d * y) & ~63) + (cy << 8);
int originX = (a * clip(hoffset - hcenter) & ~63) + (b * clip(voffset - vcenter) & ~63) + (b * y & ~63) + (hcenter << 8);
int originY = (c * clip(hoffset - hcenter) & ~63) + (d * clip(voffset - vcenter) & ~63) + (d * y & ~63) + (vcenter << 8);
int px = psx + (a * x);
int py = psy + (c * x);
int pixelX = originX + a * x >> 8;
int pixelY = originY + c * x >> 8;
uint16 paletteAddress = (pixelY & 7) << 3 | (pixelX & 7);
//mask pseudo-FP bits
px >>= 8;
py >>= 8;
int tileX = pixelX >> 3;
int tileY = pixelY >> 3;
uint16 tileAddress = (tileY & 127) << 7 | (tileX & 127);
uint tile;
uint palette;
switch(ppu.io.repeatMode7) {
//screen repetition outside of screen area
case 0:
case 1:
px &= 1023;
py &= 1023;
tile = ppu.vram[(py >> 3) * 128 + (px >> 3)] >> 0;
palette = ppu.vram[(tile << 6) + ((py & 7) << 3) + (px & 7)] >> 8;
break;
bool outOfBounds = (pixelX | pixelY) & ~1023;
//palette color 0 outside of screen area
case 2:
if((px | py) & ~1023) {
palette = 0;
} else {
px &= 1023;
py &= 1023;
tile = ppu.vram[(py >> 3) * 128 + (px >> 3)] >> 0;
palette = ppu.vram[(tile << 6) + ((py & 7) << 3) + (px & 7)] >> 8;
}
break;
//character 0 repetition outside of screen area
case 3:
if((px | py) & ~1023) {
tile = 0;
} else {
px &= 1023;
py &= 1023;
tile = ppu.vram[(py >> 3) * 128 + (px >> 3)] >> 0;
}
palette = ppu.vram[(tile << 6) + ((py & 7) << 3) + (px & 7)] >> 8;
break;
}
uint8 tile = ppu.io.repeatMode7 == 3 & outOfBounds ? 0 : ppu.vram[tileAddress] >> 0;
uint8 palette = ppu.io.repeatMode7 == 2 && outOfBounds ? 0 : ppu.vram[tile << 6 | paletteAddress] >> 8;
uint priority;
if(id == ID::BG1) {