DEADSOFTWARE

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