aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Fleming <matt.fleming@intel.com>2012-12-03 13:30:36 +0000
committerMatt Fleming <matt.fleming@intel.com>2012-12-03 13:54:46 +0000
commit82cbb1bd4133035fb37a753c15dfaa57e34db87f (patch)
treec76b33222850286a6fa5d379cdddad519a358e0a
parent0163d235652d2cc8f0564da7470983ee450a8a91 (diff)
downloadsyslinux-82cbb1bd4133035fb37a753c15dfaa57e34db87f.tar.gz
syslinux-82cbb1bd4133035fb37a753c15dfaa57e34db87f.tar.xz
syslinux-82cbb1bd4133035fb37a753c15dfaa57e34db87f.zip
ldlinux: Move DISPLAY file handling out of the coresyslinux-5.00-pre13
The code that handles the DISPLAY directive was writing directly to the BIOS VGA page with __intcall(0x10). This caused corruption problems on the screen because the ansi library code was also writing to the screen. The correct way to fix this is to always use the ansi library code (via printf()) instead of going behind its back and using separate code paths to write to the screen. Reported-by: Ady <ady-sf@hotmail.com> Signed-off-by: Matt Fleming <matt.fleming@intel.com>
-rw-r--r--com32/elflink/ldlinux/Makefile2
-rw-r--r--com32/elflink/ldlinux/msg.c214
-rw-r--r--core/conio.c339
3 files changed, 215 insertions, 340 deletions
diff --git a/com32/elflink/ldlinux/Makefile b/com32/elflink/ldlinux/Makefile
index 0666d9f6..b4e5cfa1 100644
--- a/com32/elflink/ldlinux/Makefile
+++ b/com32/elflink/ldlinux/Makefile
@@ -21,7 +21,7 @@ all: ldlinux.c32 ldlinux_lnx.a
ldlinux.c32 : ldlinux.o cli.o readconfig.o refstr.o colors.o getadv.o \
adv.o execute.o chainboot.o kernel.o get_key.o \
- advwrite.o setadv.o eprintf.o loadhigh.o
+ advwrite.o setadv.o eprintf.o loadhigh.o msg.o
$(LD) $(LDFLAGS) -o $@ $^ $(LIBS)
LNXLIBOBJS = get_key.lo
diff --git a/com32/elflink/ldlinux/msg.c b/com32/elflink/ldlinux/msg.c
new file mode 100644
index 00000000..fdb3c981
--- /dev/null
+++ b/com32/elflink/ldlinux/msg.c
@@ -0,0 +1,214 @@
+#include <com32.h>
+#include <stdio.h>
+#include <bios.h>
+#include <graphics.h>
+
+static uint8_t TextAttribute; /* Text attribute for message file */
+static uint8_t DisplayMask; /* Display modes mask */
+
+/* Routine to interpret next print char */
+static void (*NextCharJump)(uint8_t);
+
+void msg_initvars(void);
+static void msg_setfg(uint8_t data);
+static void msg_putchar(uint8_t ch);
+
+/*
+ *
+ * get_msg_file: Load a text file and write its contents to the screen,
+ * interpreting color codes.
+ *
+ * Returns 0 on success, -1 on failure.
+ */
+int get_msg_file(char *filename)
+{
+ FILE *f;
+ char ch;
+
+ f = fopen(filename, "r");
+ if (!f)
+ return -1;
+
+ TextAttribute = 0x7; /* Default grey on white */
+ DisplayMask = 0x7; /* Display text in all modes */
+ msg_initvars();
+
+ /*
+ * Read the text file a byte at a time and interpret that
+ * byte.
+ */
+ while ((ch = getc(f)) != EOF) {
+ /* DOS EOF? */
+ if (ch == 0x1A)
+ break;
+
+ /*
+ * 01h = text mode
+ * 02h = graphics mode
+ */
+ UsingVGA &= 0x1;
+ UsingVGA += 1;
+
+ NextCharJump(ch); /* Do what shall be done */
+ }
+
+ fclose(f);
+ return 0;
+}
+
+static void msg_setbg(uint8_t data)
+{
+ if (unhexchar(&data) == 0) {
+ data <<= 4;
+ if (DisplayMask & UsingVGA) {
+ TextAttribute = data;
+ }
+
+ NextCharJump = msg_setfg;
+ } else {
+ TextAttribute = 0x7; /* Default attribute */
+ NextCharJump = msg_putchar;
+ }
+}
+
+static void msg_setfg(uint8_t data)
+{
+ if (unhexchar(&data) == 0) {
+ if (DisplayMask & UsingVGA) {
+ /* setbg set foreground to 0 */
+ TextAttribute |= data;
+ }
+ } else
+ TextAttribute = 0x7; /* Default attribute */
+
+ NextCharJump = msg_putchar;
+}
+
+static inline void msg_ctrl_o(void)
+{
+ NextCharJump = msg_setbg;
+}
+
+static void msg_novga(void)
+{
+ syslinux_force_text_mode();
+ msg_initvars();
+}
+
+static void msg_viewimage(void)
+{
+ FILE *f;
+
+ *VGAFilePtr = '\0'; /* Zero-terminate filename */
+
+ mangle_name(VGAFileMBuf, VGAFileBuf);
+ f = fopen(VGAFileMBuf, "r");
+ if (!f) {
+ /* Not there */
+ NextCharJump = msg_putchar;
+ return;
+ }
+
+ vgadisplayfile(f);
+ fclose(f);
+ msg_initvars();
+}
+
+/*
+ * Getting VGA filename
+ */
+static void msg_filename(uint8_t data)
+{
+ /* <LF> = end of filename */
+ if (data == 0x0A) {
+ msg_viewimage();
+ return;
+ }
+
+ /* Ignore space/control char */
+ if (data > ' ') {
+ if ((char *)VGAFilePtr < (VGAFileBuf + sizeof(VGAFileBuf)))
+ *VGAFilePtr++ = data;
+ }
+}
+
+static void msg_vga(void)
+{
+ NextCharJump = msg_filename;
+ VGAFilePtr = (uint16_t *)VGAFileBuf;
+}
+
+/* Convert ANSI colors to PC display attributes */
+static int convert_to_pcdisplay[] = { 0, 4, 2, 6, 1, 5, 3, 7 };
+
+static void msg_normal(uint8_t data)
+{
+ uint8_t bg, fg;
+
+ /* Write to serial port */
+ if (DisplayMask & 0x4)
+ write_serial(data);
+
+ if (!(DisplayMask & UsingVGA))
+ return; /* Not screen */
+
+ if (!(DisplayCon & 0x01))
+ return;
+
+ fg = convert_to_pcdisplay[(TextAttribute & 0x7)];
+ bg = convert_to_pcdisplay[((TextAttribute >> 4) & 0x7)];
+
+ printf("\033[");
+ if (TextAttribute & 0x40)
+ printf("1;"); /* Foreground bright */
+
+ printf("1;3%dm\033[", fg);
+
+ if (TextAttribute & 0x80)
+ printf("5;"); /* Foreground blink */
+
+ printf("4%dm%c\033[0m", bg, data);
+}
+
+static void msg_modectl(uint8_t data)
+{
+ data &= 0x07;
+ DisplayMask = data;
+ NextCharJump = msg_putchar;
+}
+
+static void msg_putchar(uint8_t ch)
+{
+ /* 10h to 17h are mode controls */
+ if (ch >= 0x10 && ch < 0x18) {
+ msg_modectl(ch);
+ return;
+ }
+
+ switch (ch) {
+ case 0x0F: /* ^O = color code follows */
+ msg_ctrl_o();
+ break;
+ case 0x0D: /* Ignore <CR> */
+ break;
+ case 0x19: /* <EM> = return to text mode */
+ msg_novga();
+ break;
+ case 0x18: /* <CAN> = VGA filename follows */
+ msg_vga();
+ break;
+ default:
+ msg_normal(ch);
+ break;
+ }
+}
+
+/*
+ * Subroutine to initialize variables, also needed after loading
+ * graphics file.
+ */
+void msg_initvars(void)
+{
+ /* Initialize state machine */
+ NextCharJump = msg_putchar;
+}
diff --git a/core/conio.c b/core/conio.c
index 421dabfd..be7f7d48 100644
--- a/core/conio.c
+++ b/core/conio.c
@@ -45,15 +45,6 @@ uint8_t FlowIgnore = 0; /* Ignore input unless these bits set */
uint8_t ScrollAttribute = 0x07; /* Grey on white (normal text color) */
uint16_t DisplayCon = 0x01; /* Display console enabled */
-static uint8_t TextAttribute; /* Text attribute for message file */
-static uint8_t DisplayMask; /* Display modes mask */
-
-/* Routine to interpret next print char */
-static void (*NextCharJump)(char);
-
-void msg_initvars(void);
-static void msg_setfg(char data);
-static void msg_putchar(char ch);
/*
* loadkeys: Load a LILO-style keymap
@@ -75,58 +66,6 @@ int loadkeys(char *filename)
}
/*
- *
- * get_msg_file: Load a text file and write its contents to the screen,
- * interpreting color codes.
- *
- * Returns 0 on success, -1 on failure.
- */
-int get_msg_file(char *filename)
-{
- FILE *f;
- char ch;
-
- f = fopen(filename, "r");
- if (!f)
- return -1;
-
- TextAttribute = 0x7; /* Default grey on white */
- DisplayMask = 0x7; /* Display text in all modes */
- msg_initvars();
-
- /*
- * Read the text file a byte at a time and interpret that
- * byte.
- */
- while ((ch = getc(f)) != EOF) {
- /* DOS EOF? */
- if (ch == 0x1A)
- break;
-
- /*
- * 01h = text mode
- * 02h = graphics mode
- */
- UsingVGA &= 0x1;
- UsingVGA += 1;
-
- NextCharJump(ch); /* Do what shall be done */
- }
-
- fclose(f);
- return 0;
-}
-
-static inline void msg_beep(void)
-{
- com32sys_t ireg, oreg;
-
- ireg.eax.w[0] = 0x0E07; /* Beep */
- ireg.ebx.w[0] = 0x0000;
- __intcall(0x10, &ireg, &oreg);
-}
-
-/*
* write_serial: If serial output is enabled, write character on
* serial port.
*/
@@ -182,12 +121,6 @@ void pm_serialcfg(com32sys_t *regs)
regs->ebx.w[0] = al | (ah << 8);
}
-static void write_serial_displaymask(char data)
-{
- if (DisplayMask & 0x4)
- write_serial(data);
-}
-
/*
* write_serial_str: write_serial for strings
*/
@@ -200,15 +133,6 @@ void write_serial_str(char *data)
}
/*
- * write_serial_str_displaymask: d:o, but ignore if DisplayMask & 04h == 0
- */
-static void write_serial_str_displaymask(char *data)
-{
- if (DisplayMask & 0x4)
- write_serial_str(data);
-}
-
-/*
* pollchar: check if we have an input character pending
*
* Returns 1 if character pending.
@@ -336,266 +260,3 @@ void pm_getchar(com32sys_t *regs)
{
regs->eax.b[0] = getchar((char *)&regs->eax.b[1]);
}
-
-static void msg_setbg(char data)
-{
- if (unhexchar(&data) == 0) {
- data <<= 4;
- if (DisplayMask & UsingVGA)
- TextAttribute = data;
-
- NextCharJump = msg_setfg;
- } else {
- TextAttribute = 0x7; /* Default attribute */
- NextCharJump = msg_putchar;
- }
-}
-
-static void msg_setfg(char data)
-{
- if (unhexchar(&data) == 0) {
- if (DisplayMask & UsingVGA) {
- /* setbg set foreground to 0 */
- TextAttribute |= data;
- }
- } else
- TextAttribute = 0x7; /* Default attribute */
-
- NextCharJump = msg_putchar;
-}
-
-static inline void msg_ctrl_o(void)
-{
- NextCharJump = msg_setbg;
-}
-
-static void msg_gotoxy(void)
-{
- com32sys_t ireg, oreg;
-
- memset(&ireg, 0, sizeof(ireg));
-
- ireg.ebx.b[1] = *(uint8_t *)BIOS_page;
- ireg.edx.w[0] = CursorDX;
- ireg.eax.b[1] = 0x02; /* Set cursor position */
-
- __intcall(0x10, &ireg, &oreg);
-}
-
-static void msg_newline(void)
-{
- com32sys_t ireg, oreg;
- char crlf_msg[] = { '\r', '\n', '\0' };
-
- write_serial_str_displaymask(crlf_msg);
-
- if (!(DisplayMask & UsingVGA))
- return;
-
- CursorCol = 0;
- if ((CursorRow + 1) <= VidRows)
- CursorRow++;
- else {
- ireg.ecx.w[0] = 0x0; /* Upper left hand corner */
- ireg.edx.w[0] = ScreenSize;
-
- CursorRow = ireg.edx.b[1]; /* New cursor at the bottom */
-
- ireg.ebx.b[1] = ScrollAttribute;
- ireg.eax.w[0] = 0x0601; /* Scroll up one line */
-
- __intcall(0x10, &ireg, &oreg);
- }
-
- msg_gotoxy();
-}
-
-static void msg_formfeed(void)
-{
- char crff_msg[] = { '\r', '\f', '\0' };
-
- write_serial_str_displaymask(crff_msg);
-
- if (DisplayMask & UsingVGA) {
- com32sys_t ireg, oreg;
-
- memset(&ireg, 0, sizeof(ireg));
-
- CursorDX = 0x0; /* Upper left hand corner */
-
- ireg.edx.w[0] = ScreenSize;
- ireg.ebx.b[1] = TextAttribute;
-
- ireg.eax.w[0] = 0x0600; /* Clear screen region */
- __intcall(0x10, &ireg, &oreg);
-
- msg_gotoxy();
- }
-}
-
-static void msg_novga(void)
-{
- syslinux_force_text_mode();
- msg_initvars();
-}
-
-static void msg_viewimage(void)
-{
- FILE *f;
-
- *VGAFilePtr = '\0'; /* Zero-terminate filename */
-
- mangle_name(VGAFileMBuf, VGAFileBuf);
- f = fopen(VGAFileMBuf, "r");
- if (!f) {
- /* Not there */
- NextCharJump = msg_putchar;
- return;
- }
-
- vgadisplayfile(f);
- fclose(f);
- msg_initvars();
-}
-
-/*
- * Getting VGA filename
- */
-static void msg_filename(char data)
-{
- /* <LF> = end of filename */
- if (data == 0x0A) {
- msg_viewimage();
- return;
- }
-
- /* Ignore space/control char */
- if (data > ' ') {
- if ((char *)VGAFilePtr < (VGAFileBuf + sizeof(VGAFileBuf)))
- *VGAFilePtr++ = data;
- }
-}
-
-static void msg_vga(void)
-{
- NextCharJump = msg_filename;
- VGAFilePtr = (uint16_t *)VGAFileBuf;
-}
-
-static void msg_line_wrap(void)
-{
- if (!(DisplayMask & UsingVGA))
- return;
-
- CursorCol = 0;
- if ((CursorRow + 1) <= VidRows)
- CursorRow++;
- else {
- com32sys_t ireg, oreg;
-
- memset(&ireg, 0, sizeof(ireg));
-
- ireg.ecx.w[0] = 0x0; /* Upper left hand corner */
- ireg.edx.w[0] = ScreenSize;
-
- CursorRow = ireg.edx.b[1]; /* New cursor at the bottom */
-
- ireg.ebx.b[1] = ScrollAttribute;
- ireg.eax.w[0] = 0x0601; /* Scroll up one line */
-
- __intcall(0x10, &ireg, &oreg);
- }
-
- msg_gotoxy();
-}
-
-static void msg_normal(char data)
-{
- com32sys_t ireg, oreg;
-
- /* Write to serial port */
- write_serial_displaymask(data);
-
- if (!(DisplayMask & UsingVGA))
- return; /* Not screen */
-
- if (!(DisplayCon & 0x01))
- return;
-
- memset(&ireg, 0, sizeof(ireg));
-
- ireg.ebx.b[0] = TextAttribute;
- ireg.ebx.b[1] = *(uint8_t *)BIOS_page;
- ireg.eax.b[0] = data;
- ireg.eax.b[1] = 0x09; /* Write character/attribute */
- ireg.ecx.w[0] = 1; /* One character only */
-
- /* Write to screen */
- __intcall(0x10, &ireg, &oreg);
-
- if ((CursorCol + 1) <= VidCols) {
- CursorCol++;
- msg_gotoxy();
- } else
- msg_line_wrap(); /* Screen wraparound */
-}
-
-static void msg_modectl(char data)
-{
- data &= 0x07;
- DisplayMask = data;
- NextCharJump = msg_putchar;
-}
-
-static void msg_putchar(char ch)
-{
- /* 10h to 17h are mode controls */
- if (ch >= 0x10 && ch < 0x18) {
- msg_modectl(ch);
- return;
- }
-
- switch (ch) {
- case 0x0F: /* ^O = color code follows */
- msg_ctrl_o();
- break;
- case 0x0D: /* Ignore <CR> */
- break;
- case 0x0A: /* <LF> = newline */
- msg_newline();
- break;
- case 0x0C: /* <FF> = clear screen */
- msg_formfeed();
- break;
- case 0x07: /* <BEL> = beep */
- msg_beep();
- break;
- case 0x19: /* <EM> = return to text mode */
- msg_novga();
- break;
- case 0x18: /* <CAN> = VGA filename follows */
- msg_vga();
- break;
- default:
- msg_normal(ch);
- break;
- }
-}
-
-/*
- * Subroutine to initialize variables, also needed after loading
- * graphics file.
- */
-void msg_initvars(void)
-{
- com32sys_t ireg, oreg;
-
- ireg.eax.b[1] = 0x3; /* Read cursor position */
- ireg.ebx.b[1] = *(uint8_t *)BIOS_page;
- __intcall(0x10, &ireg, &oreg);
-
- CursorDX = oreg.edx.w[0];
-
- /* Initialize state machine */
- NextCharJump = msg_putchar;
-}