Skip to content

Commit

Permalink
peanut: white frame after LCD enable
Browse files Browse the repository at this point in the history
This is a partial fix for issue #33, whereby the Game Boy LCD must
display a white screen for one frame after the LCD is enabled. This
stops garbled graphics being displayed by some games when the LCD is
enabled.

This is only a "partial" fix because Peanut-GB will simply not update
the LCD when the LCD has been enabled by the game. This means that
instead of showing a white screen, it is possible that the last
previously rendered frame will remain on the screen. This is not
accurate.

Signed-off-by: Mahyar Koshkouei <[email protected]>
  • Loading branch information
deltabeard committed Jan 1, 2022
1 parent 0233165 commit 3b97f6e
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion peanut_gb.h
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ struct gb_s
# define LCD_SEARCH_OAM 2
# define LCD_TRANSFER 3
unsigned lcd_mode : 2;
unsigned lcd_blank : 1;
};

/* Cartridge information:
Expand Down Expand Up @@ -901,6 +902,13 @@ void __gb_write(struct gb_s *gb, const uint_fast16_t addr, const uint8_t val)

/* LCD Registers */
case 0x40:
if(((gb->gb_reg.LCDC & LCDC_ENABLE) == 0) &&
(val & LCDC_ENABLE))
{
gb->counter.lcd_count = 0;
gb->lcd_blank = 1;
}

gb->gb_reg.LCDC = val;

/* LY fixed to 0 when LCD turned off. */
Expand Down Expand Up @@ -3457,6 +3465,7 @@ void __gb_step_cpu(struct gb_s *gb)
gb->lcd_mode = LCD_VBLANK;
gb->gb_frame = 1;
gb->gb_reg.IF |= VBLANK_INTR;
gb->lcd_blank = 0;

if(gb->gb_reg.STAT & STAT_MODE_1_INTR)
gb->gb_reg.IF |= LCDC_INTR;
Expand Down Expand Up @@ -3515,7 +3524,8 @@ void __gb_step_cpu(struct gb_s *gb)
{
gb->lcd_mode = LCD_TRANSFER;
#if ENABLE_LCD
__gb_draw_line(gb);
if(!gb->lcd_blank)
__gb_draw_line(gb);
#endif
}
}
Expand Down Expand Up @@ -3706,6 +3716,7 @@ enum gb_init_error_e gb_init(struct gb_s *gb,
gb->num_rom_banks_mask = num_rom_banks_mask[gb->gb_rom_read(gb, bank_count_location)] - 1;
gb->num_ram_banks = num_ram_banks[gb->gb_rom_read(gb, ram_size_location)];

gb->lcd_blank = 0;
gb->display.lcd_draw_line = NULL;

gb_reset(gb);
Expand Down

0 comments on commit 3b97f6e

Please sign in to comment.