It is currently Thu Dec 14, 2017 5:30 pm

All times are UTC - 7 hours





Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Sat Jul 22, 2017 12:07 pm 
Offline

Joined: Fri Jul 21, 2017 2:29 am
Posts: 8
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.

_________________
emugaboy - uncomplicated gameboy emulator
noexcept nes emulator


Top
 Profile  
 
PostPosted: Sat Jul 22, 2017 8:13 pm 
Offline

Joined: Sat Aug 28, 2010 9:01 am
Posts: 199
You can write to LCDC outside VBlank, just as long as you don't turn off the LCD (bit 7 set to 0).

_________________
Gameboy Genius (Blog) - Gameboy development forum (+wiki and file area)


Top
 Profile  
 
PostPosted: Sat Jul 22, 2017 10:19 pm 
Offline

Joined: Fri Jul 21, 2017 2:29 am
Posts: 8
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;
}

_________________
emugaboy - uncomplicated gameboy emulator
noexcept nes emulator


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group