1 /* $NetBSD: pcdisplay_subr.c,v 1.26 2004/05/28 21:42:29 christos 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.26 2004/05/28 21:42:29 christos 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 scr->visibleoffset = scr->dispoffset; 181 } 182 183 void 184 pcdisplay_copycols(id, row, srccol, dstcol, ncols) 185 void *id; 186 int row, srccol, dstcol, ncols; 187 { 188 struct pcdisplayscreen *scr = id; 189 bus_space_tag_t memt = scr->hdl->ph_memt; 190 bus_space_handle_t memh = scr->hdl->ph_memh; 191 bus_size_t srcoff, dstoff; 192 193 srcoff = dstoff = row * scr->type->ncols; 194 srcoff += srccol; 195 dstoff += dstcol; 196 197 if (scr->active) 198 bus_space_copy_region_2(memt, memh, 199 scr->dispoffset + srcoff * 2, 200 memh, scr->dispoffset + dstoff * 2, 201 ncols); 202 else 203 memcpy(&scr->mem[dstoff], &scr->mem[srcoff], ncols * 2); 204 } 205 206 void 207 pcdisplay_erasecols(id, row, startcol, ncols, fillattr) 208 void *id; 209 int row, startcol, ncols; 210 long fillattr; 211 { 212 struct pcdisplayscreen *scr = id; 213 bus_space_tag_t memt = scr->hdl->ph_memt; 214 bus_space_handle_t memh = scr->hdl->ph_memh; 215 bus_size_t off; 216 u_int16_t val; 217 int i; 218 219 off = row * scr->type->ncols + startcol; 220 221 val = (fillattr << 8) | ' '; 222 223 if (scr->active) 224 bus_space_set_region_2(memt, memh, scr->dispoffset + off * 2, 225 val, ncols); 226 else 227 for (i = 0; i < ncols; i++) 228 scr->mem[off + i] = val; 229 } 230 231 void 232 pcdisplay_copyrows(id, srcrow, dstrow, nrows) 233 void *id; 234 int srcrow, dstrow, nrows; 235 { 236 struct pcdisplayscreen *scr = id; 237 bus_space_tag_t memt = scr->hdl->ph_memt; 238 bus_space_handle_t memh = scr->hdl->ph_memh; 239 int ncols = scr->type->ncols; 240 bus_size_t srcoff, dstoff; 241 242 srcoff = srcrow * ncols + 0; 243 dstoff = dstrow * ncols + 0; 244 245 if (scr->active) 246 bus_space_copy_region_2(memt, memh, 247 scr->dispoffset + srcoff * 2, 248 memh, scr->dispoffset + dstoff * 2, 249 nrows * ncols); 250 else 251 memcpy(&scr->mem[dstoff], &scr->mem[srcoff], 252 nrows * ncols * 2); 253 } 254 255 void 256 pcdisplay_eraserows(id, startrow, nrows, fillattr) 257 void *id; 258 int startrow, nrows; 259 long fillattr; 260 { 261 struct pcdisplayscreen *scr = id; 262 bus_space_tag_t memt = scr->hdl->ph_memt; 263 bus_space_handle_t memh = scr->hdl->ph_memh; 264 bus_size_t off, count; 265 u_int16_t val; 266 u_int i; 267 268 off = startrow * scr->type->ncols; 269 count = nrows * scr->type->ncols; 270 271 val = (fillattr << 8) | ' '; 272 273 if (scr->active) 274 bus_space_set_region_2(memt, memh, scr->dispoffset + off * 2, 275 val, count); 276 else 277 for (i = 0; i < count; i++) 278 scr->mem[off + i] = val; 279 } 280 281 #ifdef WSDISPLAY_CHARFUNCS 282 int 283 pcdisplay_getwschar(id, wschar) 284 void *id; 285 struct wsdisplay_char *wschar; 286 { 287 struct pcdisplayscreen *scr = id; 288 bus_space_tag_t memt = scr->hdl->ph_memt; 289 bus_space_handle_t memh = scr->hdl->ph_memh; 290 int off; 291 uint16_t chardata; 292 uint8_t attrbyte; 293 294 off = wschar->row * scr->type->ncols + wschar->col; 295 if (off >= scr->type->ncols * scr->type->nrows) 296 return -1; 297 298 if (scr->active) 299 chardata = bus_space_read_2(memt, memh, 300 scr->dispoffset + off * 2); 301 else 302 chardata = scr->mem[off]; 303 304 wschar->letter = (chardata & 0x00FF); 305 wschar->flags = 0; 306 attrbyte = (chardata & 0xFF00) >> 8; 307 if ((attrbyte & 0x08)) wschar->flags |= WSDISPLAY_CHAR_BRIGHT; 308 if ((attrbyte & 0x80)) wschar->flags |= WSDISPLAY_CHAR_BLINK; 309 wschar->foreground = attrbyte & 0x07; 310 wschar->background = (attrbyte >> 4) & 0x07; 311 312 return 0; 313 } 314 315 int 316 pcdisplay_putwschar(id, wschar) 317 void *id; 318 struct wsdisplay_char *wschar; 319 { 320 struct pcdisplayscreen *scr = id; 321 bus_space_tag_t memt = scr->hdl->ph_memt; 322 bus_space_handle_t memh = scr->hdl->ph_memh; 323 int off; 324 uint16_t chardata; 325 uint8_t attrbyte; 326 327 off = wschar->row * scr->type->ncols + wschar->col; 328 if (off >= (scr->type->ncols * scr->type->nrows)) 329 return -1; 330 331 attrbyte = wschar->background & 0x07; 332 if (wschar->flags & WSDISPLAY_CHAR_BLINK) attrbyte |= 0x08; 333 attrbyte <<= 4; 334 attrbyte |= wschar->foreground & 0x07; 335 if (wschar->flags & WSDISPLAY_CHAR_BRIGHT) attrbyte |= 0x08; 336 chardata = (attrbyte << 8) | wschar->letter; 337 338 if (scr->active) 339 bus_space_write_2(memt, memh, scr->dispoffset + off * 2, 340 chardata); 341 else 342 scr->mem[off] = chardata; 343 344 return 0; 345 } 346 #endif /* WSDISPLAY_CHARFUNCS */ 347