www.pudn.com > SuperMario.zip > ENGINE.CPP
#include#include #include #include #include "engine.h" BITMAP *screen; int set_video_mode(int w,int h) { char mode; if(w==320&&h==200) mode=0x13; else return 0; union REGS inregs,outregs; inregs.h.ah=0; inregs.h.al=mode; int86(0x10,&inregs,&outregs); screen=(BITMAP *)malloc(sizeof(screen)); screen->type=VIDEO_MEM; screen->w=w; screen->h=h; screen->buffer=(char far *)0xa0000000L; return 1; } BITMAP *creat_bitmap(int w,int h) { BITMAP *temp; temp=(BITMAP *)malloc(sizeof(temp)); if((temp->buffer=(char far *)farmalloc((long)w*(long)h+1))==NULL) return(0); temp->w=w; temp->h=h; temp->type=MEM; return temp; } int blit(BITMAP *dest,BITMAP *source,int x1,int y1,int x2,int y2,int w,int h) { unsigned offset_d,offset_s; int i; if(x1>dest->w)return 0; if(x1<0){w+=x1;x1=0;} if(w<0)return 0; if(x1+w>dest->w)w=dest->w-x1; if(w<0)return 0; if(y1<0){h+=y1;y1=0;} if(h<0)return 0; if(y1+h>dest->h)h=dest->h-y1; if(h<0)return 0; offset_d=x1+y1*dest->w; offset_s=x2+y2*source->w; for(i=0;i buffer+offset_d,source->buffer+offset_s,w); offset_d+=dest->w; offset_s+=source->w; } return 1; } int blit_mask(BITMAP *dest,BITMAP *source,int x1,int y1,int x2,int y2,int w,int h) { unsigned offset_d,offset_s; int i,j; char data; if(x1>dest->w)return 0; if(x1<0){w+=x1;x1=0;} if(w<0)return 0; if(x1+w>dest->w)w=dest->w-x1; if(w<0)return 0; if(y1<0){h+=y1;y1=0;} if(h<0)return 0; if(y1+h>dest->h)h=dest->h-y1; if(h<0)return 0; offset_d=x1+y1*dest->w; offset_s=x2+y2*source->w; for(i=0;i buffer[offset_s+j])) dest->buffer[offset_d+j]=data; offset_d+=dest->w; offset_s+=source->w; } return 1; } void del_bitmap(BITMAP *temp) { if(temp->buffer)farfree(temp->buffer); if(temp)free(temp); } void wait_vsync(void) { while(inp(0x3da)&0x08); while(!(inp(0x3da)&0x08)); } void set_text_mode() { asm{ XOR AH,AH MOV AL,3 MOV BL,8 INT 10H } } void clean_bitmap(BITMAP *temp,int col) { _fmemset(temp->buffer,col,temp->w*temp->h); }