Do Blargg's test roms write to LCDC outside V-Blank period?

Discussion of programming and development for the original Game Boy and Game Boy Color.
Post Reply
Donqustix
Posts: 9
Joined: Fri Jul 21, 2017 2:29 am

Do Blargg's test roms write to LCDC outside V-Blank period?

Post by Donqustix »

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.
nitro2k01
Posts: 252
Joined: Sat Aug 28, 2010 9:01 am

Re: Do Blargg's test roms write to LCDC outside V-Blank peri

Post by nitro2k01 »

You can write to LCDC outside VBlank, just as long as you don't turn off the LCD (bit 7 set to 0).
Donqustix
Posts: 9
Joined: Fri Jul 21, 2017 2:29 am

Re: Do Blargg's test roms write to LCDC outside V-Blank peri

Post by Donqustix »

Thank you for reply.

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;
    }
}
I rewrote the code as follows:

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;
}
Post Reply