Emulate ICD desyncing

This commit is contained in:
Lior Halphon 2019-07-18 23:08:16 +03:00
parent 0623d6ac2b
commit 10038ec76d
5 changed files with 27 additions and 23 deletions

View File

@ -424,7 +424,6 @@ static void render_pixel_if_possible(GB_gameboy_t *gb)
} }
} }
/* byuu: gotta do this later so it's only done once ... you'll probably wanna refactor this somehow :/ */
if (gb->model & GB_MODEL_NO_SFC_BIT) { if (gb->model & GB_MODEL_NO_SFC_BIT) {
if (gb->icd_pixel_callback) { if (gb->icd_pixel_callback) {
gb->icd_pixel_callback(gb, icd_pixel); gb->icd_pixel_callback(gb, icd_pixel);
@ -770,7 +769,13 @@ void GB_display_run(GB_gameboy_t *gb, uint8_t cycles)
fifo_push_bg_row(&gb->bg_fifo, 0, 0, 0, false, false); fifo_push_bg_row(&gb->bg_fifo, 0, 0, 0, false, false);
/* Todo: find out actual access time of SCX */ /* Todo: find out actual access time of SCX */
gb->position_in_line = - (gb->io_registers[GB_IO_SCX] & 7) - 8; gb->position_in_line = - (gb->io_registers[GB_IO_SCX] & 7) - 8;
gb->current_lcd_line++; // Todo: unverified timing
// Todo: unverified timing
gb->current_lcd_line++;
if (gb->icd_hreset_callback) {
gb->icd_hreset_callback(gb);
}
if (gb->current_lcd_line == LINES && GB_is_sgb(gb)) { if (gb->current_lcd_line == LINES && GB_is_sgb(gb)) {
display_vblank(gb); display_vblank(gb);
} }
@ -910,11 +915,6 @@ void GB_display_run(GB_gameboy_t *gb, uint8_t cycles)
} }
GB_SLEEP(gb, display, 11, LINE_LENGTH - gb->cycles_for_line); GB_SLEEP(gb, display, 11, LINE_LENGTH - gb->cycles_for_line);
gb->mode_for_interrupt = 2; gb->mode_for_interrupt = 2;
/* TODO: Can this timing even be verified? */
if (gb->icd_hreset_callback) {
gb->icd_hreset_callback(gb);
}
} }
/* Lines 144 - 152 */ /* Lines 144 - 152 */

View File

@ -16,7 +16,6 @@ namespace SameBoy {
static auto vreset(GB_gameboy_t*) -> void { static auto vreset(GB_gameboy_t*) -> void {
icd.ly = 0; icd.ly = 0;
icd.ppuScanline();
} }
static auto icd_pixel(GB_gameboy_t*, uint8_t pixel) -> void { static auto icd_pixel(GB_gameboy_t*, uint8_t pixel) -> void {
@ -122,7 +121,8 @@ auto ICD::power() -> void {
readBank = 0; readBank = 0;
readAddress = 0; readAddress = 0;
writeBank = 0; writeBank = 0;
writeAddress = 0; writeX = 0;
writeY = 0;
packetSize = 0; packetSize = 0;
joypID = 3; joypID = 3;
@ -148,7 +148,8 @@ auto ICD::reset() -> void {
readBank = 0; readBank = 0;
readAddress = 0; readAddress = 0;
writeBank = 0; writeBank = 0;
writeAddress = 0; writeX = 0;
writeY = 0;
packetSize = 0; packetSize = 0;
joypID = 3; joypID = 3;

View File

@ -61,7 +61,8 @@ private:
uint readBank; uint readBank;
uint readAddress; uint readAddress;
uint writeBank; uint writeBank;
uint writeAddress; uint writeX;
uint writeY;
struct Information { struct Information {
uint pathID = 0; uint pathID = 0;
@ -73,7 +74,7 @@ public:
//as the offsets of all member variables will be wrong compared to what the C SameBoy code expects. //as the offsets of all member variables will be wrong compared to what the C SameBoy code expects.
GB_gameboy_t sameboy; GB_gameboy_t sameboy;
uint32_t bitmap[160 * 144]; uint32_t bitmap[160 * 144];
uint ly = 0; uint8_t ly = 0;
}; };
extern ICD icd; extern ICD icd;

View File

@ -1,18 +1,19 @@
auto ICD::ppuScanline() -> void { auto ICD::ppuScanline() -> void {
if(ly > 143) return; //Vblank if(++writeY == 8) {
if((ly & 7) == 0) {
writeBank = (writeBank + 1) & 3; writeBank = (writeBank + 1) & 3;
writeAddress = 0; writeY = 0;
} }
writeX = 0;
} }
auto ICD::ppuOutput(uint2 color) -> void { auto ICD::ppuOutput(uint2 color) -> void {
uint y = writeAddress / 160; if(writeX >= 160) return; // Unverified behavior
uint x = writeAddress % 160; if(writeY >= 8) return; // Should never happen
uint addr = writeBank * 512 + y * 2 + x / 8 * 16;
uint addr = writeBank * 512 + writeY * 2 + writeX / 8 * 16;
output[addr + 0] = (output[addr + 0] << 1) | !!(color & 1); output[addr + 0] = (output[addr + 0] << 1) | !!(color & 1);
output[addr + 1] = (output[addr + 1] << 1) | !!(color & 2); output[addr + 1] = (output[addr + 1] << 1) | !!(color & 2);
writeAddress = (writeAddress + 1) % 1280; writeX++;
} }
auto ICD::apuOutput(float left, float right) -> void { auto ICD::apuOutput(float left, float right) -> void {

View File

@ -38,5 +38,6 @@ auto ICD::serialize(serializer& s) -> void {
s.integer(readBank); s.integer(readBank);
s.integer(readAddress); s.integer(readAddress);
s.integer(writeBank); s.integer(writeBank);
s.integer(writeAddress); s.integer(writeX);
s.integer(writeY);
} }