home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / sd386v50.zip / sd386src.zip / VIO.C < prev    next >
Text File  |  1996-08-23  |  25KB  |  495 lines

  1. /*****************************************************************************/
  2. /* File:                                             IBM INTERNAL USE ONLY   */
  3. /*   vio.c                                                                   */
  4. /*                                                                           */
  5. /* Description:                                                              */
  6. /*                                                                           */
  7. /*  VIO subsystem initialization.                                            */
  8. /*                                                                           */
  9. /*                                                                           */
  10. /* History:                                                                  */
  11. /*                                                                           */
  12. /*   02/08/91 Creation of 32-bit SD86, from 16-bit version.                  */
  13. /*                                                                           */
  14. /*...16->32 port.                                                            */
  15. /*...                                                                        */
  16. /*... 02/08/91  100   Philip    port to 32 bit.                              */
  17. /*... 02/08/91  112   Joe       changed size of cursor so it could be seen   */
  18. /*                              on different size screens                    */
  19. /*                                                                           */
  20. /*...Release 1.00 (Pre-release 1)                                            */
  21. /*...                                                                        */
  22. /*... 07/09/91  200   srinivas  changed logo screen from RPGS to PRGS.       */
  23. /*                                                                           */
  24. /*...Release 1.00 (Pre-release 107 11/13/91)                                 */
  25. /*...                                                                        */
  26. /*... 11/13/91  400   Srinivas  Vertical Register Display.                   */
  27. /*...                                                                        */
  28. /*...Release 1.00 (Pre-release 108 12/05/91)                                 */
  29. /*...                                                                        */
  30. /*... 02/11/92  518   Srinivas  Remove limitation on max no of screen rows.  */
  31. /*... 02/12/92  521   Srinivas  Port to C-Set/2.                             */
  32. /*...                                                                        */
  33. /*...Release 1.01 (04/03/92)                                                 */
  34. /*...                                                                        */
  35. /*... 05/08/92  701   Srinivas  Cua Interface.                               */
  36. /**Includes*******************************************************************/
  37.                                         /*                                   */
  38. #define INCL_16                         /* 16-bit API                     100*/
  39. #define INCL_SUB                        /* vio, kbd, mouse routines       100*/
  40. #include "all.h"                        /* SD86 include files                */
  41. static int iview=0;
  42.                                         /*                                   */
  43. VIOCURSORINFO  NormalCursor;            /* normal thin line at bottom.       */
  44. VIOCURSORINFO  InsertCursor;            /* block style cursor.               */
  45. VIOCURSORINFO  HiddenCursor;            /* invisible cursor.                 */
  46.  
  47. /* logical to physical video attribute maps */
  48. static  uchar vaColor[] = { 0,
  49.   /* vaProgram  1 */ BG_blue |FG_white,
  50.   /* vaBptOk    2 */ BG_blue |FG_white|FG_light,
  51.   /* vaBptOn    3 */ BG_red  |FG_white|FG_light,
  52.   /* vaXline    4 */ BG_white|FG_black|FG_light,
  53.   /* vaXlineOn  5 */ BG_white|FG_red,
  54.   /* vaMenuBar  6 */ BG_cyan |FG_white|FG_light,
  55.   /* vaMenuCsr  7 */ BG_black|FG_white|FG_light,
  56.   /* vaStgExp   8 */ BG_white|FG_black,
  57.   /* vaStgVal   9 */ BG_white|FG_black,
  58.   /* vaRegWind 10 */ BG_blue |FG_white,
  59.   /* vaPrompt  11 */ BG_brown|FG_white|FG_light,
  60.   /* vaError   12 */ BG_black|FG_red  |FG_light,
  61.   /* vaInfo    13 */ BG_cyan |FG_white|FG_light,
  62.   /* vaHelp    14 */ BG_white|FG_black,
  63.   /* vaStgPro  15 */ BG_magenta|FG_white|FG_light,
  64.   /* vaClear   16 */ BG_black|FG_white,
  65.   /* vaStgStat 17 */ BG_cyan |FG_white|FG_light,
  66.   /* vaMxdSrc  18 */ BG_blue |FG_white,
  67.   /* vaMenuSel 19 */ BG_cyan |FG_yellow,
  68.   /* vaCallStk 20 */ BG_brown|FG_white|FG_light,
  69.   /* vaCallSel 21 */ BG_white|FG_brown,
  70.   /* vaRegTogg 22 */ BG_blue |FG_white|FG_light,
  71.   /* vaTemp1   23 */ BG_blue |FG_white|FG_light,
  72.   /* vaBadAct  24 */ BG_white|FG_black|FG_light,                        /*701*/
  73.   /* vaBadSel  25 */ BG_black|FG_white|FG_light,                        /*701*/
  74.   /* vaShadow  26 */ BG_black|FG_black|FG_light                         /*701*/
  75. };
  76. static  uchar vaMono[] = { 0,
  77.   /* vaProgram  1 */ BG_black|FG_white,
  78.   /* vaBptOk    2 */ BG_black|FG_white|FG_light,
  79.   /* vaBptOn    3 */ BG_black|FG_uline|FG_light,
  80.   /* vaXline    4 */ BG_white|FG_black,
  81.   /* vaXlineOn  5 */ BG_white|FG_black,
  82.   /* vaMenuBar  6 */ BG_white|FG_black,
  83.   /* vaMenuCsr  7 */ BG_black|FG_white,
  84.   /* vaStgExp   8 */ BG_white|FG_black,
  85.   /* vaStgVal   9 */ BG_white|FG_black,
  86.   /* vaRegWind 10 */ BG_black|FG_white,
  87.   /* vaPrompt  11 */ BG_white|FG_black,
  88.   /* vaError   12 */ BG_black|FG_white|FG_light,
  89.   /* vaInfo    13 */ BG_black|FG_white,
  90.   /* vaHelp    14 */ BG_white|FG_black,
  91.   /* vaStgPro  15 */ BG_black|FG_white|FG_light,
  92.   /* vaClear   16 */ BG_black|FG_white,
  93.   /* vaStgStat 17 */ BG_black|FG_white,
  94.   /* vaMxdSrc  18 */ BG_black|FG_white,
  95.   /* vaMenuSel 19 */ BG_black|FG_white,
  96.   /* vaCallStk 20 */ BG_white|FG_black,
  97.   /* vaCallSel 21 */ BG_black|FG_white,
  98.   /* vaRegTogg 22 */ BG_black|FG_white|FG_light,
  99.   /* vaTemp1   23 */ BG_black|FG_white|FG_light,
  100.   /* vaBadAct  24 */ BG_white|FG_black|FG_light,                        /*701*/
  101.   /* vaBadSel  25 */ BG_black|FG_white,                                 /*701*/
  102.   /* vaShadow  26 */ BG_black|FG_black|FG_light                         /*701*/
  103. };
  104.  
  105. extern CmdParms       cmd;              /* pointer to CmdParms structure  701*/
  106.                                         /* screen display.                701*/
  107.  
  108. UINT   MsgRow;                          /* screen row for messages (0..N)    */
  109. UINT   MaxData;                         /* max # of lines of Data            */
  110. UINT   MaxPer;                          /* max # of lines of Code            */
  111. UCHAR *VideoMap;                        /* -> logical-to-phys attrb.map      */
  112. UCHAR *BoundPtr;                        /* -> to screen bounds               */
  113. UINT   ProRow;                          /* screen row for prompt (0..N)      */
  114. UINT   VideoCols;                       /* # of columns per screen           */
  115.  
  116. #ifdef MSH
  117. UINT   VideoWidth;                      /* # of columns per screen           */
  118. #endif
  119.  
  120. UINT   FnameRow;                        /* screen row for file name (0..N)   */
  121. UCHAR  VideoAtr = 0;                    /* default logical video attribute.  */
  122. UINT   HelpRow;                         /* screen row for menu help (0..N)   */
  123. UINT   LinesPer;                        /* currnt # of lines/screen for Code */
  124. UINT   VideoRows;                       /* # of rows per screen              */
  125. UINT   VioStartOffSet;                  /* flag to tell were to start     701*/
  126. UINT   MinPer;                          /* min # of lines of Code            */
  127. UINT   MenuRow;                         /* screen row for menu bar (0..N)    */
  128. UCHAR *VideoPtr = NULL;                 /* -> to logical video buffer     100*/
  129. UINT   TopLine;                         /* current top line for Code (0..N)  */
  130. USHORT ColStart=0, RowStart=0;
  131.  
  132. /* Attrib is a macro in fmt.h           */
  133.  
  134. static uchar clrrow[] = { Attrib(00), RepCnt(00), ' ', 0 };
  135.  
  136.     void
  137. ClrScr(uint toprow,uint botrow,uint attr )
  138. /*         toprow  : 1st line to clear (0..N) */
  139. /*         botrow  : last line to clear (0..N) */
  140. /*         attr    : logical attribute used to clear screen */
  141. {
  142.   VideoAtr = (uchar)attr;               /* Set the default video attribute   */
  143.   clrrow[0] = (uchar)Attrib(attr);
  144.   clrrow[2] = (uchar)(VideoCols-ColStart);
  145.   while( toprow <= botrow )
  146.       putrc( toprow++, 0, clrrow );
  147. }
  148.  
  149. static  uchar *banner[] = {
  150.  "O S / 2  S o u r c e - l e v e l   D e b u g g e r",
  151.  "",
  152.  "Version 5.00",
  153.  "08/23/96",
  154.  "",
  155.  "Copyright (C) IBM Corp. 1987 - 1996",
  156.  "",
  157.  "",
  158.  "",
  159.  NULL
  160. };
  161. #define BANNER_ROW 4
  162.  
  163. void VioInit( )
  164. {
  165.  APIRET      rc;
  166.  UCHAR     **cpp;
  167.  UINT        vlen;
  168.  UINT        row;
  169.  VIOMODEINFO md;
  170.  
  171.  memset(&md, 0, sizeof(md) );
  172.  md.cb = sizeof(md);
  173.  
  174.  if( VioGetMode(&md, 0) )
  175.  {
  176.   printf( "Vio error" );
  177.   exit(0);
  178.  }
  179.  
  180.  VideoRows = md.row;
  181.  VideoCols = md.col;
  182.  MaxPer    = VideoRows - 2 ;            /* max # of lines of Code            */
  183.  MaxData   = VideoRows * 2 / 3;         /* max # of rows for data window     */
  184.  MinPer    = MaxPer - MaxData;          /* min # of lines of Code            */
  185.  ProRow    = VideoRows - 3;             /* screen row for prompt (0..N)      */
  186.  MenuRow   = VideoRows - 3;             /* screen row for menu bar (0..N)    */
  187.  FnameRow  = VideoRows - 2;             /* screen row for file name (0..N)   */
  188.  HelpRow   = VideoRows - 1;             /* screen row for menu help (0..N)   */
  189.  MsgRow    = VideoRows - 1;             /* screen row for messages (0..N)    */
  190.  LinesPer  = MaxPer - TopLine;          /* current # of lines per screen     */
  191.                                         /* for source                        */
  192.  VideoMap  = vaColor;
  193.  
  194.  if( md.color == 1 )
  195.   VideoMap = vaMono;
  196.  
  197.  
  198.     rc = VioGetBuf((PULONG)&VideoPtr, (PUSHORT)&vlen, 0);
  199.     if( rc != 0 ){
  200.         printf( "VioGetBuf() returned %d\n", rc );
  201.         panic(OOquit);
  202.     }
  203.     if( ! HiddenCursor.attr ){
  204.         rc = VioGetCurType(&NormalCursor,0);
  205.         if( rc != 0 ){
  206.             printf( "VioGetCurType() returned %d\n", rc );
  207.             panic(OOquit);  }
  208.  
  209.         /*********************************************************************/
  210.         /* If the cursor is in insert mode when we enter here then convert   */
  211.         /* the parms of cursorinfo into a normal mode cursor.                */
  212.         /*********************************************************************/
  213.         if ((NormalCursor.cEnd - NormalCursor.yStart) > 2)
  214.           NormalCursor.yStart = NormalCursor.cEnd -
  215.                            ((NormalCursor.cEnd - NormalCursor.yStart - 1) / 4);
  216.         NormalCursor.yStart -= 1;                                       /*112*/
  217.         memcpy( &InsertCursor, &NormalCursor, sizeof(InsertCursor) );   /*100*/
  218.         InsertCursor.yStart = 0;
  219.         memcpy( &HiddenCursor, &NormalCursor, sizeof(HiddenCursor) );   /*100*/
  220.         HiddenCursor.attr = -1;
  221.     }
  222.  
  223.     /*************************************************************************/
  224.     /* - Allocate memory for screen bounds                                400*/
  225.     /* - set the bounds to the video cols                                 400*/
  226.     /*************************************************************************/
  227.     BoundPtr = Talloc(VideoRows);                                   /*521 518*/
  228.     if (BoundPtr)                                                       /*518*/
  229.        memset(BoundPtr,VideoCols,VideoRows);                            /*518*/
  230.     else                                                                /*518*/
  231.     {                                                                   /*518*/
  232.         printf( "malloc failed\n");                                     /*518*/
  233.         panic(OOquit);                                                  /*518*/
  234.     }                                                                   /*518*/
  235.  
  236.     VioStartOffSet = 1;
  237.     TopLine = 1;
  238.     MenuRow  = 0;
  239.     LinesPer = MaxPer - TopLine;
  240.     InitDataWinCsr();
  241.     AccessMouse();
  242.  
  243.     HideCursor();
  244.     ClrScr( 0, VideoRows-1, vaBptOk );
  245.     cpp = banner;
  246.     for( row = BANNER_ROW; *cpp; cpp++,row++ )
  247.     {
  248.      putrc( row, (VideoCols-strlen(*cpp)) / 2, *cpp );
  249.     }
  250. }
  251.  
  252.     void
  253. ClrPhyScr(uint top,uint bot,uint attr )
  254.                                         /* 1st line to clear (0..N)          */
  255.                                         /* last line to clear (0..N)         */
  256.                                         /* logical attr used to clr scrn     */
  257. {
  258.     twoc fillchar = ( twoc )((VideoMap[attr] << 8) | ' ');/* cast         100*/
  259.  
  260.     if( VioScrollUp((ushort)top, 0, (ushort)bot, /* cast                  100*/
  261.                     (ushort)(VideoCols-1),       /* cast                  100*/
  262.                     (ushort)(bot - top + 1),     /* cast                  100*/
  263.                     (char*) &fillchar, 0)  )
  264.         panic(OOvioclr);
  265. }
  266.  
  267.     void
  268. PutPhyScr(uint top,uint bot )
  269.                         /* 1st line to show (0..N) */
  270.                         /* last line to show (0..N) */
  271. {
  272.     if( VioShowBuf((ushort)(top * 2*VideoCols),              /* cast      100*/
  273.                    (ushort)((bot - top + 1) * 2*VideoCols),  /* cast      100*/
  274.                    0) )
  275.         panic(OOvioshow);
  276. }
  277.  
  278. /* Interface for 32-bit assembly routines to call 16-bit VioShowBuf API   100*/
  279. void                                                                    /*100*/
  280. Vio32ShowBuf(ushort VioOff, ushort VioLen, ushort VioHan)               /*100*/
  281. {                                                                       /*100*/
  282.  Vio16ShowBuf(VioOff, VioLen, VioHan);                                  /*100*/
  283. }                                                                       /*100*/
  284.  
  285. /*****************************************************************************/
  286. /* Putrc()                                                                400*/
  287. /*                                                                           */
  288. /* Description:                                                              */
  289. /*      Filters the parameters being passed to putrcx (asm routine)          */
  290. /*      so that we donot write to the parts of the screen where we           */
  291. /*      do not have access to it.                                            */
  292. /* Parameters:                                                               */
  293. /*      row   - Row where to write the string                                */
  294. /*      col   - col where to write the string                                */
  295. /*      ptr   - -> to the char string with embeded attributes.               */
  296. /* Return:                                                                   */
  297. /*      none                                                                 */
  298. /* Assumptions:                                                              */
  299. /*      It is assumed that this routine is expected to handle one row        */
  300. /*      at a time. It can't handle a big string spanning across more than    */
  301. /*      screen columns.                                                      */
  302. /*****************************************************************************/
  303. void putrc(uint row, uint col, char *ptr)
  304. {
  305.  char  Save_Byte;                       /* Byte saved                     400*/
  306.  char *Save_Ptr;                        /* -> location which was modified 400*/
  307.  char *String_Ptr;                      /* -> string                      400*/
  308.  char  Restore_Flag;                    /* flag to indicate any modificat 400*/
  309.  uchar First_Char;                      /* 1st character                  400*/
  310.  uint  String_Len,temp;                 /*                                400*/
  311.  uchar Count;                           /*                                400*/
  312.  uint  No_Of_Attributes;                /* count of attributes            400*/
  313.  extern int iview;
  314.  /****************************************************************************/
  315.  /* Initialise the flags.                                                    */
  316.  /****************************************************************************/
  317.  No_Of_Attributes =  0;
  318.  Restore_Flag     =  0;
  319.  String_Ptr       =  ptr;
  320.  First_Char       = *String_Ptr;
  321.  
  322.  /****************************************************************************/
  323.  /* If the column where we want to write the string is beyond the screen     */
  324.  /* bounds then return without doing any thing.                              */
  325.  /****************************************************************************/
  326.  if (iview==2) /*This is used to turn off video writes when in MSH Browse mode.*/
  327.     return;
  328.  if(iview) {
  329.  if (col > BoundPtr[row])
  330.     return;
  331.  
  332.  if (row + RowStart >= VideoRows  - 2)
  333.     return;
  334.  }
  335.  else
  336.  {
  337.  if (col > BoundPtr[row])
  338.     return;
  339.  
  340.  if (row > VideoRows )
  341.     return;
  342.  
  343.  }/* End if*/
  344.  /****************************************************************************/
  345.  /* If the 1st char of the i/p string is 0xFF it tells us that the i/p       */
  346.  /* string is of format as follows                                           */
  347.  /*    0XFF xx  .....                                                        */
  348.  /*     |   |------->  Tells the repeat count or if it is 0xFF it a special  */
  349.  /*     |              case                                                  */
  350.  /*      ----------->  Tells us repeat count is following.                   */
  351.  /*                                                                          */
  352.  /* - Check if the repeat count when added to the col postion where to start */
  353.  /*   painting excceds the screen bounds.                                    */
  354.  /* - If it does set up the flag to restore the contents, save the repeat    */
  355.  /*   count, modify repeat count such that it does not exceed the screen     */
  356.  /*   bounds.                                                                */
  357.  /****************************************************************************/
  358.  if (First_Char == (uchar)0xFF)
  359.  {
  360.     Count = *(++String_Ptr);
  361.     if (Count < (uchar)0xFF)
  362.     {
  363.        temp = (uint)Count + col;
  364.        if (temp > BoundPtr[row])
  365.        {
  366.           Restore_Flag = 1;
  367.           Save_Ptr = String_Ptr;
  368.           Save_Byte = *Save_Ptr;
  369.           *String_Ptr = BoundPtr[row] - col;
  370.        }
  371.     }
  372.  }
  373.  else
  374.  {
  375.     /*************************************************************************/
  376.     /* If the 1st char of the i/p string is less than 0x80 it says that the  */
  377.     /* i/p string is a ordinary string with embeded attributes whose values  */
  378.     /* are greater than 0x7F.                                                */
  379.     /*    xx xx xx xx xx xx xx 0x81 xx xx xx xx                              */
  380.     /*     |                    |---> It is a attribute.                     */
  381.     /*      ----------->  Ordinary charater.                                 */
  382.     /*                                                                       */
  383.     /* - Check when the length of the string added to the col postion where  */
  384.     /*   to start painting excceds the screen bounds.                        */
  385.     /* - If it does scan the string for determining the count of attributes. */
  386.     /* - Set up a flag to restore the string contents                        */
  387.     /* - Find the location where we have to end the string so that it does   */
  388.     /*   cross the screen bounds.                                            */
  389.     /* - save the byte at that location.                                     */
  390.     /* - stuff is a null at that location.                                   */
  391.     /*************************************************************************/
  392.     if (First_Char < (uchar)0x80)
  393.     {
  394.        String_Len = strlen(String_Ptr);
  395.        if ((String_Len + col) > BoundPtr[row])
  396.        {
  397.          Save_Ptr = String_Ptr;
  398.          while (*Save_Ptr)
  399.          {
  400.             if (((uchar)*(Save_Ptr) > (uchar)0x7F) &&
  401.                 ((uchar)*(Save_Ptr) < (uchar)0x99) )
  402.                No_Of_Attributes++;
  403.                Save_Ptr++;
  404.          }
  405.          Restore_Flag = 1;
  406.          Save_Ptr = String_Ptr + BoundPtr[row] - col + No_Of_Attributes;
  407.          Save_Byte = *Save_Ptr;
  408.          *Save_Ptr = '\0';
  409.        }
  410.     }
  411.     else
  412.     {
  413.        /**********************************************************************/
  414.        /* If the 1st char of the i/p string is greater than 0x80 & the next  */
  415.        /* char is 0xFF then the format of the i/p string is as follows       */
  416.        /*  0x81  0XFF xx  .....                                              */
  417.        /*   |     |   |------->  Tells the repeat count or if it is 0xFF it  */
  418.        /*   |     |              a special case.                             */
  419.        /*   |      ----------->  Tells us repeat count is following.         */
  420.        /*    ----------------->  Attribute.                                  */
  421.        /*                                                                    */
  422.        /* - Check if the repeat count when added to the col postion where to */
  423.        /*   start painting excceds the screen bounds.                        */
  424.        /* - If it does set up the flag to restore the contents, save the rep */
  425.        /*   count, modify repeat count such that it does not exceed the scr  */
  426.        /*   bounds.                                                          */
  427.        /**********************************************************************/
  428.        if (*(++String_Ptr) == (char)0xFF)
  429.        {
  430.           Count = *(++String_Ptr);
  431.           if (Count < (uchar)0xFF)
  432.           {
  433.              temp = (uint)Count + col;
  434.              if (temp > BoundPtr[row])
  435.              {
  436.                 Restore_Flag = 1;
  437.                 Save_Ptr = String_Ptr;
  438.                 Save_Byte = *Save_Ptr;
  439.                 *String_Ptr = BoundPtr[row] - col;
  440.              }
  441.           }
  442.        }
  443.        else
  444.        {
  445.     /*************************************************************************/
  446.     /* If the 1st char of the i/p string is greater than 0x80 it says that   */
  447.     /* i/p string is a ordinary string with embeded attributes whose values  */
  448.     /* are greater than 0x7F.                                                */
  449.     /*  0x81 xx xx xx xx xx xx xx 0x81 xx xx xx xx                           */
  450.     /*   |    |                     |---> It is a attribute.                 */
  451.     /*   |     -------------------------> Ordinary charater.                 */
  452.     /*    ------------------------------> It is a attribute.                 */
  453.     /* - Check when the length of the string added to the col postion where  */
  454.     /*   to start painting excceds the screen bounds.                        */
  455.     /* - If it does scan the string for determining the count of attributes. */
  456.     /* - Set up a flag to restore the string contents                        */
  457.     /* - Find the location where we have to end the string so that it does   */
  458.     /*   cross the screen bounds.                                            */
  459.     /* - save the byte at that location.                                     */
  460.     /* - stuff is a null at that location.                                   */
  461.     /*************************************************************************/
  462.           String_Len = strlen(String_Ptr);
  463.           if ((String_Len + col) > BoundPtr[row])
  464.           {
  465.              Save_Ptr = String_Ptr;
  466.              while (*Save_Ptr)
  467.              {
  468.                if (((uchar)*(Save_Ptr) > (uchar)0x7F) &&
  469.                   ((uchar)*(Save_Ptr) < (uchar)0x99) )
  470.                   No_Of_Attributes++;
  471.                   Save_Ptr++;
  472.              }
  473.              Restore_Flag = 1;
  474.              Save_Ptr = String_Ptr + BoundPtr[row] - col + No_Of_Attributes;
  475.              Save_Byte = *Save_Ptr;
  476.              *Save_Ptr = '\0';
  477.           }
  478.        }
  479.     }
  480.  }
  481.  
  482.  /****************************************************************************/
  483.  /* Call putrcx to display the string                                        */
  484.  /****************************************************************************/
  485. /* putrcx(row, col, ptr, 1); */
  486.  {
  487.   putrcx(row, col, ptr);
  488.  }
  489.  /****************************************************************************/
  490.  /* If restore flag is set, restore the string its orginal contents          */
  491.  /****************************************************************************/
  492.  if (Restore_Flag)
  493.     *Save_Ptr = Save_Byte;
  494.  }
  495.