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