GBHawk: fix window latching, x-scroll only latching lower 3 bits, and MBC3 RTC reg behaviour.

This commit is contained in:
alyosha-tas 2020-10-01 20:09:26 -04:00
parent 7ebc3a3058
commit 38838fa3c1
4 changed files with 40 additions and 17 deletions

View File

@ -763,9 +763,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
// i.e. just keeping track of the lowest x-value sprite
if (render_cycle == 0)
{
// window X is latched for the scanline, mid-line changes have no effect
window_x_latch = window_x;
OAM_scan_index = 0;
read_case = 0;
internal_cycle = 0;
@ -1012,6 +1009,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
{
// calculate the row number of the tiles to be fetched
y_tile = (((int)scroll_y + LY) >> 3) % 32;
x_tile = scroll_x >> 3;
temp_fetch = y_tile * 32 + (x_tile + tile_inc) % 32;
tile_byte = Core.VRAM[0x1800 + (LCDC.Bit(3) ? 1 : 0) * 0x400 + temp_fetch];
@ -1103,8 +1101,10 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
// here we set up rendering
pre_render = false;
// x scroll is latched here
x_tile = scroll_x >> 3;
// window X is latched for the scanline, mid-line changes have no effect
window_x_latch = window_x;
// x scroll is latched here, only the lower 3 bits are latched though
render_offset = scroll_offset = scroll_x % 8;
render_counter = 0;

View File

@ -754,9 +754,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
// i.e. just keeping track of the lowest x-value sprite
if (render_cycle == 0)
{
// window X is latched for the scanline, mid-line changes have no effect
window_x_latch = window_x;
OAM_scan_index = 0;
read_case = 0;
internal_cycle = 0;
@ -966,6 +963,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
{
// calculate the row number of the tiles to be fetched
y_tile = (((int)scroll_y + LY) >> 3) % 32;
x_tile = scroll_x >> 3;
temp_fetch = y_tile * 32 + (x_tile + tile_inc) % 32;
tile_byte = Core.VRAM[0x1800 + (LCDC.Bit(3) ? 1 : 0) * 0x400 + temp_fetch];
@ -1058,8 +1056,10 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
// here we set up rendering
pre_render = false;
// calculate the column number of the tile to start with
x_tile = scroll_x >> 3;
// window X is latched for the scanline, mid-line changes have no effect
window_x_latch = window_x;
// x scroll is latched here, only the lower 3 bits are latched though
render_offset = scroll_offset = scroll_x % 8;
render_counter = 0;

View File

@ -445,9 +445,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
// i.e. just keeping track of the lowest x-value sprite
if (render_cycle == 0)
{
// window X is latched for the scanline, mid-line changes have no effect
window_x_latch = window_x;
OAM_scan_index = 0;
read_case = 0;
internal_cycle = 0;
@ -642,6 +639,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
{
// calculate the row number of the tiles to be fetched
y_tile = (((int)scroll_y + LY) >> 3) % 32;
x_tile = scroll_x >> 3;
temp_fetch = y_tile * 32 + (x_tile + tile_inc) % 32;
@ -720,8 +718,10 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
// here we set up rendering
pre_render = false;
// window X is latched for the scanline, mid-line changes have no effect
window_x_latch = window_x;
// x scroll is latched here
x_tile = scroll_x >> 3;
render_offset = scroll_offset = scroll_x % 8;
render_counter = 0;

View File

@ -1,5 +1,6 @@
using BizHawk.Common;
using BizHawk.Emulation.Cores.Components.LR35902;
using System;
namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
{
@ -210,6 +211,16 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
}
else if ((RAM_bank >= 8) && (RAM_bank <= 0xC))
{
// not all bits are writable
switch (RAM_bank - 8)
{
case 0: value &= 0x3F; break;
case 1: value &= 0x3F; break;
case 2: value &= 0x1F; break;
case 3: value &= 0xFF; break;
case 4: value &= 0xC1; break;
}
RTC_regs[RAM_bank - 8] = value;
if ((RAM_bank - 8) == 0) { RTC_low_clock = RTC_timer = 0; }
@ -256,15 +267,15 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
RTC_regs[0]++;
if (RTC_regs[0] > 59)
if (RTC_regs[0] == 60)
{
RTC_regs[0] = 0;
RTC_regs[1]++;
if (RTC_regs[1] > 59)
if (RTC_regs[1] == 60)
{
RTC_regs[1] = 0;
RTC_regs[2]++;
if (RTC_regs[2] > 23)
if (RTC_regs[2] == 24)
{
RTC_regs[2] = 0;
if (RTC_regs[3] < 0xFF)
@ -286,7 +297,19 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
}
}
}
else
{
RTC_regs[2] &= 0x1F;
}
}
else
{
RTC_regs[1] &= 0x3F;
}
}
else
{
RTC_regs[0] &= 0x3F;
}
}
}