home *** CD-ROM | disk | FTP | other *** search
- /*
- WORKS REGARDLESS OF COMPILER_ SETTING
- */
- char *block_clip(char *screen);
- char *block_clip2(char *screen,signed short int x,signed short int y,char w,char h);
-
- char *block_clip(char *screen)
- {
- signed short int _top,_left,_bottom,_right,x,y;
- unsigned short int i;
-
- _left = 319;
- _right = 0;
- _top = 199;
- _bottom = 0;
-
- x=0;
- y=0;
- for(i=0;i<64000;i++) {
- if(screen[i]) {
- if(y < _top)
- _top = y;
- if(y > _bottom)
- _bottom = y;
- if(x < _left)
- _left = x;
- if(x > _right)
- _right = x;
- }
- if((x++)==320) {
- x=0;
- y++;
- }
- }
-
- return((char*)block_clip2(screen,x,y,_right-_left+1,_bottom-_top+1));
- }
-
- char *block_clip2(char *screen,signed short int x,signed short int y,char w,char h)
- {
- char *ptr,*p;
- unsigned short int size,i;
-
- size = w*h+2;
- if((ptr=malloc(size))==NULL)
- return(NULL);
-
- ptr[0] = w;
- ptr[1] = h;
- p=&ptr[2];
-
- for(i=0;i<h;i++) {
- memcpy(p,&screen[320*(y+i)+x],w);
- p+=w;
- }
-
- return(ptr);
- }
-
- block_draw(char *buf,signed short int x,signed short int y,char *screen)
- {
- signed short int i,j,w,h;
- signed short int xoff,xlen;
- signed short int yoff,ylen;
- char color;
-
- w = *buf++;
- h = *buf++;
-
- x-=w;
- y-=h;
-
- // clip the block to fit within screen
- xlen = w;
- xoff = 0;
-
- if(x<0) {
- xlen+=x;
- xoff=-x;
- x=0;
- }
-
- if(x+w > 319)
- xlen = 320-x;
-
- ylen = h;
- yoff = 0;
- if(y<0) {
- ylen+=y;
- yoff=-y;
- y=0;
- }
-
- if(y+h > 199)
- ylen = 200-y;
-
- if((xlen<1) || (ylen<1))
- return;
-
- // setup the pointers
- screen+=(y<<8)+(y<<6)+x;
- buf+=yoff*w+xoff;
-
- for(i=0;i<ylen;i++) {
- for(j=0;j<xlen;j++) {
- color = buf[j];
- if(color)
- screen[j] = color;
- }
- screen+=320;
- buf+=w;
- }
- }
-