]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/console/i386/text_console.c
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>
33 * Macros and typedefs.
35 typedef short csrpos_t
; /* cursor position, ONE_SPACE bytes per char */
37 #define ONE_SPACE 2 /* bytes per character */
38 #define ONE_LINE (vga_cols * ONE_SPACE) /* number of bytes in line */
39 #define ONE_PAGE (vga_rows * ONE_LINE) /* number of bytes in page */
40 #define SPACE_CHAR 0x20
42 #define VGA_FB_START 0x0b8000
43 #define VGA_FB_SIZE 0x8000
44 #define VGA_IDX_REG 0x3d4
45 #define VGA_IO_REG 0x3d5
48 * Commands sent to graphics adapter.
50 #define VGA_C_LOW 0x0f /* return low byte of cursor addr */
51 #define VGA_C_HIGH 0x0e /* high byte */
54 * Attributes for character sent to display.
56 #define VGA_ATTR_NORMAL 0x07
57 #define VGA_ATTR_REVERSE 0x70
60 * Convert from XY coordinate to a location in display memory.
62 #define XY_TO_CSRPOS(x, y) (((y) * vga_cols + (x)) * ONE_SPACE)
67 static short vga_idx_reg
= 0; /* location of VGA index register */
68 static short vga_io_reg
= 0; /* location of VGA data register */
69 static short vga_cols
= 80; /* number of columns */
70 static short vga_rows
= 25; /* number of rows */
71 static char vga_attr
= 0; /* current character attribute */
72 static char vga_attr_rev
= 0; /* current reverse attribute */
73 static char * vram_start
= 0; /* VM start of VGA frame buffer */
76 * Functions in kdasm.s.
78 extern void kd_slmwd(unsigned char * pos
, int count
, unsigned short val
);
79 extern void kd_slmscu(unsigned char * from
, unsigned char * to
, int count
);
80 extern void kd_slmscd(unsigned char * from
, unsigned char * to
, int count
);
85 * Block move up for VGA.
88 move_up( csrpos_t from
,
92 kd_slmscu( vram_start
+ from
, vram_start
+ to
, count
);
98 * Block move down for VGA.
101 move_down( csrpos_t from
,
105 kd_slmscd( vram_start
+ from
, vram_start
+ to
, count
);
111 * Fast clear for VGA.
114 clear_block( csrpos_t start
,
118 kd_slmwd( vram_start
+ start
, size
,
119 ((unsigned short) attr
<< 8) + SPACE_CHAR
);
123 * set_cursor_position
125 * This function sets the hardware cursor position
129 set_cursor_position( csrpos_t newpos
)
131 short curpos
; /* position, not scaled for attribute byte */
133 curpos
= newpos
/ ONE_SPACE
;
135 outb(vga_idx_reg
, VGA_C_HIGH
);
136 outb(vga_io_reg
, (unsigned char)(curpos
>> 8));
138 outb(vga_idx_reg
, VGA_C_LOW
);
139 outb(vga_io_reg
, (unsigned char)(curpos
& 0xff));
145 * Display attributed character for VGA (mode 3).
148 display_char( csrpos_t pos
, /* where to put it */
149 char ch
, /* the character */
150 char attr
) /* its attribute */
152 *(vram_start
+ pos
) = ch
;
153 *(vram_start
+ pos
+ 1) = attr
;
159 * Initialize the VGA text console.
162 vga_init(int cols
, int rows
, unsigned char * addr
)
165 vga_idx_reg
= VGA_IDX_REG
;
166 vga_io_reg
= VGA_IO_REG
;
169 vga_attr
= VGA_ATTR_NORMAL
;
170 vga_attr_rev
= VGA_ATTR_REVERSE
;
172 set_cursor_position(0);
178 * Scroll the screen up 'n' character lines.
181 tc_scroll_up( int lines
, int top
, int bottom
)
189 from
= ONE_LINE
* lines
;
190 size
= ( ONE_PAGE
- ( ONE_LINE
* lines
) ) / ONE_SPACE
;
191 move_up(from
, to
, size
);
193 /* clear bottom line */
194 to
= ( ( vga_rows
- lines
) * ONE_LINE
);
195 size
= ( ONE_LINE
* lines
) / ONE_SPACE
;
196 clear_block(to
, size
, vga_attr
);
202 * Scrolls the screen down 'n' character lines.
205 tc_scroll_down( int lines
, int top
, int bottom
)
212 to
= ONE_PAGE
- ONE_SPACE
;
213 from
= ONE_PAGE
- ( ONE_LINE
* lines
) - ONE_SPACE
;
214 size
= ( ONE_PAGE
- ( ONE_LINE
* lines
) ) / ONE_SPACE
;
215 move_down(from
, to
, size
);
219 size
= ( ONE_LINE
* lines
) / ONE_SPACE
;
220 clear_block(to
, size
, vga_attr
);
223 /* Default colors for 16-color palette */
238 kVGAColorLightMagenta
,
246 * Update the foreground / background color.
249 tc_update_color( int color
, int fore
)
251 unsigned char mask_on
, mask_off
;
255 case 1: mask_on
= kVGAColorRed
; break;
256 case 3: mask_on
= kVGAColorLightBrown
; break;
257 case 4: mask_on
= kVGAColorBlue
; break;
258 case 6: mask_on
= kVGAColorCyan
; break;
259 default: mask_on
= color
; break;
272 vga_attr
= (vga_attr
& ~mask_off
) | mask_on
;
274 vga_attr_rev
= ( ((vga_attr
<< 4) & 0xf0) |
275 ((vga_attr
>> 4) & 0x0f) );
281 * Show the hardware cursor.
284 tc_show_cursor( int x
, int y
)
286 set_cursor_position( XY_TO_CSRPOS(x
, y
) );
292 * Hide the hardware cursor.
295 tc_hide_cursor( int x
, int y
)
303 * Clear the entire screen, or a portion of the screen
304 * relative to the current cursor position.
307 tc_clear_screen(int x
, int y
, int top
, int bottom
, int operation
)
314 case 0: /* To end of screen */
315 start
= XY_TO_CSRPOS(x
, y
);
316 count
= ONE_PAGE
- start
;
318 case 1: /* To start of screen */
320 count
= XY_TO_CSRPOS(x
, y
) + ONE_SPACE
;
323 case 2: /* Whole screen */
328 clear_block(start
, count
, vga_attr
);
334 * Display a character on screen with the given coordinates,
338 tc_paint_char( int x
, int y
, unsigned char ch
, int attrs
, unsigned char ch_previous
, int attrs_previous
)
340 char my_attr
= vga_attr
;
342 if ( attrs
& 4 ) my_attr
= vga_attr_rev
;
344 display_char( XY_TO_CSRPOS(x
, y
), ch
, vga_attr
);
350 * Enable / disable the console.
353 tc_enable(boolean_t enable
)
361 * Must be called before any other exported functions.
364 tc_initialize(struct vc_info
* vinfo_p
)
366 vinfo_p
->v_rows
= vinfo_p
->v_height
;
367 vinfo_p
->v_columns
= vinfo_p
->v_width
;
369 vga_init( vinfo_p
->v_columns
,
371 (unsigned char *) vinfo_p
->v_baseaddr
);