📄 move.h
字号:
#define SCROLL_WIDTH (unsigned int)640
#define SCROLL_HEIGHT (unsigned int)50
void PCX_Init_Scroll(pcx_picture_ptr image)
{
unsigned int a=(unsigned int)SCROLL_WIDTH * SCROLL_HEIGHT + 1;
// this function allocates the buffer region needed to load a pcx file
if((image->buffer = (char far *)malloc(a))==NULL)
{
printf("\ncouldn't allocate screen buffer");
exit(1);
}
} // end PCX_Init
void PCX_Load_Scroll(char *filename, pcx_picture_ptr image,int enable_palette)
{
// this function loads a pcx file into a picture structure, the actual image
// data for the pcx file is decompressed and expanded into a secondary buffer
// within the picture structure, the separate images can be grabbed from this
// buffer later. also the header and palette are loaded
FILE *fp;
int num_bytes,index;
unsigned int count;
unsigned char data;
char far *temp_buffer;
// open the file
fp = fopen(filename,"rb");
// load the header
temp_buffer = (char far *)image;
for (index=0; index<128; index++)
{
temp_buffer[index] = getc(fp);
} // end for index
// load the data and decompress into buffer
count=0;
while(count<=(unsigned int)SCROLL_WIDTH * SCROLL_HEIGHT)
{
// get the first piece of data
data = getc(fp);
// is this a rle?
if (data>=192 && data<=255)
{
// how many bytes in run?
num_bytes = data-192;
// get the actual data for the run
data = getc(fp);
// replicate data in buffer num_bytes times
while(num_bytes-->0)
{
image->buffer[count++] = data;
// video_buffer[count++]=data;
} // end while
} // end if rle
else
{
// actual data, just copy it into buffer at next location
image->buffer[count++] = data;
//video_buffer[count++]=data;
} // end else not rle
} // end while
// move to end of file then back up 768 bytes i.e. to begining of palette
fseek(fp,-768L,SEEK_END);
// load the pallete into the palette
for (index=0; index<256; index++)
{
// get the red component
image->palette[index].red = (getc(fp) >> 2);
// get the green component
image->palette[index].green = (getc(fp) >> 2);
// get the blue component
image->palette[index].blue = (getc(fp) >> 2);
} // end for index
fclose(fp);
// change the palette to newly loaded palette if commanded to do so
if (enable_palette)
{
for (index=0; index<256; index++)
{
Set_Palette_Register(index,(RGB_color_ptr)&image->palette[index]);
} // end for index
} // end if change palette
} // end PCX_Load
//////////////////////////////////////////////////////////////////////////////
void Show_View_Port_Pcx(pcx_picture_ptr background_pcx,int pos)
{
unsigned int y,scroll_off,screen_off,flag=0;
if((pos+320)>=SCROLL_WIDTH)
flag=1;
for(y=0;y<SCROLL_HEIGHT;y++)
{
scroll_off=((y<<9)+(y<<7)+pos);
screen_off=(((y+150)<<8)+((y+150)<<6));
if(flag==0)
_fmemmove((void far *)&video_buffer[screen_off],
(void far *)&background_pcx->buffer[scroll_off],320);
else
{
_fmemmove((void far *)&video_buffer[screen_off],
(void far *)&background_pcx->buffer[scroll_off],640-pos);
_fmemmove((void far *)&video_buffer[screen_off+640-pos],
(void far *)&background_pcx->buffer[scroll_off-pos],pos-320);
}
}
}
void Show_View_Port_Pcx_Left(pcx_picture_ptr background_pcx,int pos)
{
unsigned int y,scroll_off_left,screen_off_left,flag=0;
for(y=0;y<SCROLL_HEIGHT;y++)
{
scroll_off_left=((y<<9)+(y<<7)+pos);
screen_off_left=(((y+150)<<8)+((y+150)<<6)+319);
video_buffer[screen_off_left]=background_pcx->buffer[scroll_off_left];
}
}
void Move_Screen_Left(int step)
{
unsigned int first=320*150,x,y;
for(y=0;y<50*320;y=y+320)
for(x=0;x<319;x++)
video_buffer[first+y+x]=video_buffer[first+1+y+x];
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -