Skip to content

Commit

Permalink
[ppu] oam: Respect per-scanline cycle budget (fixes #98)
Browse files Browse the repository at this point in the history
  • Loading branch information
fleroviux committed Jun 1, 2020
1 parent 233a886 commit 2398e39
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions source/emulator/core/hw/ppu/render/oam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ void PPU::RenderLayerOAM(bool bitmap_mode) {

line_contains_alpha_obj = false;

int cycles = 0;
int cycle_limit = mmio.dispcnt.hblank_oam_access ? 954 : 1210;

/* TODO: check if there is a faster way to initialize the array. */
for (int x = 0; x < 240; x++) {
buffer_obj[x].priority = 4;
Expand Down Expand Up @@ -102,6 +105,8 @@ void PPU::RenderLayerOAM(bool bitmap_mode) {
x += half_width;
y += half_height;

int cycles_per_pixel = 1;

/* Load transform matrix. */
if (affine) {
int group = ((attr1 >> 9) & 0x1F) << 5;
Expand All @@ -121,6 +126,8 @@ void PPU::RenderLayerOAM(bool bitmap_mode) {
half_width *= 2;
half_height *= 2;
}

cycles_per_pixel = 2;
} else {
/* Set transform to identity:
* [ 1 0 ]
Expand Down Expand Up @@ -162,11 +169,21 @@ void PPU::RenderLayerOAM(bool bitmap_mode) {
local_y -= mmio.mosaic.obj._counter_y;
}

if (affine) {
cycles += 10;
}

/* Render OBJ scanline. */
for (int local_x = -half_width; local_x <= half_width; local_x++) {
int _local_x = local_x - mosaic_x;
int global_x = local_x + x;

if (cycles > cycle_limit) {
return;
}

cycles += cycles_per_pixel;

if (mosaic && (++mosaic_x == mmio.mosaic.obj.size_x)) {
mosaic_x = 0;
}
Expand Down

0 comments on commit 2398e39

Please sign in to comment.