2003-09-25 Yoshinori K. Okuji <okuji@enbug.org>

I forgot to check in these changes for a long time. This adds
	incomplete support for VGA console, and this is still very
	buggy. Also, a lot of consideration is required for I18N,
	UNICODE, and VGA font issues. Therefore, assume that this is
	such that "better than nothing".

	* font/manager.c: New file.
	* include/pupa/font.h: Likewise.
	* include/pupa/i386/pc/vga.h: Likewise.
	* term/i386/pc/vga.c: Likewise.
	* util/unifont2pff.rb: Likewise.

	* conf/i386-pc.rmk (kernel_img_HEADERS): Added machine/vga.h.
	(pkgdata_MODULES): Added vga.mod and font.mod.
	(vga_mod_SOURCES): New variables.
	(vga_mod_CFLAGS): Likewise.
	(font_mod_SOURCES): Likewise.
	(font_mod_CFLAGS): Likewise.

	* include/pupa/err.h (PUPA_ERR_BAD_FONT): New constant.

	* include/pupa/term.h: Include pupa/err.h.
	(struct pupa_term): Added init and fini.
	Changed the argument of putchar to pupa_uint32_t.

	* include/pupa/i386/pc/console.h: Include pupa/symbol.h.
	(pupa_console_real_putchar): New prototype.
	(pupa_console_putchar): Removed.
	(pupa_console_checkkey): Exported.
	(pupa_console_getkey): Likewise.

	* kern/misc.c (pupa_vsprintf): Add support for UNICODE
	characters.

	* kern/term.c (pupa_term_set_current): Rewritten.
	(pupa_putchar): Likewise.
	(pupa_putcode): New function.

	* kern/i386/pc/startup.S (pupa_console_putchar): Renamed to ...
	(pupa_console_real_putchar): ... this.
	(pupa_vga_set_mode): New function.
	(pupa_vga_get_font): Likewise.

	* normal/command.c: Include pupa/term.h.
	(terminal_command): New function.
	(pupa_command_init): Register the command "terminal".

	* normal/menu.c (DISP_LEFT): Changed to a UNICODE value.
	(DISP_UP): Likewise.
	(DISP_RIGHT): Likewise.
	(DISP_DOWN): Likewise.
	(DISP_HLINE): Likewise.
	(DISP_VLINE): Likewise.
	(DISP_UL): Likewise.
	(DISP_UR): Likewise.
	(DISP_LL): Likewise.
	(DISP_LR): Likewise.

	* term/i386/pc/console.c (pupa_console_putchar): New function.
This commit is contained in:
okuji 2003-09-25 20:15:53 +00:00
parent 977329f5fa
commit 18d9c7cd53
17 changed files with 1443 additions and 50 deletions

View file

@ -1090,7 +1090,7 @@ xsmap:
/*
* void pupa_console_putchar (int c)
* void pupa_console_real_putchar (int c)
*
* Put the character C on the console. Because GRUB wants to write a
* character with an attribute, this implementation is a bit tricky.
@ -1103,7 +1103,7 @@ xsmap:
* get the height of the screen, and the TELETYPE OUPUT BIOS call doesn't
* support setting a background attribute.
*/
FUNCTION(pupa_console_putchar)
FUNCTION(pupa_console_real_putchar)
movl %eax, %edx
pusha
movb EXT_C(pupa_console_cur_color), %bl
@ -1514,3 +1514,60 @@ FUNCTION(pupa_currticks)
popl %ebp
ret
/*
* unsigned char pupa_vga_set_mode (unsigned char mode)
*/
FUNCTION(pupa_vga_set_mode)
pushl %ebp
pushl %ebx
movl %eax, %ecx
call prot_to_real
.code16
/* get current mode */
xorw %bx, %bx
movb $0x0f, %ah
int $0x10
movb %al, %dl
/* set the new mode */
movb %cl, %al
xorb %ah, %ah
int $0x10
DATA32 call real_to_prot
.code32
movb %dl, %al
popl %ebx
popl %ebp
ret
/*
* unsigned char *pupa_vga_get_font (void)
*/
FUNCTION(pupa_vga_get_font)
pushl %ebp
pushl %ebx
call prot_to_real
.code16
movw $0x1130, %ax
movb $0x06, %bh
int $0x10
movw %es, %bx
movw %bp, %dx
DATA32 call real_to_prot
.code32
movzwl %bx, %ecx
shll $4, %ecx
movw %dx, %ax
addl %ecx, %eax
popl %ebx
popl %ebp
ret

View file

@ -328,10 +328,10 @@ pupa_vsprintf (char *str, const char *fmt, va_list args)
{
char c;
int count = 0;
auto void write_char (char ch);
auto void write_char (unsigned char ch);
auto void write_str (const char *s);
void write_char (char ch)
void write_char (unsigned char ch)
{
if (str)
*str++ = ch;
@ -375,7 +375,57 @@ pupa_vsprintf (char *str, const char *fmt, va_list args)
case 'c':
n = va_arg (args, int);
write_char (n);
write_char (n & 0xff);
break;
case 'C':
{
pupa_uint32_t code = va_arg (args, pupa_uint32_t);
int shift;
unsigned mask;
if (code <= 0x7f)
{
shift = 0;
mask = 0;
}
else if (code <= 0x7ff)
{
shift = 6;
mask = 0xc0;
}
else if (code <= 0xffff)
{
shift = 12;
mask = 0xe0;
}
else if (code <= 0x1fffff)
{
shift = 18;
mask = 0xf0;
}
else if (code <= 0x3ffffff)
{
shift = 24;
mask = 0xf8;
}
else if (code <= 0x7fffffff)
{
shift = 30;
mask = 0xfc;
}
else
{
code = '?';
shift = 0;
mask = 0;
}
write_char (mask | (code >> shift));
for (shift -= 6; shift >= 0; shift -= 6)
write_char (0x80 | (0x3f & (code >> shift)));
}
break;
case 's':

View file

@ -1,7 +1,7 @@
/*
* PUPA -- Preliminary Universal Programming Architecture for GRUB
* Copyright (C) 2002 Free Software Foundation, Inc.
* Copyright (C) 2002 Yoshinori K. Okuji <okuji@enbug.org>
* Copyright (C) 2002 Free Software Foundation, Inc.
* Copyright (C) 2002,2003 Yoshinori K. Okuji <okuji@enbug.org>
*
* PUPA is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -58,10 +58,20 @@ pupa_term_iterate (int (*hook) (pupa_term_t term))
break;
}
void
pupa_err_t
pupa_term_set_current (pupa_term_t term)
{
if (pupa_cur_term && pupa_cur_term->fini)
if ((pupa_cur_term->fini) () != PUPA_ERR_NONE)
return pupa_errno;
if (term->init)
if ((term->init) () != PUPA_ERR_NONE)
return pupa_errno;
pupa_cur_term = term;
pupa_cls ();
return PUPA_ERR_NONE;
}
pupa_term_t
@ -70,24 +80,89 @@ pupa_term_get_current (void)
return pupa_cur_term;
}
/* Put a Unicode character. */
void
pupa_putchar (int c)
pupa_putcode (pupa_uint32_t code)
{
if (c == '\t' && pupa_cur_term->getxy)
if (code == '\t' && pupa_cur_term->getxy)
{
int n;
n = 8 - ((pupa_getxy () >> 8) & 7);
while (n--)
pupa_putchar (' ');
pupa_putcode (' ');
return;
}
(pupa_cur_term->putchar) (c);
(pupa_cur_term->putchar) (code);
if (c == '\n')
pupa_putchar ('\r');
if (code == '\n')
pupa_putcode ('\r');
}
/* Put a character. C is one byte of a UTF-8 stream.
This function gathers bytes until a valid Unicode character is found. */
void
pupa_putchar (int c)
{
static pupa_uint32_t code = 0;
static int count = 0;
if (count)
{
if ((c & 0xc0) != 0x80)
{
/* invalid */
code = '@';
count = 0;
}
else
{
code <<= 6;
code |= (c & 0x3f);
count--;
}
}
else
{
if ((c & 0x80) == 0x00)
code = c;
else if ((c & 0xe0) == 0xc0)
{
count = 1;
code = c & 0x1f;
}
else if ((c & 0xf0) == 0xe0)
{
count = 2;
code = c & 0x0f;
}
else if ((c & 0xf8) == 0xf0)
{
count = 3;
code = c & 0x07;
}
else if ((c & 0xfc) == 0xf8)
{
count = 4;
code = c & 0x03;
}
else if ((c & 0xfe) == 0xfc)
{
count = 5;
code = c & 0x01;
}
else
/* invalid */
code = '?';
}
if (count)
/* Not finished yet. */
return;
pupa_putcode (code);
}
int