DEADSOFTWARE

7b461c9c43a4203e1d3052c21f98767a9adb9236
[flatwaifu.git] / src / a8.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 /*
17 #include "glob.h"
18 #include <stdio.h>
19 //#include <io.h>
20 #include <fcntl.h>
21 #include <stdlib.h>
22 #include <string.h>
23 //#include "vga.h"
24 #include "keyb.h"
25 #include "error.h"
26 #include "files.h"
27 #include "sound.h"
28 #include "a8.h"
29 */
31 /*
32 #define WAIT_SZ 400000
34 extern byte gamcor[5][64];
36 extern char cd_path[];
38 extern int gammaa;
39 void setgamma(int);
41 extern void *cd_scr;
43 static byte skipping=0,credits=0;
45 #define A8_ID 0xA8
47 enum{
48 A8C_ENDFR,A8C_PAL,A8C_CLRSCR,A8C_DRAW,
49 A8C_FILL,A8C_DRAW2C,A8C_DRAW2
50 };
52 typedef struct{
53 unsigned char id,ver;
54 short width,height,frames;
55 long maxfsize;
56 long f1size;
57 }a8_hdr_t;
59 typedef unsigned char uchar;
61 #define SQ 4
63 static int sqw,sqh;
65 static int norm_gamma;
67 static unsigned char *frp,sqc[2][50][80];
68 static int frame;
69 static a8_hdr_t ah;
70 static snd_t *strk;
71 static int strk_ch;
73 static signed char *unpack(char *d,signed char *p,int l) {
74 for(;l>0;) if(*p>0) {
75 memcpy(d,p+1,*p);d+=*p;l-=*p;p+=*p+1;
76 }else if(*p<0) {
77 memset(d,p[1],-*p);d+=-*p;l-=-*p;p+=2;
78 }else return p+1;
79 return p;
80 }
82 static unsigned char *draw(signed char *p) {
83 int x,y,sy,yc,n;
85 for(y=0;y<sqh;) if(*p>0) {
86 for(yc=*p++;yc;--yc,++y) for(x=0;x<sqw;) if(*p>0) {
87 n=(*p++)*SQ;
88 for(sy=0;sy<SQ;++sy) {
89 p=unpack(scra+(y*SQ+sy)*320+x*SQ,p,n);
90 }
91 x+=n/SQ;
92 }else x+=-*p++;
93 }else y+=-*p++;
94 return p;
95 }
97 static unsigned char *fill(signed char *p) {
98 int x,y,yc,n;
100 for(y=0;y<sqh;) if(*p>0) {
101 for(yc=*p++;yc;--yc,++y) for(x=0;x<sqw;) if(*p>0) {
102 for(n=*p++;n;--n,++p,++x)
103 V_clr(x*SQ,SQ,y*SQ,SQ,*p);
104 }else x+=-*p++;
105 }else y+=-*p++;
106 return p;
109 static unsigned char *draw2c(signed char *p) {
110 int x,y,sx,sy,yc,n;
111 unsigned short w;
113 for(y=0;y<sqh;) if(*p>0) {
114 for(yc=*p++;yc;--yc,++y) for(x=0;x<sqw;) if(*p>0) {
115 for(n=*p++;n;--n,++x) {
116 sqc[0][y][x]=*p++;
117 sqc[1][y][x]=*p++;
118 w=*(unsigned short*)p;p+=2;
119 for(sy=0;sy<SQ;++sy)
120 for(sx=0;sx<SQ;++sx,w>>=1)
121 scra[(y*SQ+sy)*320+x*SQ+sx]=sqc[w&1][y][x];
123 }else x+=-*p++;
124 }else y+=-*p++;
125 return p;
128 static unsigned char *draw2(signed char *p) {
129 int x,y,sx,sy,yc,n;
130 unsigned short w;
132 for(y=0;y<sqh;) if(*p>0) {
133 for(yc=*p++;yc;--yc,++y) for(x=0;x<sqw;) if(*p>0) {
134 for(n=*p++;n;--n,++x) {
135 w=*(unsigned short*)p;p+=2;
136 for(sy=0;sy<SQ;++sy)
137 for(sx=0;sx<SQ;++sx,w>>=1)
138 scra[(y*SQ+sy)*320+x*SQ+sx]=sqc[w&1][y][x];
140 }else x+=-*p++;
141 }else y+=-*p++;
142 return p;
145 //---------------------------------------------------------------//
147 static int fsz,fdptr;
148 static FILE *fh;
149 static char *fdata;
152 static void f_close(void) {
153 if(fdata) {
154 free(fdata);fdata=NULL;
155 }else if(fh!=NULL) {fclose(fh);fh=NULL;}
158 static char end_clr=1;
159 */
161 void A8_close(void) {
162 /*
163 if(strk) if(strk_ch) S_stop(strk_ch);
164 f_close();
165 if(frp) {free(frp);frp=NULL;}
166 if(strk) {free(strk);strk=NULL;}
167 if(end_clr) {
168 VP_fill(0,0,0);
169 V_clr(0,320,0,200,0);V_copytoscr(0,320,0,200);
170 setgamma(norm_gamma);
172 */
175 int A8_nextframe(void) {
176 /*
177 unsigned char *p;
178 int i,j,k;
179 static int len;
181 if(credits) if(keys[0x33] && keys[0x34]) skipping=1;
182 if(frame==-1) if(strk) strk_ch=S_play(strk,-1,1024,255);
183 if(fdata) {
184 len=*(int*)(fdata+fdptr);fdptr+=4;
185 }else {len=0;myfread(&len,1,4,fh);}
186 len-=4;
187 if(len<=0) {
188 A8_close();
189 return 0;
191 if(fdata) {
192 p=fdata+fdptr;fdptr+=len;
193 }else {myfread(frp,1,len,fh);p=frp;}
194 for(;*p;) switch(*p++) {
195 case A8C_PAL:
196 i=*p++;j=*p++;if(!j) j=256;
197 for(k=0;k<j*3;++k) p[k]=gamcor[3][p[k]];
198 VP_set(p,i,j);
199 p+=j*3;
200 break;
201 case A8C_CLRSCR:
202 V_clr(0,ah.width,0,ah.height,*p++);
203 break;
204 case A8C_DRAW:
205 p=draw(p);
206 break;
207 case A8C_FILL:
208 p=fill(p);
209 break;
210 case A8C_DRAW2C:
211 p=draw2c(p);
212 break;
213 case A8C_DRAW2:
214 p=draw2(p);
215 break;
216 default:
217 ERR_fatal("Плохой блок в файле A8");
219 ++frame;
220 return 1;
221 */
222 return 0;
225 /*
226 static char wscr;
228 static void wait_scr(int s) {
229 if(!end_clr) return;
230 if(s<WAIT_SZ) return;
231 F_freemus();
232 V_setrect(0,320,0,200);
233 V_clr(0,320,0,200,0);
234 V_copytoscr(0,320,0,200);
235 V_pic(0,0,(void*)((char*)cd_scr+768));
236 VP_setall(cd_scr);
237 V_copytoscr(0,320,0,200);
238 wscr=1;
241 static void blank_scr(void) {
242 VP_fill(0,0,0);
243 V_setrect(0,320,0,200);
244 V_clr(0,320,0,200,0);
245 V_copytoscr(0,320,0,200);
247 */
249 int A8_start(char *nm) {
251 /*
252 static char s[40];
253 int sz;
254 FILE* h;
255 unsigned char *p;
257 end_clr=1;
258 if(strcasecmp(nm,"FINAL")==0 || strcasecmp(nm,"CREDITS")==0) end_clr=0;
259 else if(strcasecmp(nm,"KONEC")==0) end_clr=0;
260 credits=(strcasecmp(nm,"FINAL")==0)?1:0;
261 if(strcasecmp(nm,"CREDITS")==0) if(skipping) return 0;
262 wscr=0;
263 strk=NULL;strk_ch=0;
264 fdata=NULL;frp=NULL;
265 if(snd_type!=ST_NONE) {
266 sprintf(s,"%sA8\\%s.SND",cd_path,nm);
267 if((h=fopen(s,"rb"))!=NULL) {
268 fseek(h,0,SEEK_END);sz=ftell(h);fseek(h,0,SEEK_SET);
269 if((strk=malloc(sz+sizeof(snd_t)))!=NULL) {
270 wait_scr(sz);
271 myfread(strk+1,1,sz,h);
272 strk->rate=11000;
273 strk->len=sz;
274 strk->lstart=strk->llen=0;
275 for(p=(unsigned char *)(strk+1);sz;--sz,++p) *p^=0x80;
277 fclose(h);
280 sprintf(s,"%sA8\\%s.A8",cd_path,nm);
281 if((fh=fopen(s,"rb"))==NULL) {
282 ERR_fatal("Не могу открыть файл %s",s);
284 myfread(&ah,1,sizeof(ah)-4,fh);
285 if(ah.id!=A8_ID || ah.ver!=0) ERR_fatal("Испорченный файл A8 %s",s);
286 fseek(fh,0,SEEK_END);
287 fsz=ftell(fh)-sizeof(ah)+4;
288 fseek(fh,sizeof(ah)-4,SEEK_SET);
289 if((fdata=malloc(fsz))!=NULL) {
290 wait_scr(fsz);
291 myfread(fdata,1,fsz,fh);
292 fdptr=0;
293 fclose(fh);fh=NULL;
294 }else if(!(frp=malloc(ah.maxfsize))) {
295 if(strk) {free(strk);strk=NULL;}
296 if(!(frp=malloc(ah.maxfsize))) {
297 fclose(fh);fh=NULL;return 0;
300 sqw=ah.width/SQ;sqh=ah.height/SQ;
301 frame=-1;
302 norm_gamma=gammaa;
303 if(wscr) blank_scr();
306 return 1;
307 */
309 return 0;
312 //----------//
313 //----------//