📄 slsmg.c
字号:
tmp = SL_Screen[r2].old;
for (j = r2; j > r1; j--)
{
SL_Screen[j].old = SL_Screen[j - 1].old;
SL_Screen[j].old_hash = SL_Screen[j - 1].old_hash;
}
SL_Screen[r1].old = tmp;
blank_line (SL_Screen[r1].old, Screen_Cols, ' ');
SL_Screen[r1].old_hash = Blank_Hash;
r1++;
}
This_Color = color;
}
if (did_scroll) return;
/* Try other direction */
for (i = rmin; i < rmax; i++)
{
hash = SL_Screen[i].new_hash;
if (hash == Blank_Hash) continue;
if (hash == SL_Screen[i].old_hash) continue;
/* find a match further down screen */
for (j = i + 1; j <= rmax; j++)
{
if (hash == SL_Screen[j].old_hash) break;
}
if (j > rmax) continue;
r1 = i; /* beg scroll region */
di = j - i; /* number of lines to scroll */
j++; /* since we know this is a match */
/* find end of scroll region */
ignore = 0;
while ((j <= rmax) && (SL_Screen[j].old_hash == SL_Screen[j - di].new_hash))
{
if (SL_Screen[j].old_hash == Blank_Hash) ignore++;
j++;
}
r2 = j - 1; /* end of scroll region */
/* If this scroll only scrolls this line into place, don't do it.
*/
if ((di > 1) && (r1 + di + ignore == r2)) continue;
/* If there is anything in the scrolling region that is ok, abort the
* scroll.
*/
for (j = r1; j <= r2; j++)
{
if ((SL_Screen[j].old_hash != Blank_Hash)
&& (SL_Screen[j].old_hash == SL_Screen[j].new_hash))
{
if ((j - di < r1) || (SL_Screen[j].old_hash != SL_Screen[j - di].new_hash))
break;
}
}
if (j <= r2) continue;
color = This_Color; This_Color = 0;
SLtt_normal_video ();
SLtt_set_scroll_region (r1, r2);
SLtt_goto_rc (0, 0); /* relative to scroll region */
SLtt_delete_nlines (di);
SLtt_reset_scroll_region ();
/* Now we have a hole in the screen. Make the virtual screen look
* like it.
*/
for (j = r1; j <= r2; j++) SL_Screen[j].flags = TOUCHED;
while (di--)
{
tmp = SL_Screen[r1].old;
for (j = r1; j < r2; j++)
{
SL_Screen[j].old = SL_Screen[j + 1].old;
SL_Screen[j].old_hash = SL_Screen[j + 1].old_hash;
}
SL_Screen[r2].old = tmp;
blank_line (SL_Screen[r2].old, Screen_Cols, ' ');
SL_Screen[r2].old_hash = Blank_Hash;
r2--;
}
This_Color = color;
}
}
#endif /* NOT pc_system */
static int Smg_Inited;
void SLsmg_refresh (void)
{
int i;
if (Smg_Inited == 0) return;
#ifndef pc_system
for (i = 0; i < Screen_Rows; i++)
{
if (SL_Screen[i].flags == 0) continue;
SL_Screen[i].new_hash = compute_hash (SL_Screen[i].neew, Screen_Cols);
}
#endif
if (Cls_Flag)
{
SLtt_normal_video (); SLtt_cls ();
}
#ifndef pc_system
else if (SLtt_Term_Cannot_Scroll == 0) try_scroll ();
#endif
for (i = 0; i < Screen_Rows; i++)
{
int trashed;
if (SL_Screen[i].flags == 0) continue;
if (SL_Screen[i].flags & TRASHED)
{
SLtt_goto_rc (i, -1); /* Force cursor to move */
SLtt_goto_rc (i, 0);
if (Cls_Flag == 0) SLtt_del_eol ();
trashed = 1;
}
else trashed = 0;
if (Cls_Flag || trashed)
{
int color = This_Color;
This_Color = 0;
blank_line (SL_Screen[i].old, Screen_Cols, ' ');
This_Color = color;
}
SL_Screen[i].old[Screen_Cols] = 0;
SL_Screen[i].neew[Screen_Cols] = 0;
SLtt_smart_puts (SL_Screen[i].neew, SL_Screen[i].old, Screen_Cols, i);
SLMEMCPY ((char *) SL_Screen[i].old, (char *) SL_Screen[i].neew,
Screen_Cols * sizeof (short));
SL_Screen[i].flags = 0;
#ifndef pc_system
SL_Screen[i].old_hash = SL_Screen[i].new_hash;
#endif
}
if (point_visible (1)) SLtt_goto_rc (This_Row - Start_Row, This_Col - Start_Col);
SLtt_flush_output ();
Cls_Flag = 0;
}
static int compute_clip (int row, int n, int box_start, int box_end,
int *rmin, int *rmax)
{
int row_max;
if (n < 0) return 0;
if (row >= box_end) return 0;
row_max = row + n;
if (row_max <= box_start) return 0;
if (row < box_start) row = box_start;
if (row_max >= box_end) row_max = box_end;
*rmin = row;
*rmax = row_max;
return 1;
}
void SLsmg_touch_lines (int row, int n)
{
int i;
int r1, r2;
if (0 == compute_clip (row, n, Start_Row, Start_Row + Screen_Rows, &r1, &r2))
return;
r1 -= Start_Row;
r2 -= Start_Row;
for (i = r1; i < r2; i++)
{
SL_Screen[i].flags |= TRASHED;
}
}
#ifndef pc_system
static char Fake_Alt_Char_Pairs [] = "a:j+k+l+m+q-t+u+v+w+x|";
static void init_alt_char_set (void)
{
int i;
unsigned char *p, *pmax, ch;
if (Alt_Char_Set[128] == 128) return;
i = 32;
memset ((char *)Alt_Char_Set, ' ', i);
while (i <= 128)
{
Alt_Char_Set [i] = i;
i++;
}
/* Map to VT100 */
if (SLtt_Has_Alt_Charset)
{
p = (unsigned char *) SLtt_Graphics_Char_Pairs;
if (p == NULL) return;
}
else p = (unsigned char *) Fake_Alt_Char_Pairs;
pmax = p + strlen ((char *) p);
/* Some systems have messed up entries for this */
while (p < pmax)
{
ch = *p++;
ch &= 0x7F; /* should be unnecessary */
Alt_Char_Set [ch] = *p;
p++;
}
}
#endif
#ifndef pc_system
# define BLOCK_SIGNALS SLsig_block_signals ();
# define UNBLOCK_SIGNALS SLsig_unblock_signals ();
#else
# define BLOCK_SIGNALS
# define UNBLOCK_SIGNALS
#endif
static int Smg_Suspended;
void SLsmg_suspend_smg (void)
{
BLOCK_SIGNALS
if (Smg_Suspended == 0)
{
SLtt_reset_video ();
Smg_Suspended = 1;
}
UNBLOCK_SIGNALS
}
void SLsmg_resume_smg (void)
{
int i;
BLOCK_SIGNALS
if (Smg_Suspended == 0)
{
UNBLOCK_SIGNALS
return;
}
Smg_Suspended = 0;
SLtt_init_video ();
Cls_Flag = 1;
for (i = 0; i < Screen_Rows; i++)
SL_Screen[i].flags |= TRASHED;
SLsmg_refresh ();
UNBLOCK_SIGNALS
}
int SLsmg_init_smg (void)
{
int i, len;
unsigned short *old, *neew;
BLOCK_SIGNALS
if (Smg_Inited) SLsmg_reset_smg ();
SLtt_init_video ();
Screen_Cols = SLtt_Screen_Cols;
Screen_Rows = SLtt_Screen_Rows;
This_Col = This_Row = Start_Col = Start_Row = 0;
This_Color = 0;
This_Alt_Char = 0;
Cls_Flag = 1;
#ifndef pc_system
init_alt_char_set ();
#endif
len = Screen_Cols + 3;
for (i = 0; i < Screen_Rows; i++)
{
if ((NULL == (old = (unsigned short *) SLMALLOC (sizeof(short) * len)))
|| ((NULL == (neew = (unsigned short *) SLMALLOC (sizeof(short) * len)))))
{
SLang_Error = SL_MALLOC_ERROR;
UNBLOCK_SIGNALS
return 0;
}
blank_line (old, len, ' ');
blank_line (neew, len, ' ');
SL_Screen[i].old = old;
SL_Screen[i].neew = neew;
SL_Screen[i].flags = 0;
#ifndef pc_system
Blank_Hash = compute_hash (old, Screen_Cols);
SL_Screen[i].new_hash = SL_Screen[i].old_hash = Blank_Hash;
#endif
}
Smg_Inited = 1;
UNBLOCK_SIGNALS
return 1;
}
void SLsmg_reset_smg (void)
{
int i;
BLOCK_SIGNALS
if (Smg_Inited == 0)
{
UNBLOCK_SIGNALS
return;
}
for (i = 0; i < Screen_Rows; i++)
{
if (SL_Screen[i].old != NULL) SLFREE (SL_Screen[i].old);
if (SL_Screen[i].neew != NULL) SLFREE (SL_Screen[i].neew);
SL_Screen[i].old = SL_Screen[i].neew = NULL;
}
SLtt_reset_video ();
This_Alt_Char = This_Color = 0;
Smg_Inited = 0;
UNBLOCK_SIGNALS
}
unsigned short SLsmg_char_at (void)
{
if (point_visible (1))
{
return SL_Screen[This_Row - Start_Row].neew[This_Col - Start_Col];
}
return 0;
}
void SLsmg_vprintf (char *fmt, va_list ap)
{
char p[1000];
(void) vsprintf(p, fmt, ap);
SLsmg_write_string (p);
}
void SLsmg_set_screen_start (int *r, int *c)
{
int or = Start_Row, oc = Start_Col;
if (c == NULL) Start_Col = 0;
else
{
Start_Col = *c;
*c = oc;
}
if (r == NULL) Start_Row = 0;
else
{
Start_Row = *r;
*r = or;
}
}
void SLsmg_draw_object (int r, int c, unsigned char object)
{
This_Row = r; This_Col = c;
if (point_visible (1))
{
int color = This_Color;
This_Color |= ALT_CHAR_FLAG;
SLsmg_write_char (object);
This_Color = color;
}
This_Col = c + 1;
}
void SLsmg_draw_hline (int n)
{
static unsigned char hbuf[16];
int count;
int cmin, cmax;
int final_col = This_Col + n;
int save_color;
if ((This_Row < Start_Row) || (This_Row >= Start_Row + Screen_Rows)
|| (0 == compute_clip (This_Col, n, Start_Col, Start_Col + Screen_Cols,
&cmin, &cmax)))
{
This_Col = final_col;
return;
}
if (hbuf[0] == 0)
{
SLMEMSET ((char *) hbuf, SLSMG_HLINE_CHAR, 16);
}
n = cmax - cmin;
count = n / 16;
save_color = This_Color;
This_Color |= ALT_CHAR_FLAG;
This_Col = cmin;
SLsmg_write_nchars ((char *) hbuf, n % 16);
while (count-- > 0)
{
SLsmg_write_nchars ((char *) hbuf, 16);
}
This_Color = save_color;
This_Col = final_col;
}
void SLsmg_draw_vline (int n)
{
unsigned char ch = SLSMG_VLINE_CHAR;
int c = This_Col, rmin, rmax;
int final_row = This_Row + n;
int save_color;
if (((c < Start_Col) || (c >= Start_Col + Screen_Cols)) ||
(0 == compute_clip (This_Row, n, Start_Row, Start_Row + Screen_Rows,
&rmin, &rmax)))
{
This_Row = final_row;
return;
}
save_color = This_Color;
This_Color |= ALT_CHAR_FLAG;
for (This_Row = rmin; This_Row < rmax; This_Row++)
{
This_Col = c;
SLsmg_write_nchars ((char *) &ch, 1);
}
This_Col = c; This_Row = final_row;
This_Color = save_color;
}
void SLsmg_draw_box (int r, int c, int dr, int dc)
{
if (!dr || !dc) return;
This_Row = r; This_Col = c;
dr--; dc--;
SLsmg_draw_hline (dc);
SLsmg_draw_vline (dr);
This_Row = r; This_Col = c;
SLsmg_draw_vline (dr);
SLsmg_draw_hline (dc);
SLsmg_draw_object (r, c, SLSMG_ULCORN_CHAR);
SLsmg_draw_object (r, c + dc, SLSMG_URCORN_CHAR);
SLsmg_draw_object (r + dr, c, SLSMG_LLCORN_CHAR);
SLsmg_draw_object (r + dr, c + dc, SLSMG_LRCORN_CHAR);
This_Row = r; This_Col = c;
}
void SLsmg_fill_region (int r, int c, int dr, int dc, unsigned char ch)
{
static unsigned char hbuf[16];
int count;
int dcmax, rmax;
if ((dc < 0) || (dr < 0)) return;
SLsmg_gotorc (r, c);
r = This_Row; c = This_Col;
dcmax = Screen_Cols - This_Col;
if (dc > dcmax) dc = dcmax;
rmax = This_Row + dr;
if (rmax > Screen_Rows) rmax = Screen_Rows;
#if 0
ch = Alt_Char_Set[ch];
#endif
if (ch != hbuf[0]) SLMEMSET ((char *) hbuf, (char) ch, 16);
for (This_Row = r; This_Row < rmax; This_Row++)
{
This_Col = c;
count = dc / 16;
SLsmg_write_nchars ((char *) hbuf, dc % 16);
while (count-- > 0)
{
SLsmg_write_nchars ((char *) hbuf, 16);
}
}
This_Row = r;
}
void SLsmg_forward (int n)
{
This_Col += n;
}
void SLsmg_write_color_chars (unsigned short *s, unsigned int len)
{
unsigned short *smax, sh;
char buf[32], *b, *bmax;
int color, save_color;
smax = s + len;
b = buf;
bmax = b + sizeof (buf);
save_color = This_Color;
while (s < smax)
{
sh = *s++;
color = sh >> 8;
if ((color != This_Color) || (b == bmax))
{
if (b != buf)
{
SLsmg_write_nchars (buf, (int) (b - buf));
b = buf;
}
This_Color = color;
}
*b++ = (char) (sh & 0xFF);
}
if (b != buf)
SLsmg_write_nchars (buf, (int) (b - buf));
This_Color = save_color;
}
unsigned int SLsmg_read_raw (unsigned short *buf, unsigned int len)
{
unsigned int r, c;
if (0 == point_visible (1)) return 0;
r = (unsigned int) (This_Row - Start_Row);
c = (unsigned int) (This_Col - Start_Col);
if (c + len > (unsigned int) Screen_Cols)
len = (unsigned int) Screen_Cols - c;
memcpy ((char *) buf, (char *) (SL_Screen[r].neew + c), len * sizeof (short));
return len;
}
unsigned int SLsmg_write_raw (unsigned short *buf, unsigned int len)
{
unsigned int r, c;
unsigned short *dest;
if (0 == point_visible (1)) return 0;
r = (unsigned int) (This_Row - Start_Row);
c = (unsigned int) (This_Col - Start_Col);
if (c + len > (unsigned int) Screen_Cols)
len = (unsigned int) Screen_Cols - c;
dest = SL_Screen[r].neew + c;
if (0 != memcmp ((char *) dest, (char *) buf, len * sizeof (short)))
{
memcpy ((char *) dest, (char *) buf, len * sizeof (short));
SL_Screen[r].flags |= TOUCHED;
}
return len;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -