DEADSOFTWARE

f68f0a215bd6b930c82e03eaa8425fb8f22de261
[flatwaifu.git] / src / anim.c
1 /*
2 Copyright (C) Prikol Software 1996-1997
3 Copyright (C) Aleksey Volynskov 1996-1997
5 This file is part of the Doom2D:Rembo project.
7 Doom2D:Rembo is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License version 2 as
9 published by the Free Software Foundation.
11 Doom2D:Rembo is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, see <http://www.gnu.org/licenses/> or
18 write to the Free Software Foundation, Inc.,
19 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21 /*
23 #include "glob.h"
24 #include <stdlib.h>
25 #include <string.h>
26 #include <vga.h>
27 //#include <keyb.h>
28 #include "error.h"
29 #include "anim.h"
31 enum{AB_END,AB_SCREEN,AB_UPDATE};
33 typedef struct{
34 short t,st;
35 unsigned len;
36 }anm_blk_t;
38 #define SQ 4
40 static byte cnum[256];
42 static void init_cpack(void) {
43 int i;
45 for(i=0;i<256;++i) cnum[i]=i;
46 }
48 static byte cpack(byte n) {
49 byte c;
51 c=cnum[n];
52 if(n) memmove(cnum+1,cnum,n);
53 cnum[0]=c;
54 return c;
55 }
57 static byte *unpack(byte *d,byte *s,int l) {
58 for(;l>0;--l,++d,++s) {
59 if(*s==0) {memset(d,cpack(0),(dword)(*(++s))+1);d+=(dword)*s;l-=(dword)*s;}
60 else *d=cpack(*s);
61 }
62 return s;
63 }
65 static byte *line(int y,byte *u) {
66 int x,n,sy;
68 for(x=0;x<scrw/SQ;)
69 if(*u&0x80) {
70 n=(*u&0x7F)+1;++u;
71 for(sy=0;sy<SQ*320;sy+=320) {u=unpack(scra+y+sy+x*SQ,u,n*SQ);}
72 x+=n;
73 }else{x+=*u+1;++u;}
74 return u;
75 }
77 static anm_blk_t *anm;
79 void ANM_start(void *p) {
80 init_cpack();
81 anm=p;
82 }
84 int ANM_play(void) {
85 byte *u;
86 int x,y;
88 // while(!keys[0x39]);
89 // while(keys[0x39]);
90 if(anm->t==AB_END) return 0;
91 switch(anm->t) {
92 case AB_SCREEN:
93 unpack(scra,(byte*)(anm+1),64000);
94 break;
95 case AB_UPDATE:
96 for(u=(byte*)(anm+1),y=0;y<200/SQ;)
97 if(*u&0x80) {
98 for(x=(*u&0x7F)+1,++u;x;--x,++y)
99 u=line(y*320*SQ,u);
100 }else{y+=*u+1;++u;}
101 break;
102 default: ERR_fatal("\8f«®å®© ANM-ä ©«");
104 anm=((anm_blk_t*)((byte*)anm+anm->len))+1;
105 if(anm->t==AB_END) return 0;
106 return 1;
108 */