home *** CD-ROM | disk | FTP | other *** search
- /*****************************************************************************/
- /* STEST.C Scaled bit map code test program. Used to compare C */
- /* implementation of bit mapped scaling versus assembly language*/
- /* version of the same. */
- /* Written by John W. Ratcliff, December 20, 1992. */
- /*****************************************************************************/
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <alloc.h>
-
- #include "video.h" // ASSEMBLY IMPLEMTATION PROTOTYPES: VGA 320x200 graphics primitives.
- #include "cvideo.h" // C IMPLEMTATION: PROTOTYPES: prototype to standard VGA 320x200 graphics primitives.
- #include "keys.h" // Define extended key code defininations.
-
- unsigned char far * far memalloc(long int siz); // Prototype memory allocation function.
- void far memfree(char far *memory); // Prototype memory free function.
-
- void far *FileLoad(char *fname,long int *siz); // Prototype file load fuction.
- int GetKey(void);
-
- unsigned char far * far memalloc(long int siz)
- {
- return(farmalloc(siz)); // C's far memory allocation functions.
- }
-
- void far memfree(char far *memory)
- {
- farfree(memory);
- }
-
- void main(int argc,char **argv)
- {
- int xcon,key,mode;
- int xloc,yloc,size;
- int far *temp;
- int width,height;
- long int siz;
- char far *blit;
- char far *pal;
- char bname[80]; // blit file name.
- char pname[80]; // palette file name.
-
- if ( argc != 2 )
- {
- printf("Usage: STEST <filename>\n");
- printf("where filename is the name of a bit mapped graphics image\n");
- printf("with the assumed extension of .BLT and the palette information\n");
- printf("is located in the file with the extension of .RGB\n");
- exit(1);
- }
-
- strcpy(bname,argv[1]);
- strcpy(pname,argv[1]);
- strcat(bname,".BLT");
- strcat(pname,".RGB");
-
- blit = FileLoad(bname,&siz);
- if ( blit == NULL )
- {
- printf("Unable to find blit file '%s'\n",bname);
- exit(1);
- }
- temp = (int *) blit;
- width = *temp++;
- height = *temp;
- if ( (long)width*(long)height+4L != siz )
- {
- printf("Not a valid blit image. '%s'\n",bname);
- exit(1);
- }
-
- pal = FileLoad(pname,&siz);
- if ( pal == NULL )
- {
- printf("Unable to find palette file '%s'\n",pname);
- exit(1);
- }
- if ( siz%3 ) // If not integer multiple of 3 (RGB) not valid size.
- {
- printf("Palette file invalid size. '%s'\n",pname);
- exit(1);
- }
-
- VidOn();
- VGAP(pal,0,siz/3); // Set color palette.
-
- xcon = 0;
- mode = 0; // C by default.
- xloc = 0; yloc = 0;
- size = FULLSIZE;
-
- // Interactive BitMap display, and scaling.
-
- do
- {
- if ( mode )
- PutBlitSize(blit,xloc,yloc,size);
- else
- CPutBlitSize(blit,xloc,yloc,size);
- key = GetKey();
- switch ( key )
- {
- case '+': size++; break;
- case '-': size--; break;
- case LEFT: xloc--; break;
- case RIGHT: xloc++; break;
- case UP: yloc--; break;
- case DOWN: yloc++; break;
- case HOME: xloc--; yloc--; break;
- case PGUP: xloc++; yloc--; break;
- case END: xloc--; yloc++; break;
- case PGDN: xloc++; yloc++; break;
- case ESC: xcon = 1;
- case SPACEBAR:
- if ( mode )
- mode = 0;
- else
- mode = 1;
- break;
-
- }
- if ( size > FULLSIZE ) size = FULLSIZE;
- if ( size <= 0 ) size = 1;
- if ( xloc < 0 ) xloc = 0;
- if ( yloc < 0 ) yloc = 0;
- if ( xloc+width > 320 ) xloc = 320-width;
- if ( yloc+height > 200 ) yloc = 200-height;
- } while (!xcon);
-
-
- // Call C implementation of PutBlit until a key is pressed.
-
-
- do
- {
- xloc = rand()%(320-width);
- yloc = rand()%(200-height);
- CPutBlit(blit,xloc,yloc);
- } while ( !kbhit() );
- getch();
-
- // Call assembly implementation of PutBlit until a key is pressed
-
- do
- {
- xloc = rand()%(320-width);
- yloc = rand()%(200-height);
- PutBlit(blit,xloc,yloc);
- } while ( !kbhit() );
- getch();
-
- // Call C implementation of PutBlitSize until a key is pressed
-
- do
- {
- xloc = rand()%(320-width);
- yloc = rand()%(200-height);
- size = rand()%FULLSIZE+1;
- CPutBlitSize(blit,xloc,yloc,size);
- } while ( !kbhit() );
- getch();
-
- // Call Assembly implementation of PutBlitSize until a key is pressed
-
- do
- {
- xloc = rand()%(320-width);
- yloc = rand()%(200-height);
- size = rand()%FULLSIZE+1;
- PutBlitSize(blit,xloc,yloc,size);
- } while ( !kbhit() );
- getch();
-
-
-
- VidOff();
-
- }
-
-
- void far * FileLoad(char *fname,long int *siz)
- {
- unsigned char far *data;
- FILE *fph;
- long int insiz;
-
- fph = fopen(fname, "rb");
- if ( fph == NULL ) return(0);
- fseek( fph, 0L, SEEK_END);
- insiz = ftell( fph );
- fseek( fph, 0L, SEEK_SET);
- data = farmalloc(insiz); // Allocate memory to read sound file in.
- if ( !data )
- {
- fclose(fph);
- return(0);
- }
- fread(data, insiz, 1, fph); // Read sound data into memory.
- fclose(fph); // Close out the file.
- *siz = insiz; // Assign total size.
- return(data);
- }
-
-
- int GetKey(void)
- {
- int key;
-
- key = getch();
- if ( !key ) key = getch()+256; // process extended key code.
- return(key);
- }
-