⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 makemmp.c

📁 一个C做的蛇蛇游戏阿
💻 C
字号:
/******************************************/
/*        makemmp.c of goldenbugs         */
/*                                        */
/*            make mmp files              */
/*                                        */
/*          Cat Tom  4.14.2003            */
/******************************************/


#include<conio.h>
#include<stdio.h>
#include<process.h>
#include<graphics.h>
#include<bios.h>
#include<stdlib.h>
#include<time.h>
#include<dos.h>


struct bmphead{
unsigned char b;
unsigned char m;
unsigned long bfsize;
unsigned int bfresterved1;
unsigned int bfresterved2;
unsigned long bfoffbits;
unsigned long bitsize;
unsigned long bmpwidth;
unsigned long bmpheight;
unsigned int bmpplanes;
unsigned int bmpcount;
unsigned long bmpcompression;
unsigned long bmpimgsize;
unsigned long bmpxpeispermeter;
unsigned long bmpypeispermeter;
unsigned long bmpcirused;
unsigned long bmpimportant;
}bmp;
/*----------------------------------------------------------------------------------------------*/
struct ColorIndex
{
        unsigned char Blue;
        unsigned char Green;
        unsigned char Red;
        unsigned char Reserved;
}index[16];
int pageno;

/*==============================================================================================*/
void SetPlate(int ColorIndex,char Red,char Green,char Blue)
{
        outportb(0x3c8,ColorIndex);
        outportb(0x3c9,Red);
        outportb(0x3c9,Green);
        outportb(0x3c9,Blue);
}
/*----------------------------------------------------------------------------------------------*/


void showbmp(char *filename)
{
        FILE *fp;
        char c,temp1,temp2;
        register int m;
        int n;
        register unsigned long i=0,j=0;
        struct palettetype  *sq;

        if((fp=fopen(filename,"rb"))==NULL)
                printf("bmp file open error!");
        else
        {
        fread(&bmp,sizeof(struct bmphead),1,fp);
        fread(index,sizeof(struct ColorIndex),16,fp);
        }
        if(bmp.bmpwidth%32==0)
                n=bmp.bmpwidth/2;
        else    n=4+bmp.bmpwidth/2-(bmp.bmpwidth/2)%4;

        fseek(fp, bmp.bfoffbits,0);
        for(m=0; m<bmp.bmpheight; m++){
                j=0;
                for(i=0;i<n;i++)
                {
                c=fgetc(fp);
                if(j<bmp.bmpwidth)
                        {
                        temp1=(c&0xF0)>>4;
                        temp2=c&0x0F;
                        putpixel(j,m,temp1);
                        j++;
                        putpixel(j,m,temp2);
                        j++;
                        }
                }
        }
        fclose(fp);
}


void savemmp(char *filename)
{
 int i,j;
 FILE *fp;
 if((fp=fopen(filename,"wb"))==NULL)
 {
  printf("mmp file open error!\n");
  exit(0);
 }

 fwrite(&bmp.bmpwidth,sizeof(long),1,fp);
 fwrite(&bmp.bmpheight,sizeof(long),1,fp);

 for(i=0;i<bmp.bmpheight;i++)
   for(j=0;j<bmp.bmpwidth;j++)
     putc(getpixel(j,i),fp);
 fclose(fp);
}


main()
{
 int gd=VGA,gm=VGAHI;
 char *bmpfile[10],*mmpfile[10];
 printf("To change bmp file into Memory Picture files.\n\n");
 printf("Input the filename of the bmp file(*.bmp):");
 gets(bmpfile);
 printf("Input the filename of the mmp file(*.mmp):");
 gets(mmpfile);
 initgraph(&gd,&gm,"");
 showbmp(bmpfile);
 savemmp(mmpfile);
 getch();
 closegraph();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -