From 6fb626386b4e8e32258897b9bf293f7b698b29a6 Mon Sep 17 00:00:00 2001 From: alyosha-tas Date: Sat, 15 Dec 2018 13:05:01 -0600 Subject: [PATCH] GBHawk: Pass sprite tests --- .../Consoles/Nintendo/GBHawk/GBC_PPU.cs | 27 ++++++++++++------- .../Consoles/Nintendo/GBHawk/GB_PPU.cs | 18 ++++++++----- 2 files changed, 30 insertions(+), 15 deletions(-) diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBC_PPU.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBC_PPU.cs index e6de37117d..125bd266e5 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBC_PPU.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBC_PPU.cs @@ -661,6 +661,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk fetch_sprite = false; going_to_fetch = false; first_fetch = true; + consecutive_sprite = -render_offset + 8; no_sprites = false; evaled_sprites = 0; window_pre_render = false; @@ -1155,21 +1156,29 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk } } + // x scroll offsets the penalty table // there is no penalty if the next sprites to be fetched are within the currentfetch block (8 pixels) if (first_fetch || (last_eval >= consecutive_sprite)) { - if ((last_eval % 8) == 0) { sprite_fetch_counter += 5; } - else if ((last_eval % 8) == 1) { sprite_fetch_counter += 4; } - else if ((last_eval % 8) == 2) { sprite_fetch_counter += 3; } - else if ((last_eval % 8) == 3) { sprite_fetch_counter += 2; } - else if ((last_eval % 8) == 4) { sprite_fetch_counter += 1; } - else if ((last_eval % 8) == 5) { sprite_fetch_counter += 0; } - else if ((last_eval % 8) == 6) { sprite_fetch_counter += 0; } - else if ((last_eval % 8) == 7) { sprite_fetch_counter += 0; } + if (((last_eval + render_offset) % 8) == 0) { sprite_fetch_counter += 5; } + else if (((last_eval + render_offset) % 8) == 1) { sprite_fetch_counter += 4; } + else if (((last_eval + render_offset) % 8) == 2) { sprite_fetch_counter += 3; } + else if (((last_eval + render_offset) % 8) == 3) { sprite_fetch_counter += 2; } + else if (((last_eval + render_offset) % 8) == 4) { sprite_fetch_counter += 1; } + else if (((last_eval + render_offset) % 8) == 5) { sprite_fetch_counter += 0; } + else if (((last_eval + render_offset) % 8) == 6) { sprite_fetch_counter += 0; } + else if (((last_eval + render_offset) % 8) == 7) { sprite_fetch_counter += 0; } + + consecutive_sprite = (int)Math.Floor((double)(last_eval + render_offset) / 8) * 8 + 8 - render_offset; + + // special case exists here for sprites at zero with non-zero x-scroll. Not sure exactly the reason for it. + if (last_eval == 0 && render_offset != 0) + { + sprite_fetch_counter += render_offset; + } } total_counter += sprite_fetch_counter; - consecutive_sprite = last_eval + (8 - (last_eval % 8)); first_fetch = false; } diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GB_PPU.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GB_PPU.cs index 7b6a0ce9cc..d6cae63418 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GB_PPU.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GB_PPU.cs @@ -75,13 +75,13 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk //if (!STAT.Bit(6)) { LYC_INT = false; } if (!STAT.Bit(4)) { VBL_INT = false; } - break; + break; case 0xFF42: // SCY scroll_y = value; - break; + break; case 0xFF43: // SCX scroll_x = value; - break; + break; case 0xFF44: // LY LY = 0; /*reset*/ break; @@ -455,6 +455,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk fetch_sprite = false; going_to_fetch = false; first_fetch = true; + consecutive_sprite = -render_offset + 8; no_sprites = false; evaled_sprites = 0; window_pre_render = false; @@ -852,8 +853,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk tile_data_latch[0] = tile_data[0]; tile_data_latch[1] = tile_data[1]; } - - if (consecutive_sprite > 0) { consecutive_sprite -= 1; } } // every in range sprite takes 6 cycles to process @@ -892,10 +891,17 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk else if (((last_eval + render_offset) % 8) == 5) { sprite_fetch_counter += 0; } else if (((last_eval + render_offset) % 8) == 6) { sprite_fetch_counter += 0; } else if (((last_eval + render_offset) % 8) == 7) { sprite_fetch_counter += 0; } + + consecutive_sprite = (int)Math.Floor((double)(last_eval + render_offset) / 8) * 8 + 8 - render_offset; + + // special case exists here for sprites at zero with non-zero x-scroll. Not sure exactly the reason for it. + if (last_eval == 0 && render_offset != 0) + { + sprite_fetch_counter += render_offset; + } } total_counter += sprite_fetch_counter; - consecutive_sprite = last_eval + (8 - (last_eval % 8)); first_fetch = false; }