2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
29 * VGA text console support.
33 #include <console/video_console.h>
36 * Macros and typedefs.
38 typedef short csrpos_t
; /* cursor position, ONE_SPACE bytes per char */
40 #define ONE_SPACE 2 /* bytes per character */
41 #define ONE_LINE (vga_cols * ONE_SPACE) /* number of bytes in line */
42 #define ONE_PAGE (vga_rows * ONE_LINE) /* number of bytes in page */
43 #define SPACE_CHAR 0x20
45 #define VGA_FB_START 0x0b8000
46 #define VGA_FB_SIZE 0x8000
47 #define VGA_IDX_REG 0x3d4
48 #define VGA_IO_REG 0x3d5
51 * Commands sent to graphics adapter.
53 #define VGA_C_LOW 0x0f /* return low byte of cursor addr */
54 #define VGA_C_HIGH 0x0e /* high byte */
57 * Attributes for character sent to display.
59 #define VGA_ATTR_NORMAL 0x07
60 #define VGA_ATTR_REVERSE 0x70
63 * Convert from XY coordinate to a location in display memory.
65 #define XY_TO_CSRPOS(x, y) (((y) * vga_cols + (x)) * ONE_SPACE)
70 static short vga_idx_reg
= 0; /* location of VGA index register */
71 static short vga_io_reg
= 0; /* location of VGA data register */
72 static short vga_cols
= 80; /* number of columns */
73 static short vga_rows
= 25; /* number of rows */
74 static char vga_attr
= 0; /* current character attribute */
75 static char vga_attr_rev
= 0; /* current reverse attribute */
76 static char * vram_start
= 0; /* VM start of VGA frame buffer */
79 * Functions in kdasm.s.
81 extern void kd_slmwd(unsigned char * pos
, int count
, unsigned short val
);
82 extern void kd_slmscu(unsigned char * from
, unsigned char * to
, int count
);
83 extern void kd_slmscd(unsigned char * from
, unsigned char * to
, int count
);
88 * Block move up for VGA.
91 move_up( csrpos_t from
,
95 kd_slmscu( vram_start
+ from
, vram_start
+ to
, count
);
101 * Block move down for VGA.
104 move_down( csrpos_t from
,
108 kd_slmscd( vram_start
+ from
, vram_start
+ to
, count
);
114 * Fast clear for VGA.
117 clear_block( csrpos_t start
,
121 kd_slmwd( vram_start
+ start
, size
,
122 ((unsigned short) attr
<< 8) + SPACE_CHAR
);
126 * set_cursor_position
128 * This function sets the hardware cursor position
132 set_cursor_position( csrpos_t newpos
)
134 short curpos
; /* position, not scaled for attribute byte */
136 curpos
= newpos
/ ONE_SPACE
;
138 outb(vga_idx_reg
, VGA_C_HIGH
);
139 outb(vga_io_reg
, (unsigned char)(curpos
>> 8));
141 outb(vga_idx_reg
, VGA_C_LOW
);
142 outb(vga_io_reg
, (unsigned char)(curpos
& 0xff));
148 * Display attributed character for VGA (mode 3).
151 display_char( csrpos_t pos
, /* where to put it */
152 char ch
, /* the character */
153 char attr
) /* its attribute */
155 *(vram_start
+ pos
) = ch
;
156 *(vram_start
+ pos
+ 1) = attr
;
162 * Initialize the VGA text console.
165 vga_init(int cols
, int rows
, unsigned char * addr
)
168 vga_idx_reg
= VGA_IDX_REG
;
169 vga_io_reg
= VGA_IO_REG
;
172 vga_attr
= VGA_ATTR_NORMAL
;
173 vga_attr_rev
= VGA_ATTR_REVERSE
;
175 set_cursor_position(0);
181 * Scroll the screen up 'n' character lines.
184 tc_scroll_up( int lines
, int top
, int bottom
)
192 from
= ONE_LINE
* lines
;
193 size
= ( ONE_PAGE
- ( ONE_LINE
* lines
) ) / ONE_SPACE
;
194 move_up(from
, to
, size
);
196 /* clear bottom line */
197 to
= ( ( vga_rows
- lines
) * ONE_LINE
);
198 size
= ( ONE_LINE
* lines
) / ONE_SPACE
;
199 clear_block(to
, size
, vga_attr
);
205 * Scrolls the screen down 'n' character lines.
208 tc_scroll_down( int lines
, int top
, int bottom
)
215 to
= ONE_PAGE
- ONE_SPACE
;
216 from
= ONE_PAGE
- ( ONE_LINE
* lines
) - ONE_SPACE
;
217 size
= ( ONE_PAGE
- ( ONE_LINE
* lines
) ) / ONE_SPACE
;
218 move_down(from
, to
, size
);
222 size
= ( ONE_LINE
* lines
) / ONE_SPACE
;
223 clear_block(to
, size
, vga_attr
);
226 /* Default colors for 16-color palette */
241 kVGAColorLightMagenta
,
249 * Update the foreground / background color.
252 tc_update_color( int color
, int fore
)
254 unsigned char mask_on
, mask_off
;
258 case 1: mask_on
= kVGAColorRed
; break;
259 case 3: mask_on
= kVGAColorLightBrown
; break;
260 case 4: mask_on
= kVGAColorBlue
; break;
261 case 6: mask_on
= kVGAColorCyan
; break;
262 default: mask_on
= color
; break;
275 vga_attr
= (vga_attr
& ~mask_off
) | mask_on
;
277 vga_attr_rev
= ( ((vga_attr
<< 4) & 0xf0) |
278 ((vga_attr
>> 4) & 0x0f) );
284 * Show the hardware cursor.
287 tc_show_cursor( int x
, int y
)
289 set_cursor_position( XY_TO_CSRPOS(x
, y
) );
295 * Hide the hardware cursor.
298 tc_hide_cursor( int x
, int y
)
306 * Clear the entire screen, or a portion of the screen
307 * relative to the current cursor position.
310 tc_clear_screen(int x
, int y
, int top
, int bottom
, int operation
)
317 case 0: /* To end of screen */
318 start
= XY_TO_CSRPOS(x
, y
);
319 count
= ONE_PAGE
- start
;
321 case 1: /* To start of screen */
323 count
= XY_TO_CSRPOS(x
, y
) + ONE_SPACE
;
326 case 2: /* Whole screen */
331 clear_block(start
, count
, vga_attr
);
337 * Display a character on screen with the given coordinates,
341 tc_paint_char( int x
, int y
, unsigned char ch
, int attrs
, unsigned char ch_previous
, int attrs_previous
)
343 char my_attr
= vga_attr
;
345 if ( attrs
& 4 ) my_attr
= vga_attr_rev
;
347 display_char( XY_TO_CSRPOS(x
, y
), ch
, vga_attr
);
353 * Enable / disable the console.
356 tc_enable(boolean_t enable
)
364 * Must be called before any other exported functions.
367 tc_initialize(struct vc_info
* vinfo_p
)
369 vinfo_p
->v_rows
= vinfo_p
->v_height
;
370 vinfo_p
->v_columns
= vinfo_p
->v_width
;
372 vga_init( vinfo_p
->v_columns
,
374 (unsigned char *) vinfo_p
->v_baseaddr
);