📄 slvideo.c
字号:
src = (unsigned short*)org_src; /* restart the src pointer */
/* write into attributes only */
while (n-- > 0)
{
pair = *(src++); /* character/color pair */
SLtt_reverse_video (pair >> 8); /* color change */
*(p++) = Attribute_Byte; /* attribute byte */
*(p++) = 0; /* what's this for? */
}
WriteConsoleOutputAttribute(hStdout, (WORD*)Line_Buffer, count, coord, &bytes);
# else /* __os2__ */
/* ScreenUpdateLine (void *virtual_screen_line, int row); */
p = Line_Buffer;
n = Cursor_Col;
while (count-- > 0)
{
ScreenPutChar ((int)p[0], (int)p[1], n++, Cursor_Row);
p += 2;
}
# endif /* EMX_VIDEO */
# endif /* __os2__ */
# endif /* HAS_LINEAR_SCREEN */
#else /* not USE_ASM */
unsigned char ch, color;
register unsigned short *pos = mkScreenPointer (Cursor_Row, 0);
while (count--)
{
pair = *(src++); /* character/color pair */
ch = pair & 0xff; /* character value */
color = pair >> 8; /* color value */
if (color != Current_Color) /* need a new color */
{
if (p != Line_Buffer)
{
pos = video_write (Line_Buffer, p, pos);
p = Line_Buffer;
}
SLtt_reverse_video (color); /* change color */
}
*(p++) = ch;
}
pos = video_write (Line_Buffer, p, pos);
#endif /* not USE_ASM */
}
/*----------------------------------------------------------------------*\
* Function: void SLtt_smart_puts (unsigned short *new_string,
* unsigned short *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 (unsigned short *new_string,
unsigned short *old_string,
int len, int row)
{
(void) old_string;
Cursor_Row = row;
Cursor_Col = 0;
write_attributes (new_string, len);
}
/*----------------------------------------------------------------------*\
* Function: void SLtt_reset_video (void);
\*----------------------------------------------------------------------*/
void SLtt_reset_video (void)
{
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 ();
}
#if 0
void wide_width (void)
{
}
void narrow_width (void)
{
}
#endif
/*----------------------------------------------------------------------*\
* Function: void SLtt_cls (void);
\*----------------------------------------------------------------------*/
void SLtt_cls (void)
{
#ifdef WIN32
DWORD bytes;
COORD coord;
char ch;
#endif
SLtt_normal_video ();
#if defined (__GO32__) || defined (__WATCOMC__) || defined (EMX_VIDEO)
SLtt_reset_scroll_region ();
SLtt_goto_rc (0, 0);
SLtt_delete_nlines (SLtt_Screen_Rows);
#else /* __GO32__ or __WATCOMC__ or EMX_VIDEO */
# ifdef __os2__
{
Line_Buffer [0] = ' '; Line_Buffer [1] = Attribute_Byte;
VioScrollUp (0, 0, -1, -1, -1, (PCH)Line_Buffer, 0);
}
# elif defined(WIN32)
/* clear the WIN32 screen in one shot */
coord.X = 0;
coord.Y = 0;
ch = ' ';
(void) FillConsoleOutputCharacter(hStdout,
ch,
csbiInfo.dwMaximumWindowSize.Y * csbiInfo.dwMaximumWindowSize.X,
coord,
&bytes);
/* now set screen to the current attribute */
ch = Attribute_Byte;
(void) FillConsoleOutputAttribute(hStdout,
ch,
csbiInfo.dwMaximumWindowSize.Y * csbiInfo.dwMaximumWindowSize.X,
coord,
&bytes);
# else /* __os2__ */
asm mov dx, SLtt_Screen_Cols
asm dec dx
asm mov ax, SLtt_Screen_Rows
asm dec ax
asm mov dh, al
asm xor cx, cx
asm xor ax, ax
asm mov ah, 7
asm mov bh, byte ptr Attribute_Byte
asm int 10h
# endif /* __os2__ */
#endif /* __GO32__ or __WATCOMC__ or EMX_VIDEO */
}
/*----------------------------------------------------------------------*\
* Function: void SLtt_putchar (char ch);
*
* put CH on the screen in the current position.
* this function is called assuming that cursor is in correct position
\*----------------------------------------------------------------------*/
void SLtt_putchar (char ch)
{
#if !defined (GO32_VIDEO) && !defined (EMX_VIDEO)
unsigned short p, *pp;
# if defined(WIN32)
DWORD bytes;
# endif
#endif
if (Current_Color) SLtt_normal_video ();
slvid_getxy (); /* get current position */
switch (ch)
{
case 7: /* ^G - break */
SLtt_beep (); break;
case 8: /* ^H - backspace */
SLtt_goto_rc (Cursor_Row, Cursor_Col - 1); break;
case 13: /* ^M - carriage return */
SLtt_goto_rc (Cursor_Row, 0); break;
default: /* write character to screen */
#if defined (EMX_VIDEO)
v_putn (ch, 1);
#else /* EMX_VIDEO */
# ifdef __os2__
VioWrtCharStrAtt (&ch, 1, Cursor_Row, Cursor_Col,
(BYTE*)&Attribute_Byte, 0);
# elif defined(WIN32)
WriteConsole(hStdout, &ch, 1, &bytes, NULL);
# else /* __os2__ */
# ifdef GO32_VIDEO
ScreenPutChar ((int) ch, Attribute_Byte, Cursor_Col, Cursor_Row);
# else /* GO32_VIDEO */
pp = mkScreenPointer (Cursor_Row, Cursor_Col);
p = (Attribute_Byte << 8) | (unsigned char) ch;
*pp = p;
# ifdef USE_ASM
SNOW_CHECK;
# endif
# endif /* GO32_VIDEO */
# endif /* __os2__ */
#endif /* EMX_VIDEO */
SLtt_goto_rc (Cursor_Row, Cursor_Col + 1);
}
}
/*----------------------------------------------------------------------*\
* 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 = -1, f = -1;
#ifdef WIN32
int newcolor;
#endif
(void) what;
if ( !IsColor || (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 == -1) || (b == -1) || (f == b)) return;
#if 1
Color_Map [obj] = (b << 4) | f;
#else
/*
0 1 2 3
"black", "blue", "green", "cyan",
4 5 6 7
"red", "magenta", "brown", "lightgray",
8 9 10 11
"gray", "brightblue", "brightgreen", "brightcyan",
12 13 14 15
"brightred", "brightmagenta", "yellow", "white"
*/
/* these aren't all right yet */
switch (f)
{
case 0: newcolor = 0; break;
case 1: newcolor = FOREGROUND_BLUE; break;
case 2: newcolor = FOREGROUND_GREEN; break;
case 3: newcolor = FOREGROUND_GREEN | FOREGROUND_BLUE; break;
case 4: newcolor = FOREGROUND_RED; break;
case 5: newcolor = FOREGROUND_RED | FOREGROUND_BLUE; break;
case 6: newcolor = FOREGROUND_GREEN | FOREGROUND_RED; break;
case 7: newcolor = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY; break;
case 8: newcolor = FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_GREEN; break;
case 9: newcolor = FOREGROUND_BLUE | FOREGROUND_INTENSITY; break;
case 10: newcolor = FOREGROUND_GREEN | FOREGROUND_INTENSITY; break;
case 11: newcolor = FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY; break;
case 12: newcolor = FOREGROUND_RED | FOREGROUND_INTENSITY; break;
case 13: newcolor = FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY; break;
case 14: newcolor = FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY; break;
case 15: newcolor = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY; break;
}
// switch
/*
0 1 2 3
"black", "blue", "green", "cyan",
4 5 6 7
"red", "magenta", "brown", "lightgray",
8 9 10 11
"gray", "brightblue", "brightgreen", "brightcyan",
12 13 14 15
"brightred", "brightmagenta", "yellow", "white"
*/
switch (b)
{
case 0: newcolor |= 0; break;
case 1: newcolor |= BACKGROUND_BLUE; break;
case 2: newcolor |= BACKGROUND_GREEN; break;
case 3: newcolor |= BACKGROUND_GREEN | BACKGROUND_BLUE; break;
case 4: newcolor |= BACKGROUND_RED; break;
case 5: newcolor |= BACKGROUND_RED | BACKGROUND_BLUE; break;
case 6: newcolor |= BACKGROUND_GREEN | BACKGROUND_RED; break;
case 7: newcolor |= BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | BACKGROUND_INTENSITY; break;
case 8: newcolor |= BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE; break;
case 9: newcolor |= BACKGROUND_BLUE | BACKGROUND_INTENSITY; break;
case 10: newcolor |= BACKGROUND_GREEN | BACKGROUND_INTENSITY; break;
case 11: newcolor |= BACKGROUND_GREEN | BACKGROUND_BLUE | BACKGROUND_INTENSITY; break;
case 12: newcolor |= BACKGROUND_RED | BACKGROUND_INTENSITY; break;
case 13: newcolor |= BACKGROUND_RED | BACKGROUND_BLUE | BACKGROUND_INTENSITY; break;
case 14: newcolor |= BACKGROUND_GREEN | BACKGROUND_BLUE | BACKGROUND_INTENSITY; break;
case 15: newcolor |= BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | BACKGROUND_INTENSITY; break;
}
// switch
Color_Map [obj] = newcolor;
#endif
/* 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);
}
/*----------------------------------------------------------------------*\
* Function: void SLtt_get_terminfo (void)
\*----------------------------------------------------------------------*/
void SLtt_get_terminfo (void)
{
#ifdef WIN32
SLtt_Screen_Rows = csbiInfo.dwMaximumWindowSize.Y;
SLtt_Screen_Cols = csbiInfo.dwMaximumWindowSize.X;
#endif
#ifdef GO32_VIDEO
SLtt_Screen_Rows = ScreenRows ();
SLtt_Screen_Cols = ScreenCols ();
#endif
}
/*----------------------------------------------------------------------*\
* Function: void SLtt_init_video (void);
\*----------------------------------------------------------------------*/
void SLtt_init_video (void)
{
#if defined (EMX_VIDEO)
int OldCol, OldRow;
#endif
#ifdef HAS_SAVE_SCREEN
save_screen ();
#endif
Cursor_Row = Cursor_Col = 0;
#if defined (EMX_VIDEO)
v_init ();
if ( v_hardware () != V_MONOCHROME ) IsColor = 1; else IsColor = 0;
v_getxy(&OldCol,&OldRow);
v_gotoxy (0, 0);
if (IsColor)
{
if (_osmode == OS2_MODE)
{
# if 0
/* Enable high-intensity background colors */
VIOINTENSITY RequestBlock;
RequestBlock.cb = sizeof (RequestBlock);
RequestBlock.type = 2; RequestBlock.fs = 1;
VioSetState (&RequestBlock, 0); /* nop if !fullscreen */
# endif
Blink_Killed = 1;
}
else
{
Blink_Killed = 1; /* seems to work */
}
}
if (!Attribute_Byte)
{
/* find the attribute currently under the cursor */
v_getline (Line_Buffer, OldCol, OldRow, 1);
Attribute_Byte = Line_Buffer[1];
set_color_from_attribute (Attribute_Byte);
}
v_attrib (Attribute_Byte);
/* SLtt_Term_Cannot_Insert = 1; */
#else /* EMX_VIDEO */
# ifdef __os2__
IsColor = 1; /* is it really? */
{
/* Enable high-intensity background colors */
VIOINTENSITY RequestBlock;
RequestBlock.cb = sizeof (RequestBlock);
RequestBlock.type = 2; RequestBlock.fs = 1;
VioSetState (&RequestBlock, 0); /* nop if !fullscreen */
Blink_Killed = 1;
}
if (!Attribute_Byte)
{
/* find the attribute currently under the cursor */
USHORT Length = 2, Row, Col;
VioGetCurPos (&Row, &Col, 0);
VioReadCellStr ((PCH)Line_Buffer, &Length, Row, Col, 0);
Attribute_Byte = Line_Buffer[1];
set_color_from_attribute (Attribute_Byte);
}
# elif defined(WIN32)
/* initialize the WIN32 console */
IsColor = 1; /* yes, the WIN32 console can do color (on a color monitor) */
# else
# if defined (__GO32__) || defined (__WATCOMC__)
# ifdef GO32_VIDEO
SLtt_Term_Cannot_Insert = 1;
# else
Video_Base = (unsigned char *) ScreenPrimary;
# endif
if (!Attribute_Byte) Attribute_Byte = 0x17;
IsColor = 1; /* is it really? */
if (IsColor)
{
union REGS r;
# ifdef __WATCOMC__
r.x.eax = 0x1003; r.x.ebx = 0;
# else
r.x.ax = 0x1003; r.x.bx = 0;
# endif
int86 (0x10, &r, &r);
Blink_Killed = 1;
}
# else /* (__GO32__ or __WATCOMC__ */
{
unsigned char *p = (unsigned char far *) 0x00400049L;
if (*p == 7)
{
Video_Status_Port = MONO_STATUS;
Video_Base = (unsigned char *) MK_FP (0xb000,0000);
IsColor = 0;
}
else
{
Video_Status_Port = CGA_STATUS;
Video_Base = (unsigned char *) MK_FP (0xb800,0000);
IsColor = 1;
}
}
/* test for video adapter type. Of primary interest is whether there is
* snow or not. Assume snow if the card is color and not EGA or greater.
*/
/* Use Ralf Brown test for EGA or greater */
asm mov ah, 0x12
asm mov bl, 0x10
asm mov bh, 0xFF
asm int 10h
asm cmp bh, 0xFF
asm je L1
/* (V)EGA */
asm xor bx, bx
asm mov SLtt_Msdos_Cheap_Video, bx
asm mov ax, Attribute_Byte
asm cmp ax, bx
asm jne L2
asm mov ax, 0x17
asm mov Attribute_Byte, ax
asm jmp L2
L1:
/* Not (V)EGA */
asm mov ah, 0x0F
asm int 10h
asm cmp al, 7
asm je L3
asm mov ax, 1
asm mov SLtt_Msdos_Cheap_Video, ax
L3:
asm mov ax, Attribute_Byte
asm cmp ax, 0
asm jne L2
asm mov ax, 0x07
asm mov Attribute_Byte, ax
L2:
/* toggle the blink bit so we can use hi intensity background */
if (IsColor && !SLtt_Msdos_Cheap_Video)
{
asm mov ax, 0x1003
asm mov bx, 0
asm int 0x10
Blink_Killed = 1;
}
# endif /* __GO32__ or __WATCOMC__ */
# endif /* __os2__ */
#endif /* EMX_VIDEO */
SLtt_set_scroll_region (0, SLtt_Screen_Rows);
SLtt_Use_Ansi_Colors = IsColor;
}
/*----------------------------------------------------------------------*\
* Function: int SLtt_flush_output (void);
\*----------------------------------------------------------------------*/
int SLtt_flush_output (void)
{
fflush (stdout);
return -1;
}
int SLtt_set_cursor_visibility (int show)
{
(void) show;
return -1;
}
void SLtt_set_mono (int obj_unused, char *unused, SLtt_Char_Type c_unused)
{
(void) obj_unused;
(void) unused;
(void) c_unused;
}
/* /////////////////////// end of file (c source) ///////////////////// */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -