*******************************************************************************
WARNING: SOME (A LOT?) OF THESE COULD BE VERY INACCURATE!! YOU'VE BEEN WARNED!!
*******************************************************************************

Values of CRTC registers in graphics mode D:

Horiz Total (00): 37
Hrz Disp End (01): 27
Strt Hrz Blk (02): 2D (28??)
End Hrz Blk (03): 37, practically... 37? (9A??? -> consider only 1A for the blanking itself)
Strt Hrz Retr (04): 30, practically 34? (2B???)
End Hrz Retr (05): 14 (8A???)
Vert Total (06): 04
Overflow (07): 11
Preset Row SC (08): 00
Max Scan Line (09): 00 (40???)
Cursor Start (0A): 00
Cursor End (0B): 00
Strt Addr Hi (0C): -
Strt Addr Lo (0D): -
Cursor LC Hi (0E): -
Cursor LC Low (0F): -
Vrt Retr Strt (10): E1 (E0???)
Light Pen Hi (10): -
Vert Retr End (11): 24 (82???)
Light Pen Low (11): -
Vrt Disp End (12): C7
Offset (13): 14 (18 manually set in some code...)
Underline Loc (14): 00
Strt Vert Blk (15): E0 (DF???)
End Vert Blk (16): F0 (ED???)
Mode Control (17): E3
Line Compare (18): FF

Meanings:

* By register 00, the total number of characters in the horizontal scan
interval (including the retrace) is (in hex) 37+02=39.
* Reg 01: The total number of displayed characters per horizontal line is
27+1=28 or 40d. So a total of 320d pixels per line.
* Reg 02: Start Horizontal Blanking. 2D is the value of the character counter
when the horizontal blanking signal becomes active.
* Reg 03: The 5 least significant bits of this register are the 5 least
significant bits of the character counter value when the signal becomes
inactive. If the width of the blanking signal is W, then by adding W to the
value of reg 02 and taking the 5 significant bits, we obtain most of the
the relevant bits for this register.
As for the 3 most significant bits, the 7th is not used, while bits 5-6 are
use for skew control. A value of 1 is set for these (one character clock skew).
Back to the end of the blanking, bits 0-4 give out a value of 17.
At least on the VGA, The 5th bit of the actual value is actually the 7th bit of register 5
(End Horizontal Retrace), so the actual value is, still, 17.
Anyway, since we begin at 2D, the end really comes at 37.
* Reg 04: Used to center the screen horizontally. In the case of mode D
specifies that 30 is the character count value where the Horizontal Retrace
Pulse signal becomes active.
* Reg 05: The 5 least significant bits of the register are the 5 least
significant bits of the value of the character counter where the Horizontal
Retrace signal becomes inactive. In that case, the value is 14.
Since the 3 most significant bits are turned off, their roles might not have
any "interesting" effect.
More details: Bits 5-6 determine a skew of the horizontal retrace signal. Set
to 0 for mode D. Bit 7 is used in conjuction with horizontal panning
applications, determining if the initial memory address output after a
horizontal retrace is even or odd. Initially set to 0, or even.
Back to the end of the retrace signal: Based on the initial value of 30,
the end actually comes at 34.
* Reg 06: Vertical Total Register. The lower 8-bits of the number of horizontal
scans (including vertical retrace). So it is 4+100*<overflow bit> = 104.
* Reg 07: Overflow register.
* Reg 08: Used for pel scrolling. Initially set to 0.

* Reg 10: Low 8 bits of the vertical retrace pulse start (when the signal
becomes active), measured in horizontal scan lines. They consist of the value
E1. By adding the zero bit from the overflow register we obtain E1 again.
* Reg 11: Low 4 bits determine retrace pulse end (i.e. when the signal becomes
inactive), again measured by scanlines. The reg value is 24, so 4 for the
pulse end. The 20 portion may state something about vertical interrupt,
although it isn't perfectly clear according to the doc...
Back to the pulse end, from start value of E1 and end of value of 4 we obtain
the practical end value of E4.
* Reg 12: Low 8 bits of a value determining the scan line that ends the active
video area of the screen. The value is C7, and with the addition of a zero bit
from the overflow register it is still C7. By adding 1 we obtain C8=200h lines.
* Reg 13: Used to determine the actual scanline length used in video memory.
i.e. if we want 384d pixels per row in RAM (even though only 320d are screen),
we use... 384d/(8*2)=24h=18. The reason for division by 2 is measurement by
words (although on some cases it can be dwords).

* Reg 15: Low 8 bits of the vertical blanking start (or horizontal scan line
count). The value is E0, with/without the overflow bit.
* Reg 16: The low 5 bits represent the horizontal scan count value when the
vertical blanking output becomes inactive. The value set here is F0, but the 3
most significant bits are (supposedly) ignored. So it is really 10. Based on
the start value of E0, it is actually... F0.

* Reg 17: Value is E3= 11100011b.

SO TO SUMMARIZE:

* The Display Enable signal is skewed by 1 character.
* The total no. of characters in a scan line is 39, the first 28 of them are
displayed (ending at 27), horizontal blanking begins at 2D and ends at 37,
and horizontal retrace begins at 30 and ends at 34.
* The total no. of horizontal scan lines is 104. The retrace start is E1 and its
end is E4. There are C8 lines of active display area (so this ends at C7).
Vertical blanking starts at E0 and ends at F0.

Back to the horizontal one but with the skewing applied:
* No signal at 0, display during [1,29) (including 28!), blanking during
[2D,37) and retrace during [30,34). All chars in a scanline: [0,39).
So back porch = (1-37) mod 39 = 3 and front porch = 2D - 29 = 4 chars.

And vertically:
* Display during [0,C8), retrace during [E1,E4) and blanking during [E0,F0).
Back porch = 104-F0 = 14 and front porch = E1-C8 = 19 LINES.
