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