source: rtems/c/src/lib/libbsp/powerpc/ppcn_60x/console/vga.c @ 0c04c377

4.104.114.84.9
Last change on this file since 0c04c377 was 0c04c377, checked in by Joel Sherrill <joel.sherrill@…>, on Feb 18, 1999 at 4:48:14 PM

./clock/Makefile.in,v
./clock/clock.c,v
./console/Makefile.in,v
./console/config.c,v
./console/console.c,v
./console/console.h,v
./console/debugio.c,v
./console/i8042.c,v
./console/i8042_p.h,v
./console/i8042vga.c,v
./console/i8042vga.h,v
./console/ns16550.c,v
./console/ns16550.h,v
./console/ns16550_p.h,v
./console/ns16550cfg.c,v
./console/ns16550cfg.h,v
./console/vga.c,v
./console/vga_p.h,v
./console/z85c30.c,v
./console/z85c30.h,v
./console/z85c30_p.h,v
./console/z85c30cfg.c,v
./console/z85c30cfg.h,v
./include/Makefile.in,v
./include/bsp.h,v
./include/chain.h,v
./include/coverhd.h,v
./include/extisrdrv.h,v
./include/nvram.h,v
./include/pci.h,v
./include/tod.h,v
./network/Makefile.in,v
./network/amd79c970.c,v
./network/amd79c970.h,v
./nvram/Makefile.in,v
./nvram/ds1385.h,v
./nvram/mk48t18.h,v
./nvram/nvram.c,v
./nvram/prepnvr.h,v
./nvram/stk11c68.h,v
./pci/Makefile.in,v
./pci/pci.c,v
./start/Makefile.in,v
./start/start.s,v
./startup/Makefile.in,v
./startup/bspclean.c,v
./startup/bspstart.c,v
./startup/bsptrap.s,v
./startup/device-tree,v
./startup/genpvec.c,v
./startup/linkcmds,v
./startup/rtems-ctor.cc,v
./startup/sbrk.c,v
./startup/setvec.c,v
./startup/spurious.c,v
./startup/swap.c,v
./timer/Makefile.in,v
./timer/timer.c,v
./tod/Makefile.in,v
./tod/cmos.h,v
./tod/tod.c,v
./universe/Makefile.in,v
./universe/universe.c,v
./vectors/Makefile.in,v
./vectors/README,v
./vectors/align_h.s,v
./vectors/vectors.s,v
./wrapup/Makefile.in,v
./Makefile.in,v
./README,v
./STATUS,v
./bsp_specs,v

  • Property mode set to 100644
File size: 9.6 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| * All rights assigned to U.S. Government, 1994.                          *
39| *                                                                        *
40| * This material may be reproduced by or for the U.S. Government pursuant *
41| * to the copyright license under the clause at DFARS 252.227-7013.  This *
42| * notice must appear in all copies of this file and its derivatives.     *
43| **************************************************************************
44+--------------------------------------------------------------------------*/
45
46
47#include <bsp.h>
48
49#include <stdlib.h>
50#include <string.h>
51
52#include "vga_p.h"
53
54/*-------------------------------------------------------------------------+
55| Constants
56+--------------------------------------------------------------------------*/
57#define DISPLAY_CELL_COUNT (VGA_NUM_ROWS * VGA_NUM_COLS)
58                                       /* Number of display cells.            */
59#define TABSIZE 4                      /* Number of spaces for TAB (\t) char. */
60#define WHITE   0x0007                 /* White on Black background colour.   */
61#define BLANK   (WHITE | (' '<<8))     /* Blank character.                    */
62
63/*
64 * This is imported from i8042.c to provide flow control
65 */
66extern volatile boolean bScrollLock;
67
68/*-------------------------------------------------------------------------+
69| Global Variables
70+--------------------------------------------------------------------------*/
71/* Physical address of start of video text memory. */
72static unsigned16 *videoRam    = (unsigned16 *)VGA_FB;
73/* Pointer for current output position in display. */
74static unsigned16 *videoRamPtr = (unsigned16 *)VGA_FB;
75static unsigned8  videoRows = VGA_NUM_ROWS; /* Number of rows in display.    */
76static unsigned8  videoCols = VGA_NUM_COLS; /* Number of columns in display. */
77static unsigned8  cursRow   = 0;       /* Current cursor row.           */
78static unsigned8  cursCol   = 0;       /* Current cursor column.        */
79
80
81/*-------------------------------------------------------------------------+
82|         Function: setHardwareCursorPos
83|      Description: Set hardware video cursor at given offset into video RAM.
84| Global Variables: None.
85|        Arguments: videoCursor - Offset into video memory.
86|          Returns: Nothing.
87+--------------------------------------------------------------------------*/
88static inline void
89setHardwareCursorPos(unsigned16 videoCursor)
90{
91        VGA_WRITE_CRTC(0x0e, (videoCursor >> 8) & 0xff);
92        VGA_WRITE_CRTC(0x0f, videoCursor & 0xff);
93} /* setHardwareCursorPos */
94
95
96/*-------------------------------------------------------------------------+
97|         Function: updateVideoRamPtr
98|      Description: Updates value of global variable "videoRamPtr" based on
99|                   current window's cursor position.
100| Global Variables: videoRamPtr, cursRow, cursCol.
101|        Arguments: None.
102|          Returns: Nothing.
103+--------------------------------------------------------------------------*/
104static inline void
105updateVideoRamPtr(void)
106{
107        videoRamPtr = videoRam + cursRow * videoCols + cursCol;
108} /* updateVideoRamPtr */
109
110
111/*-------------------------------------------------------------------------+
112|         Function: scrollUp
113|      Description: Scrolls display up n lines.
114| Global Variables: None.
115|        Arguments: lines - number of lines to scroll.
116|          Returns: Nothing.
117+--------------------------------------------------------------------------*/
118static void
119scrollUp(unsigned8 lines)
120{
121        /* Number of blank display cells on bottom of window. */
122        unsigned16 blankCount;
123
124       /* Source and destination pointers for memory copy operations. */
125        unsigned16 *ptrDst, *ptrSrc;
126
127        if(lines<videoRows)  /* Move window's contents up. */
128        {
129                /*
130                 * Number of non-blank cells on upper part
131                 * of display (total - blank).
132                 */
133                unsigned16 nonBlankCount;
134
135                blankCount = lines * videoCols;
136                nonBlankCount = DISPLAY_CELL_COUNT - blankCount;
137                ptrSrc = videoRam + blankCount;
138                ptrDst = videoRam; 
139
140                while(nonBlankCount--)
141                {
142                        *ptrDst++ = *ptrSrc++;
143                }
144        }
145        else
146        {
147                /*
148                 * Clear the whole display.
149                 */
150                blankCount = DISPLAY_CELL_COUNT;
151                ptrDst = videoRam;
152        }
153
154        /* Fill bottom with blanks. */
155        while (blankCount-->0)
156        {
157                *ptrDst++ = BLANK;
158        }
159} /* scrollUp */
160
161
162/*-------------------------------------------------------------------------+
163|         Function: printCHAR
164|      Description: Print printable character to display.
165| Global Variables: videoRamPtr, cursRow, cursCol.
166|        Arguments: c - character to write to display.
167|          Returns: Nothing.
168+--------------------------------------------------------------------------*/
169static void
170printCHAR(char c)
171{
172        *videoRamPtr++ = (c<<8) | WHITE;
173        cursCol++;
174        if(cursCol==videoCols)
175        {
176                cursCol = 0;
177                cursRow++;
178                if(cursRow==videoRows)
179                {
180                        cursRow--;
181                        scrollUp(1);
182                        videoRamPtr -= videoCols;
183                }
184        }
185} /* printCHAR */
186
187/*-------------------------------------------------------------------------+
188|         Function: printBS
189|      Description: Print BS (BackSpace - '\b') character to display.
190| Global Variables: videoRamPtr, cursRow, cursCol.
191|        Arguments: None.
192|          Returns: Nothing.
193+--------------------------------------------------------------------------*/
194static inline void
195printBS(void)
196{
197        /* Move cursor back one cell. */
198        if(cursCol>0)
199        {
200                cursCol--;
201        }
202        else if(cursRow>0)
203        {
204                cursRow--;
205                cursCol = videoCols - 1;
206        }
207        else
208        {
209                return;
210        }
211
212        /* Write a whitespace. */
213        *(--videoRamPtr) = BLANK;
214} /* printBS */
215
216
217/*-------------------------------------------------------------------------+
218|         Function: printHT
219|      Description: Print HT (Horizontal Tab - '\t') character to display.
220| Global Variables: cursCol.
221|        Arguments: None.
222|          Returns: Nothing.
223+--------------------------------------------------------------------------*/
224static inline void
225printHT(void)
226{
227        do
228        {
229                printCHAR(' ');
230        }
231        while (cursCol % TABSIZE);
232} /* printHT */
233
234
235/*-------------------------------------------------------------------------+
236|         Function: printLF
237|      Description: Print LF (Line Feed  - '\n') character to display.
238| Global Variables: cursRow.
239|        Arguments: None.
240|          Returns: Nothing.
241+--------------------------------------------------------------------------*/
242static inline void
243printLF(void)
244{
245        cursRow++;
246        if(cursRow==videoRows)
247        {
248                cursRow--;
249                scrollUp(1);
250        }
251        updateVideoRamPtr();
252} /* printLF */
253
254
255/*-------------------------------------------------------------------------+
256|         Function: printCR
257|      Description: Print CR (Carriage Return - '\r') to display.
258| Global Variables: cursCol.
259|        Arguments: None.
260|          Returns: Nothing.
261+--------------------------------------------------------------------------*/
262static inline void
263printCR(void)
264{
265        cursCol = 0;
266        updateVideoRamPtr();
267} /* printCR */
268
269/*
270 *  Console Device Driver Entry Points
271 */
272void
273vga_write(
274        int   minor, 
275        char cChar)
276{
277        switch (cChar)
278        {
279                case '\b':
280                        printBS();
281                        break;
282                case '\t':
283                        printHT();
284                        break;
285                case '\n':
286                        printLF();
287                        break;
288                case '\r':
289                        printCR();
290                        break;
291                default:
292                        printCHAR(cChar);
293                        break;
294        }
295
296        setHardwareCursorPos(videoRamPtr - videoRam);
297} /* vga_write */
298
299/*
300 *  vga_write_support
301 *
302 *  Console Termios output entry point.
303 *
304 */
305int vga_write_support(
306        int   minor, 
307        const char *buf, 
308        int   len
309)
310{
311        int nwrite = 0;
312
313        while(bScrollLock)
314        {
315                /*
316                 * The Scroll lock on the keyboard is active
317                 */
318                /*
319                 * Yield while we wait
320                 */
321                rtems_task_wake_after(RTEMS_YIELD_PROCESSOR);
322        }
323
324        /*
325         * Write each byte in the string to the display
326         */
327        while (nwrite<len)
328        {
329                /*
330                 * transmit character
331                 */
332                vga_write(minor, *buf++);
333                nwrite++;
334        }
335
336        /*
337         * return the number of bytes written.
338         */
339        return nwrite;
340}
341
342boolean vga_probe(int minor)
343{
344        unsigned8 ucMiscIn;
345
346        /*
347         * Check for presence of VGA adaptor
348         */
349        inport_byte(0x3cc, ucMiscIn);
350        if(ucMiscIn!=0xff)
351        {
352                /*
353                 * VGA device is present
354                 */
355                return(TRUE);
356        }
357        return(FALSE);
358}
359
360void vga_init(int minor)
361{
362        scrollUp(videoRows);     /* Clear entire screen         */
363        setHardwareCursorPos(0); /* Cursor at upper left corner */
364        /*
365         * Enable the cursor
366         */
367        VGA_WRITE_CRTC(0x0a, 0x0e);     /* Crt cursor start */
368}
Note: See TracBrowser for help on using the repository browser.