1*62cf489dScegger /* $NetBSD: ite_cl.c,v 1.11 2009/10/26 19:16:54 cegger Exp $ */
235bb9b1fSchopps
335bb9b1fSchopps /*
435bb9b1fSchopps * Copyright (c) 1995 Ezra Story
535bb9b1fSchopps * Copyright (c) 1995 Kari Mettinen
635bb9b1fSchopps * Copyright (c) 1994 Markus Wild
735bb9b1fSchopps * Copyright (c) 1994 Lutz Vieweg
835bb9b1fSchopps * All rights reserved.
935bb9b1fSchopps *
1035bb9b1fSchopps * Redistribution and use in source and binary forms, with or without
1135bb9b1fSchopps * modification, are permitted provided that the following conditions
1235bb9b1fSchopps * are met:
1335bb9b1fSchopps * 1. Redistributions of source code must retain the above copyright
1435bb9b1fSchopps * notice, this list of conditions and the following disclaimer.
1535bb9b1fSchopps * 2. Redistributions in binary form must reproduce the above copyright
1635bb9b1fSchopps * notice, this list of conditions and the following disclaimer in the
1735bb9b1fSchopps * documentation and/or other materials provided with the distribution.
1835bb9b1fSchopps * 3. All advertising materials mentioning features or use of this software
1935bb9b1fSchopps * must display the following acknowledgement:
2035bb9b1fSchopps * This product includes software developed by Lutz Vieweg.
2135bb9b1fSchopps * 4. The name of the author may not be used to endorse or promote products
2235bb9b1fSchopps * derived from this software without specific prior written permission
2335bb9b1fSchopps *
2435bb9b1fSchopps * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
2535bb9b1fSchopps * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
2635bb9b1fSchopps * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2735bb9b1fSchopps * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
2835bb9b1fSchopps * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2935bb9b1fSchopps * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
3035bb9b1fSchopps * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
3135bb9b1fSchopps * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3235bb9b1fSchopps * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
3335bb9b1fSchopps * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3435bb9b1fSchopps */
3535bb9b1fSchopps
36d19d45b8Sis #include "opt_amigacons.h"
371ea4df81Saymeric
381ea4df81Saymeric #include <sys/cdefs.h>
39*62cf489dScegger __KERNEL_RCSID(0, "$NetBSD: ite_cl.c,v 1.11 2009/10/26 19:16:54 cegger Exp $");
401ea4df81Saymeric
4135bb9b1fSchopps #include "grfcl.h"
4235bb9b1fSchopps #if NGRFCL > 0
4335bb9b1fSchopps
4435bb9b1fSchopps #include <sys/param.h>
4535bb9b1fSchopps #include <sys/conf.h>
4635bb9b1fSchopps #include <sys/proc.h>
4735bb9b1fSchopps #include <sys/device.h>
4835bb9b1fSchopps #include <sys/ioctl.h>
4935bb9b1fSchopps #include <sys/tty.h>
5035bb9b1fSchopps #include <sys/systm.h>
5135bb9b1fSchopps #include <dev/cons.h>
5235bb9b1fSchopps #include <machine/cpu.h>
5335bb9b1fSchopps #include <amiga/amiga/device.h>
5435bb9b1fSchopps #include <amiga/dev/grfioctl.h>
5535bb9b1fSchopps #include <amiga/dev/grfvar.h>
5635bb9b1fSchopps #include <amiga/dev/grf_clreg.h>
5735bb9b1fSchopps #include <amiga/dev/itevar.h>
5835bb9b1fSchopps
5935bb9b1fSchopps #ifdef CL5426CONSOLE
6035bb9b1fSchopps int cl_console = 1;
6135bb9b1fSchopps #else
6235bb9b1fSchopps int cl_console = 0;
6335bb9b1fSchopps #endif
6435bb9b1fSchopps
659382c873Saymeric void cl_init(struct ite_softc *ip);
669382c873Saymeric void cl_cursor(struct ite_softc *ip, int flag);
679382c873Saymeric void cl_deinit(struct ite_softc *ip);
689382c873Saymeric void cl_putc(struct ite_softc *ip, int c, int dy, int dx, int mode);
699382c873Saymeric void cl_clear(struct ite_softc *ip, int sy, int sx, int h, int w);
709382c873Saymeric void cl_scroll(struct ite_softc *ip, int sy, int sx, int count, int dir);
7135bb9b1fSchopps
7235bb9b1fSchopps
7335bb9b1fSchopps /*
7435bb9b1fSchopps * Called to determine ite status. Because the connection between the
7535bb9b1fSchopps * console & ite in this driver is rather intimate, we return CN_DEAD
7635bb9b1fSchopps * if the cl_console is not active.
7735bb9b1fSchopps */
7835bb9b1fSchopps int
grfcl_cnprobe(void)7935bb9b1fSchopps grfcl_cnprobe(void)
8035bb9b1fSchopps {
8135bb9b1fSchopps static int done;
8235bb9b1fSchopps int rv;
8335bb9b1fSchopps
8435bb9b1fSchopps if (cl_console && (done == 0))
8535bb9b1fSchopps rv = CN_INTERNAL;
8635bb9b1fSchopps else
8735bb9b1fSchopps rv = CN_DEAD;
8835bb9b1fSchopps
8935bb9b1fSchopps done = 1;
9035bb9b1fSchopps return(rv);
9135bb9b1fSchopps }
9235bb9b1fSchopps
9335bb9b1fSchopps void
grfcl_iteinit(struct grf_softc * gp)949382c873Saymeric grfcl_iteinit(struct grf_softc *gp)
9535bb9b1fSchopps {
9635bb9b1fSchopps gp->g_iteinit = cl_init;
9735bb9b1fSchopps gp->g_itedeinit = cl_deinit;
9835bb9b1fSchopps gp->g_iteclear = cl_clear;
9935bb9b1fSchopps gp->g_iteputc = cl_putc;
10035bb9b1fSchopps gp->g_itescroll = cl_scroll;
10135bb9b1fSchopps gp->g_itecursor = cl_cursor;
10235bb9b1fSchopps }
10335bb9b1fSchopps
10435bb9b1fSchopps void
cl_init(struct ite_softc * ip)1059382c873Saymeric cl_init(struct ite_softc *ip)
10635bb9b1fSchopps {
10735bb9b1fSchopps struct grfcltext_mode *md;
10835bb9b1fSchopps
10935bb9b1fSchopps ip->priv = ip->grf->g_data;
11035bb9b1fSchopps md = (struct grfcltext_mode *) ip->priv;
11135bb9b1fSchopps
11235bb9b1fSchopps ip->cols = md->cols;
11335bb9b1fSchopps ip->rows = md->rows;
11435bb9b1fSchopps }
11535bb9b1fSchopps
11635bb9b1fSchopps
11735bb9b1fSchopps void
cl_cursor(struct ite_softc * ip,int flag)1189382c873Saymeric cl_cursor(struct ite_softc *ip, int flag)
11935bb9b1fSchopps {
12035bb9b1fSchopps volatile u_char *ba = ip->grf->g_regkva;
12135bb9b1fSchopps
12235bb9b1fSchopps switch (flag) {
12335bb9b1fSchopps case DRAW_CURSOR:
12435bb9b1fSchopps /*WCrt(ba, CRT_ID_CURSOR_START, & ~0x20); */
12535bb9b1fSchopps case MOVE_CURSOR:
12635bb9b1fSchopps flag = ip->curx + ip->cury * ip->cols;
12735bb9b1fSchopps WCrt(ba, CRT_ID_CURSOR_LOC_LOW, flag & 0xff);
12835bb9b1fSchopps WCrt(ba, CRT_ID_CURSOR_LOC_HIGH, flag >> 8);
12935bb9b1fSchopps ip->cursorx = ip->curx;
13035bb9b1fSchopps ip->cursory = ip->cury;
13135bb9b1fSchopps break;
13235bb9b1fSchopps case ERASE_CURSOR:
13335bb9b1fSchopps /*WCrt(ba, CRT_ID_CURSOR_START, | 0x20); */
13435bb9b1fSchopps case START_CURSOROPT:
13535bb9b1fSchopps case END_CURSOROPT:
13635bb9b1fSchopps default:
13735bb9b1fSchopps break;
13835bb9b1fSchopps }
13935bb9b1fSchopps }
14035bb9b1fSchopps
14135bb9b1fSchopps
14235bb9b1fSchopps void
cl_deinit(struct ite_softc * ip)1439382c873Saymeric cl_deinit(struct ite_softc *ip)
14435bb9b1fSchopps {
14535bb9b1fSchopps ip->flags &= ~ITE_INITED;
14635bb9b1fSchopps }
14735bb9b1fSchopps
14835bb9b1fSchopps
14935bb9b1fSchopps void
cl_putc(struct ite_softc * ip,int c,int dy,int dx,int mode)1509382c873Saymeric cl_putc(struct ite_softc *ip, int c, int dy, int dx, int mode)
15135bb9b1fSchopps {
15235bb9b1fSchopps volatile unsigned char *ba = ip->grf->g_regkva;
1533ba91b05She volatile unsigned char *fb = ip->grf->g_fbkva;
15435bb9b1fSchopps unsigned char attr;
1555760e713Smhitch volatile unsigned char *cp;
15635bb9b1fSchopps
157f4351f7bSis if (ip->flags & ITE_INGRF)
158f4351f7bSis return;
159f4351f7bSis
16035bb9b1fSchopps attr =(unsigned char) ((mode & ATTR_INV) ? (0x70) : (0x07));
16135bb9b1fSchopps if (mode & ATTR_UL) attr = 0x01; /* ???????? */
16235bb9b1fSchopps if (mode & ATTR_BOLD) attr |= 0x08;
16335bb9b1fSchopps if (mode & ATTR_BLINK) attr |= 0x80;
16435bb9b1fSchopps
16535bb9b1fSchopps cp = fb + ((dy * ip->cols) + dx);
16635bb9b1fSchopps SetTextPlane(ba,0x00);
16735bb9b1fSchopps *cp = (unsigned char) c;
16835bb9b1fSchopps SetTextPlane(ba,0x01);
16935bb9b1fSchopps *cp = (unsigned char) attr;
17035bb9b1fSchopps }
17135bb9b1fSchopps
17235bb9b1fSchopps void
cl_clear(struct ite_softc * ip,int sy,int sx,int h,int w)1739382c873Saymeric cl_clear(struct ite_softc *ip, int sy, int sx, int h, int w)
17435bb9b1fSchopps {
17535bb9b1fSchopps /* cl_clear and cl_scroll both rely on ite passing arguments
17635bb9b1fSchopps * which describe continuous regions. For a VT200 terminal,
17735bb9b1fSchopps * this is safe behavior.
17835bb9b1fSchopps */
17935bb9b1fSchopps unsigned char *src, *dst;
18035bb9b1fSchopps volatile unsigned char *ba = ip->grf->g_regkva;
18135bb9b1fSchopps int len;
18235bb9b1fSchopps
183f4351f7bSis if (ip->flags & ITE_INGRF)
184f4351f7bSis return;
185f4351f7bSis
1863ba91b05She dst = (unsigned char*)__UNVOLATILE(ip->grf->g_fbkva) +
1873ba91b05She (sy * ip->cols) + sx;
18835bb9b1fSchopps src = dst + (ip->rows*ip->cols);
18935bb9b1fSchopps len = w*h;
19035bb9b1fSchopps
19135bb9b1fSchopps SetTextPlane(ba, 0x00);
192e2cb8590Scegger memcpy(dst, src, len);
19335bb9b1fSchopps SetTextPlane(ba, 0x01);
194e2cb8590Scegger memcpy(dst, src, len);
19535bb9b1fSchopps }
19635bb9b1fSchopps
19735bb9b1fSchopps void
cl_scroll(struct ite_softc * ip,int sy,int sx,int count,int dir)1989382c873Saymeric cl_scroll(struct ite_softc *ip, int sy, int sx, int count, int dir)
19935bb9b1fSchopps {
20035bb9b1fSchopps unsigned char *fb;
20135bb9b1fSchopps volatile unsigned char *ba = ip->grf->g_regkva;
20235bb9b1fSchopps
203f4351f7bSis if (ip->flags & ITE_INGRF)
204f4351f7bSis return;
205f4351f7bSis
2063ba91b05She fb = (unsigned char*)__UNVOLATILE(ip->grf->g_fbkva) + sy * ip->cols;
20735bb9b1fSchopps SetTextPlane(ba, 0x00);
20835bb9b1fSchopps
20935bb9b1fSchopps switch (dir) {
21035bb9b1fSchopps case SCROLL_UP:
211e2cb8590Scegger memcpy(fb - (count * ip->cols), fb,
21235bb9b1fSchopps (ip->bottom_margin + 1 - sy) * ip->cols);
21335bb9b1fSchopps break;
21435bb9b1fSchopps case SCROLL_DOWN:
215e2cb8590Scegger memcpy(fb + (count * ip->cols), fb,
21635bb9b1fSchopps (ip->bottom_margin + 1 - (sy + count)) * ip->cols);
21735bb9b1fSchopps break;
21835bb9b1fSchopps case SCROLL_RIGHT:
219e2cb8590Scegger memcpy(fb+sx+count, fb+sx, ip->cols - (sx + count));
22035bb9b1fSchopps break;
22135bb9b1fSchopps case SCROLL_LEFT:
222e2cb8590Scegger memcpy(fb+sx-count, fb+sx, ip->cols - sx);
22335bb9b1fSchopps break;
22435bb9b1fSchopps }
22535bb9b1fSchopps
22635bb9b1fSchopps SetTextPlane(ba, 0x01);
22735bb9b1fSchopps
22835bb9b1fSchopps switch (dir) {
22935bb9b1fSchopps case SCROLL_UP:
230e2cb8590Scegger memcpy(fb - (count * ip->cols), fb,
23135bb9b1fSchopps (ip->bottom_margin + 1 - sy) * ip->cols);
23235bb9b1fSchopps break;
23335bb9b1fSchopps case SCROLL_DOWN:
234e2cb8590Scegger memcpy(fb + (count * ip->cols), fb,
23535bb9b1fSchopps (ip->bottom_margin + 1 - (sy + count)) * ip->cols);
23635bb9b1fSchopps break;
23735bb9b1fSchopps case SCROLL_RIGHT:
238e2cb8590Scegger memcpy(fb+sx+count, fb+sx, ip->cols - (sx + count));
23935bb9b1fSchopps break;
24035bb9b1fSchopps case SCROLL_LEFT:
241e2cb8590Scegger memcpy(fb+sx-count, fb+sx, ip->cols - sx);
24235bb9b1fSchopps break;
24335bb9b1fSchopps }
24435bb9b1fSchopps }
24535bb9b1fSchopps #endif /* NGRFCL */
246