home *** CD-ROM | disk | FTP | other *** search
- #include <graphics.h>
- #include <stdio.h>
- #include <alloc.h>
- #include <fcntl.h>
- #include <dos.h>
- #include <conio.h>
-
- #define TRUE 1
- #define FALSE 0
- #define MaxX 320
- #define MaxY 200
- #define MaxInt 32767
- #define ImageStart 772 /* Start of BitMap in Image File */
- #define A_VGA_Driver 9
- #define PalOffset 4 /* Start of Palette in Image File */
-
- int SetVideoMode(void);
- void SetPalette(char *InBuf);
-
- /***********************************************************************
- * *
- * VGALoad first reads the image file from the command line and *
- * determines if it is a valid bitmap. It then reads and sets the *
- * palette from the image file. The buffer is filled and written *
- * to video memory, which starts at [$A000:0000], until the file is *
- * empty. The image can be repostioned on the screen by adjusting *
- * the MemIndex value. *
- * *
- ***********************************************************************/
-
- void main(int argc,char *argv[])
- {
-
- int Infile;
- int Width;
- int Height;
- unsigned long BufSize;
- long Vertical;
- long Horizon;
- long MemIndex;
- long ArrayIndex;
- unsigned char *InBuf;
-
-
- if ((SetVideoMode() == TRUE) || (argc != 2))
- {
-
- Infile = open(argv[1], O_RDONLY | O_BINARY);
- BufSize=filelength( Infile );
- if (BufSize > MaxInt)
- BufSize = MaxInt;
-
- InBuf = malloc(BufSize);
- read( Infile, InBuf, BufSize );
-
- Width = *( InBuf + 0) + *( InBuf + 1)*256;
- Height = *( InBuf + 2) + *( InBuf + 3)*256;
-
- if ((Width < MaxX) && (Height < MaxY))
- {
-
- SetPalette(InBuf);
-
- MemIndex = 0;
- ArrayIndex = ImageStart;
- for( Vertical = 1; Vertical <= Height; Vertical++)
- for( Horizon = 1; Horizon <= MaxX; Horizon++)
- {
-
- if (Horizon <= Width)
- {
- /* Place BitMap buffer into Video Memory */
- poke( 0xA000, MemIndex, *( InBuf + ArrayIndex ));
- if ( ArrayIndex >= BufSize)
- {
-
- read( Infile, InBuf, BufSize );
- ArrayIndex = 0;
-
- }
- ArrayIndex++;
- }
- MemIndex++;
- }
- getch();
- }
-
- free(InBuf);
- close(Infile);
-
- }
- textmode(LASTMODE);
- }
-
- /***********************************************************************
- * *
- * Sets video display to VGA 320x200x256 mode after first checking *
- * to see if the monitor supports that mode. *
- * *
- ***********************************************************************/
-
- int SetVideoMode()
- {
-
- union REGS regs;
- int Driver;
- int Mode;
-
- detectgraph( &Driver, &Mode ); /* Detects VGA Monitor */
- if ( Driver == A_VGA_Driver )
- {
-
- regs.h.ah = 0;
- regs.h.al = 0x13; /* 320x200x256 VGA Mode */
- int86(0x10, ®s, ®s);
- return(TRUE);
-
- }
- else return(FALSE);
-
- }
-
- /***********************************************************************
- * *
- * Sets the display palette to the current image palette before *
- * displaying that image. This C code uses port addresses to *
- * change the video palette to the image palette, whereas the *
- * Pascal Code uses interrupt $10. Either one can be used with the *
- * same results. *
- * *
- ***********************************************************************/
-
- void SetPalette(char *InBuf)
- {
- int color;
-
- for (color=0; color < 256; color++)
- {
-
- outportb( 0x3C8, color );
- outportb( 0x3C9, *( InBuf + PalOffset + (color * 3) + 0 ));
- outportb( 0x3C9, *( InBuf + PalOffset + (color * 3) + 1 ));
- outportb( 0x3C9, *( InBuf + PalOffset + (color * 3) + 2 ));
-
- }
- }
-