Skip to content

Commit

Permalink
accuracy PPU: fix incorrect rendering in hires mode (fixes #297)
Browse files Browse the repository at this point in the history
  • Loading branch information
devinacker committed Aug 29, 2021
1 parent ad4111a commit a58b23d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 30 deletions.
38 changes: 20 additions & 18 deletions bsnes/snes/ppu/background/background.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,34 +145,36 @@ void PPU::Background::run(bool screen) {

if(regs.mode == Mode::Mode7) return run_mode7();

uint8 palette = get_tile_color();
Pixel pixel;
pixel.priority = priority;
pixel.palette = get_tile_color();
if(pixel.palette) pixel.palette += palette_index;
pixel.tile = tile;

bool update_mosaic = !hires || screen == Screen::Sub;
if(x == 0) mosaic_hcounter = 1;
if((x == 0 && update_mosaic)
|| (x > 0 && update_mosaic && --mosaic_hcounter == 0)) {
mosaic_hcounter = regs.mosaic ? self.regs.mosaic_size : 1;
mosaic_priority = priority;
mosaic_palette = palette ? palette_index + palette : 0;
mosaic_tile = tile;
mosaic = pixel;
}
else if (regs.mosaic)
{
pixel = mosaic;
}

if(screen == Screen::Main) x++;
if(mosaic_palette == 0) return;
if(pixel.palette == 0) return;

if(regs.mode == Mode::Inactive) return;
if(!hires || screen == Screen::Main) {
if(regs.main_enable) {
output.main.priority = mosaic_priority;
output.main.palette = mosaic_palette;
output.main.tile = mosaic_tile;
}
if(regs.main_enable)
output.main = pixel;
}

if(!hires || screen == Screen::Sub) {
if(regs.sub_enable) {
output.sub.priority = mosaic_priority;
output.sub.palette = mosaic_palette;
output.sub.tile = mosaic_tile;
}
if(regs.sub_enable)
output.sub = pixel;
}
}

Expand Down Expand Up @@ -222,9 +224,9 @@ void PPU::Background::reset() {
mosaic_hcounter = 0;
mosaic_hoffset = 0;

mosaic_priority = 0;
mosaic_palette = 0;
mosaic_tile = 0;
mosaic.priority = 0;
mosaic.palette = 0;
mosaic.tile = 0;

tile_counter = 0;
tile = 0;
Expand Down
17 changes: 8 additions & 9 deletions bsnes/snes/ppu/background/background.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ class Background {
unsigned voffset;
} regs;

struct Pixel {
unsigned priority;
uint8 palette; //0 = none (transparent)
uint16 tile;
};

struct Output {
struct Pixel {
unsigned priority; //0 = none (transparent)
uint8 palette;
uint16 tile;
} main, sub;
Pixel main, sub;
} output;

struct {
Expand All @@ -39,10 +41,7 @@ class Background {

unsigned mosaic_hcounter;
unsigned mosaic_hoffset;

unsigned mosaic_priority;
uint8 mosaic_palette;
uint16 mosaic_tile;
Pixel mosaic;

unsigned tile_counter;
unsigned tile;
Expand Down
6 changes: 3 additions & 3 deletions bsnes/snes/ppu/serialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ void PPU::Background::serialize(serializer &s) {
s.integer(mosaic_hcounter);
s.integer(mosaic_hoffset);

s.integer(mosaic_priority);
s.integer(mosaic_palette);
s.integer(mosaic_tile);
s.integer(mosaic.priority);
s.integer(mosaic.palette);
s.integer(mosaic.tile);

s.integer(tile_counter);
s.integer(tile);
Expand Down

0 comments on commit a58b23d

Please sign in to comment.