merge mainline into emu-mod
This commit is contained in:
commit
19a9fb834b
459 changed files with 26481 additions and 7640 deletions
|
@ -17,13 +17,14 @@
|
|||
*/
|
||||
|
||||
#include <grub/dl.h>
|
||||
#include <grub/i386/pc/console.h>
|
||||
#include <grub/i386/at_keyboard.h>
|
||||
#include <grub/i386/io.h>
|
||||
#include <grub/at_keyboard.h>
|
||||
#include <grub/cpu/at_keyboard.h>
|
||||
#include <grub/cpu/io.h>
|
||||
#include <grub/misc.h>
|
||||
#include <grub/term.h>
|
||||
|
||||
static short at_keyboard_status = 0;
|
||||
static int pending_key = -1;
|
||||
|
||||
#define KEYBOARD_STATUS_SHIFT_L (1 << 0)
|
||||
#define KEYBOARD_STATUS_SHIFT_R (1 << 1)
|
||||
|
@ -32,6 +33,13 @@ static short at_keyboard_status = 0;
|
|||
#define KEYBOARD_STATUS_CTRL_L (1 << 4)
|
||||
#define KEYBOARD_STATUS_CTRL_R (1 << 5)
|
||||
#define KEYBOARD_STATUS_CAPS_LOCK (1 << 6)
|
||||
#define KEYBOARD_STATUS_NUM_LOCK (1 << 7)
|
||||
|
||||
static grub_uint8_t led_status;
|
||||
|
||||
#define KEYBOARD_LED_SCROLL (1 << 0)
|
||||
#define KEYBOARD_LED_NUM (1 << 1)
|
||||
#define KEYBOARD_LED_CAPS (1 << 2)
|
||||
|
||||
static char keyboard_map[128] =
|
||||
{
|
||||
|
@ -65,9 +73,15 @@ static char keyboard_map_shift[128] =
|
|||
static grub_uint8_t grub_keyboard_controller_orig;
|
||||
|
||||
static void
|
||||
grub_keyboard_controller_write (grub_uint8_t c)
|
||||
keyboard_controller_wait_until_ready (void)
|
||||
{
|
||||
while (! KEYBOARD_COMMAND_ISREADY (grub_inb (KEYBOARD_REG_STATUS)));
|
||||
}
|
||||
|
||||
static void
|
||||
grub_keyboard_controller_write (grub_uint8_t c)
|
||||
{
|
||||
keyboard_controller_wait_until_ready ();
|
||||
grub_outb (KEYBOARD_COMMAND_WRITE, KEYBOARD_REG_STATUS);
|
||||
grub_outb (c, KEYBOARD_REG_DATA);
|
||||
}
|
||||
|
@ -75,11 +89,20 @@ grub_keyboard_controller_write (grub_uint8_t c)
|
|||
static grub_uint8_t
|
||||
grub_keyboard_controller_read (void)
|
||||
{
|
||||
while (! KEYBOARD_COMMAND_ISREADY (grub_inb (KEYBOARD_REG_STATUS)));
|
||||
keyboard_controller_wait_until_ready ();
|
||||
grub_outb (KEYBOARD_COMMAND_READ, KEYBOARD_REG_STATUS);
|
||||
return grub_inb (KEYBOARD_REG_DATA);
|
||||
}
|
||||
|
||||
static void
|
||||
keyboard_controller_led (grub_uint8_t leds)
|
||||
{
|
||||
keyboard_controller_wait_until_ready ();
|
||||
grub_outb (0xed, KEYBOARD_REG_DATA);
|
||||
keyboard_controller_wait_until_ready ();
|
||||
grub_outb (leds & 0x7, KEYBOARD_REG_DATA);
|
||||
}
|
||||
|
||||
/* FIXME: This should become an interrupt service routine. For now
|
||||
it's just used to catch events from control keys. */
|
||||
static void
|
||||
|
@ -158,14 +181,37 @@ grub_at_keyboard_getkey_noblock (void)
|
|||
switch (code)
|
||||
{
|
||||
case CAPS_LOCK:
|
||||
at_keyboard_status ^= KEYBOARD_STATUS_CAPS_LOCK;
|
||||
/* Caps lock sends scan code twice. Get the second one and discard it. */
|
||||
while (grub_keyboard_getkey () == -1);
|
||||
|
||||
at_keyboard_status ^= KEYBOARD_STATUS_CAPS_LOCK;
|
||||
led_status ^= KEYBOARD_LED_CAPS;
|
||||
keyboard_controller_led (led_status);
|
||||
|
||||
#ifdef DEBUG_AT_KEYBOARD
|
||||
grub_dprintf ("atkeyb", "caps_lock = %d\n", !!(at_keyboard_status & KEYBOARD_STATUS_CAPS_LOCK));
|
||||
#endif
|
||||
key = -1;
|
||||
break;
|
||||
case NUM_LOCK:
|
||||
/* Num lock sends scan code twice. Get the second one and discard it. */
|
||||
while (grub_keyboard_getkey () == -1);
|
||||
|
||||
at_keyboard_status ^= KEYBOARD_STATUS_NUM_LOCK;
|
||||
led_status ^= KEYBOARD_LED_NUM;
|
||||
keyboard_controller_led (led_status);
|
||||
|
||||
#ifdef DEBUG_AT_KEYBOARD
|
||||
grub_dprintf ("atkeyb", "num_lock = %d\n", !!(at_keyboard_status & KEYBOARD_STATUS_NUM_LOCK));
|
||||
#endif
|
||||
key = -1;
|
||||
break;
|
||||
case SCROLL_LOCK:
|
||||
/* For scroll lock we don't keep track of status. Only update its led. */
|
||||
led_status ^= KEYBOARD_LED_SCROLL;
|
||||
keyboard_controller_led (led_status);
|
||||
key = -1;
|
||||
break;
|
||||
default:
|
||||
if (at_keyboard_status & (KEYBOARD_STATUS_CTRL_L | KEYBOARD_STATUS_CTRL_R))
|
||||
key = keyboard_map[code] - 'a' + 1;
|
||||
|
@ -192,14 +238,27 @@ grub_at_keyboard_getkey_noblock (void)
|
|||
static int
|
||||
grub_at_keyboard_checkkey (void)
|
||||
{
|
||||
/* FIXME: this will be triggered by BREAK events. */
|
||||
return KEYBOARD_ISREADY (grub_inb (KEYBOARD_REG_STATUS)) ? 1 : -1;
|
||||
if (pending_key != -1)
|
||||
return 1;
|
||||
|
||||
pending_key = grub_at_keyboard_getkey_noblock ();
|
||||
|
||||
if (pending_key != -1)
|
||||
return 1;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int
|
||||
grub_at_keyboard_getkey (void)
|
||||
{
|
||||
int key;
|
||||
if (pending_key != -1)
|
||||
{
|
||||
key = pending_key;
|
||||
pending_key = -1;
|
||||
return key;
|
||||
}
|
||||
do
|
||||
{
|
||||
key = grub_at_keyboard_getkey_noblock ();
|
||||
|
@ -210,6 +269,8 @@ grub_at_keyboard_getkey (void)
|
|||
static grub_err_t
|
||||
grub_keyboard_controller_init (void)
|
||||
{
|
||||
pending_key = -1;
|
||||
at_keyboard_status = 0;
|
||||
grub_keyboard_controller_orig = grub_keyboard_controller_read ();
|
||||
grub_keyboard_controller_write (grub_keyboard_controller_orig | KEYBOARD_SCANCODE_SET1);
|
||||
return GRUB_ERR_NONE;
|
|
@ -351,8 +351,7 @@ static struct grub_term_output grub_console_term_output =
|
|||
.setcolorstate = grub_console_setcolorstate,
|
||||
.setcolor = grub_console_setcolor,
|
||||
.getcolor = grub_console_getcolor,
|
||||
.setcursor = grub_console_setcursor,
|
||||
.flags = 0,
|
||||
.setcursor = grub_console_setcursor
|
||||
};
|
||||
|
||||
void
|
||||
|
|
503
term/gfxterm.c
503
term/gfxterm.c
|
@ -24,10 +24,13 @@
|
|||
#include <grub/mm.h>
|
||||
#include <grub/env.h>
|
||||
#include <grub/video.h>
|
||||
#include <grub/gfxterm.h>
|
||||
#include <grub/bitmap.h>
|
||||
#include <grub/command.h>
|
||||
#include <grub/extcmd.h>
|
||||
#include <grub/bitmap_scale.h>
|
||||
|
||||
#define DEFAULT_VIDEO_MODE "1024x768,800x600,640x480"
|
||||
#define DEFAULT_VIDEO_MODE "auto"
|
||||
#define DEFAULT_BORDER_WIDTH 10
|
||||
|
||||
#define DEFAULT_STANDARD_COLOR 0x07
|
||||
|
@ -95,15 +98,33 @@ struct grub_virtual_screen
|
|||
/* Color settings. */
|
||||
grub_video_color_t fg_color;
|
||||
grub_video_color_t bg_color;
|
||||
grub_video_color_t bg_color_display;
|
||||
|
||||
/* Text buffer for virtual screen. Contains (columns * rows) number
|
||||
of entries. */
|
||||
struct grub_colored_char *text_buffer;
|
||||
|
||||
int total_scroll;
|
||||
};
|
||||
|
||||
static struct grub_virtual_screen virtual_screen;
|
||||
struct grub_gfxterm_window
|
||||
{
|
||||
unsigned x;
|
||||
unsigned y;
|
||||
unsigned width;
|
||||
unsigned height;
|
||||
int double_repaint;
|
||||
};
|
||||
|
||||
static struct grub_video_mode_info mode_info;
|
||||
static struct grub_video_render_target *render_target;
|
||||
void (*grub_gfxterm_decorator_hook) (void) = NULL;
|
||||
static struct grub_gfxterm_window window;
|
||||
static struct grub_virtual_screen virtual_screen;
|
||||
static grub_gfxterm_repaint_callback_t repaint_callback;
|
||||
static int repaint_schedulded = 0;
|
||||
static int repaint_was_schedulded = 0;
|
||||
|
||||
static void destroy_window (void);
|
||||
|
||||
static struct grub_video_render_target *text_layer;
|
||||
|
||||
|
@ -124,6 +145,8 @@ static unsigned int calculate_normal_character_width (grub_font_t font);
|
|||
|
||||
static unsigned char calculate_character_width (struct grub_font_glyph *glyph);
|
||||
|
||||
static void grub_gfxterm_refresh (void);
|
||||
|
||||
static void
|
||||
set_term_color (grub_uint8_t term_color)
|
||||
{
|
||||
|
@ -189,7 +212,7 @@ grub_virtual_screen_setup (unsigned int x, unsigned int y,
|
|||
virtual_screen.font = grub_font_get (font_name);
|
||||
if (!virtual_screen.font)
|
||||
return grub_error (GRUB_ERR_BAD_FONT,
|
||||
"No font loaded.");
|
||||
"no font loaded");
|
||||
virtual_screen.width = width;
|
||||
virtual_screen.height = height;
|
||||
virtual_screen.offset_x = x;
|
||||
|
@ -201,6 +224,7 @@ grub_virtual_screen_setup (unsigned int x, unsigned int y,
|
|||
virtual_screen.cursor_x = 0;
|
||||
virtual_screen.cursor_y = 0;
|
||||
virtual_screen.cursor_state = 1;
|
||||
virtual_screen.total_scroll = 0;
|
||||
|
||||
/* Calculate size of text buffer. */
|
||||
virtual_screen.columns = virtual_screen.width / virtual_screen.normal_char_width;
|
||||
|
@ -235,7 +259,9 @@ grub_virtual_screen_setup (unsigned int x, unsigned int y,
|
|||
|
||||
set_term_color (virtual_screen.term_color);
|
||||
|
||||
grub_video_set_active_render_target (GRUB_VIDEO_RENDER_TARGET_DISPLAY);
|
||||
grub_video_set_active_render_target (render_target);
|
||||
|
||||
virtual_screen.bg_color_display = grub_video_map_rgba(0, 0, 0, 0);
|
||||
|
||||
/* Clear out text buffer. */
|
||||
for (i = 0; i < virtual_screen.columns * virtual_screen.rows; i++)
|
||||
|
@ -244,75 +270,122 @@ grub_virtual_screen_setup (unsigned int x, unsigned int y,
|
|||
return grub_errno;
|
||||
}
|
||||
|
||||
static int NESTED_FUNC_ATTR video_hook (grub_video_adapter_t p __attribute__ ((unused)),
|
||||
struct grub_video_mode_info *info)
|
||||
void
|
||||
grub_gfxterm_schedule_repaint (void)
|
||||
{
|
||||
return ! (info->mode_type & GRUB_VIDEO_MODE_TYPE_PURE_TEXT);
|
||||
repaint_schedulded = 1;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_gfxterm_term_init (void)
|
||||
grub_err_t
|
||||
grub_gfxterm_set_window (struct grub_video_render_target *target,
|
||||
int x, int y, int width, int height,
|
||||
int double_repaint,
|
||||
const char *font_name, int border_width)
|
||||
{
|
||||
char *font_name;
|
||||
char *modevar;
|
||||
char *tmp;
|
||||
grub_video_color_t color;
|
||||
int width;
|
||||
int height;
|
||||
grub_err_t err;
|
||||
/* Clean up any prior instance. */
|
||||
destroy_window ();
|
||||
|
||||
/* Select the font to use. */
|
||||
font_name = grub_env_get ("gfxterm_font");
|
||||
if (! font_name)
|
||||
font_name = ""; /* Allow fallback to any font. */
|
||||
/* Set the render target. */
|
||||
render_target = target;
|
||||
|
||||
/* Parse gfxmode environment variable if set. */
|
||||
modevar = grub_env_get ("gfxmode");
|
||||
if (! modevar || *modevar == 0)
|
||||
err = grub_video_set_mode (DEFAULT_VIDEO_MODE, video_hook);
|
||||
else
|
||||
/* Create virtual screen. */
|
||||
if (grub_virtual_screen_setup (border_width, border_width,
|
||||
width - 2 * border_width,
|
||||
height - 2 * border_width,
|
||||
font_name)
|
||||
!= GRUB_ERR_NONE)
|
||||
{
|
||||
tmp = grub_malloc (grub_strlen (modevar)
|
||||
+ sizeof (DEFAULT_VIDEO_MODE) + 1);
|
||||
grub_sprintf (tmp, "%s;" DEFAULT_VIDEO_MODE, modevar);
|
||||
err = grub_video_set_mode (tmp, video_hook);
|
||||
grub_free (tmp);
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
if (err)
|
||||
return err;
|
||||
/* Set window bounds. */
|
||||
window.x = x;
|
||||
window.y = y;
|
||||
window.width = width;
|
||||
window.height = height;
|
||||
window.double_repaint = double_repaint;
|
||||
|
||||
dirty_region_reset ();
|
||||
grub_gfxterm_schedule_repaint ();
|
||||
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
grub_err_t
|
||||
grub_gfxterm_fullscreen (void)
|
||||
{
|
||||
const char *font_name;
|
||||
struct grub_video_mode_info mode_info;
|
||||
grub_video_color_t color;
|
||||
grub_err_t err;
|
||||
int double_redraw;
|
||||
|
||||
err = grub_video_get_info (&mode_info);
|
||||
/* Figure out what mode we ended up. */
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
grub_video_set_active_render_target (GRUB_VIDEO_RENDER_TARGET_DISPLAY);
|
||||
|
||||
double_redraw = mode_info.mode_type & GRUB_VIDEO_MODE_TYPE_DOUBLE_BUFFERED
|
||||
&& !(mode_info.mode_type & GRUB_VIDEO_MODE_TYPE_UPDATING_SWAP);
|
||||
|
||||
/* Make sure screen is black. */
|
||||
color = grub_video_map_rgb (0, 0, 0);
|
||||
grub_video_fill_rect (color, 0, 0, mode_info.width, mode_info.height);
|
||||
if (double_redraw)
|
||||
{
|
||||
grub_video_swap_buffers ();
|
||||
grub_video_fill_rect (color, 0, 0, mode_info.width, mode_info.height);
|
||||
}
|
||||
bitmap = 0;
|
||||
|
||||
/* Leave borders for virtual screen. */
|
||||
width = mode_info.width - (2 * DEFAULT_BORDER_WIDTH);
|
||||
height = mode_info.height - (2 * DEFAULT_BORDER_WIDTH);
|
||||
/* Select the font to use. */
|
||||
font_name = grub_env_get ("gfxterm_font");
|
||||
if (! font_name)
|
||||
font_name = ""; /* Allow fallback to any font. */
|
||||
|
||||
/* Create virtual screen. */
|
||||
if (grub_virtual_screen_setup (DEFAULT_BORDER_WIDTH, DEFAULT_BORDER_WIDTH,
|
||||
width, height, font_name) != GRUB_ERR_NONE)
|
||||
{
|
||||
grub_video_restore ();
|
||||
return grub_errno;
|
||||
}
|
||||
grub_gfxterm_decorator_hook = NULL;
|
||||
|
||||
/* Mark whole screen as dirty. */
|
||||
dirty_region_reset ();
|
||||
dirty_region_add (0, 0, mode_info.width, mode_info.height);
|
||||
|
||||
return (grub_errno = GRUB_ERR_NONE);
|
||||
return grub_gfxterm_set_window (GRUB_VIDEO_RENDER_TARGET_DISPLAY,
|
||||
0, 0, mode_info.width, mode_info.height,
|
||||
double_redraw,
|
||||
font_name, DEFAULT_BORDER_WIDTH);
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_gfxterm_term_fini (void)
|
||||
grub_gfxterm_term_init (void)
|
||||
{
|
||||
char *tmp;
|
||||
grub_err_t err;
|
||||
const char *modevar;
|
||||
|
||||
/* Parse gfxmode environment variable if set. */
|
||||
modevar = grub_env_get ("gfxmode");
|
||||
if (! modevar || *modevar == 0)
|
||||
err = grub_video_set_mode (DEFAULT_VIDEO_MODE,
|
||||
GRUB_VIDEO_MODE_TYPE_PURE_TEXT, 0);
|
||||
else
|
||||
{
|
||||
tmp = grub_xasprintf ("%s;" DEFAULT_VIDEO_MODE, modevar);
|
||||
if (!tmp)
|
||||
return grub_errno;
|
||||
err = grub_video_set_mode (tmp, GRUB_VIDEO_MODE_TYPE_PURE_TEXT, 0);
|
||||
grub_free (tmp);
|
||||
}
|
||||
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
err = grub_gfxterm_fullscreen ();
|
||||
if (err)
|
||||
grub_video_restore ();
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
static void
|
||||
destroy_window (void)
|
||||
{
|
||||
if (bitmap)
|
||||
{
|
||||
|
@ -320,10 +393,18 @@ grub_gfxterm_term_fini (void)
|
|||
bitmap = 0;
|
||||
}
|
||||
|
||||
repaint_callback = 0;
|
||||
grub_virtual_screen_free ();
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_gfxterm_term_fini (void)
|
||||
{
|
||||
destroy_window ();
|
||||
grub_video_restore ();
|
||||
|
||||
/* Clear error state. */
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
|
@ -332,9 +413,15 @@ redraw_screen_rect (unsigned int x, unsigned int y,
|
|||
unsigned int width, unsigned int height)
|
||||
{
|
||||
grub_video_color_t color;
|
||||
grub_video_rect_t saved_view;
|
||||
|
||||
grub_video_set_active_render_target (GRUB_VIDEO_RENDER_TARGET_DISPLAY);
|
||||
|
||||
grub_video_set_active_render_target (render_target);
|
||||
/* Save viewport and set it to our window. */
|
||||
grub_video_get_viewport ((unsigned *) &saved_view.x,
|
||||
(unsigned *) &saved_view.y,
|
||||
(unsigned *) &saved_view.width,
|
||||
(unsigned *) &saved_view.height);
|
||||
grub_video_set_viewport (window.x, window.y, window.width, window.height);
|
||||
|
||||
if (bitmap)
|
||||
{
|
||||
|
@ -345,7 +432,7 @@ redraw_screen_rect (unsigned int x, unsigned int y,
|
|||
|
||||
/* If bitmap is smaller than requested blit area, use background
|
||||
color. */
|
||||
color = virtual_screen.bg_color;
|
||||
color = virtual_screen.bg_color_display;
|
||||
|
||||
/* Fill right side of the bitmap if needed. */
|
||||
if ((x + width >= bitmap_width) && (y < bitmap_height))
|
||||
|
@ -392,7 +479,7 @@ redraw_screen_rect (unsigned int x, unsigned int y,
|
|||
else
|
||||
{
|
||||
/* Render background layer. */
|
||||
color = virtual_screen.bg_color;
|
||||
color = virtual_screen.bg_color_display;
|
||||
grub_video_fill_rect (color, x, y, width, height);
|
||||
|
||||
/* Render text layer as replaced (to get texts background color). */
|
||||
|
@ -401,6 +488,14 @@ redraw_screen_rect (unsigned int x, unsigned int y,
|
|||
y - virtual_screen.offset_y,
|
||||
width, height);
|
||||
}
|
||||
|
||||
/* Restore saved viewport. */
|
||||
grub_video_set_viewport (saved_view.x, saved_view.y,
|
||||
saved_view.width, saved_view.height);
|
||||
grub_video_set_active_render_target (render_target);
|
||||
|
||||
if (repaint_callback)
|
||||
repaint_callback (x, y, width, height);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -410,6 +505,7 @@ dirty_region_reset (void)
|
|||
dirty_region.top_left_y = -1;
|
||||
dirty_region.bottom_right_x = -1;
|
||||
dirty_region.bottom_right_y = -1;
|
||||
repaint_was_schedulded = 0;
|
||||
}
|
||||
|
||||
static int
|
||||
|
@ -429,6 +525,16 @@ dirty_region_add (int x, int y, unsigned int width, unsigned int height)
|
|||
if ((width == 0) || (height == 0))
|
||||
return;
|
||||
|
||||
if (repaint_schedulded)
|
||||
{
|
||||
x = virtual_screen.offset_x;
|
||||
y = virtual_screen.offset_y;
|
||||
width = virtual_screen.width;
|
||||
height = virtual_screen.height;
|
||||
repaint_schedulded = 0;
|
||||
repaint_was_schedulded = 1;
|
||||
}
|
||||
|
||||
if (dirty_region_is_empty ())
|
||||
{
|
||||
dirty_region.top_left_x = x;
|
||||
|
@ -475,13 +581,14 @@ dirty_region_redraw (void)
|
|||
width = dirty_region.bottom_right_x - x + 1;
|
||||
height = dirty_region.bottom_right_y - y + 1;
|
||||
|
||||
redraw_screen_rect (x, y, width, height);
|
||||
if (repaint_was_schedulded && grub_gfxterm_decorator_hook)
|
||||
grub_gfxterm_decorator_hook ();
|
||||
|
||||
dirty_region_reset ();
|
||||
redraw_screen_rect (x, y, width, height);
|
||||
}
|
||||
|
||||
static void
|
||||
write_char (void)
|
||||
static inline void
|
||||
paint_char (unsigned cx, unsigned cy)
|
||||
{
|
||||
struct grub_colored_char *p;
|
||||
struct grub_font_glyph *glyph;
|
||||
|
@ -493,10 +600,12 @@ write_char (void)
|
|||
unsigned int height;
|
||||
unsigned int width;
|
||||
|
||||
if (cy + virtual_screen.total_scroll >= virtual_screen.rows)
|
||||
return;
|
||||
|
||||
/* Find out active character. */
|
||||
p = (virtual_screen.text_buffer
|
||||
+ virtual_screen.cursor_x
|
||||
+ (virtual_screen.cursor_y * virtual_screen.columns));
|
||||
+ cx + (cy * virtual_screen.columns));
|
||||
|
||||
p -= p->index;
|
||||
|
||||
|
@ -510,68 +619,163 @@ write_char (void)
|
|||
color = p->fg_color;
|
||||
bgcolor = p->bg_color;
|
||||
|
||||
x = virtual_screen.cursor_x * virtual_screen.normal_char_width;
|
||||
y = virtual_screen.cursor_y * virtual_screen.normal_char_height;
|
||||
x = cx * virtual_screen.normal_char_width;
|
||||
y = (cy + virtual_screen.total_scroll) * virtual_screen.normal_char_height;
|
||||
|
||||
/* Render glyph to text layer. */
|
||||
grub_video_set_active_render_target (text_layer);
|
||||
grub_video_fill_rect (bgcolor, x, y, width, height);
|
||||
grub_font_draw_glyph (glyph, color, x, y + ascent);
|
||||
grub_video_set_active_render_target (GRUB_VIDEO_RENDER_TARGET_DISPLAY);
|
||||
grub_video_set_active_render_target (render_target);
|
||||
|
||||
/* Mark character to be drawn. */
|
||||
dirty_region_add (virtual_screen.offset_x + x, virtual_screen.offset_y + y,
|
||||
width, height);
|
||||
}
|
||||
|
||||
static void
|
||||
static inline void
|
||||
write_char (void)
|
||||
{
|
||||
paint_char (virtual_screen.cursor_x, virtual_screen.cursor_y);
|
||||
}
|
||||
|
||||
static inline void
|
||||
draw_cursor (int show)
|
||||
{
|
||||
unsigned int x;
|
||||
unsigned int y;
|
||||
unsigned int width;
|
||||
unsigned int height;
|
||||
grub_video_color_t color;
|
||||
|
||||
write_char ();
|
||||
|
||||
if (show)
|
||||
if (!show)
|
||||
return;
|
||||
|
||||
if (virtual_screen.cursor_y + virtual_screen.total_scroll
|
||||
>= virtual_screen.rows)
|
||||
return;
|
||||
|
||||
/* Determine cursor properties and position on text layer. */
|
||||
x = virtual_screen.cursor_x * virtual_screen.normal_char_width;
|
||||
width = virtual_screen.normal_char_width;
|
||||
color = virtual_screen.fg_color;
|
||||
y = ((virtual_screen.cursor_y + virtual_screen.total_scroll)
|
||||
* virtual_screen.normal_char_height
|
||||
+ grub_font_get_ascent (virtual_screen.font));
|
||||
height = 2;
|
||||
|
||||
/* Render cursor to text layer. */
|
||||
grub_video_set_active_render_target (text_layer);
|
||||
grub_video_fill_rect (color, x, y, width, height);
|
||||
grub_video_set_active_render_target (render_target);
|
||||
|
||||
/* Mark cursor to be redrawn. */
|
||||
dirty_region_add (virtual_screen.offset_x + x,
|
||||
virtual_screen.offset_y + y,
|
||||
width, height);
|
||||
}
|
||||
|
||||
static void
|
||||
real_scroll (void)
|
||||
{
|
||||
unsigned int i, j, was_scroll;
|
||||
grub_video_color_t color;
|
||||
|
||||
if (!virtual_screen.total_scroll)
|
||||
return;
|
||||
|
||||
/* If we have bitmap, re-draw screen, otherwise scroll physical screen too. */
|
||||
if (bitmap)
|
||||
{
|
||||
unsigned int x;
|
||||
unsigned int y;
|
||||
unsigned int width;
|
||||
unsigned int height;
|
||||
grub_video_color_t color;
|
||||
|
||||
/* Determine cursor properties and position on text layer. */
|
||||
x = virtual_screen.cursor_x * virtual_screen.normal_char_width;
|
||||
width = virtual_screen.normal_char_width;
|
||||
color = virtual_screen.fg_color;
|
||||
y = (virtual_screen.cursor_y * virtual_screen.normal_char_height
|
||||
+ grub_font_get_ascent (virtual_screen.font));
|
||||
height = 2;
|
||||
|
||||
/* Render cursor to text layer. */
|
||||
/* Scroll physical screen. */
|
||||
grub_video_set_active_render_target (text_layer);
|
||||
grub_video_fill_rect (color, x, y, width, height);
|
||||
grub_video_set_active_render_target (GRUB_VIDEO_RENDER_TARGET_DISPLAY);
|
||||
color = virtual_screen.bg_color;
|
||||
grub_video_scroll (color, 0, -virtual_screen.normal_char_height
|
||||
* virtual_screen.total_scroll);
|
||||
|
||||
/* Mark cursor to be redrawn. */
|
||||
dirty_region_add (virtual_screen.offset_x + x,
|
||||
virtual_screen.offset_y + y,
|
||||
width, height);
|
||||
/* Mark virtual screen to be redrawn. */
|
||||
dirty_region_add_virtualscreen ();
|
||||
}
|
||||
else
|
||||
{
|
||||
grub_video_rect_t saved_view;
|
||||
|
||||
/* Remove cursor. */
|
||||
draw_cursor (0);
|
||||
|
||||
grub_video_set_active_render_target (render_target);
|
||||
/* Save viewport and set it to our window. */
|
||||
grub_video_get_viewport ((unsigned *) &saved_view.x,
|
||||
(unsigned *) &saved_view.y,
|
||||
(unsigned *) &saved_view.width,
|
||||
(unsigned *) &saved_view.height);
|
||||
grub_video_set_viewport (window.x, window.y, window.width, window.height);
|
||||
|
||||
i = window.double_repaint ? 2 : 1;
|
||||
|
||||
color = virtual_screen.bg_color;
|
||||
|
||||
while (i--)
|
||||
{
|
||||
/* Clear new border area. */
|
||||
grub_video_fill_rect (color,
|
||||
virtual_screen.offset_x,
|
||||
virtual_screen.offset_y,
|
||||
virtual_screen.width,
|
||||
virtual_screen.normal_char_height
|
||||
* virtual_screen.total_scroll);
|
||||
|
||||
grub_video_set_active_render_target (render_target);
|
||||
dirty_region_redraw ();
|
||||
|
||||
/* Scroll physical screen. */
|
||||
grub_video_scroll (color, 0, -virtual_screen.normal_char_height
|
||||
* virtual_screen.total_scroll);
|
||||
|
||||
if (i)
|
||||
grub_video_swap_buffers ();
|
||||
}
|
||||
dirty_region_reset ();
|
||||
|
||||
/* Scroll physical screen. */
|
||||
grub_video_set_active_render_target (text_layer);
|
||||
color = virtual_screen.bg_color;
|
||||
grub_video_scroll (color, 0, -virtual_screen.normal_char_height
|
||||
* virtual_screen.total_scroll);
|
||||
|
||||
/* Restore saved viewport. */
|
||||
grub_video_set_viewport (saved_view.x, saved_view.y,
|
||||
saved_view.width, saved_view.height);
|
||||
grub_video_set_active_render_target (render_target);
|
||||
|
||||
}
|
||||
|
||||
was_scroll = virtual_screen.total_scroll;
|
||||
virtual_screen.total_scroll = 0;
|
||||
|
||||
if (was_scroll > virtual_screen.rows)
|
||||
was_scroll = virtual_screen.rows;
|
||||
|
||||
/* Draw shadow part. */
|
||||
for (i = virtual_screen.rows - was_scroll;
|
||||
i < virtual_screen.rows; i++)
|
||||
for (j = 0; j < virtual_screen.columns; j++)
|
||||
paint_char (j, i);
|
||||
|
||||
/* Draw cursor if visible. */
|
||||
if (virtual_screen.cursor_state)
|
||||
draw_cursor (1);
|
||||
|
||||
if (repaint_callback)
|
||||
repaint_callback (window.x, window.y, window.width, window.height);
|
||||
}
|
||||
|
||||
static void
|
||||
scroll_up (void)
|
||||
{
|
||||
unsigned int i;
|
||||
grub_video_color_t color;
|
||||
|
||||
/* If we don't have background bitmap, remove cursor. */
|
||||
if (!bitmap)
|
||||
{
|
||||
/* Remove cursor. */
|
||||
draw_cursor (0);
|
||||
|
||||
/* Redraw only changed regions. */
|
||||
dirty_region_redraw ();
|
||||
}
|
||||
|
||||
/* Scroll text buffer with one line to up. */
|
||||
grub_memmove (virtual_screen.text_buffer,
|
||||
|
@ -586,32 +790,7 @@ scroll_up (void)
|
|||
i++)
|
||||
clear_char (&(virtual_screen.text_buffer[i]));
|
||||
|
||||
/* Scroll physical screen. */
|
||||
grub_video_set_active_render_target (text_layer);
|
||||
color = virtual_screen.bg_color;
|
||||
grub_video_scroll (color, 0, -virtual_screen.normal_char_height);
|
||||
grub_video_set_active_render_target (GRUB_VIDEO_RENDER_TARGET_DISPLAY);
|
||||
|
||||
/* If we have bitmap, re-draw screen, otherwise scroll physical screen too. */
|
||||
if (bitmap)
|
||||
{
|
||||
/* Mark virtual screen to be redrawn. */
|
||||
dirty_region_add_virtualscreen ();
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Clear new border area. */
|
||||
grub_video_fill_rect (color,
|
||||
virtual_screen.offset_x, virtual_screen.offset_y,
|
||||
virtual_screen.width, virtual_screen.normal_char_height);
|
||||
|
||||
/* Scroll physical screen. */
|
||||
grub_video_scroll (color, 0, -virtual_screen.normal_char_height);
|
||||
|
||||
/* Draw cursor if visible. */
|
||||
if (virtual_screen.cursor_state)
|
||||
draw_cursor (1);
|
||||
}
|
||||
virtual_screen.total_scroll++;
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -814,11 +993,14 @@ grub_gfxterm_cls (void)
|
|||
/* Clear text layer. */
|
||||
grub_video_set_active_render_target (text_layer);
|
||||
color = virtual_screen.bg_color;
|
||||
grub_video_fill_rect (color, 0, 0, mode_info.width, mode_info.height);
|
||||
grub_video_set_active_render_target (GRUB_VIDEO_RENDER_TARGET_DISPLAY);
|
||||
grub_video_fill_rect (color, 0, 0,
|
||||
virtual_screen.width, virtual_screen.height);
|
||||
grub_video_set_active_render_target (render_target);
|
||||
|
||||
/* Mark virtual screen to be redrawn. */
|
||||
dirty_region_add_virtualscreen ();
|
||||
|
||||
grub_gfxterm_refresh ();
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -879,15 +1061,41 @@ grub_gfxterm_setcursor (int on)
|
|||
static void
|
||||
grub_gfxterm_refresh (void)
|
||||
{
|
||||
real_scroll ();
|
||||
|
||||
/* Redraw only changed regions. */
|
||||
dirty_region_redraw ();
|
||||
|
||||
grub_video_swap_buffers ();
|
||||
|
||||
if (window.double_repaint)
|
||||
dirty_region_redraw ();
|
||||
dirty_region_reset ();
|
||||
}
|
||||
|
||||
void
|
||||
grub_gfxterm_set_repaint_callback (grub_gfxterm_repaint_callback_t func)
|
||||
{
|
||||
repaint_callback = func;
|
||||
}
|
||||
|
||||
/* Option array indices. */
|
||||
#define BACKGROUND_CMD_ARGINDEX_MODE 0
|
||||
|
||||
static const struct grub_arg_option background_image_cmd_options[] =
|
||||
{
|
||||
{"mode", 'm', 0, "Background image mode.", "stretch|normal",
|
||||
ARG_TYPE_STRING},
|
||||
{0, 0, 0, 0, 0, 0}
|
||||
};
|
||||
|
||||
static grub_err_t
|
||||
grub_gfxterm_background_image_cmd (grub_command_t cmd __attribute__ ((unused)),
|
||||
grub_gfxterm_background_image_cmd (grub_extcmd_t cmd __attribute__ ((unused)),
|
||||
int argc,
|
||||
char **args)
|
||||
{
|
||||
struct grub_arg_list *state = cmd->state;
|
||||
|
||||
/* Check that we have video adapter active. */
|
||||
if (grub_video_get_info(NULL) != GRUB_ERR_NONE)
|
||||
return grub_errno;
|
||||
|
@ -899,8 +1107,7 @@ grub_gfxterm_background_image_cmd (grub_command_t cmd __attribute__ ((unused)),
|
|||
bitmap = 0;
|
||||
|
||||
/* Mark whole screen as dirty. */
|
||||
dirty_region_reset ();
|
||||
dirty_region_add (0, 0, mode_info.width, mode_info.height);
|
||||
dirty_region_add (0, 0, window.width, window.height);
|
||||
}
|
||||
|
||||
/* If filename was provided, try to load that. */
|
||||
|
@ -911,16 +1118,38 @@ grub_gfxterm_background_image_cmd (grub_command_t cmd __attribute__ ((unused)),
|
|||
if (grub_errno != GRUB_ERR_NONE)
|
||||
return grub_errno;
|
||||
|
||||
/* Determine if the bitmap should be scaled to fit the screen. */
|
||||
if (!state[BACKGROUND_CMD_ARGINDEX_MODE].set
|
||||
|| grub_strcmp (state[BACKGROUND_CMD_ARGINDEX_MODE].arg,
|
||||
"stretch") == 0)
|
||||
{
|
||||
if (window.width != grub_video_bitmap_get_width (bitmap)
|
||||
|| window.height != grub_video_bitmap_get_height (bitmap))
|
||||
{
|
||||
struct grub_video_bitmap *scaled_bitmap;
|
||||
grub_video_bitmap_create_scaled (&scaled_bitmap,
|
||||
window.width,
|
||||
window.height,
|
||||
bitmap,
|
||||
GRUB_VIDEO_BITMAP_SCALE_METHOD_BEST);
|
||||
if (grub_errno == GRUB_ERR_NONE)
|
||||
{
|
||||
/* Replace the original bitmap with the scaled one. */
|
||||
grub_video_bitmap_destroy (bitmap);
|
||||
bitmap = scaled_bitmap;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* If bitmap was loaded correctly, display it. */
|
||||
if (bitmap)
|
||||
{
|
||||
/* Determine bitmap dimensions. */
|
||||
bitmap_width = grub_video_bitmap_get_width (bitmap);
|
||||
bitmap_height = grub_video_bitmap_get_width (bitmap);
|
||||
bitmap_height = grub_video_bitmap_get_height (bitmap);
|
||||
|
||||
/* Mark whole screen as dirty. */
|
||||
dirty_region_reset ();
|
||||
dirty_region_add (0, 0, mode_info.width, mode_info.height);
|
||||
dirty_region_add (0, 0, window.width, window.height);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -949,18 +1178,22 @@ static struct grub_term_output grub_video_term =
|
|||
.next = 0
|
||||
};
|
||||
|
||||
static grub_command_t cmd;
|
||||
static grub_extcmd_t background_image_cmd_handle;
|
||||
|
||||
GRUB_MOD_INIT(gfxterm)
|
||||
{
|
||||
grub_term_register_output ("gfxterm", &grub_video_term);
|
||||
cmd = grub_register_command ("background_image",
|
||||
grub_gfxterm_background_image_cmd,
|
||||
0, "Load background image for active terminal");
|
||||
background_image_cmd_handle =
|
||||
grub_register_extcmd ("background_image",
|
||||
grub_gfxterm_background_image_cmd,
|
||||
GRUB_COMMAND_FLAG_BOTH,
|
||||
"[-m (stretch|normal)] FILE",
|
||||
"Load background image for active terminal.",
|
||||
background_image_cmd_options);
|
||||
}
|
||||
|
||||
GRUB_MOD_FINI(gfxterm)
|
||||
{
|
||||
grub_unregister_command (cmd);
|
||||
grub_unregister_extcmd (background_image_cmd_handle);
|
||||
grub_term_unregister_output (&grub_video_term);
|
||||
}
|
||||
|
|
|
@ -65,8 +65,7 @@ static struct grub_term_output grub_console_term_output =
|
|||
.setcolorstate = grub_console_setcolorstate,
|
||||
.setcolor = grub_console_setcolor,
|
||||
.getcolor = grub_console_getcolor,
|
||||
.setcursor = grub_console_setcursor,
|
||||
.flags = 0,
|
||||
.setcursor = grub_console_setcursor
|
||||
};
|
||||
|
||||
void
|
||||
|
@ -79,10 +78,6 @@ grub_console_init (void)
|
|||
void
|
||||
grub_console_fini (void)
|
||||
{
|
||||
/* This is to make sure the console is restored to text mode before
|
||||
we boot. */
|
||||
grub_term_set_current_output (&grub_console_term_output);
|
||||
|
||||
grub_term_unregister_input (&grub_console_term_input);
|
||||
grub_term_unregister_output (&grub_console_term_output);
|
||||
}
|
||||
|
|
|
@ -163,7 +163,7 @@ grub_vga_mod_init (void)
|
|||
set_start_address (PAGE_OFFSET (page));
|
||||
font = grub_font_get (""); /* Choose any font, for now. */
|
||||
if (!font)
|
||||
return grub_error (GRUB_ERR_BAD_FONT, "No font loaded.");
|
||||
return grub_error (GRUB_ERR_BAD_FONT, "no font loaded");
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
|
|
@ -77,7 +77,7 @@ inc_y (void)
|
|||
static void
|
||||
inc_x (void)
|
||||
{
|
||||
if (grub_curr_x >= COLS - 2)
|
||||
if (grub_curr_x >= COLS - 1)
|
||||
inc_y ();
|
||||
else
|
||||
grub_curr_x++;
|
||||
|
|
|
@ -83,12 +83,17 @@ grub_ofconsole_putchar (grub_uint32_t c)
|
|||
grub_curr_y++;
|
||||
grub_curr_x = 0;
|
||||
}
|
||||
else if (c == '\r')
|
||||
{
|
||||
grub_curr_x = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
grub_curr_x++;
|
||||
if (grub_curr_x > grub_ofconsole_width)
|
||||
if (grub_curr_x >= grub_ofconsole_width)
|
||||
{
|
||||
grub_putcode ('\n');
|
||||
grub_ofconsole_putchar ('\n');
|
||||
grub_ofconsole_putchar ('\r');
|
||||
grub_curr_x++;
|
||||
}
|
||||
}
|
||||
|
@ -104,7 +109,7 @@ grub_ofconsole_getcharwidth (grub_uint32_t c __attribute__((unused)))
|
|||
static void
|
||||
grub_ofconsole_setcolorstate (grub_term_color_state state)
|
||||
{
|
||||
char setcol[20];
|
||||
char setcol[256];
|
||||
int fg;
|
||||
int bg;
|
||||
|
||||
|
@ -123,7 +128,7 @@ grub_ofconsole_setcolorstate (grub_term_color_state state)
|
|||
return;
|
||||
}
|
||||
|
||||
grub_sprintf (setcol, "\e[3%dm\e[4%dm", fg, bg);
|
||||
grub_snprintf (setcol, sizeof (setcol), "\e[3%dm\e[4%dm", fg, bg);
|
||||
grub_ofconsole_writeesc (setcol);
|
||||
}
|
||||
|
||||
|
@ -234,44 +239,32 @@ grub_ofconsole_getxy (void)
|
|||
return ((grub_curr_x - 1) << 8) | grub_curr_y;
|
||||
}
|
||||
|
||||
static grub_uint16_t
|
||||
grub_ofconsole_getwh (void)
|
||||
static void
|
||||
grub_ofconsole_dimensions (void)
|
||||
{
|
||||
grub_ieee1275_ihandle_t options;
|
||||
char *val;
|
||||
grub_ssize_t lval;
|
||||
|
||||
if (grub_ofconsole_width && grub_ofconsole_height)
|
||||
return (grub_ofconsole_width << 8) | grub_ofconsole_height;
|
||||
|
||||
if (! grub_ieee1275_finddevice ("/options", &options)
|
||||
&& options != (grub_ieee1275_ihandle_t) -1)
|
||||
{
|
||||
if (! grub_ieee1275_get_property_length (options, "screen-#columns",
|
||||
&lval) && lval != -1)
|
||||
&lval)
|
||||
&& lval >= 0 && lval < 1024)
|
||||
{
|
||||
val = grub_malloc (lval);
|
||||
if (val)
|
||||
{
|
||||
if (! grub_ieee1275_get_property (options, "screen-#columns",
|
||||
val, lval, 0))
|
||||
grub_ofconsole_width = (grub_uint8_t) grub_strtoul (val, 0, 10);
|
||||
char val[lval];
|
||||
|
||||
grub_free (val);
|
||||
}
|
||||
if (! grub_ieee1275_get_property (options, "screen-#columns",
|
||||
val, lval, 0))
|
||||
grub_ofconsole_width = (grub_uint8_t) grub_strtoul (val, 0, 10);
|
||||
}
|
||||
if (! grub_ieee1275_get_property_length (options, "screen-#rows",
|
||||
&lval) && lval != -1)
|
||||
if (! grub_ieee1275_get_property_length (options, "screen-#rows", &lval)
|
||||
&& lval >= 0 && lval < 1024)
|
||||
{
|
||||
val = grub_malloc (lval);
|
||||
if (val)
|
||||
{
|
||||
if (! grub_ieee1275_get_property (options, "screen-#rows",
|
||||
val, lval, 0))
|
||||
grub_ofconsole_height = (grub_uint8_t) grub_strtoul (val, 0, 10);
|
||||
|
||||
grub_free (val);
|
||||
}
|
||||
char val[lval];
|
||||
if (! grub_ieee1275_get_property (options, "screen-#rows",
|
||||
val, lval, 0))
|
||||
grub_ofconsole_height = (grub_uint8_t) grub_strtoul (val, 0, 10);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -280,21 +273,24 @@ grub_ofconsole_getwh (void)
|
|||
grub_ofconsole_width = 80;
|
||||
if (! grub_ofconsole_height)
|
||||
grub_ofconsole_height = 24;
|
||||
}
|
||||
|
||||
static grub_uint16_t
|
||||
grub_ofconsole_getwh (void)
|
||||
{
|
||||
return (grub_ofconsole_width << 8) | grub_ofconsole_height;
|
||||
}
|
||||
|
||||
static void
|
||||
grub_ofconsole_gotoxy (grub_uint8_t x, grub_uint8_t y)
|
||||
{
|
||||
char s[11]; /* 5 + 3 + 3. */
|
||||
|
||||
if (! grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_NO_ANSI))
|
||||
{
|
||||
char s[256];
|
||||
grub_curr_x = x;
|
||||
grub_curr_y = y;
|
||||
|
||||
grub_sprintf (s, "\e[%d;%dH", y + 1, x + 1);
|
||||
grub_snprintf (s, sizeof (s), "\e[%d;%dH", y + 1, x + 1);
|
||||
grub_ofconsole_writeesc (s);
|
||||
}
|
||||
else
|
||||
|
@ -319,7 +315,7 @@ grub_ofconsole_cls (void)
|
|||
* ANSI escape sequence. Using video console, Apple Open Firmware (version
|
||||
* 3.1.1) only recognizes the literal ^L. So use both. */
|
||||
grub_ofconsole_writeesc ("\e[2J");
|
||||
grub_gotoxy (0, 0);
|
||||
grub_ofconsole_gotoxy (0, 0);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -346,7 +342,7 @@ grub_ofconsole_init_input (void)
|
|||
if (grub_ieee1275_get_integer_property (grub_ieee1275_chosen, "stdin", &stdin_ihandle,
|
||||
sizeof stdin_ihandle, &actual)
|
||||
|| actual != sizeof stdin_ihandle)
|
||||
return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "Cannot find stdin");
|
||||
return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "cannot find stdin");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -365,7 +361,7 @@ grub_ofconsole_init_output (void)
|
|||
if (grub_ieee1275_get_integer_property (grub_ieee1275_chosen, "stdout", &stdout_ihandle,
|
||||
sizeof stdout_ihandle, &actual)
|
||||
|| actual != sizeof stdout_ihandle)
|
||||
return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "Cannot find stdout");
|
||||
return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "cannot find stdout");
|
||||
|
||||
/* Initialize colors. */
|
||||
if (! grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_CANNOT_SET_COLORS))
|
||||
|
@ -379,6 +375,8 @@ grub_ofconsole_init_output (void)
|
|||
grub_ofconsole_setcolorstate (GRUB_TERM_COLOR_NORMAL);
|
||||
}
|
||||
|
||||
grub_ofconsole_dimensions ();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -414,8 +412,7 @@ static struct grub_term_output grub_ofconsole_term_output =
|
|||
.setcolor = grub_ofconsole_setcolor,
|
||||
.getcolor = grub_ofconsole_getcolor,
|
||||
.setcursor = grub_ofconsole_setcursor,
|
||||
.refresh = grub_ofconsole_refresh,
|
||||
.flags = 0,
|
||||
.refresh = grub_ofconsole_refresh
|
||||
};
|
||||
|
||||
void
|
||||
|
|
|
@ -17,8 +17,7 @@
|
|||
*/
|
||||
|
||||
#include <grub/machine/memory.h>
|
||||
#include <grub/machine/serial.h>
|
||||
#include <grub/machine/console.h>
|
||||
#include <grub/serial.h>
|
||||
#include <grub/term.h>
|
||||
#include <grub/types.h>
|
||||
#include <grub/dl.h>
|
||||
|
@ -26,9 +25,10 @@
|
|||
#include <grub/terminfo.h>
|
||||
#include <grub/cpu/io.h>
|
||||
#include <grub/extcmd.h>
|
||||
#include <grub/i18n.h>
|
||||
|
||||
#define TEXT_WIDTH 80
|
||||
#define TEXT_HEIGHT 25
|
||||
#define TEXT_HEIGHT 24
|
||||
|
||||
static unsigned int xpos, ypos;
|
||||
static unsigned int keep_track = 1;
|
||||
|
@ -38,22 +38,24 @@ static unsigned int registered = 0;
|
|||
static char input_buf[8];
|
||||
static unsigned int npending = 0;
|
||||
|
||||
static struct grub_term_output grub_serial_term_output;
|
||||
|
||||
/* Argument options. */
|
||||
static const struct grub_arg_option options[] =
|
||||
{
|
||||
{"unit", 'u', 0, "Set the serial unit", 0, ARG_TYPE_INT},
|
||||
{"port", 'p', 0, "Set the serial port address", 0, ARG_TYPE_STRING},
|
||||
{"speed", 's', 0, "Set the serial port speed", 0, ARG_TYPE_INT},
|
||||
{"word", 'w', 0, "Set the serial port word length", 0, ARG_TYPE_INT},
|
||||
{"parity", 'r', 0, "Set the serial port parity", 0, ARG_TYPE_STRING},
|
||||
{"stop", 't', 0, "Set the serial port stop bits", 0, ARG_TYPE_INT},
|
||||
{"unit", 'u', 0, N_("Set the serial unit."), 0, ARG_TYPE_INT},
|
||||
{"port", 'p', 0, N_("Set the serial port address."), 0, ARG_TYPE_STRING},
|
||||
{"speed", 's', 0, N_("Set the serial port speed."), 0, ARG_TYPE_INT},
|
||||
{"word", 'w', 0, N_("Set the serial port word length."), 0, ARG_TYPE_INT},
|
||||
{"parity", 'r', 0, N_("Set the serial port parity."), 0, ARG_TYPE_STRING},
|
||||
{"stop", 't', 0, N_("Set the serial port stop bits."), 0, ARG_TYPE_INT},
|
||||
{0, 0, 0, 0, 0, 0}
|
||||
};
|
||||
|
||||
/* Serial port settings. */
|
||||
struct serial_port
|
||||
{
|
||||
unsigned short port;
|
||||
grub_port_t port;
|
||||
unsigned short divisor;
|
||||
unsigned short word_len;
|
||||
unsigned int parity;
|
||||
|
@ -67,12 +69,13 @@ static struct serial_port serial_settings;
|
|||
static const unsigned short *serial_hw_io_addr = (const unsigned short *) GRUB_MEMORY_MACHINE_BIOS_DATA_AREA_ADDR;
|
||||
#define GRUB_SERIAL_PORT_NUM 4
|
||||
#else
|
||||
static const unsigned short serial_hw_io_addr[] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8 };
|
||||
#include <grub/machine/serial.h>
|
||||
static const grub_port_t serial_hw_io_addr[] = GRUB_MACHINE_SERIAL_PORTS;
|
||||
#define GRUB_SERIAL_PORT_NUM (ARRAY_SIZE(serial_hw_io_addr))
|
||||
#endif
|
||||
|
||||
/* Return the port number for the UNITth serial device. */
|
||||
static inline unsigned short
|
||||
static inline grub_port_t
|
||||
serial_hw_get_port (const unsigned int unit)
|
||||
{
|
||||
if (unit < GRUB_SERIAL_PORT_NUM)
|
||||
|
@ -148,7 +151,7 @@ serial_translate_key_sequence (void)
|
|||
if (input_buf[0] != '\e' || input_buf[1] != '[')
|
||||
return;
|
||||
|
||||
for (i = 0; ARRAY_SIZE (three_code_table); i++)
|
||||
for (i = 0; i < ARRAY_SIZE (three_code_table); i++)
|
||||
if (three_code_table[i].key == input_buf[2])
|
||||
{
|
||||
input_buf[0] = three_code_table[i].ascii;
|
||||
|
@ -253,6 +256,9 @@ grub_serial_getkey (void)
|
|||
;
|
||||
|
||||
c = input_buf[0];
|
||||
if (c == 0x7f)
|
||||
c = GRUB_TERM_BACKSPACE;
|
||||
|
||||
grub_memmove (input_buf, input_buf + 1, --npending);
|
||||
|
||||
return c;
|
||||
|
@ -363,7 +369,7 @@ grub_serial_putchar (grub_uint32_t c)
|
|||
break;
|
||||
|
||||
case '\n':
|
||||
if (ypos < TEXT_HEIGHT)
|
||||
if (ypos < TEXT_HEIGHT - 1)
|
||||
ypos++;
|
||||
break;
|
||||
|
||||
|
@ -413,7 +419,7 @@ grub_serial_gotoxy (grub_uint8_t x, grub_uint8_t y)
|
|||
else
|
||||
{
|
||||
keep_track = 0;
|
||||
grub_terminfo_gotoxy (x, y);
|
||||
grub_terminfo_gotoxy (x, y, &grub_serial_term_output);
|
||||
keep_track = 1;
|
||||
|
||||
xpos = x;
|
||||
|
@ -425,7 +431,7 @@ static void
|
|||
grub_serial_cls (void)
|
||||
{
|
||||
keep_track = 0;
|
||||
grub_terminfo_cls ();
|
||||
grub_terminfo_cls (&grub_serial_term_output);
|
||||
keep_track = 1;
|
||||
|
||||
xpos = ypos = 0;
|
||||
|
@ -439,10 +445,10 @@ grub_serial_setcolorstate (const grub_term_color_state state)
|
|||
{
|
||||
case GRUB_TERM_COLOR_STANDARD:
|
||||
case GRUB_TERM_COLOR_NORMAL:
|
||||
grub_terminfo_reverse_video_off ();
|
||||
grub_terminfo_reverse_video_off (&grub_serial_term_output);
|
||||
break;
|
||||
case GRUB_TERM_COLOR_HIGHLIGHT:
|
||||
grub_terminfo_reverse_video_on ();
|
||||
grub_terminfo_reverse_video_on (&grub_serial_term_output);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
@ -454,9 +460,9 @@ static void
|
|||
grub_serial_setcursor (const int on)
|
||||
{
|
||||
if (on)
|
||||
grub_terminfo_cursor_on ();
|
||||
grub_terminfo_cursor_on (&grub_serial_term_output);
|
||||
else
|
||||
grub_terminfo_cursor_off ();
|
||||
grub_terminfo_cursor_off (&grub_serial_term_output);
|
||||
}
|
||||
|
||||
static struct grub_term_input grub_serial_term_input =
|
||||
|
@ -498,11 +504,11 @@ grub_cmd_serial (grub_extcmd_t cmd,
|
|||
unit = grub_strtoul (state[0].arg, 0, 0);
|
||||
serial_settings.port = serial_hw_get_port (unit);
|
||||
if (!serial_settings.port)
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT, "bad unit number.");
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT, "bad unit number");
|
||||
}
|
||||
|
||||
if (state[1].set)
|
||||
serial_settings.port = (unsigned short) grub_strtoul (state[1].arg, 0, 0);
|
||||
serial_settings.port = (grub_port_t) grub_strtoul (state[1].arg, 0, 0);
|
||||
|
||||
if (state[2].set)
|
||||
{
|
|
@ -103,57 +103,57 @@ grub_terminfo_set_current (const char *str)
|
|||
return grub_errno;
|
||||
}
|
||||
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT, "unknown terminfo type.");
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT, "unknown terminfo type");
|
||||
}
|
||||
|
||||
/* Wrapper for grub_putchar to write strings. */
|
||||
static void
|
||||
putstr (const char *str)
|
||||
putstr (const char *str, grub_term_output_t oterm)
|
||||
{
|
||||
while (*str)
|
||||
grub_putchar (*str++);
|
||||
grub_putcode (*str++, oterm);
|
||||
}
|
||||
|
||||
/* Move the cursor to the given position starting with "0". */
|
||||
void
|
||||
grub_terminfo_gotoxy (grub_uint8_t x, grub_uint8_t y)
|
||||
grub_terminfo_gotoxy (grub_uint8_t x, grub_uint8_t y, grub_term_output_t oterm)
|
||||
{
|
||||
putstr (grub_terminfo_tparm (term.gotoxy, y, x));
|
||||
putstr (grub_terminfo_tparm (term.gotoxy, y, x), oterm);
|
||||
}
|
||||
|
||||
/* Clear the screen. */
|
||||
void
|
||||
grub_terminfo_cls (void)
|
||||
grub_terminfo_cls (grub_term_output_t oterm)
|
||||
{
|
||||
putstr (grub_terminfo_tparm (term.cls));
|
||||
putstr (grub_terminfo_tparm (term.cls), oterm);
|
||||
}
|
||||
|
||||
/* Set reverse video mode on. */
|
||||
void
|
||||
grub_terminfo_reverse_video_on (void)
|
||||
grub_terminfo_reverse_video_on (grub_term_output_t oterm)
|
||||
{
|
||||
putstr (grub_terminfo_tparm (term.reverse_video_on));
|
||||
putstr (grub_terminfo_tparm (term.reverse_video_on), oterm);
|
||||
}
|
||||
|
||||
/* Set reverse video mode off. */
|
||||
void
|
||||
grub_terminfo_reverse_video_off (void)
|
||||
grub_terminfo_reverse_video_off (grub_term_output_t oterm)
|
||||
{
|
||||
putstr (grub_terminfo_tparm (term.reverse_video_off));
|
||||
putstr (grub_terminfo_tparm (term.reverse_video_off), oterm);
|
||||
}
|
||||
|
||||
/* Show cursor. */
|
||||
void
|
||||
grub_terminfo_cursor_on (void)
|
||||
grub_terminfo_cursor_on (grub_term_output_t oterm)
|
||||
{
|
||||
putstr (grub_terminfo_tparm (term.cursor_on));
|
||||
putstr (grub_terminfo_tparm (term.cursor_on), oterm);
|
||||
}
|
||||
|
||||
/* Hide cursor. */
|
||||
void
|
||||
grub_terminfo_cursor_off (void)
|
||||
grub_terminfo_cursor_off (grub_term_output_t oterm)
|
||||
{
|
||||
putstr (grub_terminfo_tparm (term.cursor_off));
|
||||
putstr (grub_terminfo_tparm (term.cursor_off), oterm);
|
||||
}
|
||||
|
||||
/* GRUB Command. */
|
||||
|
@ -168,7 +168,7 @@ grub_cmd_terminfo (grub_command_t cmd __attribute__ ((unused)),
|
|||
return GRUB_ERR_NONE;
|
||||
}
|
||||
else if (argc != 1)
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT, "too many parameters.");
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT, "too many parameters");
|
||||
else
|
||||
return grub_terminfo_set_current (args[0]);
|
||||
}
|
||||
|
@ -178,7 +178,7 @@ static grub_command_t cmd;
|
|||
GRUB_MOD_INIT(terminfo)
|
||||
{
|
||||
cmd = grub_register_command ("terminfo", grub_cmd_terminfo,
|
||||
"terminfo [TERM]", "Set terminfo type.");
|
||||
"[TERM]", "Set terminfo type.");
|
||||
grub_terminfo_set_current ("vt100");
|
||||
}
|
||||
|
||||
|
|
|
@ -167,7 +167,7 @@ save_text(const char *fmt, const char *s, int len)
|
|||
|
||||
get_space(s_len + 1);
|
||||
|
||||
(void) grub_sprintf(out_buff + out_used, fmt, s);
|
||||
(void) grub_snprintf(out_buff + out_used, s_len + 1, fmt, s);
|
||||
out_used += grub_strlen(out_buff + out_used);
|
||||
}
|
||||
|
||||
|
@ -179,7 +179,7 @@ save_number(const char *fmt, int number, int len)
|
|||
|
||||
get_space((unsigned) len + 1);
|
||||
|
||||
(void) grub_sprintf(out_buff + out_used, fmt, number);
|
||||
(void) grub_snprintf(out_buff + out_used, len + 1, fmt, number);
|
||||
out_used += grub_strlen(out_buff + out_used);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue