1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
|
/*
* Copyright 1997 through 2004 by Marc Aurele La France (TSI @ UQV), tsi@xfree86.org
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
* the above copyright notice appear in all copies and that both that copyright
* notice and this permission notice appear in supporting documentation, and
* that the name of Marc Aurele La France not be used in advertising or
* publicity pertaining to distribution of the software without specific,
* written prior permission. Marc Aurele La France makes no representations
* about the suitability of this software for any purpose. It is provided
* "as-is" without express or implied warranty.
*
* MARC AURELE LA FRANCE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO
* EVENT SHALL MARC AURELE LA FRANCE BE LIABLE FOR ANY SPECIAL, INDIRECT OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <string.h>
#include "ati.h"
#include "atidac.h"
#include "atimach64io.h"
/*
* RAMDAC-related definitions.
*/
const SymTabRec ATIDACDescriptors[] =
{ /* Keep this table in ascending DACType order */
{ATI_DAC_ATI68830, "ATI 68830 or similar"},
{ATI_DAC_SC11483, "Sierra 11483 or similar"},
{ATI_DAC_ATI68875, "ATI 68875 or similar"},
{ATI_DAC_TVP3026_A, "TI ViewPoint3026 or similar"},
{ATI_DAC_GENERIC, "Brooktree 476 or similar"},
{ATI_DAC_BT481, "Brooktree 481 or similar"},
{ATI_DAC_ATT20C491, "AT&T 20C491 or similar"},
{ATI_DAC_SC15026, "Sierra 15026 or similar"},
{ATI_DAC_MU9C1880, "Music 9C1880 or similar"},
{ATI_DAC_IMSG174, "Inmos G174 or similar"},
{ATI_DAC_ATI68860_B, "ATI 68860 (Revision B) or similar"},
{ATI_DAC_ATI68860_C, "ATI 68860 (Revision C) or similar"},
{ATI_DAC_TVP3026_B, "TI ViewPoint3026 or similar"},
{ATI_DAC_STG1700, "SGS-Thompson 1700 or similar"},
{ATI_DAC_ATT20C498, "AT&T 20C498 or similar"},
{ATI_DAC_STG1702, "SGS-Thompson 1702 or similar"},
{ATI_DAC_SC15021, "Sierra 15021 or similar"},
{ATI_DAC_ATT21C498, "AT&T 21C498 or similar"},
{ATI_DAC_STG1703, "SGS-Thompson 1703 or similar"},
{ATI_DAC_CH8398, "Chrontel 8398 or similar"},
{ATI_DAC_ATT20C408, "AT&T 20C408 or similar"},
{ATI_DAC_INTERNAL, "Internal"},
{ATI_DAC_IBMRGB514, "IBM RGB 514 or similar"},
{ATI_DAC_UNKNOWN, "Unknown"} /* Must be last */
};
#ifndef AVOID_CPIO
/*
* ATISetDACIOPorts --
*
* This function sets up DAC access I/O port numbers.
*/
void
ATISetDACIOPorts
(
ATIPtr pATI,
ATICRTCType crtc
)
{
switch (crtc)
{
case ATI_CRTC_VGA:
pATI->CPIO_DAC_DATA = VGA_DAC_DATA;
pATI->CPIO_DAC_MASK = VGA_DAC_MASK;
pATI->CPIO_DAC_READ = VGA_DAC_READ;
pATI->CPIO_DAC_WRITE = VGA_DAC_WRITE;
pATI->CPIO_DAC_WAIT = GENS1(pATI->CPIO_VGABase);
break;
case ATI_CRTC_8514:
pATI->CPIO_DAC_DATA = IBM_DAC_DATA;
pATI->CPIO_DAC_MASK = IBM_DAC_MASK;
pATI->CPIO_DAC_READ = IBM_DAC_READ;
pATI->CPIO_DAC_WRITE = IBM_DAC_WRITE;
pATI->CPIO_DAC_WAIT = pATI->CPIO_DAC_MASK;
break;
case ATI_CRTC_MACH64:
pATI->CPIO_DAC_DATA = ATIIOPort(DAC_REGS) + 1;
pATI->CPIO_DAC_MASK = ATIIOPort(DAC_REGS) + 2;
pATI->CPIO_DAC_READ = ATIIOPort(DAC_REGS) + 3;
pATI->CPIO_DAC_WRITE = ATIIOPort(DAC_REGS) + 0;
pATI->CPIO_DAC_WAIT = pATI->CPIOBase;
break;
default:
break;
}
}
#endif /* AVOID_CPIO */
/*
* ATIGetDACCmdReg --
*
* Setup to access a RAMDAC's command register.
*/
CARD8
ATIGetDACCmdReg
(
ATIPtr pATI
)
{
#ifdef AVOID_CPIO
(void)in8(M64_DAC_WRITE); /* Reset to PEL mode */
(void)in8(M64_DAC_MASK);
(void)in8(M64_DAC_MASK);
(void)in8(M64_DAC_MASK);
return in8(M64_DAC_MASK);
#else /* AVOID_CPIO */
(void)inb(pATI->CPIO_DAC_WRITE); /* Reset to PEL mode */
(void)inb(pATI->CPIO_DAC_MASK);
(void)inb(pATI->CPIO_DAC_MASK);
(void)inb(pATI->CPIO_DAC_MASK);
return inb(pATI->CPIO_DAC_MASK);
#endif /* AVOID_CPIO */
}
/*
* ATIDACPreInit --
*
* This function initialises the fields in an ATIHWRec that relate to DACs.
*/
void
ATIDACPreInit
(
ScrnInfoPtr pScreenInfo,
ATIPtr pATI,
ATIHWPtr pATIHW
)
{
CARD8 maxColour = (1 << pATI->rgbBits) - 1;
pATIHW->dac_read = pATIHW->dac_write = 0x00U;
pATIHW->dac_mask = 0xFFU;
/*
* Set colour lookup table. The first entry has already been zeroed out.
*/
if (pATI->depth > 8)
for (int Index = 1; Index < (NumberOf(pATIHW->lut) / 3); Index++)
{
int Index2 = Index * 3;
pATIHW->lut[Index2 + 0] =
pATIHW->lut[Index2 + 1] =
pATIHW->lut[Index2 + 2] = Index;
}
else
{
/*
* Initialise hardware colour map so that use of uninitialised
* software colour map entries can easily be seen. For 256-colour
* modes, this doesn't remain effective for very long...
*/
pATIHW->lut[3] = pATIHW->lut[4] = pATIHW->lut[5] = 0xFFU;
for (int Index = 2; Index < (NumberOf(pATIHW->lut) / 3); Index++)
{
int Index2 = Index * 3;
pATIHW->lut[Index2 + 0] = maxColour;
pATIHW->lut[Index2 + 1] = 0x00U;
pATIHW->lut[Index2 + 2] = maxColour;
}
}
}
/*
* ATIDACSave --
*
* This function is called to save the current RAMDAC state into an ATIHWRec
* structure occurrence.
*/
void
ATIDACSave
(
ATIPtr pATI,
ATIHWPtr pATIHW
)
{
#ifdef AVOID_CPIO
pATIHW->dac_read = in8(M64_DAC_READ);
DACDelay;
pATIHW->dac_write = in8(M64_DAC_WRITE);
DACDelay;
pATIHW->dac_mask = in8(M64_DAC_MASK);
DACDelay;
/* Save DAC's colour lookup table */
out8(M64_DAC_MASK, 0xFFU);
DACDelay;
out8(M64_DAC_READ, 0x00U);
DACDelay;
for (int Index = 0; Index < NumberOf(pATIHW->lut); Index++)
{
pATIHW->lut[Index] = in8(M64_DAC_DATA);
DACDelay;
}
out8(M64_DAC_MASK, pATIHW->dac_mask);
DACDelay;
out8(M64_DAC_READ, pATIHW->dac_read);
DACDelay;
#else /* AVOID_CPIO */
ATISetDACIOPorts(pATI, pATIHW->crtc);
pATIHW->dac_read = inb(pATI->CPIO_DAC_READ);
DACDelay;
pATIHW->dac_write = inb(pATI->CPIO_DAC_WRITE);
DACDelay;
pATIHW->dac_mask = inb(pATI->CPIO_DAC_MASK);
DACDelay;
/* Save DAC's colour lookup table */
outb(pATI->CPIO_DAC_MASK, 0xFFU);
DACDelay;
outb(pATI->CPIO_DAC_READ, 0x00U);
DACDelay;
for (int Index = 0; Index < NumberOf(pATIHW->lut); Index++)
{
pATIHW->lut[Index] = inb(pATI->CPIO_DAC_DATA);
DACDelay;
}
outb(pATI->CPIO_DAC_MASK, pATIHW->dac_mask);
DACDelay;
outb(pATI->CPIO_DAC_READ, pATIHW->dac_read);
DACDelay;
#endif /* AVOID_CPIO */
}
/*
* ATIDACSet --
*
* This function loads RAMDAC data from an ATIHWRec structure occurrence.
*/
void
ATIDACSet
(
ATIPtr pATI,
ATIHWPtr pATIHW
)
{
#ifdef AVOID_CPIO
/* Load DAC's colour lookup table */
out8(M64_DAC_MASK, 0xFFU);
DACDelay;
out8(M64_DAC_WRITE, 0x00U);
DACDelay;
for (int Index = 0; Index < NumberOf(pATIHW->lut); Index++)
{
out8(M64_DAC_DATA, pATIHW->lut[Index]);
DACDelay;
}
out8(M64_DAC_MASK, pATIHW->dac_mask);
DACDelay;
out8(M64_DAC_READ, pATIHW->dac_read);
DACDelay;
out8(M64_DAC_WRITE, pATIHW->dac_write);
DACDelay;
#else /* AVOID_CPIO */
ATISetDACIOPorts(pATI, pATIHW->crtc);
/* Load DAC's colour lookup table */
outb(pATI->CPIO_DAC_MASK, 0xFFU);
DACDelay;
outb(pATI->CPIO_DAC_WRITE, 0x00U);
DACDelay;
for (int Index = 0; Index < NumberOf(pATIHW->lut); Index++)
{
outb(pATI->CPIO_DAC_DATA, pATIHW->lut[Index]);
DACDelay;
}
outb(pATI->CPIO_DAC_MASK, pATIHW->dac_mask);
DACDelay;
outb(pATI->CPIO_DAC_READ, pATIHW->dac_read);
DACDelay;
outb(pATI->CPIO_DAC_WRITE, pATIHW->dac_write);
DACDelay;
#endif /* AVOID_CPIO */
}
/*
* ATISetLUTEntry --
*
* This function is called to set one of a DAC's LUT entries.
*/
static void
ATISetLUTEntry
(
ATIPtr pATI,
int Index,
CARD8 *LUTEntry
)
{
#ifdef AVOID_CPIO
out8(M64_DAC_WRITE, Index);
DACDelay;
out8(M64_DAC_DATA, LUTEntry[0]);
DACDelay;
out8(M64_DAC_DATA, LUTEntry[1]);
DACDelay;
out8(M64_DAC_DATA, LUTEntry[2]);
DACDelay;
#else /* AVOID_CPIO */
outb(pATI->CPIO_DAC_WRITE, Index);
DACDelay;
outb(pATI->CPIO_DAC_DATA, LUTEntry[0]);
DACDelay;
outb(pATI->CPIO_DAC_DATA, LUTEntry[1]);
DACDelay;
outb(pATI->CPIO_DAC_DATA, LUTEntry[2]);
DACDelay;
#endif /* AVOID_CPIO */
}
/*
* ATILoadPalette --
*
* This function updates the RAMDAC's LUT and the in-memory copy of it in
* NewHW.
*/
void
ATILoadPalette
(
ScrnInfoPtr pScreenInfo,
int nColours,
int *Indices,
LOCO *Colours,
VisualPtr pVisual
)
{
ATIPtr pATI = ATIPTR(pScreenInfo);
CARD8 *LUTEntry;
if (((pVisual->class | DynamicClass) == DirectColor) &&
((1 << pVisual->nplanes) > (SizeOf(pATI->NewHW.lut) / 3)))
{
int reds = pVisual->redMask >> pVisual->offsetRed;
int greens = pVisual->greenMask >> pVisual->offsetGreen;
int blues = pVisual->blueMask >> pVisual->offsetBlue;
int redShift = 8 - pATI->weight.red;
int greenShift = 8 - pATI->weight.green;
int blueShift = 8 - pATI->weight.blue;
int redMult = 3 << redShift;
int greenMult = 3 << greenShift;
int blueMult = 3 << blueShift;
int minShift;
CARD8 fChanged[SizeOf(pATI->NewHW.lut) / 3];
(void)memset(fChanged, 0, SizeOf(fChanged));
minShift = redShift;
if (minShift > greenShift)
minShift = greenShift;
if (minShift > blueShift)
minShift = blueShift;
for (int i = 0; i < nColours; i++)
{
int j, Index;
if((Index = Indices[i]) < 0)
continue;
if (Index <= reds)
{
j = Index * redMult;
pATI->NewHW.lut[j + 0] = Colours[Index].red;
fChanged[j / 3] = TRUE;
}
if (Index <= greens)
{
j = Index * greenMult;
pATI->NewHW.lut[j + 1] = Colours[Index].green;
fChanged[j / 3] = TRUE;
}
if (Index <= blues)
{
j = Index * blueMult;
pATI->NewHW.lut[j + 2] = Colours[Index].blue;
fChanged[j / 3] = TRUE;
}
}
if (pScreenInfo->vtSema || pATI->currentMode)
{
/* Rewrite LUT entries that could have been changed */
int i = 1 << minShift;
LUTEntry = pATI->NewHW.lut;
for (int Index = 0;
Index < (SizeOf(pATI->NewHW.lut) / 3);
Index += i, LUTEntry += i * 3)
if (fChanged[Index])
ATISetLUTEntry(pATI, Index, LUTEntry);
}
}
else
{
for (int i = 0; i < nColours; i++)
{
int Index = Indices[i];
if ((Index < 0) || (Index >= (SizeOf(pATI->NewHW.lut) / 3)))
continue;
LUTEntry = &pATI->NewHW.lut[Index * 3];
LUTEntry[0] = Colours[Index].red;
LUTEntry[1] = Colours[Index].green;
LUTEntry[2] = Colours[Index].blue;
if (pScreenInfo->vtSema || pATI->currentMode)
ATISetLUTEntry(pATI, Index, LUTEntry);
}
}
}
|