source: rtems/c/src/lib/libbsp/i386/go32/console/outch.c @ 4ca27cf

4.104.114.84.95
Last change on this file since 4ca27cf was 4ca27cf, checked in by Joel Sherrill <joel.sherrill@…>, on 07/18/95 at 21:19:53

committing for rtems-3.2.01 snapshot

  • Property mode set to 100644
File size: 2.8 KB
Line 
1/*
2 *  $Id$
3 */
4
5#include <go32.h>
6#include <bsp.h>
7
8#include <memory.h>
9
10#define MAX_COL 80
11#define MAX_ROW 50
12
13static unsigned         nrow            = 25;
14static unsigned         ncol            = 80;
15static unsigned short * tvram           = TVRAM;
16static unsigned char    current_col     = 0;
17static unsigned char    current_row     = 0;
18static unsigned short   screen_copy[ MAX_ROW*MAX_COL ];
19
20static void init_cons( void );
21
22/*
23 * set_cursor_pos()
24 *      Set cursor position based on current absolute screen offset
25 */
26static void
27set_cursor_pos(void)
28{
29    register unsigned short gdc_pos = current_row * ncol + current_col;
30    outport_byte( GDC_REG_PORT, 0xe );
31    outport_byte( GDC_VAL_PORT, (gdc_pos >> 8) & 0xff );
32    outport_byte( GDC_REG_PORT, 0xf );
33    outport_byte( GDC_VAL_PORT, gdc_pos & 0xff );
34}
35
36/*
37 * scroll_up()
38 *      Scroll screen up one line
39 */
40static void
41scroll_up( unsigned short * tv, unsigned short * copy, unsigned int lines )
42{
43    if ( lines > nrow )
44        lines = nrow;
45
46    /* move everything up */
47    memmove( copy, copy+ncol*lines, (nrow-lines)*ncol*sizeof copy[0] );
48
49    /* fill bottom with blanks */
50    {
51        int loop = ncol*lines;
52        unsigned short * ptr = copy + ncol*(nrow-lines);
53        while ( --loop >= 0 )
54            *ptr++ = (WHITE<<8) | ' ';
55    }
56
57    /* copy new screen to video buffer */
58    dosmemput( copy, nrow*ncol*sizeof copy[0], (int)tv );
59}
60
61
62/*
63 * PUT()
64 *      Write character at current screen location
65 */
66inline static void PUT( char c )
67{
68    unsigned short loc = current_row*ncol+current_col;
69    unsigned short val = (WHITE<<8) | c;
70    screen_copy[loc] = val;
71    dosmemput( &screen_copy[loc], sizeof screen_copy[0], (int)(tvram+loc) );
72}
73
74/*
75 * cons_putc()
76 *      Place a character on next screen position
77 */
78static void
79cons_putc( unsigned char c )
80{
81    static int first = 1;
82    if ( first )  {
83        init_cons();
84        first = 0;
85    }
86
87        switch (c) {
88        case '\t':
89                while ( current_row % 8 )
90                        cons_putc(' ');
91                break;
92        case '\r':
93                current_col = 0;
94                break;
95        case '\n':
96                if ( ++current_row >= nrow ) {
97                        scroll_up( tvram, screen_copy, 1 );
98                        current_row -= 1;
99                }
100                break;
101        case '\b':
102                if ( current_col > 0 ) {
103                        --current_col;
104                        PUT(' ');
105                }
106                break;
107        default:
108                PUT(c);
109                current_col += 1;
110                if ( current_col >= ncol ) {
111                        current_col = 0;
112                        current_row += 1;
113                        if ( current_row >= nrow ) {
114                                scroll_up( tvram, screen_copy, 1 );
115                                current_row -= 1;
116                        }
117                }
118        };
119        set_cursor_pos();
120}
121
122
123/*
124 * init_cons()
125 *      Hook for any early setup
126 */
127static void
128init_cons( void )
129{
130#if 0
131    /* Get a copy of original screen */
132    dosmemget( (int)tvram, nrow*ncol*sizeof *tvram, screen_copy );
133#else
134    /* Clear entire screen */
135    scroll_up( tvram, screen_copy, nrow );
136#endif
137}
138
139
140
141void _IBMPC_outch( unsigned char ch )
142{
143    extern int _IBMPC_Use_Go32_IO;
144
145    if ( _IBMPC_Use_Go32_IO )  {
146        write( 1, &ch, 1 );
147    } else {
148        cons_putc( ch );
149    }
150}
Note: See TracBrowser for help on using the repository browser.