📄 pcvt_vtf.c
字号:
/* * Copyright (c) 1992, 1995 Hellmuth Michaelis and Joerg Wunsch. * * Copyright (c) 1992, 1993 Brian Dunford-Shore. * * All rights reserved. * * This code is derived from software contributed to Berkeley by * William Jolitz and Don Ahn. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by Hellmuth Michaelis, * Brian Dunford-Shore and Joerg Wunsch. * 4. The name authors may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * * @(#)pcvt_vtf.c, 3.20, Last Edit-Date: [Wed Apr 5 18:08:50 1995] *//*---------------------------------------------------------------------------* * * pcvt_vtf.c VT220 Terminal Emulator Functions * ------------------------------------------------- * -hm ------------ Release 3.00 -------------- * -hm integrating NetBSD-current patches * -hm integrating patch from Thomas Gellekum * -hm fixed bug fkey labels not properly (re)set after ris * -hm Michael Havemester fixed NOFASTSCROLL define bug * -hm set caps/scroll/num_lock in vt_str() and made led_update() * -hm applying patch from Joerg fixing Crtat bug * -hm fixing NOFASTSCROLL operation for MDA/Hercules * -jw/hm fixing bug in roll_up() and roll_down() * -hm fastscroll/Crtat bugfix from Lon Willett * -hm patch for non-XSERVER/UCONSOLE compiles from Rafal Boni * -hm bugfix: PCVT_USL_COMPAT renamed to PCVT_USL_VT_COMPAT ... * *---------------------------------------------------------------------------*/#include "vt.h"#if NVT > 0#define PCVT_INCLUDE_VT_SELATTR /* get inline function from pcvt_hdr.h */#include <i386/isa/pcvt/pcvt_hdr.h> /* global include */#include <i386/isa/pcvt/pcvt_tbl.h> /* character set conversion tables */static void clear_dld ( struct video_state *svsp );static void init_dld ( struct video_state *svsp );static void init_udk ( struct video_state *svsp );static void respond ( struct video_state *svsp );static void roll_down ( struct video_state *svsp, int n );static void selective_erase ( struct video_state *svsp, u_short *pcrtat, int length );static void swcsp ( struct video_state *svsp, u_short *ctp );/*---------------------------------------------------------------------------* * DECSTBM - set top and bottom margins *---------------------------------------------------------------------------*/voidvt_stbm(struct video_state *svsp){ /* both 0 => scrolling region = entire screen */ if((svsp->parms[0] == 0) && (svsp->parms[1] == 0)) { svsp->cur_offset = 0; svsp->scrr_beg = 0; svsp->scrr_len = svsp->screen_rows; svsp->scrr_end = svsp->scrr_len - 1; svsp->col = 0; return; } if(svsp->parms[1] <= svsp->parms[0]) return; /* range parm 1 */ if(svsp->parms[0] < 1) svsp->parms[0] = 1; else if(svsp->parms[0] > svsp->screen_rows-1) svsp->parms[0] = svsp->screen_rows-1; /* range parm 2 */ if(svsp->parms[1] < 2) svsp->parms[1] = 2; else if(svsp->parms[1] > svsp->screen_rows) svsp->parms[1] = svsp->screen_rows; svsp->scrr_beg = svsp->parms[0]-1; /* begin of scrolling region */ svsp->scrr_len = svsp->parms[1] - svsp->parms[0] + 1; /* no of lines */ svsp->scrr_end = svsp->parms[1]-1; /* cursor to first pos */ if(svsp->m_om) svsp->cur_offset = svsp->scrr_beg * svsp->maxcol; else svsp->cur_offset = 0; svsp->col = 0;}/*---------------------------------------------------------------------------* * SGR - set graphic rendition *---------------------------------------------------------------------------*/voidvt_sgr(struct video_state *svsp){ register int i = 0; u_short setcolor = 0; char colortouched = 0; do { switch(svsp->parms[i++]) { case 0: /* reset to normal attributes */ svsp->vtsgr = VT_NORMAL; break; case 1: /* bold */ svsp->vtsgr |= VT_BOLD; break; case 4: /* underline */ svsp->vtsgr |= VT_UNDER; break; case 5: /* blinking */ svsp->vtsgr |= VT_BLINK; break; case 7: /* reverse */ svsp->vtsgr |= VT_INVERSE; break; case 22: /* not bold */ svsp->vtsgr &= ~VT_BOLD; break; case 24: /* not underlined */ svsp->vtsgr &= ~VT_UNDER; break; case 25: /* not blinking */ svsp->vtsgr &= ~VT_BLINK; break; case 27: /* not reverse */ svsp->vtsgr &= ~VT_INVERSE; break; case 30: /* foreground colors */ case 31: case 32: case 33: case 34: case 35: case 36: case 37: if(color) { colortouched = 1; setcolor |= ((fgansitopc[(svsp->parms[i-1]-30) & 7]) << 8); } break; case 40: /* background colors */ case 41: case 42: case 43: case 44: case 45: case 46: case 47: if(color) { colortouched = 1; setcolor |= ((bgansitopc[(svsp->parms[i-1]-40) & 7]) << 8); } break; } } while(i <= svsp->parmi); if(color) { if(colortouched) svsp->c_attr = setcolor; else svsp->c_attr = ((sgr_tab_color[svsp->vtsgr]) << 8); } else { if(adaptor_type == MDA_ADAPTOR) svsp->c_attr = ((sgr_tab_imono[svsp->vtsgr]) << 8); else svsp->c_attr = ((sgr_tab_mono[svsp->vtsgr]) << 8); }}/*---------------------------------------------------------------------------* * CUU - cursor up *---------------------------------------------------------------------------*/voidvt_cuu(struct video_state *svsp){ register int p = svsp->parms[0]; if (p <= 0) /* parameter min */ p = 1; p = min(p, svsp->row - svsp->scrr_beg); if (p <= 0) return; svsp->cur_offset -= (svsp->maxcol * p);}/*---------------------------------------------------------------------------* * CUD - cursor down *---------------------------------------------------------------------------*/voidvt_cud(struct video_state *svsp){ register int p = svsp->parms[0]; if (p <= 0) p = 1; p = min(p, svsp->scrr_end - svsp->row); if (p <= 0) return; svsp->cur_offset += (svsp->maxcol * p);}/*---------------------------------------------------------------------------* * CUF - cursor forward *---------------------------------------------------------------------------*/voidvt_cuf(struct video_state *svsp){ register int p = svsp->parms[0]; if(svsp->col == ((svsp->maxcol)-1)) /* already at right margin */ return; if(p <= 0) /* parameter min = 1 */ p = 1; else if(p > ((svsp->maxcol)-1)) /* parameter max = 79 */ p = ((svsp->maxcol)-1); if((svsp->col + p) > ((svsp->maxcol)-1))/* not more than right margin */ p = ((svsp->maxcol)-1) - svsp->col; svsp->cur_offset += p; svsp->col += p;}/*---------------------------------------------------------------------------* * CUB - cursor backward *---------------------------------------------------------------------------*/voidvt_cub(struct video_state *svsp){ register int p = svsp->parms[0]; if(svsp->col == 0) /* already at left margin ? */ return; if(p <= 0) /* parameter min = 1 */ p = 1; else if(p > ((svsp->maxcol)-1)) /* parameter max = 79 */ p = ((svsp->maxcol)-1); if((svsp->col - p) <= 0) /* not more than left margin */ p = svsp->col; svsp->cur_offset -= p; svsp->col -= p;}/*---------------------------------------------------------------------------* * ED - erase in display *---------------------------------------------------------------------------*/voidvt_clreos(struct video_state *svsp){ switch(svsp->parms[0]) { case 0: fillw(user_attr | ' ', svsp->Crtat + svsp->cur_offset, svsp->Crtat + (svsp->maxcol * svsp->screen_rows) - (svsp->Crtat + svsp->cur_offset)); break; case 1: fillw(user_attr | ' ', svsp->Crtat, svsp->Crtat + svsp->cur_offset - svsp->Crtat + 1 ); break; case 2: fillw(user_attr | ' ', svsp->Crtat, svsp->maxcol * svsp->screen_rows); break; }}/*---------------------------------------------------------------------------* * EL - erase in line *---------------------------------------------------------------------------*/voidvt_clreol(struct video_state *svsp){ switch(svsp->parms[0]) { case 0: fillw(user_attr | ' ', svsp->Crtat + svsp->cur_offset, svsp->maxcol-svsp->col); break; case 1: fillw(user_attr | ' ', svsp->Crtat + svsp->cur_offset - svsp->col, svsp->col + 1); break; case 2: fillw(user_attr | ' ', svsp->Crtat + svsp->cur_offset - svsp->col, svsp->maxcol); break; }}/*---------------------------------------------------------------------------* * CUP - cursor position / HVP - horizontal & vertical position *---------------------------------------------------------------------------*/voidvt_curadr(struct video_state *svsp){ if(svsp->m_om) /* relative to scrolling region */ { if((svsp->parms[0] == 0) && (svsp->parms[1] == 0)) { svsp->cur_offset = svsp->scrr_beg * svsp->maxcol; svsp->col = 0; svsp->abs_write = 0; return; } if(svsp->parms[0] <= 0) svsp->parms[0] = 1; else if(svsp->parms[0] > svsp->scrr_len) svsp->parms[0] = svsp->scrr_len; if(svsp->parms[1] <= 0 ) svsp->parms[1] = 1; if(svsp->parms[1] > svsp->maxcol) svsp->parms[1] = svsp->maxcol; svsp->cur_offset = (svsp->scrr_beg * svsp->maxcol) + ((svsp->parms[0] - 1) * svsp->maxcol) + svsp->parms[1] - 1; svsp->col = svsp->parms[1] - 1; svsp->abs_write = 0; } else /* relative to screen start */ { if((svsp->parms[0] == 0) && (svsp->parms[1] == 0)) { svsp->cur_offset = 0; svsp->col = 0; svsp->abs_write = 0; return; } if(svsp->parms[0] <= 0) svsp->parms[0] = 1; else if(svsp->parms[0] > svsp->screen_rows) svsp->parms[0] = svsp->screen_rows; if(svsp->parms[1] <= 0 ) svsp->parms[1] = 1; if(svsp->parms[1] > svsp->maxcol) /* col */ svsp->parms[1] = svsp->maxcol; svsp->cur_offset = (((svsp->parms[0]-1)*svsp->maxcol) + (svsp->parms[1]-1)); svsp->col = svsp->parms[1]-1; if (svsp->cur_offset >= ((svsp->scrr_beg + svsp->scrr_len + 1) * svsp->maxcol)) svsp->abs_write = 1; else svsp->abs_write = 0; }}/*---------------------------------------------------------------------------* * RIS - reset to initial state (hard emulator runtime reset) *---------------------------------------------------------------------------*/voidvt_ris(struct video_state *svsp){ fillw(user_attr | ' ', svsp->Crtat, svsp->maxcol * svsp->screen_rows); svsp->cur_offset = 0; /* cursor upper left corner */ svsp->col = 0; svsp->row = 0; svsp->lnm = 0; /* CR only */ clear_dld(svsp); /* clear download charset */ vt_clearudk(svsp); /* clear user defined keys */ svsp->selchar = 0; /* selective attribute off */ vt_str(svsp); /* and soft terminal reset */}/*---------------------------------------------------------------------------* * DECSTR - soft terminal reset (SOFT emulator runtime reset) *---------------------------------------------------------------------------*/voidvt_str(struct video_state *svsp){ int i; clr_parms(svsp); /* escape parameter init */ svsp->state = STATE_INIT; /* initial state */ svsp->dis_fnc = 0; /* display functions reset */ svsp->sc_flag = 0; /* save cursor position */ svsp->transparent = 0; /* enable control code processing */ for(i = 0; i < MAXTAB; i++) /* setup tabstops */ { if(!(i % 8)) svsp->tab_stops[i] = 1; else svsp->tab_stops[i] = 0; } svsp->irm = 0; /* replace mode */ svsp->m_om = 0; /* origin mode */ svsp->m_awm = 1; /* auto wrap mode */#if PCVT_INHIBIT_NUMLOCK svsp->num_lock = 0; /* keypad application mode */#else svsp->num_lock = 1; /* keypad numeric mode */#endif svsp->scroll_lock = 0; /* reset keyboard modes */ svsp->caps_lock = 0; svsp->ckm = 1; /* cursor key mode = "normal" ... */ svsp->scrr_beg = 0; /* start of scrolling region */ svsp->scrr_len = svsp->screen_rows; /* no. of lines in scrolling region */ svsp->abs_write = 0; /* scrr is complete screen */ svsp->scrr_end = svsp->scrr_len - 1; if(adaptor_type == EGA_ADAPTOR || adaptor_type == VGA_ADAPTOR) { svsp->G0 = cse_ascii; /* G0 = ascii */ svsp->G1 = cse_ascii; /* G1 = ascii */ svsp->G2 = cse_supplemental; /* G2 = supplemental */ svsp->G3 = cse_supplemental; /* G3 = supplemental */ svsp->GL = &svsp->G0; /* GL = G0 */ svsp->GR = &svsp->G2; /* GR = G2 */ } else { svsp->G0 = csd_ascii; /* G0 = ascii */ svsp->G1 = csd_ascii; /* G1 = ascii */ svsp->G2 = csd_supplemental; /* G2 = supplemental */ svsp->G3 = csd_supplemental; /* G3 = supplemental */ svsp->GL = &svsp->G0; /* GL = G0 */ svsp->GR = &svsp->G2; /* GR = G2 */ } svsp->vtsgr = VT_NORMAL; /* no attributes */ svsp->c_attr = user_attr; /* reset sgr to normal */ svsp->selchar = 0; /* selective attribute off */ vt_initsel(svsp); init_ufkl(svsp); /* init user fkey labels */ init_sfkl(svsp); /* init system fkey labels */ update_led(); /* update keyboard LED's */}/*---------------------------------------------------------------------------* * RI - reverse index, move cursor up *---------------------------------------------------------------------------*/voidvt_ri(struct video_state *svsp){ if(svsp->cur_offset >= ((svsp->scrr_beg * svsp->maxcol) + svsp->maxcol)) svsp->cur_offset -= svsp->maxcol; else roll_down(svsp, 1);}/*---------------------------------------------------------------------------* * IND - index, move cursor down *---------------------------------------------------------------------------*/voidvt_ind(struct video_state *svsp){ if(svsp->cur_offset < (svsp->scrr_end * svsp->maxcol)) svsp->cur_offset += svsp->maxcol; else roll_up(svsp, 1);}/*---------------------------------------------------------------------------* * NEL - next line, first pos of next line *---------------------------------------------------------------------------*/voidvt_nel(struct video_state *svsp)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -