DEADSOFTWARE

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