Skip to content

Commit

Permalink
BIOS logo: Fix corrupted palette issues with MDA/Hercules/CGA/PCjr/Ta…
Browse files Browse the repository at this point in the history
…ndy after rebooting the VM
  • Loading branch information
joncampbell123 committed Dec 30, 2024
1 parent 34e64d8 commit 24e0d70
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
35 changes: 25 additions & 10 deletions src/hardware/vga_draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3451,6 +3451,8 @@ struct BIOSlogo_t {
unsigned int width = 0,height = 0;
unsigned char* palette = NULL; /* 256 colors (NOTE: Except for VGA and PC-98, not all 256 colors available!) */
VGA_Line_Handler DrawLine = NULL;
bool visible = false;
bool vsync_enable = false;

BIOSlogo_t() {
}
Expand All @@ -3462,6 +3464,8 @@ struct BIOSlogo_t {
bmp = NULL;
if (palette) delete[] palette;
palette = NULL;
visible = false;
vsync_enable = false;
}
void position(unsigned int new_x,unsigned int new_y) {
x = new_x;
Expand Down Expand Up @@ -3491,7 +3495,7 @@ static uint8_t *VGA_DrawLineBiosLogoOverlay(Bitu vidstart, Bitu line) {
* causing random garbage on the VGA graphics RAM. As usual, modifying through pointer "r" causes
* corruption. Modifying TempLine, which is basically the same exact memory "r" points to, does not. */

if (BIOSlogo.bmp != NULL && BIOSlogo.palette != NULL) {
if (BIOSlogo.bmp != NULL && BIOSlogo.palette != NULL && BIOSlogo.visible && BIOSlogo.vsync_enable) {
if (vga.draw.lines_done >= BIOSlogo.y && r >= TempLine && r < (TempLine+sizeof(TempLine))) {
const unsigned int rel = vga.draw.lines_done - BIOSlogo.y;
const unsigned int bofs = (unsigned int)(r - TempLine);
Expand Down Expand Up @@ -3523,22 +3527,30 @@ static uint8_t *VGA_DrawLineBiosLogoOverlay(Bitu vidstart, Bitu line) {
return r;
}

void BiosLogoHookVGADrawLine(void) {
if (VGA_DrawLine != VGA_DrawLineBiosLogoOverlay) {
BIOSlogo.DrawLine = VGA_DrawLine;
VGA_DrawLine = VGA_DrawLineBiosLogoOverlay;

if (vga.draw.bpp == 8) {
for (unsigned int i=0;i < 0x40;i++) {
RENDER_SetPal(0xC0+i,
void VGA_BIOSLogoUpdatePalette(void) {
if (vga.draw.bpp == 8) {
for (unsigned int i=0;i < 0x40;i++) {
RENDER_SetPal(0xC0+i,
BIOSlogo.palette[(i*3)+0],
BIOSlogo.palette[(i*3)+1],
BIOSlogo.palette[(i*3)+2]);
}
}
}
}

void BiosLogoHookVGADrawLine(void) {
if (VGA_DrawLine != VGA_DrawLineBiosLogoOverlay) {
BIOSlogo.DrawLine = VGA_DrawLine;
VGA_DrawLine = VGA_DrawLineBiosLogoOverlay;
VGA_BIOSLogoUpdatePalette();
}
}

void VGA_ShowBIOSLogo(void) {
VGA_BIOSLogoUpdatePalette();
BIOSlogo.visible = true;
}

bool VGA_InitBiosLogo(unsigned int w,unsigned int h,unsigned int x,unsigned int y) {
BIOSlogo.allocate(w,h);
BIOSlogo.position(x,y);
Expand All @@ -3558,6 +3570,7 @@ void VGA_WriteBiosLogoPalette(unsigned int start,unsigned int count,unsigned cha
BIOSlogo.palette[((i+start)*3)+1] = rgb[(i*3)+1];
BIOSlogo.palette[((i+start)*3)+2] = rgb[(i*3)+2];
}
if (BIOSlogo.visible) VGA_BIOSLogoUpdatePalette();
}
}

Expand Down Expand Up @@ -5799,6 +5812,8 @@ static void VGA_VerticalTimer(Bitu /*val*/) {
}
#endif

if (BIOSlogo.visible) BIOSlogo.vsync_enable = true;

dbg_event_maxscan = false;
dbg_event_scanstep = false;
dbg_event_hretrace = false;
Expand Down
2 changes: 2 additions & 0 deletions src/ints/bios.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ bool VGA_InitBiosLogo(unsigned int w,unsigned int h,unsigned int x,unsigned int
void VGA_WriteBiosLogoBMP(unsigned int y,unsigned char *scanline,unsigned int w);
void VGA_WriteBiosLogoPalette(unsigned int start,unsigned int count,unsigned char *rgb);
void VGA_FreeBiosLogo(void);
void VGA_ShowBIOSLogo(void);

extern bool ega200;

Expand Down Expand Up @@ -11007,6 +11008,7 @@ class BIOS:public Module_base{
png_read_rows(png_context,rows,NULL,1);
VGA_WriteBiosLogoBMP(y,row,png_width);
}
VGA_ShowBIOSLogo();
}

delete[] row;
Expand Down

0 comments on commit 24e0d70

Please sign in to comment.