nesdev.com
http://forums.nesdev.com/

Do Blargg's test roms write to LCDC outside V-Blank period?
http://forums.nesdev.com/viewtopic.php?f=20&t=16245
Page 1 of 1

Author:  Donqustix [ Sat Jul 22, 2017 12:07 pm ]
Post subject:  Do Blargg's test roms write to LCDC outside V-Blank period?

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.

Author:  nitro2k01 [ Sat Jul 22, 2017 8:13 pm ]
Post subject:  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).

Author:  Donqustix [ Sat Jul 22, 2017 10:19 pm ]
Post subject:  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:
Code:
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:
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;
}

Page 1 of 1 All times are UTC - 7 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/