source: rtems/c/src/lib/libbsp/i386/pc386/console/outch.c @ 7150f00f

4.104.114.84.95
Last change on this file since 7150f00f was 7150f00f, checked in by Joel Sherrill <joel.sherrill@…>, on Dec 1, 1997 at 10:06:48 PM

Inclusion of PC386 BSP submitted by Pedro Miguel Da Cruz Neto Romano
<pmcnr@…> and Jose Rufino <ruf@…>
of NavIST (http://pandora.ist.utl.pt/).

  • Property mode set to 100644
File size: 9.5 KB
Line 
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+--------------------------------------------------------------------------*/
49static rtems_unsigned16 *videoRam    = TVRAM;
50                           /* Physical address of start of video text memory. */
51static rtems_unsigned16 *videoRamPtr = TVRAM;
52                           /* Pointer for current output position in display. */
53static rtems_unsigned8  videoRows = MAX_ROW; /* Number of rows in display.    */
54static rtems_unsigned8  videoCols = MAX_COL; /* Number of columns in display. */
55static rtems_unsigned8  cursRow   = 0;       /* Current cursor row.           */
56static 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+--------------------------------------------------------------------------*/
66static inline void
67setHardwareCursorPos(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+--------------------------------------------------------------------------*/
84static inline void
85updateVideoRamPtr(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+--------------------------------------------------------------------------*/
98static void
99scrollUp(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+--------------------------------------------------------------------------*/
138static void
139printCHAR(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+--------------------------------------------------------------------------*/
164static inline void
165printBS(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+--------------------------------------------------------------------------*/
190static inline void
191printHT(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+--------------------------------------------------------------------------*/
206static inline void
207printLF(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+--------------------------------------------------------------------------*/
226static inline void
227printCR(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+--------------------------------------------------------------------------*/
241static void
242consPutc(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+--------------------------------------------------------------------------*/
265void
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+--------------------------------------------------------------------------*/
279void
280_IBMPC_initVideo(void)
281{
282  scrollUp(videoRows);     /* Clear entire screen         */
283  setHardwareCursorPos(0); /* Cursor at upper left corner */
284} /* _IBMPC_initVideo */
Note: See TracBrowser for help on using the repository browser.