-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathzombietitle.c
851 lines (671 loc) · 18.4 KB
/
zombietitle.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
/***************************************************************\
* *
* Monster Manor (Alice in ZombieLand) title sequence *
* *
* By: Jon Leupp *
* *
* Last update: 1-June-93 *
* *
* Copyright (c) 1993, The 3DO Company, Inc. *
* *
* This program is proprietary and confidential *
* *
\***************************************************************/
#define SOUNDSTUFF
#include <types.h>
#include <ctype.h>
#include <kernel.h>
#include <kernelnodes.h>
#include <mem.h>
#include <io.h>
#include <graphics.h>
#include <operamath.h>
#include <event.h>
#include <time.h>
#include <Form3DO.h>
#include <strings.h>
#include <stdlib.h>
#include <stdio.h>
#include <debug.h>
// Sound Includes
#include <operror.h>
#include <filefunctions.h>
#include <audio.h>
#include <soundfile.h>
#include "castle.h"
#include "app_proto.h"
/***************************************************************************
* #defines
*/
#define DBUG(x) { printf x ; }
#define FULLDBUG(x) { printf x ; }
#define MAKETAG(a,b,c,d) (((int32)(a)<<24)|((int32)(b)<<16)|((int32)(c)<<8)|(int32)(d))
#define MAXCELS 100
#define NBUFFERS 3
#define NUMSPRITES (MAXCELS+1)
#define CHUNK_SPRH CHAR4LITERAL('S','P','R','H')
#define CHUNK_PIPT CHAR4LITERAL('P','I','P','T')
// Sound equates
#define PRT(x) { printf x; }
#define ERR(x) PRT(x)
#define MAXAMPLITUDE 0x7FFF
#define AUDIODIR "^"
//void opentimer (void);
//void gettime (uint32 timebuffer[2]);
void opentitlestuff (void);
void closetitlestuff (void);
void loadcel (ubyte *spname, int32 index);
void loadbackground (ubyte *backname);
void ccbtodispccb (uint32 ccbn, uint32 dispccbn);
void ClearScreen (void);
void terminate (int i);
void play (void);
void *malloctype (int32 size, uint32 memtype);
void freetype (void *ptr);
//extern char BuildDate[];
extern RastPort rports[];
extern Item vblIO, sportIO;
static GrafCon gc;
static Item ScreenItems[NBUFFERS], BitmapItems[NBUFFERS],
ScreenGroupItem;
static Bitmap *Bitmaps[NBUFFERS];
static CCB *ccbs[NUMSPRITES];
static uint32 *pluts[NUMSPRITES];
static uint32 *cels[NUMSPRITES];
static CCB *dispccbs[NUMSPRITES];
static uint32 dispccb;
static TagArg ScreenTags[] = {
CSG_TAG_SPORTBITS, (void*)0,
CSG_TAG_DISPLAYHEIGHT, (void*)240,
CSG_TAG_SCREENCOUNT, (void*)NBUFFERS,
CSG_TAG_SCREENHEIGHT, (void*)240,
CSG_TAG_DONE, (void*)0,
};
static uint32 savebuffer, currentbuffer, tempbuffer;
static PixelChunk *pxlc;
static CCC *ccc;
static PLUTChunk *pipc;
static int32 numcels;
static int32 xtable[] = { 0, 0, 0, 0, 25, 50, 50, 30, 30 };
static int32 ytable[] = { 0, 0, 0, 0, 40, 0, 20, 0, 20 };
static ControlPadEventData cped;
static int32 bloodtextht;
static int32 EndSound;
static uint32 ScreenPages;
/*
** Allocate enough space so that you don't get stack overflows.
** An overflow will be characterized by seemingly random crashes
** that defy all attempts at logical analysis. You might want to
** start big then reduce the size till you crash, then double it.
*/
#define STACKSIZE (10000)
/* Macro to simplify error checking. */
#define CHECKRESULT(val,name) \
if (val < 0) \
{ \
Result = val; \
ERR(("Failure in %s: $%x\n", name, val)); \
PrintfSysErr(Result); \
goto error; \
}
#define CHECKPTR(val,name) \
if (val == 0) \
{ \
Result = -1; \
ERR(("Failure in %s\n", name)); \
goto error; \
}
#define NUMBLOCKS (64)
#define BLOCKSIZE (2048)
#define BUFSIZE (NUMBLOCKS*BLOCKSIZE)
#define NUMBUFFS (2)
int32 PlaySoundFile (char *FileName, int32 BufSize );
void SpoolSoundFileThread( void );
/********* Globals for Thread **********/
static Item SpoolerThread;
static char *gFileName;
static char gCurrentDir[80];
static int32 gSignal1;
static Item gMainTaskItem;
// End of Sound Equates
/***************************************************************\
* *
* Code *
* *
\***************************************************************/
void
dotitlesequence ()
{
int32 i;
// Sound variables
//
// gFileName = "/remote/aiff/EerieBoing.aiff";
gFileName = "aiff/LongTitle.aiff";
EndSound = 0;
// DBUG (("Zombie title program\n%s\n", BuildDate));
i = GetDirectory (gCurrentDir, sizeof (gCurrentDir));
opentitlestuff ();
DisplayScreen (ScreenItems[savebuffer], ScreenItems[savebuffer]);
play ();
EndSound = 1;
WaitSignal (gSignal1);
#ifdef SOUNDSTUFF
// Sound end code
PRT(("Playback complete.\n"));
//
#endif
closetitlestuff ();
}
void
opentitlestuff ()
{
register int i;
int32 Result;
int32 Priority;
#if 0
FULLDBUG (("Create screen group\n"));
ScreenTags[0].ta_Arg = (void*)GETBANKBITS(GrafBase->gf_ZeroPage);
ScreenGroupItem = CreateScreenGroup (ScreenItems, ScreenTags);
if (ScreenGroupItem<0) {
DBUG (("Error: CreateScreenGroup() == %lx\n", ScreenGroupItem));
terminate (1);
}
FULLDBUG (("Add screen group\n"));
AddScreenGroup (ScreenGroupItem, NULL);
#endif
for (i = 0; i < NBUFFERS; i++) {
#if 0
Screen *screen;
screen = (Screen*)LookupItem (ScreenItems[i]);
if (screen==0) {
DBUG (("Error: could not locate screen\n"));
terminate (1);
}
BitmapItems[i] = screen->scr_TempBitmap->bm.n_Item;
Bitmaps[i] = screen->scr_TempBitmap;
#endif
BitmapItems[i] = rports[i].rp_BitmapItem;
Bitmaps[i] = rports[i].rp_Bitmap;
ScreenItems[i] = rports[i].rp_ScreenItem;
FULLDBUG (("Screen[%d] buffer @ %08lx\n", i, Bitmaps[i]->bm_Buffer));
}
ScreenPages = (Bitmaps[0]->bm_Width * Bitmaps[0]->bm_Height * 2 +
GrafBase->gf_VRAMPageSize-1) /
GrafBase->gf_VRAMPageSize;
#ifdef SOUNDSTUFF
// Sound code
/* Get parent task Item so that thread can signal back. */
gMainTaskItem = KernelBase->kb_CurrentTask->t.n_Item;
/* Allocate a signal for each thread to notify parent task. */
gSignal1 = AllocSignal( 0 );
CHECKRESULT(gSignal1,"AllocSignal");
Priority = 180;
SpoolerThread = CreateThread ("SoundSpooler",
Priority,
SpoolSoundFileThread,
STACKSIZE);
CHECKRESULT (SpoolerThread, "CreateThread");
#endif
numcels = 0;
savebuffer = 2;
currentbuffer = 0;
FULLDBUG (("Clear screen\n"));
SetVRAMPages (sportIO,
Bitmaps[savebuffer]->bm_Buffer,
MakeRGB15Pair (0, 0, 0),
ScreenPages,
0xffffffff);
ClearScreen ();
// allocate display ccb memory
for (i=0; i<NUMSPRITES; i++) {
dispccbs[i] = (CCB *) ALLOCMEM (sizeof (CCB), MEMTYPE_CEL);
if (!dispccbs[i]) {
DBUG (("Error allocating CCBs\n"));
terminate (1);
}
if (i) dispccbs[i-1]->ccb_NextPtr = dispccbs[i];
}
loadcel ("skull.dark", numcels++);
loadcel ("skull.light", numcels++);
loadcel ("hellhouse.dark", numcels++);
loadcel ("hellhouse.light", numcels++);
loadcel ("bloodtext", numcels++);
bloodtextht = REALCELDIM (ccbs[numcels-1]->ccb_Height);
loadcel ("lightning1a", numcels++);
loadcel ("lightning1b", numcels++);
loadcel ("lightning2a", numcels++);
loadcel ("lightning2b", numcels++);
return;
error:
die ("CHECKRESULT failure.\n");
}
void
closetitlestuff ()
{
register int i;
for (i = numcels; --i >= 0; ) {
freetype (pluts[i]); pluts[i] = NULL;
freetype (cels[i]); cels[i] = NULL;
freetype (ccbs[i]); ccbs[i] = NULL;
}
for (i = NUMSPRITES; --i >= 0; ) {
if (dispccbs[i]) {
FreeMem (dispccbs[i], sizeof (CCB));
dispccbs[i] = NULL;
}
}
if (SpoolerThread) {
DeleteThread (SpoolerThread);
SpoolerThread = 0;
}
#if 0
if (ScreenGroupItem) {
RemoveScreenGroup (ScreenGroupItem);
DeleteScreenGroup (ScreenGroupItem);
ScreenGroupItem = 0;
}
#endif
}
void
play (void)
{
int32 lightning_X, flash, flashdelay=32, phase=0, count=0;
int32 joy=0, oldjoy=0xffffffff, joyedge=0, frame;
// int32 currentcel=0;
struct timeval timein, timeout;
int32 timerend;
Point q[4];
ccbtodispccb(0,0); // 0 <- skull.dark
ccbtodispccb(1,2); // 1 <- hellhouse.dark
ccbtodispccb(2,4); // 2 <- bloodtext
dispccbs[2]->ccb_Flags |= CCB_LAST;
for (frame=3;frame<4000;frame++) {
oldjoy = joy;
GetControlPad (1,0,&cped);
joy = cped.cped_ButtonBits;
joyedge = joy&~oldjoy;
if (joyedge&ControlStart) {
return;
}
if (GetCurrentSignals () & gSignal1)
return;
/*****
if (joyedge&JOYFIREA) {
currentcel++;
if (currentcel>=numcels) {
currentcel = 0;
}
}
if (joy&JOYLEFT) {
ccbs[currentcel]->ccb_XPos -= 1<<16;
}
if (joy&JOYRIGHT) {
ccbs[currentcel]->ccb_XPos += 1<<16;
}
if (joy&JOYUP) {
ccbs[currentcel]->ccb_YPos -= 1<<16;
}
if (joy&JOYDOWN) {
ccbs[currentcel]->ccb_YPos += 1<<16;
}
*****/
flash=0;
switch (phase) {
case 0:
count++;
// dispccbs[2]->ccb_PRE0 = ((dispccbs[2]->ccb_PRE0)& ~0xffc0);
// if (dispccbs[2]->ccb_PRE0 = ((dispccbs[2]->ccb_PRE0)& ~0xffc0)|((count-20)<<6);
if (count < REALCELDIM (dispccbs[2]->ccb_Width) / 2) {
q[0].pt_X = q[3].pt_X = 110-count;
q[1].pt_X = q[2].pt_X = 110+count;
}
q[0].pt_Y = q[1].pt_Y = 83+count/4;
if (q[0].pt_Y>40) q[0].pt_Y = q[1].pt_Y = 40;
q[2].pt_Y = q[3].pt_Y = q[0].pt_Y+count;
FasterMapCel (dispccbs[2], q);
if (count == bloodtextht) phase++;
break;
// wait for lightning
case 1:
switch (--flashdelay) {
case 7:
lightning_X = ((rand()&255)-90)<<16;
case 6:
case 5:
flash = 1;
case 3:
case 2:
case 1:
ccbtodispccb(0,1); // 0 <- skull.light
ccbtodispccb(1,3); // 1 <- hellhouse.light
ccbtodispccb(3,5+flash+(rand()&2)); // 3 <- lightning
dispccbs[2]->ccb_Flags &= ~CCB_LAST;
dispccbs[3]->ccb_Flags |= CCB_LAST;
dispccbs[3]->ccb_XPos = lightning_X;
break;
case 0:
flashdelay=(rand()&63)+(rand()&63)+10;
case 4:
ccbtodispccb(0,0); // 0 <- skull.dark
ccbtodispccb(1,2); // 1 <- hellhouse.dark
dispccbs[2]->ccb_Flags |= CCB_LAST;
break;
default:
break;
}
break;
}
CopyVRAMPages (sportIO,
Bitmaps[currentbuffer]->bm_Buffer,
Bitmaps[savebuffer]->bm_Buffer,
ScreenPages,
0xffffffff);
gettime (&timein);
DrawCels (BitmapItems[currentbuffer], dispccbs[0]);
gettime (&timeout);
timerend = subtime (&timeout, &timein);
if (joyedge&JOYFIREC) {
DBUG (("%ld\n", timerend));
}
DisplayScreen (ScreenItems[currentbuffer],
ScreenItems[currentbuffer]);
currentbuffer = 1-currentbuffer;
}
}
void
loadcel (ubyte *spname, int32 index)
{
ubyte fname[80];
int32 celbufsize, *celbuffer, *p;
strcpy (fname, "zombie/");
strcat (fname, spname);
FULLDBUG (("Attempt to load cel file %s\n", fname));
if (!(celbuffer = allocloadfile (fname, 0, &celbufsize))) {
filerr (fname, celbufsize);
terminate (1);
}
#if 0
/* The old stuff... */
celbufsize = getfilesize (fname);
if (celbufsize < 8) {
DBUG (("Error - unable to load cel file (%s)\n", fname));
terminate (1);
}
celbuffer = (int32 *)malloc(celbufsize);
if (!celbuffer) {
DBUG (("Unable to allocate buffer memory for cel (%s)\n", fname));
terminate (1);
}
FULLDBUG (("celbuffer = %lx\n", celbuffer));
if (!loadfile(fname, celbuffer, celbufsize, 0)) {
DBUG (("Error - unable to load cel file (%s)\n", fname));
terminate (1);
}
#endif
p = celbuffer;
ccc = 0;
pxlc = 0;
pipc = 0;
while (celbufsize > 0) {
int32 token, chunksize;
token = p[0];
chunksize = p[1];
switch (token) {
case CHUNK_CCB:
case CHUNK_SPRH:
ccc = (CCC *)p;
FULLDBUG (("Cel header @ %lx\n", ccc));
break;
case CHUNK_PDAT:
pxlc = (PixelChunk *)p;
FULLDBUG (("Pixel data @ %lx\n", pxlc));
break;
case CHUNK_PLUT:
case CHUNK_PIPT:
pipc = (PLUTChunk *)p;
FULLDBUG (("PLUT data @ %lx\n", pipc));
break;
default:
break;
}
p += (chunksize)/4;
celbufsize -= chunksize;
}
if ((celbufsize<0) || (!ccc) || (!pxlc)) {
DBUG (("Error - invalid cel file (%s)\n", fname));
terminate (1);
}
ccbs[index] = (CCB *) malloctype (sizeof(CCB), MEMTYPE_DMA|MEMTYPE_CEL);
if (!ccbs[index]) {
DBUG (("Error - unable to allocate ccb memory (%s)\n", fname));
terminate (1);
}
memcpy (ccbs[index], &ccc->ccb_Flags, sizeof (CCB));
FULLDBUG (("ccb = %lx\n", ccbs[index]));
cels[index] = (uint32 *) malloctype (pxlc->chunk_size-8, MEMTYPE_DMA|MEMTYPE_CEL);
if (!cels[index]) {
DBUG (("Error - unable to allocate cel image memory (%s)\n", fname));
terminate (1);
}
memcpy (cels[index], pxlc->pixels, pxlc->chunk_size-8);
FULLDBUG (("celdata = %lx\n", cels[index]));
if (pipc) {
pluts[index] = (uint32 *) malloctype (pipc->chunk_size-8, MEMTYPE_DMA|MEMTYPE_CEL);
if (!pluts[index]) {
DBUG (("Error - unable to allocate plut memory (%s)\n", fname));
terminate (1);
}
memcpy (pluts[index], pipc->PLUT, pipc->chunk_size-8);
}
FULLDBUG (("plut = %lx\n", pluts[index]));
ccbs[index]->ccb_SourcePtr = (CelData *)cels[index];
ccbs[index]->ccb_PLUTPtr = pluts[index];
ccbs[index]->ccb_Flags |= CCB_SPABS|CCB_PPABS|CCB_NPABS;
ccbs[index]->ccb_XPos = xtable[index%(sizeof(xtable)/sizeof(*xtable))]<<16;
ccbs[index]->ccb_YPos = ytable[index%(sizeof(ytable)/sizeof(*ytable))]<<16;
ccbs[index]->ccb_HDX = 1<<20;
ccbs[index]->ccb_HDY = 0<<20;
ccbs[index]->ccb_VDX = 0<<16;
ccbs[index]->ccb_VDY = 1<<16;
ccbs[index]->ccb_HDDX = 0<<20;
ccbs[index]->ccb_HDDY = 0<<20;
FreeMem (celbuffer, celbufsize);
return;
}
void
ccbtodispccb (uint32 dispccbn, uint32 ccbn)
{
memcpy (dispccbs[dispccbn], ccbs[ccbn], sizeof(CCB));
dispccbs[dispccbn]->ccb_NextPtr = dispccbs[dispccbn+1];
++dispccb;
// any of this necessary?
dispccbs[dispccbn]->ccb_Flags=ccbs[ccbn]->ccb_Flags;
dispccbs[dispccbn]->ccb_SourcePtr=ccbs[ccbn]->ccb_SourcePtr;
dispccbs[dispccbn]->ccb_Width=ccbs[ccbn]->ccb_Width;
dispccbs[dispccbn]->ccb_Height=ccbs[ccbn]->ccb_Height;
dispccbs[dispccbn]->ccb_PLUTPtr=ccbs[ccbn]->ccb_PLUTPtr;
dispccbs[dispccbn]->ccb_PIXC=ccbs[ccbn]->ccb_PIXC;
dispccbs[dispccbn]->ccb_PRE0=ccbs[ccbn]->ccb_PRE0;
dispccbs[dispccbn]->ccb_PRE1=ccbs[ccbn]->ccb_PRE1;
(dispccbs[dispccbn]->ccb_Flags) &= ~CCB_LAST;
}
void
loadbackground (ubyte *backname)
{
ubyte fname[80];
int32 bufsize, *buffer, *p;
ImageCC *icc;
PixelChunk *pxlc;
strcpy (fname, backname);
FULLDBUG (("Attempt to load background image file\n"));
if (!(buffer = allocloadfile (fname, MEMTYPE_CEL, &bufsize))) {
filerr (fname, bufsize);
terminate (1);
}
#if 0
/* The old stuff... */
bufsize = getfilesize (fname);
if (bufsize < 8) {
DBUG (("Error - unable to load background image file (%s)\n", fname));
terminate (1);
}
buffer = (int32 *)malloc(bufsize);
if (!buffer) {
DBUG (("Unable to allocate buffer memory for background (%s)\n", fname));
terminate (1);
}
FULLDBUG (("buffer = %lx\n", buffer));
if (!loadfile(fname, buffer, bufsize, 0)) {
DBUG (("Error - unable to load background image file (%s)\n", fname));
terminate (1);
}
#endif
p = buffer;
icc = 0;
pxlc = 0;
while (bufsize > 0) {
int32 token, chunksize;
token = p[0];
chunksize = p[1];
switch (token) {
case CHUNK_IMAG:
icc = (ImageCC *)p;
FULLDBUG (("Image header chunk at %lx\n", icc));
break;
case CHUNK_PDAT:
pxlc = (PixelChunk *)p;
FULLDBUG (("Image data chunk at %lx\n", pxlc->pixels));
break;
default:
break;
}
p += (chunksize)/4;
bufsize -= chunksize;
}
if ((bufsize<0) || (!icc) || (!pxlc)) {
DBUG (("Error - invalid image file (%s)\n", fname));
terminate (1);
}
if ((icc->w!=Bitmaps[savebuffer]->bm_Width) || (icc->h!=Bitmaps[savebuffer]->bm_Height)
|| (icc->bitsperpixel!=16) || (icc->numcomponents!=3) || (icc->numplanes!=1)
|| (icc->colorspace!=0) || (icc->comptype!=0) || (icc->pixelorder!=1)) {
DBUG (("Error - image must be %dx%d normal screen format image\n",
Bitmaps[savebuffer]->bm_Width, Bitmaps[savebuffer]->bm_Height));
terminate (1);
}
memcpy (Bitmaps[savebuffer]->bm_Buffer, pxlc->pixels,
Bitmaps[savebuffer]->bm_Width*Bitmaps[savebuffer]->bm_Height*2);
FreeMem (buffer, bufsize);
}
void
ClearScreen (void)
{
CopyVRAMPages (sportIO,
Bitmaps[currentbuffer]->bm_Buffer,
Bitmaps[savebuffer]->bm_Buffer,
ScreenPages,
~0);
}
void
fadetoblack (rp, frames)
register struct RastPort *rp;
int32 frames;
{
int32 j, k, l, m;
for (j = frames; --j >= 0; ) {
WaitVBL (vblIO, 1);
k = j * 255 / (frames - 1);
for (l = 0; l < 32; l++) {
m = k * l / 31;
SetScreenColor (rp->rp_ScreenItem,
MakeCLUTColorEntry (l, m, m, m));
}
SetScreenColor (rp->rp_ScreenItem,
MakeCLUTColorEntry (32, 0, 0, 0));
}
SetRast (rp, 0);
ResetScreenColors (rp->rp_ScreenItem);
}
void *
malloctype (size, memtype)
int32 size;
uint32 memtype;
{
register int32 *ptr;
size += sizeof (int32);
if (ptr = AllocMem (size, memtype))
*ptr++ = size;
return ((void *) ptr);
}
void
freetype (ptr)
void *ptr;
{
register int32 *lptr;
if (lptr = (int32 *) ptr) {
lptr--;
FreeMem (lptr, *lptr);
}
}
void
terminate (int i)
{
if (!i) {
fadetoblack (&rports[1-currentbuffer], 32);
}
closestuff ();
exit (i);
}
#ifdef SOUNDSTUFF
/**************************************************************************
** PlaySoundFile - hangs until finished so rewrite and stick in a thread
**************************************************************************/
void SpoolSoundFileThread( void )
{
Item NewDir;
int32 Result;
/* Initialize audio, return if error. */
if (OpenAudioFolio())
{
ERR(("Audio Folio could not be opened!\n"));
}
/* Set directory for audio data files. */
NewDir = ChangeDirectory(gCurrentDir);
if (NewDir > 0)
{
PRT(("Directory changed to %s for Mac based file-system.\n", AUDIODIR));
}
else
{
ERR(("Directory %s not found! Err = $%x\n", AUDIODIR, NewDir));
}
Result = PlaySoundFile ( gFileName, BUFSIZE );
CloseAudioFolio();
SendSignal( gMainTaskItem, gSignal1 );
WaitSignal(0); /* Waits forever. Don't return! */
}
int32 PlaySoundFile (char *FileName, int32 BufSize )
{
int32 Result;
SoundFilePlayer *sfp;
int32 SignalIn=0, SignalsNeeded=0;
sfp = OpenSoundFile(FileName, NUMBUFFS, BufSize);
CHECKPTR(sfp, "OpenSoundFile");
Result = StartSoundFile( sfp, MAXAMPLITUDE );
CHECKRESULT(Result,"StartSoundFile");
/* Keep playing until no more samples. */
do
{
if (SignalsNeeded) SignalIn = WaitSignal(SignalsNeeded);
Result = ServiceSoundFile(sfp, SignalIn, &SignalsNeeded);
CHECKRESULT(Result,"ServiceSoundFile");
} while (SignalsNeeded && (!EndSound));
Result = StopSoundFile (sfp);
CHECKRESULT(Result,"StopSoundFile");
Result = CloseSoundFile (sfp);
CHECKRESULT(Result,"CloseSoundFile");
return 0;
error:
return (Result);
}
#endif