1 | /* |
---|
2 | * outch.c - This file contains code for displaying characters |
---|
3 | * on the console uisng information that should be |
---|
4 | * maintained by the BIOS in its data Area. |
---|
5 | * |
---|
6 | * Copyright (C) 1998 valette@crf.canon.fr |
---|
7 | * |
---|
8 | * Canon Centre Recherche France. |
---|
9 | * |
---|
10 | * This code is free software; you can redistribute it and/or |
---|
11 | * modify it under the terms of the GNU Library General Public |
---|
12 | * License as published by the Free Software Foundation; either |
---|
13 | * version 2 of the License, or (at your option) any later version. |
---|
14 | * |
---|
15 | * This code is distributed in the hope that it will be useful, |
---|
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
18 | * Library General Public License for more details. |
---|
19 | * |
---|
20 | * You should have received a copy of the GNU Library General Public |
---|
21 | * License along with this file; if not, write to the Free Software |
---|
22 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
---|
23 | * |
---|
24 | * $Header$ |
---|
25 | */ |
---|
26 | |
---|
27 | |
---|
28 | #include <bsp.h> |
---|
29 | |
---|
30 | #include <stdlib.h> |
---|
31 | #include <string.h> |
---|
32 | |
---|
33 | #include <crt.h> |
---|
34 | |
---|
35 | extern void wr_cursor(int, unsigned short); |
---|
36 | |
---|
37 | #define TAB_SPACE 4 |
---|
38 | static unsigned short *bitMapBaseAddr; |
---|
39 | static unsigned short ioCrtBaseAddr; |
---|
40 | static unsigned short maxCol; |
---|
41 | static unsigned short maxRow; |
---|
42 | static unsigned char row; |
---|
43 | static unsigned char column; |
---|
44 | static unsigned short attribute; |
---|
45 | static unsigned int nLines; |
---|
46 | |
---|
47 | static void |
---|
48 | scroll() |
---|
49 | { |
---|
50 | int i, j; /* Counters */ |
---|
51 | unsigned short *pt_scroll, *pt_bitmap; /* Pointers on the bit-map */ |
---|
52 | |
---|
53 | pt_bitmap = bitMapBaseAddr; |
---|
54 | j = 0; |
---|
55 | pt_bitmap = pt_bitmap + j; |
---|
56 | pt_scroll = pt_bitmap + maxCol; |
---|
57 | for (i = j; i < (maxRow - 1) * maxCol; i++) { |
---|
58 | *pt_bitmap++ = *pt_scroll++; |
---|
59 | } |
---|
60 | |
---|
61 | /* |
---|
62 | * Blank characters are displayed on the last line. |
---|
63 | */ |
---|
64 | for (i = 0; i < maxCol; i++) { |
---|
65 | *pt_bitmap++ = (short) (' ' | attribute); |
---|
66 | } |
---|
67 | } |
---|
68 | |
---|
69 | static void |
---|
70 | endColumn() |
---|
71 | { |
---|
72 | if (++row == maxRow) { |
---|
73 | scroll(); /* Scroll the screen now */ |
---|
74 | row = maxRow - 1; |
---|
75 | } |
---|
76 | column = 0; |
---|
77 | nLines++; |
---|
78 | /* Move cursor on the next location */ |
---|
79 | wr_cursor(row * maxCol + column, ioCrtBaseAddr); |
---|
80 | } |
---|
81 | |
---|
82 | |
---|
83 | |
---|
84 | static void |
---|
85 | videoPutChar(char car) |
---|
86 | { |
---|
87 | unsigned short *pt_bitmap = bitMapBaseAddr + row * maxCol; |
---|
88 | |
---|
89 | switch (car) { |
---|
90 | case '\b': { |
---|
91 | if (column) column--; |
---|
92 | /* Move cursor on the previous location */ |
---|
93 | wr_cursor(row * maxCol + column, ioCrtBaseAddr); |
---|
94 | return; |
---|
95 | } |
---|
96 | case '\t': { |
---|
97 | int i; |
---|
98 | |
---|
99 | i = TAB_SPACE - (column & (TAB_SPACE - 1)); |
---|
100 | pt_bitmap += column; |
---|
101 | column += i; |
---|
102 | if (column >= maxCol) { |
---|
103 | endColumn(); |
---|
104 | return; |
---|
105 | } |
---|
106 | while (i--) *pt_bitmap++ = ' ' | attribute; |
---|
107 | wr_cursor(row * maxCol + column, ioCrtBaseAddr); |
---|
108 | return; |
---|
109 | } |
---|
110 | case '\n': { |
---|
111 | endColumn(); |
---|
112 | return; |
---|
113 | } |
---|
114 | case 7: { /* Bell code must be inserted here */ |
---|
115 | return; |
---|
116 | } |
---|
117 | case '\r' : { /* Already handled via \n */ |
---|
118 | return; |
---|
119 | } |
---|
120 | default: { |
---|
121 | pt_bitmap += column; |
---|
122 | *pt_bitmap = car | attribute; |
---|
123 | if (++column == maxCol) endColumn(); |
---|
124 | else wr_cursor(row * maxCol + column, |
---|
125 | ioCrtBaseAddr); |
---|
126 | return; |
---|
127 | } |
---|
128 | } |
---|
129 | } |
---|
130 | |
---|
131 | void |
---|
132 | clear_screen() |
---|
133 | { |
---|
134 | int i,j; |
---|
135 | |
---|
136 | for (j = 0; j <= maxRow; j++) { |
---|
137 | for (i = 0; i <= maxCol; i++) { |
---|
138 | videoPutChar(' '); |
---|
139 | } |
---|
140 | } |
---|
141 | column = 0; |
---|
142 | row = 0; |
---|
143 | } |
---|
144 | |
---|
145 | /*-------------------------------------------------------------------------+ |
---|
146 | | Function: _IBMPC_outch |
---|
147 | | Description: Higher level (console) interface to consPutc. |
---|
148 | | Global Variables: None. |
---|
149 | | Arguments: c - character to write to console. |
---|
150 | | Returns: Nothing. |
---|
151 | +--------------------------------------------------------------------------*/ |
---|
152 | void |
---|
153 | _IBMPC_outch(char c) |
---|
154 | { |
---|
155 | videoPutChar(c); |
---|
156 | } /* _IBMPC_outch */ |
---|
157 | |
---|
158 | |
---|
159 | /*-------------------------------------------------------------------------+ |
---|
160 | | Function: _IBMPC_initVideo |
---|
161 | | Description: Video system initialization. Hook for any early setup. |
---|
162 | | Global Variables: bitMapBaseAddr, ioCrtBaseAddr, maxCol, maxRow, row |
---|
163 | | column, attribute, nLines; |
---|
164 | | Arguments: None. |
---|
165 | | Returns: Nothing. |
---|
166 | +--------------------------------------------------------------------------*/ |
---|
167 | void |
---|
168 | _IBMPC_initVideo(void) |
---|
169 | { |
---|
170 | unsigned char* pt = (unsigned char*) (VIDEO_MODE_ADDR); |
---|
171 | |
---|
172 | if (*pt == VGAMODE7) { |
---|
173 | bitMapBaseAddr = (unsigned short*) V_MONO; |
---|
174 | } |
---|
175 | else { |
---|
176 | bitMapBaseAddr = (unsigned short*) V_COLOR; |
---|
177 | } |
---|
178 | ioCrtBaseAddr = *(unsigned short*) DISPLAY_CRT_BASE_IO_ADDR; |
---|
179 | maxCol = * (unsigned short*) NB_MAX_COL_ADDR; |
---|
180 | maxRow = * (unsigned char*) NB_MAX_ROW_ADDR; |
---|
181 | column = 0; |
---|
182 | row = 0; |
---|
183 | attribute = ((BLACK << 4) | WHITE)<<8; |
---|
184 | nLines = 0; |
---|
185 | clear_screen(); |
---|
186 | #ifdef DEBUG_EARLY_STAGE |
---|
187 | printk("bitMapBaseAddr = %X, display controller base IO = %X\n", |
---|
188 | (unsigned) bitMapBaseAddr, |
---|
189 | (unsigned) ioCrtBaseAddr); |
---|
190 | videoPrintf("maxCol = %d, maxRow = %d\n", (unsigned) maxCol, (unsigned) maxRow); |
---|
191 | #endif |
---|
192 | } /* _IBMPC_initVideo */ |
---|