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