141488Smckusick /* 241488Smckusick * Copyright (c) 1988 University of Utah. 341488Smckusick * Copyright (c) 1990 The Regents of the University of California. 441488Smckusick * All rights reserved. 541488Smckusick * 641488Smckusick * This code is derived from software contributed to Berkeley by 741488Smckusick * the Systems Programming Group of the University of Utah Computer 841488Smckusick * Science Department. 941488Smckusick * 1041488Smckusick * %sccs.include.redist.c% 1141488Smckusick * 12*63730Shibler * from: Utah $Hdr: ite.c 1.24 93/06/25$ 1341488Smckusick * 14*63730Shibler * @(#)ite.c 7.6 (Berkeley) 07/08/93 1541488Smckusick */ 1641488Smckusick 1741488Smckusick /* 1841488Smckusick * Standalone Internal Terminal Emulator (CRT and keyboard) 1941488Smckusick */ 2056510Sbostic #include <hp300/stand/samachdep.h> 2141488Smckusick 2241488Smckusick #ifdef ITECONSOLE 2341488Smckusick 2456510Sbostic #include <sys/param.h> 2556510Sbostic #include <hp/dev/cons.h> 2656510Sbostic #include <hp/dev/device.h> 2756510Sbostic #include <hp/dev/itevar.h> 2856510Sbostic #include <hp/dev/grfreg.h> 2941488Smckusick 3054073Shibler extern int nodev(); 3154073Shibler extern u_char ite_readbyte(); 3254073Shibler extern int ite_writeglyph(); 3341488Smckusick 3454073Shibler extern int topcat_init(), topcat_putc(); 3554073Shibler extern int topcat_clear(), topcat_cursor(), topcat_scroll(); 3654073Shibler extern int gbox_init(), gbox_clear(); 3754073Shibler extern int gbox_putc(), gbox_cursor(), gbox_scroll(); 3854073Shibler extern int rbox_init(), rbox_clear(); 3954073Shibler extern int rbox_putc(), rbox_cursor(), rbox_scroll(); 4054073Shibler extern int dvbox_init(), dvbox_clear(); 4154073Shibler extern int dvbox_putc(), dvbox_cursor(), dvbox_scroll(); 4254073Shibler extern int hyper_init(), hyper_clear(); 4354073Shibler extern int hyper_putc(), hyper_cursor(), hyper_scroll(); 4441488Smckusick 4541488Smckusick struct itesw itesw[] = { 4654073Shibler GID_TOPCAT, 4754073Shibler topcat_init, nodev, topcat_clear, topcat_putc, 4854073Shibler topcat_cursor, topcat_scroll, ite_readbyte, ite_writeglyph, 4954073Shibler GID_GATORBOX, 5054073Shibler gbox_init, nodev, gbox_clear, gbox_putc, 5154073Shibler gbox_cursor, gbox_scroll, ite_readbyte, ite_writeglyph, 5254073Shibler GID_RENAISSANCE, 5354073Shibler rbox_init, nodev, rbox_clear, rbox_putc, 5454073Shibler rbox_cursor, rbox_scroll, ite_readbyte, ite_writeglyph, 5554073Shibler GID_LRCATSEYE, 5654073Shibler topcat_init, nodev, topcat_clear, topcat_putc, 5754073Shibler topcat_cursor, topcat_scroll, ite_readbyte, ite_writeglyph, 5854073Shibler GID_HRCCATSEYE, 5954073Shibler topcat_init, nodev, topcat_clear, topcat_putc, 6054073Shibler topcat_cursor, topcat_scroll, ite_readbyte, ite_writeglyph, 6154073Shibler GID_HRMCATSEYE, 6254073Shibler topcat_init, nodev, topcat_clear, topcat_putc, 6354073Shibler topcat_cursor, topcat_scroll, ite_readbyte, ite_writeglyph, 6454073Shibler GID_DAVINCI, 6554073Shibler dvbox_init, nodev, dvbox_clear, dvbox_putc, 6654073Shibler dvbox_cursor, dvbox_scroll, ite_readbyte, ite_writeglyph, 6754073Shibler GID_HYPERION, 6854073Shibler hyper_init, nodev, hyper_clear, hyper_putc, 6954073Shibler hyper_cursor, hyper_scroll, ite_readbyte, ite_writeglyph, 7041488Smckusick }; 7154073Shibler int nitesw = sizeof(itesw) / sizeof(itesw[0]); 7241488Smckusick 7341488Smckusick /* these guys need to be in initialized data */ 7441488Smckusick int itecons = -1; 7541488Smckusick struct ite_softc ite_softc[NITE] = { 0 }; 7641488Smckusick 7741488Smckusick /* 7841488Smckusick * Locate all bitmapped displays 7941488Smckusick */ 8041488Smckusick iteconfig() 8141488Smckusick { 8241488Smckusick extern struct hp_hw sc_table[]; 8341488Smckusick int dtype, fboff, i; 8441488Smckusick struct hp_hw *hw; 8541488Smckusick struct grfreg *gr; 8641488Smckusick struct ite_softc *ip; 8741488Smckusick 8841488Smckusick i = 0; 8949334Shibler for (hw = sc_table; hw < &sc_table[MAXCTLRS]; hw++) { 9049334Shibler if (!HW_ISDEV(hw, D_BITMAP)) 9141488Smckusick continue; 9249334Shibler gr = (struct grfreg *) hw->hw_kva; 9341488Smckusick /* XXX: redundent but safe */ 9441488Smckusick if (badaddr((caddr_t)gr) || gr->gr_id != GRFHWID) 9541488Smckusick continue; 9654073Shibler for (dtype = 0; dtype < nitesw; dtype++) 9754073Shibler if (itesw[dtype].ite_hwid == gr->gr_id2) 9854073Shibler break; 9954073Shibler if (dtype == nitesw) 10041488Smckusick continue; 10141488Smckusick if (i >= NITE) 10241488Smckusick break; 10341488Smckusick ip = &ite_softc[i]; 10454073Shibler ip->isw = &itesw[dtype]; 10541488Smckusick ip->regbase = (caddr_t) gr; 10641488Smckusick fboff = (gr->gr_fbomsb << 8) | gr->gr_fbolsb; 10741488Smckusick ip->fbbase = (caddr_t) (*((u_char *)ip->regbase+fboff) << 16); 10841488Smckusick /* DIO II: FB offset is relative to select code space */ 10949334Shibler if (ip->regbase >= (caddr_t)DIOIIBASE) 11041488Smckusick ip->fbbase += (int)ip->regbase; 11154073Shibler ip->fbwidth = gr->gr_fbwidth_h << 8 | gr->gr_fbwidth_l; 11254073Shibler ip->fbheight = gr->gr_fbheight_h << 8 | gr->gr_fbheight_l; 11354073Shibler ip->dwidth = gr->gr_dwidth_h << 8 | gr->gr_dwidth_l; 11454073Shibler ip->dheight = gr->gr_dheight_h << 8 | gr->gr_dheight_l; 115*63730Shibler /* 116*63730Shibler * XXX some displays (e.g. the davinci) appear 117*63730Shibler * to return a display height greater than the 118*63730Shibler * returned FB height. Guess we should go back 119*63730Shibler * to getting the display dimensions from the 120*63730Shibler * fontrom... 121*63730Shibler */ 122*63730Shibler if (ip->dwidth > ip->fbwidth) 123*63730Shibler ip->dwidth = ip->fbwidth; 124*63730Shibler if (ip->dheight > ip->fbheight) 125*63730Shibler ip->dheight = ip->fbheight; 12641488Smckusick ip->flags = ITE_ALIVE|ITE_CONSOLE; 12741488Smckusick i++; 12841488Smckusick } 12941488Smckusick } 13041488Smckusick 13141488Smckusick #ifdef CONSDEBUG 13241488Smckusick /* 13341488Smckusick * Allows us to cycle through all possible consoles (NITE ites and serial port) 13441488Smckusick * by using SHIFT-RESET on the keyboard. 13541488Smckusick */ 13641488Smckusick int whichconsole = -1; 13741488Smckusick #endif 13841488Smckusick 13941488Smckusick iteprobe(cp) 14041488Smckusick struct consdev *cp; 14141488Smckusick { 14241488Smckusick register int ite; 14341488Smckusick register struct ite_softc *ip; 14441488Smckusick int unit, pri; 14541488Smckusick 14641488Smckusick #ifdef CONSDEBUG 14741488Smckusick whichconsole = ++whichconsole % (NITE+1); 14841488Smckusick #endif 14941488Smckusick 15041488Smckusick if (itecons != -1) 15141488Smckusick return(1); 15241488Smckusick 15341488Smckusick iteconfig(); 15441488Smckusick unit = -1; 15541488Smckusick pri = CN_DEAD; 15641488Smckusick for (ite = 0; ite < NITE; ite++) { 15741488Smckusick #ifdef CONSDEBUG 15841488Smckusick if (ite < whichconsole) 15941488Smckusick continue; 16041488Smckusick #endif 16141488Smckusick ip = &ite_softc[ite]; 16241488Smckusick if ((ip->flags & (ITE_ALIVE|ITE_CONSOLE)) 16341488Smckusick != (ITE_ALIVE|ITE_CONSOLE)) 16441488Smckusick continue; 16541488Smckusick if ((int)ip->regbase == GRFIADDR) { 16641488Smckusick pri = CN_INTERNAL; 16741488Smckusick unit = ite; 16841488Smckusick } else if (unit < 0) { 16941488Smckusick pri = CN_NORMAL; 17041488Smckusick unit = ite; 17141488Smckusick } 17241488Smckusick } 17341488Smckusick cp->cn_dev = unit; 17441488Smckusick cp->cn_pri = pri; 17541488Smckusick } 17641488Smckusick 17741488Smckusick iteinit(cp) 17841488Smckusick struct consdev *cp; 17941488Smckusick { 18041488Smckusick int ite = cp->cn_dev; 18141488Smckusick struct ite_softc *ip; 18241488Smckusick 18341488Smckusick if (itecons != -1) 18441488Smckusick return(1); 18541488Smckusick 18641488Smckusick ip = &ite_softc[ite]; 18741488Smckusick 18841488Smckusick ip->curx = 0; 18941488Smckusick ip->cury = 0; 19041488Smckusick ip->cursorx = 0; 19141488Smckusick ip->cursory = 0; 19241488Smckusick 19354073Shibler (*ip->isw->ite_init)(ip); 19454073Shibler (*ip->isw->ite_cursor)(ip, DRAW_CURSOR); 19541488Smckusick 19641488Smckusick itecons = ite; 19741488Smckusick kbdinit(); 19841488Smckusick } 19941488Smckusick 20041488Smckusick iteputchar(c) 20141488Smckusick register int c; 20241488Smckusick { 20341488Smckusick register struct ite_softc *ip = &ite_softc[itecons]; 20454073Shibler register struct itesw *sp = ip->isw; 20541488Smckusick 20641488Smckusick c &= 0x7F; 20741488Smckusick switch (c) { 20841488Smckusick 20941488Smckusick case '\n': 21041488Smckusick if (++ip->cury == ip->rows) { 21141488Smckusick ip->cury--; 21241488Smckusick (*sp->ite_scroll)(ip, 1, 0, 1, SCROLL_UP); 21341488Smckusick ite_clrtoeol(ip, sp, ip->cury, 0); 21441488Smckusick } 21541488Smckusick else 21641488Smckusick (*sp->ite_cursor)(ip, MOVE_CURSOR); 21741488Smckusick break; 21841488Smckusick 21941488Smckusick case '\r': 22041488Smckusick ip->curx = 0; 22141488Smckusick (*sp->ite_cursor)(ip, MOVE_CURSOR); 22241488Smckusick break; 22341488Smckusick 22441488Smckusick case '\b': 22541488Smckusick if (--ip->curx < 0) 22641488Smckusick ip->curx = 0; 22741488Smckusick else 22841488Smckusick (*sp->ite_cursor)(ip, MOVE_CURSOR); 22941488Smckusick break; 23041488Smckusick 23141488Smckusick default: 23241488Smckusick if (c < ' ' || c == 0177) 23341488Smckusick break; 23441488Smckusick (*sp->ite_putc)(ip, c, ip->cury, ip->curx, ATTR_NOR); 23541488Smckusick (*sp->ite_cursor)(ip, DRAW_CURSOR); 23641488Smckusick itecheckwrap(ip, sp); 23741488Smckusick break; 23841488Smckusick } 23941488Smckusick } 24041488Smckusick 24141488Smckusick itecheckwrap(ip, sp) 24241488Smckusick register struct ite_softc *ip; 24341488Smckusick register struct itesw *sp; 24441488Smckusick { 24541488Smckusick if (++ip->curx == ip->cols) { 24641488Smckusick ip->curx = 0; 24741488Smckusick if (++ip->cury == ip->rows) { 24841488Smckusick --ip->cury; 24941488Smckusick (*sp->ite_scroll)(ip, 1, 0, 1, SCROLL_UP); 25041488Smckusick ite_clrtoeol(ip, sp, ip->cury, 0); 25141488Smckusick return; 25241488Smckusick } 25341488Smckusick } 25441488Smckusick (*sp->ite_cursor)(ip, MOVE_CURSOR); 25541488Smckusick } 25641488Smckusick 25741488Smckusick ite_clrtoeol(ip, sp, y, x) 25841488Smckusick register struct ite_softc *ip; 25941488Smckusick register struct itesw *sp; 26041488Smckusick register int y, x; 26141488Smckusick { 26241488Smckusick (*sp->ite_clear)(ip, y, x, 1, ip->cols - x); 26341488Smckusick (*sp->ite_cursor)(ip, DRAW_CURSOR); 26441488Smckusick } 26541488Smckusick 26641488Smckusick itegetchar() 26741488Smckusick { 26841488Smckusick #ifdef SMALL 26941488Smckusick return (0); 27041488Smckusick #else 27141488Smckusick return (kbdgetc()); 27241488Smckusick #endif 27341488Smckusick } 27441488Smckusick #endif 275