#include   <stdlib.h>
#include   <stdio.h>
#include   <string.h>
#include   <fcntl.h>
#include   <dos.h>
#include   <bios.h>
#include   <io.h>
#include   <graphics.h>
#include <conio.h>
void   initgraphs(int   Vmode)
{
   union   REGS   inregs,outregs;
   inregs.h.ah=0;
   inregs.h.al=Vmode;
   int86(0x10,&inregs,&outregs);
}

void   set_color_map(int   i,int   n,char   *r,char   *g,char   *b)
{
   union   REGS   regs;   
   struct   SREGS   sr;
   char   buff[3*256];
   int   m;
   for(m=0;m<n;m++)
   {
        buff[3*m]=*r++>>2;
        buff[3*m+1]=*b++>>2;
        buff[3*m+2]=*g++>>2;
   }
   regs.h.ah=0x10;
   regs.h.al=0x12;
   regs.x.bx=0;   
   regs.x.cx=256;   
   sr.es=FP_SEG(&buff);   
   regs.x.dx=FP_OFF(&buff);
   int86x(0x10,&regs,&regs,&sr);
}


int   main()
{
   union   REGS   in,out   ;
   unsigned   char   CUR_MODE,CUR_PAGE;
   int   i,j,k;
   FILE   *fp;
   int   vseg;
   int readSize;
   char far *ptr = (char far *)0xA0000000;                  //显存地址
   char   r[256],g[256],b[256],rev[256];
   int   Vmode;
   char file_name[20];
   unsigned char *tempBMP;
   int   flag=0;
   in.h.ah=15;
   int86(0x10,&in,&out);         //用于退出时恢复原始画面
   CUR_MODE=out.h.al;
   CUR_PAGE=out.h.bh;
   strcpy(file_name,"c:\\winnt256.bmp");
   Vmode=0x13;

   initgraphs(Vmode);
  
  

   if((fp=fopen(file_name,"rb"))==NULL)   
   {
    printf("map is not found!");
    getch();
    return 0;
   }



fseek(fp,54,SEEK_SET);

for(i=0;i<256;i++)
{
   fread(r+i,1,1,fp);
   fread(b+i,1,1,fp);
   fread(g+i,1,1,fp);
   fread(rev+i,1,1,fp);
}
set_color_map(0,256,g,r,b);

   fseek(fp,1078,SEEK_SET);
   for (i=199;i>=0;i--)
   {   
   tempBMP = (unsigned char *)malloc(320);
   fread(tempBMP,320,1,fp);
   for(j=0;j<320;j++)
   {
    ptr[(i<<8)+(i<<6)+j] = tempBMP[j];
   }
   free(tempBMP);
   }

    fclose(fp);
   getch();

   in.h.ah=0;   
   in.h.al=CUR_MODE;   
   in.h.bl=CUR_PAGE;   
   int86(0x10,&in,&out);
    return 0;
}

