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

1.1       root        1: /* netboot
                      2:  *
                      3:  * cga.c,v
                      4:  * Revision 1.1  1993/07/08  16:03:54  brezak
                      5:  * Diskless boot prom code from Jim McKim ([email protected])
                      6:  *
                      7:  * Revision 1.1.1.1  1993/05/28  11:41:06  mckim
                      8:  * Initial version.
                      9:  *
                     10:  *
                     11:  * source in this file came from
                     12:  * the original 386BSD boot block.
                     13:  *
                     14:  * Copyright (c) 1990 The Regents of the University of California.
                     15:  * All rights reserved.
                     16:  *
                     17:  * This code is derived from software contributed to Berkeley by
                     18:  * William Jolitz.
                     19:  *
                     20:  * Redistribution and use in source and binary forms, with or without
                     21:  * modification, are permitted provided that the following conditions
                     22:  * are met:
                     23:  * 1. Redistributions of source code must retain the above copyright
                     24:  *    notice, this list of conditions and the following disclaimer.
                     25:  * 2. Redistributions in binary form must reproduce the above copyright
                     26:  *    notice, this list of conditions and the following disclaimer in the
                     27:  *    documentation and/or other materials provided with the distribution.
                     28:  * 3. All advertising materials mentioning features or use of this software
                     29:  *    must display the following acknowledgement:
                     30:  *     This product includes software developed by the University of
                     31:  *     California, Berkeley and its contributors.
                     32:  * 4. Neither the name of the University nor the names of its contributors
                     33:  *    may be used to endorse or promote products derived from this software
                     34:  *    without specific prior written permission.
                     35:  *
                     36:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     37:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     38:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     39:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     40:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     41:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     42:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     43:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     44:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     45:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     46:  * SUCH DAMAGE.
                     47:  *
                     48:  *     @(#)cga.c       5.3 (Berkeley) 4/28/91
                     49:  */
                     50: 
                     51: #include "proto.h"
                     52: 
                     53: #define        COL             80
                     54: #define        ROW             25
                     55: #define        CHR             2
                     56: #define MONO_BASE      0x3B4
                     57: #define MONO_BUF       0xB0000
                     58: #define CGA_BASE       0x3D4
                     59: #define CGA_BUF                0xB8000
                     60: 
                     61: static u_char  att = 0x7 ;
                     62: u_char *Crtat = (u_char *)CGA_BUF;
                     63: 
                     64: static unsigned int addr_6845 = CGA_BASE;
                     65: 
                     66: static void cursor(int pos) {
                     67:   outb(addr_6845, 14);
                     68:   outb(addr_6845+1, pos >> 8);
                     69:   outb(addr_6845, 15);
                     70:   outb(addr_6845+1, pos&0xff);
                     71: }
                     72: 
                     73: void
                     74: putc(int c) {
                     75: #ifdef USE_BIOS
                     76:   asm("
                     77:        movb    %0, %%cl
                     78:        call    _prot_to_real
                     79:        .byte   0x66
                     80:        mov     $0x1, %%ebx
                     81:        movb    $0xe, %%ah
                     82:        movb    %%cl, %%al
                     83:        sti
                     84:        int     $0x10
                     85:        cli
                     86:        .byte   0x66
                     87:        call    _real_to_prot
                     88:        " : : "g" (ch));
                     89: #else
                     90:   static u_char *crtat = 0;
                     91:   unsigned cursorat; u_short was;
                     92:   u_char *cp;
                     93: 
                     94:   if (crtat == 0) {
                     95: 
                     96:     /* XXX probe to find if a color or monochrome display */
                     97:     was = *(u_short *)Crtat;
                     98:     *(u_short *)Crtat = 0xA55A;
                     99:     if (*(u_short *)Crtat != 0xA55A) {
                    100:       Crtat = (u_char *) MONO_BUF;
                    101:       addr_6845 = MONO_BASE;
                    102:     }
                    103:     *(u_short *)Crtat = was;
                    104: 
                    105:     /* Extract cursor location */
                    106:     outb(addr_6845,14);
                    107:     cursorat = inb(addr_6845+1)<<8 ;
                    108:     outb(addr_6845,15);
                    109:     cursorat |= inb(addr_6845+1);
                    110: 
                    111:     if(cursorat <= COL*ROW) {
                    112:       crtat = Crtat + cursorat*CHR;
                    113:       /* att = crtat[1]; */    /* use current attribute present */
                    114:     } else     crtat = Crtat;
                    115: 
                    116:     /* clean display */
                    117:     for (cp = crtat; cp < Crtat+ROW*COL*CHR; cp += 2) {
                    118:       cp[0] = ' ';
                    119:       cp[1] = att;
                    120:     }
                    121:   }
                    122: 
                    123:   switch (c) {
                    124: 
                    125:   case '\t':
                    126:     do
                    127:       putc(' ');
                    128:     while ((int)crtat % (8*CHR));
                    129:     break;
                    130: 
                    131:   case '\010':
                    132:     crtat -= CHR;
                    133:     break;
                    134: 
                    135:   case '\r':
                    136:     crtat -= (crtat - Crtat) % (COL*CHR);
                    137:     break;
                    138: 
                    139:   case '\n':
                    140:     crtat += COL*CHR ;
                    141:     break;
                    142: 
                    143:   default:
                    144:     crtat[0] = c;
                    145:     crtat[1] = att;
                    146:     crtat += CHR;
                    147:     break ;
                    148:   }
                    149: 
                    150:   /* implement a scroll */
                    151:   if (crtat >= Crtat+COL*ROW*CHR) {
                    152:     /* move text up */
                    153:     bcopy((char *)(Crtat+COL*CHR), (char *)Crtat, COL*(ROW-1)*CHR);
                    154: 
                    155:     /* clear line */
                    156:     for (cp = Crtat+ COL*(ROW-1)*CHR;
                    157:         cp < Crtat + COL*ROW*CHR ; cp += 2)
                    158:       cp[0] = ' ';
                    159: 
                    160:     crtat -= COL*CHR ;
                    161:   }
                    162:   cursor((crtat-Crtat)/CHR);
                    163: #endif
                    164: }
                    165: 
                    166: void
                    167: putchar(int c)
                    168: {
                    169:   if (c == '\n')
                    170:     putc('\r');
                    171:   putc(c);
                    172: }
                    173: 
                    174: /* printf - only handles %d as decimal, %c as char, %s as string */
                    175: 
                    176: void
                    177: printf(format,data)
                    178:      const char *format;
                    179:      int data;
                    180: {
                    181:   int *dataptr = &data;
                    182:   char c;
                    183:   while ((c = *format++)) {
                    184:     if (c != '%')
                    185:       putchar(c);
                    186:     else {
                    187:       switch (c = *format++) {
                    188:       case 'd': {
                    189:        int num = *dataptr++;
                    190:        char buf[10], *ptr = buf;
                    191:        if (num<0) {
                    192:          num = -num;
                    193:          putchar('-');
                    194:        }
                    195:        do
                    196:          *ptr++ = '0'+num%10;
                    197:        while ((num /= 10));
                    198:        do
                    199:          putchar(*--ptr);
                    200:        while (ptr != buf);
                    201:        break;
                    202:       }
                    203:       case 'x': {
                    204:        int num = *dataptr++, dig;
                    205:        char buf[8], *ptr = buf;
                    206:        do
                    207:          *ptr++ = (dig=(num&0xf)) > 9?
                    208:            'a' + dig - 10 :
                    209:              '0' + dig;
                    210:        while ((num >>= 4));
                    211:        do
                    212:          putchar(*--ptr);
                    213:        while (ptr != buf);
                    214:        break;
                    215:       }
                    216:       case 'c': putchar((*dataptr++)&0xff); break;
                    217:       case 's': {
                    218:        char *ptr = (char *)*dataptr++;
                    219:        while ((c = *ptr++))
                    220:          putchar(c);
                    221:        break;
                    222:       }
                    223:       }
                    224:     }
                    225:   }
                    226: }

unix.superglobalmegacorp.com

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