|
BGI graphics not supported under Windows.
Hi there. I've recently started to revise an old school project from 10 years ago which I originally compiled under an old Borland C compiler. I've been trying to compile it again on Borland c++ 4.5, and keep running into the same error.... "bgi graphics not supported under windows". I've linked my .c file with the egavga.obj file, and the graphics.lib in an .ide file, but still meet the same problem when I try to use the Make All command.
(I haven't been able to compile the .c file on its own, which I think is how it should work.) I've been away from programming since I tried this project originaly, so if anyone can help, I'd be very grateful.
Thanks, John
Source code follows:
#include <stdio.h>
#include <string.h>
#include <windows.h>
#include <conio.h>
#include <graphics.h>
#include <alloc.h>
#include <math.h>
#include <stdlib.h>
#define EGraphics -10
#define BLACK 0
#define WHITE 15
unsigned e;
FILE *BMPfile,*MIDIfile;
struct BMP_FILE{
BITMAPFILEHEADER BMPheader;
BITMAPINFOHEADER info;
RGBQUAD Palette[256];
};
struct MIDI_FILE_HEADER{
DWORD miType;
DWORD miChunk;
UINT miFormat;
UINT miTracks;
UINT miResol;
};
struct MIDI_FILE_TRACK{
DWORD mdName;
DWORD mdChunk;
};
struct MIDI_FILE{
struct MIDI_FILE_HEADER MIDIheader;
struct MIDI_FILE_TRACK MIDImusic;
};
struct MIDI_FILE MIDIData;
struct BMP_FILE BMPData;
int index,pv,y1,y2,y3,y4,y5;
int pixelcount1,pixelcount2,pixelcount3,pixelcount4,pixelcount5;
int pixelcount6,pixelcount7,pixelcount8,pixelcount9,pixelcount10;
long z,x,y,count;
BYTE huge *ImageMemory;
char *MIDI_FILE_NAME;
/* Functions */
DWORD DWORDByteSwap ( DWORD );
UINT UINTByteSwap( UINT );
void InitGraphics(void);
unsigned getbits(unsigned x,int p,int n);
main(int argc, char *argv[])
{
textbackground(LIGHTBLUE);
if(argc == 1)
{
printf("You need to specify a file. Type the filename with the"
" extension");
return(-1);
}
if(argc == 2)
{
if((BMPfile = fopen(*++argv,"rb")) == NULL)
{
printf("\nBMPFile: %s not found\n",*argv);
return(-2);
}
if(fread(&BMPData,sizeof(struct BMP_FILE),1,BMPfile) != 1 )
{
printf("Error reading BMP fileheader \n");
return(-3);
}
if(BMPData.BMPheader.bfType != *(WORD*) "BM")
{
printf("Error not a BMP file\n");
return(-4);
}
clrscr();
printf("BMP Image Information For File %s\n\n",*argv);
printf("\tSize (in Bytes): %ld\n",BMPData.BMPheader.bfSize);
printf("\tOffset : %d\n",BMPData.BMPheader.bfOffBits);
printf("\tSize of BITMAPINFOHEADER (in bytes) : %d\n",BMPData.info.biSize);
printf("\tWidth in pixels: %ld\n",BMPData.info.biWidth);
printf("\tHeight in pixels: %ld\n",BMPData.info.biHeight);
printf("\tNumber of bit planes: %d\n",BMPData.info.biPlanes);
printf("\tBits per pixel: %d\n",BMPData.info.biBitCount);
printf("\tCompression: %ld\n",BMPData.info.biCompression);
printf("\tSize of image bits (in bytes) : %ld\n",BMPData.info.biSizeImage);
printf("\tHoriz. Res.: %ld\n",BMPData.info.biXPelsPerMeter);
printf("\tVert. Res.: %ld\n", BMPData.info.biYPelsPerMeter);
printf("\tColours Used: %d\n",BMPData.info.biClrUsed);
printf("\tNumber of important colours : %d\n",BMPData.info.biClrImportant);
printf("\n\nRGBQuad values for BMPfile %s\n",*argv);
printf("(These values are in hexadecimal notation)\n");
for (index = 0;index < pow(2,BMPData.info.biBitCount); index++ )
{
printf("\tPalette index: %2d R = %2x G = %2x B = %2x\n",index,
BMPData.Palette[index].rgbRed,BMPData.Palette[index].rgbGreen,
BMPData.Palette[index].rgbBlue);
}
getch();
clrscr();
printf("\n Please wait. The program is now reading in the pixels");
ImageMemory = (BYTE huge *)farmalloc(BMPData.BMPheader.bfSize -
BMPData.BMPheader.bfOffBits);
if(ImageMemory == NULL)
{
printf("\nNot enough memory for BMP buffer\n");
return(-5);
}
InitGraphics();
z = 0;
fseek(BMPfile,BMPData.BMPheader.bfOffBits,SEEK_SET);
setgraphmode(VGAHI);
for(y = 0; y < BMPData.info.biHeight; y++)
{
for(x = 0; x < 72; x++)
{
ImageMemory[z] = getc(BMPfile);
e = getbits(ImageMemory[z],7,1);
if(e == 1)
putpixel(8*x,BMPData.info.biHeight-1-y,BLACK);
else
putpixel(8*x,BMPData.info.biHeight-1-y,WHITE);
e = getbits(ImageMemory[z],6,1);
if(e == 1)
putpixel(8*x+1,BMPData.info.biHeight-1-y,BLACK);
else
putpixel(8*x+1,BMPData.info.biHeight-1-y,WHITE);
e = getbits(ImageMemory[z],5,1);
if(e == 1)
putpixel(8*x+2,BMPData.info.biHeight-1-y,BLACK);
else
putpixel(8*x+2,BMPData.info.biHeight-1-y,WHITE);
e = getbits(ImageMemory[z],4,1);
if(e == 1)
putpixel(8*x+3,BMPData.info.biHeight-1-y,BLACK);
else
putpixel(8*x+3,BMPData.info.biHeight-1-y,WHITE);
e = getbits(ImageMemory[z],3,1);
if(e == 1)
putpixel(8*x+4,BMPData.info.biHeight-1-y,BLACK);
else
putpixel(8*x+4,BMPData.info.biHeight-1-y,WHITE);
e = getbits(ImageMemory[z],2,1);
if(e == 1)
putpixel(8*x+5,BMPData.info.biHeight-1-y,BLACK);
else
putpixel(8*x+5,BMPData.info.biHeight-1-y,WHITE);
e = getbits(ImageMemory[z],1,1);
if(e == 1)
putpixel(8*x+6,BMPData.info.biHeight-1-y,BLACK);
else
putpixel(8*x+6,BMPData.info.biHeight-1-y,WHITE);
e = getbits(ImageMemory[z],0,1);
if(e == 1)
putpixel(8*x+7,BMPData.info.biHeight-1-y,BLACK);
else
putpixel(8*x+7,BMPData.info.biHeight-1-y,WHITE);
z++;
}
}
getch();
fseek(BMPfile,BMPData.BMPheader.bfOffBits,SEEK_SET);
z = 0;
restorecrtmode();
printf("\n\nPlease note the co-ordinates\n");
for(y = 0; y < BMPData.info.biHeight; y++)
{
count = 0;
for(x = 0; x < 72; x++)
{
ImageMemory[z] = getc(BMPfile);
if( (BMPData.info.biHeight - 1 - y) < 60)
{
for(pv = 7;pv >= 0;pv--)
{
if((x < 15) && getbits(ImageMemory[z],pv,1) != 0)
count++;
}
}
}
if( (BMPData.info.biHeight - 1 - y) < 60)
{
if(( count > 40) && (BMPData.info.biHeight - 1 - y) != 32)
{
printf("\nThere is a staff line at y = %d",BMPData.info.biHeight - 1 - y);
}
}
}
fseek(BMPfile,BMPData.BMPheader.bfOffBits,SEEK_SET);
z = 0;
printf("\n\nEnter first co-ordinate, starting with highest number\n");
scanf("%d",&y1);
printf("Enter next co-ordinate\n");
scanf("%d",&y2);
printf("Enter next co-ordinate\n");
scanf("%d",&y3);
printf("Enter next co-ordinate\n");
scanf("%d",&y4);
printf("Enter last co-ordinate\n");
scanf("%d",&y5);
fseek(BMPfile,BMPData.BMPheader.bfOffBits,SEEK_SET);
z = 0;
pixelcount1 = pixelcount2 = 0;
for(y = 0; y < BMPData.info.biHeight; y++)
{
for(x = 0; x < 72; x++)
{
ImageMemory[z] = getc(BMPfile);
for(pv = 7;pv >= 0;pv--)
{
if((8*x + (7-pv)) == 93)
{
if((abs(( BMPData.info.biHeight -1 -y) -y5) < 3)
&& getbits(ImageMemory[z],pv,1) != 0)
{
pixelcount1++;
}
if((( y5 - (BMPData.info.biHeight - 1 -y) ) < 5) &&
((y5-(BMPData.info.biHeight - 1 - y) ) >= 0) &&
getbits(ImageMemory[z],pv,1) != 0)
{
pixelcount2++;
}
if((abs(( BMPData.info.biHeight -1 -y) -y4) < 3)
&& getbits(ImageMemory[z],pv,1) != 0)
{
pixelcount3++;
}
if((( y4 - (BMPData.info.biHeight - 1 -y) ) < 5) &&
((y4-(BMPData.info.biHeight - 1 - y) ) >= 0) &&
getbits(ImageMemory[z],pv,1) != 0)
{
pixelcount4++;
}
if((abs(( BMPData.info.biHeight -1 -y) -y3) < 3)
&& getbits(ImageMemory[z],pv,1) != 0)
{
pixelcount5++;
}
if((( y3 - (BMPData.info.biHeight - 1 -y) ) < 5) &&
((y3-(BMPData.info.biHeight - 1 - y) ) >= 0) &&
getbits(ImageMemory[z],pv,1) != 0)
{
pixelcount6++;
}
if((abs(( BMPData.info.biHeight -1 -y) -y2) < 3)
&& getbits(ImageMemory[z],pv,1) != 0)
{
pixelcount7++;
}
if((( y2 - (BMPData.info.biHeight - 1 -y) ) < 5) &&
((y2-(BMPData.info.biHeight - 1 - y) ) >= 0) &&
getbits(ImageMemory[z],pv,1) != 0)
{
pixelcount8++;
}
if((abs(( BMPData.info.biHeight -1 -y) -y1) < 3)
&& getbits(ImageMemory[z],pv,1) != 0)
{
pixelcount9++;
}
if((( y1 - (BMPData.info.biHeight - 1 -y) ) < 5) &&
((y1-(BMPData.info.biHeight - 1 - y) ) >= 0) &&
getbits(ImageMemory[z],pv,1) != 0)
{
pixelcount10++;
}
}
}
z++;
}
}
getch();
clrscr();
printf("Pixelcount1 which gives high F is %d",pixelcount1);
printf("\nPixelcount2 which gives high G is %d",pixelcount2);
printf("\nPixelcount3 which gives high D is %d",pixelcount3);
printf("\nPixelcount4 which gives high E is %d",pixelcount4);
printf("\nPixelcount5 which gives B is %d",pixelcount5);
printf("\nPixelcount6 which gives high C is %d",pixelcount6);
printf("\nPixelcount7 which gives low G is %d",pixelcount7);
printf("\nPixelcount8 which gives A is %d",pixelcount8);
printf("\nPixelcount9 which gives low E is %d",pixelcount9);
printf("\nPixelcount10 which gives low F is %d",pixelcount10);
if(pixelcount1 > 3)
printf("\n\nThere is a high F present");
if(pixelcount2 > 4)
printf("\n\nThere is a high G present");
if(pixelcount3 > 3)
printf("\nThere is a high D present");
if(pixelcount4 > 4)
printf("\nThere is a high E present");
if(pixelcount5 > 3)
printf("\n\nThere is a B present");
if(pixelcount6 > 4)
printf("\n\nThere is a high C present");
if(pixelcount7 > 3)
printf("\n\nThere is a low G present");
if(pixelcount8 > 4)
printf("\n\nThere is a A present");
if(pixelcount9 > 3)
printf("\n\nThere is a low E present");
if(pixelcount10 > 4)
printf("\n\nThere is a low F present");
fclose(BMPfile);
getch();
printf("\n\nHit <Enter> to proceed");
getch();
/*From here until the return deals with the MIDI file.*/
clrscr();
printf("\nPlease enter the name of the MIDI file to be created\n");
scanf("%s",MIDI_FILE_NAME);
if((MIDIfile = fopen(MIDI_FILE_NAME,"w+b")) == NULL)
{
printf("\nUnable to open file %s",MIDI_FILE_NAME);
return(-1);
}
/*The DWORDByteSwap and UINTByteSwap functions are called because MIDI files
store bytes in a different order to intel processors. This is called
the Big Endian / Little Endian issue. */
MIDIData.MIDIheader.miType = *(DWORD*)"MThd";
MIDIData.MIDIheader.miChunk = DWORDByteSwap(6);
MIDIData.MIDIheader.miFormat = UINTByteSwap(0);
MIDIData.MIDIheader.miTracks = UINTByteSwap(1);
MIDIData.MIDIheader.miResol = UINTByteSwap(96);
MIDIData.MIDImusic.mdName = *(DWORD*)"MTrk";
MIDIData.MIDImusic.mdChunk = DWORDByteSwap(79);
if(fwrite(&MIDIData,sizeof(struct MIDI_FILE),1,MIDIfile) != 1)
{
printf("\nError writing MIDI file header\n");
return(-2);
}
fputc(0x00,MIDIfile);
fputc(0xFF,MIDIfile);
fputc(0x59,MIDIfile);
fputc(0x02,MIDIfile);
fputc(0x01,MIDIfile);
fputc(0x00,MIDIfile);
fputc(0x00,MIDIfile);
fputc(0xFF,MIDIfile);
fputc(0x58,MIDIfile);
fputc(0x04,MIDIfile);
fputc(0x04,MIDIfile);
fputc(0x02,MIDIfile);
fputc(0x18,MIDIfile);
fputc(0x08,MIDIfile);
fputc(0x00,MIDIfile);
fputc(0xFF,MIDIfile);
fputc(0x51,MIDIfile);
fputc(0x03,MIDIfile);
fputc(0x16,MIDIfile);
fputc(0xE3,MIDIfile);
fputc(0x60,MIDIfile);
fputc(0x00,MIDIfile);
fputc(0xC0,MIDIfile);
fputc(0x00,MIDIfile);
fputc(0x00,MIDIfile);
fputc(0xCD,MIDIfile);
fputc(0x29,MIDIfile);
fputc(0x00,MIDIfile);
fputc(0x90,MIDIfile);
fputc(0x4F,MIDIfile);
fputc(0x7F,MIDIfile);
fputc(0x00,MIDIfile);
fputc(0x9D,MIDIfile);
fputc(0x4F,MIDIfile);
fputc(0x7F,MIDIfile);
fputc(0x00,MIDIfile);
fputc(0x90,MIDIfile);
fputc(0x47,MIDIfile);
fputc(0x7F,MIDIfile);
fputc(0x00,MIDIfile);
fputc(0x9D,MIDIfile);
fputc(0x47,MIDIfile);
fputc(0x7F,MIDIfile);
fputc(0x00,MIDIfile);
fputc(0x90,MIDIfile);
fputc(0x43,MIDIfile);
fputc(0x7F,MIDIfile);
fputc(0x00,MIDIfile);
fputc(0x9D,MIDIfile);
fputc(0x43,MIDIfile);
fputc(0x7F,MIDIfile);
fputc(0x60,MIDIfile);
fputc(0x90,MIDIfile);
fputc(0x4F,MIDIfile);
fputc(0x00,MIDIfile);
fputc(0x00,MIDIfile);
fputc(0x9D,MIDIfile);
fputc(0x4F,MIDIfile);
fputc(0x00,MIDIfile);
fputc(0x00,MIDIfile);
fputc(0x90,MIDIfile);
fputc(0x47,MIDIfile);
fputc(0x00,MIDIfile);
fputc(0x00,MIDIfile);
fputc(0x9D,MIDIfile);
fputc(0x47,MIDIfile);
fputc(0x00,MIDIfile);
fputc(0x00,MIDIfile);
fputc(0x90,MIDIfile);
fputc(0x43,MIDIfile);
fputc(0x00,MIDIfile);
fputc(0x00,MIDIfile);
fputc(0x9D,MIDIfile);
fputc(0x43,MIDIfile);
fputc(0x00,MIDIfile);
fputc(0x60,MIDIfile);
fputc(0xFF,MIDIfile);
fputc(0x2F,MIDIfile);
fputc(0x00,MIDIfile);
fclose(MIDIfile);
printf("\n\nMIDI file has now been written.Please check to confirm");
printf("\nHit <Enter> to continue");
getch();
textbackground(BLACK);
return(0);
}
}
/* getbits: get n bits from position p */
unsigned getbits(unsigned x,int p,int n)
{
return (x >> (p+1-n)) & ~(~0 << n);
}
/* Initialize the graphics subsystem */
void InitGraphics( void )
{
int g_driver, g_mode, g_error;
/*
Make sure graphic system is not already open. Whether
it is or not, close it and open it again. Otherwise
memory for driver will be allocated each time this
function is called.
*/
closegraph();
/* initialize graphics variables */
g_driver = g_mode = g_error = 0;
/*
The call to registerbgidriver below links the display driver
to the application program. It assumes the driver was converted from
egavga.bgi to egavga.obj by the bgiobj converter program and
linked into the application program. The line egavga.obj must
be in the .prj file for the application program.
*/
registerbgidriver(EGAVGA_driver);
initgraph(&g_driver,&g_mode,"");
g_error = graphresult();
if (g_error < 0)
{
printf("Initgraph error: %s.\n",
grapherrormsg(g_error));
exit(EGraphics);
}
restorecrtmode();
}
Last edited by LuciWiz : 29-Jun-2005 at 23:36.
Reason: Please insert your C++ code between [c++] & [/c++] tags
|