Reply 20 of 21, by superfury
In the end, I just created the lookup table manually, using a simple loop from index 0 to 256(VGA DAC entries) to create RGB entries using the rgbRGB format, then modifying the VGA precalcs(also used by the EGA) to ignore any values in the DAC table(that's usually filled by VGA DAC writes using the VGA DAC ports) to instead use the precalculated DAC entries below:
void VGA_setupEGAPalette(VGA_Type *VGA)
{
word index;
DACEntry entry;
byte r,g,b;
byte strengthtable[4] = {0x00,0xAA,0x55,0xFF};
VGA->registers->DACMaskRegister = 0x3F; //Set a DAC mask register to apply!
for (index=0;index<0x100;++index) //
{
b = strengthtable[(((index&0x08)>>2)|(index&1))];
g = strengthtable[((((index&0x10)>>2)|(index&2))>>1)];
r = strengthtable[((((index&0x20)>>2)|(index&4))>>2)];
VGA->precalcs.DAC[index] = RGB(r,g,b); //Calculate the color to use!
}
VGA_calcprecalcs(VGA,WHEREUPDATED_DACMASKREGISTER); //Update the entire DAC with our loaded DAC values!
}
VGA_calcprecalcs updates the active entries as needed:
1. It generates the VGA->precalcs.DAC when not emulating EGA(to apply VGA/SVGA+ DAC entries mentioned above to generate a 256-entry RGBA lookup table, written to VGA->precalcs.DAC).
2. It refreshes the active video entries by either normal color values(direct copy of VGA->precalcs.DAC) or b/w values(depending on the setting in the settings menu, to generate a lookup table containing the grayscale, greenscale or amberscale).
This resulting table is then used to render all EGA+ colors on the screen(e.g. all modes on EGA, VGA and SVGA graphics cards).
The EGA BIOS does seem to completely clear the Misc Output Register for some reason, which normally shouldn't happen anywhere? So the CPU emulation itself is going wrong somewhere?
Author of the UniPCemu emulator.
UniPCemu Git repository
UniPCemu for Android, Windows, PSP, Vita and Switch on itch.io