nepx / halfix

x86 PC emulator that runs both natively and in the browser, via WebAssembly
https://nepx.github.io/halfix-demo/
GNU General Public License v3.0
669 stars 86 forks source link

Native build on osx has missing color channels? #18

Closed ikreymer closed 3 years ago

ikreymer commented 3 years ago

Ex: This happens for at least win2k and win98 when using a native build. The emscripten build has correct rendering with the same images. It seems like the initial blue channel background persists?

Screen Shot 2020-12-26 at 9 53 23 AM
nepx commented 3 years ago

I had a very similar issue when first booting XP in the browser. It turned out that the colors were being moved in the wrong location, and the fix was here. You can try doing #define EMSCRIPTEN at the top, and if that works, I'll add it as a workaround (unfortunately, I don't have a Mac). If that doesn't work, you might have to fiddle around with the positions in the DAC. I wonder if there's a way to determine pixel format at compile time...

The bug doesn't happen on Emscripten version since browsers have have standardized on ARGB for 32bpp displays, at least.

ikreymer commented 3 years ago

Thanks for the pointer on where to look!

Yes, I had to set the DAC to:

    vga.dac_palette[i] = 255 << 0 | c6to8(vga.dac[index | 0]) << 8 | c6to8(vga.dac[index | 1]) << 16 | c6to8(vga.dac[index | 2]) << 24;

The SDL PixelFormat had Ashift 0, Rshift 8, Gshift 16, Bshift 24, so I tried that and it worked..

Maybe there's way to use the pixel format settings?

nepx commented 3 years ago

I didn't like the idea of creating an #ifdef for each system, so I solved the root issue: instead of relying on SDL_SetVideoMode, I use SDL_CreateRGBSurfaceFrom and blit the pixels from there. Let me know if this works!

ikreymer commented 3 years ago

Yep, that fixes it on osx. Thanks!

nepx commented 3 years ago

That's good to hear! Thanks for the bug report.