home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c005 / 4.ddi / C / SCRDBUF.C < prev    next >
Encoding:
C/C++ Source or Header  |  1986-08-05  |  4.7 KB  |  139 lines

  1. /**
  2. *
  3. * Name        scrdbuf -- Read series of adjacent characters
  4. *               from the current display page via BIOS
  5. *
  6. * Synopsis    num_read = scrdbuf(row,col,num_spaces,buffer,option);
  7. *
  8. *        int  num_read    Number of character cells actually read
  9. *        int  row,col    Row and column at which to begin reading
  10. *        int  num_spaces Number of character cells to read.
  11. *        char *buffer    Space in which to put the data
  12. *        int  option    The option value tells SCRDBUF how the
  13. *                buffer is constructed and where to
  14. *                position the cursor after the string has
  15. *                been read.  Three bits are relevant:
  16. *
  17. *              Value        Meaning
  18. *              -----------   ------------------------------------
  19. *              CUR_BEG        Leave cursor at (row,col).
  20. *              CUR_AFTER     Leave cursor after end of string.
  21. *
  22. *              CHARS_ONLY    Buffer contains characters only.
  23. *              CHAR_ATTR     Buffer contains (char,attr) pairs.
  24. *
  25. *              MOVE_CUR        Leave cursor according to
  26. *                      CUR_BEG/CUR_AFTER bit.
  27. *              NO_MOVE_CUR   Preserve cursor location.
  28. *
  29. * Description    This function reads adjacent characters from the current
  30. *        display page with or without their corresponding video
  31. *        attributes.  It can leave the cursor at the beginning or
  32. *        end of the space read or leave the cursor unmoved.
  33. *
  34. *        The num_spaces argument specifies the number of
  35. *        "character cells" to read, where "character cells" means
  36. *        the number of physical spaces on the screen.  (If
  37. *        CHAR_ATTR is specified, twice this number of bytes will
  38. *        be returned in the buffer.)  If num_spaces exceeds the
  39. *        number of characters to the end of the line, the read
  40. *        will continue on the following line, and so on to the
  41. *        end of the screen.  The read will stop at the end of the
  42. *        screen, hence the number of cells actually read may be
  43. *        less than num_spaces.  The actual number is returned as
  44. *        the value of the function.
  45. *
  46. *        If the read includes the lower right corner of the
  47. *        screen, then the cursor is left at the lower right
  48. *        corner if both MOVE_CUR and CUR_AFTER are specified.
  49. *
  50. *        If CHAR_ATTR is specified and the screen is in a
  51. *        graphics mode, then 1 will be returned as the attribute
  52. *        values regardless of the colors of the displayed
  53. *        characters.
  54. *
  55. *        Be aware that this function does NOT add a trailing NUL
  56. *        ('\0') at the end of the buffer, and that any 8-bit
  57. *        character may be present in the buffer, depending on
  58. *        what is in video memory.
  59. *
  60. * Returns    num_read    Number of character cells read
  61. *        *buffer     Characters read from the display page
  62. *                (perhaps with their attributes)
  63. *
  64. * Version    3.0  (C)Copyright Blaise Computing Inc. 1986
  65. *
  66. **/
  67.  
  68. #include <bscreen.h>
  69.  
  70. int scrdbuf(row,col,num_spaces,buffer,option)
  71. register int row,col;
  72. int         num_spaces;
  73. char         *buffer;
  74. int         option;
  75. {
  76.     int ax,bx,cx,dx,flags;
  77.     int mode,last_row,columns,act_page;
  78.     int want_attr,graphics;
  79.     int save_row,save_col,save_num;
  80.     int cursor_was_on,top_scan,bot_scan;
  81.  
  82.     scmode(&mode,&columns,&act_page);
  83.     last_row = scrows() - 1;
  84.  
  85.     /* Force reasonable values                          */
  86.  
  87.     utbound(row,0,last_row)
  88.     utbound(col,0,columns - 1)
  89.     utuplim(num_spaces,columns - col + ((last_row - row) * columns))
  90.     save_num = num_spaces;
  91.  
  92.                       /* Save cursor size & position. */
  93.     if (cursor_was_on = !sccurst(&save_row,&save_col,&top_scan,&bot_scan))
  94.                       /* Turn the cursor off          */
  95.     scpgcur(1,top_scan,bot_scan,CUR_NO_ADJUST);
  96.  
  97.     if (0 == (option & NO_MOVE_CUR))
  98.     {
  99.     save_row = row;           /* Beginning of string.          */
  100.     save_col = col;
  101.     }
  102.  
  103.     sccurset(row,col);
  104.     if (want_attr = ((option & CHAR_ATTR) != 0))
  105.     graphics = (mode > 3 && mode != 7);
  106.  
  107.     bx = utbyword(b_curpage,0);       /* This remains stable.          */
  108.  
  109.     while (num_spaces--)
  110.     {
  111.     ax = utbyword(8,0);          /* Read char & attribute          */
  112.     bios(16,&ax,&bx,&cx,&dx,&flags);
  113.     *buffer++ = (char) utlobyte(ax);    /* The data byte          */
  114.     if (want_attr)                /* The attribute          */
  115.         *buffer++ = (char) (graphics ? 1
  116.                      : uthibyte(ax));
  117.     if (++col >= columns)
  118.     {
  119.         col = 0;
  120.         row++;
  121.     }
  122.     ax = utbyword(2,0);          /* Set cursor position          */
  123.     dx = utbyword(row,col);
  124.     bios(16,&ax,&bx,&cx,&dx,&flags);
  125.                       /* Cursor is left after each    */
  126.                       /* character read.          */
  127.     }
  128.  
  129.     if ((option & NO_MOVE_CUR) || !(option & CUR_AFTER))
  130.     sccurset(save_row,save_col);  /* Restore cursor position      */
  131.                       /* (either to previous location */
  132.                       /* or to beginning of string).  */
  133.  
  134.     if (cursor_was_on)              /* Restore cursor size.          */
  135.     scpgcur(0,top_scan,bot_scan,CUR_NO_ADJUST);
  136.  
  137.     return save_num;
  138. }
  139.