1 /* $NetBSD: ite_cl.c,v 1.11 2009/10/26 19:16:54 cegger 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 "opt_amigacons.h" 37 38 #include <sys/cdefs.h> 39 __KERNEL_RCSID(0, "$NetBSD: ite_cl.c,v 1.11 2009/10/26 19:16:54 cegger Exp $"); 40 41 #include "grfcl.h" 42 #if NGRFCL > 0 43 44 #include <sys/param.h> 45 #include <sys/conf.h> 46 #include <sys/proc.h> 47 #include <sys/device.h> 48 #include <sys/ioctl.h> 49 #include <sys/tty.h> 50 #include <sys/systm.h> 51 #include <dev/cons.h> 52 #include <machine/cpu.h> 53 #include <amiga/amiga/device.h> 54 #include <amiga/dev/grfioctl.h> 55 #include <amiga/dev/grfvar.h> 56 #include <amiga/dev/grf_clreg.h> 57 #include <amiga/dev/itevar.h> 58 59 #ifdef CL5426CONSOLE 60 int cl_console = 1; 61 #else 62 int cl_console = 0; 63 #endif 64 65 void cl_init(struct ite_softc *ip); 66 void cl_cursor(struct ite_softc *ip, int flag); 67 void cl_deinit(struct ite_softc *ip); 68 void cl_putc(struct ite_softc *ip, int c, int dy, int dx, int mode); 69 void cl_clear(struct ite_softc *ip, int sy, int sx, int h, int w); 70 void cl_scroll(struct ite_softc *ip, int sy, int sx, int count, int dir); 71 72 73 /* 74 * Called to determine ite status. Because the connection between the 75 * console & ite in this driver is rather intimate, we return CN_DEAD 76 * if the cl_console is not active. 77 */ 78 int 79 grfcl_cnprobe(void) 80 { 81 static int done; 82 int rv; 83 84 if (cl_console && (done == 0)) 85 rv = CN_INTERNAL; 86 else 87 rv = CN_DEAD; 88 89 done = 1; 90 return(rv); 91 } 92 93 void 94 grfcl_iteinit(struct grf_softc *gp) 95 { 96 gp->g_iteinit = cl_init; 97 gp->g_itedeinit = cl_deinit; 98 gp->g_iteclear = cl_clear; 99 gp->g_iteputc = cl_putc; 100 gp->g_itescroll = cl_scroll; 101 gp->g_itecursor = cl_cursor; 102 } 103 104 void 105 cl_init(struct ite_softc *ip) 106 { 107 struct grfcltext_mode *md; 108 109 ip->priv = ip->grf->g_data; 110 md = (struct grfcltext_mode *) ip->priv; 111 112 ip->cols = md->cols; 113 ip->rows = md->rows; 114 } 115 116 117 void 118 cl_cursor(struct ite_softc *ip, 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(struct ite_softc *ip) 144 { 145 ip->flags &= ~ITE_INITED; 146 } 147 148 149 void 150 cl_putc(struct ite_softc *ip, int c, int dy, int dx, int mode) 151 { 152 volatile unsigned char *ba = ip->grf->g_regkva; 153 volatile unsigned char *fb = ip->grf->g_fbkva; 154 unsigned char attr; 155 volatile unsigned char *cp; 156 157 if (ip->flags & ITE_INGRF) 158 return; 159 160 attr =(unsigned char) ((mode & ATTR_INV) ? (0x70) : (0x07)); 161 if (mode & ATTR_UL) attr = 0x01; /* ???????? */ 162 if (mode & ATTR_BOLD) attr |= 0x08; 163 if (mode & ATTR_BLINK) attr |= 0x80; 164 165 cp = fb + ((dy * ip->cols) + dx); 166 SetTextPlane(ba,0x00); 167 *cp = (unsigned char) c; 168 SetTextPlane(ba,0x01); 169 *cp = (unsigned char) attr; 170 } 171 172 void 173 cl_clear(struct ite_softc *ip, int sy, int sx, int h, int w) 174 { 175 /* cl_clear and cl_scroll both rely on ite passing arguments 176 * which describe continuous regions. For a VT200 terminal, 177 * this is safe behavior. 178 */ 179 unsigned char *src, *dst; 180 volatile unsigned char *ba = ip->grf->g_regkva; 181 int len; 182 183 if (ip->flags & ITE_INGRF) 184 return; 185 186 dst = (unsigned char*)__UNVOLATILE(ip->grf->g_fbkva) + 187 (sy * ip->cols) + sx; 188 src = dst + (ip->rows*ip->cols); 189 len = w*h; 190 191 SetTextPlane(ba, 0x00); 192 memcpy(dst, src, len); 193 SetTextPlane(ba, 0x01); 194 memcpy(dst, src, len); 195 } 196 197 void 198 cl_scroll(struct ite_softc *ip, int sy, int sx, int count, int dir) 199 { 200 unsigned char *fb; 201 volatile unsigned char *ba = ip->grf->g_regkva; 202 203 if (ip->flags & ITE_INGRF) 204 return; 205 206 fb = (unsigned char*)__UNVOLATILE(ip->grf->g_fbkva) + sy * ip->cols; 207 SetTextPlane(ba, 0x00); 208 209 switch (dir) { 210 case SCROLL_UP: 211 memcpy(fb - (count * ip->cols), fb, 212 (ip->bottom_margin + 1 - sy) * ip->cols); 213 break; 214 case SCROLL_DOWN: 215 memcpy(fb + (count * ip->cols), fb, 216 (ip->bottom_margin + 1 - (sy + count)) * ip->cols); 217 break; 218 case SCROLL_RIGHT: 219 memcpy(fb+sx+count, fb+sx, ip->cols - (sx + count)); 220 break; 221 case SCROLL_LEFT: 222 memcpy(fb+sx-count, fb+sx, ip->cols - sx); 223 break; 224 } 225 226 SetTextPlane(ba, 0x01); 227 228 switch (dir) { 229 case SCROLL_UP: 230 memcpy(fb - (count * ip->cols), fb, 231 (ip->bottom_margin + 1 - sy) * ip->cols); 232 break; 233 case SCROLL_DOWN: 234 memcpy(fb + (count * ip->cols), fb, 235 (ip->bottom_margin + 1 - (sy + count)) * ip->cols); 236 break; 237 case SCROLL_RIGHT: 238 memcpy(fb+sx+count, fb+sx, ip->cols - (sx + count)); 239 break; 240 case SCROLL_LEFT: 241 memcpy(fb+sx-count, fb+sx, ip->cols - sx); 242 break; 243 } 244 } 245 #endif /* NGRFCL */ 246