1 /* $NetBSD: ite_cl.c,v 1.2 1996/04/21 21:11:57 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 "grfcl.h" 37 #if NGRFCL > 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_clreg.h> 52 #include <amiga/dev/itevar.h> 53 54 #ifdef CL5426CONSOLE 55 int cl_console = 1; 56 #else 57 int cl_console = 0; 58 #endif 59 60 void cl_init __P((struct ite_softc *ip)); 61 void cl_cursor __P((struct ite_softc *ip, int flag)); 62 void cl_deinit __P((struct ite_softc *ip)); 63 void cl_putc __P((struct ite_softc *ip, int c, int dy, int dx, int mode)); 64 void cl_clear __P((struct ite_softc *ip, int sy, int sx, int h, int w)); 65 void cl_scroll __P((struct ite_softc *ip, int sy, int sx, int count, 66 int dir)); 67 68 69 /* 70 * Called to determine ite status. Because the connection between the 71 * console & ite in this driver is rather intimate, we return CN_DEAD 72 * if the cl_console is not active. 73 */ 74 int 75 grfcl_cnprobe(void) 76 { 77 static int done; 78 int rv; 79 80 if (cl_console && (done == 0)) 81 rv = CN_INTERNAL; 82 else 83 rv = CN_DEAD; 84 85 done = 1; 86 return(rv); 87 } 88 89 void 90 grfcl_iteinit(gp) 91 struct grf_softc *gp; 92 { 93 gp->g_iteinit = cl_init; 94 gp->g_itedeinit = cl_deinit; 95 gp->g_iteclear = cl_clear; 96 gp->g_iteputc = cl_putc; 97 gp->g_itescroll = cl_scroll; 98 gp->g_itecursor = cl_cursor; 99 } 100 101 void 102 cl_init(ip) 103 struct ite_softc *ip; 104 { 105 struct grfcltext_mode *md; 106 107 ip->priv = ip->grf->g_data; 108 md = (struct grfcltext_mode *) ip->priv; 109 110 ip->cols = md->cols; 111 ip->rows = md->rows; 112 } 113 114 115 void 116 cl_cursor(ip, flag) 117 struct ite_softc *ip; 118 int flag; 119 { 120 volatile u_char *ba = ip->grf->g_regkva; 121 122 switch (flag) { 123 case DRAW_CURSOR: 124 /*WCrt(ba, CRT_ID_CURSOR_START, & ~0x20); */ 125 case MOVE_CURSOR: 126 flag = ip->curx + ip->cury * ip->cols; 127 WCrt(ba, CRT_ID_CURSOR_LOC_LOW, flag & 0xff); 128 WCrt(ba, CRT_ID_CURSOR_LOC_HIGH, flag >> 8); 129 ip->cursorx = ip->curx; 130 ip->cursory = ip->cury; 131 break; 132 case ERASE_CURSOR: 133 /*WCrt(ba, CRT_ID_CURSOR_START, | 0x20); */ 134 case START_CURSOROPT: 135 case END_CURSOROPT: 136 default: 137 break; 138 } 139 } 140 141 142 void 143 cl_deinit(ip) 144 struct ite_softc *ip; 145 { 146 ip->flags &= ~ITE_INITED; 147 } 148 149 150 void 151 cl_putc(ip, c, dy, dx, mode) 152 struct ite_softc *ip; 153 int c; 154 int dy; 155 int dx; 156 int mode; 157 { 158 volatile unsigned char *ba = ip->grf->g_regkva; 159 unsigned char *fb = ip->grf->g_fbkva; 160 unsigned char attr; 161 unsigned char *cp; 162 163 attr =(unsigned char) ((mode & ATTR_INV) ? (0x70) : (0x07)); 164 if (mode & ATTR_UL) attr = 0x01; /* ???????? */ 165 if (mode & ATTR_BOLD) attr |= 0x08; 166 if (mode & ATTR_BLINK) attr |= 0x80; 167 168 cp = fb + ((dy * ip->cols) + dx); 169 SetTextPlane(ba,0x00); 170 *cp = (unsigned char) c; 171 SetTextPlane(ba,0x01); 172 *cp = (unsigned char) attr; 173 } 174 175 void 176 cl_clear(ip, sy, sx, h, w) 177 struct ite_softc *ip; 178 int sy; 179 int sx; 180 int h; 181 int w; 182 { 183 /* cl_clear and cl_scroll both rely on ite passing arguments 184 * which describe continuous regions. For a VT200 terminal, 185 * this is safe behavior. 186 */ 187 unsigned char *src, *dst; 188 volatile unsigned char *ba = ip->grf->g_regkva; 189 int len; 190 191 dst = ip->grf->g_fbkva + (sy * ip->cols) + sx; 192 src = dst + (ip->rows*ip->cols); 193 len = w*h; 194 195 SetTextPlane(ba, 0x00); 196 bcopy(src, dst, len); 197 SetTextPlane(ba, 0x01); 198 bcopy(src, dst, len); 199 } 200 201 void 202 cl_scroll(ip, sy, sx, count, dir) 203 struct ite_softc *ip; 204 int sy; 205 int sx; 206 int count; 207 int dir; 208 { 209 unsigned char *fb; 210 volatile unsigned char *ba = ip->grf->g_regkva; 211 212 fb = ip->grf->g_fbkva + sy * ip->cols; 213 SetTextPlane(ba, 0x00); 214 215 switch (dir) { 216 case SCROLL_UP: 217 bcopy(fb, fb - (count * ip->cols), 218 (ip->bottom_margin + 1 - sy) * ip->cols); 219 break; 220 case SCROLL_DOWN: 221 bcopy(fb, fb + (count * ip->cols), 222 (ip->bottom_margin + 1 - (sy + count)) * ip->cols); 223 break; 224 case SCROLL_RIGHT: 225 bcopy(fb+sx, fb+sx+count, ip->cols - (sx + count)); 226 break; 227 case SCROLL_LEFT: 228 bcopy(fb+sx, fb+sx-count, ip->cols - sx); 229 break; 230 } 231 232 SetTextPlane(ba, 0x01); 233 234 switch (dir) { 235 case SCROLL_UP: 236 bcopy(fb, fb - (count * ip->cols), 237 (ip->bottom_margin + 1 - sy) * ip->cols); 238 break; 239 case SCROLL_DOWN: 240 bcopy(fb, fb + (count * ip->cols), 241 (ip->bottom_margin + 1 - (sy + count)) * ip->cols); 242 break; 243 case SCROLL_RIGHT: 244 bcopy(fb+sx, fb+sx+count, ip->cols - (sx + count)); 245 break; 246 case SCROLL_LEFT: 247 bcopy(fb+sx, fb+sx-count, ip->cols - sx); 248 break; 249 } 250 } 251 #endif /* NGRFCL */ 252