2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
26 * VGA text console support.
30 #include <console/video_console.h>
31 #include "text_console.h"
34 * Macros and typedefs.
36 typedef short csrpos_t
; /* cursor position, ONE_SPACE bytes per char */
38 #define ONE_SPACE 2 /* bytes per character */
39 #define ONE_LINE (vga_cols * ONE_SPACE) /* number of bytes in line */
40 #define ONE_PAGE (vga_rows * ONE_LINE) /* number of bytes in page */
41 #define SPACE_CHAR 0x20
43 #define VGA_FB_START 0x0b8000
44 #define VGA_FB_SIZE 0x8000
45 #define VGA_IDX_REG 0x3d4
46 #define VGA_IO_REG 0x3d5
49 * Commands sent to graphics adapter.
51 #define VGA_C_START 0x0a /* cursor start position, on/off bit */
52 #define VGA_C_LOW 0x0f /* return low byte of cursor addr */
53 #define VGA_C_HIGH 0x0e /* high byte */
56 * Attributes for character sent to display.
58 #define VGA_ATTR_NORMAL 0x07
59 #define VGA_ATTR_REVERSE 0x70
62 * Cursor Start Register bit fields.
64 #define VGA_CURSOR_CS 0x1F
65 #define VGA_CURSOR_ON 0x20
68 * Convert from XY coordinate to a location in display memory.
70 #define XY_TO_CSRPOS(x, y) (((y) * vga_cols + (x)) * ONE_SPACE)
75 static short vga_idx_reg
= 0; /* location of VGA index register */
76 static short vga_io_reg
= 0; /* location of VGA data register */
77 static short vga_cols
= 80; /* number of columns */
78 static short vga_rows
= 25; /* number of rows */
79 static char vga_attr
= 0; /* current character attribute */
80 static char vga_attr_rev
= 0; /* current reverse attribute */
81 static char vga_cursor_start
= 0; /* cached cursor start scan line */
82 static char * vram_start
= 0; /* VM start of VGA frame buffer */
85 * Functions in kdasm.s.
87 extern void kd_slmwd(unsigned char * pos
, int count
, unsigned short val
);
88 extern void kd_slmscu(unsigned char * from
, unsigned char * to
, int count
);
89 extern void kd_slmscd(unsigned char * from
, unsigned char * to
, int count
);
94 * Block move up for VGA.
97 move_up( csrpos_t from
,
101 kd_slmscu( vram_start
+ from
, vram_start
+ to
, count
);
107 * Block move down for VGA.
110 move_down( csrpos_t from
,
114 kd_slmscd( vram_start
+ from
, vram_start
+ to
, count
);
120 * Fast clear for VGA.
123 clear_block( csrpos_t start
,
127 kd_slmwd( vram_start
+ start
, size
,
128 ((unsigned short) attr
<< 8) + SPACE_CHAR
);
132 * set_cursor_position
134 * This function sets the hardware cursor position
138 set_cursor_position( csrpos_t newpos
)
140 short curpos
; /* position, not scaled for attribute byte */
142 curpos
= newpos
/ ONE_SPACE
;
144 outb(vga_idx_reg
, VGA_C_HIGH
);
145 outb(vga_io_reg
, (unsigned char)(curpos
>> 8));
147 outb(vga_idx_reg
, VGA_C_LOW
);
148 outb(vga_io_reg
, (unsigned char)(curpos
& 0xff));
154 * Allow the cursor to be turned on or off.
157 set_cursor_enable( boolean_t enable
)
159 outb(vga_idx_reg
, VGA_C_START
);
160 outb(vga_io_reg
, vga_cursor_start
|
161 (enable
== TRUE
? VGA_CURSOR_ON
: 0));
167 * Display attributed character for VGA (mode 3).
170 display_char( csrpos_t pos
, /* where to put it */
171 char ch
, /* the character */
172 char attr
) /* its attribute */
174 *(vram_start
+ pos
) = ch
;
175 *(vram_start
+ pos
+ 1) = attr
;
181 * Initialize the VGA text console.
184 vga_init(int cols
, int rows
, unsigned char * addr
)
187 vga_idx_reg
= VGA_IDX_REG
;
188 vga_io_reg
= VGA_IO_REG
;
191 vga_attr
= VGA_ATTR_NORMAL
;
192 vga_attr_rev
= VGA_ATTR_REVERSE
;
194 /* cache cursor start position */
195 outb(vga_idx_reg
, VGA_C_START
);
196 vga_cursor_start
= inb(vga_io_reg
) & VGA_CURSOR_CS
;
198 /* defaults to a hidden hw cursor */
199 set_cursor_enable( FALSE
);
205 * Scroll the screen up 'n' character lines.
208 tc_scroll_up( int lines
, __unused
int top
, __unused
int bottom
)
216 from
= ONE_LINE
* lines
;
217 size
= ( ONE_PAGE
- ( ONE_LINE
* lines
) ) / ONE_SPACE
;
218 move_up(from
, to
, size
);
220 /* clear bottom line */
221 to
= ( ( vga_rows
- lines
) * ONE_LINE
);
222 size
= ( ONE_LINE
* lines
) / ONE_SPACE
;
223 clear_block(to
, size
, vga_attr
);
229 * Scrolls the screen down 'n' character lines.
232 tc_scroll_down( int lines
, __unused
int top
, __unused
int bottom
)
239 to
= ONE_PAGE
- ONE_SPACE
;
240 from
= ONE_PAGE
- ( ONE_LINE
* lines
) - ONE_SPACE
;
241 size
= ( ONE_PAGE
- ( ONE_LINE
* lines
) ) / ONE_SPACE
;
242 move_down(from
, to
, size
);
246 size
= ( ONE_LINE
* lines
) / ONE_SPACE
;
247 clear_block(to
, size
, vga_attr
);
250 /* Default colors for 16-color palette */
265 kVGAColorLightMagenta
,
273 * Update the foreground / background color.
276 tc_update_color( int color
, int fore
)
278 unsigned char mask_on
, mask_off
;
282 case 1: mask_on
= kVGAColorRed
; break;
283 case 3: mask_on
= kVGAColorLightBrown
; break;
284 case 4: mask_on
= kVGAColorBlue
; break;
285 case 6: mask_on
= kVGAColorCyan
; break;
286 default: mask_on
= color
; break;
299 vga_attr
= (vga_attr
& ~mask_off
) | mask_on
;
301 vga_attr_rev
= ( ((vga_attr
<< 4) & 0xf0) |
302 ((vga_attr
>> 4) & 0x0f) );
308 * Show the hardware cursor.
311 tc_show_cursor( int x
, int y
)
313 set_cursor_position( XY_TO_CSRPOS(x
, y
) );
314 set_cursor_enable( TRUE
);
320 * Hide the hardware cursor.
323 tc_hide_cursor( __unused
int x
, __unused
int y
)
325 set_cursor_enable( FALSE
);
331 * Clear the entire screen, or a portion of the screen
332 * relative to the current cursor position.
335 tc_clear_screen(int x
, int y
, __unused
int top
, __unused
int bottom
,
343 case 0: /* To end of screen */
344 start
= XY_TO_CSRPOS(x
, y
);
345 count
= ONE_PAGE
- start
;
347 case 1: /* To start of screen */
349 count
= XY_TO_CSRPOS(x
, y
) + ONE_SPACE
;
352 case 2: /* Whole screen */
357 clear_block(start
, count
, vga_attr
);
363 * Display a character on screen with the given coordinates,
367 tc_paint_char(int x
, int y
, unsigned char ch
, int attrs
,
368 __unused
unsigned char ch_previous
, __unused
int attrs_previous
)
370 char my_attr
= vga_attr
;
372 if ( attrs
& 4 ) my_attr
= vga_attr_rev
;
374 display_char( XY_TO_CSRPOS(x
, y
), ch
, vga_attr
);
380 * Enable / disable the console.
383 tc_enable(__unused boolean_t enable
)
391 * Must be called before any other exported functions.
394 tc_initialize(struct vc_info
* vinfo_p
)
396 vinfo_p
->v_rows
= vinfo_p
->v_height
;
397 vinfo_p
->v_columns
= vinfo_p
->v_width
;
399 vga_init( vinfo_p
->v_columns
,
401 (unsigned char *) vinfo_p
->v_baseaddr
);