home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / screen / stest / stest.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-12-22  |  5.0 KB  |  214 lines

  1. /*****************************************************************************/
  2. /* STEST.C            Scaled bit map code test program.  Used to compare C                 */
  3. /*                            implementation of bit mapped scaling versus assembly language*/
  4. /*                            version of the same.                                                                                 */
  5. /*                            Written by John W. Ratcliff, December 20, 1992.                          */
  6. /*****************************************************************************/
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10. #include <alloc.h>
  11.  
  12. #include "video.h" // ASSEMBLY IMPLEMTATION PROTOTYPES: VGA 320x200 graphics primitives.
  13. #include "cvideo.h" // C IMPLEMTATION: PROTOTYPES: prototype to standard VGA 320x200 graphics primitives.
  14. #include "keys.h" // Define extended key code defininations.
  15.  
  16. unsigned char far * far memalloc(long int siz); // Prototype memory allocation function.
  17. void far memfree(char far *memory); // Prototype memory free function.
  18.  
  19. void far *FileLoad(char *fname,long int *siz); // Prototype file load fuction.
  20. int GetKey(void);
  21.  
  22. unsigned char far * far memalloc(long int siz)
  23. {
  24.     return(farmalloc(siz)); // C's far memory allocation functions.
  25. }
  26.  
  27. void far memfree(char far *memory)
  28. {
  29.     farfree(memory);
  30. }
  31.  
  32. void main(int argc,char **argv)
  33. {
  34.     int xcon,key,mode;
  35.     int xloc,yloc,size;
  36.     int far *temp;
  37.     int width,height;
  38.     long int siz;
  39.     char far *blit;
  40.     char far *pal;
  41.     char bname[80];     // blit file name.
  42.     char pname[80];     // palette file name.
  43.  
  44.     if ( argc != 2 )
  45.     {
  46.         printf("Usage: STEST <filename>\n");
  47.         printf("where filename is the name of a bit mapped graphics image\n");
  48.         printf("with the assumed extension of .BLT and the palette information\n");
  49.         printf("is located in the file with the extension of .RGB\n");
  50.         exit(1);
  51.     }
  52.  
  53.     strcpy(bname,argv[1]);
  54.     strcpy(pname,argv[1]);
  55.     strcat(bname,".BLT");
  56.     strcat(pname,".RGB");
  57.  
  58.     blit = FileLoad(bname,&siz);
  59.     if ( blit == NULL )
  60.     {
  61.         printf("Unable to find blit file '%s'\n",bname);
  62.         exit(1);
  63.     }
  64.     temp = (int *) blit;
  65.     width = *temp++;
  66.     height = *temp;
  67.     if ( (long)width*(long)height+4L != siz )
  68.     {
  69.         printf("Not a valid blit image. '%s'\n",bname);
  70.         exit(1);
  71.     }
  72.  
  73.     pal = FileLoad(pname,&siz);
  74.     if ( pal == NULL )
  75.     {
  76.         printf("Unable to find palette file '%s'\n",pname);
  77.         exit(1);
  78.     }
  79.     if ( siz%3 )    // If not integer multiple of 3 (RGB) not valid size.
  80.     {
  81.         printf("Palette file invalid size. '%s'\n",pname);
  82.         exit(1);
  83.     }
  84.  
  85.     VidOn();
  86.     VGAP(pal,0,siz/3);    // Set color palette.
  87.  
  88.     xcon = 0;
  89.     mode = 0; // C by default.
  90.     xloc = 0; yloc = 0;
  91.     size = FULLSIZE;
  92.  
  93. // Interactive BitMap display, and scaling.
  94.  
  95.     do
  96.     {
  97.         if ( mode )
  98.             PutBlitSize(blit,xloc,yloc,size);
  99.         else
  100.             CPutBlitSize(blit,xloc,yloc,size);
  101.         key = GetKey();
  102.         switch ( key )
  103.         {
  104.             case '+': size++; break;
  105.             case '-': size--; break;
  106.             case LEFT: xloc--; break;
  107.             case RIGHT: xloc++; break;
  108.             case UP:     yloc--; break;
  109.             case DOWN: yloc++; break;
  110.             case HOME: xloc--; yloc--; break;
  111.             case PGUP: xloc++; yloc--; break;
  112.             case END: xloc--; yloc++; break;
  113.             case PGDN: xloc++; yloc++; break;
  114.             case ESC: xcon = 1;
  115.             case SPACEBAR:
  116.                 if ( mode )
  117.                     mode = 0;
  118.                 else
  119.                     mode = 1;
  120.                 break;
  121.  
  122.         }
  123.         if ( size > FULLSIZE ) size = FULLSIZE;
  124.         if ( size <= 0 ) size = 1;
  125.         if ( xloc < 0 ) xloc = 0;
  126.         if ( yloc < 0 ) yloc = 0;
  127.         if ( xloc+width > 320 ) xloc = 320-width;
  128.         if ( yloc+height > 200 ) yloc = 200-height;
  129.     } while (!xcon);
  130.  
  131.  
  132. // Call C implementation of PutBlit until a key is pressed.
  133.  
  134.  
  135.     do
  136.     {
  137.         xloc = rand()%(320-width);
  138.         yloc = rand()%(200-height);
  139.         CPutBlit(blit,xloc,yloc);
  140.     } while ( !kbhit() );
  141.     getch();
  142.  
  143. // Call assembly implementation of PutBlit until a key is pressed
  144.  
  145.     do
  146.     {
  147.         xloc = rand()%(320-width);
  148.         yloc = rand()%(200-height);
  149.         PutBlit(blit,xloc,yloc);
  150.     } while ( !kbhit() );
  151.     getch();
  152.  
  153. // Call C implementation of PutBlitSize until a key is pressed
  154.  
  155.     do
  156.     {
  157.         xloc = rand()%(320-width);
  158.         yloc = rand()%(200-height);
  159.         size = rand()%FULLSIZE+1;
  160.         CPutBlitSize(blit,xloc,yloc,size);
  161.     } while ( !kbhit() );
  162.     getch();
  163.  
  164. // Call Assembly implementation of PutBlitSize until a key is pressed
  165.  
  166.     do
  167.     {
  168.         xloc = rand()%(320-width);
  169.         yloc = rand()%(200-height);
  170.         size = rand()%FULLSIZE+1;
  171.         PutBlitSize(blit,xloc,yloc,size);
  172.     } while ( !kbhit() );
  173.     getch();
  174.  
  175.  
  176.  
  177.     VidOff();
  178.  
  179. }
  180.  
  181.  
  182. void far * FileLoad(char *fname,long int *siz)
  183. {
  184.     unsigned char far *data;
  185.     FILE *fph;
  186.     long int insiz;
  187.  
  188.     fph = fopen(fname, "rb");
  189.     if ( fph == NULL ) return(0);
  190.     fseek( fph, 0L, SEEK_END);
  191.     insiz = ftell( fph );
  192.     fseek( fph, 0L, SEEK_SET);
  193.     data = farmalloc(insiz);    // Allocate memory to read sound file in.
  194.     if ( !data )
  195.     {
  196.         fclose(fph);
  197.         return(0);
  198.     }
  199.     fread(data, insiz, 1, fph); // Read sound data into memory.
  200.     fclose(fph); // Close out the file.
  201.     *siz = insiz; // Assign total size.
  202.     return(data);
  203. }
  204.  
  205.  
  206. int GetKey(void)
  207. {
  208.     int key;
  209.  
  210.     key = getch();
  211.     if ( !key ) key = getch()+256;    // process extended key code.
  212.     return(key);
  213. }
  214.