smg.c revision 1.4 1 /* $NetBSD: smg.c,v 1.4 1998/06/20 21:59:44 drochner Exp $ */
2 /*
3 * Copyright (c) 1998 Ludd, University of Lule}, Sweden.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed at Ludd, University of
17 * Lule}, Sweden and its contributors.
18 * 4. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33
34
35
36 #include <sys/types.h>
37 #include <sys/param.h>
38 #include <sys/device.h>
39 #include <sys/systm.h>
40 #include <sys/time.h>
41 #include <sys/malloc.h>
42 #include <sys/conf.h>
43
44 #include <dev/cons.h>
45
46 #include <dev/wscons/wsdisplayvar.h>
47 #include <dev/wscons/wsconsio.h>
48 #include <dev/wscons/wscons_callbacks.h>
49
50 #include <machine/vsbus.h>
51 #include <machine/sid.h>
52
53 #include "lkc.h"
54
55 #define SM_COLS 128 /* char width of screen */
56 #define SM_ROWS 57 /* rows of char on screen */
57 #define SM_CHEIGHT 15 /* lines a char consists of */
58 #define SM_NEXTROW (SM_COLS * SM_CHEIGHT)
59
60 static int smg_match __P((struct device *, struct cfdata *, void *));
61 static void smg_attach __P((struct device *, struct device *, void *));
62
63 struct smg_softc {
64 struct device ss_dev;
65 };
66
67 struct cfattach smg_ca = {
68 sizeof(struct smg_softc), smg_match, smg_attach,
69 };
70
71 static void smg_cursor __P((void *, int, int, int));
72 static void smg_putchar __P((void *, int, int, u_int, long));
73 static void smg_copycols __P((void *, int, int, int,int));
74 static void smg_erasecols __P((void *, int, int, int, long));
75 static void smg_copyrows __P((void *, int, int, int));
76 static void smg_eraserows __P((void *, int, int, long));
77 static int smg_alloc_attr __P((void *, int, int, int, long *));
78
79 const struct wsdisplay_emulops smg_emulops = {
80 smg_cursor,
81 smg_putchar,
82 smg_copycols,
83 smg_erasecols,
84 smg_copyrows,
85 smg_eraserows,
86 smg_alloc_attr
87 };
88
89 const struct wsscreen_descr smg_stdscreen = {
90 "128x57", 128, 57,
91 &smg_emulops,
92 8, 15,
93 0, /* WSSCREEN_UNDERLINE??? */
94 };
95
96 const struct wsscreen_descr *_smg_scrlist[] = {
97 &smg_stdscreen,
98 };
99
100 const struct wsscreen_list smg_screenlist = {
101 sizeof(_smg_scrlist) / sizeof(struct wsscreen_descr *),
102 _smg_scrlist,
103 };
104
105 static int smg_ioctl __P((void *, u_long, caddr_t, int, struct proc *));
106 static int smg_mmap __P((void *, off_t, int));
107 static int smg_alloc_screen __P((void *, const struct wsscreen_descr *,
108 void **, int *, int *, long *));
109 static void smg_free_screen __P((void *, void *));
110 static void smg_show_screen __P((void *, void *));
111 static int smg_load_font __P((void *, void *, int, int, int, void *));
112
113 const struct wsdisplay_accessops smg_accessops = {
114 smg_ioctl,
115 smg_mmap,
116 smg_alloc_screen,
117 smg_free_screen,
118 smg_show_screen,
119 smg_load_font
120 };
121
122 struct smg_screen {
123 int ss_curx;
124 int ss_cury;
125 u_char ss_image[SM_ROWS][SM_COLS]; /* Image of current screen */
126 };
127
128 static struct smg_screen smg_conscreen;
129 static struct smg_screen *curscr;
130
131 int
132 smg_match(parent, match, aux)
133 struct device *parent;
134 struct cfdata *match;
135 void *aux;
136 {
137 struct vsbus_attach_args *va = aux;
138
139 if (va->va_type != INR_VF)
140 return 0;
141 #ifdef DIAGNOSTIC
142 if (sm_addr == 0)
143 panic("smg: inconsistency in smg address mapping");
144 #endif
145 return 1;
146 }
147
148 void
149 smg_attach(parent, self, aux)
150 struct device *parent, *self;
151 void *aux;
152 {
153 struct wsemuldisplaydev_attach_args aa;
154
155 printf("\n");
156 curscr = &smg_conscreen;
157 aa.console = !(vax_confdata & 0x20);
158 aa.scrdata = &smg_screenlist;
159 aa.accessops = &smg_accessops;
160
161 config_found(self, &aa, wsemuldisplaydevprint);
162 }
163
164 void
165 smg_cursor(id, on, row, col)
166 void *id;
167 int on, row, col;
168 {
169 struct smg_screen *ss = id;
170
171 ss->ss_curx = col;
172 ss->ss_cury = row;
173 if (ss == curscr)
174 sm_addr[(row * 15 * 128) + col + (14 * 128)] = on ? 255 : 0;
175 }
176
177 static void
178 smg_putchar(id, row, col, c, attr)
179 void *id;
180 int row, col;
181 u_int c;
182 long attr;
183 {
184 struct smg_screen *ss = id;
185 int i;
186 extern char q_font[];
187
188 c &= 0xff;
189
190 ss->ss_image[row][col] = c;
191 if (ss != curscr)
192 return;
193 for (i = 0; i < 15; i++)
194 sm_addr[col + (row * 15 * 128) + i * 128] =
195 q_font[(c - 32) * 15 + i];
196 }
197
198 /*
199 * copies columns inside a row.
200 */
201 static void
202 smg_copycols(id, row, srccol, dstcol, ncols)
203 void *id;
204 int row, srccol, dstcol, ncols;
205 {
206 struct smg_screen *ss = id;
207 int i;
208
209 bcopy(&ss->ss_image[row][srccol], &ss->ss_image[row][dstcol], ncols);
210 if (ss != curscr)
211 return;
212 for (i = 0; i < SM_CHEIGHT; i++)
213 bcopy(&sm_addr[(row * SM_NEXTROW) + srccol + (i * 128)],
214 &sm_addr[(row * SM_NEXTROW) + dstcol + i*128], ncols);
215
216 }
217
218 /*
219 * Erases a bunch of chars inside one row.
220 */
221 static void
222 smg_erasecols(id, row, startcol, ncols, fillattr)
223 void *id;
224 int row, startcol, ncols;
225 long fillattr;
226 {
227 struct smg_screen *ss = id;
228 int i;
229
230 bzero(&ss->ss_image[row][startcol], ncols);
231 if (ss != curscr)
232 return;
233 for (i = 0; i < SM_CHEIGHT; i++)
234 bzero(&sm_addr[(row * SM_NEXTROW) + startcol + i * 128], ncols);
235 }
236
237 static void
238 smg_copyrows(id, srcrow, dstrow, nrows)
239 void *id;
240 int srcrow, dstrow, nrows;
241 {
242 struct smg_screen *ss = id;
243 int frows;
244
245 bcopy(&ss->ss_image[srcrow][0], &ss->ss_image[dstrow][0], nrows * 128);
246 if (ss != curscr)
247 return;
248 if (nrows > 25) {
249 frows = nrows >> 1;
250 if (srcrow > dstrow) {
251 bcopy(&sm_addr[(srcrow * SM_NEXTROW)],
252 &sm_addr[(dstrow * SM_NEXTROW)],
253 frows * SM_NEXTROW);
254 bcopy(&sm_addr[((srcrow + frows) * SM_NEXTROW)],
255 &sm_addr[((dstrow + frows) * SM_NEXTROW)],
256 (nrows - frows) * SM_NEXTROW);
257 } else {
258 bcopy(&sm_addr[((srcrow + frows) * SM_NEXTROW)],
259 &sm_addr[((dstrow + frows) * SM_NEXTROW)],
260 (nrows - frows) * SM_NEXTROW);
261 bcopy(&sm_addr[(srcrow * SM_NEXTROW)],
262 &sm_addr[(dstrow * SM_NEXTROW)],
263 frows * SM_NEXTROW);
264 }
265 } else
266 bcopy(&sm_addr[(srcrow * SM_NEXTROW)],
267 &sm_addr[(dstrow * SM_NEXTROW)], nrows * SM_NEXTROW);
268 }
269
270 static void
271 smg_eraserows(id, startrow, nrows, fillattr)
272 void *id;
273 int startrow, nrows;
274 long fillattr;
275 {
276 struct smg_screen *ss = id;
277 int frows;
278
279 bzero(&ss->ss_image[startrow][0], nrows * 128);
280 if (ss != curscr)
281 return;
282 if (nrows > 25) {
283 frows = nrows >> 1;
284 bzero(&sm_addr[(startrow * SM_NEXTROW)], frows * SM_NEXTROW);
285 bzero(&sm_addr[((startrow + frows) * SM_NEXTROW)],
286 (nrows - frows) * SM_NEXTROW);
287 } else
288 bzero(&sm_addr[(startrow * SM_NEXTROW)], nrows * SM_NEXTROW);
289 }
290
291 static int
292 smg_alloc_attr(id, fg, bg, flags, attrp)
293 void *id;
294 int fg, bg;
295 int flags;
296 long *attrp;
297 {
298 return 0;
299 }
300
301 int
302 smg_ioctl(v, cmd, data, flag, p)
303 void *v;
304 u_long cmd;
305 caddr_t data;
306 int flag;
307 struct proc *p;
308 {
309 return -1;
310 }
311
312 static int
313 smg_mmap(v, offset, prot)
314 void *v;
315 off_t offset;
316 int prot;
317 {
318 return -1;
319 }
320
321 int
322 smg_alloc_screen(v, type, cookiep, curxp, curyp, defattrp)
323 void *v;
324 const struct wsscreen_descr *type;
325 void **cookiep;
326 int *curxp, *curyp;
327 long *defattrp;
328 {
329 *cookiep = malloc(sizeof(struct smg_screen), M_DEVBUF, M_WAITOK);
330 bzero(*cookiep, sizeof(struct smg_screen));
331 *curxp = *curyp = *defattrp = 0;
332 return 0;
333 }
334
335 void
336 smg_free_screen(v, cookie)
337 void *v;
338 void *cookie;
339 {
340 }
341
342 void
343 smg_show_screen(v, cookie)
344 void *v;
345 void *cookie;
346 {
347 struct smg_screen *ss = cookie;
348 int row, col, line;
349 extern char q_font[];
350
351 if (ss == curscr)
352 return;
353
354 for (row = 0; row < 57; row++)
355 for (line = 0; line < 15; line++)
356 for (col = 0; col < 128; col++) {
357 u_char c = ss->ss_image[row][col];
358
359 if (c > 0x9f)
360 c -= 64;
361 else if (c > 0x1f)
362 c -= 32;
363 sm_addr[row * 128 * 15 + line * 128 + col] =
364 q_font[c * 15 + line];
365 }
366 curscr = ss;
367 }
368
369 static int
370 smg_load_font(v, cookie, first, num, stride, data)
371 void *v;
372 void *cookie;
373 int first, num, stride;
374 void *data;
375 {
376 return 0;
377 }
378
379 cons_decl(smg);
380
381 #define WSCONSOLEMAJOR 68
382
383 void
384 smgcninit(cndev)
385 struct consdev *cndev;
386 {
387 extern void lkccninit __P((struct consdev *));
388 extern int lkccngetc __P((dev_t));
389 /* Clear screen */
390 blkclr(sm_addr, 128*864);
391
392 curscr = &smg_conscreen;
393 wsdisplay_cnattach(&smg_stdscreen, &smg_conscreen, 0, 0, 0);
394 cn_tab->cn_dev = makedev(WSCONSOLEMAJOR, 0);
395 #if NLKC
396 lkccninit(cndev);
397 wsdisplay_set_cons_kbd(lkccngetc, nullcnpollc);
398 #endif
399 }
400
401 int smgprobe(void);
402 int
403 smgprobe()
404 {
405 switch (vax_boardtype) {
406 case VAX_BTYP_410:
407 case VAX_BTYP_420:
408 case VAX_BTYP_43:
409 if (vax_confdata & 0x20) /* doesn't use graphics console */
410 break;
411 if (sm_addr == 0) /* Haven't mapped graphic area */
412 break;
413
414 return 1;
415
416 default:
417 break;
418 }
419 return 0;
420 }
421