Jump to content
  • Advertisement
Sign in to follow this  
kamyarseifi

loading a simple bmp

This topic is 2907 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi every one , i have written a bmp file loader but i have problem with it, my compiler is turbo c++ and my code is this:

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

unsigned char buf[14][80];
void goto_xy(int x,int y);
void load_pic();
int main()
{
load_pic();
getch();
return 0;
}

void load_pic()
{
char fname[80];
FILE *fp;
register int i,j;
char far *ptr= (char far *)0xB8000000;
char far *temp;

temp=ptr;
for(i=0;i<14;i++)
for(j=0;j<80;j+=2){
buf[j]=*temp;
buf[j+1]=*(temp+8152);
*temp=0;
*(temp+8152)=0;
temp++;
}
goto_xy(0,0);
printf("enter file name: ");
gets(fname);
fp=fopen(fname,"rb");
if(fp==NULL){
printf("cannot open the file,press a key...");
temp=ptr;
for(i=0;i<14;i++)
for(j=0;j<80;j+=2){
*temp=buf[j];
*(temp+8152)=buf[j+1];
temp++;
}
return ;
}
for(i=0;i<8152;i++){
*ptr=getc(fp);
*(ptr+8152)=getc(fp);
ptr++;
}
fclose(fp);
}



void goto_xy(int x,int y)
{
union REGS r;
r.h.ah=2;
r.h.dl=y;
r.h.dh=x;
r.h.bh=0;
int86(0x10,&r,&r);
}

the problem is with buf[j] for displaying , it is "general protection exception, 0x215F:0x01BB Processor Fault" can anyone help me?

Share this post


Link to post
Share on other sites
Advertisement
*shudder*

It looks like you're in real mode. Text mode memory isn't at 0xB8000000 (unless a far cast actually composes the segment:offset). Text mode memory is in segment 0xB800 but since segments overlap every 16 bytes the linear offset is actually 0xB8000.

However if you're running this under Windows there's a chance that this is actually a privileged operation.

Jans.

Share this post


Link to post
Share on other sites
As Jansic said, unless you're running some flavour of DOS, I would be very surprised if this worked.

Here in the 21st century we use graphics APIs to draw to the screen [smile]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!