Category : C Source Code
Archive   : IMDSRC78.ZIP
Filename : REFRESH.C

 
Output of file : REFRESH.C contained in archive : IMDSRC78.ZIP
/*** 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.

Rewritten to use a file for the refresh buffer instead of RAM by
A. Warnock, 1/91.

Add interface to extended memory - Ron Baalke - 05/91

***/

#define __MSC

/* * * * INCLUDE files * * * */

#include
#include
#include
#include
#include
#include
#include "imdef.h"
#include "dispio.h"
#include "mem.h"

/* * * * External functions * * * */

/* * * * Function declarations * * * */

int AllocRefresh (int);
int PutRefresh (unsigned char *, int, int, int);
int GetRefresh (unsigned char *, int, int, int);
void FreeRefresh (void);
void DeallocRefresh (void);
void EraseRefresh (void);
void Screen2Refresh (void);

/* * * * Global Variables * * * */

int RefreshLines;
unsigned char *RefreshBuf[MAXDISPNL];
unsigned char StageRefresh[MAXDISPNS];
char RefreshName[40] = "C:\\REFRESH.TMP";
int refresh;
int RefreshLocation;
static long current;


int AllocRefresh(int startup)
/*** AllocRefresh opens the refresh buffer file, and initializes it (if
it's newly created) to all NULLs.

***/
{
int n_bytes, i;
unsigned long size;
long offset;
int type;

RefreshLines = 0;

/* Attempt extended memory first */

size = ((long)dispns * (long)dispnl);
if (Memory_Alloc(size,&refresh,&type) == 0)
{
memset( StageRefresh, 0, dispns);
for (i=0; i {
offset = (long) i * (long) dispns;
Memory_PutLine(refresh, type, StageRefresh, offset,dispns);
}
RefreshLines = dispnl;
RefreshLocation = type;
}

if ((RefreshLines == 0) && (!startup)) /* Attempt virtual file next */
{
refresh = open( RefreshName, O_CREAT|O_RDWR|O_BINARY, S_IREAD|S_IWRITE );
if (refresh == -1)
{
/* File must already exist - reopen w/o initialize */
refresh = open( RefreshName, O_RDWR|O_BINARY, S_IREAD|S_IWRITE );
if (refresh == -1) /* If open fails, just set #lines to 0 */
RefreshLines = 0;
}
else
{
/* Initialize the file to all 0's, one line at a time */
memset( StageRefresh, 0, dispns);
n_bytes = dispns;
while ( (n_bytes == dispns) && (RefreshLines < dispnl) )
{
n_bytes = write( refresh, StageRefresh, dispns);
if (n_bytes == dispns)
RefreshLines++;
}
RefreshLocation = VIRTUAL_FILE;
}
}

return(RefreshLines);
}

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
***/
{
int n_bytes;
long offset;

offset = (long)(line-1) * dispns + ss - 1;

if (RefreshLocation != VIRTUAL_FILE) /* Ron Baalke - 05/91 */
{
Memory_PutLine(refresh, RefreshLocation, buffer, offset, ns);
n_bytes = ns;
}
else
{
current = lseek( refresh, offset, SEEK_SET);
n_bytes = write( refresh, buffer, ns);
}

return( n_bytes );
}

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
***/
{
int n_bytes;
long offset;

offset = (long)(line-1) * dispns + ss - 1;

if (RefreshLocation != VIRTUAL_FILE) /* Ron Baalke - 05/91 */
{
Memory_GetLine(refresh, RefreshLocation, buffer, offset, ns);
n_bytes = ns;
}
else
{
current = lseek( refresh, offset, SEEK_SET);
n_bytes = read( refresh, buffer, ns);
}

return( n_bytes );
}

void FreeRefresh(void)
/*** FreeRefresh releases the refresh buffer back to DOS, by closing
the refresh file, but not deleting it.
***/
{
if ((RefreshLocation == VIRTUAL_FILE) && (RefreshLines > 0))
{
close( refresh );
RefreshLines = 0;
}
}

void DeallocRefresh(void)
/*** DeallocRefresh releases the refresh buffer back to DOS, by deleting
the refresh file.
***/
{
if (RefreshLocation != VIRTUAL_FILE) /* Ron Baalke - 05/91 */
Memory_Free(refresh, RefreshLocation);
else
remove( RefreshName );

RefreshLines = 0;
}

void EraseRefresh(void)
/*** EraseRefresh will erase the contents of the refresh buffer
Ron Baalke - 05/91

***/
{
FreeRefresh();
DeallocRefresh();
RefreshLines = AllocRefresh(0);
}

void Screen2Refresh(void)
{
char buffer[MAXDISPNS];
int i;
int DN;
int save;

save = RefreshLines; /* temporarily disable GetLine() from using*/
RefreshLines = 0; /* the refresh buffer */

for (i=1; i<=dispnl; i++)
{
GetLine(buffer,i,1,dispns);
PutRefresh(buffer,i,1,dispns);
}

RefreshLines = save; /* Restore */
}


  3 Responses to “Category : C Source Code
Archive   : IMDSRC78.ZIP
Filename : REFRESH.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/