smg.c revision 1.62 1 1.62 tsutsui /* $NetBSD: smg.c,v 1.62 2023/01/13 19:45:45 tsutsui Exp $ */
2 1.1 ragge /*
3 1.1 ragge * Copyright (c) 1998 Ludd, University of Lule}, Sweden.
4 1.1 ragge * All rights reserved.
5 1.1 ragge *
6 1.1 ragge * Redistribution and use in source and binary forms, with or without
7 1.1 ragge * modification, are permitted provided that the following conditions
8 1.1 ragge * are met:
9 1.1 ragge * 1. Redistributions of source code must retain the above copyright
10 1.1 ragge * notice, this list of conditions and the following disclaimer.
11 1.1 ragge * 2. Redistributions in binary form must reproduce the above copyright
12 1.1 ragge * notice, this list of conditions and the following disclaimer in the
13 1.1 ragge * documentation and/or other materials provided with the distribution.
14 1.1 ragge *
15 1.1 ragge * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 1.1 ragge * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 1.1 ragge * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 1.1 ragge * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 1.1 ragge * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 1.1 ragge * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 1.1 ragge * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 1.1 ragge * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 1.1 ragge * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 1.1 ragge * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 1.1 ragge */
26 1.37 lukem
27 1.37 lukem #include <sys/cdefs.h>
28 1.62 tsutsui __KERNEL_RCSID(0, "$NetBSD: smg.c,v 1.62 2023/01/13 19:45:45 tsutsui Exp $");
29 1.1 ragge
30 1.1 ragge #include <sys/param.h>
31 1.1 ragge #include <sys/systm.h>
32 1.21 thorpej #include <sys/callout.h>
33 1.1 ragge #include <sys/conf.h>
34 1.54 matt #include <sys/cpu.h>
35 1.54 matt #include <sys/device.h>
36 1.6 ragge #include <sys/kernel.h>
37 1.59 thorpej #include <sys/kmem.h>
38 1.54 matt #include <sys/time.h>
39 1.1 ragge
40 1.26 ragge #include <machine/vsbus.h>
41 1.26 ragge #include <machine/sid.h>
42 1.26 ragge #include <machine/ka420.h>
43 1.26 ragge
44 1.1 ragge #include <dev/cons.h>
45 1.1 ragge
46 1.28 ad #include <dev/dec/dzreg.h>
47 1.28 ad #include <dev/dec/dzvar.h>
48 1.26 ragge #include <dev/dec/dzkbdvar.h>
49 1.26 ragge
50 1.1 ragge #include <dev/wscons/wsdisplayvar.h>
51 1.1 ragge #include <dev/wscons/wsconsio.h>
52 1.1 ragge #include <dev/wscons/wscons_callbacks.h>
53 1.39 he #include <dev/wsfont/wsfont.h>
54 1.1 ragge
55 1.26 ragge #include "dzkbd.h"
56 1.26 ragge #include "opt_wsfont.h"
57 1.1 ragge
58 1.26 ragge /* Screen hardware defs */
59 1.6 ragge #define SM_COLS 128 /* char width of screen */
60 1.6 ragge #define SM_ROWS 57 /* rows of char on screen */
61 1.6 ragge #define SM_CHEIGHT 15 /* lines a char consists of */
62 1.6 ragge #define SM_NEXTROW (SM_COLS * SM_CHEIGHT)
63 1.26 ragge #define SM_YWIDTH 864
64 1.26 ragge #define SM_XWIDTH 1024
65 1.26 ragge
66 1.26 ragge /* Cursor register definitions */
67 1.26 ragge #define CUR_CMD 0
68 1.26 ragge #define CUR_XPOS 4
69 1.26 ragge #define CUR_YPOS 8
70 1.26 ragge #define CUR_XMIN_1 12
71 1.26 ragge #define CUR_XMAX_1 16
72 1.26 ragge #define CUR_YMIN_1 20
73 1.26 ragge #define CUR_YMAX_1 24
74 1.26 ragge #define CUR_XMIN_2 28
75 1.26 ragge #define CUR_XMAX_2 32
76 1.26 ragge #define CUR_YMIN_2 36
77 1.26 ragge #define CUR_YMAX_2 40
78 1.26 ragge #define CUR_LOAD 44
79 1.26 ragge
80 1.26 ragge #define CUR_CMD_TEST 0x8000
81 1.26 ragge #define CUR_CMD_HSHI 0x4000
82 1.26 ragge #define CUR_CMD_VBHI 0x2000
83 1.26 ragge #define CUR_CMD_LODSA 0x1000
84 1.26 ragge #define CUR_CMD_FORG2 0x0800
85 1.26 ragge #define CUR_CMD_ENRG2 0x0400
86 1.26 ragge #define CUR_CMD_FORG1 0x0200
87 1.26 ragge #define CUR_CMD_ENRG1 0x0100
88 1.26 ragge #define CUR_CMD_XHWID 0x0080
89 1.26 ragge #define CUR_CMD_XHCL1 0x0040
90 1.26 ragge #define CUR_CMD_XHCLP 0x0020
91 1.26 ragge #define CUR_CMD_XHAIR 0x0010
92 1.26 ragge #define CUR_CMD_FOPB 0x0008
93 1.26 ragge #define CUR_CMD_ENPB 0x0004
94 1.26 ragge #define CUR_CMD_FOPA 0x0002
95 1.26 ragge #define CUR_CMD_ENPA 0x0001
96 1.26 ragge
97 1.26 ragge #define CUR_XBIAS 216 /* Add to cursor position */
98 1.26 ragge #define CUR_YBIAS 33
99 1.26 ragge
100 1.47 matt #define WRITECUR(addr, val) *(volatile uint16_t *)(curaddr + (addr)) = (val)
101 1.43 christos static char *curaddr;
102 1.47 matt static uint16_t curcmd, curx, cury, hotX, hotY;
103 1.56 msaitoh static int bgmask, fgmask;
104 1.1 ragge
105 1.47 matt static int smg_match(device_t, cfdata_t, void *);
106 1.47 matt static void smg_attach(device_t, device_t, void *);
107 1.1 ragge
108 1.48 matt CFATTACH_DECL_NEW(smg, 0,
109 1.35 thorpej smg_match, smg_attach, NULL, NULL);
110 1.1 ragge
111 1.24 matt static void smg_cursor(void *, int, int, int);
112 1.24 matt static int smg_mapchar(void *, int, unsigned int *);
113 1.24 matt static void smg_putchar(void *, int, int, u_int, long);
114 1.24 matt static void smg_copycols(void *, int, int, int,int);
115 1.24 matt static void smg_erasecols(void *, int, int, int, long);
116 1.24 matt static void smg_copyrows(void *, int, int, int);
117 1.24 matt static void smg_eraserows(void *, int, int, long);
118 1.31 junyoung static int smg_allocattr(void *, int, int, int, long *);
119 1.1 ragge
120 1.1 ragge const struct wsdisplay_emulops smg_emulops = {
121 1.47 matt .cursor = smg_cursor,
122 1.47 matt .mapchar = smg_mapchar,
123 1.47 matt .putchar = smg_putchar,
124 1.47 matt .copycols = smg_copycols,
125 1.47 matt .erasecols = smg_erasecols,
126 1.47 matt .copyrows = smg_copyrows,
127 1.47 matt .eraserows = smg_eraserows,
128 1.47 matt .allocattr = smg_allocattr
129 1.1 ragge };
130 1.1 ragge
131 1.1 ragge const struct wsscreen_descr smg_stdscreen = {
132 1.47 matt .name = "128x57",
133 1.47 matt .ncols = SM_COLS,
134 1.47 matt .nrows = SM_ROWS,
135 1.47 matt .textops = &smg_emulops,
136 1.47 matt .fontwidth = 8,
137 1.47 matt .fontheight = SM_CHEIGHT,
138 1.47 matt .capabilities = WSSCREEN_UNDERLINE|WSSCREEN_REVERSE,
139 1.1 ragge };
140 1.1 ragge
141 1.1 ragge const struct wsscreen_descr *_smg_scrlist[] = {
142 1.1 ragge &smg_stdscreen,
143 1.1 ragge };
144 1.1 ragge
145 1.1 ragge const struct wsscreen_list smg_screenlist = {
146 1.47 matt .nscreens = __arraycount(_smg_scrlist),
147 1.47 matt .screens = _smg_scrlist,
148 1.1 ragge };
149 1.1 ragge
150 1.43 christos static char *sm_addr;
151 1.12 ragge
152 1.26 ragge static u_char *qf;
153 1.26 ragge
154 1.6 ragge #define QCHAR(c) (c < 32 ? 32 : (c > 127 ? c - 66 : c - 32))
155 1.26 ragge #define QFONT(c,line) qf[QCHAR(c) * 15 + line]
156 1.6 ragge #define SM_ADDR(row, col, line) \
157 1.6 ragge sm_addr[col + (row * SM_CHEIGHT * SM_COLS) + line * SM_COLS]
158 1.6 ragge
159 1.6 ragge
160 1.42 christos static int smg_ioctl(void *, void *, u_long, void *, int, struct lwp *);
161 1.41 jmmv static paddr_t smg_mmap(void *, void *, off_t, int);
162 1.24 matt static int smg_alloc_screen(void *, const struct wsscreen_descr *,
163 1.24 matt void **, int *, int *, long *);
164 1.24 matt static void smg_free_screen(void *, void *);
165 1.24 matt static int smg_show_screen(void *, void *, int,
166 1.24 matt void (*) (void *, int, int), void *);
167 1.24 matt static void smg_crsr_blink(void *);
168 1.1 ragge
169 1.1 ragge const struct wsdisplay_accessops smg_accessops = {
170 1.47 matt .ioctl = smg_ioctl,
171 1.47 matt .mmap = smg_mmap,
172 1.47 matt .alloc_screen = smg_alloc_screen,
173 1.47 matt .free_screen = smg_free_screen,
174 1.47 matt .show_screen = smg_show_screen,
175 1.1 ragge };
176 1.1 ragge
177 1.1 ragge struct smg_screen {
178 1.1 ragge int ss_curx;
179 1.1 ragge int ss_cury;
180 1.2 ragge u_char ss_image[SM_ROWS][SM_COLS]; /* Image of current screen */
181 1.6 ragge u_char ss_attr[SM_ROWS][SM_COLS]; /* Reversed etc... */
182 1.1 ragge };
183 1.1 ragge
184 1.2 ragge static struct smg_screen smg_conscreen;
185 1.2 ragge static struct smg_screen *curscr;
186 1.1 ragge
187 1.45 ad static callout_t smg_cursor_ch;
188 1.21 thorpej
189 1.1 ragge int
190 1.47 matt smg_match(device_t parent, cfdata_t match, void *aux)
191 1.1 ragge {
192 1.47 matt struct vsbus_attach_args * const va = aux;
193 1.47 matt volatile uint16_t *ccmd;
194 1.47 matt volatile uint16_t *cfgtst;
195 1.47 matt uint16_t tmp, tmp2;
196 1.15 ragge
197 1.27 ragge if (vax_boardtype == VAX_BTYP_49 || vax_boardtype == VAX_BTYP_53)
198 1.17 ragge return 0;
199 1.17 ragge
200 1.47 matt ccmd = (uint16_t *)va->va_addr;
201 1.47 matt cfgtst = (uint16_t *)vax_map_physmem(VS_CFGTST, 1);
202 1.15 ragge /*
203 1.15 ragge * Try to find the cursor chip by testing the flip-flop.
204 1.15 ragge * If nonexistent, no glass tty.
205 1.15 ragge */
206 1.38 ragge ccmd[0] = CUR_CMD_HSHI|CUR_CMD_FOPB;
207 1.15 ragge DELAY(300000);
208 1.15 ragge tmp = cfgtst[0];
209 1.38 ragge ccmd[0] = CUR_CMD_TEST|CUR_CMD_HSHI;
210 1.15 ragge DELAY(300000);
211 1.15 ragge tmp2 = cfgtst[0];
212 1.15 ragge vax_unmap_physmem((vaddr_t)cfgtst, 1);
213 1.15 ragge
214 1.15 ragge if (tmp2 != tmp)
215 1.15 ragge return 20; /* Using periodic interrupt */
216 1.15 ragge else
217 1.12 ragge return 0;
218 1.1 ragge }
219 1.1 ragge
220 1.1 ragge void
221 1.47 matt smg_attach(device_t parent, device_t self, void *aux)
222 1.1 ragge {
223 1.1 ragge struct wsemuldisplaydev_attach_args aa;
224 1.39 he struct wsdisplay_font *console_font;
225 1.39 he int fcookie;
226 1.1 ragge
227 1.47 matt aprint_normal("\n");
228 1.42 christos sm_addr = (void *)vax_map_physmem(SMADDR, (SMSIZE/VAX_NBPG));
229 1.42 christos curaddr = (void *)vax_map_physmem(KA420_CUR_BASE, 1);
230 1.15 ragge if (sm_addr == 0) {
231 1.47 matt aprint_error_dev(self, "Couldn't alloc graphics memory.\n");
232 1.15 ragge return;
233 1.15 ragge }
234 1.45 ad if (curscr == NULL)
235 1.45 ad callout_init(&smg_cursor_ch, 0);
236 1.2 ragge curscr = &smg_conscreen;
237 1.30 ragge aa.console = (vax_confdata & (KA420_CFG_L3CON|KA420_CFG_MULTU)) == 0;
238 1.30 ragge
239 1.1 ragge aa.scrdata = &smg_screenlist;
240 1.1 ragge aa.accessops = &smg_accessops;
241 1.22 ragge callout_reset(&smg_cursor_ch, hz / 2, smg_crsr_blink, NULL);
242 1.26 ragge curcmd = CUR_CMD_HSHI;
243 1.26 ragge WRITECUR(CUR_CMD, curcmd);
244 1.62 tsutsui wsfont_init();
245 1.55 macallan if ((fcookie = wsfont_find(NULL, 8, 15, 0, WSDISPLAY_FONTORDER_R2L,
246 1.55 macallan WSDISPLAY_FONTORDER_L2R, WSFONT_FIND_BITMAP)) < 0) {
247 1.47 matt aprint_error_dev(self, "could not find 8x15 font\n");
248 1.39 he return;
249 1.39 he }
250 1.39 he if (wsfont_lock(fcookie, &console_font) != 0) {
251 1.47 matt aprint_error_dev(self, "could not lock 8x15 font\n");
252 1.39 he return;
253 1.39 he }
254 1.39 he qf = console_font->data;
255 1.1 ragge
256 1.61 thorpej config_found(self, &aa, wsemuldisplaydevprint, CFARGS_NONE);
257 1.1 ragge }
258 1.1 ragge
259 1.6 ragge static u_char *cursor;
260 1.6 ragge static int cur_on;
261 1.6 ragge
262 1.6 ragge static void
263 1.26 ragge smg_crsr_blink(void *arg)
264 1.6 ragge {
265 1.6 ragge if (cur_on)
266 1.6 ragge *cursor ^= 255;
267 1.21 thorpej callout_reset(&smg_cursor_ch, hz / 2, smg_crsr_blink, NULL);
268 1.6 ragge }
269 1.6 ragge
270 1.1 ragge void
271 1.26 ragge smg_cursor(void *id, int on, int row, int col)
272 1.1 ragge {
273 1.47 matt struct smg_screen * const ss = id;
274 1.2 ragge
275 1.6 ragge if (ss == curscr) {
276 1.6 ragge SM_ADDR(ss->ss_cury, ss->ss_curx, 14) =
277 1.6 ragge QFONT(ss->ss_image[ss->ss_cury][ss->ss_curx], 14);
278 1.6 ragge cursor = &SM_ADDR(row, col, 14);
279 1.6 ragge if ((cur_on = on))
280 1.6 ragge *cursor ^= 255;
281 1.6 ragge }
282 1.2 ragge ss->ss_curx = col;
283 1.2 ragge ss->ss_cury = row;
284 1.5 drochner }
285 1.5 drochner
286 1.14 ragge int
287 1.26 ragge smg_mapchar(void *id, int uni, unsigned int *index)
288 1.5 drochner {
289 1.13 drochner if (uni < 256) {
290 1.13 drochner *index = uni;
291 1.13 drochner return (5);
292 1.13 drochner }
293 1.13 drochner *index = ' ';
294 1.5 drochner return (0);
295 1.1 ragge }
296 1.1 ragge
297 1.1 ragge static void
298 1.26 ragge smg_putchar(void *id, int row, int col, u_int c, long attr)
299 1.1 ragge {
300 1.47 matt struct smg_screen * const ss = id;
301 1.4 drochner int i;
302 1.1 ragge
303 1.4 drochner c &= 0xff;
304 1.4 drochner
305 1.4 drochner ss->ss_image[row][col] = c;
306 1.6 ragge ss->ss_attr[row][col] = attr;
307 1.2 ragge if (ss != curscr)
308 1.2 ragge return;
309 1.6 ragge for (i = 0; i < 15; i++) {
310 1.6 ragge unsigned char ch = QFONT(c, i);
311 1.6 ragge
312 1.6 ragge SM_ADDR(row, col, i) = (attr & WSATTR_REVERSE ? ~ch : ch);
313 1.6 ragge
314 1.6 ragge }
315 1.6 ragge if (attr & WSATTR_UNDERLINE)
316 1.6 ragge SM_ADDR(row, col, 14) ^= SM_ADDR(row, col, 14);
317 1.1 ragge }
318 1.1 ragge
319 1.1 ragge /*
320 1.1 ragge * copies columns inside a row.
321 1.1 ragge */
322 1.1 ragge static void
323 1.26 ragge smg_copycols(void *id, int row, int srccol, int dstcol, int ncols)
324 1.1 ragge {
325 1.47 matt struct smg_screen * const ss = id;
326 1.1 ragge int i;
327 1.1 ragge
328 1.53 cegger memcpy(&ss->ss_image[row][dstcol], &ss->ss_image[row][srccol], ncols);
329 1.53 cegger memcpy(&ss->ss_attr[row][dstcol], &ss->ss_attr[row][srccol], ncols);
330 1.2 ragge if (ss != curscr)
331 1.2 ragge return;
332 1.1 ragge for (i = 0; i < SM_CHEIGHT; i++)
333 1.52 he memcpy(&SM_ADDR(row, dstcol, i), &SM_ADDR(row, srccol, i), ncols);
334 1.1 ragge }
335 1.1 ragge
336 1.1 ragge /*
337 1.1 ragge * Erases a bunch of chars inside one row.
338 1.1 ragge */
339 1.1 ragge static void
340 1.26 ragge smg_erasecols(void *id, int row, int startcol, int ncols, long fillattr)
341 1.1 ragge {
342 1.47 matt struct smg_screen * const ss = id;
343 1.1 ragge int i;
344 1.1 ragge
345 1.50 cegger memset(&ss->ss_image[row][startcol], 0, ncols);
346 1.50 cegger memset(&ss->ss_attr[row][startcol], 0, ncols);
347 1.2 ragge if (ss != curscr)
348 1.2 ragge return;
349 1.1 ragge for (i = 0; i < SM_CHEIGHT; i++)
350 1.50 cegger memset(&SM_ADDR(row, startcol, i), 0, ncols);
351 1.1 ragge }
352 1.1 ragge
353 1.1 ragge static void
354 1.26 ragge smg_copyrows(void *id, int srcrow, int dstrow, int nrows)
355 1.1 ragge {
356 1.47 matt struct smg_screen * const ss = id;
357 1.1 ragge int frows;
358 1.1 ragge
359 1.53 cegger memcpy(&ss->ss_image[dstrow][0], &ss->ss_image[srcrow][0],
360 1.6 ragge nrows * SM_COLS);
361 1.53 cegger memcpy(&ss->ss_attr[dstrow][0], &ss->ss_attr[srcrow][0],
362 1.6 ragge nrows * SM_COLS);
363 1.2 ragge if (ss != curscr)
364 1.2 ragge return;
365 1.1 ragge if (nrows > 25) {
366 1.1 ragge frows = nrows >> 1;
367 1.1 ragge if (srcrow > dstrow) {
368 1.1 ragge bcopy(&sm_addr[(srcrow * SM_NEXTROW)],
369 1.1 ragge &sm_addr[(dstrow * SM_NEXTROW)],
370 1.1 ragge frows * SM_NEXTROW);
371 1.1 ragge bcopy(&sm_addr[((srcrow + frows) * SM_NEXTROW)],
372 1.1 ragge &sm_addr[((dstrow + frows) * SM_NEXTROW)],
373 1.1 ragge (nrows - frows) * SM_NEXTROW);
374 1.1 ragge } else {
375 1.1 ragge bcopy(&sm_addr[((srcrow + frows) * SM_NEXTROW)],
376 1.1 ragge &sm_addr[((dstrow + frows) * SM_NEXTROW)],
377 1.1 ragge (nrows - frows) * SM_NEXTROW);
378 1.1 ragge bcopy(&sm_addr[(srcrow * SM_NEXTROW)],
379 1.1 ragge &sm_addr[(dstrow * SM_NEXTROW)],
380 1.1 ragge frows * SM_NEXTROW);
381 1.1 ragge }
382 1.1 ragge } else
383 1.1 ragge bcopy(&sm_addr[(srcrow * SM_NEXTROW)],
384 1.1 ragge &sm_addr[(dstrow * SM_NEXTROW)], nrows * SM_NEXTROW);
385 1.1 ragge }
386 1.1 ragge
387 1.1 ragge static void
388 1.26 ragge smg_eraserows(void *id, int startrow, int nrows, long fillattr)
389 1.1 ragge {
390 1.47 matt struct smg_screen * const ss = id;
391 1.1 ragge int frows;
392 1.1 ragge
393 1.50 cegger memset(&ss->ss_image[startrow][0], 0, nrows * SM_COLS);
394 1.50 cegger memset(&ss->ss_attr[startrow][0], 0, nrows * SM_COLS);
395 1.2 ragge if (ss != curscr)
396 1.2 ragge return;
397 1.1 ragge if (nrows > 25) {
398 1.1 ragge frows = nrows >> 1;
399 1.50 cegger memset(&sm_addr[(startrow * SM_NEXTROW)], 0, frows * SM_NEXTROW);
400 1.50 cegger memset(&sm_addr[((startrow + frows) * SM_NEXTROW)], 0,
401 1.1 ragge (nrows - frows) * SM_NEXTROW);
402 1.1 ragge } else
403 1.50 cegger memset(&sm_addr[(startrow * SM_NEXTROW)], 0, nrows * SM_NEXTROW);
404 1.1 ragge }
405 1.1 ragge
406 1.1 ragge static int
407 1.31 junyoung smg_allocattr(void *id, int fg, int bg, int flags, long *attrp)
408 1.1 ragge {
409 1.6 ragge *attrp = flags;
410 1.1 ragge return 0;
411 1.1 ragge }
412 1.1 ragge
413 1.26 ragge static void
414 1.26 ragge setcursor(struct wsdisplay_cursor *v)
415 1.26 ragge {
416 1.47 matt uint16_t red, green, blue;
417 1.47 matt uint32_t curfg[16], curmask[16];
418 1.26 ragge int i;
419 1.26 ragge
420 1.26 ragge /* Enable cursor */
421 1.26 ragge if (v->which & WSDISPLAY_CURSOR_DOCUR) {
422 1.26 ragge if (v->enable)
423 1.26 ragge curcmd |= CUR_CMD_ENPB|CUR_CMD_ENPA;
424 1.26 ragge else
425 1.26 ragge curcmd &= ~(CUR_CMD_ENPB|CUR_CMD_ENPA);
426 1.26 ragge WRITECUR(CUR_CMD, curcmd);
427 1.26 ragge }
428 1.26 ragge if (v->which & WSDISPLAY_CURSOR_DOHOT) {
429 1.26 ragge hotX = v->hot.x;
430 1.26 ragge hotY = v->hot.y;
431 1.26 ragge }
432 1.26 ragge if (v->which & WSDISPLAY_CURSOR_DOCMAP) {
433 1.26 ragge /* First background */
434 1.58 thorpej if (copyin(v->cmap.red, &red, sizeof(red)) == 0 &&
435 1.58 thorpej copyin(v->cmap.green, &green, sizeof(green)) == 0 &&
436 1.58 thorpej copyin(v->cmap.blue, &blue, sizeof(blue)) == 0) {
437 1.58 thorpej bgmask = (((30L * red + 59L * green + 11L * blue) >> 8)
438 1.58 thorpej >= (((1<<8)-1)*50)) ? ~0 : 0;
439 1.58 thorpej }
440 1.58 thorpej if (copyin(v->cmap.red + 2, &red, sizeof(red)) == 0 &&
441 1.58 thorpej copyin(v->cmap.green + 2, &green, sizeof(green)) == 0 &&
442 1.58 thorpej copyin(v->cmap.blue + 2, &blue, sizeof(blue)) == 0) {
443 1.58 thorpej fgmask = (((30L * red + 59L * green + 11L * blue) >> 8)
444 1.58 thorpej >= (((1<<8)-1)*50)) ? ~0 : 0;
445 1.58 thorpej }
446 1.26 ragge }
447 1.26 ragge if (v->which & WSDISPLAY_CURSOR_DOSHAPE) {
448 1.26 ragge WRITECUR(CUR_CMD, curcmd | CUR_CMD_LODSA);
449 1.26 ragge copyin(v->image, curfg, sizeof(curfg));
450 1.26 ragge copyin(v->mask, curmask, sizeof(curmask));
451 1.36 ad for (i = 0; i < sizeof(curfg)/sizeof(curfg[0]); i++) {
452 1.47 matt WRITECUR(CUR_LOAD, ((uint16_t)curfg[i] & fgmask) |
453 1.47 matt (((uint16_t)curmask[i] & (uint16_t)~curfg[i])
454 1.36 ad & bgmask));
455 1.26 ragge }
456 1.36 ad for (i = 0; i < sizeof(curmask)/sizeof(curmask[0]); i++) {
457 1.47 matt WRITECUR(CUR_LOAD, (uint16_t)curmask[i]);
458 1.26 ragge }
459 1.26 ragge WRITECUR(CUR_CMD, curcmd);
460 1.26 ragge }
461 1.26 ragge }
462 1.26 ragge
463 1.1 ragge int
464 1.42 christos smg_ioctl(void *v, void *vs, u_long cmd, void *data, int flag, struct lwp *l)
465 1.1 ragge {
466 1.26 ragge struct wsdisplay_fbinfo *fb = (void *)data;
467 1.47 matt static uint16_t curc;
468 1.8 ragge
469 1.8 ragge switch (cmd) {
470 1.8 ragge case WSDISPLAYIO_GTYPE:
471 1.26 ragge *(u_int *)data = WSDISPLAY_TYPE_VAX_MONO;
472 1.8 ragge break;
473 1.8 ragge
474 1.8 ragge case WSDISPLAYIO_GINFO:
475 1.26 ragge fb->height = SM_YWIDTH;
476 1.26 ragge fb->width = SM_XWIDTH;
477 1.26 ragge fb->depth = 1;
478 1.26 ragge fb->cmsize = 2;
479 1.26 ragge break;
480 1.26 ragge
481 1.26 ragge case WSDISPLAYIO_SVIDEO:
482 1.26 ragge if (*(u_int *)data == WSDISPLAYIO_VIDEO_ON) {
483 1.26 ragge curcmd = curc;
484 1.26 ragge } else {
485 1.26 ragge curc = curcmd;
486 1.26 ragge curcmd &= ~(CUR_CMD_FOPA|CUR_CMD_ENPA);
487 1.26 ragge curcmd |= CUR_CMD_FOPB;
488 1.26 ragge }
489 1.26 ragge WRITECUR(CUR_CMD, curcmd);
490 1.26 ragge break;
491 1.26 ragge
492 1.26 ragge case WSDISPLAYIO_GVIDEO:
493 1.26 ragge *(u_int *)data = (curcmd & CUR_CMD_FOPB ?
494 1.26 ragge WSDISPLAYIO_VIDEO_OFF : WSDISPLAYIO_VIDEO_ON);
495 1.26 ragge break;
496 1.26 ragge
497 1.26 ragge case WSDISPLAYIO_SCURSOR:
498 1.26 ragge setcursor((struct wsdisplay_cursor *)data);
499 1.26 ragge break;
500 1.26 ragge
501 1.26 ragge case WSDISPLAYIO_SCURPOS:
502 1.26 ragge curx = ((struct wsdisplay_curpos *)data)->x;
503 1.26 ragge cury = ((struct wsdisplay_curpos *)data)->y;
504 1.26 ragge WRITECUR(CUR_XPOS, curx + CUR_XBIAS);
505 1.26 ragge WRITECUR(CUR_YPOS, cury + CUR_YBIAS);
506 1.26 ragge break;
507 1.26 ragge
508 1.26 ragge case WSDISPLAYIO_GCURPOS:
509 1.26 ragge ((struct wsdisplay_curpos *)data)->x = curx;
510 1.26 ragge ((struct wsdisplay_curpos *)data)->y = cury;
511 1.36 ad break;
512 1.36 ad
513 1.36 ad case WSDISPLAYIO_GCURMAX:
514 1.36 ad ((struct wsdisplay_curpos *)data)->x = 16;
515 1.36 ad ((struct wsdisplay_curpos *)data)->y = 16;
516 1.26 ragge break;
517 1.8 ragge
518 1.8 ragge default:
519 1.29 atatat return EPASSTHROUGH;
520 1.8 ragge }
521 1.8 ragge return 0;
522 1.1 ragge }
523 1.1 ragge
524 1.23 simonb static paddr_t
525 1.41 jmmv smg_mmap(void *v, void *vs, off_t offset, int prot)
526 1.1 ragge {
527 1.9 mrg if (offset >= SMSIZE || offset < 0)
528 1.8 ragge return -1;
529 1.20 ragge return (SMADDR + offset) >> PGSHIFT;
530 1.1 ragge }
531 1.1 ragge
532 1.1 ragge int
533 1.26 ragge smg_alloc_screen(void *v, const struct wsscreen_descr *type, void **cookiep,
534 1.26 ragge int *curxp, int *curyp, long *defattrp)
535 1.1 ragge {
536 1.59 thorpej *cookiep = kmem_zalloc(sizeof(struct smg_screen), KM_SLEEP);
537 1.3 ragge *curxp = *curyp = *defattrp = 0;
538 1.1 ragge return 0;
539 1.1 ragge }
540 1.1 ragge
541 1.1 ragge void
542 1.26 ragge smg_free_screen(void *v, void *cookie)
543 1.1 ragge {
544 1.1 ragge }
545 1.1 ragge
546 1.19 drochner int
547 1.26 ragge smg_show_screen(void *v, void *cookie, int waitok,
548 1.26 ragge void (*cb)(void *, int, int), void *cbarg)
549 1.1 ragge {
550 1.2 ragge struct smg_screen *ss = cookie;
551 1.2 ragge int row, col, line;
552 1.2 ragge
553 1.2 ragge if (ss == curscr)
554 1.19 drochner return (0);
555 1.2 ragge
556 1.6 ragge for (row = 0; row < SM_ROWS; row++)
557 1.8 ragge for (line = 0; line < SM_CHEIGHT; line++) {
558 1.6 ragge for (col = 0; col < SM_COLS; col++) {
559 1.6 ragge u_char s, c = ss->ss_image[row][col];
560 1.6 ragge
561 1.6 ragge if (c < 32)
562 1.6 ragge c = 32;
563 1.6 ragge s = QFONT(c, line);
564 1.6 ragge if (ss->ss_attr[row][col] & WSATTR_REVERSE)
565 1.6 ragge s ^= 255;
566 1.6 ragge SM_ADDR(row, col, line) = s;
567 1.44 matt if (ss->ss_attr[row][col] & WSATTR_UNDERLINE)
568 1.44 matt SM_ADDR(row, col, line) = 255;
569 1.2 ragge }
570 1.8 ragge }
571 1.6 ragge cursor = &sm_addr[(ss->ss_cury * SM_CHEIGHT * SM_COLS) + ss->ss_curx +
572 1.6 ragge ((SM_CHEIGHT - 1) * SM_COLS)];
573 1.2 ragge curscr = ss;
574 1.19 drochner return (0);
575 1.1 ragge }
576 1.1 ragge
577 1.1 ragge cons_decl(smg);
578 1.1 ragge
579 1.1 ragge void
580 1.47 matt smgcninit(struct consdev *cndev)
581 1.1 ragge {
582 1.39 he int fcookie;
583 1.39 he struct wsdisplay_font *console_font;
584 1.24 matt extern void lkccninit(struct consdev *);
585 1.24 matt extern int lkccngetc(dev_t);
586 1.47 matt extern int dz_vsbus_lk201_cnattach(int);
587 1.1 ragge /* Clear screen */
588 1.10 ragge memset(sm_addr, 0, 128*864);
589 1.1 ragge
590 1.45 ad callout_init(&smg_cursor_ch, 0);
591 1.45 ad
592 1.2 ragge curscr = &smg_conscreen;
593 1.2 ragge wsdisplay_cnattach(&smg_stdscreen, &smg_conscreen, 0, 0, 0);
594 1.18 ragge cn_tab->cn_pri = CN_INTERNAL;
595 1.62 tsutsui wsfont_init();
596 1.55 macallan if ((fcookie = wsfont_find(NULL, 8, 15, 0, WSDISPLAY_FONTORDER_R2L,
597 1.55 macallan WSDISPLAY_FONTORDER_L2R, WSFONT_FIND_BITMAP)) < 0)
598 1.39 he {
599 1.39 he printf("smg: could not find 8x15 font\n");
600 1.39 he return;
601 1.39 he }
602 1.39 he if (wsfont_lock(fcookie, &console_font) != 0) {
603 1.39 he printf("smg: could not lock 8x15 font\n");
604 1.39 he return;
605 1.39 he }
606 1.39 he qf = console_font->data;
607 1.26 ragge
608 1.26 ragge #if NDZKBD > 0
609 1.26 ragge dzkbd_cnattach(0); /* Connect keyboard and screen together */
610 1.1 ragge #endif
611 1.1 ragge }
612 1.1 ragge
613 1.18 ragge /*
614 1.18 ragge * Called very early to setup the glass tty as console.
615 1.18 ragge * Because it's called before the VM system is inited, virtual memory
616 1.18 ragge * for the framebuffer can be stolen directly without disturbing anything.
617 1.18 ragge */
618 1.18 ragge void
619 1.47 matt smgcnprobe(struct consdev *cndev)
620 1.1 ragge {
621 1.18 ragge extern vaddr_t virtual_avail;
622 1.32 gehenna extern const struct cdevsw wsdisplay_cdevsw;
623 1.18 ragge
624 1.1 ragge switch (vax_boardtype) {
625 1.1 ragge case VAX_BTYP_410:
626 1.1 ragge case VAX_BTYP_420:
627 1.1 ragge case VAX_BTYP_43:
628 1.16 ragge if ((vax_confdata & KA420_CFG_L3CON) ||
629 1.16 ragge (vax_confdata & KA420_CFG_MULTU))
630 1.16 ragge break; /* doesn't use graphics console */
631 1.42 christos sm_addr = (void *)virtual_avail;
632 1.18 ragge virtual_avail += SMSIZE;
633 1.18 ragge ioaccess((vaddr_t)sm_addr, SMADDR, (SMSIZE/VAX_NBPG));
634 1.18 ragge cndev->cn_pri = CN_INTERNAL;
635 1.32 gehenna cndev->cn_dev = makedev(cdevsw_lookup_major(&wsdisplay_cdevsw),
636 1.32 gehenna 0);
637 1.18 ragge break;
638 1.1 ragge
639 1.1 ragge default:
640 1.1 ragge break;
641 1.1 ragge }
642 1.1 ragge }
643