home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c070 / 4.ddi / TOOLS.4 / TCTSRC1.EXE / SCSAVEPG.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-03-31  |  3.1 KB  |  102 lines

  1. /**
  2. *
  3. * Name        SCSAVEPG - Save the current display page.
  4. *
  5. * Synopsis    error = scsavepg(ppage_state);
  6. *
  7. *        int error         Returned error code.
  8. *        PAGE_STATE *ppage_state  Pointer to structure in
  9. *                     which to save the state of
  10. *                     the current display page.
  11. *
  12. * Description    This function saves the image and cursor coordinates
  13. *        of the current display page, placing them in the
  14. *        structure pointed to by ppage_state.  The page's
  15. *        image is stored in compressed format using UTSQZSCN.
  16. *
  17. *        A buffer is allocated via malloc() to hold the
  18. *        compressed screen image.  The address of the buffer is
  19. *        returned in ppage_state->pimage.  It can be freed at
  20. *        any time if the function return value is SC_NO_ERROR.
  21. *
  22. * Returns    int error         SC_NO_MEMORY if memory for the
  23. *                     page image can't be allocated;
  24. *                     SC_NO_ERROR if no errors occur.
  25. *        PAGE_STATE *ppage_state  The cursor coordinates and
  26. *                     compressed image of the current
  27. *                     display page.
  28. *
  29. * Version    6.00 (C)Copyright Blaise Computing Inc.  1989
  30. *
  31. **/
  32. #include <bscreens.h>
  33. #include <bvideo.h>
  34.  
  35. int cdecl scsavepg(ppage_state)
  36. PAGE_STATE *ppage_state;
  37. {
  38.     int       color_or_mono;
  39.     int       mode, act_page;
  40.     int       rows, columns;
  41.     int       cursor_high, cursor_low;
  42.     int       raw_image_length, compressed_image_length;
  43.     char far *praw_image;
  44.     char     *pcompressed_image;
  45.     char     *pbuffer;
  46.     int       allocated_buffer = 0;
  47.     char      dummy_char;
  48.  
  49.         /* First get the screen size and cursor coordinates.*/
  50.  
  51.     color_or_mono = scmode(&mode, &columns, &act_page);
  52.     rows = scrows();
  53.     sccurst(&(ppage_state->curs_row), &(ppage_state->curs_column),
  54.         &cursor_high, &cursor_low);
  55.  
  56.     raw_image_length = columns * rows * 2;
  57.  
  58.         /* If the current adapter is a CGA and b_vifast is  */
  59.         /* zero, then we need to first read the screen into */
  60.         /* a temporary buffer using virdrect() to prevent   */
  61.         /* snow.  Otherwise, compress from the screen        */
  62.         /* directly.                        */
  63.     if (!b_vifast && (b_cga == color_or_mono))
  64.     {
  65.     pbuffer = malloc(raw_image_length);
  66.     if (pbuffer == NIL)
  67.         return(SC_NO_MEMORY);
  68.     allocated_buffer = 1;
  69.  
  70.     virdrect(0, 0, rows - 1, columns - 1, pbuffer, CHAR_ATTR);
  71.     praw_image = pbuffer;
  72.  
  73.  
  74.     }
  75.     else
  76.     praw_image = viptr(0, 0);
  77.  
  78.         /* Now determine how much memory the compressed     */
  79.         /* screen image will require by passing a dummy     */
  80.         /* buffer of length 0 to utsqzscn, then allocate    */
  81.         /* space for the compressed image and perform the   */
  82.         /* compression.                     */
  83.     compressed_image_length = utsqzscn(praw_image, &dummy_char,
  84.                        raw_image_length, 0);
  85.  
  86.     pcompressed_image = malloc(compressed_image_length);
  87.     if (pcompressed_image == NIL)
  88.     return(SC_NO_MEMORY);
  89.  
  90.     utsqzscn(praw_image, pcompressed_image,
  91.          raw_image_length, compressed_image_length);
  92.  
  93.     ppage_state->pimage       = pcompressed_image;
  94.     ppage_state->image_length = compressed_image_length;
  95.  
  96.         /* Now free the temporary buffer if necessary.        */
  97.     if (allocated_buffer)
  98.     free(pbuffer);
  99.  
  100.     return(SC_NO_ERROR);
  101. }
  102.