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

📄 buffer.h

📁 一些GBA游戏的开发资料
💻 H
字号:
unsigned char far *double_buffer=NULL;
unsigned int buffer_height=SCREEN_HEIGHT;
unsigned int buffer_size=SCREEN_WIDTH*SCREEN_HEIGHT/2;

int Create_Double_Buffer(int num_lines)
{
if((double_buffer=
(unsigned char far*)malloc(SCREEN_WIDTH*(num_lines+1)))==NULL)
return(0);
buffer_height=num_lines;
buffer_size=SCREEN_WIDTH*num_lines/2;
_fmemset(double_buffer,0,SCREEN_WIDTH*num_lines);
return(1);
}


void Plot_Pixel_Fast_DB(int x,int y,unsigned char color)
{
double_buffer[((y<<8)+(y<<6))+x]=color;
}

void Bline_DB(int x0,int y0,int x1,int y1,unsigned char color)
{
int dx,dy,x_inc,y_inc,error=0,index;
unsigned char far *vb_start=double_buffer;
vb_start=vb_start+((unsigned int )y0<<6)+((unsigned int)y0<<8)+(unsigned int)x0;
dx=x1-x0;
dy=y1-y0;
if(dx>=0)
{
x_inc=1;
}
else
{
x_inc=-1;
dx=-dx;
}
if(dy>=0)
{
y_inc=320;
}
else
{
y_inc=-320;
dy=-dy;
}
if(dx>dy)
{
for(index=0;index<=dx;index++)
{
*vb_start=color;
error+=dy;
if(error>dx)
{
error-=dx;
vb_start+=y_inc;
}
vb_start+=x_inc;
}
}
else
{
for(index=0;index<=dy;index++)
{
*vb_start=color;
error+=dx;
if(error>0)
{
error-=dy;
vb_start+=x_inc;
}
vb_start+=y_inc;
}
}
}

void H_Line_DB(int x1,int x2,int y,unsigned int color)
{
	memset( (char far *) (video_buffer + ( (y<<8) + (y<<6) ) + x1) , color , x2-x1+1 );
}

void V_Line_DB(int y1,int y2,int x,unsigned int color)
{
	int i;
	for(i=y1;i<y2;i++)
		double_buffer[ (i<<8) + (i<<6) + x]=color;
}

void Circle_DB(int x,int y,int r,int color)
{
	int x0,y0,x1,y1,index;
	x0=y0=r/sqrt(2);
	for(index=0;index<=360;index++)
	{
		x1=x0*cos_look[index]-y0*sin_look[index];
		y1=x0*sin_look[index]+y0*cos_look[index];
		Plot_Pixel_Fast_DB(x+x1,y+y1,color);
	}

}


void Delete_Double_Buffer(void)
{
if(double_buffer)
free(double_buffer);
}

void Fill_Double_Buffer(int color)
{
_fmemset(double_buffer,color,SCREEN_WIDTH*buffer_height);
}

void Show_Double_Buffer(char far *buffer)
{
_asm{
push ds
mov cx,buffer_size
les di,video_buffer
lds si,buffer
cld
rep movsw
pop ds
}
}

⌨️ 快捷键说明

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