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