home *** CD-ROM | disk | FTP | other *** search
- /*************************************************************/
- /* Copyright (C) 1989, California Institute of Technology */
- /* U. S. Government Sponsorship under NASA Contract */
- /* NAS7-918 is acknowledged. */
- /*************************************************************/
-
- /*** IMDISP module REFRESH.C
-
- REFRESH contains all the routines for manipulating the refresh
- buffer, which holds a copy of the last image displayed. Created as
- a separate module by A. Warnock, ST Systems Corp., NASA/GSFC, 5/90.
-
- ***/
-
- /* * * * INCLUDE files * * * */
-
- #include <process.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include "imdef.h"
- #include "dispio.h"
-
- /* * * * External functions * * * */
-
- /* * * * Function declarations * * * */
-
- int FreeRefresh (char *);
- int PutRefresh (unsigned char *, int, int, int);
- int GetRefresh (unsigned char *, int, int, int);
- int AllocRefresh (void);
-
- /* * * * Global Variables * * * */
-
- int RefreshLines;
- unsigned int segment;
- unsigned char *RefreshBuf[MAXDISPNL];
-
-
- int FreeRefresh(char * caller)
- /*** FreeRefresh releases one line of the refresh buffer back to DOS,
- as long as there are allocated lines in the buffer.
- ***/
- {
- if (RefreshLines > 0)
- {
- RefreshLines--;
- free( RefreshBuf[RefreshLines] );
- }
-
- if (RefreshLines == 0)
- {
- DisplayOff();
- printf("Not enough memory in %s.",caller);
- exit(1);
- }
- }
-
- int PutRefresh (unsigned char * buffer, int line, int ss, int ns)
-
- /*** PutRefresh stores a line of pixels in the refresh buffer.
- Parameter type description
- buffer char ptr The array of pixel values
- line integer The line coordinate of the first pixel
- sample integer The sample coordinate of the first pixel
- ns integer The number of pixels to store
- ***/
-
- {
- unsigned char *p;
-
- if (line <= RefreshLines)
- {
- p = &RefreshBuf[line-1][ss-1];
- memcpy (p, buffer, ns);
- }
-
- }
-
- int GetRefresh (unsigned char * buffer, int line, int ss, int ns)
-
- /*** GetRefresh reads a line of pixels from the refresh buffer.
- Parameter type description
- buffer char ptr The receiving array of pixel values
- line integer The line coordinate of the first pixel
- sample integer The sample coordinate of the first pixel
- ns integer The number of pixels to read
- ***/
-
- {
- unsigned char *p;
-
- if (line <= RefreshLines)
- {
- p = &RefreshBuf[line-1][ss-1];
- memcpy (buffer, p, ns);
- }
- else
- memset (buffer, 0, ns);
- }
- int AllocRefresh(void)
- {
- int i;
-
- i = 0;
-
- while ( ((RefreshBuf[i] = (unsigned char *) calloc( dispns, sizeof(char)) ) != NULL)
- && (i < dispnl) ) i++;
- if (i == dispnl)
- RefreshLines = i + 1;
- else
- RefreshLines = i;
-
- return(RefreshLines);
- }
-