Annotation of Net2/arch/i386/stand/cga.c, revision 1.1.1.1

1.1       root        1: /*-
                      2:  * Copyright (c) 1990 The Regents of the University of California.
                      3:  * All rights reserved.
                      4:  *
                      5:  * This code is derived from software contributed to Berkeley by
                      6:  * William Jolitz.
                      7:  *
                      8:  * Redistribution and use in source and binary forms, with or without
                      9:  * modification, are permitted provided that the following conditions
                     10:  * are met:
                     11:  * 1. Redistributions of source code must retain the above copyright
                     12:  *    notice, this list of conditions and the following disclaimer.
                     13:  * 2. Redistributions in binary form must reproduce the above copyright
                     14:  *    notice, this list of conditions and the following disclaimer in the
                     15:  *    documentation and/or other materials provided with the distribution.
                     16:  * 3. All advertising materials mentioning features or use of this software
                     17:  *    must display the following acknowledgement:
                     18:  *     This product includes software developed by the University of
                     19:  *     California, Berkeley and its contributors.
                     20:  * 4. Neither the name of the University nor the names of its contributors
                     21:  *    may be used to endorse or promote products derived from this software
                     22:  *    without specific prior written permission.
                     23:  *
                     24:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     25:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     26:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     27:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     28:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     29:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     30:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     31:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     32:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     33:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     34:  * SUCH DAMAGE.
                     35:  *
                     36:  *     @(#)cga.c       5.3 (Berkeley) 4/28/91
                     37:  */
                     38: 
                     39: #include "param.h"
                     40: 
                     41: #define        COL             80
                     42: #define        ROW             25
                     43: #define        CHR             2
                     44: #define MONO_BASE      0x3B4
                     45: #define MONO_BUF       0xB0000
                     46: #define CGA_BASE       0x3D4
                     47: #define CGA_BUF                0xB8000
                     48: 
                     49: static u_char  att = 0x7 ;
                     50: u_char *Crtat = (u_char *)CGA_BUF;
                     51: 
                     52: static unsigned int addr_6845 = CGA_BASE;
                     53: cursor(pos)
                     54: int pos;
                     55: {
                     56:        outb(addr_6845,14);
                     57:        outb(addr_6845+1,pos >> 8);
                     58:        outb(addr_6845,15);
                     59:        outb(addr_6845+1,pos&0xff);
                     60: }
                     61: 
                     62: sput(c)
                     63: u_char c;
                     64: {
                     65: 
                     66:        static u_char *crtat = 0;
                     67:        unsigned cursorat; u_short was;
                     68:        u_char *cp;
                     69: 
                     70:        if (crtat == 0) {
                     71: 
                     72:                /* XXX probe to find if a color or monochrome display */
                     73:                was = *(u_short *)Crtat;
                     74:                *(u_short *)Crtat = 0xA55A;
                     75:                if (*(u_short *)Crtat != 0xA55A) {
                     76:                        Crtat = (u_char *) MONO_BUF;
                     77:                        addr_6845 = MONO_BASE;
                     78:                }
                     79:                *(u_short *)Crtat = was;
                     80: 
                     81:                /* Extract cursor location */
                     82:                outb(addr_6845,14);
                     83:                cursorat = inb(addr_6845+1)<<8 ;
                     84:                outb(addr_6845,15);
                     85:                cursorat |= inb(addr_6845+1);
                     86: 
                     87:                if(cursorat <= COL*ROW) {
                     88:                        crtat = Crtat + cursorat*CHR;
                     89:                        att = crtat[1]; /* use current attribute present */
                     90:                } else  crtat = Crtat;
                     91: 
                     92:                /* clean display */
                     93:                for (cp = crtat; cp < Crtat+ROW*COL*CHR; cp += 2) {
                     94:                        cp[0] = ' ';
                     95:                        cp[1] = att;
                     96:                }
                     97:        }
                     98: 
                     99:        switch (c) {
                    100: 
                    101:        case '\t':
                    102:                do
                    103:                        sput(' ');
                    104:                while ((int)crtat % (8*CHR));
                    105:                break;
                    106: 
                    107:        case '\010':
                    108:                crtat -= CHR;
                    109:                break;
                    110: 
                    111:        case '\r':
                    112:                crtat -= (crtat - Crtat) % (COL*CHR);
                    113:                break;
                    114: 
                    115:        case '\n':
                    116:                crtat += COL*CHR ;
                    117:                break;
                    118: 
                    119:        default:
                    120:                crtat[0] = c;
                    121:                crtat[1] = att;
                    122:                crtat += CHR;
                    123:                break ;
                    124:        }
                    125: 
                    126: #ifndef SMALL
                    127:        /* implement a scroll */
                    128:        if (crtat >= Crtat+COL*ROW*CHR) {
                    129:                /* move text up */
                    130:                bcopy(Crtat+COL*CHR, Crtat, COL*(ROW-1)*CHR);
                    131: 
                    132:                /* clear line */
                    133:                for (cp = Crtat+ COL*(ROW-1)*CHR;
                    134:                        cp < Crtat + COL*ROW*CHR ; cp += 2)
                    135:                        cp[0] = ' ';
                    136: 
                    137:                crtat -= COL*CHR ;
                    138:        }
                    139: #endif
                    140: 
                    141:        cursor((crtat-Crtat)/CHR);
                    142: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.