source: rtems/c/src/lib/libbsp/powerpc/ppcn_60x/console/vga.c @ 14b34738

Last change on this file since 14b34738 was 14b34738, checked in by Joel Sherrill <joel.sherrill@…>, on Sep 4, 2003 at 5:31:07 PM

2003-09-04 Joel Sherrill <joel@…>

  • console/vga.c, universe/universe.c: Removed incorrect statement about copyright assignment.
  • Property mode set to 100644
File size: 9.3 KB
Line 
1/*
2 *  This file contains the TTY driver for VGA
3 *
4 *  COPYRIGHT (c) 1998 by Radstone Technology
5 *
6 *
7 * THIS FILE IS PROVIDED TO YOU, THE USER, "AS IS", WITHOUT WARRANTY OF ANY
8 * KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
9 * IMPLIED WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK
10 * AS TO THE QUALITY AND PERFORMANCE OF ALL CODE IN THIS FILE IS WITH YOU.
11 *
12 * You are hereby granted permission to use, copy, modify, and distribute
13 * this file, provided that this notice, plus the above copyright notice
14 * and disclaimer, appears in all copies. Radstone Technology will provide
15 * no support for this code.
16 *
17 *  This driver uses the termios pseudo driver.
18 */
19/*-------------------------------------------------------------------------+
20| (C) Copyright 1997 -
21| - NavIST Group - Real-Time Distributed Systems and Industrial Automation
22|
23| http://pandora.ist.utl.pt
24|
25| Instituto Superior Tecnico * Lisboa * PORTUGAL
26+--------------------------------------------------------------------------+
27| Disclaimer:
28|
29| This file is provided "AS IS" without warranty of any kind, either
30| expressed or implied.
31+--------------------------------------------------------------------------+
32| This code is based on:
33|   outch.c,v 1.4 1995/12/19 20:07:27 joel Exp - go32 BSP
34| With the following copyright notice:
35| **************************************************************************
36| * COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994.                      *
37| * On-Line Applications Research Corporation (OAR).                       *
38| **************************************************************************
39+--------------------------------------------------------------------------*/
40
41
42#include <bsp.h>
43
44#include <stdlib.h>
45#include <string.h>
46
47#include "vga_p.h"
48
49/*-------------------------------------------------------------------------+
50| Constants
51+--------------------------------------------------------------------------*/
52#define DISPLAY_CELL_COUNT (VGA_NUM_ROWS * VGA_NUM_COLS)
53                                       /* Number of display cells.            */
54#define TABSIZE 4                      /* Number of spaces for TAB (\t) char. */
55#define WHITE   0x0007                 /* White on Black background colour.   */
56#define BLANK   (WHITE | (' '<<8))     /* Blank character.                    */
57
58/*
59 * This is imported from i8042.c to provide flow control
60 */
61extern volatile boolean bScrollLock;
62
63/*-------------------------------------------------------------------------+
64| Global Variables
65+--------------------------------------------------------------------------*/
66/* Physical address of start of video text memory. */
67static unsigned16 *videoRam    = (unsigned16 *)VGA_FB;
68/* Pointer for current output position in display. */
69static unsigned16 *videoRamPtr = (unsigned16 *)VGA_FB;
70static unsigned8  videoRows = VGA_NUM_ROWS; /* Number of rows in display.    */
71static unsigned8  videoCols = VGA_NUM_COLS; /* Number of columns in display. */
72static unsigned8  cursRow   = 0;       /* Current cursor row.           */
73static unsigned8  cursCol   = 0;       /* Current cursor column.        */
74
75
76/*-------------------------------------------------------------------------+
77|         Function: setHardwareCursorPos
78|      Description: Set hardware video cursor at given offset into video RAM.
79| Global Variables: None.
80|        Arguments: videoCursor - Offset into video memory.
81|          Returns: Nothing.
82+--------------------------------------------------------------------------*/
83static inline void
84setHardwareCursorPos(unsigned16 videoCursor)
85{
86        VGA_WRITE_CRTC(0x0e, (videoCursor >> 8) & 0xff);
87        VGA_WRITE_CRTC(0x0f, videoCursor & 0xff);
88} /* setHardwareCursorPos */
89
90
91/*-------------------------------------------------------------------------+
92|         Function: updateVideoRamPtr
93|      Description: Updates value of global variable "videoRamPtr" based on
94|                   current window's cursor position.
95| Global Variables: videoRamPtr, cursRow, cursCol.
96|        Arguments: None.
97|          Returns: Nothing.
98+--------------------------------------------------------------------------*/
99static inline void
100updateVideoRamPtr(void)
101{
102        videoRamPtr = videoRam + cursRow * videoCols + cursCol;
103} /* updateVideoRamPtr */
104
105
106/*-------------------------------------------------------------------------+
107|         Function: scrollUp
108|      Description: Scrolls display up n lines.
109| Global Variables: None.
110|        Arguments: lines - number of lines to scroll.
111|          Returns: Nothing.
112+--------------------------------------------------------------------------*/
113static void
114scrollUp(unsigned8 lines)
115{
116        /* Number of blank display cells on bottom of window. */
117        unsigned16 blankCount;
118
119       /* Source and destination pointers for memory copy operations. */
120        unsigned16 *ptrDst, *ptrSrc;
121
122        if(lines<videoRows)  /* Move window's contents up. */
123        {
124                /*
125                 * Number of non-blank cells on upper part
126                 * of display (total - blank).
127                 */
128                unsigned16 nonBlankCount;
129
130                blankCount = lines * videoCols;
131                nonBlankCount = DISPLAY_CELL_COUNT - blankCount;
132                ptrSrc = videoRam + blankCount;
133                ptrDst = videoRam; 
134
135                while(nonBlankCount--)
136                {
137                        *ptrDst++ = *ptrSrc++;
138                }
139        }
140        else
141        {
142                /*
143                 * Clear the whole display.
144                 */
145                blankCount = DISPLAY_CELL_COUNT;
146                ptrDst = videoRam;
147        }
148
149        /* Fill bottom with blanks. */
150        while (blankCount-->0)
151        {
152                *ptrDst++ = BLANK;
153        }
154} /* scrollUp */
155
156
157/*-------------------------------------------------------------------------+
158|         Function: printCHAR
159|      Description: Print printable character to display.
160| Global Variables: videoRamPtr, cursRow, cursCol.
161|        Arguments: c - character to write to display.
162|          Returns: Nothing.
163+--------------------------------------------------------------------------*/
164static void
165printCHAR(char c)
166{
167        *videoRamPtr++ = (c<<8) | WHITE;
168        cursCol++;
169        if(cursCol==videoCols)
170        {
171                cursCol = 0;
172                cursRow++;
173                if(cursRow==videoRows)
174                {
175                        cursRow--;
176                        scrollUp(1);
177                        videoRamPtr -= videoCols;
178                }
179        }
180} /* printCHAR */
181
182/*-------------------------------------------------------------------------+
183|         Function: printBS
184|      Description: Print BS (BackSpace - '\b') character to display.
185| Global Variables: videoRamPtr, cursRow, cursCol.
186|        Arguments: None.
187|          Returns: Nothing.
188+--------------------------------------------------------------------------*/
189static inline void
190printBS(void)
191{
192        /* Move cursor back one cell. */
193        if(cursCol>0)
194        {
195                cursCol--;
196        }
197        else if(cursRow>0)
198        {
199                cursRow--;
200                cursCol = videoCols - 1;
201        }
202        else
203        {
204                return;
205        }
206
207        /* Write a whitespace. */
208        *(--videoRamPtr) = BLANK;
209} /* printBS */
210
211
212/*-------------------------------------------------------------------------+
213|         Function: printHT
214|      Description: Print HT (Horizontal Tab - '\t') character to display.
215| Global Variables: cursCol.
216|        Arguments: None.
217|          Returns: Nothing.
218+--------------------------------------------------------------------------*/
219static inline void
220printHT(void)
221{
222        do
223        {
224                printCHAR(' ');
225        }
226        while (cursCol % TABSIZE);
227} /* printHT */
228
229
230/*-------------------------------------------------------------------------+
231|         Function: printLF
232|      Description: Print LF (Line Feed  - '\n') character to display.
233| Global Variables: cursRow.
234|        Arguments: None.
235|          Returns: Nothing.
236+--------------------------------------------------------------------------*/
237static inline void
238printLF(void)
239{
240        cursRow++;
241        if(cursRow==videoRows)
242        {
243                cursRow--;
244                scrollUp(1);
245        }
246        updateVideoRamPtr();
247} /* printLF */
248
249
250/*-------------------------------------------------------------------------+
251|         Function: printCR
252|      Description: Print CR (Carriage Return - '\r') to display.
253| Global Variables: cursCol.
254|        Arguments: None.
255|          Returns: Nothing.
256+--------------------------------------------------------------------------*/
257static inline void
258printCR(void)
259{
260        cursCol = 0;
261        updateVideoRamPtr();
262} /* printCR */
263
264/*
265 *  Console Device Driver Entry Points
266 */
267void
268vga_write(
269        int   minor, 
270        char cChar)
271{
272        switch (cChar)
273        {
274                case '\b':
275                        printBS();
276                        break;
277                case '\t':
278                        printHT();
279                        break;
280                case '\n':
281                        printLF();
282                        break;
283                case '\r':
284                        printCR();
285                        break;
286                default:
287                        printCHAR(cChar);
288                        break;
289        }
290
291        setHardwareCursorPos(videoRamPtr - videoRam);
292} /* vga_write */
293
294/*
295 *  vga_write_support
296 *
297 *  Console Termios output entry point.
298 *
299 */
300int vga_write_support(
301        int   minor, 
302        const char *buf, 
303        int   len
304)
305{
306        int nwrite = 0;
307
308        while(bScrollLock)
309        {
310                /*
311                 * The Scroll lock on the keyboard is active
312                 */
313                /*
314                 * Yield while we wait
315                 */
316                rtems_task_wake_after(RTEMS_YIELD_PROCESSOR);
317        }
318
319        /*
320         * Write each byte in the string to the display
321         */
322        while (nwrite<len)
323        {
324                /*
325                 * transmit character
326                 */
327                vga_write(minor, *buf++);
328                nwrite++;
329        }
330
331        /*
332         * return the number of bytes written.
333         */
334        return nwrite;
335}
336
337boolean vga_probe(int minor)
338{
339        unsigned8 ucMiscIn;
340
341        /*
342         * Check for presence of VGA adaptor
343         */
344        inport_byte(0x3cc, ucMiscIn);
345        if(ucMiscIn!=0xff)
346        {
347                /*
348                 * VGA device is present
349                 */
350                return(TRUE);
351        }
352        return(FALSE);
353}
354
355void vga_init(int minor)
356{
357        scrollUp(videoRows);     /* Clear entire screen         */
358        setHardwareCursorPos(0); /* Cursor at upper left corner */
359        /*
360         * Enable the cursor
361         */
362        VGA_WRITE_CRTC(0x0a, 0x0e);     /* Crt cursor start */
363}
Note: See TracBrowser for help on using the repository browser.