DEADSOFTWARE

2203b5226ac0fc5e578f840366c5d632e98c7429
[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 */
36 /*
37 #define WAIT_SZ 400000
39 extern byte gamcor[5][64];
41 extern char cd_path[];
43 extern int gammaa;
44 void setgamma(int);
46 extern void *cd_scr;
48 static byte skipping=0,credits=0;
50 #define A8_ID 0xA8
52 enum{
53 A8C_ENDFR,A8C_PAL,A8C_CLRSCR,A8C_DRAW,
54 A8C_FILL,A8C_DRAW2C,A8C_DRAW2
55 };
57 typedef struct{
58 unsigned char id,ver;
59 short width,height,frames;
60 long maxfsize;
61 long f1size;
62 }a8_hdr_t;
64 typedef unsigned char uchar;
66 #define SQ 4
68 static int sqw,sqh;
70 static int norm_gamma;
72 static unsigned char *frp,sqc[2][50][80];
73 static int frame;
74 static a8_hdr_t ah;
75 static snd_t *strk;
76 static int strk_ch;
78 static signed char *unpack(char *d,signed char *p,int l) {
79 for(;l>0;) if(*p>0) {
80 memcpy(d,p+1,*p);d+=*p;l-=*p;p+=*p+1;
81 }else if(*p<0) {
82 memset(d,p[1],-*p);d+=-*p;l-=-*p;p+=2;
83 }else return p+1;
84 return p;
85 }
87 static unsigned char *draw(signed char *p) {
88 int x,y,sy,yc,n;
90 for(y=0;y<sqh;) if(*p>0) {
91 for(yc=*p++;yc;--yc,++y) for(x=0;x<sqw;) if(*p>0) {
92 n=(*p++)*SQ;
93 for(sy=0;sy<SQ;++sy) {
94 p=unpack(scra+(y*SQ+sy)*320+x*SQ,p,n);
95 }
96 x+=n/SQ;
97 }else x+=-*p++;
98 }else y+=-*p++;
99 return p;
102 static unsigned char *fill(signed char *p) {
103 int x,y,yc,n;
105 for(y=0;y<sqh;) if(*p>0) {
106 for(yc=*p++;yc;--yc,++y) for(x=0;x<sqw;) if(*p>0) {
107 for(n=*p++;n;--n,++p,++x)
108 V_clr(x*SQ,SQ,y*SQ,SQ,*p);
109 }else x+=-*p++;
110 }else y+=-*p++;
111 return p;
114 static unsigned char *draw2c(signed char *p) {
115 int x,y,sx,sy,yc,n;
116 unsigned short w;
118 for(y=0;y<sqh;) if(*p>0) {
119 for(yc=*p++;yc;--yc,++y) for(x=0;x<sqw;) if(*p>0) {
120 for(n=*p++;n;--n,++x) {
121 sqc[0][y][x]=*p++;
122 sqc[1][y][x]=*p++;
123 w=*(unsigned short*)p;p+=2;
124 for(sy=0;sy<SQ;++sy)
125 for(sx=0;sx<SQ;++sx,w>>=1)
126 scra[(y*SQ+sy)*320+x*SQ+sx]=sqc[w&1][y][x];
128 }else x+=-*p++;
129 }else y+=-*p++;
130 return p;
133 static unsigned char *draw2(signed char *p) {
134 int x,y,sx,sy,yc,n;
135 unsigned short w;
137 for(y=0;y<sqh;) if(*p>0) {
138 for(yc=*p++;yc;--yc,++y) for(x=0;x<sqw;) if(*p>0) {
139 for(n=*p++;n;--n,++x) {
140 w=*(unsigned short*)p;p+=2;
141 for(sy=0;sy<SQ;++sy)
142 for(sx=0;sx<SQ;++sx,w>>=1)
143 scra[(y*SQ+sy)*320+x*SQ+sx]=sqc[w&1][y][x];
145 }else x+=-*p++;
146 }else y+=-*p++;
147 return p;
150 //---------------------------------------------------------------//
152 static int fsz,fdptr;
153 static FILE *fh;
154 static char *fdata;
157 static void f_close(void) {
158 if(fdata) {
159 free(fdata);fdata=NULL;
160 }else if(fh!=NULL) {fclose(fh);fh=NULL;}
163 static char end_clr=1;
164 */
166 void A8_close(void) {
167 /*
168 if(strk) if(strk_ch) S_stop(strk_ch);
169 f_close();
170 if(frp) {free(frp);frp=NULL;}
171 if(strk) {free(strk);strk=NULL;}
172 if(end_clr) {
173 VP_fill(0,0,0);
174 V_clr(0,320,0,200,0);V_copytoscr(0,320,0,200);
175 setgamma(norm_gamma);
177 */
180 int A8_nextframe(void) {
181 /*
182 unsigned char *p;
183 int i,j,k;
184 static int len;
186 if(credits) if(keys[0x33] && keys[0x34]) skipping=1;
187 if(frame==-1) if(strk) strk_ch=S_play(strk,-1,1024,255);
188 if(fdata) {
189 len=*(int*)(fdata+fdptr);fdptr+=4;
190 }else {len=0;myfread(&len,1,4,fh);}
191 len-=4;
192 if(len<=0) {
193 A8_close();
194 return 0;
196 if(fdata) {
197 p=fdata+fdptr;fdptr+=len;
198 }else {myfread(frp,1,len,fh);p=frp;}
199 for(;*p;) switch(*p++) {
200 case A8C_PAL:
201 i=*p++;j=*p++;if(!j) j=256;
202 for(k=0;k<j*3;++k) p[k]=gamcor[3][p[k]];
203 VP_set(p,i,j);
204 p+=j*3;
205 break;
206 case A8C_CLRSCR:
207 V_clr(0,ah.width,0,ah.height,*p++);
208 break;
209 case A8C_DRAW:
210 p=draw(p);
211 break;
212 case A8C_FILL:
213 p=fill(p);
214 break;
215 case A8C_DRAW2C:
216 p=draw2c(p);
217 break;
218 case A8C_DRAW2:
219 p=draw2(p);
220 break;
221 default:
222 ERR_fatal("Плохой блок в файле A8");
224 ++frame;
225 return 1;
226 */
227 return 0;
230 /*
231 static char wscr;
233 static void wait_scr(int s) {
234 if(!end_clr) return;
235 if(s<WAIT_SZ) return;
236 F_freemus();
237 V_setrect(0,320,0,200);
238 V_clr(0,320,0,200,0);
239 V_copytoscr(0,320,0,200);
240 V_pic(0,0,(void*)((char*)cd_scr+768));
241 VP_setall(cd_scr);
242 V_copytoscr(0,320,0,200);
243 wscr=1;
246 static void blank_scr(void) {
247 VP_fill(0,0,0);
248 V_setrect(0,320,0,200);
249 V_clr(0,320,0,200,0);
250 V_copytoscr(0,320,0,200);
252 */
254 int A8_start(char *nm) {
256 /*
257 static char s[40];
258 int sz;
259 FILE* h;
260 unsigned char *p;
262 end_clr=1;
263 if(strcasecmp(nm,"FINAL")==0 || strcasecmp(nm,"CREDITS")==0) end_clr=0;
264 else if(strcasecmp(nm,"KONEC")==0) end_clr=0;
265 credits=(strcasecmp(nm,"FINAL")==0)?1:0;
266 if(strcasecmp(nm,"CREDITS")==0) if(skipping) return 0;
267 wscr=0;
268 strk=NULL;strk_ch=0;
269 fdata=NULL;frp=NULL;
270 if(snd_type!=ST_NONE) {
271 sprintf(s,"%sA8\\%s.SND",cd_path,nm);
272 if((h=fopen(s,"rb"))!=NULL) {
273 fseek(h,0,SEEK_END);sz=ftell(h);fseek(h,0,SEEK_SET);
274 if((strk=malloc(sz+sizeof(snd_t)))!=NULL) {
275 wait_scr(sz);
276 myfread(strk+1,1,sz,h);
277 strk->rate=11000;
278 strk->len=sz;
279 strk->lstart=strk->llen=0;
280 for(p=(unsigned char *)(strk+1);sz;--sz,++p) *p^=0x80;
282 fclose(h);
285 sprintf(s,"%sA8\\%s.A8",cd_path,nm);
286 if((fh=fopen(s,"rb"))==NULL) {
287 ERR_fatal("Не могу открыть файл %s",s);
289 myfread(&ah,1,sizeof(ah)-4,fh);
290 if(ah.id!=A8_ID || ah.ver!=0) ERR_fatal("Испорченный файл A8 %s",s);
291 fseek(fh,0,SEEK_END);
292 fsz=ftell(fh)-sizeof(ah)+4;
293 fseek(fh,sizeof(ah)-4,SEEK_SET);
294 if((fdata=malloc(fsz))!=NULL) {
295 wait_scr(fsz);
296 myfread(fdata,1,fsz,fh);
297 fdptr=0;
298 fclose(fh);fh=NULL;
299 }else if(!(frp=malloc(ah.maxfsize))) {
300 if(strk) {free(strk);strk=NULL;}
301 if(!(frp=malloc(ah.maxfsize))) {
302 fclose(fh);fh=NULL;return 0;
305 sqw=ah.width/SQ;sqh=ah.height/SQ;
306 frame=-1;
307 norm_gamma=gammaa;
308 if(wscr) blank_scr();
311 return 1;
312 */
314 return 0;
317 //----------//
318 //----------//