slvideo.c
字号:
if (Current_Color) SLtt_normal_video (); os2_video_getxy (); /* get current position */ switch (ch) { case 7: /* ^G - break */ SLtt_beep (); break; case 8: /* ^H - backspace */ goto_rc_abs (Cursor_Row, Cursor_Col - 1); break; case 13: /* ^M - carriage return */ goto_rc_abs (Cursor_Row, 0); break; default: /* write character to screen */ VioWrtCharStrAtt (&ch, 1, Cursor_Row, Cursor_Col, (BYTE*)&Attribute_Byte, 0); goto_rc_abs (Cursor_Row, Cursor_Col + 1); }}void SLtt_get_screen_size (void){#ifdef __os2__# ifdef __IBMC__ VIOMODEINFO vioModeInfo;# endif vioModeInfo.cb = sizeof(vioModeInfo); VioGetMode (&vioModeInfo, 0); SLtt_Screen_Cols = vioModeInfo.col; SLtt_Screen_Rows = vioModeInfo.row;#endif}void SLtt_get_terminfo (void){ SLtt_get_screen_size ();}int SLtt_init_video (void){ VIOINTENSITY RequestBlock; PTIB ptib; PPIB ppib; USHORT args[3] = { 6, 2, 1 }; Cursor_Row = Cursor_Col = 0; IsColor = 1; /* is it really? */ /* Enable high-intensity background colors */ RequestBlock.cb = sizeof (RequestBlock); RequestBlock.type = 2; RequestBlock.fs = 1; VioSetState (&RequestBlock, 0); /* nop if !fullscreen */ DosGetInfoBlocks (&ptib, &ppib); if ((ppib->pib_ultype) == 2) /* VIO */ Blink_Killed = 1; else { /* Fullscreen */ if (VioSetState (args, 0) == 0) Blink_Killed = 1; else Blink_Killed = 0; } if (!Attribute_Byte) { /* find the attribute currently under the cursor */ USHORT len, r, c; len = 2; VioGetCurPos (&r, &c, 0); VioReadCellStr ((PCH)Line_Buffer, &len, r, c, 0); Attribute_Byte = Line_Buffer[1]; SLtt_set_color (JNORMAL_COLOR, NULL, Color_Names[(Attribute_Byte) & 0xf], Color_Names[(Attribute_Byte) >> 4]); } SLtt_Use_Ansi_Colors = IsColor; SLtt_get_screen_size (); SLtt_reset_scroll_region (); fixup_colors (); return 0;}#endif /* OS2_VIDEO *//*}}}*/#ifdef WATCOM_VIDEO /*{{{*/# include <graph.h># define int86 int386 /* simplify code writing */#include <dos.h>/* this is how to make a space character */#define MK_SPACE_CHAR() (((Attribute_Byte) << 8) | 0x20)/* buffer to hold a line of character/attribute pairs */#define MAXCOLS 256static unsigned char Line_Buffer [MAXCOLS*2];/* define for direct to memory screen writes */static unsigned char *Video_Base;#define MK_SCREEN_POINTER(row,col) \ ((unsigned short *)(Video_Base + 2 * (SLtt_Screen_Cols * (row) + (col))))#define ScreenPrimary (0xb800 << 4)#define ScreenSize (SLtt_Screen_Cols * SLtt_Screen_Rows)#define ScreenSetCursor(x,y) _settextposition (x+1,y+1)void ScreenGetCursor (int *x, int *y){ struct rccoord rc = _gettextposition (); *x = rc.row - 1; *y = rc.col - 1;}void ScreenRetrieve (unsigned char *dest){ memcpy (dest, (unsigned char *) ScreenPrimary, 2 * ScreenSize);}void ScreenUpdate (unsigned char *src){ memcpy ((unsigned char *) ScreenPrimary, src, 2 * ScreenSize);}void SLtt_write_string (char *str){ /* FIXME: Priority=medium * This should not go to stdout. */ fputs (str, stdout);}void SLtt_goto_rc (int row, int col){ row += Scroll_r1; if (row > SLtt_Screen_Rows) row = SLtt_Screen_Rows; if (col > SLtt_Screen_Cols) col = SLtt_Screen_Cols; ScreenSetCursor(row, col); Cursor_Row = row; Cursor_Col = col;}static void watcom_video_getxy (void){ ScreenGetCursor (&Cursor_Row, &Cursor_Col);}void SLtt_begin_insert (void){ unsigned short *p; unsigned short *pmin; int n; watcom_video_getxy (); n = SLtt_Screen_Cols - Cursor_Col; p = MK_SCREEN_POINTER (Cursor_Row, SLtt_Screen_Cols - 1); pmin = MK_SCREEN_POINTER (Cursor_Row, Cursor_Col); while (p-- > pmin) *(p + 1) = *p;}void SLtt_end_insert (void){}void SLtt_delete_char (void){ unsigned short *p; register unsigned short *p1; int n; watcom_video_getxy (); n = SLtt_Screen_Cols - Cursor_Col - 1; p = MK_SCREEN_POINTER (Cursor_Row, Cursor_Col); while (n--) { p1 = p + 1; *p = *p1; p++; }}void SLtt_erase_line (void){ unsigned short w; unsigned short *p = MK_SCREEN_POINTER (Cursor_Row, 0); register unsigned short *pmax = p + SLtt_Screen_Cols; Attribute_Byte = 0x07; w = MK_SPACE_CHAR (); while (p < pmax) *p++ = w; Current_Color = JNO_COLOR; /* since we messed with attribute byte */}void SLtt_delete_nlines (int nlines){ union REGS r; SLtt_normal_video (); r.x.eax = nlines; r.x.ecx = 0; r.h.ah = 6; r.h.ch = Scroll_r1; r.h.dl = SLtt_Screen_Cols - 1; r.h.dh = Scroll_r2; r.h.bh = Attribute_Byte; int86 (0x10, &r, &r);}void SLtt_reverse_index (int nlines){ union REGS r; SLtt_normal_video (); r.h.al = nlines; r.x.ecx = 0; r.h.ah = 7; r.h.ch = Scroll_r1; r.h.dl = SLtt_Screen_Cols - 1; r.h.dh = Scroll_r2; r.h.bh = Attribute_Byte; int86 (0x10, &r, &r);}static void watcom_video_invert_region (int top_row, int bot_row){ unsigned char buf [2 * 180 * 80]; /* 180 cols x 80 rows */ unsigned char *b, *bmax; b = buf + 1 + 2 * SLtt_Screen_Cols * top_row; bmax = buf + 1 + 2 * SLtt_Screen_Cols * bot_row; ScreenRetrieve (buf); while (b < bmax) { *b ^= 0xFF; b += 2; } ScreenUpdate (buf);}void SLtt_beep (void){ int audible; /* audible bell */ int special = 0; /* first row to invert */ int visual = 0; /* final row to invert */ if (!SLtt_Ignore_Beep) return; audible = (SLtt_Ignore_Beep & 1); if ( (SLtt_Ignore_Beep & 4) ) { special = SLtt_Screen_Rows - 1; visual = special--; /* only invert bottom status line */ } else if ( (SLtt_Ignore_Beep & 2) ) { visual = SLtt_Screen_Rows; } if (visual) watcom_video_invert_region (special, visual); if (audible) sound (1500); delay (100); if (audible) nosound (); if (visual) watcom_video_invert_region (special, visual);}void SLtt_del_eol (void){ unsigned short *p, *pmax; unsigned short w; int n; n = SLtt_Screen_Cols - Cursor_Col; p = MK_SCREEN_POINTER (Cursor_Row, Cursor_Col); pmax = p + n; if (Current_Color != JNO_COLOR) SLtt_normal_video (); w = MK_SPACE_CHAR (); while (p < pmax) *p++ = w;}static voidwrite_attributes (SLsmg_Char_Type *src, unsigned int count){ register unsigned short pair; register unsigned short *pos = MK_SCREEN_POINTER (Cursor_Row, 0); /* write into a character/attribute pair */ while (count--) { pair = SLSMG_CHAR_TO_USHORT(*src);/* character/color pair */ src++; SLtt_reverse_video (pair >> 8); /* color change */ *(pos++) = ((unsigned short) Attribute_Byte << 8) | (pair & 0xff); }}void SLtt_cls (void){ SLtt_normal_video (); SLtt_reset_scroll_region (); SLtt_goto_rc (0, 0); SLtt_delete_nlines (SLtt_Screen_Rows);}void SLtt_putchar (char ch){ unsigned short p, *pp; if (Current_Color) SLtt_normal_video (); watcom_video_getxy (); switch (ch) { case 7: /* ^G - break */ SLtt_beep (); break; case 8: /* ^H - backspace */ goto_rc_abs (Cursor_Row, Cursor_Col - 1); break; case 13: /* ^M - carriage return */ goto_rc_abs (Cursor_Row, 0); break; default: /* write character to screen */ p = (Attribute_Byte << 8) | (unsigned char) ch; pp = MK_SCREEN_POINTER (Cursor_Row, Cursor_Col); *pp = p; goto_rc_abs (Cursor_Row, Cursor_Col + 1); }}void SLtt_get_screen_size (void){ struct videoconfig vc; _getvideoconfig(&vc); SLtt_Screen_Rows = vc.numtextrows; SLtt_Screen_Cols = vc.numtextcols;}void SLtt_get_terminfo (void){ SLtt_get_screen_size ();}int SLtt_init_video (void){#ifdef HAS_SAVE_SCREEN save_screen ();#endif Cursor_Row = Cursor_Col = 0; Video_Base = (unsigned char *) ScreenPrimary; if (!Attribute_Byte) Attribute_Byte = 0x17; IsColor = 1; /* is it really? */ if (IsColor) { union REGS r; r.x.eax = 0x1003; r.x.ebx = 0; int86 (0x10, &r, &r); Blink_Killed = 1; } SLtt_Use_Ansi_Colors = IsColor; SLtt_get_screen_size (); SLtt_reset_scroll_region (); fixup_colors (); return 0;}#endif /* WATCOM_VIDEO *//*}}}*//* -------------------------------------------------------------------------*\ * The rest of the functions are, for the most part, independent of a specific * video system.\* ------------------------------------------------------------------------ *//*----------------------------------------------------------------------*\ * Function: void SLtt_set_scroll_region (int r1, int r2); * * define a scroll region of top_row to bottom_row\*----------------------------------------------------------------------*/void SLtt_set_scroll_region (int top_row, int bottom_row){ Scroll_r1 = top_row; Scroll_r2 = bottom_row;}/*----------------------------------------------------------------------*\ * Function: void SLtt_reset_scroll_region (void); * * reset the scrol region to be the entire screen, * ie, SLtt_set_scroll_region (0, SLtt_Screen_Rows);\*----------------------------------------------------------------------*/void SLtt_reset_scroll_region (void){ Scroll_r1 = 0; Scroll_r2 = SLtt_Screen_Rows - 1;}/*----------------------------------------------------------------------*\ * Function: int SLtt_flush_output (void);\*----------------------------------------------------------------------*/int SLtt_flush_output (void){#if defined(WIN32_VIDEO) return 0;#else /* FIXME: Priority=medium * This should not go to stdout. */ fflush (stdout); return 0;#endif}int SLtt_set_cursor_visibility (int show){#if defined(WIN32_VIDEO) CONSOLE_CURSOR_INFO c; if (0 == GetConsoleCursorInfo (hStdout, &c)) return -1; c.bVisible = (show ? TRUE: FALSE); if (0 == SetConsoleCursorInfo (hStdout, &c)) return -1; return 0;#else (void) show; return -1;#endif}/*----------------------------------------------------------------------*\ * Function: void SLtt_reverse_video (int color); * * set Attribute_Byte corresponding to COLOR. * Use Current_Color to remember the color which was set. * convert from the COLOR number to the attribute value.\*----------------------------------------------------------------------*/void SLtt_reverse_video (int color){ if ((color >= JMAX_COLORS) || (color < 0)) return; Attribute_Byte = Color_Map [color]; Current_Color = color;}/*----------------------------------------------------------------------*\ * Function: void SLtt_normal_video (void); * * reset the attributes for normal video\*----------------------------------------------------------------------*/void SLtt_normal_video (void){ SLtt_reverse_video (JNORMAL_COLOR);}/*----------------------------------------------------------------------*\ * Function: void SLtt_smart_puts (SLsmg_Char_Type *new_string, * SLsmg_Char_Type *old_string, * int len, int row); * * puts NEW_STRING, which has length LEN, at row ROW. NEW_STRING contains * characters/colors packed in the form value = ((color << 8) | (ch)); * * the puts tries to avoid overwriting the same characters/colors * * OLD_STRING is not used, maintained for compatibility with other systems\*----------------------------------------------------------------------*/void SLtt_smart_puts (SLsmg_Char_Type *new_string, SLsmg_Char_Type *old_string, int len, int row){ (void) old_string; Cursor_Row = row; Cursor_Col = 0; write_attributes (new_string, len);}/*----------------------------------------------------------------------*\ * Function: int SLtt_reset_video (void);\*----------------------------------------------------------------------*/#ifndef WIN32_VIDEOint SLtt_reset_video (void){ SLtt_reset_scroll_region (); SLtt_goto_rc (SLtt_Screen_Rows - 1, 0);#ifdef HAS_SAVE_SCREEN restore_screen ();#endif Attribute_Byte = 0x07; Current_Color = JNO_COLOR; SLtt_del_eol (); return 0;}#endif/*----------------------------------------------------------------------*\ * Function: void SLtt_set_color (int obj, char *what, char *fg, char *bg); * * set foreground and background colors of OBJ to the attributes which * correspond to the names FG and BG, respectively. * * WHAT is the name corresponding to the object OBJ, but is not used in * this routine.\*----------------------------------------------------------------------*/void SLtt_set_color (int obj, char *what, char *fg, char *bg){ int i, b = 0, f = 7; (void) what; if ((obj < 0) || (obj >= JMAX_COLORS)) return; for (i = 0; i < JMAX_COLOR_NAMES; i++ ) { if (!strcmp (fg, Color_Names [i])) { f = i; break; } } for (i = 0; i < JMAX_COLOR_NAMES; i++) { if (!strcmp (bg, Color_Names [i])) { if (Blink_Killed) b = i; else b = i & 0x7; break; } } if (f == b) return; Color_Map [obj] = (b << 4) | f; /* if we're setting the normal color, and the attribute byte hasn't been set yet, set it to the new color */ if ((obj == 0) && (Attribute_Byte == 0)) SLtt_reverse_video (0); if (_SLtt_color_changed_hook != NULL) (*_SLtt_color_changed_hook)();}static void fixup_colors (void){ unsigned int i; if (Blink_Killed) return; for (i = 0; i < JMAX_COLORS; i++) Color_Map[i] &= 0x7F; SLtt_normal_video ();}/* FIXME!!! Add mono support. * The following functions have not been fully implemented. */void SLtt_set_mono (int obj_unused, char *unused, SLtt_Char_Type c_unused){ (void) obj_unused; (void) unused; (void) c_unused;}#if 0void SLtt_add_color_attribute (int obj, SLtt_Char_Type attr){ (void) obj; (void) attr;}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -