From: Guillermo J. Rozas Date: Sat, 17 Oct 1992 22:22:32 +0000 (+0000) Subject: Get rid of environment variables in the microcode. X-Git-Tag: 20090517-FFI~8851 X-Git-Url: https://birchwood-abbey.net/git?a=commitdiff_plain;h=3f845cbddbea6f68912556724f6bbfa7119c5863;p=mit-scheme.git Get rid of environment variables in the microcode. --- diff --git a/v7/src/microcode/dosint10.c b/v7/src/microcode/dosint10.c index a6105d04f..37fbaa934 100644 --- a/v7/src/microcode/dosint10.c +++ b/v7/src/microcode/dosint10.c @@ -1,6 +1,6 @@ /* -*-C-*- -$Id: dosint10.c,v 1.3 1992/10/07 06:23:28 jinx Exp $ +$Id: dosint10.c,v 1.4 1992/10/17 22:22:16 jinx Exp $ Copyright (c) 1992 Massachusetts Institute of Technology @@ -40,18 +40,23 @@ MIT in each case. */ calls, bios_* are slightly cooked interfaces, e.g. they do not have the exact same parameters that the BIOS calls document. - The coordinates (0x00,0x00) is the upper-left corner. + The coordinates (0,0) correspond to the upper-left corner. */ #include "scheme.h" #include "prims.h" #include "msdos.h" #include "dosint10.h" +#include "osio.h" +#include "ostty.h" /**********************************************************************/ #define MAP map_ansi_sys_color_to_bios_attribute +#define DEFAULT_FOREGROUND 37 /* White */ +#define DEFAULT_BACKGROUND 40 /* Black */ + static int map_ansi_sys_color_to_bios_attribute (int iANSIcode) { @@ -97,74 +102,51 @@ map_ansi_sys_color_to_bios_attribute (int iANSIcode) /* covers case of atoi parse failure returning 0 */ } -int DISPLAY_COLUMNS = UNINITIALIZED; -int DISPLAY_ROWS = UNINITIALIZED; +static int bios_initialized_p = 0; +static int display_columns = UNINITIALIZED; +static int display_rows = UNINITIALIZED; /* 0-based values, initialized from variables in dostty.c */ -int FOREGROUND_ATTRIBUTE = UNINITIALIZED; -int BACKGROUND_ATTRIBUTE = UNINITIALIZED; -int NORMAL_VIDEO = UNINITIALIZED; -int REVERSE_VIDEO = UNINITIALIZED; - -extern unsigned long RealModeBufferParagraph; -extern char *pRealModeBuffer; +static int foreground_attribute = UNINITIALIZED; +static int background_attribute = UNINITIALIZED; +static int normal_video = UNINITIALIZED; +static int reverse_video = UNINITIALIZED; static void -bios_initialize_variables (void) -/* - If valid environment variables exist, use values. Otherwise - queries BIOS for parameters. -*/ +bios_initialize_variables (int foreground, int background) { char* psTemp; - if (DISPLAY_COLUMNS == UNINITIALIZED) - DISPLAY_COLUMNS = tty_x_size-1; - - if (DISPLAY_ROWS == UNINITIALIZED) - DISPLAY_ROWS = tty_y_size-1; - - if (FOREGROUND_ATTRIBUTE == UNINITIALIZED) - { - psTemp = (getenv ("EDWIN_FOREGROUND")); - if (NULL == psTemp) - FOREGROUND_ATTRIBUTE = _0B(0,0,0,0,0,1,1,1); /* White */ - else - { - if (atoi(psTemp) == 0) - FOREGROUND_ATTRIBUTE = _0B(0,0,0,0,0,1,1,1); /* White */ - else - FOREGROUND_ATTRIBUTE = MAP(atoi(psTemp)); - } - } + if (display_columns == UNINITIALIZED) + display_columns = (tty_x_size - 1); - if (BACKGROUND_ATTRIBUTE == UNINITIALIZED) - { - psTemp = (getenv ("EDWIN_BACKGROUND")); - if (NULL == psTemp) - BACKGROUND_ATTRIBUTE = _0B(0,0,0,0,0,0,0,0) << 4; /* Black */ - else - { - if (atoi(psTemp) == 0) - BACKGROUND_ATTRIBUTE = _0B(0,0,0,0,0,0,0,0) << 4; /* Black */ - else - BACKGROUND_ATTRIBUTE = MAP(atoi(psTemp)) << 4; - } - } + if (display_rows == UNINITIALIZED) + display_rows = (tty_y_size - 1); - NORMAL_VIDEO = (FOREGROUND_ATTRIBUTE | BACKGROUND_ATTRIBUTE); - REVERSE_VIDEO = ((FOREGROUND_ATTRIBUTE << 4) | (BACKGROUND_ATTRIBUTE >> 4)); + foreground_attribute = (MAP (foreground)); + background_attribute = (MAP (background)); + normal_video = (foreground_attribute | background_attribute); + reverse_video = ((foreground_attribute << 4) | (background_attribute >> 4)); return; } + +static int +stdout_is_console_p (void) +{ + Tchannel output = (OS_tty_output_channel ()); + if ((OS_channel_type (output)) != channel_type_terminal) + return (0); + return (1); +} static void bios_uninitialize_variables (void) { - DISPLAY_COLUMNS = UNINITIALIZED; - DISPLAY_ROWS = UNINITIALIZED; - FOREGROUND_ATTRIBUTE = UNINITIALIZED; - BACKGROUND_ATTRIBUTE = UNINITIALIZED; - NORMAL_VIDEO = UNINITIALIZED; - REVERSE_VIDEO = UNINITIALIZED; + display_columns = UNINITIALIZED; + display_rows = UNINITIALIZED; + foreground_attribute = UNINITIALIZED; + background_attribute = UNINITIALIZED; + normal_video = UNINITIALIZED; + reverse_video = UNINITIALIZED; return; } @@ -275,7 +257,7 @@ bios__set_cursor_size (int iBlinkMode, int iTopScan, int iBottomScan) static void bios_clear_line (int iCol, int iRow, int iFirstUnusedX) { - bios__scroll_up_rectangle (NORMAL_VIDEO, 0, iCol, iRow, iFirstUnusedX, iRow); + bios__scroll_up_rectangle (normal_video, 0, iCol, iRow, iFirstUnusedX, iRow); return; } @@ -283,7 +265,7 @@ static void bios_clear_region (int iUpperLeftX, int iUpperLeftY, int iBottomRightX, int iBottomRightY) { - bios__scroll_up_rectangle (NORMAL_VIDEO, 0, + bios__scroll_up_rectangle (normal_video, 0, iUpperLeftX, iUpperLeftY, iBottomRightX, iBottomRightY); return; @@ -292,8 +274,8 @@ bios_clear_region (int iUpperLeftX, int iUpperLeftY, static void bios_clear_screen (void) { - bios__scroll_up_rectangle (NORMAL_VIDEO, 0x00, - 0, 0, DISPLAY_COLUMNS, DISPLAY_ROWS); + bios__scroll_up_rectangle (normal_video, 0x00, + 0, 0, display_columns, display_rows); return; } @@ -320,91 +302,125 @@ bios_write_string_attributed (char * pString, long lLength, int iColumn, ((RealModeBufferParagraph << 16) + 0)); return; } + +/* This does no argument checking. */ + +void +bios__set_text_size (int al, int bl) +{ + union REGS regs; + + regs.h.ah = 0x11; + regs.h.al = al; + regs.h.bl = bl; + int10h (®s, ®s); + return; +} -DEFINE_PRIMITIVE ("BIOS:BEEP", Prim_bios_beep, 0, 0, 0) +DEFINE_PRIMITIVE ("BIOS:CAN-USE-BIOS?", Prim_bios_p, 0, 0, + "#T if BIOS operations can be used, otherwise #F. ()") +{ + PRIMITIVE_HEADER (0); + PRIMITIVE_RETURN ((stdout_is_console_p ()) ? SHARP_T : SHARP_F); +} + +DEFINE_PRIMITIVE ("BIOS:BEEP", Prim_bios_beep, 0, 0, + "Produce a Beep [feep]. ()") { PRIMITIVE_HEADER (0); + if (!bios_initialized_p) + error_external_return (); bios__teletype_output_char ('\007', 0, 0x00); PRIMITIVE_RETURN (SHARP_T); } -DEFINE_PRIMITIVE ("BIOS:CLEAR-LINE!", Prim_bios_clear_line, 3, 3, 0) +DEFINE_PRIMITIVE ("BIOS:CLEAR-LINE!", Prim_bios_clear_line, 3, 3, + "Clear a line in the console. (column row first-unused)") { PRIMITIVE_HEADER (3); + if (!bios_initialized_p) + error_external_return (); bios_clear_line ((arg_integer (1)), (arg_integer (2)), (arg_integer (3))); PRIMITIVE_RETURN (SHARP_T); } -DEFINE_PRIMITIVE ("BIOS:CLEAR-RECTANGLE!", Prim_bios_clear_rectangle, 5, 5, 0) - /* xl xu yl yu highlight */ +DEFINE_PRIMITIVE ("BIOS:CLEAR-RECTANGLE!", Prim_bios_clear_rectangle, 5, 5, + "Clear a rectangle in the console. (xl xu yl yu hl)") { PRIMITIVE_HEADER (5); + if (!bios_initialized_p) + error_external_return (); bios_clear_region ((arg_integer (1)), (arg_integer (3)), (arg_integer (2)), (arg_integer (4))); PRIMITIVE_RETURN (SHARP_T); } -DEFINE_PRIMITIVE ("BIOS:CLEAR-SCREEN!", Prim_bios_clear_screen, 0, 0, 0) +DEFINE_PRIMITIVE ("BIOS:CLEAR-SCREEN!", Prim_bios_clear_screen, 0, 0, + "Clear the whole console. ()") { PRIMITIVE_HEADER (0); + if (!bios_initialized_p) + error_external_return (); bios_clear_screen (); PRIMITIVE_RETURN (SHARP_T); } -DEFINE_PRIMITIVE ("BIOS:DISCARD!", Prim_bios_discard, 0, 0, 0) +DEFINE_PRIMITIVE ("BIOS:INITIALIZE!", Prim_bios_enter, 2, 2, + "Initialize bios internal state. (foreground background)") { - PRIMITIVE_HEADER (0); - bios_uninitialize_variables (); - PRIMITIVE_RETURN (SHARP_T); -} - -DEFINE_PRIMITIVE ("BIOS:ENTER!", Prim_bios_enter, 0, 0, 0) -{ - PRIMITIVE_HEADER (0); - bios_initialize_variables (); + int foreground, background; + PRIMITIVE_HEADER (2); + if ((! (stdout_is_console_p ())) || bios_initialized_p) + error_external_return (); + bios_initialize_variables ((arg_integer (1)), (arg_integer (2))); bios_clear_screen (); - bios__set_cursor_position (0, 0, DISPLAY_ROWS); + bios__set_cursor_position (0, 0, display_rows); + bios_initialized_p = 1; PRIMITIVE_RETURN (SHARP_T); } -DEFINE_PRIMITIVE ("BIOS:EXIT!", Prim_bios_exit, 0, 0, 0) +DEFINE_PRIMITIVE ("BIOS:EXIT!", Prim_bios_exit, 0, 0, + "Clean up bios internal state. ()") { PRIMITIVE_HEADER (0); - bios__set_cursor_position (0, 0, DISPLAY_ROWS); + if (!bios_initialized_p) + error_external_return (); + bios__set_cursor_position (0, 0, display_rows); + bios_uninitialize_variables (); + bios_initialized_p = 0; PRIMITIVE_RETURN (SHARP_T); } -/* - flush!, modeline-event!, and discretionary-flush have no meaning - for BIOS output, no corresponding primitives have been defined. -*/ - -DEFINE_PRIMITIVE ("BIOS:SCROLL-LINES-DOWN!", Prim_bios_scroll_lines_down, - 5, 5, 0) - /* xl xu yl yu amount */ +DEFINE_PRIMITIVE ("BIOS:SCROLL-LINES-DOWN!", Prim_bios_scroll_lines_down, 5, 5, + "Scroll a console rectangle down. (xl xu yl yu delta)") { PRIMITIVE_HEADER (5); - bios__scroll_down_rectangle (NORMAL_VIDEO, (arg_integer (5)), + bios__scroll_down_rectangle (normal_video, (arg_integer (5)), (arg_integer (1)), (arg_integer (3)), (arg_integer (2)), (arg_integer (4))); PRIMITIVE_RETURN (SHARP_T); } -DEFINE_PRIMITIVE ("BIOS:SCROLL-LINES-UP!", Prim_bios_scroll_lines_up, 5, 5, 0) +DEFINE_PRIMITIVE ("BIOS:SCROLL-LINES-UP!", Prim_bios_scroll_lines_up, 5, 5, + "Scroll a console rectangle up. (xl xu yl yu delta)") { PRIMITIVE_HEADER (5); - bios__scroll_up_rectangle (NORMAL_VIDEO, (arg_integer (5)), + bios__scroll_up_rectangle (normal_video, (arg_integer (5)), (arg_integer (1)), (arg_integer (3)), (arg_integer (2)), (arg_integer (4))); PRIMITIVE_RETURN (SHARP_T); } -/* - console-wrap-update! has no meaning for BIOS output, no primitive defined. -*/ +DEFINE_PRIMITIVE ("BIOS:WRITE-CURSOR!", Prim_bios_write_cursor, 2, 2, + "Draw the cursor on the console. (x y)") +{ + PRIMITIVE_HEADER (2); + bios__set_cursor_position (0, (arg_integer (1)), (arg_integer (2))); + PRIMITIVE_RETURN (SHARP_T); +} -DEFINE_PRIMITIVE ("BIOS:WRITE-CHAR!", Prim_bios_write_char, 2, 2, 0) - /* char highlight */ +DEFINE_PRIMITIVE ("BIOS:WRITE-CHAR!", Prim_bios_write_char, 2, 2, + "Write a character on the console. (char highlight)") { PRIMITIVE_HEADER (2); if (BOOLEAN_ARG (2)) @@ -412,62 +428,71 @@ DEFINE_PRIMITIVE ("BIOS:WRITE-CHAR!", Prim_bios_write_char, 2, 2, 0) int x, y; bios_get_cursor_position (&x, &y); - bios__scroll_up_rectangle (REVERSE_VIDEO, 1, x, y, x, y); + bios__scroll_up_rectangle (reverse_video, 1, x, y, x, y); bios__teletype_output_char ((arg_ascii_char (1)), 0, 0); } else bios__teletype_output_char ((arg_ascii_char (1)), 0, 0); PRIMITIVE_RETURN (SHARP_T); } - -DEFINE_PRIMITIVE ("BIOS:WRITE-CURSOR!", Prim_bios_write_cursor, 2, 2, 0) -{ - PRIMITIVE_HEADER (2); - bios__set_cursor_position (0, (arg_integer (1)), (arg_integer (2))); - PRIMITIVE_RETURN (SHARP_T); -} -DEFINE_PRIMITIVE ("BIOS:WRITE-SUBSTRING!", Prim_bios_write_substring, 4, 4, 0) - /* string start end highlight */ +DEFINE_PRIMITIVE ("BIOS:WRITE-SUBSTRING!", Prim_bios_write_substring, 4, 4, + "Write a string on the console. (str start end highlight)") { int x, y; long start, end; PRIMITIVE_HEADER (4); - start = (arg_integer (2)); end = (arg_integer (3)); if (start > end) PRIMITIVE_RETURN (SHARP_F); - bios_get_cursor_position (&x, &y); - bios_write_string_attributed (((STRING_ARG(1)) + start), (end - start), + bios_write_string_attributed (((STRING_ARG (1)) + start), (end - start), x, y, ((BOOLEAN_ARG (4)) - ? REVERSE_VIDEO - : NORMAL_VIDEO)); - + ? reverse_video + : normal_video)); PRIMITIVE_RETURN (SHARP_T); } -DEFINE_PRIMITIVE ("BIOS:SET-VIDEO-MODE!", Prim_bios_set_video_mode, 1, 1, 0) +DEFINE_PRIMITIVE ("BIOS:SET-VIDEO-MODE!", Prim_bios_set_video_mode, 1, 1, + "Set the video display mode for the console. (mode)") { - extern void pc_gestalt_screen_x_size (void); - extern void pc_gestalt_screen_y_size (void); PRIMITIVE_HEADER (1); - - bios__set_video_mode (arg_integer(1)); + if ((! (stdout_is_console_p ())) || bios_initialized_p) + error_external_return (); + bios__set_video_mode (arg_integer (1)); pc_gestalt_screen_x_size (); pc_gestalt_screen_y_size (); - bios_initialize_variables (); bios_clear_screen (); - bios__set_cursor_position (0, 0, DISPLAY_ROWS); + bios__set_cursor_position (0, 0, display_rows); PRIMITIVE_RETURN (SHARP_T); } -DEFINE_PRIMITIVE ("BIOS:SET-CURSOR-SIZE!", Prim_bios_set_cursor_size, 3, 3, 0) +DEFINE_PRIMITIVE ("BIOS:SET-CURSOR-SIZE!", Prim_bios_set_cursor_size, 3, 3, + "Set the cursor's shape and size. (blinkmode top bottom)") + /* blinkmode: 0 = normal, 1 = invisible, 2 = erratic, 3 = slow */ { PRIMITIVE_HEADER (3); - bios__set_cursor_size ((arg_integer (1)), (arg_integer (2)), + if (! (stdout_is_console_p ())) + error_external_return (); + bios__set_cursor_size ((arg_integer (1)), + (arg_integer (2)), (arg_integer (3))); PRIMITIVE_RETURN (SHARP_T); } + +DEFINE_PRIMITIVE ("BIOS:SET-TEXT-SIZE!", Prim_bios_set_text_size, 2, 2, + "Diddle the character generator's blocks. (al bl)") +{ + int al, bl; + PRIMITIVE_HEADER (2); + if ((! (stdout_is_console_p ())) || bios_initialized_p) + error_external_return (); + al = (arg_integer_in_range (1, 0x0, 0x20)); + bl = (arg_integer (2)); + if (((al & 0x8) != 0) || ((al & 0x7) == 0) || ((al & 0x7) > 4)) + error_bad_range_arg (1); + bios__set_text_size (al, bl); + PRIMITIVE_RETURN (SHARP_T); +} diff --git a/v7/src/microcode/dosint10.h b/v7/src/microcode/dosint10.h index 727f37e73..ebc199bc6 100644 --- a/v7/src/microcode/dosint10.h +++ b/v7/src/microcode/dosint10.h @@ -1,6 +1,6 @@ /* -*-C-*- -$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/Attic/dosint10.h,v 1.1 1992/07/28 18:16:42 jinx Exp $ +$Id: dosint10.h,v 1.2 1992/10/17 22:22:32 jinx Exp $ Copyright (c) 1992 Massachusetts Institute of Technology @@ -39,37 +39,42 @@ MIT in each case. */ #define _0B(b7,b6,b5,b4,b3,b2,b1,b0) ((b7<<7)|(b6<<6)|(b5<<5)|(b4<<4)|(b3<<3)|(b2<<2)|(b1<<1)|(b0)) #define UNINITIALIZED -1 -int map_ansi_sys_color_to_bios_attribute(int iANSIcode); +int map_ansi_sys_color_to_bios_attribute (int iANSIcode); -void bios_initialize_variables(void); -void bios_uninitialize_variables(void); +void bios_initialize_variables (int, int); +void bios_uninitialize_variables (void); -void bios__scroll_up_rectangle(int iBlankAttribute, int iLines, +void bios__scroll_up_rectangle (int iBlankAttribute, int iLines, int iUpperLeftX, int iUpperLeftY, int iBottomRightX, int iBottomRightY); -void bios__scroll_down_rectangle(int iBlankAttribute, int iLines, +void bios__scroll_down_rectangle (int iBlankAttribute, int iLines, int iUpperLeftX, int iUpperLeftY, int iBottomRightX, int iBottomRightY); -void bios__set_cursor_position(int iPageNumber, int iColumn, int iRow); -void bios__write_char_with_attribute(char cChar, int iPageNumber, +void bios__set_cursor_position (int iPageNumber, int iColumn, int iRow); +void bios__write_char_with_attribute (char cChar, int iPageNumber, int iAttribute, int iRepeatCount); -void bios__teletype_output_char(char cChar, int iPageNumber, +void bios__teletype_output_char (char cChar, int iPageNumber, int iGraphicsModeForegroundColor); -void bios__set_video_mode(int iModeNumber); -void bios__set_cursor_size(int iBlinkMode, int iTopScan, int iBottomScan); +void bios__set_video_mode (int iModeNumber); +void bios__set_cursor_size (int iBlinkMode, int iTopScan, int iBottomScan); -void bios_clear_line(int iCol, int iRow, int iFirstUnusedX); -void bios_clear_region(int iUpperLeftX, int iUpperLeftY, +void bios_clear_line (int iCol, int iRow, int iFirstUnusedX); +void bios_clear_region (int iUpperLeftX, int iUpperLeftY, int iBottomRightX, int iBottomRightY); -void bios_clear_screen(void); -void bios_get_cursor_position(int *x, int *y); -void bios_write_string_attributed(char *pString, long lLength, int iColumn, +void bios_clear_screen (void); +void bios_get_cursor_position (int *x, int *y); +void bios_write_string_attributed (char *pString, long lLength, int iColumn, int iRow, int iSingleAttribute); -void asm_bios__write_string_attr(unsigned long lAttributeMode, +extern void asm_bios__write_string_attr (unsigned long lAttributeMode, unsigned long lPageNumber, unsigned long lSingleAttribute, unsigned long lCharCount, unsigned long lColumn, unsigned long lRow, unsigned long pString); extern int tty_x_size; extern int tty_y_size; +extern unsigned long RealModeBufferParagraph; +extern char * pRealModeBuffer; +extern void pc_gestalt_screen_x_size (void); +extern void pc_gestalt_screen_y_size (void); +