From 198187748729536df5486dc62db434f8b84e2d12 Mon Sep 17 00:00:00 2001 From: alyosha-tas Date: Sun, 27 Jan 2019 17:18:16 -0600 Subject: [PATCH] NESHawk: Remove GOTOs --- .../Consoles/Nintendo/NES/Boards/ExROM.cs | 6 ++- .../Consoles/Nintendo/NES/PPU.cs | 39 ++++++++++++++----- 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Boards/ExROM.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Boards/ExROM.cs index ce0e72510f..b1a561e271 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Boards/ExROM.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Boards/ExROM.cs @@ -255,7 +255,10 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES // top 2 bits of address come from chr_reg_high bank_1k += chr_reg_high << 8; ofs = addr & (4 * 1024 - 1); - goto MAPPED; + + bank_1k &= chr_bank_mask_1k; + addr = (bank_1k << 10) | ofs; + return addr; } if (NES.ppu.reg_2000.obj_size_16) @@ -278,7 +281,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES bank_1k = a_banks_1k[bank_1k]; } - MAPPED: bank_1k &= chr_bank_mask_1k; addr = (bank_1k<<10)|ofs; return addr; diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/PPU.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/PPU.cs index b04744f5f8..c3341b15ab 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/PPU.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/PPU.cs @@ -105,6 +105,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES int sum = 0; int ymin = Math.Max(Math.Max(y - radius, ppur.status.sl - 20), 0); + if (ymin > 239) { ymin = 239; } int ymax = Math.Min(y + radius, 239); int xmin = Math.Max(x - radius, 0); int xmax = Math.Min(x + radius, 255); @@ -112,21 +113,39 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES int ystop = ppur.status.sl - 2; int xstop = ppur.status.cycle - 20; - for (int j = ymin; j <= ymax; j++) + bool all_stop = false; + + int j = ymin; + int i = xmin; + short s = 0; + short palcolor = 0; + short intensity = 0; + + if (j >= ystop && i >= xstop || j > ystop) { all_stop = true; } + + while (!all_stop) { - for (int i = xmin; i <= xmax; i++) + s = xbuf[j * 256 + i]; + palcolor = (short)(s & 0x3F); + intensity = (short)((s >> 6) & 0x7); + + sum += _currentLuma[palcolor]; + + i++; + if (i > xmax) { - if (j >= ystop && i >= xstop || j > ystop) - goto loopout; + i = xmin; + j++; - short s = xbuf[j * 256 + i]; - - short palcolor = (short)(s & 0x3F); - short intensity = (short)((s >> 6) & 0x7); - sum += _currentLuma[palcolor]; + if (j > ymax) + { + all_stop = true; + } } + + if (j >= ystop && i >= xstop || j > ystop) { all_stop = true; } } - loopout: + return sum >= 2000; }