1 /* $NetBSD: pcdisplay_subr.c,v 1.25 2002/08/25 19:11:16 thorpej Exp $ */ 2 3 /* 4 * Copyright (c) 1995, 1996 Carnegie-Mellon University. 5 * All rights reserved. 6 * 7 * Author: Chris G. Demetriou 8 * 9 * Permission to use, copy, modify and distribute this software and 10 * its documentation is hereby granted, provided that both the copyright 11 * notice and this permission notice appear in all copies of the 12 * software, derivative works or modified versions, and any portions 13 * thereof, and that both notices appear in supporting documentation. 14 * 15 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 16 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND 17 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 18 * 19 * Carnegie Mellon requests users of this software to return to 20 * 21 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 22 * School of Computer Science 23 * Carnegie Mellon University 24 * Pittsburgh PA 15213-3890 25 * 26 * any improvements or extensions that they make and grant Carnegie the 27 * rights to redistribute these changes. 28 */ 29 30 #include <sys/cdefs.h> 31 __KERNEL_RCSID(0, "$NetBSD: pcdisplay_subr.c,v 1.25 2002/08/25 19:11:16 thorpej Exp $"); 32 33 #include <sys/param.h> 34 #include <sys/systm.h> 35 #include <sys/device.h> 36 #include <machine/bus.h> 37 38 #include <dev/ic/mc6845reg.h> 39 #include <dev/ic/pcdisplayvar.h> 40 #include <dev/wscons/wsconsio.h> 41 42 #include <dev/wscons/wsdisplayvar.h> 43 44 #include "opt_wsdisplay_compat.h" /* for WSDISPLAY_CHARFUNCS */ 45 46 void 47 pcdisplay_cursor_init(scr, existing) 48 struct pcdisplayscreen *scr; 49 int existing; 50 { 51 #ifdef PCDISPLAY_SOFTCURSOR 52 bus_space_tag_t memt; 53 bus_space_handle_t memh; 54 int off; 55 56 pcdisplay_6845_write(scr->hdl, curstart, 0x10); 57 pcdisplay_6845_write(scr->hdl, curend, 0x10); 58 59 if (existing) { 60 /* 61 * This is the first screen. At this point, scr->mem is NULL 62 * (no backing store), so we can't use pcdisplay_cursor() to 63 * do this. 64 */ 65 memt = scr->hdl->ph_memt; 66 memh = scr->hdl->ph_memh; 67 off = (scr->cursorrow * scr->type->ncols + scr->cursorcol) * 2 68 + scr->dispoffset; 69 70 scr->cursortmp = bus_space_read_2(memt, memh, off); 71 bus_space_write_2(memt, memh, off, scr->cursortmp ^ 0x7700); 72 } else 73 scr->cursortmp = 0; 74 #else 75 /* 76 * Firmware might not have initialized the cursor shape. Make 77 * sure there's something we can see. 78 * Don't touch the hardware if this is not the first screen. 79 */ 80 if (existing) { 81 pcdisplay_6845_write(scr->hdl, curstart, 82 scr->type->fontheight - 2); 83 pcdisplay_6845_write(scr->hdl, curend, 84 scr->type->fontheight - 1); 85 } 86 #endif 87 scr->cursoron = 1; 88 } 89 90 void 91 pcdisplay_cursor(id, on, row, col) 92 void *id; 93 int on, row, col; 94 { 95 #ifdef PCDISPLAY_SOFTCURSOR 96 struct pcdisplayscreen *scr = id; 97 bus_space_tag_t memt = scr->hdl->ph_memt; 98 bus_space_handle_t memh = scr->hdl->ph_memh; 99 int off; 100 101 /* Remove old cursor image */ 102 if (scr->cursoron) { 103 off = scr->cursorrow * scr->type->ncols + scr->cursorcol; 104 if (scr->active) 105 bus_space_write_2(memt, memh, scr->dispoffset + off * 2, 106 scr->cursortmp); 107 else 108 scr->mem[off] = scr->cursortmp; 109 } 110 111 scr->cursorrow = row; 112 scr->cursorcol = col; 113 114 if ((scr->cursoron = on) == 0) 115 return; 116 117 off = (scr->cursorrow * scr->type->ncols + scr->cursorcol); 118 if (scr->active) { 119 off = off * 2 + scr->dispoffset; 120 scr->cursortmp = bus_space_read_2(memt, memh, off); 121 bus_space_write_2(memt, memh, off, scr->cursortmp ^ 0x7700); 122 } else { 123 scr->cursortmp = scr->mem[off]; 124 scr->mem[off] = scr->cursortmp ^ 0x7700; 125 } 126 #else /* PCDISPLAY_SOFTCURSOR */ 127 struct pcdisplayscreen *scr = id; 128 int pos; 129 130 scr->cursorrow = row; 131 scr->cursorcol = col; 132 scr->cursoron = on; 133 134 if (scr->active) { 135 if (!on) 136 pos = 0x3fff; 137 else 138 pos = scr->dispoffset / 2 139 + row * scr->type->ncols + col; 140 141 pcdisplay_6845_write(scr->hdl, cursorh, pos >> 8); 142 pcdisplay_6845_write(scr->hdl, cursorl, pos); 143 } 144 #endif /* PCDISPLAY_SOFTCURSOR */ 145 } 146 147 #if 0 148 unsigned int 149 pcdisplay_mapchar_simple(id, uni) 150 void *id; 151 int uni; 152 { 153 if (uni < 128) 154 return (uni); 155 156 return (1); /* XXX ??? smiley */ 157 } 158 #endif 159 160 void 161 pcdisplay_putchar(id, row, col, c, attr) 162 void *id; 163 int row, col; 164 u_int c; 165 long attr; 166 { 167 struct pcdisplayscreen *scr = id; 168 bus_space_tag_t memt = scr->hdl->ph_memt; 169 bus_space_handle_t memh = scr->hdl->ph_memh; 170 int off; 171 172 off = row * scr->type->ncols + col; 173 174 if (scr->active) 175 bus_space_write_2(memt, memh, scr->dispoffset + off * 2, 176 c | (attr << 8)); 177 else 178 scr->mem[off] = c | (attr << 8); 179 } 180 181 void 182 pcdisplay_copycols(id, row, srccol, dstcol, ncols) 183 void *id; 184 int row, srccol, dstcol, ncols; 185 { 186 struct pcdisplayscreen *scr = id; 187 bus_space_tag_t memt = scr->hdl->ph_memt; 188 bus_space_handle_t memh = scr->hdl->ph_memh; 189 bus_size_t srcoff, dstoff; 190 191 srcoff = dstoff = row * scr->type->ncols; 192 srcoff += srccol; 193 dstoff += dstcol; 194 195 if (scr->active) 196 bus_space_copy_region_2(memt, memh, 197 scr->dispoffset + srcoff * 2, 198 memh, scr->dispoffset + dstoff * 2, 199 ncols); 200 else 201 memcpy(&scr->mem[dstoff], &scr->mem[srcoff], ncols * 2); 202 } 203 204 void 205 pcdisplay_erasecols(id, row, startcol, ncols, fillattr) 206 void *id; 207 int row, startcol, ncols; 208 long fillattr; 209 { 210 struct pcdisplayscreen *scr = id; 211 bus_space_tag_t memt = scr->hdl->ph_memt; 212 bus_space_handle_t memh = scr->hdl->ph_memh; 213 bus_size_t off; 214 u_int16_t val; 215 int i; 216 217 off = row * scr->type->ncols + startcol; 218 219 val = (fillattr << 8) | ' '; 220 221 if (scr->active) 222 bus_space_set_region_2(memt, memh, scr->dispoffset + off * 2, 223 val, ncols); 224 else 225 for (i = 0; i < ncols; i++) 226 scr->mem[off + i] = val; 227 } 228 229 void 230 pcdisplay_copyrows(id, srcrow, dstrow, nrows) 231 void *id; 232 int srcrow, dstrow, nrows; 233 { 234 struct pcdisplayscreen *scr = id; 235 bus_space_tag_t memt = scr->hdl->ph_memt; 236 bus_space_handle_t memh = scr->hdl->ph_memh; 237 int ncols = scr->type->ncols; 238 bus_size_t srcoff, dstoff; 239 240 srcoff = srcrow * ncols + 0; 241 dstoff = dstrow * ncols + 0; 242 243 if (scr->active) 244 bus_space_copy_region_2(memt, memh, 245 scr->dispoffset + srcoff * 2, 246 memh, scr->dispoffset + dstoff * 2, 247 nrows * ncols); 248 else 249 memcpy(&scr->mem[dstoff], &scr->mem[srcoff], 250 nrows * ncols * 2); 251 } 252 253 void 254 pcdisplay_eraserows(id, startrow, nrows, fillattr) 255 void *id; 256 int startrow, nrows; 257 long fillattr; 258 { 259 struct pcdisplayscreen *scr = id; 260 bus_space_tag_t memt = scr->hdl->ph_memt; 261 bus_space_handle_t memh = scr->hdl->ph_memh; 262 bus_size_t off, count; 263 u_int16_t val; 264 u_int i; 265 266 off = startrow * scr->type->ncols; 267 count = nrows * scr->type->ncols; 268 269 val = (fillattr << 8) | ' '; 270 271 if (scr->active) 272 bus_space_set_region_2(memt, memh, scr->dispoffset + off * 2, 273 val, count); 274 else 275 for (i = 0; i < count; i++) 276 scr->mem[off + i] = val; 277 } 278 279 #ifdef WSDISPLAY_CHARFUNCS 280 int 281 pcdisplay_getwschar(id, wschar) 282 void *id; 283 struct wsdisplay_char *wschar; 284 { 285 struct pcdisplayscreen *scr = id; 286 bus_space_tag_t memt = scr->hdl->ph_memt; 287 bus_space_handle_t memh = scr->hdl->ph_memh; 288 int off; 289 uint16_t chardata; 290 uint8_t attrbyte; 291 292 off = wschar->row * scr->type->ncols + wschar->col; 293 if (off >= scr->type->ncols * scr->type->nrows) 294 return -1; 295 296 if (scr->active) 297 chardata = bus_space_read_2(memt, memh, 298 scr->dispoffset + off * 2); 299 else 300 chardata = scr->mem[off]; 301 302 wschar->letter = (chardata & 0x00FF); 303 wschar->flags = 0; 304 attrbyte = (chardata & 0xFF00) >> 8; 305 if ((attrbyte & 0x08)) wschar->flags |= WSDISPLAY_CHAR_BRIGHT; 306 if ((attrbyte & 0x80)) wschar->flags |= WSDISPLAY_CHAR_BLINK; 307 wschar->foreground = attrbyte & 0x07; 308 wschar->background = (attrbyte >> 4) & 0x07; 309 310 return 0; 311 } 312 313 int 314 pcdisplay_putwschar(id, wschar) 315 void *id; 316 struct wsdisplay_char *wschar; 317 { 318 struct pcdisplayscreen *scr = id; 319 bus_space_tag_t memt = scr->hdl->ph_memt; 320 bus_space_handle_t memh = scr->hdl->ph_memh; 321 int off; 322 uint16_t chardata; 323 uint8_t attrbyte; 324 325 off = wschar->row * scr->type->ncols + wschar->col; 326 if (off >= (scr->type->ncols * scr->type->nrows)) 327 return -1; 328 329 attrbyte = wschar->background & 0x07; 330 if (wschar->flags & WSDISPLAY_CHAR_BLINK) attrbyte |= 0x08; 331 attrbyte <<= 4; 332 attrbyte |= wschar->foreground & 0x07; 333 if (wschar->flags & WSDISPLAY_CHAR_BRIGHT) attrbyte |= 0x08; 334 chardata = (attrbyte << 8) | wschar->letter; 335 336 if (scr->active) 337 bus_space_write_2(memt, memh, scr->dispoffset + off * 2, 338 chardata); 339 else 340 scr->mem[off] = chardata; 341 342 return 0; 343 } 344 #endif /* WSDISPLAY_CHARFUNCS */ 345