delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/04/06/00:59:17

Message-ID: <35286AB8.2307AC67@bellsouth.net>
Date: Mon, 06 Apr 1998 00:40:12 -0500
From: dragon <Hutch66 AT bellsouth DOT net>
Reply-To: afriend AT there DOT com
MIME-Version: 1.0
To: djgpp AT delorie DOT com
Subject: Graphics trouble (ASM?)

Hello,

I have not programmed in roughly two years. I thought I would start back
as a hobby so I apologize in advance if I ask something silly.

I want to work with some graphics programs. the following is some code
that I downloaded but can not compile -I am assuming there is a problem
with ASM language that is being referenced. I have checked the FAQ, but
it did not seem to help. Is there another place that I can get code of
this nature?
Alan

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

** Demonstration of loading and displaying an 8-bit BMP
file.              **
**  by Steven H
Don                                                        **
*****************************************************************************

** Use at least a COMPACT memory model when
compiling                      **
*****************************************************************************

**
**
** For questions, feel free to e-mail
me.                                  **
**
**
**
shd AT earthling DOT net                                                    **
**
http://shd.home.ml.org                                               **
**
**
****************************************************************************/

#include <dos.h>
#include <stdio.h>

void VgaScreen ()
/*This sets the display to VGA 320x200 in 256 colours*/
{
  asm {
    mov ax, 0x13
    int 0x10
  }
}

void TextScreen ()
/*This resets the display to text mode*/
{
  asm {
    mov ax, 0x3
    int 0x10
  }
}

void SetDAC (unsigned char DAC, unsigned char R, unsigned char G,
unsigned char B)
{
  /*This sets a DAC register to a specific Red Green Blue-value*/
  outportb (0x3c8, DAC);
  outportb (0x3c9, R);
  outportb (0x3c9, G);
  outportb (0x3c9, B);
}

void LoadBMP (char *FileName)
/*
  This loads in the actual BMP-file and displays it.
*/
{
   /*BMP Header structure*/
   struct BMPHeader {
     unsigned int bfType;
     long         bfSize,
                  bfReserved,
                  bfOffBits,
                  biSize,
                  biWidth,
                  biHeight;
     unsigned int biPlanes,
                  biBitCount;
     long         biCompression,
                  biSizeImage,
                  biXPelsPerMeter,
                  biYPelsPerMeter,
                  biClrUsed,
                  biClrImportant;
   } Header;
   /*File handle*/
   FILE *BMPFile;
   /*Required for palette*/
   unsigned char c, Palette[256][4];
   /*USed for loading into video memory*/
   unsigned int offset, lines;

   /*Set up a pointer to the vga memory at A000:0000*/
   char far *screen; screen = MK_FP (0xA000,0);

   /*Check to see whether the file exists and can be opened*/
   BMPFile = fopen (FileName, "rb");
   if (BMPFile == NULL)  {
      strcat (FileName,".BMP");
      BMPFile = fopen (FileName, "rb");
      if (BMPFile == NULL) {
 printf ("Couldn't open file.");
 return;
      }
   }

   /*Read in header information*/
   fread (&Header, 54, 1, BMPFile);

   /*Check to see whether we can display it*/

   if (Header.bfType != 19778 || Header.bfReserved != 0 ||
Header.biPlanes !=1) {
     /*Not a valid bitmap file - don't display*/
     fclose (BMPFile);
     return;
   }
   if (Header.biCompression != 0) {
     /*Compressed file - don't display*/
     fclose (BMPFile);
     return;
   }
   if (Header.biBitCount != 8) {
     /*Other than 8-bit colour - don't display*/
     fclose (BMPFile);
     return;
   }
   if (Header.biWidth > 320 || Header.biHeight > 200) {
     /*Too large - don't display*/
     fclose (BMPFile);
     return;
   }

   /*Load in the palette*/
   fread (&Palette, 1024, 1, BMPFile);
   for (c = 0; c < 255; c++) {
     SetDAC (c, Palette[c][2] >> 2, Palette[c][1] >> 2, Palette[c][0] >>
2);
   }

   /*Set appropriate position to display graphics data*/
   offset = (100 + (Header.biHeight >> 1)) * 320 + 160 - (Header.biWidth
>> 1);

   /*We've read no lines so far*/
   lines = 0;

   /*Decode and display graphics*/
   while (lines < Header.biHeight) {
      /*Read next line*/
      fread (&screen [offset], Header.biWidth, 1, BMPFile);
      /*Move up one line on the screen*/
      offset -= 320;
      /*increase amount of lines read*/
      lines++;
   }
   fclose (BMPFile);
}

void main (int argcount, char *argvalue[])
{
   char FileName[80];

   if (argcount>1) {
     strcpy (FileName,argvalue[1]);
   } else {
     printf ("Enter filename:"); gets (FileName);
   }

   VgaScreen ();
   LoadBMP (FileName);
   getch ();
   TextScreen ();

}


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019