home *** CD-ROM | disk | FTP | other *** search
- /**
- *
- * Name SCSAVEPG - Save the current display page.
- *
- * Synopsis error = scsavepg(ppage_state);
- *
- * int error Returned error code.
- * PAGE_STATE *ppage_state Pointer to structure in
- * which to save the state of
- * the current display page.
- *
- * Description This function saves the image and cursor coordinates
- * of the current display page, placing them in the
- * structure pointed to by ppage_state. The page's
- * image is stored in compressed format using UTSQZSCN.
- *
- * A buffer is allocated via malloc() to hold the
- * compressed screen image. The address of the buffer is
- * returned in ppage_state->pimage. It can be freed at
- * any time if the function return value is SC_NO_ERROR.
- *
- * Returns int error SC_NO_MEMORY if memory for the
- * page image can't be allocated;
- * SC_NO_ERROR if no errors occur.
- * PAGE_STATE *ppage_state The cursor coordinates and
- * compressed image of the current
- * display page.
- *
- * Version 6.00 (C)Copyright Blaise Computing Inc. 1989
- *
- **/
- #include <bscreens.h>
- #include <bvideo.h>
-
- int cdecl scsavepg(ppage_state)
- PAGE_STATE *ppage_state;
- {
- int color_or_mono;
- int mode, act_page;
- int rows, columns;
- int cursor_high, cursor_low;
- int raw_image_length, compressed_image_length;
- char far *praw_image;
- char *pcompressed_image;
- char *pbuffer;
- int allocated_buffer = 0;
- char dummy_char;
-
- /* First get the screen size and cursor coordinates.*/
-
- color_or_mono = scmode(&mode, &columns, &act_page);
- rows = scrows();
- sccurst(&(ppage_state->curs_row), &(ppage_state->curs_column),
- &cursor_high, &cursor_low);
-
- raw_image_length = columns * rows * 2;
-
- /* If the current adapter is a CGA and b_vifast is */
- /* zero, then we need to first read the screen into */
- /* a temporary buffer using virdrect() to prevent */
- /* snow. Otherwise, compress from the screen */
- /* directly. */
- if (!b_vifast && (b_cga == color_or_mono))
- {
- pbuffer = malloc(raw_image_length);
- if (pbuffer == NIL)
- return(SC_NO_MEMORY);
- allocated_buffer = 1;
-
- virdrect(0, 0, rows - 1, columns - 1, pbuffer, CHAR_ATTR);
- praw_image = pbuffer;
-
-
- }
- else
- praw_image = viptr(0, 0);
-
- /* Now determine how much memory the compressed */
- /* screen image will require by passing a dummy */
- /* buffer of length 0 to utsqzscn, then allocate */
- /* space for the compressed image and perform the */
- /* compression. */
- compressed_image_length = utsqzscn(praw_image, &dummy_char,
- raw_image_length, 0);
-
- pcompressed_image = malloc(compressed_image_length);
- if (pcompressed_image == NIL)
- return(SC_NO_MEMORY);
-
- utsqzscn(praw_image, pcompressed_image,
- raw_image_length, compressed_image_length);
-
- ppage_state->pimage = pcompressed_image;
- ppage_state->image_length = compressed_image_length;
-
- /* Now free the temporary buffer if necessary. */
- if (allocated_buffer)
- free(pbuffer);
-
- return(SC_NO_ERROR);
- }