Hello, I'm writing a Gameboy emulator and I ran into problems.
Some time, each test rom (from cpu_instrs) that my emulator executes, writes to LCDC not during V-Blank period, which is bad.
Are there knowledgeable people who can help me, is this problem of my emulator or not?
UPDATE:
I just have understood how dumb this question is. Sorry for wasting your time, my problem is solved.
Do Blargg's test roms write to LCDC outside V-Blank period?
Re: Do Blargg's test roms write to LCDC outside V-Blank peri
You can write to LCDC outside VBlank, just as long as you don't turn off the LCD (bit 7 set to 0).
Re: Do Blargg's test roms write to LCDC outside V-Blank peri
Thank you for reply.
Yes, I see. The problem was my emulator didn't correctly handle writing to LCDC.
That was incorrect code:
I rewrote the code as follows:
Yes, I see. The problem was my emulator didn't correctly handle writing to LCDC.
That was incorrect code:
Code: Select all
void GPU::write_lcd_control(unsigned value) noexcept
{
control = value;
if (control & CONTROL_MASK_LCD_DISPLAY_ENABLE) {
stat = (stat & ~STAT_MASK_MODE_FLAG) | STAT_MODE_READ_OAM; mode_clock = 0;
}
else {
stat &= ~(STAT_MASK_MODE_FLAG | STAT_MASK_COINCIDENCE_FLAG); ly = 0;
}
}
Code: Select all
void GPU::write_lcd_control(unsigned value) noexcept
{
if ((control ^ value) & CONTROL_MASK_LCD_DISPLAY_ENABLE)
{
if (value & CONTROL_MASK_LCD_DISPLAY_ENABLE) {
stat = (stat & ~STAT_MASK_MODE_FLAG) | STAT_MODE_READ_OAM; mode_clock = 0;
} else {
stat &= ~(STAT_MASK_MODE_FLAG | STAT_MASK_COINCIDENCE_FLAG); ly = 0;
}
}
control = value;
}