m6845Vga.c
上传用户:luoyougen
上传日期:2008-05-12
资源大小:23136k
文件大小:45k
源码类别:

VxWorks

开发平台:

C/C++

  1. /* m6845Vga.c - motorola 6845 vga console driver routines */
  2. /* Copyright 1993-1993 Wind River System, Inc. */
  3. #include "copyright_wrs.h"
  4. /*
  5. modification history
  6. --------------------
  7. 01e,12feb97,hdn  fixed the bug causes workQ panic. (SPR#7923)
  8. 01d,03aug95,myz  fixed the warning message
  9. 01c,14jun95,hdn  removed function declarations defined in sysLib.h.
  10. 01b,30mar94,hdn  changed CONSOLE_TTY to PC_CONSOLE.
  11. 01a,20oct93,vin  created
  12. */
  13. /*
  14. DESCRIPTION
  15. This is the driver fo Video Contoroller Chip (6845) normally  used in the
  16. 386/486 personal computers.
  17. USER CALLABLE ROUTINES
  18. The routines in this driver are accessed from a generic console
  19. driver through the hook routine, the pointer to which is initialized
  20. in the VGA_CON_DEV structure at the time of initialization.
  21. This makes the access to these routines more generic without declaring
  22. these functions as external. 
  23. The routines in this driver which are accessed from an external module
  24. are vgaWriteString() and vgaHrdInit(). vgaWriteString() is installed
  25. as a device transmit start-up routine in tyDevInit(). vgaHrdInit() is
  26. called to initialize the device descriptors and the vga console.
  27. All virtual consoles are mapped to the same screen buffer. This is a 
  28. very basic implementation of virtual consoles. Multiple screen
  29. buffers are not used to switch between consoles. This implementation
  30. is left for the future. Mutual exclusion for the screen buffer is 
  31. guaranteed within the same console but it is not implemented across multiple
  32. virtual consoles because all virtual consoles use the same screen buffer. If
  33. multiple screen buffers are implemented then the mutual exclusion between
  34. virtual consoles can be implemented.
  35. Before using the driver, it must be initialized by calling vgaHrdInit(). 
  36. This routine should be called exactly once. Normally, it is called from 
  37. a generic driver for eg. from tyCoDrv() which is called before tyCoDevCreate.
  38. SEE ALSO
  39. tyLib
  40. NOTES
  41. The macro N_VIRTUAL_CONSOLES should be defined in config.h file.
  42. This refers to the number of virtual consoles which the user wishes to have.
  43. The user should define INCLUDE_ANSI_ESC_SEQUENCE in <target>.h file if
  44. the ansi escape sequences are required. Special processing in the vga
  45. driver is done if an escape sequence exists.
  46. */
  47. /* includes */
  48. #include "vxWorks.h"
  49. #include "iv.h"
  50. #include "ioLib.h"
  51. #include "iosLib.h"
  52. #include "memLib.h"
  53. #include "rngLib.h"
  54. #include "tyLib.h"
  55. #include "private/funcBindP.h"
  56. #include "intLib.h"
  57. #include "taskLib.h"
  58. #include "errnoLib.h"
  59. #include "stdio.h"
  60. #include "string.h"
  61. #include "config.h"
  62. #include "drv/serial/pcConsole.h"
  63. /* externals */
  64. IMPORT PC_CON_DEV pcConDv [N_VIRTUAL_CONSOLES] ;
  65. /* locals */
  66. LOCAL VGA_CON_DEV vgaConDv [N_VIRTUAL_CONSOLES];
  67. LOCAL UCHAR curSt,curEd; /* current cursor mode */
  68. LOCAL int  tyWrtThreshold  = 20; /* min bytes free in output 
  69.  * buffer before the next 
  70.  * writer will be enabled */
  71. LOCAL int  jobaddThreshold = 20; /* bytes processed in int lvl */
  72. LOCAL UCHAR * vgaCharTable [] = 
  73.     {
  74.     /* 8-bit Latin-1 mapped to the PC charater set: '' means non-printable */
  75.     (unsigned char *)
  76.     ""
  77.     ""
  78.     " !"#$%&'()*+,-./0123456789:;<=>?"
  79.     "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_"
  80.     "`abcdefghijklmnopqrstuvwxyz{|}~"
  81.     ""
  82.     ""
  83.     "402552332343762351742537637624625625255376376"
  84.     "37036137537637634624371376376247257254253376250"
  85.     "376376376376216217222200376220376376376376376376"
  86.     "376245376376376376231376235376376376232376376341"
  87.     "205240203376204206221207212202210211215241214213"
  88.     "376244225242223376224366233227243226201376376230",
  89.     /* vt100 graphics */
  90.     (unsigned char *)
  91.     ""
  92.     ""
  93.     " !"#$%&'()*+,-./0123456789:;<=>?"
  94.     "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^ "
  95.     "0426107070707370361400733127733230030507"
  96.     "0730407073032643013022630707070707234"
  97.     ""
  98.     ""
  99.     "402552332343762351742537637624625625255376376"
  100.     "37036137537637634624371376376247257254253376250"
  101.     "376376376376216217222200376220376376376376376376"
  102.     "376245376376376376231376376376376376232376376341"
  103.     "205240203376204206221207212202210211215241214213"
  104.     "376244225242223376224366376227243226201376376230",
  105.     /* IBM graphics: minimal translations (CR, LF, LL, SO, SI and ESC) */
  106.     (unsigned char *)
  107.     "00010203040506071011001300000000"
  108.     "20212223242526273031320034353637"
  109.     "40414243444546475051525354555657"
  110.     "60616263646566677071727374757677"
  111.     "100101102103104105106107110111112113114115116117"
  112.     "120121122123124125126127130131132133134135136137"
  113.     "140141142143144145146147150151152153154155156157"
  114.     "160161162163164165166167170171172173174175176177"
  115.     "200201202203204205206207210211212213214215216217"
  116.     "220221222223224225226227230231232233234235236237"
  117.     "240241242243244245246247250251252253254255256257"
  118.     "260261262263264265266267270271272273274275276277"
  119.     "300301302303304305306307310311312313314315316317"
  120.     "320321322323324325326327330331332333334335336337"
  121.     "340341342343344345346347350351352353354355356357"
  122.     "360361362363364365366367370371372373374375376377"
  123.     };
  124. /* forward declarations */
  125. LOCAL void vgaStatInit (void);
  126. LOCAL void vgaHook (FAST VGA_CON_DEV *  pVgaConDv, int arg, int opCode);
  127. LOCAL void vgaClear (FAST VGA_CON_DEV *  pVgaConDv, int position, 
  128.   UCHAR eraseChar);
  129. LOCAL void vgaScroll (FAST VGA_CON_DEV *  pVgaConDv, int pos, int line, 
  130.    BOOL upDn, FAST UCHAR atr);
  131. LOCAL void vgaInsertChar (FAST VGA_CON_DEV *  pVgaConDv, 
  132.        FAST int nInsChar);
  133. LOCAL void  vgaCursorOn (void);
  134. LOCAL void vgaCursorOff (void);
  135. LOCAL void vgaCursorPos (FAST UINT16 pos);
  136. LOCAL void vgaScreenRev (FAST VGA_CON_DEV * pVgaConDv);
  137. LOCAL void vgaDelLeftChar (FAST VGA_CON_DEV *  pVgaConDv);
  138. LOCAL void vgaCarriageReturn (FAST VGA_CON_DEV *  pVgaConDv);
  139. LOCAL void vgaBackSpace (FAST VGA_CON_DEV *  pVgaConDv);
  140. LOCAL void vgaLineFeed (FAST VGA_CON_DEV *  pVgaConDv);
  141. LOCAL void vgaTab (FAST VGA_CON_DEV *  pVgaConDv);
  142. LOCAL void vgaConBeep (BOOL mode);
  143. #ifdef INCLUDE_ANSI_ESC_SEQUENCE
  144. LOCAL UCHAR vgaColorTable [] = 
  145.     {
  146.     /* black, red, green, brown, blue, magenta, cyan, light grey */
  147.            0,   4,     2,     6,    1,       5,    3,          7
  148.     };
  149. LOCAL void vgaEscResponse (FAST PC_CON_DEV * pPcCoDv, int  responseId );
  150. LOCAL void vgaPutCursor (FAST VGA_CON_DEV *  pVgaConDv);
  151. LOCAL void vgaSaveCurAttrib (FAST VGA_CON_DEV *  pVgaConDv);
  152. LOCAL void vgaRestAttrib (FAST VGA_CON_DEV *  pVgaConDv);
  153. LOCAL void vgaSetMode (FAST  PC_CON_DEV *  pPcCoDv, BOOL onOff);
  154. LOCAL void vgaClearLine (FAST VGA_CON_DEV *  pVgaConDv);
  155. LOCAL void vgaInsertLine (FAST VGA_CON_DEV *  pVgaConDv);
  156. LOCAL void vgaSetAttrib (FAST VGA_CON_DEV *  pVgaConDv);
  157. LOCAL void vgaDelLines (FAST VGA_CON_DEV *  pVgaConDv);
  158. LOCAL void vgaDelRightChars (FAST VGA_CON_DEV *  pVgaConDv, int nDelChar);
  159. #endif /* INCLUDE_ANSI_ESC_SEQUENCE */
  160. /*******************************************************************************
  161. *
  162. * vgaConBeep - sound beep function (using timer 2 for tone)
  163. * This function is responsible for producing the beep 
  164. *
  165. * RETURNS: N/A
  166. *
  167. * NOMANUAL
  168. */
  169. LOCAL void vgaConBeep 
  170.     (
  171.     BOOL mode /* TRUE:long beep  FALSE:short beep */
  172.     )
  173.     {
  174.     int beepTime;
  175.     int beepPitch;
  176.     FAST int  oldlevel;
  177.     if (mode)
  178.         { 
  179.         beepPitch = BEEP_PITCH_L;
  180.         beepTime  = BEEP_TIME_L; /* long beep */
  181.         }
  182.     else
  183.         { 
  184.         beepPitch = BEEP_PITCH_S;
  185.         beepTime  = BEEP_TIME_S; /* short beep */
  186.         }
  187.     oldlevel = intLock ();
  188.     /* set command for counter 2, 2 byte write */
  189.     sysOutByte (PIT_BASE_ADR + 3, 0xb6);
  190.     sysOutByte (PIT_BASE_ADR + 2, (beepPitch & 0xff));
  191.     sysOutByte (PIT_BASE_ADR + 2, (beepPitch >> 8));
  192.     /* enable counter 2 */
  193.     sysOutByte (DIAG_CTRL, sysInByte (DIAG_CTRL) | 0x03);
  194.     taskDelay (beepTime);
  195.     /* desable counter 2 */
  196.     sysOutByte (DIAG_CTRL, sysInByte (DIAG_CTRL) & ~0x03);
  197.     intUnlock (oldlevel);
  198.     return;
  199.     }
  200. /******************************************************************************
  201. *
  202. * vgaHrdInit - initialize the VGA Display
  203. *
  204. * This function is called externally to initialize the vga display
  205. *
  206. * RETURNS: N/A
  207. *
  208. * NOMANUAL
  209. */
  210. void vgaHrdInit (void)
  211.     {
  212.     /* get cursor shape and mode */
  213.     sysOutByte ((int) CTRL_SEL_REG, 0x0a);
  214.     curSt = sysInByte ((int) CTRL_VAL_REG);
  215.     sysOutByte ((int) CTRL_SEL_REG, 0x0b);
  216.     curEd = sysInByte ((int) CTRL_VAL_REG);
  217.     vgaStatInit ();
  218.     /* clear screen and position cursor at 0,0 */
  219.     vgaClear (pcConDv [PC_CONSOLE].vs, 2,' ');
  220.     vgaCursorOn ();
  221.     return;
  222.     } 
  223. /*******************************************************************************
  224. *
  225. * vgaStatInit - initialize the VGA Display state
  226. *
  227. * RETURNS: N/A
  228. */
  229. LOCAL void vgaStatInit (void)
  230.     {
  231.     int ix; /* to hold the index */
  232.     FAST VGA_CON_DEV * pVgaConDv; /* pointer to hold vga descriptor */
  233.     for (ix = 0; ix < N_VIRTUAL_CONSOLES; ix++)
  234. {
  235. pcConDv [ix].vs = pVgaConDv = &vgaConDv [ix];
  236. /* (VGA) Display status initialization */
  237. pVgaConDv->memBase  = CTRL_MEM_BASE;
  238. pVgaConDv->colorMode     = COLOR_MODE;      /* color mode */   
  239. pVgaConDv->sv_col        = pVgaConDv->col   = 0;
  240. pVgaConDv->sv_row        = pVgaConDv->row   = 0;
  241. pVgaConDv->sv_curAttrib  = pVgaConDv->curAttrib = DEFAULT_ATR;
  242. pVgaConDv->defAttrib     = DEFAULT_ATR;
  243. pVgaConDv->curChrPos     = pVgaConDv->memBase;  /* current  position */
  244. pVgaConDv->sv_rev        = pVgaConDv->rev   = FALSE;
  245. pVgaConDv->ncol          = 80;                /* Number of columns */
  246. pVgaConDv->nrow          = 25;                /* Number of text rows */
  247. pVgaConDv->scst          = 0;                 /* scroll start */
  248. pVgaConDv->sced          = 24;                /* scroll end */
  249. pVgaConDv->autoWrap      = TRUE;              /* auto Wrap mode */
  250. pVgaConDv->scrollCheck   = FALSE;             /* scroll  flag off */
  251. pVgaConDv->charSet       = vgaCharTable [TEXT_SET]; /* character set */
  252. pVgaConDv->vgaMode       = TEXT_MODE;         /* video mode  */
  253. pVgaConDv->insMode       = INSERT_MODE_OFF;   /* insert mode */
  254. pVgaConDv->escFlags      = ESC_NORMAL;        /* normal character */
  255. pVgaConDv->escParaCount  = 0;                 /* zero parameters */
  256. pVgaConDv->escQuestion   = FALSE;             /* ? flag set to false */
  257. bzero ((char *)pVgaConDv->escPara, sizeof(pVgaConDv->escPara));
  258. bzero (pVgaConDv->tab_stop, sizeof(pVgaConDv->tab_stop));
  259. pVgaConDv->tab_stop [ 0] = 1;
  260. pVgaConDv->tab_stop [ 8] = 1;
  261. pVgaConDv->tab_stop [16] = 1;
  262. pVgaConDv->tab_stop [24] = 1;
  263. pVgaConDv->tab_stop [32] = 1;
  264. pVgaConDv->tab_stop [40] = 1;
  265. pVgaConDv->tab_stop [48] = 1;
  266. pVgaConDv->tab_stop [56] = 1;
  267. pVgaConDv->tab_stop [64] = 1;
  268. pVgaConDv->tab_stop [72] = 1;
  269. pVgaConDv->vgaHook  = (FUNCPTR) vgaHook; /* install the hook */
  270. }
  271.     return;
  272.     } 
  273. /******************************************************************************
  274. *
  275. * vgaHook - hook called from an external module
  276. * This function performs various functions depending on the opCode.
  277. * Typically this hook is to facilitate the user to add any additional
  278. * routines which can be accessed externally through the vga console
  279. * descriptor.
  280. *
  281. * RETURNS: N/A
  282. */
  283. LOCAL void vgaHook 
  284.     (
  285.     FAST VGA_CON_DEV *  pVgaConDv,      /* pointer to the vga descriptor */
  286.     int arg, /* argument */
  287.     int opCode /* operation to perform */
  288.     )
  289.     {
  290.     switch (opCode)
  291. {
  292. case 0:
  293.       vgaScreenRev (pVgaConDv); /* reverse screen */
  294.       break;
  295. case 1:
  296.       vgaConBeep (arg); /* produce beep */
  297.       break;
  298. case 2:
  299.       vgaCursorOn (); /* turn the cursor on */
  300.       break;
  301. case 3:
  302.       vgaCursorOff (); /* turn the cursor Off */
  303.       break;
  304. case 4: /* position the cursor */
  305.       pVgaConDv->row = (arg >> 8) & 0xff;
  306.       pVgaConDv->col = arg & 0xff;
  307.       if (pVgaConDv->row >= pVgaConDv->nrow)
  308.       pVgaConDv->row = pVgaConDv->nrow - 1;
  309.       if (pVgaConDv->col >= pVgaConDv->ncol)
  310.       pVgaConDv->col = pVgaConDv->ncol - 1;
  311.       vgaCursorPos ((UINT16) (pVgaConDv->row * pVgaConDv->ncol 
  312.       + pVgaConDv->col));
  313.       break;
  314. default:
  315.       break;
  316. }
  317.     }
  318. /******************************************************************************
  319. *
  320. * vgaClear - Clear Screen
  321. *
  322. * This routine clears the screen depending on the value of position.
  323. * If position is 2 then it clears the whole screen and moves the cursor to 
  324. * location 0,0. If position is 1 then the screen is erased from the cursor to
  325. * until the end of display. If position is equal to any other value then 
  326. * the screen is erased until the cursor.
  327. *
  328. * RETURNS: N/A
  329. */
  330. LOCAL void vgaClear 
  331.     (
  332.     FAST VGA_CON_DEV * pVgaConDv, /* pointer to the vga descriptor */
  333.     int position, /* cursor position  0 or 1 or 2 */
  334.     UCHAR eraseChar /* erase character eg space is  0x20 */
  335.     )
  336.     {
  337.     FAST UINT16 * cp; /* hold the beginning position */
  338.     FAST UINT16 * end; /* hold the end position */
  339.     FAST UINT16  erase; /* erase character with attribute */
  340.     erase = (pVgaConDv->defAttrib << 8) + eraseChar;
  341.     if ( position == 2 )
  342. cp  = (UINT16 *) pVgaConDv->memBase;
  343. end = (UINT16 *) (pVgaConDv->memBase + 2048 * CHR);
  344. pVgaConDv->col = pVgaConDv->row = 0;
  345. pVgaConDv->curChrPos = (UCHAR *) pVgaConDv->memBase;
  346. }
  347.     else if ( position == 0 )
  348. cp  = (UINT16 *)pVgaConDv->curChrPos;
  349. end = (UINT16 *)(pVgaConDv->memBase + 2048 * CHR);
  350. }
  351.     else  
  352. {
  353. cp  = (UINT16 *) pVgaConDv->memBase;
  354. end = (UINT16 *) (pVgaConDv->curChrPos + CHR);
  355. }
  356.     for (; cp < end; cp++ )
  357.         {
  358.         *cp     = erase;  
  359.         }
  360.     }
  361. /******************************************************************************
  362. *
  363. * vgaScreenRev - Reverse Screen
  364. *
  365. * RETURNS: N/A
  366. */
  367. LOCAL void vgaScreenRev 
  368.     (
  369.     FAST VGA_CON_DEV * pVgaConDv /* pointer to the vga descriptor */
  370.     )
  371.     {
  372.     UCHAR * cp; /* to hold the current pointer */
  373.     UCHAR atr; /* to hold the attribute character */
  374.     for (cp = pVgaConDv->memBase; cp < pVgaConDv->memBase + 2000 * CHR; 
  375.  cp += CHR)
  376.         {
  377.         atr = *(cp+1);
  378.         *(cp+1)  = atr & INT_BLINK_MASK;
  379.         *(cp+1) |= (atr << 4) & BG_ATTR_MASK;
  380.         *(cp+1) |= (atr >> 4) & FG_ATTR_MASK;
  381.         }
  382.     }
  383. /*******************************************************************************
  384. *
  385. * vgaScroll - Scroll Screen
  386. *
  387. * This function scrolls the screen according to the scroll direction.
  388. * scroll direction FORWARD or BACKWARD 
  389. *
  390. * RETURNS: N/A
  391. */
  392. LOCAL void vgaScroll 
  393.     (
  394.     FAST VGA_CON_DEV * pVgaConDv, /* pointer to the vga descriptor */
  395.     int pos, /* scroll start line position */
  396.     int lines, /* scroll line count */
  397.     BOOL upDn, /* scroll direction  */
  398.     FAST UCHAR atr /* atrribute for char */
  399.     )
  400.     {
  401.     FAST UCHAR * dest; /* to hold the destination pointer */
  402.     FAST UCHAR * src; /* to hold the source pointer */
  403.     if (pos < pVgaConDv->scst || pos > pVgaConDv->sced)
  404.         return;
  405.     if (upDn)
  406.         {
  407. /* scroll direction is forward */
  408.         if (pVgaConDv->scst + lines > pVgaConDv->sced + 1)
  409.             lines = pVgaConDv->sced - pVgaConDv->scst + 1;
  410.         for (dest = pVgaConDv->memBase + pVgaConDv->ncol * CHR * 
  411.      pVgaConDv->scst, src = pVgaConDv->memBase + pVgaConDv->ncol * 
  412.      CHR * (pVgaConDv->scst + lines); src < pVgaConDv->memBase + 
  413.      pVgaConDv->ncol * CHR * (pos + 1); *dest++ = *src++ );
  414.         for (dest = pVgaConDv->memBase + pVgaConDv->ncol * CHR * 
  415.      (pos - (lines - 1)); dest < pVgaConDv->memBase + pVgaConDv->ncol *
  416.      CHR * (pos + 1); dest += CHR )
  417.             {
  418.             *dest     = ' ';
  419.             *(dest+1) = atr;
  420.             }
  421.         }
  422.     else
  423.         {
  424. /* scroll direction is backward */
  425.         if (pVgaConDv->scst + lines > pVgaConDv->sced + 1)
  426.             lines = pVgaConDv->sced - pVgaConDv->scst + 1;
  427.         for (dest = pVgaConDv->memBase + pVgaConDv->ncol * CHR * 
  428.      (pVgaConDv->sced + 1) - 1, src = pVgaConDv->memBase + 
  429.      pVgaConDv->ncol * CHR * (pVgaConDv->sced - (lines - 1)) - 1;
  430.              src > pVgaConDv->memBase + pVgaConDv->ncol * CHR * pos - 1;
  431.              *dest-- = *src-- );
  432.         for (dest = pVgaConDv->memBase + pVgaConDv->ncol * CHR * 
  433.      (pos + lines) - 1; dest > pVgaConDv->memBase + pVgaConDv->ncol * 
  434.      CHR * pos - 1;
  435.              dest -= CHR )
  436.             {
  437.             *dest     = atr;
  438.             *(dest-1) = ' ';
  439.             }
  440.         }
  441.     return;
  442.     }
  443. /*****************************************************************************
  444. *
  445. * vgaInsertChar - insert the character at the current cursor location
  446. *
  447. * RETURNS: N/A
  448. */
  449. LOCAL void vgaInsertChar
  450.     (
  451.     FAST VGA_CON_DEV * pVgaConDv, /* pointer to the vga descriptor */
  452.     FAST int nInsChar /* number of insert Characters */
  453.     )
  454.     {
  455.     FAST int xPos ;  /* to hold the horizontal position  */
  456.     FAST UINT16    erase; /* to hold erase character with attribute */
  457.     FAST UINT16    swap; /* to hold old x position */
  458.     FAST UINT16 * chrPos; /* to hold actual address of character */
  459.     if (nInsChar > pVgaConDv->ncol)
  460. nInsChar = pVgaConDv->ncol;
  461.     else if (nInsChar == 0) 
  462. nInsChar = 1;
  463.     
  464.     while (nInsChar-- != 0)
  465. {
  466. xPos   = pVgaConDv->col;
  467. chrPos = (UINT16 *) pVgaConDv->curChrPos;
  468. erase  = (pVgaConDv->defAttrib << 8) + ' ' ; 
  469. while (xPos++ < pVgaConDv->ncol)
  470.     {
  471.     /* make the current character as next erase */
  472.     swap    = *chrPos;
  473.     *chrPos = erase ; 
  474.     erase   = swap;   
  475.     chrPos++;
  476.     }
  477. }
  478.     }
  479. /*****************************************************************************
  480. *
  481. * vgaDelLeftChar - delete the character to the left side of the cursor
  482. *
  483. * RETURNS: N/A
  484. */
  485. LOCAL void vgaDelLeftChar 
  486.     (
  487.     FAST VGA_CON_DEV * pVgaConDv /* pointer to the vga descriptor */
  488.     )
  489.     {
  490.     FAST UINT16 erase; /* erase character with attributes */
  491.     erase = (pVgaConDv->defAttrib << 8) + ' ' ;
  492.     if (pVgaConDv->autoWrap || pVgaConDv->ncol > 0)
  493. {
  494. pVgaConDv->col--;
  495. pVgaConDv->curChrPos -= CHR;
  496. }
  497.     *(UINT16 *)pVgaConDv->curChrPos = erase;
  498.     }
  499. /*****************************************************************************
  500. *
  501. * vgaCarriageReturn - do a carriage return on the monitor
  502. *
  503. * RETURNS: N/A
  504. */
  505. LOCAL void vgaCarriageReturn 
  506.     (
  507.     FAST VGA_CON_DEV * pVgaConDv /* pointer to the vga descriptor */
  508.     )
  509.     {
  510.     pVgaConDv->curChrPos -= pVgaConDv->col * CHR;
  511.     pVgaConDv->col = 0;
  512.     }
  513. /*****************************************************************************
  514. *
  515. * vgaBackSpace - do a back space on the monitor
  516. *
  517. * RETURNS: N/A
  518. */
  519. LOCAL void vgaBackSpace 
  520.     (
  521.     FAST VGA_CON_DEV * pVgaConDv /* pointer to the vga descriptor */
  522.     )
  523.     {
  524.     if (pVgaConDv->autoWrap || pVgaConDv->ncol > 0)
  525. {
  526. pVgaConDv->col--;
  527. pVgaConDv->curChrPos -= CHR;
  528. }
  529.     if (pVgaConDv->col < 0)
  530. {
  531. pVgaConDv->col = pVgaConDv->ncol - 1;
  532. pVgaConDv->row--;
  533. pVgaConDv->scrollCheck = TRUE;
  534. }
  535.     }
  536. /*****************************************************************************
  537. *
  538. * vgaTab - do a tab on the monitor
  539. *
  540. * RETURNS: N/A
  541. */
  542. LOCAL void vgaTab 
  543.     (
  544.     FAST VGA_CON_DEV * pVgaConDv /* pointer to the vga descriptor */
  545.     )
  546.     {
  547.     int ix;
  548.     for (ix = pVgaConDv->col + 1; ix < 80; ix++)
  549. {
  550. if (pVgaConDv->tab_stop [ix])
  551.     {
  552.     pVgaConDv->col = ix;
  553.     break;
  554.     }
  555. }
  556.     if (pVgaConDv->autoWrap && ix >= 80)
  557. {
  558. pVgaConDv->col = 0;
  559. pVgaConDv->row++;
  560. pVgaConDv->scrollCheck = TRUE;
  561. }
  562.     pVgaConDv->curChrPos = ( pVgaConDv->memBase + 
  563.     pVgaConDv->row * pVgaConDv->ncol * CHR + 
  564.     pVgaConDv->col * CHR) ;
  565.     }
  566. /******************************************************************************
  567. *
  568. * vgaLineFeed - do a line feed on the monitor
  569. *
  570. * RETURNS: N/A
  571. */
  572. LOCAL void vgaLineFeed 
  573.     (
  574.     FAST VGA_CON_DEV * pVgaConDv /* pointer to the vga descriptor */
  575.     )
  576.     {
  577.     pVgaConDv->curChrPos += pVgaConDv->ncol * CHR;
  578.     pVgaConDv->row++;
  579.     pVgaConDv->scrollCheck = TRUE;
  580.     }
  581. /******************************************************************************
  582. *
  583. * vgaCursorPos - Put the cursor at a specified location
  584. *
  585. * RETURNS: N/A
  586. */
  587. LOCAL void vgaCursorPos 
  588.     (
  589.     FAST UINT16 pos /* position of the cursor */
  590.     )
  591.     {
  592.     sysOutByte ((int) CTRL_SEL_REG, 0x0e);
  593.     sysOutByte ((int) CTRL_VAL_REG, (pos >> 8) & 0xff);
  594.     sysOutByte ((int) CTRL_SEL_REG, 0x0f);
  595.     sysOutByte ((int) CTRL_VAL_REG, pos & 0xff);
  596.     return;
  597.     }
  598. /******************************************************************************
  599. *
  600. * vgaCursorOn - switch the cursor on
  601. *
  602. * RETURNS: N/A
  603. */
  604. LOCAL void vgaCursorOn (void)
  605.     {
  606.     sysOutByte ((int) CTRL_SEL_REG, 0x0a);
  607.     sysOutByte ((int) CTRL_VAL_REG, curSt & ~0x20);
  608.     sysOutByte ((int) CTRL_SEL_REG, 0x0b);
  609.     sysOutByte ((int) CTRL_VAL_REG, curEd);
  610.     return;
  611.     }
  612. /******************************************************************************
  613. *
  614. * vgacursoroff - swith the cursor off
  615. *
  616. * RETURNS: N/A
  617. */
  618. LOCAL void vgaCursorOff (void)
  619.     {
  620.     sysOutByte ((int) CTRL_SEL_REG, 0x0a);
  621.     sysOutByte ((int) CTRL_VAL_REG, 0x20);
  622.     sysOutByte ((int) CTRL_SEL_REG, 0x0b);
  623.     sysOutByte ((int) CTRL_VAL_REG, 0x00);
  624.     return;
  625.     }
  626. /*******************************************************************************
  627. *
  628. * vgaWriteString - Write Character string  to VGA Display
  629. * This function does the write to the vga routine. This routine is provided as
  630. * transmitter startup routine when tyDevInit is called.
  631. *
  632. * RETURNS: number of bytes written to the screen
  633. *
  634. * NOMANUAL
  635. */
  636. int vgaWriteString
  637.     (
  638.     FAST PC_CON_DEV * pPcCoDv /* pointer to the console descriptor */
  639.     )
  640.     {
  641.     int dummy;
  642.     UCHAR ch;
  643.     FAST int nBytes;
  644.     FAST UCHAR atr;
  645.     FAST RING_ID        ringId = pPcCoDv->tyDev.wrtBuf;
  646.     FAST VGA_CON_DEV * pVgaConDv = pPcCoDv->vs;
  647.     
  648.     pPcCoDv->tyDev.wrtState.busy = TRUE;
  649.     atr = pVgaConDv->curAttrib;
  650.     nBytes = 0;
  651.     
  652.     /* check if we need to output XON/XOFF for the read side */
  653.     if (pPcCoDv->tyDev.wrtState.xoff || pPcCoDv->tyDev.wrtState.flushingWrtBuf)
  654. {
  655.      pPcCoDv->tyDev.wrtState.busy = FALSE;
  656. return nBytes;
  657. }
  658.     while (RNG_ELEM_GET (ringId,&ch,dummy) != 0)
  659.         {
  660. nBytes++; /* increment the number of bytes */
  661. /* If character is normal and printable */
  662. if ( (pVgaConDv->escFlags == ESC_NORMAL) && (pVgaConDv->charSet [ch]
  663.      != 0))
  664.     {
  665.     *(UINT16 *)pVgaConDv->curChrPos = (atr << 8) + 
  666.                                   pVgaConDv->charSet [ch];
  667.     if (pVgaConDv->col == pVgaConDv->ncol - 1)
  668. if (pVgaConDv->autoWrap)
  669.     { 
  670.     vgaCarriageReturn (pVgaConDv); /* time to wrap */
  671.     vgaLineFeed (pVgaConDv);
  672.     goto VGA_CHECK; /* go do the wrap check */
  673.     }
  674. }
  675.     else
  676. {
  677. pVgaConDv->col++;
  678. pVgaConDv->curChrPos += CHR;
  679. continue;
  680. }
  681.     }
  682. switch (ch)
  683.     {
  684.     case 0x07: /* BEL */
  685.          vgaConBeep (FALSE);
  686.  continue;
  687.     
  688.     case 0x08: /* Back Space */
  689.  vgaBackSpace (pVgaConDv);
  690.  continue;
  691.             case 't': /* TAB code */
  692.  vgaTab (pVgaConDv);
  693.  continue;
  694.             case 'n': /* LF code */
  695.  if ((pPcCoDv->tyDev.options & OPT_CRMOD) == OPT_CRMOD)
  696.     vgaCarriageReturn (pVgaConDv);
  697.  vgaLineFeed (pVgaConDv);
  698.  goto VGA_CHECK;
  699.             case 0x0b: /* VT code */
  700.  vgaLineFeed (pVgaConDv);
  701.  goto VGA_CHECK;
  702.             case 0x0c: /* Clear Screen code */
  703.  vgaClear (pVgaConDv, 2, ' ');
  704.  continue;
  705.     case 0x0d: /* CR code */
  706.  vgaCarriageReturn (pVgaConDv);
  707.  continue;
  708. #ifdef INCLUDE_ANSI_ESC_SEQUENCE
  709.     case 0x1b: /* escape character */
  710.  pVgaConDv->escFlags = ESC_ESC;
  711.  continue; 
  712.             case 0x9b: /* escape brace */
  713.  pVgaConDv->escFlags = ESC_BRACE;
  714.  continue;
  715. #endif /* INCLUDE_ANSI_ESC_SEQUENCE */
  716.     case 0x0e: /* set the character set to VT100 graphics */
  717.  pVgaConDv->charSet = vgaCharTable [GRAPHICS_VT100_SET];
  718.  continue;
  719.             case 0x0f: /* set the character set to normal text set */
  720.  pVgaConDv->charSet = vgaCharTable [TEXT_SET];
  721.  continue;
  722.     case 0x7f: /* special character for del */
  723.  vgaDelLeftChar (pVgaConDv);
  724.  continue;
  725.   }
  726. #ifdef INCLUDE_ANSI_ESC_SEQUENCE
  727. switch (pVgaConDv->escFlags)
  728.     {
  729.     int  ix; /* to hold temp data */
  730.     case ESC_ESC:
  731.             pVgaConDv->escFlags = ESC_NORMAL;
  732.     switch (ch)
  733. {
  734. case '[': /* escape brace */
  735. pVgaConDv->escFlags = ESC_BRACE;
  736. continue;
  737. case 'E': /* cr lf */
  738. vgaCarriageReturn (pVgaConDv);
  739. vgaLineFeed (pVgaConDv);
  740. goto VGA_CHECK;
  741. case 'M': /* cursor up */
  742. pVgaConDv->row --;
  743. vgaPutCursor (pVgaConDv);
  744. continue;
  745. case 'D': /* generate a linefeed */
  746. vgaLineFeed (pVgaConDv);
  747. goto VGA_CHECK;
  748. case 'H': /* give tab */
  749. vgaTab (pVgaConDv);
  750. continue;
  751. case 'Z': /* get device attribute */
  752. vgaEscResponse (pPcCoDv,2);
  753. continue;
  754. case '7': /* save current attributes */
  755. vgaSaveCurAttrib (pVgaConDv);
  756. continue;
  757. case '8': /* restore current attributes */
  758. vgaRestAttrib (pVgaConDv);
  759. continue;
  760. case '(': /* set character set to text */
  761. pVgaConDv->escFlags = ESC_SET_TEXT;
  762. continue;
  763. case ')': /* set character set to grapics set */
  764. pVgaConDv->escFlags = ESC_SET_GPRAHICS;
  765. continue;
  766. case '#': /* goto ESC_HASH state */
  767. pVgaConDv->escFlags = ESC_HASH;
  768. continue;
  769. case 'c': /* reset display */
  770. pPcCoDv->ks->kbdHook (0);
  771. vgaStatInit ();
  772. vgaClear (pVgaConDv, 2, ' ');
  773. vgaCursorOn ();
  774. continue;
  775. case '>': /* set numeric mode */
  776. pPcCoDv->ks->kbdFlags |= NUM;
  777. pPcCoDv->ks->kbdHook (1);
  778. continue;
  779. case '=': /* set non numeric mode */
  780. pPcCoDv->ks->kbdFlags &= ~NUM;
  781. pPcCoDv->ks->kbdHook (1);
  782. continue;
  783.             }
  784.     continue;
  785.     case ESC_BRACE: /* Got ESC [ */
  786.             for (ix = 0; ix < NPARS; ix++)
  787.         pVgaConDv->escPara [ix] = 0;
  788.     pVgaConDv->escParaCount = 0;
  789.             pVgaConDv->escFlags = ESC_GET_PARAMS;
  790.     if ( ch == '[')
  791. {
  792. pVgaConDv->escFlags = ESC_FUNC_KEY;
  793. continue;
  794. }
  795.             /* if received ? in the escape sequence */
  796.     if ( (pVgaConDv->escQuestion = (ch == '?')) )
  797.        continue;
  798.     case ESC_GET_PARAMS: /* get parameters */
  799.     if ( (ch == ';') && (pVgaConDv->escParaCount < NPARS -1))
  800. {
  801. pVgaConDv->escParaCount++;
  802. continue;
  803. }
  804.     else if (ch >= '0' && ch <= '9')
  805. {
  806. pVgaConDv->escPara[pVgaConDv->escParaCount] *= 10;
  807. pVgaConDv->escPara[pVgaConDv->escParaCount] += ch -'0';
  808. continue;
  809. }
  810.     else
  811.         pVgaConDv->escFlags = ESC_GOT_PARAMS;
  812.     case ESC_GOT_PARAMS:
  813.     pVgaConDv->escFlags = ESC_NORMAL;
  814.     switch (ch)
  815. {
  816. case 'h': /* set vga modes  ESC [ n h */
  817.         vgaSetMode (pPcCoDv, TRUE);
  818. continue;
  819. case 'l': /* reset vga mode  ESC [ n l */
  820. vgaSetMode (pPcCoDv, FALSE);
  821. continue;
  822. case 'n':
  823. if (!pVgaConDv->escQuestion)
  824.     {
  825.     if (pVgaConDv->escPara [0] == 5)
  826. { /* status report */
  827. vgaEscResponse (pPcCoDv,1);
  828. }
  829.     else if ( pVgaConDv->escPara [0] == 6)
  830. { /* cursor position report */
  831. vgaEscResponse (pPcCoDv,0);
  832. }
  833.     continue;
  834.     }
  835. }
  836.     if (pVgaConDv->escQuestion) 
  837. {
  838. pVgaConDv->escQuestion = FALSE;
  839. continue;
  840. }
  841.     switch (ch)
  842. {
  843. case 'G': /* ESC [ n G :move cursor by columns */
  844.         if (pVgaConDv->escPara [0] > 0)
  845.     pVgaConDv->escPara [0]--;
  846. pVgaConDv->col = pVgaConDv->escPara [0];
  847. vgaPutCursor (pVgaConDv);
  848. continue;
  849. case 'A': /* ESC [ n A :cursor move up */
  850.         if (pVgaConDv->escPara [0] == 0)
  851.     pVgaConDv->escPara [0]++;
  852. pVgaConDv->row -= pVgaConDv->escPara [0];
  853. vgaPutCursor (pVgaConDv);
  854.                                 continue;
  855. case 'B': /* ESC [ n B :cursor move down */
  856.         if (pVgaConDv->escPara [0] == 0)
  857.     pVgaConDv->escPara [0]++;
  858. pVgaConDv->row += pVgaConDv->escPara [0];
  859. vgaPutCursor (pVgaConDv);
  860. continue;
  861. case 'C': /* ESC [ n C :cursor move right */
  862.         if (pVgaConDv->escPara [0] == 0)
  863.     pVgaConDv->escPara [0]++;
  864. pVgaConDv->col += pVgaConDv->escPara [0];
  865. vgaPutCursor (pVgaConDv);
  866. continue;
  867. case 'D': /* ESC [ n D :cursor move left */
  868.         if (pVgaConDv->escPara [0] == 0)
  869.     pVgaConDv->escPara [0]++;
  870. pVgaConDv->col -= pVgaConDv->escPara [0];
  871. vgaPutCursor (pVgaConDv);
  872. continue;
  873. case 'E': /* ESC [ n E :cursor move by n rows */
  874.         if (pVgaConDv->escPara [0] == 0)
  875.     pVgaConDv->escPara [0]++;
  876. pVgaConDv->row += pVgaConDv->escPara [0];
  877. pVgaConDv->col = 0;
  878. vgaPutCursor (pVgaConDv);
  879. continue;
  880. case 'F': /* ESC [ n F :move cursor laterally */
  881.         if (pVgaConDv->escPara [0] == 0)
  882.     pVgaConDv->escPara [0]++;
  883. pVgaConDv->row -= pVgaConDv->escPara [0];
  884. pVgaConDv->col = 0;
  885. vgaPutCursor (pVgaConDv);
  886. continue;
  887. case 'd': /* ESC [ n d :move cursor vertically */
  888.         if (pVgaConDv->escPara [0] > 0)
  889.     pVgaConDv->escPara [0]--;
  890. pVgaConDv->row = pVgaConDv->escPara [0];
  891. vgaPutCursor (pVgaConDv);
  892. continue;
  893. case 'H': /* ESC [ n;n H :position the cursor */
  894.                         case 'f': /* ESC [ n;n f :position the cursor */
  895.         if (pVgaConDv->escPara [0] > 0)
  896.     pVgaConDv->escPara [0]--;
  897.         if (pVgaConDv->escPara [1] > 0)
  898.     pVgaConDv->escPara [1]--;
  899. pVgaConDv->row = pVgaConDv->escPara [0];
  900. pVgaConDv->col = pVgaConDv->escPara [1];
  901. vgaPutCursor (pVgaConDv);
  902. continue;
  903. case 'J': /* ESC [ n J :clear display */
  904. vgaClear (pVgaConDv, pVgaConDv->escPara [0],
  905.   ' ');
  906. continue;
  907. case 'K': /* ESC [ n K :clear Line */
  908. vgaClearLine (pVgaConDv);
  909. continue;
  910.    
  911. case 'L': /* ESC [ n L :insert Lines */
  912. vgaInsertLine (pVgaConDv);
  913. continue;
  914. case 'M': /* ESC [ n M :delete lines */
  915. vgaDelLines (pVgaConDv);
  916. continue;
  917. case 'P': /* ESC [ n P :delete on right side */
  918. vgaDelRightChars (pVgaConDv, 
  919.   pVgaConDv->escPara [0]);
  920. continue;
  921. case 'c': /* ESC [ n c :get response from term */
  922. if ( pVgaConDv->escPara [0] == 0 )
  923.     vgaEscResponse (pPcCoDv,2);
  924. continue;
  925. case 'g': /* ESC [ n g :give tabs */
  926. if ( pVgaConDv->escPara [0] == 0 )
  927.     {
  928.     vgaTab (pVgaConDv);
  929.     }
  930. else if ( pVgaConDv->escPara [0] == 3)
  931.     {
  932.     pVgaConDv->tab_stop [0] = 0; 
  933.     pVgaConDv->tab_stop [1] = 0;
  934.     pVgaConDv->tab_stop [2] = 0;
  935.     pVgaConDv->tab_stop [3] = 0;
  936.     pVgaConDv->tab_stop [4] = 0;
  937.     }
  938. continue;
  939. case 'm': /* ESC [ m :set the attributes */
  940. vgaSetAttrib (pVgaConDv);
  941. continue;
  942. case 'r': /* ESC [ n;n r : set scroll limits */
  943. if (pVgaConDv->escPara [0] == 0)
  944.     pVgaConDv->escPara [0]++;
  945. if (pVgaConDv->escPara [1] == 0)
  946.     pVgaConDv->escPara[1] = pVgaConDv->ncol-1;
  947. if ((pVgaConDv->escPara [0] < 
  948.     pVgaConDv->escPara [1]) && 
  949.     (pVgaConDv->escPara [1] < pVgaConDv->ncol))
  950.     {
  951.     pVgaConDv->scst = pVgaConDv->escPara [0] -
  952.            1;
  953.     pVgaConDv->sced = pVgaConDv->escPara [1];
  954.     pVgaConDv->row = 0;
  955.     vgaPutCursor (pVgaConDv);
  956.     }
  957. continue;
  958. case 's': /* ESC [ s :save attributes */
  959. vgaSaveCurAttrib (pVgaConDv);
  960. continue;
  961. case 'u': /* ESC [ u :restore attributes */
  962. vgaRestAttrib (pVgaConDv);
  963. continue;
  964. case '@': /* ESC [ n @ :insert n characters */
  965. vgaInsertChar (pVgaConDv, 
  966.        pVgaConDv->escPara [0]);
  967. continue;
  968. }
  969.     
  970.     continue;
  971.     case ESC_FUNC_KEY:
  972.     pVgaConDv->escFlags = ESC_NORMAL;
  973.     continue;
  974.     case ESC_HASH:
  975.     pVgaConDv->escFlags = ESC_NORMAL;
  976.     if ( ch == '8' )
  977.        vgaClear (pVgaConDv, 2, 'E'); /* erase char to 'E' */
  978.     continue;
  979.     
  980.     case ESC_SET_TEXT:
  981.     case ESC_SET_GPRAHICS:
  982.     if ( ch == 'O' )
  983.        pVgaConDv->charSet = vgaCharTable [GRAPHICS_VT100_SET];
  984.     else if ( ch == 'B')
  985. {
  986. pVgaConDv->charSet = vgaCharTable [TEXT_SET];
  987. pVgaConDv->escFlags = ESC_NORMAL;
  988. }
  989.     else if ( ch == 'U')
  990. {
  991. pVgaConDv->charSet = vgaCharTable [IBM_GRAPHICS_SET];
  992. pVgaConDv->escFlags = ESC_NORMAL;
  993. }
  994.     continue;
  995.     default:
  996.     pVgaConDv->escFlags = ESC_NORMAL;
  997.     }
  998. #endif /* INCLUDE_ANSI_ESC_SEQUENCE */
  999. VGA_CHECK: /* label for checking at the end of the loop */
  1000.     {
  1001.     if (pVgaConDv->scrollCheck && pVgaConDv->curChrPos >= 
  1002. pVgaConDv->memBase + pVgaConDv->ncol * CHR * (pVgaConDv->sced 
  1003.       + 1))
  1004. /* forward scroll check */
  1005. pVgaConDv->row = pVgaConDv->sced;
  1006. vgaScroll (pVgaConDv, pVgaConDv->row, pVgaConDv->scrollCheck,
  1007.    FORWARD, pVgaConDv->defAttrib);
  1008. while (pVgaConDv->curChrPos >= pVgaConDv->memBase + 
  1009.        pVgaConDv->ncol * CHR * (pVgaConDv->sced + 1))
  1010. pVgaConDv->curChrPos -= pVgaConDv->ncol * CHR;
  1011. }
  1012.     else if (pVgaConDv->scrollCheck && pVgaConDv->curChrPos < 
  1013.      pVgaConDv->memBase + pVgaConDv->col * CHR * 
  1014.      pVgaConDv->scst)
  1015. {
  1016. /* rearword scroll check */
  1017. pVgaConDv->row = pVgaConDv->scst;
  1018. vgaScroll (pVgaConDv, pVgaConDv->row, pVgaConDv->scrollCheck,
  1019.    BACKWARD, pVgaConDv->defAttrib);
  1020. while (pVgaConDv->curChrPos < pVgaConDv->memBase + 
  1021.        pVgaConDv->col * CHR * pVgaConDv->scst)
  1022. pVgaConDv->curChrPos += pVgaConDv->ncol * CHR;
  1023. }
  1024.     else if (pVgaConDv->curChrPos > pVgaConDv->memBase + 
  1025.      pVgaConDv->ncol * CHR * pVgaConDv->nrow)
  1026. /* out of range check (over) */
  1027. while (pVgaConDv->curChrPos > pVgaConDv->memBase + 
  1028.        pVgaConDv->ncol * CHR * pVgaConDv->nrow)
  1029.     {
  1030.     pVgaConDv->curChrPos -= pVgaConDv->ncol * CHR;
  1031.     pVgaConDv->row--;
  1032.     }
  1033. }
  1034.     else if (pVgaConDv->curChrPos < pVgaConDv->memBase)
  1035. /* out of range check (under) */
  1036. while (pVgaConDv->curChrPos < pVgaConDv->memBase)
  1037.     {
  1038.     pVgaConDv->curChrPos += pVgaConDv->ncol * CHR;
  1039.     pVgaConDv->row++;
  1040.     }
  1041. }
  1042.     } /* VGA_CHECK: */
  1043. /* this line prevents the workQ panic */
  1044. if ((intContext()) && (nBytes >= jobaddThreshold))
  1045.     {
  1046.     excJobAdd ((VOIDFUNCPTR)vgaWriteString, (int)pPcCoDv, 0,0,0,0,0);
  1047.     return (nBytes);
  1048.     }
  1049. } /* end of the main for loop */
  1050.     vgaCursorPos ((pVgaConDv->curChrPos - pVgaConDv->memBase) / CHR );
  1051.     pPcCoDv->tyDev.wrtState.busy = FALSE;
  1052.     /* when we pass the write threshhold, give write synchonization
  1053.      * and release tasks pended in select */
  1054.     
  1055.     if (rngFreeBytes (ringId) >= tyWrtThreshold)
  1056.             {
  1057.             semGive (&pPcCoDv->tyDev.wrtSyncSem);
  1058.             if (_func_selWakeupAll != NULL)
  1059.                 (* _func_selWakeupAll) (&pPcCoDv->tyDev.selWakeupList, 
  1060. SELWRITE);
  1061.     }
  1062.     return nBytes; /* return the number of characters processed */
  1063.     }
  1064. #ifdef INCLUDE_ANSI_ESC_SEQUENCE
  1065.     
  1066. /*****************************************************************************
  1067. *
  1068. * vgaEscResponse - This function gives back a response to an escape sequence.
  1069. *                  The valid response Ids are 
  1070. *                  0 for cursor position, 1 for terminal status, 
  1071. *                  2 for terminal device attributes.
  1072. *
  1073. * RETURNS: N/A
  1074. */
  1075. LOCAL void vgaEscResponse
  1076.     (
  1077.     FAST PC_CON_DEV * pPcCoDv, /* pointer to the console descriptor */
  1078.     int responseId /* response Id */
  1079.     )
  1080.     {
  1081.     FAST VGA_CON_DEV * pVgaConDv; /* pointer to the vga descriptor */
  1082.     pVgaConDv = pPcCoDv->vs;
  1083.     tyIoctl (&pPcCoDv->tyDev, FIORFLUSH, 0);
  1084.     if ( responseId == 0)
  1085. {
  1086. sprintf (pVgaConDv->escResp, "33[%d;%dR",pVgaConDv->row, 
  1087.  pVgaConDv->col );
  1088. }
  1089.     else if ( responseId == 1) 
  1090. {
  1091. sprintf (pVgaConDv->escResp, "33[0n");
  1092. }
  1093.     else if ( responseId == 2)
  1094. {
  1095. sprintf (pVgaConDv->escResp, "33[?1;0c");
  1096. }
  1097.     else
  1098. {
  1099. pVgaConDv->escResp[0] = '';
  1100. }
  1101.     
  1102.     rngBufPut (pPcCoDv->tyDev.rdBuf, pVgaConDv->escResp, 
  1103.        strlen (pVgaConDv->escResp) );
  1104.     semGive (&pPcCoDv->tyDev.rdSyncSem);
  1105.     selWakeupAll (&pPcCoDv->tyDev.selWakeupList, SELREAD);
  1106.     }
  1107. /*****************************************************************************
  1108. *
  1109. * vgaSaveCurAttrib - saves all the current attributes, cursor position
  1110. *                    screen reverse mode.
  1111. *
  1112. * RETURNS: N/A
  1113. */
  1114. LOCAL void vgaSaveCurAttrib 
  1115.     (
  1116.     FAST VGA_CON_DEV * pVgaConDv /* pointer to the vga descriptor */
  1117.     )
  1118.     {
  1119.     pVgaConDv->sv_rev       = pVgaConDv->rev;
  1120.     pVgaConDv->sv_col       = pVgaConDv->col;
  1121.     pVgaConDv->sv_row       = pVgaConDv->row;
  1122.     pVgaConDv->sv_curAttrib = pVgaConDv->curAttrib;
  1123.     }
  1124.     
  1125. /*****************************************************************************
  1126. *
  1127. * vgaRestAttrib - restores all the saved attributes, cursor position
  1128. *                    screen reverse mode.
  1129. *
  1130. * RETURNS: N/A
  1131. */
  1132. LOCAL void vgaRestAttrib 
  1133.     (
  1134.     FAST VGA_CON_DEV * pVgaConDv /* pointer to the vga descriptor */
  1135.     )
  1136.     {
  1137.     pVgaConDv->rev       = pVgaConDv->sv_rev;
  1138.     pVgaConDv->col       = pVgaConDv->sv_col;
  1139.     pVgaConDv->row       = pVgaConDv->sv_row;
  1140.     pVgaConDv->curAttrib = pVgaConDv->sv_curAttrib;
  1141.     
  1142.     }
  1143. /*****************************************************************************
  1144. *
  1145. * vgaSetAttrib - sets various attributes 
  1146. *
  1147. * RETURNS: N/A
  1148. */
  1149. LOCAL void vgaSetAttrib 
  1150.     (
  1151.     FAST VGA_CON_DEV * pVgaConDv /* pointer to the vga descriptor */
  1152.     )  
  1153.     {
  1154.     FAST int ix; /* register to hold the index */
  1155.     FAST UCHAR attr; /* register to hold the current attribute */
  1156.     
  1157.     attr = pVgaConDv->curAttrib;
  1158.     for (ix = 0 ; ix <= pVgaConDv->escParaCount; ix++)
  1159. {
  1160. switch (pVgaConDv->escPara [ix])
  1161.     {
  1162.     case 0:
  1163.           attr =  DEFAULT_ATR;
  1164.   break;
  1165.   
  1166.             case 1:
  1167.   attr |= ATRB_BRIGHT; /* set intensity */
  1168.   break;
  1169.        
  1170.     case 4:
  1171.   if (!pVgaConDv->colorMode)
  1172.       {
  1173.       attr |= UNDERLINE;
  1174.       }
  1175.   break;
  1176.   
  1177.     case 5:
  1178.   attr |= ATRB_BLINK; /* toggle blinking */
  1179.   break;
  1180.     case 7:
  1181.   pVgaConDv->rev = TRUE; /* set reverse mode */
  1182.   attr = (attr & 0x88) | (((attr >> 4) | ((attr << 4) & 0x7)));
  1183.   break;
  1184.   
  1185.     case 21:
  1186.     case 22:
  1187.   attr &= ~ATRB_BRIGHT; /* reset brightness */
  1188.   break;
  1189.   
  1190.     case 24:
  1191.   if (!pVgaConDv->colorMode)
  1192.       {
  1193.       attr &= ~UNDERLINE; /* reset underline mode */
  1194.       }
  1195.   break;
  1196.   
  1197.     case 25:
  1198.   attr &= ~ATRB_BLINK;
  1199.   break;
  1200.     case 27:
  1201.   pVgaConDv->rev = FALSE;  /* reset reverse mode */
  1202.   break;
  1203.     default:
  1204.   /* set foreground and background attribute */
  1205.   if ((pVgaConDv->escPara [ix] >= 30) && 
  1206.       (pVgaConDv->escPara [ix] <= 37) )
  1207.       {
  1208.       attr = (attr & 0xf8) | 
  1209.              (vgaColorTable [pVgaConDv->escPara [ix] - 30]) ;
  1210.       }
  1211.   else if ((pVgaConDv->escPara [ix] >= 40) &&
  1212.    (pVgaConDv->escPara [ix] <= 47))
  1213.       {
  1214.       attr = (attr & 0x8f) |
  1215.              vgaColorTable [pVgaConDv->escPara [ix] - 40] << 4;
  1216.       }
  1217.   break;
  1218.             }
  1219. }
  1220.     pVgaConDv->curAttrib = attr;   /* set the current attribute */
  1221.     }
  1222. /*****************************************************************************
  1223. *
  1224. * vgaSetMode - set various special modes according to the input onOff
  1225. *
  1226. * RETURNS: N/A
  1227. */
  1228. LOCAL void vgaSetMode
  1229.     (
  1230.     FAST  PC_CON_DEV * pPcCoDv, /* pointer to the vga descriptor */
  1231.     BOOL          onOff /* on or off */
  1232.     )
  1233.     {
  1234.     FAST int ix;
  1235.     FAST VGA_CON_DEV * pVgaConDv; /* pointer to the vga descriptor */
  1236.     
  1237.     pVgaConDv = pPcCoDv->vs;
  1238.     for ( ix =0; ix <= pVgaConDv->escParaCount; ix++ )
  1239. {
  1240. if ( pVgaConDv->escQuestion )
  1241.     {
  1242.     switch (pVgaConDv->escPara [ix])
  1243. { /* modes set reset */
  1244. case 1:
  1245.       pPcCoDv->ks->curMode = (onOff) ?  FALSE : TRUE;
  1246.       break;
  1247.       
  1248.                 case 3: /* 80/132 mode switch unimplemented */
  1249.       vgaClear (pVgaConDv, 2, ' ');
  1250.       break;
  1251.       
  1252.                 case 5:
  1253.       pVgaConDv->rev = (pVgaConDv->rev) ? FALSE : TRUE;
  1254.       vgaScreenRev (pVgaConDv);
  1255.       break;
  1256.       
  1257.                 case 7:
  1258.       pVgaConDv->autoWrap = onOff;
  1259.       break;
  1260.       
  1261.                 case 25:
  1262.       (onOff) ?  vgaCursorOn() : vgaCursorOff() ;
  1263.       break;
  1264. }
  1265.     }
  1266. else if ( pVgaConDv->escPara [ix] == 4)
  1267.     {
  1268.     pVgaConDv->insMode = onOff;
  1269.     }
  1270. }
  1271.     }
  1272. /*****************************************************************************
  1273. *
  1274. * vgaPutCursor - place the cursor in the specified location
  1275. *
  1276. * RETURNS: N/A
  1277. */
  1278. LOCAL void vgaPutCursor 
  1279.     (
  1280.     FAST VGA_CON_DEV * pVgaConDv /* pointer to the vga descriptor */
  1281.     )
  1282.     {
  1283.     if ( pVgaConDv->col  < 0)
  1284. pVgaConDv->col = 0;
  1285.     else if (pVgaConDv->col >= pVgaConDv->ncol)
  1286. pVgaConDv->col = pVgaConDv->ncol - 1;
  1287.     if ( pVgaConDv->row < pVgaConDv->scst)
  1288. pVgaConDv->row = pVgaConDv->scst;
  1289.     else if ( pVgaConDv->row >= pVgaConDv->sced )
  1290. pVgaConDv->row = pVgaConDv->sced;
  1291.     
  1292.     pVgaConDv->curChrPos = (pVgaConDv->memBase + pVgaConDv->row *
  1293.     pVgaConDv->ncol * CHR + pVgaConDv->col * CHR );
  1294.     
  1295.     }
  1296. /*****************************************************************************
  1297. *
  1298. * vgaClearLine - clear the line according to the position passed.
  1299. *
  1300. * RETURNS: N/A
  1301. */
  1302. LOCAL void vgaClearLine 
  1303.     (
  1304.     FAST VGA_CON_DEV * pVgaConDv /* pointer to the vga descriptor */
  1305.     )
  1306.     {
  1307.     FAST UINT16 * cp; /* hold the beginning value */
  1308.     FAST UINT16 * end; /* hold the end value */
  1309.     FAST UINT16 erase; /* hold the erase character */
  1310.     erase = (pVgaConDv->defAttrib << 8 ) + ' ';
  1311.     
  1312.     if (pVgaConDv->escPara [0] == 0 )
  1313. {
  1314. cp  = (UINT16 *) (pVgaConDv->curChrPos + CHR );
  1315. end = (UINT16 *) (pVgaConDv->memBase + pVgaConDv->row  * 
  1316.   pVgaConDv->ncol * CHR + (pVgaConDv->ncol - 1) * CHR);
  1317. }
  1318.     else if (pVgaConDv->escPara [0] == 1)
  1319. {
  1320. cp  = (UINT16 *) (pVgaConDv->memBase + pVgaConDv->row * 
  1321.  pVgaConDv->ncol * CHR);
  1322. end = (UINT16 *) (pVgaConDv->curChrPos);
  1323. }
  1324.     else 
  1325. {
  1326. cp  = (UINT16 *) (pVgaConDv->memBase + pVgaConDv->row * 
  1327.   pVgaConDv->ncol * CHR);
  1328. end = (UINT16 *) (cp + (pVgaConDv->ncol - 1) * CHR);
  1329. pVgaConDv->curChrPos = (UCHAR *) cp ;
  1330. pVgaConDv->col = 0;
  1331. }
  1332.     for (; cp <= end; cp ++)
  1333. {
  1334. *cp = erase;
  1335. }
  1336.     }
  1337. /******************************************************************************
  1338. *
  1339. * vgaInsertLine - inserts as many number of lines as passed in the escape
  1340. *                  parameter
  1341. *
  1342. * RETURNS: N/A
  1343. */
  1344. LOCAL void vgaInsertLine 
  1345.     (
  1346.     FAST VGA_CON_DEV * pVgaConDv /* pointer to the vga descriptor */
  1347.     )
  1348.     {
  1349.     int ix;
  1350.     int start;
  1351.     int end;
  1352.     start = pVgaConDv->scst;
  1353.     end   = pVgaConDv->sced;
  1354.     pVgaConDv->scst = pVgaConDv->row;
  1355.     pVgaConDv->sced = pVgaConDv->nrow - 1 ;
  1356.     ix = pVgaConDv->escPara [0];
  1357.     if (pVgaConDv->escPara [0] == 0)
  1358. {
  1359. ix = 1;
  1360. }
  1361.     if (pVgaConDv->row + ix >= pVgaConDv->nrow)
  1362. {
  1363. ix = pVgaConDv->nrow - pVgaConDv->row - 1;
  1364. }
  1365.     vgaScroll (pVgaConDv, pVgaConDv->row, ix, BACKWARD, pVgaConDv->defAttrib);
  1366.     pVgaConDv->curChrPos -= pVgaConDv->col * CHR;
  1367.     pVgaConDv->col = 0;
  1368.     pVgaConDv->scst = start;
  1369.     pVgaConDv->sced = end ;
  1370.     
  1371.     }
  1372.      
  1373. /******************************************************************************
  1374. *
  1375. * vgaDelLines - deletes as many as lines as passed in the escape 
  1376. *               parameter
  1377. *
  1378. * RETURNS: N/A
  1379. */
  1380. LOCAL void vgaDelLines 
  1381.     (
  1382.     FAST VGA_CON_DEV * pVgaConDv /* pointer to the vga descriptor */
  1383.     )
  1384.     {
  1385.     int ix;
  1386.     int start;
  1387.     int end;
  1388.     start = pVgaConDv->scst;
  1389.     end = pVgaConDv->sced;
  1390.     pVgaConDv->scst = pVgaConDv->row;
  1391.     pVgaConDv->sced = pVgaConDv->nrow - 1;
  1392.     ix = pVgaConDv->escPara [0];
  1393.     if (ix == 0)
  1394. {
  1395. ix = 1;
  1396. }
  1397.     if (pVgaConDv->row + ix > pVgaConDv->nrow) 
  1398. {
  1399. ix = pVgaConDv->row;
  1400. }
  1401.     vgaScroll (pVgaConDv, pVgaConDv->sced, ix, FORWARD, pVgaConDv->defAttrib);
  1402.     pVgaConDv->curChrPos -= pVgaConDv->col * CHR;
  1403.     pVgaConDv->col = 0;
  1404.     pVgaConDv->scst = start;
  1405.     pVgaConDv->sced = end;
  1406.     }
  1407. /******************************************************************************
  1408. *
  1409. * vgaDelRightChars - deletes character right of the cursor
  1410. *
  1411. * RETURNS: N/A
  1412. */
  1413. LOCAL void vgaDelRightChars
  1414.     (
  1415.     FAST VGA_CON_DEV * pVgaConDv, /* pointer to the vga descriptor */
  1416.     int nDelChar /* number of Deletes to do */
  1417.     )
  1418.     {
  1419.     FAST int xPos; /* current position in columns */
  1420.     FAST UINT16 * cp; /* current pointer */
  1421.     FAST UINT16 erase; /* to hold erase character with Attribute */
  1422.     
  1423.     erase = (pVgaConDv->defAttrib << 8 ) + ' ';
  1424.     if (nDelChar + pVgaConDv->col  >=  pVgaConDv->ncol )
  1425. {
  1426. nDelChar = pVgaConDv->ncol - pVgaConDv->col - 1;
  1427. }
  1428.     else if (nDelChar == 0)
  1429. {
  1430. nDelChar = 1;
  1431. }
  1432.     while ( nDelChar-- )
  1433. {
  1434. xPos = pVgaConDv->col;
  1435. cp   = (unsigned short *) pVgaConDv->curChrPos;
  1436. while (++xPos < pVgaConDv->ncol)
  1437.     {
  1438.     *cp = *(cp +1);
  1439.     cp++;
  1440.     }
  1441. *cp =  erase;           /* erase the last character */
  1442. }
  1443.     }
  1444. #endif /* INCLUDE_ANSI_ESC_SEQUENCE */