The upper bits of SCX might mid-line

This commit is contained in:
Lior Halphon 2020-02-21 21:59:03 +02:00
parent ea2f32b255
commit 39b88d546b
2 changed files with 6 additions and 2 deletions

View File

@ -581,18 +581,20 @@ static void advance_fetcher_state_machine(GB_gameboy_t *gb)
/* Todo: Verified for DMG (Tested: SGB2), CGB timing is wrong. */ /* Todo: Verified for DMG (Tested: SGB2), CGB timing is wrong. */
uint8_t y = fetcher_y(gb); uint8_t y = fetcher_y(gb);
uint8_t x = gb->in_window? gb->fetcher_x :
(((gb->io_registers[GB_IO_SCX] / 8) + (gb->position_in_line / 8) + 1) & 0x1F);
if (gb->model > GB_MODEL_CGB_C) { if (gb->model > GB_MODEL_CGB_C) {
/* This value is cached on the CGB-D and newer, so it cannot be used to mix tiles together */ /* This value is cached on the CGB-D and newer, so it cannot be used to mix tiles together */
gb->fetcher_y = y; gb->fetcher_y = y;
} }
gb->current_tile = gb->vram[map + gb->fetcher_x + y / 8 * 32]; gb->current_tile = gb->vram[map + x + y / 8 * 32];
if (gb->vram_ppu_blocked) { if (gb->vram_ppu_blocked) {
gb->current_tile = 0xFF; gb->current_tile = 0xFF;
} }
if (GB_is_cgb(gb)) { if (GB_is_cgb(gb)) {
/* The CGB actually accesses both the tile index AND the attributes in the same T-cycle. /* The CGB actually accesses both the tile index AND the attributes in the same T-cycle.
This probably means the CGB has a 16-bit data bus for the VRAM. */ This probably means the CGB has a 16-bit data bus for the VRAM. */
gb->current_tile_attributes = gb->vram[map + gb->fetcher_x + y / 8 * 32 + 0x2000]; gb->current_tile_attributes = gb->vram[map + x + y / 8 * 32 + 0x2000];
if (gb->vram_ppu_blocked) { if (gb->vram_ppu_blocked) {
gb->current_tile_attributes = 0xFF; gb->current_tile_attributes = 0xFF;
} }

View File

@ -266,6 +266,7 @@ int GB_load_state(GB_gameboy_t *gb, const char *path)
gb->oam_fifo.read_end &= 0xF; gb->oam_fifo.read_end &= 0xF;
gb->oam_fifo.write_end &= 0xF; gb->oam_fifo.write_end &= 0xF;
gb->object_low_line_address &= gb->vram_size & ~1; gb->object_low_line_address &= gb->vram_size & ~1;
gb->fetcher_x &= 0x1f;
if (gb->object_priority == GB_OBJECT_PRIORITY_UNDEFINED) { if (gb->object_priority == GB_OBJECT_PRIORITY_UNDEFINED) {
gb->object_priority = gb->cgb_mode? GB_OBJECT_PRIORITY_INDEX : GB_OBJECT_PRIORITY_X; gb->object_priority = gb->cgb_mode? GB_OBJECT_PRIORITY_INDEX : GB_OBJECT_PRIORITY_X;
@ -376,6 +377,7 @@ int GB_load_state_from_buffer(GB_gameboy_t *gb, const uint8_t *buffer, size_t le
gb->oam_fifo.read_end &= 0xF; gb->oam_fifo.read_end &= 0xF;
gb->oam_fifo.write_end &= 0xF; gb->oam_fifo.write_end &= 0xF;
gb->object_low_line_address &= gb->vram_size & ~1; gb->object_low_line_address &= gb->vram_size & ~1;
gb->fetcher_x &= 0x1f;
if (gb->object_priority == GB_OBJECT_PRIORITY_UNDEFINED) { if (gb->object_priority == GB_OBJECT_PRIORITY_UNDEFINED) {
gb->object_priority = gb->cgb_mode? GB_OBJECT_PRIORITY_INDEX : GB_OBJECT_PRIORITY_X; gb->object_priority = gb->cgb_mode? GB_OBJECT_PRIORITY_INDEX : GB_OBJECT_PRIORITY_X;