New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rework "EGA mode with VGA palette" CRT shader auto-switching #3354
Conversation
4dcd621
to
44816f3
Compare
crt-auto
EGA modes with VGA palettes auto-switching rework
c1cd7b7
to
ce139aa
Compare
crt-auto
EGA modes with VGA palettes auto-switching reworkce139aa
to
5eb23a6
Compare
f5acd15
to
d940c94
Compare
Ping @FeralChild64 @weirddan455 @kklobe, can any of you review this over the next week or so? I only need one person at least π Don't be afraid of it, it's short and only reviewing it at the surface-level is better than nothing. I don't expect anyone to become DOSBox VGA code experts overnight (I'm not one either π) The reasons I'm pinging you is because this needs to go into the final. |
d940c94
to
dea7c15
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two code modernisation hints. Approved anyhow, should you decide to ignore them.
dea7c15
to
ddb95e3
Compare
When setting up an EGA video mode on an emulated VGA card via the 10H BIOS interrupt, the following used to happen: 1. The 16 Palette Registers that store the indices into the first 64 Color Registers were set up first. The Color Registers store the actual 18-bit RGB values the VGA card outputs when emulating EGA modes (in other words, the 16 Color Registers hold indexes into the 256-element VGA DAC table, and only the first 64 DAC entries can be addressed). 2. As the second step, the 16 Color Registers were loaded with the correct "canonical" EGA RGB colours. The problem with this approach was that setting the Palette Registers also triggers reloading the Color Registers. This triggering is probably necessary and has something to do with murky details of how the actual VGA hardware workd. But the Color Registers don't necessarily contain the correct EGA colours when this triggering happens (they still have whatever DAC colours were set last). So this is what usually happened with the Color Registers when switching to an EGA mode: - 16 Color Register writes triggered by the Palette Register writes, often with the wrong non-EGA RGB values. - Then another 16 Color Register writes when the VGA hardware sets up the emulated EGA colours in the DAC entries, now with the correct RGB values. The problem with this approach was that it could often throw off the "EGA modes with VGA colours" detection logic that listens to Color Register writes after a mode change is initiated. The obvious fix is to swap steps 1 and 2 to ensure the 2 x 16 Color Register writes are all performed using the correct EGA RGB colours. The exact same set of 16 colours are expected to be set after this swap. This seems to be a rather safe change, and it's unlikely that it would cause any side effects. Especially because all this setup stuff happens in the scope of a BIOS interrupt, so nothing else should be able to muck around with the VGA registers in the meantime.
All text modes get classified as GraphicsStandard::Vga on an emulated VGA adapter, which can trip this assert under some circumstances.
c1e4d91
to
10e38c8
Compare
OK, I ran through the manual testing steps to compare against |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
approved even sans-const
π
The previous method only worked by fluke in text mode to EGA mode transitions.
10e38c8
to
9645b4c
Compare
Thanks @kklobe . Just force-pushed that minor change into the last commit. |
Description
The auto-switching to VGA shaders for EGA modes with custom VGA palettes on emulated VGA adapters worked when launching games, but kinda by fluke. It was only reliable on text mode to EGA graphics mode transitions, but only by sheer luck... Things then started falling apart when using an image viewer such as QPV.
Definitely review commit by commit; the first commit is just about removing warnings and is very noisy.
It's a bit hard to explain succinctly why the implementation needs to be done in this particular way. I've spent about 5-6 hours just tracing through the code to figure out how the Rube Goldberg mode-switching machinery works... I understand it now, but I don't want to write 10 pages to explain which no one would bother to read anyway... π Please read the comments and the commit messages if you want to understand it deeper what's really going on.
The high-level overview is that I tried to be a bit too clever previously when detecting non-EGA colours; now it just checks the new colour against all possible EGA colours whenever the program changes a VGA DAC palette entry.
I don't really expect anybody to go through my manual testing steps in detail, but it forces me to do a thorough job, and it will be useful for regression testing later if needed.
Could this all be done in a simpler and more straightforward way? Sure. After spending 5k+ hours refactoring the whole VGA code, everything VGA-related should be simpler. See you in 2050 π π€π»
Related issues
Original PR:
crt-auto should auto-switch to VGA shaders in EGA modes with 18-bit VGA palettes
#2819
Manual testing
General testing
Used the following specially prepared test pics in QPV: test-pics.zip
Grafx2 is great for such manipulations of paletted/bitplane-based graphics.
MONKEY1.IFF
320x200, 16-colour, EGA palette in canonical EGA colour order.
MONKEY2.IFF
320x200, 16-colour, EGA palette, but with bright cyan missing.
SQ3.IFF
320x200, 16-colour, EGA palette, but with brown missing and a completely different colour ordering.
MAGICWLD.IFF
320x200, 16-colour, non-EGA palette.
SCOOPEX.IFF
320x200, 16-colour, non-EGA palette.
Make sure QPV is configured for EGA modes. You should have something like this in
QPV.CFG
:Turn off auto resolution (
#
key) and select the 320x200 16-colour mode (with the+
and-
keys).Test 1
With the default config:
MONKEY1.IFF
β EGA shader gets picked.MONKEY2.IFF
β EGA shader gets picked.SQ3.IFF
β EGA shader gets picked.MAGICWLD.IFF
β VGA shader gets picked.SCOOPEX.IFF
β VGA shader gets picked.Test 2
With the default config:
MONKEY1.IFF
β EGA shader gets pickedMONKEY2.IFF
β This involves no scree mode change, but as the image still contains EGA colours only, the EGA shader remains active.SCOOPEX.IFF
β This contains VGA colours, so the VGA shader gets selected.SQ3.IFF
β This has EGA colours, but no screen mode change is involved, so we're stuck with the VGA shader.SQ3.IFF
but trigger a screen mode change β EGA shader gets picked.Test 3
Repeated the above tests with different
glshader
andmachine
settings:glshader = none
&sharp
β Works as expected.glshader = crt-auto-arcade
&crt-auto-arcade-sharp
β The single-scanned arcade shaders get always picked.glshader = crt-auto-machine
&machine = vga
β Always the VGA shader gets picked.Test 4
Test 4
Tried a few games with the default config plus
cga_color = colodore
:Test 5
Regression tested Total Eclipse in Hercules, CGA, CGA Mono, and Tandy modes with the appropriate machine settings.
"True EGA"
Confirmed that the below "true EGA" games pick the EGA shader with
crt-auto
on a VGA adapter:EGA modes with VGA palette
Confirmed that the below games that use EGA modes with custom VGA palettes pick the VGA shader with
crt-auto
:Checklist
Please tick the items as you have addressed them. Don't remove items; leave the ones that are not applicable unchecked.
I have: