aboutsummaryrefslogtreecommitdiff
path: root/engines/avalanche/stars.cpp
blob: 518124170ac45f6d9c15d52db55b87261187aa45 (plain)
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
               /* Demonstration of the Bigo II system. */
/* $I c:\sleep5\DSMI.INC*/
#include "graph.h"
/*#include "Crt.h"*/
/*#include "Rodent.h"*/
/*#include "Tommys.h"*/

integer gd,gm;

typedef matrix<'\0','\377',0,15,byte> fonttype;

boolean reverse;
word spinnum;
array<0,1,fonttype> f;
file<fonttype> ff;
array<0,7,0,15,0,79,byte> strip;
byte across;
word w; byte y;
byte charnum;
byte cfont; /* current font. 0=roman, 1=italic. */

char* c;

boolean nomusic;

const integer colours = 12; /* Run Workout to see possible values of these two. */
const integer steps = 6; /* 60,30,20,15,12,10,6,5,4,3,2,1 */
const integer gmtop = 360 / steps;

 const integer scardcount = 13;

     const array<0,scardcount-1,integer> soundcards = 
       {{1,2,6,3,4,5,8,9,10,7,7,7,7}};

/*$L credits.obj*/ extern void credits(); 

void bigo2(string date)
{
 integer gd,gm;
 byte c;
 palettetype p;
 untyped_file f; pointer pp; word s;


 getpalette(p);
 setvisualpage(1); setactivepage(0);
 assign(f,"logo.avd"); reset(f,1);
 for( gd=7; gd <= 194; gd ++)
  blockread(f,mem[0xa000*(gd*80)],53);
 close(f);
 s=imagesize(0,7,415,194); getmem(pp,s); getimage(0,7,415,194,pp);

 cleardevice();
 for( gd=1; gd <= 64; gd ++)
 {
  for( gm=0; gm <= gmtop; gm ++)
  {
   c=(c % colours)+1;
/*   putpixel(trunc(sin(gm*steps*n)*gd*6)+320,
              trunc(cos(gm*steps*n)*gd*3)+175,c); */
   if (c>5)  continue_;
   setcolor(c); arc(320,175,gm*steps,gm*steps+1,gd*6);
  }
  if (keypressed())  { closegraph(); exit(0); }
 }
 settextstyle(0,0,1); setcolor(13);
 outtextxy(550,343,"(press any key)");

 putimage(112,0,pp,orput); freemem(pp,s);
 resetmouse; setvisualpage(0);
}

void nextchar()     /* Sets up charnum & cline for the next character. */
{

 c += 1;
}

void getchar()
{
 do {
  nextchar();

  switch (*c) {
   case '@': { cfont=1; nextchar(); } break;
   case '^': { cfont=0; nextchar(); } break;
   case '%': if (nomusic) 
        {
          closegraph(); exit(0);      /* End of text and no music => stop. */
        }
        else c=addr(credits());
        break;                   /* End of test, but still playing => again. */
  }

 } while (!((*c!='\15') && (*c!='\12')));

 for( w=0; w <= 7; w ++)
  for( y=0; y <= 15; y ++)
   move(strip[w][y][1],strip[w][y][0],79);

 for( w=0; w <= 7; w ++)
  for( y=0; y <= 15; y ++)
   strip[w][y][79]=(byte)((strip[7][y][78] << (w+1)))+
    ((cardinal)f[cfont][*c][y] >> (7-w));

 across=0;
}

void scrolltext()
{
 byte c,w,y;

 across += 1;
 if (across==8)  getchar();

 for( y=0; y <= 15; y ++)
  for( w=0; w <= 1; w ++)
  move(strip[across][y][0],mem[0xa000*24000+(y*2+w)*80],80);
}

void do_stuff()
{
 switch (spinnum) {
  case 50 ... 110: {
            setfillstyle(1,14);
            bar(0,315+(spinnum-50) / 3,640,315+(spinnum-50) / 3);
            bar(0,316-(spinnum-50) / 3,640,316-(spinnum-50) / 3);
            if (spinnum>56) 
            {
             setfillstyle(1,13);
             bar(0,315+(spinnum-56) / 3,640,315+(spinnum-56) / 3);
             bar(0,316-(spinnum-56) / 3,640,316-(spinnum-56) / 3);
            }
          }
          break;
  case 150 ... 198: {
             setfillstyle(1,0);
             bar(0,315+(spinnum-150) / 3,640,315+(spinnum-150) / 3);
             bar(0,316-(spinnum-150) / 3,640,316-(spinnum-150) / 3);
            }
            break;
  case 200: scrolltext(); break;
 }
}

void setcol(byte which,byte what)
/*var dummy:byte;*/
{;
/* setpalette(which,what);
 asm
(*  mov dx,$3DA;
  in ax,dx;

  or ah,ah;

  mov dx,$3C0;
  mov al,which;
  out dx,al;

  mov dx,$3C0;
  mov al,what;
  out dx,al;
 end;
(* dummy:=port[$3DA];
 port[$3C0]:=which; port[$3C0]:=what;*/
}

void bigo2go()
{
 palettetype p; byte c; boolean lmo;
 boolean altnow,altbefore;

 for( gd=0; gd <= 13; gd ++) p.colors[gd]=0;

 setcol(13,24); /* murk */ setcol(14,38); /* gold */
 setcol(15,egawhite); /* white- of course */
 p.colors[13]=24; p.colors[14]=38; p.colors[15]=egawhite;

 /***/

    p.colors[5]=egawhite;
    p.colors[4]=egalightcyan;
    p.colors[3]=egacyan;
    p.colors[2]=egalightblue;
    p.colors[1]=egablue;

 /***/

 c=1; p.size=16; lmo=false;
 setallpalette(p);

 do {
/*  if reverse then
  begin
   dec(c); if c=0 then c:=colours;
  end else
  begin
   inc(c); if c>colours then c:=1;
  end;
  for gm:=1 to colours do
   case p.colors[gm] of
    egaWhite: begin p.colors[gm]:=egaLightcyan; setcol(gm,egaLightCyan); end;
    egaLightcyan: begin p.colors[gm]:=egaCyan; setcol(gm,egaCyan); end;
    egaCyan: begin p.colors[gm]:=egaLightblue; setcol(gm,egaLightblue); end;
    egaLightblue: begin p.colors[gm]:=egaBlue; setcol(gm,egaBlue); end;
    egaBlue: begin p.colors[gm]:=0; setcol(gm,0); end;
   end;
  p.colors[c]:=egaWhite; setcol(c,egaWhite);

  AltBefore:=AltNow; AltNow:=testkey(sAlt);*/

  if (anymousekeypressed)  lmo=true;
  if (keypressed())  lmo=true;
  if ((! nomusic) && (ampgetmodulestatus != md_playing))  lmo=true;

 /* if (AltNow=True) and (AltBefore=False) then reverse:=not reverse;*/

  do_stuff();
  if (spinnum<200)  spinnum += 1;
 } while (!lmo);
}

void parse_cline()
{
    integer e;

 if (paramstr(1)!="jsb") 
 {
  output << "Not a standalone program." << NL; exit(255);
 }
}

integer getsoundhardware(psoundcard scard)
{
    integer sc,i,autosel,select;
    char ch;
    integer e;



integer getsoundhardware_result;
Lagain:
  sc=detectgus(scard);
  if (sc!=0)  sc=detectpas(scard);
  if (sc!=0)  sc=detectaria(scard);
  if (sc!=0)  sc=detectsb(scard);

  /* if no sound card found, zero scard */
  if (sc!=0)  fillchar(scard,sizeof(tsoundcard),0);

  autosel=-1;
/*  if sc=0 then
    for i:=0 to scardcount-1 do
      if scard^.ID=soundcards[i].ID then begin
        { Set auto selection mark }
        autosel:=i+1;
        break;
      end;*/

  /* Print the list of sound cards */

  val(paramstr(13),select,e);

  /* Default entry? */
  if (select==0)  select=autosel;
  if (select!=autosel)  {
    /* clear all assumptions */
    sc=-1;
    fillchar(scard,sizeof(tsoundcard),0);
    scard->id=soundcards[select-1];  /* set correct ID */
  }

  /* Query I/O address */
  if (scard->id==id_dac)  scard->ioport=0x378;

  /* Read user input */
  val(paramstr(15),i,e);

  if (i!=0)  scard->ioport=i;
  if (sc!=1)    /* Not autodetected */
    switch (scard->id) {
      case id_sb16:
      case id_pas16:
      case id_wss:
      case id_aria:
      case id_gus    : scard->samplesize=2;
      break;                            /* 16-bit card */
      case id_sbpro:
      case id_pas:
      case id_pasplus: scard->stereo=true;
      break;                            /* enable stereo */
      default: {
        scard->samplesize=1;
        scard->stereo=false;
      }
    }

  if (scard->id!=id_dac)  {
    val(paramstr(17),i,e);

    if (i!=0)  scard->dmairq=i;

    val(paramstr(16),i,e);

    if (i!=0)  scard->dmachannel=i;
  } else {
    /* Select correct DAC */
    scard->maxrate=44100;
    if (select==11)  {
      scard->stereo=true;
      scard->dmachannel=1;    /* Special 'mark' */
      scard->maxrate=60000;
    } else
    if (select==12)  {
      scard->stereo=true;
      scard->dmachannel=2;
      scard->maxrate=60000;
      if (scard->ioport==0)  scard->ioport=0x378;
    } else
    if (select==13)  {
      scard->dmachannel=0;
      scard->ioport=0x42;     /* Special 'mark' */
      scard->maxrate=44100;
    }
  }

/*    writeln('Your selection: ',select,' at ',scard^.ioPort,
            ' using IRQ ',scard^.dmaIRQ,' and DMA channel ',scard^.dmaChannel);
  readln;*/

  getsoundhardware_result=0;
return getsoundhardware_result;
}

tsoundcard scard;
tmcpstruct mcpstrc;
tdds dds;
pmodule module;
tsdi_init sdi;
integer e,
bufsize;
char ch;
boolean v86,
vdsok;
longint a,rate,
tempseg;
string answer;
pointer temp;
word flags;
word curch;
byte modulevolume;
array<0,4,tsampleinfo> sample;
array<0,31,word> voltable;

int main(int argc, const char* argv[])
{
 pio_initialize(argc, argv);
 parse_cline();

 nomusic=paramstr(13)=='0';

 if (! nomusic) 
 {
    /* Read sound card information */
    if (getsoundhardware(&scard)==-1)  exit(1);


    /* Initialize Timer Service */
    tsinit;
    atexit(&tsclose);
    if (scard.id==id_gus)  {
      /* Initialize GUS player */
      #ifndef DPMI
      scard.extrafield[2]=1;  /* GUS DMA transfer does not work in V86 */
      #endif
      gusinit(&scard);
      atexit(&gusclose);

      /* Initialize GUS heap manager */
      gushminit;

      /* Init CDI */
      cdiinit;

      /* Register GUS into CDI */
      cdiregister(&cdi_gus,0,31);

      /* Add GUS event player engine into Timer Service */
      tsaddroutine(&gusinterrupt,gus_timer);
    } else {
      /* Initialize Virtual DMA Specification */
      #ifndef DPMI
      vdsok=vdsinit==0;
      #else
      vdsok=false;
      #endif

      fillchar(mcpstrc,sizeof(tmcpstruct),0);

      /* Query for sampling rate */
      val(paramstr(14),a,e);
      if (a>4000)  rate=a; else rate=21000;

      /* Query for quality */
      mcpstrc.options=mcp_quality;

      switch (scard.id) {
        case id_sb     : {
                      sdi=sdi_sb;
                      scard.maxrate=22000;
                    }
                    break;
        case id_sbpro  : {
                      sdi=sdi_sbpro;
                      scard.maxrate=22000;
                    }
                    break;
        case id_pas:
        case id_pasplus:
        case id_pas16  : {
                      sdi=sdi_pas;
                      scard.maxrate=44100;
                    }
                    break;
        case id_sb16   : {
                      sdi=sdi_sb16;
                      scard.maxrate=44100;
                    }
                    break;
        case id_aria   : {
                      sdi=sdi_aria;
                      scard.maxrate=44100;
                    }
                    break;
        case id_wss    : {
                      sdi=sdi_wss;
                      scard.maxrate=48000;
                    }
                    break;
        #ifndef DPMI
        case id_dac    : sdi=sdi_dac; break; /* Only available in real mode */
        #endif
      }

      mcpinitsounddevice(sdi,&scard);
      a=mcp_tablesize;
      mcpstrc.reqsize=0;

      /* Calculate mixing buffer size */
      bufsize=(longint)(2800*(integer)(scard.samplesize) << (byte)(scard.stereo))*
               (longint)(rate) / (longint)(22000);
      mcpstrc.reqsize=0;
      if ((mcpstrc.options & mcp_quality)>0) 
        if (scard.samplesize==1)  a += mcp_qualitysize; else
          a=mcp_tablesize16+mcp_qualitysize16;
      if ((longint)(bufsize)+(longint)(a)>65500)  bufsize=longint(65500)-a;

      #ifdef DPMI
      dpmiversion((byte)(e),(byte)(e),(byte)(e),flags);
      v86=(flags & 2)==0;
      #endif

      /* Allocate volume table + mixing buffer */
      #ifdef DPMI

      /* In the V86 mode, the buffer must be allocated below 1M */
      if (v86)  {
        tempseg=0;
        dpmiallocdos((a+longint(bufsize)) / longint(16)+longint(1),flags,(word)(tempseg));
      } else {
      #endif
      getmem(temp,a+longint(bufsize));
      if (temp==nil)  exit(2);
      #ifdef DPMI
      tempseg=seg(temp);
      }
      #else
      tempseg=seg(temp)+ofs(temp) / 16+1;
      #endif
      mcpstrc.bufferseg=tempseg;
      mcpstrc.bufferphysical=-1;

      if (vdsok && (scard.id!=id_dac))  {
        dds.size=bufsize;
        dds.segment=tempseg;
        dds.offset=0;

        /* Lock DMA buffer if VDS present */
        if (vdslockdma(&dds)==0)  mcpstrc.bufferphysical=dds.address;
      }
      if (mcpstrc.bufferphysical==-1) 
        #ifdef DPMI
        mcpstrc.bufferphysical=dpmigetlinearaddr(tempseg);
        #else
        mcpstrc.bufferphysical=(longint)(tempseg) << 4;
        #endif

      mcpstrc.buffersize=bufsize;
      mcpstrc.samplingrate=rate;
      /* Initialize Multi Channel Player */
      if (mcpinit(&mcpstrc)!=0)  exit(3);
      atexit(&mcpclose);

      /* Initialize Channel Distributor */
      cdiinit;

      /* Register MCP into CDI*/
      cdiregister(&cdi_mcp,0,31);
    }

    /* Try to initialize AMP */
    if (ampinit(0)!=0)  exit(3);
    atexit(&ampclose);

    /* Hook AMP player routine into Timer Service */
    tsaddroutine(&ampinterrupt,amp_timer);

    #ifndef DPMI
    /* If using DAC, then adjust DAC timer */
    if (scard.id==id_dac)  setdactimer(tsgettimerrate);
    #endif

    if (scard.id!=id_gus)  mcpstartvoice; else gusstartvoice;

    /* Load an example AMF */
    module=amploadmod("avalot2.mod",0);
    if (module==nil)  exit(4);

    /* Is it MCP, Quality mode and 16-bit card? */
    if ((scard.id!=id_gus) && ((mcpstrc.options & mcp_quality)>0)
       && (scard.samplesize==2))  {
      /* Open module+2 channels with amplified volumetable (4.7 gain) */
      for( a=1; a <= 32; a ++) voltable[a-longint(1)]=a*longint(150) / longint(32);
      cdisetupchannels(0,module->channelcount+2,&voltable);
    } else {
      /* Open module+2 channels with regular volumetable */
      cdisetupchannels(0,module->channelcount+2,nil);
    }

    curch=module->channelcount;
    modulevolume=64;

   /***/ ampplaymodule(module,0);
 }

 gd=3; gm=1; initgraph(gd,gm,"");
 assign(ff,"avalot.fnt"); reset(ff); ff >> f[0]; close(ff);
 assign(ff,"avitalic.fnt"); reset(ff); ff >> f[1]; close(ff);

 c=addr(credits()); c -= 1;

 fillchar(strip,sizeof(strip),'\0');
 reverse=false; spinnum=0; across=7; charnum=1; cfont=0;
 bigo2("1189"); /* 1189? 79? 2345? 1967? */
 bigo2go();

 if (! nomusic)  ampstopmodule;
 closegraph();
 return EXIT_SUCCESS;
}