1 /* $NetBSD: ite_et.c,v 1.3 1997/03/05 22:50:41 veego Exp $ */ 2 3 /* 4 * Copyright (c) 1995 Ezra Story 5 * Copyright (c) 1995 Kari Mettinen 6 * Copyright (c) 1994 Markus Wild 7 * Copyright (c) 1994 Lutz Vieweg 8 * All rights reserved. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by Lutz Vieweg. 21 * 4. The name of the author may not be used to endorse or promote products 22 * derived from this software without specific prior written permission 23 * 24 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 25 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 26 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 27 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 28 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 29 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 33 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 */ 35 36 #include "grfet.h" 37 #if NGRFET > 0 38 39 #include <sys/param.h> 40 #include <sys/conf.h> 41 #include <sys/proc.h> 42 #include <sys/device.h> 43 #include <sys/ioctl.h> 44 #include <sys/tty.h> 45 #include <sys/systm.h> 46 #include <dev/cons.h> 47 #include <machine/cpu.h> 48 #include <amiga/amiga/device.h> 49 #include <amiga/dev/grfioctl.h> 50 #include <amiga/dev/grfvar.h> 51 #include <amiga/dev/grf_etreg.h> 52 #include <amiga/dev/itevar.h> 53 54 #ifdef TSENGCONSOLE 55 int et_console = 1; 56 #else 57 int et_console = 0; 58 #endif 59 60 void et_init __P((struct ite_softc *ip)); 61 void et_cursor __P((struct ite_softc *ip, int flag)); 62 void et_deinit __P((struct ite_softc *ip)); 63 void et_putc __P((struct ite_softc *ip, int c, int dy, int dx, int mode)); 64 void et_clear __P((struct ite_softc *ip, int sy, int sx, int h, int w)); 65 void et_scroll __P((struct ite_softc *ip, int sy, int sx, int count, 66 int dir)); 67 static void etbcopy(const void *src, void *dst, size_t len); 68 69 70 /* 71 * Called to determine ite status. Because the connection between the 72 * console & ite in this driver is rather intimate, we return CN_DEAD 73 * if the cl_console is not active. 74 */ 75 int 76 grfet_cnprobe(void) 77 { 78 static int done; 79 int rv; 80 81 if (et_console && (done == 0)) 82 rv = CN_INTERNAL; 83 else 84 rv = CN_DEAD; 85 86 done = 1; 87 return(rv); 88 } 89 90 91 void 92 grfet_iteinit(gp) 93 struct grf_softc *gp; 94 { 95 gp->g_iteinit = et_init; 96 gp->g_itedeinit = et_deinit; 97 gp->g_iteclear = et_clear; 98 gp->g_iteputc = et_putc; 99 gp->g_itescroll = et_scroll; 100 gp->g_itecursor = et_cursor; 101 } 102 103 104 void 105 et_init(ip) 106 struct ite_softc *ip; 107 { 108 struct grfettext_mode *md; 109 110 ip->priv = ip->grf->g_data; 111 md = (struct grfettext_mode *) ip->priv; 112 113 ip->cols = md->cols; 114 ip->rows = md->rows; 115 } 116 117 118 void 119 et_cursor(ip, flag) 120 struct ite_softc *ip; 121 int flag; 122 { 123 volatile u_char *ba = ip->grf->g_regkva; 124 125 switch (flag) { 126 case DRAW_CURSOR: 127 /*WCrt(ba, CRT_ID_CURSOR_START, & ~0x20); */ 128 case MOVE_CURSOR: 129 flag = ip->curx + ip->cury * ip->cols; 130 WCrt(ba, CRT_ID_CURSOR_LOC_LOW, flag & 0xff); 131 WCrt(ba, CRT_ID_CURSOR_LOC_HIGH, (flag >> 8) & 0xff); 132 WCrt(ba, CRT_ID_EXT_START, (flag >> (16-2)) & 0x0c); 133 134 ip->cursorx = ip->curx; 135 ip->cursory = ip->cury; 136 break; 137 case ERASE_CURSOR: 138 /*WCrt(ba, CRT_ID_CURSOR_START, | 0x20); */ 139 case START_CURSOROPT: 140 case END_CURSOROPT: 141 default: 142 break; 143 } 144 } 145 146 147 void 148 et_deinit(ip) 149 struct ite_softc *ip; 150 { 151 ip->flags &= ~ITE_INITED; 152 } 153 154 155 void 156 et_putc(ip, c, dy, dx, mode) 157 struct ite_softc *ip; 158 int c; 159 int dy; 160 int dx; 161 int mode; 162 { 163 volatile unsigned char *ba = ip->grf->g_regkva; 164 unsigned char *fb = ip->grf->g_fbkva; 165 unsigned char attr; 166 unsigned char *cp; 167 168 attr =(unsigned char) ((mode & ATTR_INV) ? (0x70) : (0x07)); 169 if (mode & ATTR_UL) attr = 0x01; /* ???????? */ 170 if (mode & ATTR_BOLD) attr |= 0x08; 171 if (mode & ATTR_BLINK) attr |= 0x80; 172 173 cp = fb + ((dy * ip->cols) + dx); 174 SetTextPlane(ba,0x00); 175 *cp = (unsigned char) c; 176 SetTextPlane(ba,0x01); 177 *cp = (unsigned char) attr; 178 } 179 180 181 void 182 et_clear(ip, sy, sx, h, w) 183 struct ite_softc *ip; 184 int sy; 185 int sx; 186 int h; 187 int w; 188 { 189 /* cl_clear and cl_scroll both rely on ite passing arguments 190 * which describe continuous regions. For a VT200 terminal, 191 * this is safe behavior. 192 */ 193 unsigned char *src, *dst; 194 volatile unsigned char *ba = ip->grf->g_regkva; 195 int len; 196 197 dst = ip->grf->g_fbkva + (sy * ip->cols) + sx; 198 src = dst + (ip->rows*ip->cols); 199 len = w*h; 200 201 SetTextPlane(ba, 0x00); 202 etbcopy(src, dst, len); 203 SetTextPlane(ba, 0x01); 204 etbcopy(src, dst, len); 205 } 206 207 208 void 209 et_scroll(ip, sy, sx, count, dir) 210 struct ite_softc *ip; 211 int sy; 212 int sx; 213 int count; 214 int dir; 215 { 216 unsigned char *fb; 217 volatile unsigned char *ba = ip->grf->g_regkva; 218 219 fb = ip->grf->g_fbkva + sy * ip->cols; 220 SetTextPlane(ba, 0x00); 221 222 switch (dir) { 223 case SCROLL_UP: 224 etbcopy(fb, fb - (count * ip->cols), 225 (ip->bottom_margin + 1 - sy) * ip->cols); 226 break; 227 case SCROLL_DOWN: 228 etbcopy(fb, fb + (count * ip->cols), 229 (ip->bottom_margin + 1 - (sy + count)) * ip->cols); 230 break; 231 case SCROLL_RIGHT: 232 etbcopy(fb+sx, fb+sx+count, ip->cols - (sx + count)); 233 break; 234 case SCROLL_LEFT: 235 etbcopy(fb+sx, fb+sx-count, ip->cols - sx); 236 break; 237 } 238 239 SetTextPlane(ba, 0x01); 240 241 switch (dir) { 242 case SCROLL_UP: 243 etbcopy(fb, fb - (count * ip->cols), 244 (ip->bottom_margin + 1 - sy) * ip->cols); 245 break; 246 case SCROLL_DOWN: 247 etbcopy(fb, fb + (count * ip->cols), 248 (ip->bottom_margin + 1 - (sy + count)) * ip->cols); 249 break; 250 case SCROLL_RIGHT: 251 etbcopy(fb+sx, fb+sx+count, ip->cols - (sx + count)); 252 break; 253 case SCROLL_LEFT: 254 etbcopy(fb+sx, fb+sx-count, ip->cols - sx); 255 break; 256 } 257 } 258 259 260 static void etbcopy(src, dst, len) 261 const void *src; 262 void *dst; 263 size_t len; 264 { 265 int i; 266 267 if (src == dst) 268 return; 269 270 if (src > dst) 271 for (i=len; i>0; i--) { 272 *((char *)dst)++ = *((char *)src)++; 273 } 274 else { 275 ((char *)src) += len; 276 ((char *)dst) += len; 277 278 for (i=len; i>0; i--){ 279 *--((char *)dst) = *--((char *)src); 280 } 281 } 282 } 283 284 #endif /* NGRFET */ 285