00001
00025 #include <stdio.h>
00026 #include <stdlib.h>
00027 #include <string.h>
00028
00029
00030
00031 #include "movies.h"
00032 #include "images.h"
00033 #include "sdlengine.h"
00034 #include "main.h"
00035 #include "sound.h"
00036 #include "filereader.h"
00037
00038
00040 #define FLA_EXT ".fla"
00041
00042 #define MOVIES_DIR "movies//"
00043
00044 #define MOVIES_EXT ".avi"
00045
00047 #define LOAD_PALETTE 0
00048
00049 #define FADE 1
00050
00051 #define PLAY_SAMPLE 2
00052
00053 #define STOP_SAMPLE 4
00054
00055 #define DELTA_FRAME 5
00056
00057 #define KEY_FRAME 7
00058
00060 int fadeOut;
00062 int fadeOutFrames;
00063
00065 int flaSampleTable[100];
00067 int samplesInFla;
00069 unsigned char* workVideoBufferCopy;
00071
00073
00075 FLAHeaderStruct flaHeaderData;
00077 FLAFrameDataStruct frameData;
00078
00079 filereader frFla;
00080
00085 void draw_key_frame(unsigned char * ptr, int width, int height)
00086 {
00087 int a, b;
00088 unsigned char * destPtr = (unsigned char *)flaBuffer;
00089 unsigned char * startOfLine = destPtr;
00090 char flag1;
00091 char flag2;
00092
00093 do
00094 {
00095 flag1 = *(ptr++);
00096
00097 for(a=0; a < flag1; a++)
00098 {
00099 flag2 = *(ptr++);
00100
00101 if(flag2 < 0)
00102 {
00103 flag2 =- flag2;
00104 for(b=0; b < flag2; b++)
00105 {
00106 *(destPtr++) = *(ptr++);
00107 }
00108 }
00109 else
00110 {
00111 char colorFill;
00112
00113 colorFill = *(ptr++);
00114
00115 for(b=0; b < flag2; b++)
00116 {
00117 *(destPtr++) = colorFill;
00118 }
00119 }
00120 }
00121
00122 startOfLine = destPtr = startOfLine+width;
00123 }while(--height);
00124 }
00125
00129 void draw_delta_frame(unsigned char * ptr, int width)
00130 {
00131 int a,b;
00132 unsigned short int skip;
00133 unsigned char * destPtr;
00134 unsigned char * startOfLine;
00135 int height;
00136
00137 char flag1;
00138 char flag2;
00139
00140 skip = *((unsigned short int*)ptr); ptr+=2;
00141 skip *= width;
00142 startOfLine = destPtr = (unsigned char *)flaBuffer+skip;
00143 height = *((signed short int*)ptr); ptr+=2;
00144
00145 do
00146 {
00147 flag1 = *(ptr++);
00148
00149 for(a=0; a < flag1; a++)
00150 {
00151 destPtr += (unsigned char)*(ptr++);
00152 flag2 = *(ptr++);
00153
00154 if(flag2>0)
00155 {
00156 for(b=0; b < flag2; b++)
00157 {
00158 *(destPtr++) = *(ptr++);
00159 }
00160 }
00161 else
00162 {
00163 char colorFill;
00164 flag2 =- flag2;
00165
00166 colorFill = *(ptr++);
00167
00168 for(b=0; b < flag2; b++)
00169 {
00170 *(destPtr++)=colorFill;
00171 }
00172 }
00173 }
00174
00175 startOfLine=destPtr=startOfLine+width;
00176 }while(--height);
00177 }
00178
00183 void scale_fla_2x()
00184 {
00185 int i,j;
00186 unsigned char* source=(unsigned char*)flaBuffer;
00187 unsigned char* dest=(unsigned char*)workVideoBuffer;
00188
00189 if(cfgfile.FLAwide)
00190 {
00191 for(i=0;i<SCREEN_WIDTH/SCALE*40;i++)
00192 {
00193 *(dest++) = 0x00;
00194 }
00195 }
00196
00197 for(i=0;i<FLASCREEN_HEIGHT;i++)
00198 {
00199 for(j=0;j<FLASCREEN_WIDTH;j++)
00200 {
00201 *(dest++)=*(source);
00202 *(dest++)=*(source++);
00203 }
00204 if(cfgfile.FLAwide)
00205 {
00206 memcpy(dest,dest-SCREEN_WIDTH/SCALE,FLASCREEN_WIDTH*2);
00207 dest+=FLASCREEN_WIDTH*2;
00208 }
00209 else
00210 {
00211 if(i%(2))
00212 {
00213 memcpy(dest,dest-SCREEN_WIDTH/SCALE,FLASCREEN_WIDTH*2);
00214 dest+=FLASCREEN_WIDTH*2;
00215 }
00216 if(i%10)
00217 {
00218 memcpy(dest,dest-SCREEN_WIDTH/SCALE,FLASCREEN_WIDTH*2);
00219 dest+=FLASCREEN_WIDTH*2;
00220 }
00221 }
00222 }
00223
00224 if(cfgfile.FLAwide)
00225 {
00226 for(i=0;i<SCREEN_WIDTH/SCALE*40;i++)
00227 {
00228 *(dest++) = 0x00;
00229 }
00230 }
00231 }
00232
00234 void process_frame()
00235 {
00236 FLASampleStruct sample;
00237 unsigned int opcodeBlockSize;
00238 unsigned char opcode;
00239 int aux=0;
00240 unsigned char * ptr;
00241
00242 frread(&frFla,&frameData.videoSize,1);
00243 frread(&frFla,&frameData.dummy,1);
00244 frread(&frFla,&frameData.frameVar0,4);
00245
00246 frread(&frFla,workVideoBufferCopy,frameData.frameVar0);
00247
00248 if((int)frameData.videoSize<=0)
00249 return;
00250
00251 ptr = workVideoBufferCopy;
00252
00253 do
00254 {
00255 opcode = *((unsigned char*)ptr); ptr+=2;
00256 opcodeBlockSize = *((unsigned short int*)ptr); ptr+=2;
00257
00258 switch(opcode-1)
00259 {
00260 case LOAD_PALETTE:
00261 {
00262 short int numOfColor = *((short int*)ptr);
00263 short int startColor = *((short int*)(ptr+2));
00264 memcpy((palette+(startColor*3)),(ptr+4),numOfColor*3);
00265 break;
00266 }
00267 case FADE:
00268 {
00269
00270
00271 if(fadeOut!=1)
00272 {
00273 convert_pal_2_RGBA(palette, paletteRGBA);
00274 fade_2_black(paletteRGBA);
00275 fadeOut = 1;
00276 }
00277 break;
00278 }
00279 case PLAY_SAMPLE:
00280 {
00281 memcpy(&sample,ptr,sizeof(FLASampleStruct));
00282 play_fla_sample(sample.sampleNum, sample.freq, sample.repeat, sample.x, sample.y);
00283 break;
00284 }
00285 case STOP_SAMPLE:
00286 {
00287 stop_sample();
00288 break;
00289 }
00290 case DELTA_FRAME:
00291 {
00292 draw_delta_frame(ptr,FLASCREEN_WIDTH);
00293 if(fadeOut==1)
00294 fadeOutFrames++;
00295 break;
00296 }
00297 case KEY_FRAME:
00298 {
00299 draw_key_frame(ptr,FLASCREEN_WIDTH,FLASCREEN_HEIGHT);
00300 break;
00301 }
00302 default:
00303 {
00304 return;
00305 }
00306 }
00307
00308 aux++;
00309 ptr += opcodeBlockSize;
00310
00311 }while(aux < (int)frameData.videoSize);
00312
00313 }
00314
00317 void play_fla_movie(char *filename)
00318 {
00319 int i;
00320 int quit = 0;
00321 int currentFrame;
00322
00323 fadeOut = -1;
00324 fadeOutFrames = 0;
00325
00326 if(!fropen(&frFla,filename))
00327 return;
00328
00329 if(cfgfile.Debug)
00330 printf("Playing FLA: %s ",filename);
00331
00332 workVideoBufferCopy=workVideoBuffer;
00333
00334 frread(&frFla,&flaHeaderData.version,6);
00335 frread(&frFla,&flaHeaderData.numOfFrames,4);
00336 frread(&frFla,&flaHeaderData.speed,1);
00337 frread(&frFla,&flaHeaderData.var1,1);
00338 frread(&frFla,&flaHeaderData.xsize,2);
00339 frread(&frFla,&flaHeaderData.ysize,2);
00340
00341 frread(&frFla,&samplesInFla,4);
00342
00343
00344 samplesInFla&=0xFFFF;
00345
00346 if(cfgfile.Debug)
00347 printf("- Frames: %d - Speed: %d - Samples: %d\n",flaHeaderData.numOfFrames, flaHeaderData.speed, samplesInFla);
00348
00349 for(i=0; i<samplesInFla; i++)
00350 {
00351
00352 short int var0;
00353 short int var1;
00354 frread(&frFla,&var0,2);
00355 frread(&frFla,&var1,2);
00356 flaSampleTable[i] = var0;
00357 }
00358
00359 if(!strcmp(flaHeaderData.version,"V1.3"))
00360 {
00361 currentFrame=0;
00362
00363 if(!quit)
00364 {
00365 do
00366 {
00367 if(currentFrame == flaHeaderData.numOfFrames)
00368 quit=1;
00369 else
00370 {
00371
00372 process_frame();
00373 scale_fla_2x();
00374 copy_screen(workVideoBuffer, frontVideoBuffer);
00375
00376
00377 if(fadeOut==-1)
00378 {
00379 convert_pal_2_RGBA(palette, paletteRGBA);
00380 if(!currentFrame)
00381 fade_in(paletteRGBA);
00382 else
00383 set_palette(paletteRGBA);
00384 }
00385
00386
00387 if(fadeOutFrames>=2)
00388 {
00389 flip(frontVideoBuffer);
00390 convert_pal_2_RGBA(palette, paletteRGBA);
00391 fade_2_pal(paletteRGBA);
00392 fadeOut = -1;
00393 fadeOutFrames = 0;
00394 }
00395
00396 currentFrame++;
00397
00398 fps_cycles(flaHeaderData.speed+1);
00399
00400 read_keys();
00401 if(skipIntro)
00402 break;
00403 }
00404 }while(!quit);
00405 }
00406 }
00407 if(cfgfile.CrossFade)
00408 cross_fade(frontVideoBuffer,paletteRGBA);
00409 else
00410 fade_2_black(paletteRGBA);
00411 stop_sample();
00412
00413
00414
00415
00416 }
00417
00420 void play_movie(char *movie)
00421 {
00422 if(cfgfile.UseAVI)
00423 {
00424 char fileBuf[256];
00425 sprintf(fileBuf,MOVIES_DIR);
00426 strcat(fileBuf,movie);
00427 strcat(fileBuf,MOVIES_EXT);
00428 }
00429 else
00430 {
00431 char fileBuf[256];
00432 sprintf(fileBuf,FLA_DIR);
00433 strcat(fileBuf,movie);
00434 strcat(fileBuf,FLA_EXT);
00435 play_fla_movie(fileBuf);
00436 }
00437 }
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548
00549
00550
00551
00552
00553
00554
00555
00556
00557
00558
00559
00560
00561
00562
00563
00564
00565
00566
00567
00568
00569
00570
00571
00572
00573
00574
00575
00576
00577
00578
00579
00580
00581
00582
00583
00584
00585
00586
00587
00588
00589
00590
00591
00592
00593
00594
00595
00596
00597
00598
00599
00600
00601
00602
00603
00604
00605
00606
00607
00608
00609
00610
00611
00612
00613
00614
00615
00616
00617
00618
00619
00620
00621
00622
00623
00624
00625
00626
00627
00628
00629
00630
00631
00632
00633
00634
00635
00636
00637
00638
00639
00640
00641
00642
00643
00644
00645
00646
00647
00648
00649
00650
00651
00652
00653
00654
00655
00656
00657
00658
00659
00660
00661
00662
00663
00664
00665
00666
00667
00668
00669
00670
00671
00672
00673
00674
00675
00676
00677
00678
00679
00680
00681
00682
00683
00684
00685
00686
00687
00688
00689
00690
00691
00692
00693
00694
00695
00696
00697
00698
00699
00700
00701
00702
00703
00704
00705