grf_rt.c revision 1.51 1 /* $NetBSD: grf_rt.c,v 1.51 2007/03/04 05:59:19 christos Exp $ */
2
3 /*
4 * Copyright (c) 1993 Markus Wild
5 * Copyright (c) 1993 Lutz Vieweg
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by Lutz Vieweg.
19 * 4. The name of the author may not be used to endorse or promote products
20 * derived from this software without specific prior written permission
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33 #include "opt_amigacons.h"
34
35 #include <sys/cdefs.h>
36 __KERNEL_RCSID(0, "$NetBSD: grf_rt.c,v 1.51 2007/03/04 05:59:19 christos Exp $");
37
38 #include "grfrt.h"
39 #if NGRFRT > 0
40
41 /* Graphics routines for the Retina board,
42 using the NCR 77C22E+ VGA controller. */
43
44 #include <sys/param.h>
45 #include <sys/systm.h>
46 #include <sys/errno.h>
47 #include <sys/ioctl.h>
48 #include <sys/device.h>
49 #include <machine/cpu.h>
50 #include <amiga/amiga/device.h>
51 #include <amiga/dev/zbusvar.h>
52 #include <amiga/dev/grfioctl.h>
53 #include <amiga/dev/grfvar.h>
54 #include <amiga/dev/grf_rtreg.h>
55
56 int rt_ioctl(struct grf_softc *gp, u_long, void *);
57
58 /*
59 * marked true early so that retina_cnprobe() can tell if we are alive.
60 */
61 int retina_inited;
62
63
64 /*
65 * This driver for the MacroSystem Retina board was only possible,
66 * because MacroSystem provided information about the pecularities
67 * of the board. THANKS! Competition in Europe among gfx board
68 * manufacturers is rather tough, so Lutz Vieweg, who wrote the
69 * initial driver, has made an agreement with MS not to document
70 * the driver source (see also his comment below).
71 * -> ALL comments after
72 * -> " -------------- START OF CODE -------------- "
73 * -> have been added by myself (mw) from studying the publically
74 * -> available "NCR 77C22E+" Data Manual
75 */
76 /*
77 * This code offers low-level routines to access the Retina graphics-board
78 * manufactured by MS MacroSystem GmbH from within NetBSD for the Amiga.
79 *
80 * Thanks to MacroSystem for providing me with the necessary information
81 * to create theese routines. The sparse documentation of this code
82 * results from the agreements between MS and me.
83 */
84
85 extern unsigned char kernel_font_8x8_width, kernel_font_8x8_height;
86 extern unsigned char kernel_font_8x8_lo, kernel_font_8x8_hi;
87 extern unsigned char kernel_font_8x8[];
88
89
90 #define MDF_DBL 1
91 #define MDF_LACE 2
92 #define MDF_CLKDIV2 4
93
94
95 /* standard-palette definition */
96
97 unsigned char NCRStdPalette[16*3] = {
98 /* R G B */
99 0, 0, 0,
100 192,192,192,
101 128, 0, 0,
102 0,128, 0,
103 0, 0,128,
104 128,128, 0,
105 0,128,128,
106 128, 0,128,
107 64, 64, 64, /* the higher 8 colors have more intensity for */
108 255,255,255, /* compatibility with standard attributes */
109 255, 0, 0,
110 0,255, 0,
111 0, 0,255,
112 255,255, 0,
113 0,255,255,
114 255, 0,255
115 };
116
117
118 /* The following structures are examples for monitor-definitions. To make one
119 of your own, first use "DefineMonitor" and create the 8-bit monitor-mode of
120 your dreams. Then save it, and make a structure from the values provided in
121 the file DefineMonitor stored - the labels in the comment above the
122 structure definition show where to put what value.
123
124 Then you'll need to adapt your monitor-definition to the font you want to
125 use. Be FX the width of the font, then the following modifications have to
126 be applied to your values:
127
128 HBS = (HBS * 4) / FX
129 HSS = (HSS * 4) / FX
130 HSE = (HSE * 4) / FX
131 HBE = (HBE * 4) / FX
132 HT = (HT * 4) / FX
133
134 Make sure your maximum width (MW) and height (MH) are even multiples of
135 the fonts' width and height.
136 */
137
138 #if 0
139 /* horizontal 31.5 kHz */
140
141 /* FQ FLG MW MH HBS HSS HSE HBE HT VBS VSS VSE VBE VT */
142 struct MonDef MON_640_512_60 = { 50000000, 28, 640, 512, 81, 86, 93, 98, 95, 513, 513, 521, 535, 535,
143 /* Depth, PAL, TX, TY, XY,FontX, FontY, FontData, FLo, Fhi */
144 4, NCRStdPalette, 80, 64, 5120, 8, 8, kernel_font_8x8, 32, 255};
145
146 struct MonDef MON_640_480_62_G = { 50000000, 4, 640, 480, 161,171,184,196,195, 481, 484, 492, 502, 502,
147 8, NCRStdPalette,640,480, 5120, 8, 8, kernel_font_8x8, 32, 255};
148 /* Enter higher values here ^ ^ for panning! */
149
150 /* horizontal 38kHz */
151
152 struct MonDef MON_768_600_60 = { 75000000, 28, 768, 600, 97, 99,107,120,117, 601, 615, 625, 638, 638,
153 4, NCRStdPalette, 96, 75, 7200, 8, 8, kernel_font_8x8, 32, 255};
154
155 /* horizontal 64kHz */
156
157 struct MonDef MON_768_600_80 = { 50000000, 24, 768, 600, 97,104,112,122,119, 601, 606, 616, 628, 628,
158 4, NCRStdPalette, 96, 75, 7200, 8, 8, kernel_font_8x8, 32, 255};
159
160 struct MonDef MON_1024_768_80 = { 90000000, 24, 1024, 768, 129,130,141,172,169, 769, 770, 783, 804, 804,
161 4, NCRStdPalette,128, 96, 12288, 8, 8, kernel_font_8x8, 32, 255};
162
163 /* FQ FLG MW MH HBS HSS HSE HBE HT VBS VSS VSE VBE VT */
164 struct MonDef MON_1024_768_80_G = { 90000000, 0, 1024, 768, 257,258,280,344,343, 769, 770, 783, 804, 804,
165 8, NCRStdPalette, 1024, 768, 12288, 8, 8, kernel_font_8x8, 32, 255};
166
167 struct MonDef MON_1024_1024_59= { 90000000, 24, 1024,1024, 129,130,141,173,170,1025,1059,1076,1087,1087,
168 4, NCRStdPalette,128, 128, 16384, 8, 8, kernel_font_8x8, 32, 255};
169
170 /* WARNING: THE FOLLOWING MONITOR MODES EXCEED THE 90-MHz LIMIT THE PROCESSOR
171 HAS BEEN SPECIFIED FOR. USE AT YOUR OWN RISK (AND THINK ABOUT
172 MOUNTING SOME COOLING DEVICE AT THE PROCESSOR AND RAMDAC)! */
173
174 struct MonDef MON_1280_1024_60= {110000000, 24, 1280,1024, 161,162,176,211,208,1025,1026,1043,1073,1073,
175 4, NCRStdPalette,160, 128, 20480, 8, 8, kernel_font_8x8, 32, 255};
176
177 struct MonDef MON_1280_1024_60_G= {110000000, 0, 1280,1024, 321,322,349,422,421,1025,1026,1043,1073,1073,
178 8, NCRStdPalette,1280,1024, 20480, 8, 8, kernel_font_8x8, 32, 255};
179
180 /* horizontal 75kHz */
181
182 struct MonDef MON_1280_1024_69= {120000000, 24, 1280,1024, 161,162,175,200,197,1025,1026,1043,1073,1073,
183 4, NCRStdPalette,160, 128, 20480, 8, 8, kernel_font_8x8, 32, 255};
184
185 #else
186
187 struct MonDef monitor_defs[] = {
188 /* horizontal 31.5 kHz */
189
190 { 50000000, 28, 640, 512, 81, 86, 93, 98, 95, 513, 513, 521, 535, 535,
191 4, NCRStdPalette, 80, 64, 5120, 8, 8, kernel_font_8x8, 32, 255},
192
193 /* horizontal 38kHz */
194
195 { 75000000, 28, 768, 600, 97, 99,107,120,117, 601, 615, 625, 638, 638,
196 4, NCRStdPalette, 96, 75, 7200, 8, 8, kernel_font_8x8, 32, 255},
197
198 /* horizontal 64kHz */
199
200 { 50000000, 24, 768, 600, 97,104,112,122,119, 601, 606, 616, 628, 628,
201 4, NCRStdPalette, 96, 75, 7200, 8, 8, kernel_font_8x8, 32, 255},
202
203 { 90000000, 24, 1024, 768, 129,130,141,172,169, 769, 770, 783, 804, 804,
204 4, NCRStdPalette,128, 96, 12288, 8, 8, kernel_font_8x8, 32, 255},
205
206 /* GFX modes */
207
208 /* horizontal 31.5 kHz */
209
210 { 50000000, 4, 640, 480, 161,171,184,196,195, 481, 484, 492, 502, 502,
211 8, NCRStdPalette,640, 480, 5120, 8, 8, kernel_font_8x8, 32, 255},
212
213 /* horizontal 64kHz */
214
215 { 90000000, 0, 1024, 768, 257,258,280,344,343, 769, 770, 783, 804, 804,
216 8, NCRStdPalette, 1024, 768, 12288, 8, 8, kernel_font_8x8, 32, 255},
217
218 /* WARNING: THE FOLLOWING MONITOR MODES EXCEED THE 90-MHz LIMIT THE PROCESSOR
219 HAS BEEN SPECIFIED FOR. USE AT YOUR OWN RISK (AND THINK ABOUT
220 MOUNTING SOME COOLING DEVICE AT THE PROCESSOR AND RAMDAC)! */
221
222 {110000000, 0, 1280,1024, 321,322,349,422,421,1025,1026,1043,1073,1073,
223 8, NCRStdPalette,1280,1024, 20480, 8, 8, kernel_font_8x8, 32, 255},
224 };
225
226 static const char *monitor_descr[] = {
227 "80x64 (640x512) 31.5kHz",
228 "96x75 (768x600) 38kHz",
229 "96x75 (768x600) 64kHz",
230 "128x96 (1024x768) 64kHz",
231
232 "GFX (640x480) 31.5kHz",
233 "GFX (1024x768) 64kHz",
234 "GFX (1280x1024) 64kHz ***EXCEEDS CHIP LIMIT!!!***",
235 };
236
237 int retina_mon_max = sizeof (monitor_defs)/sizeof (monitor_defs[0]);
238
239 /* patchable */
240 int retina_default_mon = 0;
241 int retina_default_gfx = 4;
242
243 #endif
244
245
246 static struct MonDef *current_mon;
247
248 /* -------------- START OF CODE -------------- */
249
250
251 static const long FQTab[16] =
252 { 25175000, 28322000, 36000000, 65000000,
253 44900000, 50000000, 80000000, 75000000,
254 56644000, 63000000, 72000000, 130000000,
255 90000000, 100000000, 110000000, 120000000 };
256
257
258 /*--------------------------------------------------*/
259 /*--------------------------------------------------*/
260
261 #if 0
262 static struct MonDef *default_monitor = &DEFAULT_MONDEF;
263 #endif
264
265 int retina_alive(struct MonDef *);
266 static int rt_load_mon(struct grf_softc *, struct MonDef *);
267
268
269 /*
270 * used to query the retina to see if its alive (?)
271 */
272 int
273 retina_alive(struct MonDef *mdp)
274 {
275 short clksel;
276
277 for (clksel = 15; clksel; clksel--) {
278 if (FQTab[clksel] == mdp->FQ)
279 break;
280 }
281 if (clksel < 0)
282 return(0);
283 if (mdp->DEP != 4)
284 return(1);
285 if (mdp->FX == 4 || (mdp->FX >= 7 && mdp->FX <= 16))
286 return(1);
287 return(0);
288 }
289
290 static int
291 rt_load_mon(struct grf_softc *gp, struct MonDef *md)
292 {
293 struct grfinfo *gi = &gp->g_display;
294 volatile void *ba, fb;
295 short FW, clksel, HDE, VDE;
296
297 for (clksel = 15; clksel; clksel--) {
298 if (FQTab[clksel] == md->FQ) break;
299 }
300 if (clksel < 0)
301 return(0);
302
303 ba = gp->g_regkva;
304 fb = gp->g_fbkva;
305
306 FW = 0;
307 if (md->DEP == 4) {
308 switch (md->FX) {
309 case 4:
310 FW = 0;
311 break;
312 case 7:
313 FW = 1;
314 break;
315 case 8:
316 FW = 2;
317 break;
318 case 9:
319 FW = 3;
320 break;
321 case 10:
322 FW = 4;
323 break;
324 case 11:
325 FW = 5;
326 break;
327 case 12:
328 FW = 6;
329 break;
330 case 13:
331 FW = 7;
332 break;
333 case 14:
334 FW = 8;
335 break;
336 case 15:
337 FW = 9;
338 break;
339 case 16:
340 FW = 11;
341 break;
342 default:
343 return(0);
344 break;
345 };
346 }
347
348 if (md->DEP == 4) HDE = (md->MW+md->FX-1)/md->FX;
349 else HDE = (md->MW+3)/4;
350 VDE = md->MH-1;
351
352 /* hmm... */
353 fb[0x8000] = 0;
354
355 /* enable extension registers */
356 WSeq (ba, SEQ_ID_EXTENDED_ENABLE, 0x05);
357
358 #if 0
359 /* program the clock oscillator */
360 vgaw (ba, GREG_MISC_OUTPUT_W, 0xe3 | ((clksel & 3) * 0x04));
361 vgaw (ba, GREG_FEATURE_CONTROL_W, 0x00);
362
363 /* XXXX according to the NCR specs, this register should be set to 1
364 XXXX before doing the MISC_OUTPUT setting and CLOCKING_MODE
365 XXXX setting. */
366 WSeq (ba, SEQ_ID_RESET, 0x03);
367
368 WSeq (ba, SEQ_ID_CLOCKING_MODE, 0x01 | ((md->FLG & MDF_CLKDIV2)/ MDF_CLKDIV2 * 8));
369 WSeq (ba, SEQ_ID_MAP_MASK, 0x0f);
370 WSeq (ba, SEQ_ID_CHAR_MAP_SELECT, 0x00);
371 /* odd/even write select + extended memory */
372 WSeq (ba, SEQ_ID_MEMORY_MODE, 0x06);
373 /* XXXX I think this order of setting RESET is wrong... */
374 WSeq (ba, SEQ_ID_RESET, 0x01);
375 WSeq (ba, SEQ_ID_RESET, 0x03);
376 #else
377 WSeq (ba, SEQ_ID_RESET, 0x01);
378
379 /* set font width + rest of clocks */
380 WSeq (ba, SEQ_ID_EXT_CLOCK_MODE, 0x30 | (FW & 0x0f) | ((clksel & 4) / 4 * 0x40) );
381 /* another clock bit, plus hw stuff */
382 WSeq (ba, SEQ_ID_MISC_FEATURE_SEL, 0xf4 | (clksel & 8) );
383
384 /* program the clock oscillator */
385 vgaw (ba, GREG_MISC_OUTPUT_W, 0xe3 | ((clksel & 3) * 0x04));
386 vgaw (ba, GREG_FEATURE_CONTROL_W, 0x00);
387
388 WSeq (ba, SEQ_ID_CLOCKING_MODE, 0x01 | ((md->FLG & MDF_CLKDIV2)/ MDF_CLKDIV2 * 8));
389 WSeq (ba, SEQ_ID_MAP_MASK, 0x0f);
390 WSeq (ba, SEQ_ID_CHAR_MAP_SELECT, 0x00);
391 /* odd/even write select + extended memory */
392 WSeq (ba, SEQ_ID_MEMORY_MODE, 0x06);
393 WSeq (ba, SEQ_ID_RESET, 0x03);
394 #endif
395
396 /* monochrome cursor */
397 WSeq (ba, SEQ_ID_CURSOR_CONTROL, 0x00);
398 /* bank0 */
399 WSeq (ba, SEQ_ID_PRIM_HOST_OFF_HI, 0x00);
400 WSeq (ba, SEQ_ID_PRIM_HOST_OFF_LO, 0x00);
401 WSeq (ba, SEQ_ID_DISP_OFF_HI , 0x00);
402 WSeq (ba, SEQ_ID_DISP_OFF_LO , 0x00);
403 /* bank0 */
404 WSeq (ba, SEQ_ID_SEC_HOST_OFF_HI, 0x00);
405 WSeq (ba, SEQ_ID_SEC_HOST_OFF_LO, 0x00);
406 /* 1M-chips + ena SEC + ena EMem + rw PrimA0/rw Sec/B0 */
407 WSeq (ba, SEQ_ID_EXTENDED_MEM_ENA, 0x3 | 0x4 | 0x10 | 0x40);
408 #if 0
409 /* set font width + rest of clocks */
410 WSeq (ba, SEQ_ID_EXT_CLOCK_MODE, 0x30 | (FW & 0x0f) | ((clksel & 4) / 4 * 0x40) );
411 #endif
412 if (md->DEP == 4) {
413 /* no ext-chain4 + no host-addr-bit-16 */
414 WSeq (ba, SEQ_ID_EXT_VIDEO_ADDR, 0x00);
415 /* no packed/nibble + no 256bit gfx format */
416 WSeq (ba, SEQ_ID_EXT_PIXEL_CNTL, 0x00);
417 }
418 else {
419 WSeq (ba, SEQ_ID_EXT_VIDEO_ADDR, 0x02);
420 /* 256bit gfx format */
421 WSeq (ba, SEQ_ID_EXT_PIXEL_CNTL, 0x01);
422 }
423 /* AT-interface */
424 WSeq (ba, SEQ_ID_BUS_WIDTH_FEEDB, 0x06);
425 /* see fg/bg color expansion */
426 WSeq (ba, SEQ_ID_COLOR_EXP_WFG, 0x01);
427 WSeq (ba, SEQ_ID_COLOR_EXP_WBG, 0x00);
428 WSeq (ba, SEQ_ID_EXT_RW_CONTROL, 0x00);
429 #if 0
430 /* another clock bit, plus hw stuff */
431 WSeq (ba, SEQ_ID_MISC_FEATURE_SEL, 0xf4 | (clksel & 8) );
432 #endif
433 /* don't tristate PCLK and PIX */
434 WSeq (ba, SEQ_ID_COLOR_KEY_CNTL, 0x40 );
435 /* reset CRC circuit */
436 WSeq (ba, SEQ_ID_CRC_CONTROL, 0x00 );
437 /* set RAS/CAS swap */
438 WSeq (ba, SEQ_ID_PERF_SELECT, 0x20);
439
440 WCrt (ba, CRT_ID_END_VER_RETR, (md->VSE & 0xf ) | 0x20);
441 WCrt (ba, CRT_ID_HOR_TOTAL, md->HT & 0xff);
442 WCrt (ba, CRT_ID_HOR_DISP_ENA_END, (HDE-1) & 0xff);
443 WCrt (ba, CRT_ID_START_HOR_BLANK, md->HBS & 0xff);
444 WCrt (ba, CRT_ID_END_HOR_BLANK, (md->HBE & 0x1f) | 0x80);
445
446 WCrt (ba, CRT_ID_START_HOR_RETR, md->HSS & 0xff);
447 WCrt (ba, CRT_ID_END_HOR_RETR, (md->HSE & 0x1f) | ((md->HBE & 0x20)/ 0x20 * 0x80));
448 WCrt (ba, CRT_ID_VER_TOTAL, (md->VT & 0xff));
449 WCrt (ba, CRT_ID_OVERFLOW, (( (md->VSS & 0x200) / 0x200 * 0x80)
450 | ((VDE & 0x200) / 0x200 * 0x40)
451 | ((md->VT & 0x200) / 0x200 * 0x20)
452 | 0x10
453 | ((md->VBS & 0x100) / 0x100 * 8 )
454 | ((md->VSS & 0x100) / 0x100 * 4 )
455 | ((VDE & 0x100) / 0x100 * 2 )
456 | ((md->VT & 0x100) / 0x100 )));
457 WCrt (ba, CRT_ID_PRESET_ROW_SCAN, 0x00);
458
459 if (md->DEP == 4) {
460 WCrt (ba, CRT_ID_MAX_SCAN_LINE, (( (md->FLG & MDF_DBL)/ MDF_DBL * 0x80)
461 | 0x40
462 | ((md->VBS & 0x200)/0x200 * 0x20)
463 | ((md->FY-1) & 0x1f)));
464 }
465 else {
466 WCrt (ba, CRT_ID_MAX_SCAN_LINE, (( (md->FLG & MDF_DBL)/ MDF_DBL * 0x80)
467 | 0x40
468 | ((md->VBS & 0x200)/0x200 * 0x20)
469 | (0 & 0x1f)));
470 }
471
472 WCrt (ba, CRT_ID_CURSOR_START, (md->FY & 0x1f) - 2);
473 WCrt (ba, CRT_ID_CURSOR_END, (md->FY & 0x1f) - 1);
474
475 WCrt (ba, CRT_ID_START_ADDR_HIGH, 0x00);
476 WCrt (ba, CRT_ID_START_ADDR_LOW, 0x00);
477
478 WCrt (ba, CRT_ID_CURSOR_LOC_HIGH, 0x00);
479 WCrt (ba, CRT_ID_CURSOR_LOC_LOW, 0x00);
480
481 WCrt (ba, CRT_ID_START_VER_RETR, md->VSS & 0xff);
482 WCrt (ba, CRT_ID_END_VER_RETR, (md->VSE & 0x0f) | 0x80 | 0x20);
483 WCrt (ba, CRT_ID_VER_DISP_ENA_END, VDE & 0xff);
484 if (md->DEP == 4)
485 WCrt (ba, CRT_ID_OFFSET, (HDE / 2) & 0xff);
486 else
487 WCrt (ba, CRT_ID_OFFSET, (md->TX / 8) & 0xff);
488
489 WCrt (ba, CRT_ID_UNDERLINE_LOC, (md->FY-1) & 0x1f);
490 WCrt (ba, CRT_ID_START_VER_BLANK, md->VBS & 0xff);
491 WCrt (ba, CRT_ID_END_VER_BLANK, md->VBE & 0xff);
492 /* byte mode + wrap + select row scan counter + cms */
493 WCrt (ba, CRT_ID_MODE_CONTROL, 0xe3);
494 WCrt (ba, CRT_ID_LINE_COMPARE, 0xff);
495
496 /* enable extended end bits + those bits */
497 WCrt (ba, CRT_ID_EXT_HOR_TIMING1, ( 0x20
498 | ((md->FLG & MDF_LACE) / MDF_LACE * 0x10)
499 | ((md->HT & 0x100) / 0x100 * 0x01)
500 | (((HDE-1) & 0x100) / 0x100 * 0x02)
501 | ((md->HBS & 0x100) / 0x100 * 0x04)
502 | ((md->HSS & 0x100) / 0x100 * 0x08)));
503
504 if (md->DEP == 4)
505 WCrt (ba, CRT_ID_EXT_START_ADDR, (((HDE / 2) & 0x100)/0x100 * 16));
506 else
507 WCrt (ba, CRT_ID_EXT_START_ADDR, (((md->TX / 8) & 0x100)/0x100 * 16));
508
509 WCrt (ba, CRT_ID_EXT_HOR_TIMING2, ( ((md->HT & 0x200)/ 0x200 * 0x01)
510 | (((HDE-1) & 0x200)/ 0x200 * 0x02)
511 | ((md->HBS & 0x200)/ 0x200 * 0x04)
512 | ((md->HSS & 0x200)/ 0x200 * 0x08)
513 | ((md->HBE & 0xc0) / 0x40 * 0x10)
514 | ((md->HSE & 0x60) / 0x20 * 0x40)));
515
516 WCrt (ba, CRT_ID_EXT_VER_TIMING, ( ((md->VSE & 0x10) / 0x10 * 0x80)
517 | ((md->VBE & 0x300)/ 0x100 * 0x20)
518 | 0x10
519 | ((md->VSS & 0x400)/ 0x400 * 0x08)
520 | ((md->VBS & 0x400)/ 0x400 * 0x04)
521 | ((VDE & 0x400)/ 0x400 * 0x02)
522 | ((md->VT & 0x400)/ 0x400 * 0x01)));
523
524 WGfx (ba, GCT_ID_SET_RESET, 0x00);
525 WGfx (ba, GCT_ID_ENABLE_SET_RESET, 0x00);
526 WGfx (ba, GCT_ID_COLOR_COMPARE, 0x00);
527 WGfx (ba, GCT_ID_DATA_ROTATE, 0x00);
528 WGfx (ba, GCT_ID_READ_MAP_SELECT, 0x00);
529 WGfx (ba, GCT_ID_GRAPHICS_MODE, 0x00);
530 if (md->DEP == 4)
531 WGfx (ba, GCT_ID_MISC, 0x04);
532 else
533 WGfx (ba, GCT_ID_MISC, 0x05);
534 WGfx (ba, GCT_ID_COLOR_XCARE, 0xff);
535 WGfx (ba, GCT_ID_BITMASK, 0xff);
536
537 /* reset the Attribute Controller flipflop */
538 vgar (ba, GREG_STATUS1_R);
539 WAttr (ba, ACT_ID_PALETTE0, 0x00);
540 WAttr (ba, ACT_ID_PALETTE1, 0x01);
541 WAttr (ba, ACT_ID_PALETTE2, 0x02);
542 WAttr (ba, ACT_ID_PALETTE3, 0x03);
543 WAttr (ba, ACT_ID_PALETTE4, 0x04);
544 WAttr (ba, ACT_ID_PALETTE5, 0x05);
545 WAttr (ba, ACT_ID_PALETTE6, 0x06);
546 WAttr (ba, ACT_ID_PALETTE7, 0x07);
547 WAttr (ba, ACT_ID_PALETTE8, 0x08);
548 WAttr (ba, ACT_ID_PALETTE9, 0x09);
549 WAttr (ba, ACT_ID_PALETTE10, 0x0a);
550 WAttr (ba, ACT_ID_PALETTE11, 0x0b);
551 WAttr (ba, ACT_ID_PALETTE12, 0x0c);
552 WAttr (ba, ACT_ID_PALETTE13, 0x0d);
553 WAttr (ba, ACT_ID_PALETTE14, 0x0e);
554 WAttr (ba, ACT_ID_PALETTE15, 0x0f);
555
556 vgar (ba, GREG_STATUS1_R);
557 if (md->DEP == 4)
558 WAttr (ba, ACT_ID_ATTR_MODE_CNTL, 0x08);
559 else
560 WAttr (ba, ACT_ID_ATTR_MODE_CNTL, 0x09);
561
562 WAttr (ba, ACT_ID_OVERSCAN_COLOR, 0x00);
563 WAttr (ba, ACT_ID_COLOR_PLANE_ENA, 0x0f);
564 WAttr (ba, ACT_ID_HOR_PEL_PANNING, 0x00);
565 WAttr (ba, ACT_ID_COLOR_SELECT, 0x00);
566
567 vgar (ba, GREG_STATUS1_R);
568 /* I have *NO* idea what strobing reg-0x20 might do... */
569 vgaw (ba, ACT_ADDRESS_W, 0x20);
570
571 if (md->DEP == 4)
572 WCrt (ba, CRT_ID_MAX_SCAN_LINE, ( ((md->FLG & MDF_DBL)/ MDF_DBL * 0x80)
573 | 0x40
574 | ((md->VBS & 0x200)/0x200 * 0x20)
575 | ((md->FY-1) & 0x1f)));
576 else
577 WCrt (ba, CRT_ID_MAX_SCAN_LINE, ( ((md->FLG & MDF_DBL)/ MDF_DBL * 0x80)
578 | 0x40
579 | ((md->VBS & 0x200)/0x200 * 0x20)
580 | (0 & 0x1f)));
581
582
583 /* not it's time for guessing... */
584
585 vgaw (ba, VDAC_REG_D, 0x02);
586
587 /* if this does what I think it does, it selects DAC
588 register 0, and writes the palette in subsequent
589 registers, thus it works similar to the WD33C93
590 select/data mechanism */
591 vgaw (ba, VDAC_REG_SELECT, 0x00);
592
593 {
594
595 short x = 15;
596 const unsigned char * col = md->PAL;
597 do {
598
599 vgaw (ba, VDAC_REG_DATA, *col++);
600 vgaw (ba, VDAC_REG_DATA, *col++);
601 vgaw (ba, VDAC_REG_DATA, *col++);
602
603
604 } while (x--);
605
606 if (md->DEP != 4) {
607 short xx = 256-17;
608 unsigned char cols = 16;
609 do {
610
611 vgaw(ba, VDAC_REG_DATA, cols);
612 vgaw(ba, VDAC_REG_DATA, cols);
613 vgaw(ba, VDAC_REG_DATA, cols);
614 cols++;
615
616 } while (xx--);
617 }
618 }
619
620
621 /* now load the font into maps 2 (and 3 for fonts wider than 8 pixels) */
622 if (md->DEP == 4) {
623
624 /* first set the whole font memory to a test-pattern, so we
625 can see if something that shouldn't be drawn IS drawn.. */
626 {
627 volatile void *c = fb;
628 long x;
629 Map(2);
630
631 for (x = 0; x < 65536; x++) {
632 *c++ = (x & 1)? 0xaa : 0x55;
633 }
634 }
635
636 {
637 volatile void *c = fb;
638 long x;
639 Map(3);
640
641 for (x = 0; x < 65536; x++) {
642 *c++ = (x & 1)? 0xaa : 0x55;
643 }
644 }
645
646 {
647 /* ok, now position at first defined character, and
648 copy over the images */
649 volatile void *c = fb + md->FLo * 32;
650 const unsigned char * f = md->FData;
651 unsigned short z;
652
653 Map(2);
654 for (z = md->FLo; z <= md->FHi; z++) {
655
656 short y = md->FY-1;
657 if (md->FX > 8){
658 do {
659 *c++ = *f;
660 f += 2;
661 } while (y--);
662 }
663 else {
664 do {
665 *c++ = *f++;
666 } while (y--);
667 }
668
669 c += 32-md->FY;
670
671 }
672
673 if (md->FX > 8) {
674 unsigned short zz;
675
676 Map(3);
677 c = fb + md->FLo*32;
678 f = md->FData+1;
679 for (zz = md->FLo; z <= md->FHi; zz++) {
680
681 short y = md->FY-1;
682 do {
683 *c++ = *f;
684 f += 2;
685 } while (y--);
686
687 c += 32-md->FY;
688
689 }
690 }
691 }
692
693 }
694
695 /* select map 0 */
696 WGfx (ba, GCT_ID_READ_MAP_SELECT, 0);
697 if (md->DEP == 4)
698 /* allow writes into maps 0 and 1 */
699 WSeq (ba, SEQ_ID_MAP_MASK, 3);
700 else
701 /* allow writes into all maps */
702 WSeq (ba, SEQ_ID_MAP_MASK, 0x0f);
703
704 /* select extended chain4 addressing:
705 !A0/!A1 map 0 character to be displayed
706 !A1/ A1 map 1 attribute of that character
707 A0/!A1 map 2 not used (masked out, ignored)
708 A0/ A1 map 3 not used (masked out, ignored) */
709 WSeq (ba, SEQ_ID_EXT_VIDEO_ADDR, RSeq(ba, SEQ_ID_EXT_VIDEO_ADDR) | 0x02);
710
711 if (md->DEP == 4) {
712 /* position in display memory */
713 unsigned short * c = (unsigned short *) fb;
714
715 /* fill with blank, white on black */
716 const unsigned short fill_val = 0x2010;
717 short x = md->XY;
718 do {
719 *c = fill_val;
720 c += 2; } while (x--);
721
722 /* I won't comment this :-)) */
723 c = (unsigned short *) fb;
724 c += (md->TX-6)*2;
725 {
726 unsigned short init_msg[6] = {0x520a, 0x450b, 0x540c, 0x490d, 0x4e0e, 0x410f};
727 unsigned short * f = init_msg;
728 x = 5;
729 do {
730 *c = *f++;
731 c += 2;
732 } while (x--);
733 }
734 }
735 else if (md->DEP == 8) {
736 /* could clear the gfx screen here, but that's what the X server does anyway */
737 ;
738 }
739
740 gp->g_data = (void *)md;
741 gi->gd_regaddr = (void *)ztwopa(ba);
742 gi->gd_regsize = 64*1024;
743
744 gi->gd_fbaddr = (void *)ztwopa(fb);
745 gi->gd_fbsize = 64*1024; /* larger, but that's whats mappable */
746
747 gi->gd_colors = 1 << md->DEP;
748 gi->gd_planes = md->DEP;
749
750 gi->gd_fbwidth = md->MW;
751 gi->gd_fbheight = md->MH;
752 gi->gd_fbx = 0;
753 gi->gd_fby = 0;
754 gi->gd_dwidth = md->TX * md->FX;
755 gi->gd_dheight = md->TY * md->FY;
756 gi->gd_dx = 0;
757 gi->gd_dy = 0;
758
759 /* initialized, works, return 1 */
760 return(1);
761 }
762
763 void grfrtattach(struct device *, struct device *, void *);
764 int grfrtprint(void *, const char *);
765 int grfrtmatch(struct device *, struct cfdata *, void *);
766
767 int rt_mode(struct grf_softc *, u_long, void *, u_long, int);
768 static int rt_getvmode(struct grf_softc *, struct grfvideo_mode *);
769 static int rt_setvmode(struct grf_softc *, unsigned, int);
770 int rt_getspritepos(struct grf_softc *, struct grf_position *);
771 int rt_setspritepos(struct grf_softc *, struct grf_position *);
772 int rt_getspriteinfo(struct grf_softc *, struct grf_spriteinfo *);
773 int rt_setspriteinfo(struct grf_softc *, struct grf_spriteinfo *);
774 int rt_getspritemax(struct grf_softc *, struct grf_position *);
775 int rt_getcmap(struct grf_softc *, struct grf_colormap *);
776 int rt_putcmap(struct grf_softc *, struct grf_colormap *);
777 int rt_bitblt(struct grf_softc *, struct grf_bitblt *);
778 int rt_blank(struct grf_softc *, int *);
779
780 CFATTACH_DECL(grfrt, sizeof(struct grf_softc),
781 grfrtmatch, grfrtattach, NULL, NULL);
782
783 /*
784 * only used in console init
785 */
786 static struct cfdata *cfdata;
787
788 /*
789 * we make sure to only init things once. this is somewhat
790 * tricky regarding the console.
791 */
792 int
793 grfrtmatch(struct device *pdp, struct cfdata *cfp, void *auxp)
794 {
795 #ifdef RETINACONSOLE
796 static int rtconunit = -1;
797 #endif
798 struct zbus_args *zap;
799
800 zap = auxp;
801
802 /*
803 * allow only one retina console
804 */
805 if (amiga_realconfig == 0)
806 #ifdef RETINACONSOLE
807 if (rtconunit != -1)
808 #endif
809 return(0);
810 /*
811 * check that this is a retina board.
812 */
813 if (zap->manid != 18260 || zap->prodid != 6)
814 return(0);
815
816 #ifdef RETINACONSOLE
817 if (amiga_realconfig == 0 || rtconunit != cfp->cf_unit) {
818 #endif
819 if ((unsigned)retina_default_mon >= retina_mon_max ||
820 monitor_defs[retina_default_mon].DEP == 8)
821 retina_default_mon = 0;
822
823 current_mon = monitor_defs + retina_default_mon;
824 if (retina_alive(current_mon) == 0)
825 return(0);
826 #ifdef RETINACONSOLE
827 if (amiga_realconfig == 0) {
828 rtconunit = cfp->cf_unit;
829 cfdata = cfp;
830 }
831 }
832 #endif
833 return(1);
834 }
835
836 /*
837 * attach to the grfbus (zbus)
838 */
839 void
840 grfrtattach(struct device *pdp, struct device *dp, void *auxp)
841 {
842 static struct grf_softc congrf;
843 struct zbus_args *zap;
844 struct grf_softc *gp;
845
846 zap = auxp;
847
848 if (dp == NULL)
849 gp = &congrf;
850 else
851 gp = (struct grf_softc *)dp;
852
853 if (dp != NULL && congrf.g_regkva != 0) {
854 /*
855 * we inited earlier just copy the info
856 * take care not to copy the device struct though.
857 */
858 bcopy(&congrf.g_display, &gp->g_display,
859 (char *)&gp[1] - (char *)&gp->g_display);
860 } else {
861 gp->g_regkva = (volatile void *)zap->va;
862 gp->g_fbkva = (volatile void *)zap->va + 64 * 1024;
863 gp->g_unit = GRF_RETINAII_UNIT;
864 gp->g_flags = GF_ALIVE;
865 gp->g_mode = rt_mode;
866 gp->g_conpri = grfrt_cnprobe();
867 grfrt_iteinit(gp);
868 (void)rt_load_mon(gp, current_mon);
869 }
870 if (dp != NULL)
871 printf("\n");
872 /*
873 * attach grf
874 */
875 amiga_config_found(cfdata, &gp->g_device, gp, grfrtprint);
876 }
877
878 int
879 grfrtprint(void *auxp, const char *pnp)
880 {
881 if (pnp)
882 aprint_normal("grf%d at %s", ((struct grf_softc *)auxp)->g_unit,
883 pnp);
884 return(UNCONF);
885 }
886
887 static int
888 rt_getvmode(struct grf_softc *gp, struct grfvideo_mode *vm)
889 {
890 struct MonDef *md;
891 int vmul;
892
893 if (vm->mode_num && vm->mode_num > retina_mon_max)
894 return (EINVAL);
895
896 if (! vm->mode_num)
897 vm->mode_num = (current_mon - monitor_defs) + 1;
898
899 md = monitor_defs + (vm->mode_num - 1);
900 strncpy (vm->mode_descr, monitor_descr[vm->mode_num - 1],
901 sizeof (vm->mode_descr));
902 vm->pixel_clock = md->FQ;
903 vm->disp_width = md->MW;
904 vm->disp_height = md->MH;
905 vm->depth = md->DEP;
906
907 /*
908 * From observation of the monitor definition table above, I guess that
909 * the horizontal timings are in units of longwords. Hence, I get the
910 * pixels by multiplication with 32 and division by the depth.
911 * The text modes, apparently marked by depth == 4, are even more weird.
912 * According to a comment above, they are computed from a depth==8 mode
913 * (thats for us: * 32 / 8) by applying another factor of 4 / font width.
914 * Reverse applying the latter formula most of the constants cancel
915 * themselves and we are left with a nice (* font width).
916 * That is, internal timings are in units of longwords for graphics
917 * modes, or in units of characters widths for text modes.
918 * We better don't WRITE modes until this has been real live checked.
919 * - Ignatios Souvatzis
920 */
921
922 if (md->DEP != 4) {
923 vm->hblank_start = md->HBS * 32 / md->DEP;
924 vm->hsync_start = md->HSS * 32 / md->DEP;
925 vm->hsync_stop = md->HSE * 32 / md->DEP;
926 vm->htotal = md->HT * 32 / md->DEP;
927 } else {
928 vm->hblank_start = md->HBS * md->FX;
929 vm->hsync_start = md->HSS * md->FX;
930 vm->hsync_stop = md->HSE * md->FX;
931 vm->htotal = md->HT * md->FX;
932 }
933
934
935 /* XXX move vm->disp_flags and vmul to rt_load_mon
936 * if rt_setvmode can add new modes with grfconfig */
937 vm->disp_flags = 0;
938 vmul = 2;
939 if (md->FLG & MDF_DBL) {
940 vm->disp_flags |= GRF_FLAGS_DBLSCAN;
941 vmul = 4;
942 }
943 if (md->FLG & MDF_LACE) {
944 vm->disp_flags |= GRF_FLAGS_LACE;
945 vmul = 1;
946 }
947 vm->vblank_start = md->VBS * vmul / 2;
948 vm->vsync_start = md->VSS * vmul / 2;
949 vm->vsync_stop = md->VSE * vmul / 2;
950 vm->vtotal = md->VT * vmul / 2;
951
952 return (0);
953 }
954
955
956 static int
957 rt_setvmode(struct grf_softc *gp, unsigned mode, int txtonly)
958 {
959 int error;
960
961 if (!mode || mode > retina_mon_max)
962 return (EINVAL);
963
964 if (txtonly && monitor_defs[mode-1].DEP == 8)
965 return (EINVAL);
966
967 current_mon = monitor_defs + (mode - 1);
968
969 error = rt_load_mon (gp, current_mon) ? 0 : EINVAL;
970
971 return (error);
972 }
973
974
975 /*
976 * Change the mode of the display.
977 * Return a UNIX error number or 0 for success.
978 */
979 int
980 rt_mode(struct grf_softc *gp, u_long cmd, void *arg, u_long a2, int a3)
981 {
982 /* implement these later... */
983
984 switch (cmd) {
985 case GM_GRFON:
986 rt_setvmode (gp, retina_default_gfx + 1, 0);
987 return (0);
988
989 case GM_GRFOFF:
990 rt_setvmode (gp, retina_default_mon + 1, 0);
991 return (0);
992
993 case GM_GRFCONFIG:
994 return (0);
995
996 case GM_GRFGETVMODE:
997 return (rt_getvmode (gp, (struct grfvideo_mode *) arg));
998
999 case GM_GRFSETVMODE:
1000 return (rt_setvmode (gp, *(unsigned *) arg, 1));
1001
1002 case GM_GRFGETNUMVM:
1003 *(int *)arg = retina_mon_max;
1004 return (0);
1005
1006 case GM_GRFIOCTL:
1007 return (rt_ioctl (gp, a2, arg));
1008
1009 default:
1010 break;
1011 }
1012
1013 return (EPASSTHROUGH);
1014 }
1015
1016 int
1017 rt_ioctl(register struct grf_softc *gp, u_long cmd, void *data)
1018 {
1019 switch (cmd) {
1020 case GRFIOCGSPRITEPOS:
1021 return (rt_getspritepos (gp, (struct grf_position *) data));
1022
1023 case GRFIOCSSPRITEPOS:
1024 return (rt_setspritepos (gp, (struct grf_position *) data));
1025
1026 case GRFIOCSSPRITEINF:
1027 return (rt_setspriteinfo (gp, (struct grf_spriteinfo *) data));
1028
1029 case GRFIOCGSPRITEINF:
1030 return (rt_getspriteinfo (gp, (struct grf_spriteinfo *) data));
1031
1032 case GRFIOCGSPRITEMAX:
1033 return (rt_getspritemax (gp, (struct grf_position *) data));
1034
1035 case GRFIOCGETCMAP:
1036 return (rt_getcmap (gp, (struct grf_colormap *) data));
1037
1038 case GRFIOCPUTCMAP:
1039 return (rt_putcmap (gp, (struct grf_colormap *) data));
1040
1041 case GRFIOCBITBLT:
1042 return (rt_bitblt (gp, (struct grf_bitblt *) data));
1043
1044 case GRFIOCBLANK:
1045 return (rt_blank(gp, (int *)data));
1046 }
1047
1048 return (EPASSTHROUGH);
1049 }
1050
1051 int
1052 rt_getcmap(struct grf_softc *gfp, struct grf_colormap *cmap)
1053 {
1054 volatile unsigned char *ba;
1055 u_char red[256], green[256], blue[256], *rp, *gp, *bp;
1056 short x;
1057 int error;
1058
1059 if (cmap->count == 0 || cmap->index >= 256)
1060 return (0);
1061
1062 if (cmap->count > 256 - cmap->index)
1063 cmap->count = 256 - cmap->index;
1064
1065 ba = gfp->g_regkva;
1066 /* first read colors out of the chip, then copyout to userspace */
1067 vgaw (ba, VDAC_REG_SELECT, cmap->index);
1068 x = cmap->count - 1;
1069 rp = red + cmap->index;
1070 gp = green + cmap->index;
1071 bp = blue + cmap->index;
1072 do {
1073 *rp++ = vgar (ba, VDAC_REG_DATA);
1074 *gp++ = vgar (ba, VDAC_REG_DATA);
1075 *bp++ = vgar (ba, VDAC_REG_DATA);
1076 }
1077 while (x--);
1078
1079 if (!(error = copyout (red + cmap->index, cmap->red, cmap->count))
1080 && !(error = copyout (green + cmap->index, cmap->green, cmap->count))
1081 && !(error = copyout (blue + cmap->index, cmap->blue, cmap->count)))
1082 return (0);
1083
1084 return (error);
1085 }
1086
1087 int
1088 rt_putcmap(struct grf_softc *gfp, struct grf_colormap *cmap)
1089 {
1090 volatile unsigned char *ba;
1091 u_char red[256], green[256], blue[256], *rp, *gp, *bp;
1092 short x;
1093 int error;
1094
1095 if (cmap->count == 0 || cmap->index >= 256)
1096 return 0;
1097
1098 if (cmap->count > 256 - cmap->index)
1099 cmap->count = 256 - cmap->index;
1100
1101 /* first copy the colors into kernelspace */
1102 if (!(error = copyin (cmap->red, red + cmap->index, cmap->count))
1103 && !(error = copyin (cmap->green, green + cmap->index, cmap->count))
1104 && !(error = copyin (cmap->blue, blue + cmap->index, cmap->count)))
1105 {
1106 ba = gfp->g_regkva;
1107 vgaw (ba, VDAC_REG_SELECT, cmap->index);
1108 x = cmap->count - 1;
1109 rp = red + cmap->index;
1110 gp = green + cmap->index;
1111 bp = blue + cmap->index;
1112 do {
1113 vgaw (ba, VDAC_REG_DATA, *rp++);
1114 vgaw (ba, VDAC_REG_DATA, *gp++);
1115 vgaw (ba, VDAC_REG_DATA, *bp++);
1116 }
1117 while (x--);
1118 return (0);
1119 } else
1120 return (error);
1121 }
1122
1123
1124 int
1125 rt_getspritepos(struct grf_softc *gp, struct grf_position *pos)
1126 {
1127 volatile unsigned char *ba;
1128
1129 ba = gp->g_regkva;
1130 pos->x = vgar (ba, SEQ_ID_CURSOR_X_LOC_LO) |
1131 (vgar (ba, SEQ_ID_CURSOR_X_LOC_HI) << 8);
1132 pos->y = vgar (ba, SEQ_ID_CURSOR_Y_LOC_LO) |
1133 (vgar (ba, SEQ_ID_CURSOR_Y_LOC_HI) << 8);
1134 return (0);
1135 }
1136
1137 int
1138 rt_setspritepos(struct grf_softc *gp, struct grf_position *pos)
1139 {
1140 volatile unsigned char *ba;
1141
1142 ba = gp->g_regkva;
1143 vgaw (ba, SEQ_ID_CURSOR_X_LOC_LO, pos->x & 0xff);
1144 vgaw (ba, SEQ_ID_CURSOR_X_LOC_HI, (pos->x >> 8) & 0x07);
1145 vgaw (ba, SEQ_ID_CURSOR_Y_LOC_LO, pos->y & 0xff);
1146 vgaw (ba, SEQ_ID_CURSOR_Y_LOC_HI, (pos->y >> 8) & 0x07);
1147 return (0);
1148 }
1149
1150 /* assume an at least 2M retina (XXX), sprite is last in memory.
1151 * According to the bogus docs, the cursor can be at most 128 lines
1152 * in height, and the x-hostspot can be placed at most at pos 31,
1153 * this gives width of a long
1154 */
1155 #define SPRITE_ADDR (2*1024*1024 - 128*4)
1156
1157 int
1158 rt_getspriteinfo(struct grf_softc *gp, struct grf_spriteinfo *info)
1159 {
1160 volatile void *ba, fb;
1161
1162 ba = gp->g_regkva;
1163 fb = gp->g_fbkva;
1164 if (info->set & GRFSPRSET_ENABLE)
1165 info->enable = vgar (ba, SEQ_ID_CURSOR_CONTROL) & 0x01;
1166 if (info->set & GRFSPRSET_POS)
1167 rt_getspritepos (gp, &info->pos);
1168 if (info->set & GRFSPRSET_HOT) {
1169 info->hot.x = vgar (ba, SEQ_ID_CURSOR_X_INDEX) & 0x1f;
1170 info->hot.y = vgar (ba, SEQ_ID_CURSOR_Y_INDEX) & 0x7f;
1171 }
1172 if (info->set & GRFSPRSET_CMAP) {
1173 struct grf_colormap cmap;
1174 int index;
1175 cmap.index = 0;
1176 cmap.count = 256;
1177 rt_getcmap (gp, &cmap);
1178 index = vgar (ba, SEQ_ID_CURSOR_COLOR0);
1179 info->cmap.red[0] = cmap.red[index];
1180 info->cmap.green[0] = cmap.green[index];
1181 info->cmap.blue[0] = cmap.blue[index];
1182 index = vgar (ba, SEQ_ID_CURSOR_COLOR1);
1183 info->cmap.red[1] = cmap.red[index];
1184 info->cmap.green[1] = cmap.green[index];
1185 info->cmap.blue[1] = cmap.blue[index];
1186 }
1187 if (info->set & GRFSPRSET_SHAPE) {
1188 int saved_bank_lo = RSeq (ba, SEQ_ID_PRIM_HOST_OFF_LO);
1189 int saved_bank_hi = RSeq (ba, SEQ_ID_PRIM_HOST_OFF_HI);
1190 int last_bank = SPRITE_ADDR >> 6;
1191 int last_bank_lo = last_bank & 0xff;
1192 int last_bank_hi = last_bank >> 8;
1193 u_char mask;
1194 WSeq (ba, SEQ_ID_PRIM_HOST_OFF_LO, last_bank_lo);
1195 WSeq (ba, SEQ_ID_PRIM_HOST_OFF_HI, last_bank_hi);
1196 copyout (fb, info->image, 128*4);
1197 mask = RSeq (ba, SEQ_ID_CURSOR_PIXELMASK);
1198 WSeq (ba, SEQ_ID_PRIM_HOST_OFF_LO, saved_bank_lo);
1199 WSeq (ba, SEQ_ID_PRIM_HOST_OFF_HI, saved_bank_hi);
1200 copyout (&mask, info->mask, 1);
1201 info->size.x = 32; /* ??? */
1202 info->size.y = (RSeq (ba, SEQ_ID_CURSOR_CONTROL) & 6) << 4;
1203 }
1204
1205 return (0);
1206 }
1207
1208
1209 int
1210 rt_setspriteinfo(struct grf_softc *gp, struct grf_spriteinfo *info)
1211 {
1212 volatile void *ba, fb;
1213 u_char control;
1214
1215 ba = gp->g_regkva;
1216 fb = gp->g_fbkva;
1217 control = vgar (ba, SEQ_ID_CURSOR_CONTROL);
1218 if (info->set & GRFSPRSET_ENABLE) {
1219 if (info->enable)
1220 control |= 1;
1221 else
1222 control &= ~1;
1223 vgaw (ba, SEQ_ID_CURSOR_CONTROL, control);
1224 }
1225 if (info->set & GRFSPRSET_POS)
1226 rt_setspritepos (gp, &info->pos);
1227 if (info->set & GRFSPRSET_HOT) {
1228 vgaw (ba, SEQ_ID_CURSOR_X_INDEX, info->hot.x & 0x1f);
1229 vgaw (ba, SEQ_ID_CURSOR_Y_INDEX, info->hot.y & 0x7f);
1230 }
1231 if (info->set & GRFSPRSET_CMAP) {
1232 /* hey cheat a bit here.. XXX */
1233 vgaw (ba, SEQ_ID_CURSOR_COLOR0, 0);
1234 vgaw (ba, SEQ_ID_CURSOR_COLOR1, 1);
1235 }
1236 if (info->set & GRFSPRSET_SHAPE) {
1237 int saved_bank_lo = RSeq (ba, SEQ_ID_PRIM_HOST_OFF_LO);
1238 int saved_bank_hi = RSeq (ba, SEQ_ID_PRIM_HOST_OFF_HI);
1239 int last_bank = SPRITE_ADDR >> 6;
1240 int last_bank_lo = last_bank & 0xff;
1241 int last_bank_hi = last_bank >> 8;
1242 u_char mask;
1243 WSeq (ba, SEQ_ID_PRIM_HOST_OFF_LO, last_bank_lo);
1244 WSeq (ba, SEQ_ID_PRIM_HOST_OFF_HI, last_bank_hi);
1245 copyin (info->image, fb, 128*4);
1246 WSeq (ba, SEQ_ID_PRIM_HOST_OFF_LO, saved_bank_lo);
1247 WSeq (ba, SEQ_ID_PRIM_HOST_OFF_HI, saved_bank_hi);
1248 copyin (info->mask, &mask, 1);
1249 WSeq (ba, SEQ_ID_CURSOR_PIXELMASK, mask);
1250 /* info->size.x = 32; *//* ??? */
1251
1252 info->size.y = (RSeq (ba, SEQ_ID_CURSOR_CONTROL) & 6) << 4;
1253 control = (control & ~6) | ((info->size.y >> 4) & 6);
1254 vgaw (ba, SEQ_ID_CURSOR_CONTROL, control);
1255
1256 /* sick intel bull-addressing.. */
1257 WSeq (ba, SEQ_ID_CURSOR_STORE_LO, SPRITE_ADDR & 0x0f);
1258 WSeq (ba, SEQ_ID_CURSOR_STORE_HI, 0);
1259 WSeq (ba, SEQ_ID_CURSOR_ST_OFF_LO, (SPRITE_ADDR >> 4) & 0xff);
1260 WSeq (ba, SEQ_ID_CURSOR_ST_OFF_HI, ((SPRITE_ADDR >> 4) >> 8) & 0xff);
1261 }
1262
1263 return (0);
1264 }
1265
1266
1267 int
1268 rt_getspritemax(struct grf_softc *gp, struct grf_position *pos)
1269 {
1270 pos->x = 32;
1271 pos->y = 128;
1272
1273 return (0);
1274 }
1275
1276
1277 /*
1278 * !!! THIS AREA UNDER CONSTRUCTION !!!
1279 */
1280
1281 int
1282 rt_bitblt(struct grf_softc *gp, struct grf_bitblt *bb)
1283 {
1284 return (EINVAL);
1285
1286 #if 0
1287 volatile void *ba, fb;
1288 u_char control;
1289 u_char saved_bank_lo;
1290 u_char saved_bank_hi;
1291 u_char src_bank_lo, src_bank_hi;
1292 u_char dst_bank_lo, dst_bank_hi;
1293 u_long src_offset, dst_offset;
1294 u_short src_bank, dst_bank;
1295 u_char *srcp, *dstp;
1296 short x, y;
1297 u_long tot;
1298
1299 ba = gp->g_regkva;
1300 fb = gp->g_fbkva;
1301
1302 saved_bank_lo = RSeq (ba, SEQ_ID_PRIM_HOST_OFF_LO);
1303 saved_bank_hi = RSeq (ba, SEQ_ID_PRIM_HOST_OFF_HI);
1304
1305 /* for now, only GRFBBcopy is supported, and only for depth 8. No
1306 clipping is performed, either... */
1307
1308 if (bb->op != GRFBBcopy && gp->g_display.gd_planes != 8)
1309 return EINVAL;
1310
1311 src_offset = op->src_x + op->src_y * gp->g_display.gd_fbwidth;
1312 dst_offset = op->dst_x + op->dst_y * gp->g_display.gd_fbwidth;
1313 tot = op->w * op->h;
1314
1315 /* set write mode 1, "[...] data in the read latches is written
1316 to memory during CPU memory write cycles. [...]" */
1317 WGfx (ba, GCT_ID_GRAPHICS_MODE, (RGfx(ba, GCT_ID_GRAPHICS_MODE) & 0xfc) | 1);
1318 /* write to primary, read from secondary */
1319 WSeq (ba, SEQ_ID_EXTENDED_MEM_ENA, (RSeq(ba, SEQ_ID_EXTENDED_MEM_ENA) & 0x1f) | 0 );
1320
1321 if (src_offset < dst_offset)
1322 {
1323 /* start at end */
1324 src_offset += tot;
1325 dst_offset += tot;
1326 }
1327
1328 src_bank_lo = (src_offset >> 6) & 0xff;
1329 src_bank_hi = (src_offset >> 14) & 0xff;
1330 dst_bank_lo = (dst_offset >> 6) & 0xff;
1331 dst_bank_hi = (dst_offset >> 14) & 0xff;
1332
1333 while (tot)
1334 {
1335 WSeq (ba, SEQ_ID_SEC_HOST_OFF_LO, src_bank_lo);
1336 WSeq (ba, SEQ_ID_SEC_HOST_OFF_HI, src_bank_hi);
1337 WSeq (ba, SEQ_ID_PRIM_HOST_OFF_LO, dst_bank_lo);
1338 WSeq (ba, SEQ_ID_PRIM_HOST_OFF_HI, dst_bank_hi);
1339
1340 if (src_offset < dst_offset)
1341 {
1342
1343
1344 }
1345 else
1346 {
1347
1348 }
1349 }
1350
1351
1352 #endif
1353 }
1354
1355
1356 int
1357 rt_blank(struct grf_softc *gp, int *on)
1358 {
1359 struct MonDef *md = (struct MonDef *)gp->g_data;
1360 int r;
1361
1362 r = 0x01 | ((md->FLG & MDF_CLKDIV2)/ MDF_CLKDIV2 * 8);
1363
1364 WSeq(gp->g_regkva, SEQ_ID_CLOCKING_MODE, *on > 0 ? r : 0x21);
1365
1366 return(0);
1367 }
1368
1369 #endif /* NGRF */
1370