2203b5226ac0fc5e578f840366c5d632e98c7429
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
37 #define WAIT_SZ 400000
39 extern byte gamcor[5][64];
41 extern char cd_path[];
48 static byte skipping=0,credits=0;
53 A8C_ENDFR,A8C_PAL,A8C_CLRSCR,A8C_DRAW,
54 A8C_FILL,A8C_DRAW2C,A8C_DRAW2
59 short width,height,frames;
64 typedef unsigned char uchar;
70 static int norm_gamma;
72 static unsigned char *frp,sqc[2][50][80];
78 static signed char *unpack(char *d,signed char *p,int l) {
80 memcpy(d,p+1,*p);d+=*p;l-=*p;p+=*p+1;
82 memset(d,p[1],-*p);d+=-*p;l-=-*p;p+=2;
87 static unsigned char *draw(signed char *p) {
90 for(y=0;y<sqh;) if(*p>0) {
91 for(yc=*p++;yc;--yc,++y) for(x=0;x<sqw;) if(*p>0) {
93 for(sy=0;sy<SQ;++sy) {
94 p=unpack(scra+(y*SQ+sy)*320+x*SQ,p,n);
102 static unsigned char *fill(signed char *p) {
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);
114 static unsigned char *draw2c(signed char *p) {
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) {
123 w=*(unsigned short*)p;p+=2;
125 for(sx=0;sx<SQ;++sx,w>>=1)
126 scra[(y*SQ+sy)*320+x*SQ+sx]=sqc[w&1][y][x];
133 static unsigned char *draw2(signed char *p) {
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;
142 for(sx=0;sx<SQ;++sx,w>>=1)
143 scra[(y*SQ+sy)*320+x*SQ+sx]=sqc[w&1][y][x];
150 //---------------------------------------------------------------//
152 static int fsz,fdptr;
157 static void f_close(void) {
159 free(fdata);fdata=NULL;
160 }else if(fh!=NULL) {fclose(fh);fh=NULL;}
163 static char end_clr=1;
166 void A8_close(void) {
168 if(strk) if(strk_ch) S_stop(strk_ch);
170 if(frp) {free(frp);frp=NULL;}
171 if(strk) {free(strk);strk=NULL;}
174 V_clr(0,320,0,200,0);V_copytoscr(0,320,0,200);
175 setgamma(norm_gamma);
180 int A8_nextframe(void) {
186 if(credits) if(keys[0x33] && keys[0x34]) skipping=1;
187 if(frame==-1) if(strk) strk_ch=S_play(strk,-1,1024,255);
189 len=*(int*)(fdata+fdptr);fdptr+=4;
190 }else {len=0;myfread(&len,1,4,fh);}
197 p=fdata+fdptr;fdptr+=len;
198 }else {myfread(frp,1,len,fh);p=frp;}
199 for(;*p;) switch(*p++) {
201 i=*p++;j=*p++;if(!j) j=256;
202 for(k=0;k<j*3;++k) p[k]=gamcor[3][p[k]];
207 V_clr(0,ah.width,0,ah.height,*p++);
222 ERR_fatal("Плохой блок в файле A8");
233 static void wait_scr(int s) {
235 if(s<WAIT_SZ) return;
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));
242 V_copytoscr(0,320,0,200);
246 static void blank_scr(void) {
248 V_setrect(0,320,0,200);
249 V_clr(0,320,0,200,0);
250 V_copytoscr(0,320,0,200);
254 int A8_start(char *nm
) {
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;
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) {
276 myfread(strk+1,1,sz,h);
279 strk->lstart=strk->llen=0;
280 for(p=(unsigned char *)(strk+1);sz;--sz,++p) *p^=0x80;
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) {
296 myfread(fdata,1,fsz,fh);
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;
308 if(wscr) blank_scr();