video.c revision 1.4 1 /* $NetBSD: video.c,v 1.4 1999/06/28 01:20:45 sakamoto Exp $ */
2
3 /*-
4 * Copyright (C) 1995-1997 Gary Thomas (gdt (at) linuxppc.org)
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by Gary Thomas.
18 * 4. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 #ifdef CONS_BE
34 #include <stand.h>
35 #include "boot.h"
36 #include "iso_font.h"
37
38 #define FONT_WIDTH 8
39 #define FONT_HEIGHT 16
40 #define VRAM_WIDTH 640
41 #define VRAM_HEIGHT 480
42 #define VRAM_SIZE (VRAM_WIDTH * VRAM_HEIGHT)
43 #define ROW (VRAM_WIDTH / FONT_WIDTH)
44 #define COL (VRAM_HEIGHT / FONT_HEIGHT)
45
46 u_char *VramBase;
47 u_char save_cursor[FONT_WIDTH];
48
49 /*
50 * The current state of virtual displays
51 */
52 struct screen {
53 enum state {
54 NORMAL, /* no pending escape */
55 ESC, /* saw ESC */
56 EBRAC, /* saw ESC[ */
57 EBRACEQ /* saw ESC[= */
58 } state; /* command parser state */
59 int cx; /* the first escape seq argument */
60 int cy; /* the second escap seq argument */
61 int *accp; /* pointer to the current processed argument */
62 int row;
63 int col;
64 u_char fgcolor;
65 u_char bgcolor;
66 } screen;
67
68
69 void
70 video_init(buffer)
71 u_char *buffer;
72 {
73 struct screen *d = &screen;
74
75 VramBase = buffer;
76 d->fgcolor = 0x1f; /* WHITE */
77 d->bgcolor = 0x00; /* BLACK */
78 d->row = 0;
79 d->col = 0;
80 d->state = NORMAL;
81 memset(VramBase, d->bgcolor, VRAM_SIZE);
82 memset(save_cursor, d->bgcolor, FONT_WIDTH);
83 }
84
85 static void
86 wrtchar(c, d)
87 u_char c;
88 struct screen *d;
89 {
90 u_char *p = VramBase +
91 (d->col * VRAM_WIDTH * FONT_HEIGHT) + (d->row * FONT_WIDTH);
92 int fontbase = c * 16;
93 int x, y;
94
95 for (y = 0; y < FONT_HEIGHT; y++) {
96 for (x = 0; x < FONT_WIDTH; x++) {
97 if ((font[fontbase + y] >> (FONT_WIDTH - x)) & 1)
98 *(p + x + (y * VRAM_WIDTH)) = d->fgcolor;
99 else
100 *(p + x + (y * VRAM_WIDTH)) = d->bgcolor;
101 }
102 }
103 d->row++;
104 }
105
106 static void
107 cursor(d, flag)
108 struct screen *d;
109 int flag;
110 {
111 int x;
112 int y = FONT_HEIGHT - 1;
113
114 u_char *p = VramBase +
115 (d->col * VRAM_WIDTH * FONT_HEIGHT) + (d->row * FONT_WIDTH);
116 for (x = 0; x < FONT_WIDTH - 1; x++) {
117 if (flag) {
118 save_cursor[x] = *(p + x + (y * VRAM_WIDTH));
119 *(p + x + (y * VRAM_WIDTH)) = d->fgcolor;
120 } else {
121 *(p + x + (y * VRAM_WIDTH)) = save_cursor[x];
122 }
123 }
124 }
125
126 /*
127 * vga_putc (nee sput) has support for emulation of the 'ibmpc' termcap entry.
128 * This is a bare-bones implementation of a bare-bones entry
129 * One modification: Change li#24 to li#25 to reflect 25 lines
130 * "ca" is the color/attributes value (left-shifted by 8)
131 * or 0 if the current regular color for that screen is to be used.
132 */
133 void
134 video_putc(c)
135 int c;
136 {
137 struct screen *d = &screen;
138
139 cursor(d, 0);
140
141 switch (d->state) {
142 case NORMAL:
143 switch (c) {
144 case 0x0: /* Ignore pad characters */
145 return;
146
147 case 0x1B:
148 d->state = ESC;
149 break;
150
151 case '\t':
152 do {
153 wrtchar(' ', d);
154 } while (d->row % 8);
155 break;
156
157 case '\b': /* non-destructive backspace */
158 d->row--;
159 if (d->row < 0) {
160 if (d->col > 0) {
161 d->col--;
162 d->row += ROW; /* prev column */
163 } else {
164 d->row = 0;
165 }
166 }
167 break;
168
169 case '\n':
170 d->col++;
171 case '\r':
172 d->row = 0;
173 break;
174
175 case '\007':
176 break;
177
178 default:
179 wrtchar(c, d);
180 if (d->row >= ROW) {
181 d->row = 0;
182 d->col++;
183 }
184 break;
185 }
186 break;
187
188 case ESC:
189 case EBRAC:
190 case EBRACEQ:
191 break;
192 }
193 if (d->col >= COL) { /* scroll check */
194 memcpy(VramBase, VramBase + VRAM_WIDTH * FONT_HEIGHT,
195 VRAM_SIZE - VRAM_WIDTH * FONT_WIDTH);
196 memset(VramBase + VRAM_SIZE - VRAM_WIDTH * FONT_HEIGHT,
197 d->bgcolor, VRAM_WIDTH * FONT_HEIGHT);
198 d->col = COL - 1;
199 }
200 cursor(d, 1);
201 }
202 #endif
203