joncampbell123 / dosbox-x

DOSBox-X fork of the DOSBox project
GNU General Public License v2.0
2.53k stars 369 forks source link

Where are these CRTC timings coming from? #5028

Closed MrMadguy64 closed 1 week ago

MrMadguy64 commented 3 weeks ago

Question

As always. I don't have access to real old hardware, so I can't check anything myself. And examining DOSBox's sources has made me think, that it's author is very competent and knows a lot about real hardware.

First of all. Can I use EGA/VGA environment table at 0040:00A8 to produce modified modes? Is it supported by all EGA/VGA hardware? Or it's better not to use it? Overall idea - is that sync pulse position doesn't really matter, because old monitors had picture size/position knobs anyway. Only thing, that matters - is that sync pulse position should match for all modes. And only way to make sure, that it happens - to use timings, provided by BIOS itself.

Main question: can I read somewhere, how DOSBox CRTC timings are calculated? Where are they coming from? What sources can I read to find this info? How picture is positioned via sync pulses? What parameters matter? Leading edge? Trailing edge? Or may be something else? Why half-clock timings are so weird and don't match full-clock ones?

For example VGA: VGA 640 mode VGA 320 mode

Problems: 1) Timings don't match standard VGA ones, because 16 pixel front porch is specified for them, and we see 40 here. 2) Timings don't match VESA GTF ones, because 8% sync pulse length (64 pixels) and trailing edge position being midway within blanking period (16 pixels front porch) are specified for them 3) I expected half-clock timings to be simply divided by 2. But they aren't. They aren't even specified in VGA standard, so I expect them to be exactly the same, as full-clock ones in terms of time. 4) Sync pulse end is weird. It overlaps with next active display period. Is it right?

But all of a sudden even real MODERN hardware uses these timings: Radeon 640 mode Radeon 320 mode NVidia 640 mode NVidia 320 mode, color isn't actually green

For EGA things are even weirder: EGA 640 mode EGA 320 mode

Timings don't match specified here IBM EGA. Why sync pulse overlaps with active period so much? Are they real? Please note, that EGA CRTC timings for mode 0x0D here are carried from original DOSBox 0.74 and don't look right. First of all horizontal total is +2 for EGA, not +5. Plus 8A for retrace end means it's 0A, i.e. either 0A, 2A or 4A. It's definitely mistake. Should be 3A, I guess, but therefore retrace end should be the same, as blanking end, i.e. 9A, not 8A.

Have you checked that no similar question(s) exist?

Code of Conduct & Contributing Guidelines

MrMadguy64 commented 1 week ago

While I still don't fully understand, why 320 timing differ from 640 ones (most probable reason - some internal signals are tied to sync pulses), at least now I see, that timings are standard and taken from real hardware.