DAC registers in SCREEN 9


The SCREEN 9 thing is for the simple reason that you actually have 64 colours but you can only show 16 at the same time. Don't ask me why (again), it's EGA: it's weird.

The same things applies to SCREEN 0 text modes. You have like, say, three layers:


Real DAC colours (R, G, B), 256K
================================
64 attributes
================================
16 colours


The 64 attributes are mapped into 16 colours using PALETTE. If you try, PALETTE a, b with a = 0 to 15 and b = 0 to 63 maps the attribute #b to the colour #a.

At the same time, each one of these attributes can be assigned any colours modifying the GFX card DAC registers. This is done with OUT.

That's why you have to put all these weird values. Originally (when you reset the GFX card calling SCREEN 9), the 64 attributes are combinations of two of these eight colours (y'know: 8 x 8 = 64): black, blue, green, cyan, red, magenta, yellow and white. These are ordered like this:

* black+black, black+blue, black+cyan, black+green, etc...
* blue+black, blue+blue, ...
* ...
* white+black, white+ blue, ..., white+white.

So you have them mapped like this:


Colour: 0 1 2 3 4 5 6 7
Attribute: 0 1 2 3 4 5 6 7

Colour: 8 9 10 11 12 13 14 15
Attribute:56 57 58 59 60 61 62 63


The only exception is that colour 6 is mapped to attribute 19, which results on a extremely ugly brown (19 = 8 * 2 + 3, that is, red + cyan !!).


You can use the next formula to de-screw the thing:


' First we remap to nice colours associations
FOR i%=0 TO 15
PALETTE i%,i%
NEXT i%

' Now we modify the DAC (this version
' reads from DATA's after 'DACDATA:'.

RESTORE dacData
FOR i%=0 TO 15
READ r%, g%, b%
OUT &H3C8, i%
OUT &H3C9, r%
OUT &H3C9, g%
OUT &H3C9, b%
NEXT i%

' 16 grayscale palette:
dacData:
DATA 0,0,0,4,4,4,8,8,8,12,12,12,16,16,16
DATA 20,20,20,24,24,24,28,28,28,32,32,32
DATA 36,36,36,40,40,40,44,44,44,48,48,48
DATA 52,52,52,56,56,56,63,63,63



na_th_an


DacRegistersInScreenNine - page last edited 2003-04-04 11:20:11 by 81.203.196.11 (home) (edit)
Blast WIKI - by RoboticBoy - edited and tweaked for our evil purposes by Hexadecimal Disaster