1 /*- 2 * Copyright (c) 1990, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * William Jolitz. 7 * 8 * %sccs.include.redist.c% 9 * 10 * @(#)cga.c 8.1 (Berkeley) 06/11/93 11 */ 12 13 #include <sys/param.h> 14 15 #define COL 80 16 #define ROW 25 17 #define CHR 2 18 #define MONO_BASE 0x3B4 19 #define MONO_BUF 0xB0000 20 #define CGA_BASE 0x3D4 21 #define CGA_BUF 0xB8000 22 23 static u_char att = 0x7 ; 24 u_char *Crtat = (u_char *)CGA_BUF; 25 26 static unsigned int addr_6845 = CGA_BASE; 27 cursor(pos) 28 int pos; 29 { 30 outb(addr_6845,14); 31 outb(addr_6845+1,pos >> 8); 32 outb(addr_6845,15); 33 outb(addr_6845+1,pos&0xff); 34 } 35 36 sput(c) 37 u_char c; 38 { 39 40 static u_char *crtat = 0; 41 unsigned cursorat; u_short was; 42 u_char *cp; 43 44 if (crtat == 0) { 45 46 /* XXX probe to find if a color or monochrome display */ 47 was = *(u_short *)Crtat; 48 *(u_short *)Crtat = 0xA55A; 49 if (*(u_short *)Crtat != 0xA55A) { 50 Crtat = (u_char *) MONO_BUF; 51 addr_6845 = MONO_BASE; 52 } 53 *(u_short *)Crtat = was; 54 55 /* Extract cursor location */ 56 outb(addr_6845,14); 57 cursorat = inb(addr_6845+1)<<8 ; 58 outb(addr_6845,15); 59 cursorat |= inb(addr_6845+1); 60 61 if(cursorat <= COL*ROW) { 62 crtat = Crtat + cursorat*CHR; 63 att = crtat[1]; /* use current attribute present */ 64 } else crtat = Crtat; 65 66 /* clean display */ 67 for (cp = crtat; cp < Crtat+ROW*COL*CHR; cp += 2) { 68 cp[0] = ' '; 69 cp[1] = att; 70 } 71 } 72 73 switch (c) { 74 75 case '\t': 76 do 77 sput(' '); 78 while ((int)crtat % (8*CHR)); 79 break; 80 81 case '\010': 82 crtat -= CHR; 83 break; 84 85 case '\r': 86 crtat -= (crtat - Crtat) % (COL*CHR); 87 break; 88 89 case '\n': 90 crtat += COL*CHR ; 91 break; 92 93 default: 94 crtat[0] = c; 95 crtat[1] = att; 96 crtat += CHR; 97 break ; 98 } 99 100 #ifndef SMALL 101 /* implement a scroll */ 102 if (crtat >= Crtat+COL*ROW*CHR) { 103 /* move text up */ 104 bcopy(Crtat+COL*CHR, Crtat, COL*(ROW-1)*CHR); 105 106 /* clear line */ 107 for (cp = Crtat+ COL*(ROW-1)*CHR; 108 cp < Crtat + COL*ROW*CHR ; cp += 2) 109 cp[0] = ' '; 110 111 crtat -= COL*CHR ; 112 } 113 #endif 114 115 cursor((crtat-Crtat)/CHR); 116 } 117