: Quickly Copying a Screen Image to and from a Disk Drive

VocExile/Progmenu/Screen

Quickly Copying a Screen Image to and from a Disk Drive

by Ed Perley

This page describes a method, using C code, to quickly move screen images to and from the screen. It was used in my Moviola Animation program (See the Main Menu). A Graphic or text screen display is moved to a buffer, from where it is copied to a disk drive. The reverse process is used to copy an image file from the disk and display it on the screen. This is not a standard graphics format.

The process is simple, primative, and extremely fast. It can move up to 32 K per shot. For a greater screen memory size, two or more of these processes can be used to copy the whole thing. The C code is shown below. It is a modification of code in the manual from the Power C compiler from MIX Software.

Copying a Screen Image to Disk

The 'movedata' function is used to transfer a block of screen memory to a buffer. The Variables are:

scrn_seg-------The screen segment address in hex(0xb800 for Graphics 4).
scrn_off-------The offset from the screen segment (0 in this case.)
FP_SEG(buff)---A C Library Macro that defines the segment address of the string, buff.
Fp_OFF(buff)---A second C Library Macro used to define The offset from this address.
FRAMESIZE------A programmer defined Macro that contains the number of bytes to move (16384 for Graphics 4).

void screen_to_buff(void)
{
movedata(scrn_seg, scrn_off, FP_SEG(buff), FP_OFF(buff),FRAMESIZE);
}

The fwrite function is used to write a single block of data from the buffer to the disk drive. The variable 'size', is the frane size in bytes.

The fseek fuction is used because the picture is to be written to a file containing more than one frame, and the correct position in the file must be selected.

int buff_to_disk(int num)
{
----size_t number = num;
----size_t count;
----if (fseek(movie_fp, (long)num*size, SEEK_SET) == 0);
----{
--------count = fwrite((void* )buff, size, (size_t)1, movie_fp);
--------if (count != 1) return (int)count;/* FWRITE ERROR DETECTED */
--------return(0); /* WRITE WAS SUCCUSSFUL */
}
----return(-1); /* FSEEK ERROR DETECTED */

}

Copying a Screen Image from Disk

To go the opposite direction, the fread function is used similarly to the fwrite function, followed by a movedata function call to copy it from the buffer to the screen.

int disk_to_buff(int num)
{
----size_t number = num;
----size_t count;
----if (fseek(movie_fp, (long)num*size, SEEK_SET) == 0);
----{
--------count = fread((void* )buff, size, (size_t)1, movie_fp);
--------if (count != 1) return (int)count; /* FREAD ERROR DETECTED */
--------return(0); /* READ WAS SUCCUSSFUL */
----}
----return(-1); /* FSEEK ERROR DETECTED */
}

void buff_to_screen(void)
{
----movedata(FP_SEG(buff), FP_OFF(buff), scrn_seg, scrn_off,FRAMESIZE);
}

These functions were run on a 386 SX PC at a speed of 20 MHz. With this system, the program was able to copy 16K pictures from the hard disk to the screen at a rate of over ten frames per second.

Back to Program Menu

To Main Menu


http://www.nfinity.com/~exile/screen.htm
Email: See bottom of Program Menu
Date last updated: January 28, 1998