#include
#include //exit()
#include<dos.h> //in86()
#include //close()
#include //open()
#include //lseek(),read()
#include //outp(),getch()
#define VGA256 0x13 //320*200 256色 显示模式
#define TEXT_MODE 0x03 //80×25 16 色 文本模式
#define SCREEN_HEIGHT 200 //图象高度,像素单位
#define SCREEN_WIDTH 320 //图象宽度,像素单位
#define PALETTE_MASK 0x3c6 //调色板屏蔽寄存器端口,放入0xff可以通过调色板索引寄存器0x3c7和0x3c8访问你希望的寄存器
#define PALETTE_REGISTER_RD 0x3c7 //读颜色寄存器端口
#define PALETTE_REGISTER_WR 0x3c8 //写颜色寄存器端口
#define PALETTE_DATA 0x3c9 //调色板数据寄存器端口
unsigned char far *video_buffer=(char far *)0xA0000000L;
typedef struct BMP_file
{
unsigned int bfType; //这里恒定等于0x4D42,ASCII字符‘BM’
unsigned long bfSize; //文件大小,以字节为单位
unsigned int Reserved1; //备用,必须为0
unsigned int reserved2; //备用,必须为0
unsigned long bfOffset; //数据区在文件中的位置偏移量,以字节为单位
}bitmapfile; //文件头结构体,14 字节
typedef struct BMP_info
{
unsigned long biSize; //位图信息头大小,本结构所占用字节数
unsigned long biWidth; //图象宽度,像素单位
unsigned long biHeight; //图象高度,像素单位
unsigned int biPlanes; //位平面树,目标设备的级别,必须为1
unsigned int biBitCount; //单位像素的位数,表示BMP图片的颜色位数,必须是1(双色 ),4(16色),8(256色),24位图(真彩色),32位图
unsigned long biCompression; //图片压缩属性,必须为:0(不压缩),1(BI_RLE8压缩类型)或2(BI_RLE4压缩类型)之一
unsigned long biSizeImage; //表示图片数据区的大小,当biBompression等于0时,这里的值可以省略
unsigned long biXpolsPerMeter; //水平分辨率,每米像素数,可省略
unsigned long biYpelsPerMeter; //垂直分辨率,每米像素数,可省略
unsigned long biClrUsed; //表示使用了多少个颜色索引表,一般biBitCount属性小于16才会用到,等于0时表示有2^biBitCount个颜色索引表
unsigned long biClrImportant; //表示有多少个重要的颜色,等于0时表示所有颜色都很重要
}bitmapinfo; //位图信息头,40 字节
typedef struct RGB_BMP_typ
{
unsigned char blue; //蓝色的亮度(值范围为0-255)
unsigned char green; //绿色的亮度(值范围为0-255)
unsigned char red; //红色的亮度(值范围为0-255)
unsigned char reserved; //保留,必须为0
}RGB_BMP,*RGB_BMP_ptr; //单个像素颜色结构体,4 字节
typedef struct bmp_picture_typ
{
bitmapfile file; //位图文件头
bitmapinfo info; //位图信息头
RGB_BMP palette[256]; //位图颜色表
} bmp_picture, *bmp_picture_ptr; //位图非数据区结构体
void Set_BMP_Palette_Register(int index,RGB_BMP_ptr color) //设置调色板寄存器……
{
outp(PALETTE_MASK,0xff);
outp(PALETTE_REGISTER_WR,index);
outp(PALETTE_DATA,color->red>>2);
outp(PALETTE_DATA,color->green>>2);
outp(PALETTE_DATA,color->blue>>2);
}
void Check_Bmp(bmp_picture_ptr bmp_ptr) //检测是否是BMP文件
{
if(bmp_ptr->file.bfType!=0x4d42)
{
printf("Not a BMP file!\n");
exit(1);
}
if(bmp_ptr->info.biCompression!=0)
{
printf("Can not display a compressed BMP file!\n");
exit(1);
}
if(bmp_ptr->info.biBitCount!=8)
{
printf("Not a index 16 color BMP file!\n");
exit(1);
}
}
void BMP_Load_Screen(char *bmp) //载入BMP文件并显示……
{