|
|
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: *
1.1.1.4 ! root 36: * from: @(#)cga.c 5.3 (Berkeley) 4/28/91
! 37: * cga.c,v 1.2 1993/05/22 08:02:12 cgd Exp
1.1 root 38: */
39:
40: #include "param.h"
41:
42: #define COL 80
43: #define ROW 25
44: #define CHR 2
45: #define MONO_BASE 0x3B4
46: #define MONO_BUF 0xB0000
47: #define CGA_BASE 0x3D4
48: #define CGA_BUF 0xB8000
49:
50: static u_char att = 0x7 ;
51: u_char *Crtat = (u_char *)CGA_BUF;
52:
53: static unsigned int addr_6845 = CGA_BASE;
54: cursor(pos)
55: int pos;
56: {
57: outb(addr_6845,14);
58: outb(addr_6845+1,pos >> 8);
59: outb(addr_6845,15);
60: outb(addr_6845+1,pos&0xff);
61: }
62:
63: sput(c)
64: u_char c;
65: {
66:
67: static u_char *crtat = 0;
68: unsigned cursorat; u_short was;
69: u_char *cp;
70:
71: if (crtat == 0) {
72:
73: /* XXX probe to find if a color or monochrome display */
74: was = *(u_short *)Crtat;
75: *(u_short *)Crtat = 0xA55A;
76: if (*(u_short *)Crtat != 0xA55A) {
77: Crtat = (u_char *) MONO_BUF;
78: addr_6845 = MONO_BASE;
79: }
80: *(u_short *)Crtat = was;
81:
82: /* Extract cursor location */
83: outb(addr_6845,14);
84: cursorat = inb(addr_6845+1)<<8 ;
85: outb(addr_6845,15);
86: cursorat |= inb(addr_6845+1);
87:
88: if(cursorat <= COL*ROW) {
89: crtat = Crtat + cursorat*CHR;
1.1.1.2 root 90: /* att = crtat[1]; /* use current attribute present */
1.1 root 91: } else crtat = Crtat;
92:
93: /* clean display */
94: for (cp = crtat; cp < Crtat+ROW*COL*CHR; cp += 2) {
95: cp[0] = ' ';
96: cp[1] = att;
97: }
98: }
99:
100: switch (c) {
101:
102: case '\t':
103: do
104: sput(' ');
105: while ((int)crtat % (8*CHR));
106: break;
107:
108: case '\010':
109: crtat -= CHR;
110: break;
111:
112: case '\r':
113: crtat -= (crtat - Crtat) % (COL*CHR);
114: break;
115:
116: case '\n':
117: crtat += COL*CHR ;
118: break;
119:
120: default:
121: crtat[0] = c;
122: crtat[1] = att;
123: crtat += CHR;
124: break ;
125: }
126:
1.1.1.3 root 127: #ifndef SMALL
1.1 root 128: /* implement a scroll */
129: if (crtat >= Crtat+COL*ROW*CHR) {
130: /* move text up */
131: bcopy(Crtat+COL*CHR, Crtat, COL*(ROW-1)*CHR);
132:
133: /* clear line */
134: for (cp = Crtat+ COL*(ROW-1)*CHR;
135: cp < Crtat + COL*ROW*CHR ; cp += 2)
136: cp[0] = ' ';
137:
138: crtat -= COL*CHR ;
139: }
140: #endif
141:
142: cursor((crtat-Crtat)/CHR);
143: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.