我就是用了网上的代码,不过有不少错误!在改正运行过程中出现了问题,用F7进行单步调试的时候发现:运行到标示(%%%%%)行之前一切都还正常,
但运行标示行后一切变量都变成没有定义的了,不知道为什么????我用的是Turbo c 3.0
代码如下
#include <stdio.h>
#include <math.h>
#include <alloc.h>
#include <io.h>
#include <dos.h>
#include <mem.h>
#include <conio.h>
#include <stdlib.h>
#define SCREEN_HIGHT 200
#define SCREEN_WIDTH 320
#define MMODE 0x13
unsigned int im_width,pat_size;
disp(unsigned char huge *image,unsigned char *pattern,unsigned int row,unsigned int column)
{
unsigned char far *im;
unsigned char far *buf;
unsigned char pat[256][3];
unsigned int column1,x0=0,y0=0;
int i,j;
long size;
void set_color_pat(unsigned char far pat[256][3]);
void set_mode(int);
if((row-x0)>SCREEN_HIGHT) row=SCREEN_HIGHT;
else row=row-x0;
if((im_width-y0)>SCREEN_WIDTH) column1=SCREEN_WIDTH;
else column1=im_width-y0;
set_mode(MMODE);
/* change value of red and blue */
for(i=0;i<pat_size;i++)
for(j=0;j<3;j++)
pat[i][j]=(*(pattern+i*4+(2-j)))/4;
set_color_pat(pat);
/* write to display card */
buf=(unsigned char far *)MK_FP(0xa000,0);
size=0;
for(i=0;i<row;i++)
{
size=size+SCREEN_WIDTH;
if(size<655361)
{
memcpy(buf,(image+i*column),column1);
buf=buf+SCREEN_WIDTH;
}
else
{ printf("overflow:image too large.\n");
}
}
getch();
set_mode(3);
}
void set_mode(int mode)
{ union REGS r;
r.h.ah=0;
r.h.al=mode;
int86(0x10,&r,&r);
}
void set_color_pat(unsigned char far pat[256][3])
{
union REGS r;
struct SREGS s;
r.h.ah=0x10;
r.h.al=0x12;
r.x.bx=0;
r.x.cx=256;
r.x.dx=FP_OFF(pat);
s.es=FP_SEG(pat);
int86x(0x10,&r,&r,&s);
}
main()
{
unsigned char buffer[54];
unsigned char pat[256][4];
int bit_count;
long i;
char filename[40] ;
unsigned char huge *img1;
unsigned char huge *img;
unsigned int width,higth,j,k,color;
FILE *fp1,*fp2;
union {
struct {
unsigned lobyte:4;
unsigned hibyte:4;
}parts;
struct {
unsigned char allbyte;
}whole;
}db1;
printf("Enter the filename:\n");
scanf("%s",filename);
if(!(fp1=fopen(filename,"rb")))
{
printf("Open file %s error!\n",filename);
exit(1);
}
fread(buffer,1,54,fp1);
im_width=buffer[19]*256+buffer[18];
higth=buffer[23]*256+buffer[22];
if((im_width%8)!=0)
width=(im_width/8+1)*8;
else width=im_width;
pat_size=(buffer[11]*256+buffer[10]-54)/4;
bit_count=buffer[28];
/* read color pattern */ fread(pat,sizeof(unsigned char ),pat_size*4,fp1);
%%%%% if(!(img=farcalloc((width/(8/bit_count)),sizeof(unsigned char))))
{
printf("Can't open pointor img.\n");
abort();
}
{
if(bit_count==4)
for(k=0;k<higth;k++)
{
fread(img,sizeof(unsigned char),(width/2),fp1);
for(j=0;j<width/2;j++){
db1.whole.allbyte=(*(img+j));
(*(img1+(long)(higth-1-k)*(long)width+(long)j*2))=db1.parts.hibyte;
(*(img1+(long)(higth-1-k)*(long)width+(long)j*2+11))=db1.parts.lobyte;
}
}
if(bit_count==8)
for(k=0;k<higth;k++) {
fread(img,sizeof(unsigned char),width,fp1);
for(j=0;j<width;j++)
(*(img1+(long)(higth-1-k)*(long)width+(long)j))=(*(img+j));
}
}
disp(img1,pat,higth,width);
fclose(fp1);
farfree(img);
farfree(img1);
}