Category : C Source Code
Archive   : GXSCROLL.ZIP
Filename : SCROLL.C

 
Output of file : SCROLL.C contained in archive : GXSCROLL.ZIP
/* Scroll.C */
/* Copyright (c) Genus Microprogramming, Inc. 1988-92 All Rights Reserved. */

/****************************************************************************

This program demonstrates the usage of unlimited scrolling, like space
animation.

To Compile: Microsoft C 6.x cl /AS Scroll.c /link gx_cs pcx_cs

Quick C 2.x QC Scroll
(Specify a MAK file, 3 lines: Scroll.c )
( gx_cs.lib )
( pcx_cs.lib )
(press "F5" to run )
or QCL /AS Scroll.c /link gx_cs pcx_cs

Turbo C 2.x tc Scroll
(Specify a PRJ file, 3 lines: Scroll.c )
( gx_cs.lib )
( pcx_cs.lib )
(and press "Ctrl-F9" to run )
or tcc -I\tc\h -L\tc\lib Scroll gx_cs.lib pcx_cs.lib

Lattice C 6.x lc -ms -L+gx_cs+pcx_cs Scroll
(Use the Microsoft C small model library )

Microsoft C version 6.0 Programmer: Chris Howard 02/19/92

*****************************************************************************/

#include
#include
#include
#ifndef LATTICE
#include
#endif

/* Include GX Development Series defines */
#include "gxlib.h"
#include "pcxlib.h"

/* Direction */
#define DIRDOWN 0
#define DIRRIGHT 1
#define DIRUP 2
#define DIRLEFT 3

/* Increment */
#define MININC 0
#define MAXINC 32

/* Keys */
#define KEXTENDED 0 /* Extended key flag */
#define KLARROW 75 /* Left arrow */
#define KRARROW 77 /* Right arrow */
#define KUARROW 72 /* Up arrow */
#define KDARROW 80 /* Down arrow */
#define KHOME 71 /* Home */
#define KEND 79 /* End */
#define KPGUP 73 /* Page up */
#define KPGDN 81 /* Page down */
#define KESC 27 /* Escape */
#define KPLUS 43 /* Plus */
#define KMINUS 45 /* Minus */

#define BUFMAX 30000

/* Globals */
int pcxtype = gxVGA_11;
char pcximage[65] = "Scroll.PCX";
char pcxpal[768];

GXVINFO vi[2];
GXHEADER vh, *vhptr = &vh;
PCXHEADER header;

char buffer[BUFMAX];

/**********/

/*
* This function scrolls an image in a window, in any direction.
*
* The simplest case is when the window falls entirely within the image
* borders. This requires only one gxVirtualDisplay call.
*
* The next case involves a split in either the x or y directions. Two
* calls are required to handle the wrap around.
*
* The last case involves a split in both directions. This requires
* four virtual calls.
*
* The main manipulation involves the movement of the (VX,VY) offset into
* the virtual buffer.
*
*/

void VirtualSpace(GXHEADER *vhptr,int wx1,int wy1,int wx2,int wy2,int page)
{

int dir, inc, key, done;
int xseam, yseam;
int xseamx, yseamy;
int width, depth;
int vx, vy;
int retcode;

/* REMOVE THIS LINE IF YOU DO NOT HAVE GX 1.51 OR ABOVE */
gxRetraceCheck(gxTRUE);

/* Calc window size */
width = wx2-wx1+1;
depth = wy2-wy1+1;

/* Start at upper left corner */
vx = vy = 0;

/* Initially, scroll down */
dir = DIRDOWN;
inc = 1;

/* Scroll, until ESC is pressed */
done = gxFALSE;
while (!done) {

/* Look for seams */
xseam = yseam = gxFALSE;
if ((vx+width-1) > (int) vhptr->x2)
xseam = gxTRUE;
if ((vy+depth-1) > (int) vhptr->y2)
yseam = gxTRUE;

/* Can we display all in one piece? */
if (!xseam && !yseam) {
/* Yes, so do it */
retcode = gxVirtualDisplay(vhptr, vx, vy, wx1, wy1, wx2, wy2, page);
}
else {
/* Calc seam offsets */
xseamx = wx1+(vhptr->x2-vx);
yseamy = wy1+(vhptr->y2-vy);
/* Do we only have an X seam? */
if (xseam && !yseam) {
/* Yes, so display the 2 pieces */
retcode = gxVirtualDisplay(vhptr, vx, vy, wx1, wy1, xseamx, wy2, page);
retcode = gxVirtualDisplay(vhptr, 0, vy, xseamx, wy1, wx2, wy2, page);
}
else {
/* Do we only have a Y seam? */
if (yseam && !xseam) {
/* Yes, so display the 2 pieces */
retcode = gxVirtualDisplay(vhptr, vx, vy, wx1, wy1, wx2, yseamy, page);
retcode = gxVirtualDisplay(vhptr, vx, 0, wx1, yseamy, wx2, wy2, page);
}
else {
/* We have 4 pieces! */
retcode = gxVirtualDisplay(vhptr, vx, vy, wx1, wy1, xseamx, yseamy, page);
retcode = gxVirtualDisplay(vhptr, 0, vy, xseamx, wy1, wx2, yseamy, page);
retcode = gxVirtualDisplay(vhptr, vx, 0, wx1, yseamy, xseamx, wy2, page);
retcode = gxVirtualDisplay(vhptr, 0, 0, xseamx, yseamy, wx2, wy2, page);
}
}

}

/* Check for a key */
if (kbhit()) {

/* Get it */
key = getch();

/* Extended key? */
if (key == KEXTENDED) {

/* Yes, so get it */
key = getch();

/* Determine key action */
switch (key) {
case KUARROW:
dir = DIRDOWN;
break;
case KDARROW:
dir = DIRUP;
break;
case KLARROW:
dir = DIRRIGHT;
break;
case KRARROW:
dir = DIRLEFT;
break;
}
}
else {

/* Normal key */
switch (toupper(key)) {
case KESC:
case 'Q':
case 'X':
/* We are done */
done = gxTRUE;
break;
case KPLUS:
/* Speed up scrolling */
if (inc < MAXINC)
inc++;
break;
case KMINUS:
/* Slow down scrolling */
if (inc > MININC)
inc--;
break;
}
}

}

/* Increment */
switch (dir) {
case DIRUP:
vy += inc;
break;
case DIRDOWN:
vy -= inc;
break;
case DIRRIGHT:
vx -= inc;
break;
case DIRLEFT:
vx += inc;
break;
}
/* Make sure we wrap properly */
if (vx > (int) vhptr->x2)
vx = 0;
if (vx < 0)
vx = vhptr->x2;
if (vy > (int) vhptr->y2)
vy = 0;
if (vy < 0)
vy = vhptr->y2;
}

} /* end of VirtualSpace */

/**********/

void main(argc,argv)
int argc;
char *argv[];
{
int memtype,width,depth,wx1,wy1,wx2,wy2,retcode;
long vfree,vreq;
GXDINFO di;

/* Display program header */
printf("\n");
printf("ÕÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͸\n");
printf("³ Scroll: Example Infinite Scroll Program PCX Programmer's Toolkit 4.00 ³\n");
printf("³ Copyright (c) Genus Microprogramming, Inc. 1988-92 All Rights Reserved. ³\n");
printf("ÔÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ;\n");
printf("\n");
printf("ÕÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͸\n");
printf("³ ³\n");
printf("³ This is an example of how to scroll a virtual buffer 'infinitely'. The ³\n");
printf("³ buffer will wrap around at the edges, so simulate an infinitely large ³\n");
printf("³ virtual buffer. This is also a good example of writing your own virtual ³\n");
printf("³ scroll function. ³\n");
printf("³ ³\n");
printf("³ Note that you can use this example with any image ... simply supply a ³\n");
printf("³ filename when you begin the program, as in SCROLL MYIMAGE.PCX. ³\n");
printf("³ Otherwise, it will look for SCROLL.PCX in the current directory. ³\n");
printf("³ ³\n");
printf("³ - To change the direction of the scrolling, use the keyboard arrow keys. ³\n");
printf("³ - To change the scroll rate, use the keyboard '+' and '-' keys. ³\n");
printf("³ - To exit the program once it has started, press the ESC key. ³\n");
printf("³ ³\n");
printf("ÔÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ;\n");
printf("\n");

/* Any command line parameters? */
if (argc > 1) {
/* Yes, so assume a filename */
strcpy(pcximage, argv[1]);
}

/* Allocate a larger toolkit buffer, to speed up file and display speed.*/
/* The toolkit defaults to using an internal 4KB buffer, but if we can */
/* spare more memory than that, declare a new buffer. */
/* REMEMBER: This MUST be a GLOBAL buffer (ie, declare OUTSIDE of procs)*/
retcode = gxSetBuffer(buffer,BUFMAX);

/* Get the file header */
if ((retcode = pcxGetFileHeader(pcximage,&header)) == gxSUCCESS) {

/* Get the display type */
pcxtype = pcxGetFileType(pcximage);

/* See if we can display the image with current hardware */
if (gxVerifyDisplayType(pcxtype) != gxSUCCESS) {
/* No, so try to map it to another type */
pcxtype = gxMapDisplayType((int) header.nplanes,(int) header.bitpx);
}

/* Make sure we did determine the display type */
if ((pcxtype >= gxMINDISP) && (pcxtype <= gxMAXDISP)) {

/* Get display information */
gxGetDisplayInfo(pcxtype, &di);

/* Get the image size */
width = header.x2 - header.x1 + 1;
depth = header.y2 - header.y1 + 1;

/* Get the virtual memory required */
vreq = gxVirtualSize(pcxtype,width,depth);

/* Check CMM free memory */
memtype = gxCMM;
vfree = gxVirtualFree(memtype);

/* See if we have enough CMM */
if (vreq > vfree) {
/* No, so check for EMM */
if (gxEMInstalled() == gxSUCCESS) {
/* Check EMM free memory */
memtype = gxEMM;
vfree = gxVirtualFree(memtype);
}

/* See if we have enough yet */
if (vreq > vfree) {
/* Not enough, so try installing DMM */
if (gxInstallDMM("",gxCMM) == gxSUCCESS) {
/* Check DMM free memory */
memtype = gxDMM;
vfree = gxVirtualFree(memtype);
}
}
}

/* Did we finally have enough memory? */
if (vfree > vreq) {
/* Yes, so load the image into a virtual buffer */
printf("Loading into virtual Memory . . .\n");
pcxtype = pcxFileImage(memtype, pcximage, vhptr, gxDETECT);

/* See if the image were loaded at all */
if (pcxtype >= pcxMINDISP && pcxtype <= pcxMAXDISP) {

/* We are loaded, so get a key to continue */
printf("Press a key to run . . .\n");
getch();

/* Define a window 160x160 (Note: This window size is arbitrary) */
/* (remember: 0 to 159 = 160) */
wx1 = (di.hres-160)/2;
wy1 = (di.vres-160)/2;
wx2 = wx1+160-1;

wy2 = wy1+160-1;

/* Set the display type and mode */
gxSetDisplay(pcxtype);
gxSetMode(gxGRAPHICS);

/* We are in graphics mode, so set the image file palette */
/* NOTE: If all your images use a default BIOS palette (or the */
/* default Paintbrush palette), just SKIP setting the palette! */

if (pcxGetFilePalette(pcxtype,pcximage,pcxpal) == gxSUCCESS) {
/* Now set it */
gxSetDisplayPalette(pcxpal);
}

/* Show unlimited scrolling, like space */
VirtualSpace(vhptr,wx1,wy1,wx2,wy2,0);

/* Free the image */
pcxFreeImage(vhptr);

/* Get back to text mode */
gxSetMode(gxTEXT);

/* Were we successful? */
if (retcode != gxSUCCESS && retcode != gxERR_ESCAPE) {
printf("gxVirtualScroll Error: %d\n",retcode);
}

}
else {
/* Error loading file to virtual buffer */
printf("\nCould not load image [%s]: %d . . .\n",pcximage,pcxtype);
}
}
else {
printf("Not enough free memory ANYWHERE!\n");
}

/* If DMM was installed, uninstall it */
retcode = gxDMInstalled();
if (retcode == gxSUCCESS) {
/* It was, so remove it */
retcode = gxRemoveDMM(gxCMM);
}
}
else {
/* Error determining display type */
printf("Image requires different hardware: %d\n",pcxtype);
}
}
else {
/* Could not get image header */
printf("\nCould not load image header [%s]: %d . . .\n",pcximage,retcode);
}

} /* end of main */



  3 Responses to “Category : C Source Code
Archive   : GXSCROLL.ZIP
Filename : SCROLL.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/