1 /* $NetBSD: pcdisplay_subr.c,v 1.18 2001/07/07 15:53:20 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/param.h> 31 #include <sys/systm.h> 32 #include <sys/device.h> 33 #include <machine/bus.h> 34 35 #include <dev/ic/mc6845reg.h> 36 #include <dev/ic/pcdisplayvar.h> 37 38 #include <dev/wscons/wsdisplayvar.h> 39 40 void 41 pcdisplay_cursor_init(scr, existing) 42 struct pcdisplayscreen *scr; 43 int existing; 44 { 45 #ifdef PCDISPLAY_SOFTCURSOR 46 bus_space_tag_t memt; 47 bus_space_handle_t memh; 48 int off; 49 50 pcdisplay_6845_write(scr->hdl, curstart, 0x10); 51 pcdisplay_6845_write(scr->hdl, curend, 0x10); 52 53 if (existing) { 54 /* 55 * This is the first screen. At this point, scr->active is 56 * false and scr->mem is NULL (no backing store), so we 57 * can't use pcdisplay_cursor() to do this. 58 */ 59 memt = scr->hdl->ph_memt; 60 memh = scr->hdl->ph_memh; 61 off = (scr->vc_crow * scr->type->ncols + scr->vc_ccol) * 2 + 62 scr->dispoffset; 63 64 scr->cursortmp = bus_space_read_2(memt, memh, off); 65 bus_space_write_2(memt, memh, off, scr->cursortmp ^ 0x7700); 66 } else 67 scr->cursortmp = 0; 68 #else 69 /* 70 * Firmware might not have initialized the cursor shape. Make 71 * sure there's something we can see. 72 */ 73 pcdisplay_6845_write(scr->hdl, curstart, 0x0b); 74 pcdisplay_6845_write(scr->hdl, curend, 0x10); 75 #endif 76 scr->cursoron = 1; 77 } 78 79 void 80 pcdisplay_cursor(id, on, row, col) 81 void *id; 82 int on, row, col; 83 { 84 #ifdef PCDISPLAY_SOFTCURSOR 85 struct pcdisplayscreen *scr = id; 86 bus_space_tag_t memt = scr->hdl->ph_memt; 87 bus_space_handle_t memh = scr->hdl->ph_memh; 88 int off; 89 90 /* Remove old cursor image */ 91 if (scr->cursoron) { 92 off = scr->vc_crow * scr->type->ncols + scr->vc_ccol; 93 if (scr->active) 94 bus_space_write_2(memt, memh, scr->dispoffset + off * 2, 95 scr->cursortmp); 96 else 97 scr->mem[off] = scr->cursortmp; 98 } 99 100 scr->vc_crow = row; 101 scr->vc_ccol = col; 102 103 if ((scr->cursoron = on) == 0) 104 return; 105 106 off = (scr->vc_crow * scr->type->ncols + scr->vc_ccol); 107 if (scr->active) { 108 off = off * 2 + scr->dispoffset; 109 scr->cursortmp = bus_space_read_2(memt, memh, off); 110 bus_space_write_2(memt, memh, off, scr->cursortmp ^ 0x7700); 111 } else { 112 scr->cursortmp = scr->mem[off]; 113 scr->mem[off] = scr->cursortmp ^ 0x7700; 114 } 115 #else /* PCDISPLAY_SOFTCURSOR */ 116 struct pcdisplayscreen *scr = id; 117 int pos; 118 119 scr->vc_crow = row; 120 scr->vc_ccol = col; 121 scr->cursoron = on; 122 123 if (scr->active) { 124 if (!on) 125 pos = 0x1010; 126 else 127 pos = scr->dispoffset / 2 128 + row * scr->type->ncols + col; 129 130 pcdisplay_6845_write(scr->hdl, cursorh, pos >> 8); 131 pcdisplay_6845_write(scr->hdl, cursorl, pos); 132 } 133 #endif /* PCDISPLAY_SOFTCURSOR */ 134 } 135 136 #if 0 137 unsigned int 138 pcdisplay_mapchar_simple(id, uni) 139 void *id; 140 int uni; 141 { 142 if (uni < 128) 143 return (uni); 144 145 return (1); /* XXX ??? smiley */ 146 } 147 #endif 148 149 void 150 pcdisplay_putchar(id, row, col, c, attr) 151 void *id; 152 int row, col; 153 u_int c; 154 long attr; 155 { 156 struct pcdisplayscreen *scr = id; 157 bus_space_tag_t memt = scr->hdl->ph_memt; 158 bus_space_handle_t memh = scr->hdl->ph_memh; 159 int off; 160 161 off = row * scr->type->ncols + col; 162 163 if (scr->active) 164 bus_space_write_2(memt, memh, scr->dispoffset + off * 2, 165 c | (attr << 8)); 166 else 167 scr->mem[off] = c | (attr << 8); 168 } 169 170 void 171 pcdisplay_copycols(id, row, srccol, dstcol, ncols) 172 void *id; 173 int row, srccol, dstcol, ncols; 174 { 175 struct pcdisplayscreen *scr = id; 176 bus_space_tag_t memt = scr->hdl->ph_memt; 177 bus_space_handle_t memh = scr->hdl->ph_memh; 178 bus_size_t srcoff, dstoff; 179 180 srcoff = dstoff = row * scr->type->ncols; 181 srcoff += srccol; 182 dstoff += dstcol; 183 184 if (scr->active) 185 bus_space_copy_region_2(memt, memh, 186 scr->dispoffset + srcoff * 2, 187 memh, scr->dispoffset + dstoff * 2, 188 ncols); 189 else 190 memcpy(&scr->mem[dstoff], &scr->mem[srcoff], ncols * 2); 191 } 192 193 void 194 pcdisplay_erasecols(id, row, startcol, ncols, fillattr) 195 void *id; 196 int row, startcol, ncols; 197 long fillattr; 198 { 199 struct pcdisplayscreen *scr = id; 200 bus_space_tag_t memt = scr->hdl->ph_memt; 201 bus_space_handle_t memh = scr->hdl->ph_memh; 202 bus_size_t off; 203 u_int16_t val; 204 int i; 205 206 off = row * scr->type->ncols + startcol; 207 208 val = (fillattr << 8) | ' '; 209 210 if (scr->active) 211 bus_space_set_region_2(memt, memh, scr->dispoffset + off * 2, 212 val, ncols); 213 else 214 for (i = 0; i < ncols; i++) 215 scr->mem[off + i] = val; 216 } 217 218 void 219 pcdisplay_copyrows(id, srcrow, dstrow, nrows) 220 void *id; 221 int srcrow, dstrow, nrows; 222 { 223 struct pcdisplayscreen *scr = id; 224 bus_space_tag_t memt = scr->hdl->ph_memt; 225 bus_space_handle_t memh = scr->hdl->ph_memh; 226 int ncols = scr->type->ncols; 227 bus_size_t srcoff, dstoff; 228 229 srcoff = srcrow * ncols + 0; 230 dstoff = dstrow * ncols + 0; 231 232 if (scr->active) 233 bus_space_copy_region_2(memt, memh, 234 scr->dispoffset + srcoff * 2, 235 memh, scr->dispoffset + dstoff * 2, 236 nrows * ncols); 237 else 238 memcpy(&scr->mem[dstoff], &scr->mem[srcoff], 239 nrows * ncols * 2); 240 } 241 242 void 243 pcdisplay_eraserows(id, startrow, nrows, fillattr) 244 void *id; 245 int startrow, nrows; 246 long fillattr; 247 { 248 struct pcdisplayscreen *scr = id; 249 bus_space_tag_t memt = scr->hdl->ph_memt; 250 bus_space_handle_t memh = scr->hdl->ph_memh; 251 bus_size_t off, count; 252 u_int16_t val; 253 int i; 254 255 off = startrow * scr->type->ncols; 256 count = nrows * scr->type->ncols; 257 258 val = (fillattr << 8) | ' '; 259 260 if (scr->active) 261 bus_space_set_region_2(memt, memh, scr->dispoffset + off * 2, 262 val, count); 263 else 264 for (i = 0; i < count; i++) 265 scr->mem[off + i] = val; 266 } 267