DEADSOFTWARE

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