1 | /*-------------------------------------------------------------------------+ |
---|
2 | | outch.c v1.1 - PC386 BSP - 1997/08/07 |
---|
3 | +--------------------------------------------------------------------------+ |
---|
4 | | (C) Copyright 1997 - |
---|
5 | | - NavIST Group - Real-Time Distributed Systems and Industrial Automation |
---|
6 | | |
---|
7 | | http://pandora.ist.utl.pt |
---|
8 | | |
---|
9 | | Instituto Superior Tecnico * Lisboa * PORTUGAL |
---|
10 | +--------------------------------------------------------------------------+ |
---|
11 | | Disclaimer: |
---|
12 | | |
---|
13 | | This file is provided "AS IS" without warranty of any kind, either |
---|
14 | | expressed or implied. |
---|
15 | +--------------------------------------------------------------------------+ |
---|
16 | | This code is based on: |
---|
17 | | outch.c,v 1.4 1995/12/19 20:07:27 joel Exp - go32 BSP |
---|
18 | | With the following copyright notice: |
---|
19 | | ************************************************************************** |
---|
20 | | * COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994. * |
---|
21 | | * On-Line Applications Research Corporation (OAR). * |
---|
22 | | * All rights assigned to U.S. Government, 1994. * |
---|
23 | | * * |
---|
24 | | * This material may be reproduced by or for the U.S. Government pursuant * |
---|
25 | | * to the copyright license under the clause at DFARS 252.227-7013. This * |
---|
26 | | * notice must appear in all copies of this file and its derivatives. * |
---|
27 | | ************************************************************************** |
---|
28 | +--------------------------------------------------------------------------*/ |
---|
29 | |
---|
30 | |
---|
31 | #include <bsp.h> |
---|
32 | |
---|
33 | #include <stdlib.h> |
---|
34 | #include <string.h> |
---|
35 | |
---|
36 | /*-------------------------------------------------------------------------+ |
---|
37 | | Constants |
---|
38 | +--------------------------------------------------------------------------*/ |
---|
39 | #define DISPLAY_CELL_COUNT (MAX_ROW * MAX_COL) |
---|
40 | /* Number of display cells. */ |
---|
41 | #define TABSIZE 4 /* Number of spaces for TAB (\t) char. */ |
---|
42 | #define WHITE 0x0700 /* White on Black background colour. */ |
---|
43 | #define BLANK (WHITE | ' ') /* Blank character. */ |
---|
44 | |
---|
45 | |
---|
46 | /*-------------------------------------------------------------------------+ |
---|
47 | | Global Variables |
---|
48 | +--------------------------------------------------------------------------*/ |
---|
49 | static rtems_unsigned16 *videoRam = TVRAM; |
---|
50 | /* Physical address of start of video text memory. */ |
---|
51 | static rtems_unsigned16 *videoRamPtr = TVRAM; |
---|
52 | /* Pointer for current output position in display. */ |
---|
53 | static rtems_unsigned8 videoRows = MAX_ROW; /* Number of rows in display. */ |
---|
54 | static rtems_unsigned8 videoCols = MAX_COL; /* Number of columns in display. */ |
---|
55 | static rtems_unsigned8 cursRow = 0; /* Current cursor row. */ |
---|
56 | static rtems_unsigned8 cursCol = 0; /* Current cursor column. */ |
---|
57 | |
---|
58 | |
---|
59 | /*-------------------------------------------------------------------------+ |
---|
60 | | Function: setHardwareCursorPos |
---|
61 | | Description: Set hardware video cursor at given offset into video RAM. |
---|
62 | | Global Variables: None. |
---|
63 | | Arguments: videoCursor - Offset into video memory. |
---|
64 | | Returns: Nothing. |
---|
65 | +--------------------------------------------------------------------------*/ |
---|
66 | static inline void |
---|
67 | setHardwareCursorPos(rtems_unsigned16 videoCursor) |
---|
68 | { |
---|
69 | outport_byte(GDC_REG_PORT, 0xe); |
---|
70 | outport_byte(GDC_VAL_PORT, (videoCursor >> 8) & 0xff); |
---|
71 | outport_byte(GDC_REG_PORT, 0xf); |
---|
72 | outport_byte(GDC_VAL_PORT, videoCursor & 0xff); |
---|
73 | } /* setHardwareCursorPos */ |
---|
74 | |
---|
75 | |
---|
76 | /*-------------------------------------------------------------------------+ |
---|
77 | | Function: updateVideoRamPtr |
---|
78 | | Description: Updates value of global variable "videoRamPtr" based on |
---|
79 | | current window's cursor position. |
---|
80 | | Global Variables: videoRamPtr, cursRow, cursCol. |
---|
81 | | Arguments: None. |
---|
82 | | Returns: Nothing. |
---|
83 | +--------------------------------------------------------------------------*/ |
---|
84 | static inline void |
---|
85 | updateVideoRamPtr(void) |
---|
86 | { |
---|
87 | videoRamPtr = videoRam + cursRow * videoCols + cursCol; |
---|
88 | } /* updateVideoRamPtr */ |
---|
89 | |
---|
90 | |
---|
91 | /*-------------------------------------------------------------------------+ |
---|
92 | | Function: scrollUp |
---|
93 | | Description: Scrolls display up n lines. |
---|
94 | | Global Variables: None. |
---|
95 | | Arguments: lines - number of lines to scroll. |
---|
96 | | Returns: Nothing. |
---|
97 | +--------------------------------------------------------------------------*/ |
---|
98 | static void |
---|
99 | scrollUp(rtems_unsigned8 lines) |
---|
100 | { |
---|
101 | rtems_unsigned16 blankCount; |
---|
102 | /* Number of blank display cells on bottom of window. */ |
---|
103 | rtems_unsigned16 *ptrDst, *ptrSrc; |
---|
104 | /* Source and destination pointers for memory copy operations. */ |
---|
105 | |
---|
106 | if (lines < videoRows) /* Move window's contents up. */ |
---|
107 | { |
---|
108 | rtems_unsigned16 nonBlankCount; |
---|
109 | /* Number of non-blank cells on upper part of display (total - blank). */ |
---|
110 | |
---|
111 | blankCount = lines * videoCols; |
---|
112 | nonBlankCount = DISPLAY_CELL_COUNT - blankCount; |
---|
113 | ptrSrc = videoRam + blankCount; |
---|
114 | ptrDst = videoRam; |
---|
115 | |
---|
116 | while(nonBlankCount--) |
---|
117 | *ptrDst++ = *ptrSrc++; |
---|
118 | } |
---|
119 | else /* Clear the whole display. */ |
---|
120 | { |
---|
121 | blankCount = DISPLAY_CELL_COUNT; |
---|
122 | ptrDst = videoRam; |
---|
123 | } |
---|
124 | |
---|
125 | /* Fill bottom with blanks. */ |
---|
126 | while (blankCount-- > 0) |
---|
127 | *ptrDst++ = BLANK; |
---|
128 | } /* scrollUp */ |
---|
129 | |
---|
130 | |
---|
131 | /*-------------------------------------------------------------------------+ |
---|
132 | | Function: printCHAR |
---|
133 | | Description: Print printable character to display. |
---|
134 | | Global Variables: videoRamPtr, cursRow, cursCol. |
---|
135 | | Arguments: c - character to write to display. |
---|
136 | | Returns: Nothing. |
---|
137 | +--------------------------------------------------------------------------*/ |
---|
138 | static void |
---|
139 | printCHAR(char c) |
---|
140 | { |
---|
141 | *videoRamPtr++ = c | WHITE; |
---|
142 | cursCol++; |
---|
143 | if (cursCol == videoCols) |
---|
144 | { |
---|
145 | cursCol = 0; |
---|
146 | cursRow++; |
---|
147 | if (cursRow == videoRows) |
---|
148 | { |
---|
149 | cursRow--; |
---|
150 | scrollUp(1); |
---|
151 | videoRamPtr -= videoCols; |
---|
152 | } |
---|
153 | } |
---|
154 | } /* printCHAR */ |
---|
155 | |
---|
156 | |
---|
157 | /*-------------------------------------------------------------------------+ |
---|
158 | | Function: printBS |
---|
159 | | Description: Print BS (BackSpace - '\b') character to display. |
---|
160 | | Global Variables: videoRamPtr, cursRow, cursCol. |
---|
161 | | Arguments: None. |
---|
162 | | Returns: Nothing. |
---|
163 | +--------------------------------------------------------------------------*/ |
---|
164 | static inline void |
---|
165 | printBS(void) |
---|
166 | { |
---|
167 | /* Move cursor back one cell. */ |
---|
168 | if (cursCol > 0) |
---|
169 | cursCol--; |
---|
170 | else if (cursRow > 0) |
---|
171 | { |
---|
172 | cursRow--; |
---|
173 | cursCol = videoCols - 1; |
---|
174 | } |
---|
175 | else |
---|
176 | return; |
---|
177 | |
---|
178 | /* Write a whitespace. */ |
---|
179 | *(--videoRamPtr) = BLANK; |
---|
180 | } /* printBS */ |
---|
181 | |
---|
182 | |
---|
183 | /*-------------------------------------------------------------------------+ |
---|
184 | | Function: printHT |
---|
185 | | Description: Print HT (Horizontal Tab - '\t') character to display. |
---|
186 | | Global Variables: cursCol. |
---|
187 | | Arguments: None. |
---|
188 | | Returns: Nothing. |
---|
189 | +--------------------------------------------------------------------------*/ |
---|
190 | static inline void |
---|
191 | printHT(void) |
---|
192 | { |
---|
193 | do |
---|
194 | printCHAR(' '); |
---|
195 | while (cursCol % TABSIZE); |
---|
196 | } /* printHT */ |
---|
197 | |
---|
198 | |
---|
199 | /*-------------------------------------------------------------------------+ |
---|
200 | | Function: printLF |
---|
201 | | Description: Print LF (Line Feed - '\n') character to display. |
---|
202 | | Global Variables: cursRow. |
---|
203 | | Arguments: None. |
---|
204 | | Returns: Nothing. |
---|
205 | +--------------------------------------------------------------------------*/ |
---|
206 | static inline void |
---|
207 | printLF(void) |
---|
208 | { |
---|
209 | cursRow++; |
---|
210 | if (cursRow == videoRows) |
---|
211 | { |
---|
212 | cursRow--; |
---|
213 | scrollUp(1); |
---|
214 | } |
---|
215 | updateVideoRamPtr(); |
---|
216 | } /* printLF */ |
---|
217 | |
---|
218 | |
---|
219 | /*-------------------------------------------------------------------------+ |
---|
220 | | Function: printCR |
---|
221 | | Description: Print CR (Carriage Return - '\r') to display. |
---|
222 | | Global Variables: cursCol. |
---|
223 | | Arguments: None. |
---|
224 | | Returns: Nothing. |
---|
225 | +--------------------------------------------------------------------------*/ |
---|
226 | static inline void |
---|
227 | printCR(void) |
---|
228 | { |
---|
229 | cursCol = 0; |
---|
230 | updateVideoRamPtr(); |
---|
231 | } /* printCR */ |
---|
232 | |
---|
233 | |
---|
234 | /*-------------------------------------------------------------------------+ |
---|
235 | | Function: consPutc |
---|
236 | | Description: Print a character to display at current position. |
---|
237 | | Global Variables: videoRamPtr, videoRam. |
---|
238 | | Arguments: c - character to write to display. |
---|
239 | | Returns: Nothing. |
---|
240 | +--------------------------------------------------------------------------*/ |
---|
241 | static void |
---|
242 | consPutc(char c) |
---|
243 | { |
---|
244 | switch (c) |
---|
245 | { |
---|
246 | case '\b': printBS(); break; |
---|
247 | case '\t': printHT(); break; |
---|
248 | case '\n': printLF(); break; |
---|
249 | case '\r': printCR(); break; |
---|
250 | default: printCHAR(c); break; |
---|
251 | } /* switch */ |
---|
252 | |
---|
253 | setHardwareCursorPos(videoRamPtr - videoRam); |
---|
254 | /* At current offset into videoRam */ |
---|
255 | } /* consPutc */ |
---|
256 | |
---|
257 | |
---|
258 | /*-------------------------------------------------------------------------+ |
---|
259 | | Function: _IBMPC_outch |
---|
260 | | Description: Higher level (console) interface to consPutc. |
---|
261 | | Global Variables: None. |
---|
262 | | Arguments: c - character to write to console. |
---|
263 | | Returns: Nothing. |
---|
264 | +--------------------------------------------------------------------------*/ |
---|
265 | void |
---|
266 | _IBMPC_outch(char c) |
---|
267 | { |
---|
268 | consPutc(c); |
---|
269 | } /* _IBMPC_outch */ |
---|
270 | |
---|
271 | |
---|
272 | /*-------------------------------------------------------------------------+ |
---|
273 | | Function: _IBMPC_initVideo |
---|
274 | | Description: Video system initialization. Hook for any early setup. |
---|
275 | | Global Variables: videoRows. |
---|
276 | | Arguments: None. |
---|
277 | | Returns: Nothing. |
---|
278 | +--------------------------------------------------------------------------*/ |
---|
279 | void |
---|
280 | _IBMPC_initVideo(void) |
---|
281 | { |
---|
282 | scrollUp(videoRows); /* Clear entire screen */ |
---|
283 | setHardwareCursorPos(0); /* Cursor at upper left corner */ |
---|
284 | } /* _IBMPC_initVideo */ |
---|