2 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
3 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
4 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
5 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
6 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
7 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
8 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
9 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
10 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
11 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
36 song_info Songs[MAX_NUM_SONGS];
37 int Songs_initialized = 0;
43 extern void digi_stop_current_song();
45 int Redbook_enabled = 1;
47 //0 if redbook is no playing, else the track number
48 int Redbook_playing = 0;
50 #define NumLevelSongs (Num_songs - SONG_FIRST_LEVEL_SONG)
52 extern int CD_blast_mixer();
55 #define REDBOOK_VOLUME_SCALE (255/3) //255 is MAX
57 #define REDBOOK_VOLUME_SCALE (255)
60 //takes volume in range 0..8
61 void set_redbook_volume(int volume)
64 RBASetVolume(0); // makes the macs sound really funny
66 RBASetVolume(volume*REDBOOK_VOLUME_SCALE/8);
69 extern char CDROM_dir[];
77 if ( Songs_initialized ) return;
80 #if !defined(MACINTOSH) && !defined(WINDOWS) // don't crank it if on a macintosh!!!!!
81 if (!FindArg("-nomixer"))
82 CD_blast_mixer(); // Crank it!
86 if (cfexist("descent.sng")) { // mac (demo?) datafiles don't have the .sng file
87 fp = cfopen( "descent.sng", "rb" );
90 Error( "Couldn't open descent.sng" );
93 while (cfgets(inputline, 80, fp ))
95 char *p = strchr(inputline,'\n');
97 if ( strlen( inputline ) )
99 Assert( i < MAX_NUM_SONGS );
100 sscanf( inputline, "%s %s %s",
102 Songs[i].melodic_bank_file,
103 Songs[i].drum_bank_file );
104 //printf( "%d. '%s' '%s' '%s'\n",i,Songs[i].filename,Songs[i].melodic_bank_file,Songs[i].drum_bank_file );
109 if (Num_songs <= SONG_FIRST_LEVEL_SONG)
110 Error("Must have at least %d songs",SONG_FIRST_LEVEL_SONG+1);
114 Songs_initialized = 1;
117 #if !defined(SHAREWARE) || ( defined(SHAREWARE) && defined(APPLE_DEMO) )
118 if (FindArg("-noredbook"))
124 #ifndef __MSDOS__ // defined(WINDOWS) || defined(MACINTOSH)
127 RBAInit(toupper(CDROM_dir[0]) - 'A');
132 set_redbook_volume(Config_redbook_volume);
136 //atexit(RBAStop); // stop song on exit
137 #endif // endof ifndef SHAREWARE, ie ifdef SHAREWARE
140 #define FADE_TIME (f1_0/2)
142 //stop the redbook, so we can read off the CD
143 void songs_stop_redbook(void)
145 int old_volume = Config_redbook_volume*REDBOOK_VOLUME_SCALE/8;
146 fix old_time = timer_get_fixed_seconds();
148 if (Redbook_playing) { //fade out volume
151 fix t = timer_get_fixed_seconds();
153 new_volume = fixmuldiv(old_volume,(FADE_TIME - (t-old_time)),FADE_TIME);
158 RBASetVolume(new_volume);
160 } while (new_volume > 0);
163 //RBAStop(); // Stop CD, if playing
165 RBASetVolume(old_volume); //restore volume
171 //stop any songs - midi or redbook - that are currently playing
172 void songs_stop_all(void)
174 digi_stop_current_song(); // Stop midi song, if playing
176 songs_stop_redbook(); // Stop CD, if playing
179 int force_rb_register=0;
181 void reinit_redbook()
183 #ifndef __MSDOS__ // defined(WINDOWS) || defined(MACINTOSH)
186 RBAInit(toupper(CDROM_dir[0]) - 'A');
191 set_redbook_volume(Config_redbook_volume);
198 //returns 1 if track started sucessfully
199 //start at tracknum. if keep_playing set, play to end of disc. else
200 //play only specified track
201 int play_redbook_track(int tracknum,int keep_playing)
205 if (!RBAEnabled() && Redbook_enabled && !FindArg("-noredbook"))
208 if (force_rb_register) {
209 RBARegisterCD(); //get new track list for new CD
210 force_rb_register = 0;
213 if (Redbook_enabled && RBAEnabled()) {
214 int num_tracks = RBAGetNumberOfTracks();
215 if (tracknum <= num_tracks)
216 if (RBAPlayTracks(tracknum,keep_playing?num_tracks:tracknum)) {
217 Redbook_playing = tracknum;
221 return (Redbook_playing != 0);
225 * Some of these have different Track listings!
226 * Which one is the "correct" order?
228 #define D2_1_DISCID 0x7d0ff809 // Descent II
229 #define D2_2_DISCID 0xe010a30e // Descent II
230 #define D2_3_DISCID 0xd410070d // Descent II
231 #define D2_4_DISCID 0xc610080d // Descent II
232 #define D2_DEF_DISCID 0x87102209 // Definitive collection Disc 2
233 #define D2_OEM_DISCID 0xac0bc30d // Destination: Quartzon
234 #define D2_OEM2_DISCID 0xc40c0a0d // Destination: Quartzon
235 #define D2_VERTIGO_DISCID 0x53078208 // Vertigo
236 #define D2_VERTIGO2_DISCID 0x64071408 // Vertigo + DMB
237 #define D2_MAC_DISCID 0xb70ee40e // Macintosh
238 #define D2_IPLAY_DISCID 0x22115710 // iPlay for Macintosh
240 #define REDBOOK_TITLE_TRACK 2
241 #define REDBOOK_CREDITS_TRACK 3
242 #define REDBOOK_FIRST_LEVEL_TRACK (songs_haved2_cd()?4:1)
244 // songs_haved2_cd returns 1 if the descent 2 CD is in the drive and
248 int songs_haved2_cd()
252 if (!Redbook_enabled)
255 discid = RBAGetDiscID();
265 case D2_VERTIGO_DISCID:
266 case D2_VERTIGO2_DISCID:
268 case D2_IPLAY_DISCID:
269 printf("Found D2 CD! discid: %x\n", discid);
272 printf("Unknown CD! discid: %x\n", discid);
277 int songs_haved2_cd()
279 char temp[128],cwd[128];
283 strcpy(temp,CDROM_dir);
285 #ifndef MACINTOSH //for PC, strip of trailing slash
286 if (temp[strlen(temp)-1] == '\\')
287 temp[strlen(temp)-1] = 0;
290 if ( !chdir(temp) ) {
300 void songs_play_song( int songnum, int repeat )
303 //Assert(songnum != SONG_ENDLEVEL && songnum != SONG_ENDGAME); //not in full version
306 if ( !Songs_initialized )
309 //stop any music already playing
313 //do we want any of these to be redbook songs?
315 if (force_rb_register) {
316 RBARegisterCD(); //get new track list for new CD
317 force_rb_register = 0;
320 if (songnum == SONG_TITLE)
321 play_redbook_track(REDBOOK_TITLE_TRACK,0);
322 else if (songnum == SONG_CREDITS)
323 play_redbook_track(REDBOOK_CREDITS_TRACK,0);
325 if (!Redbook_playing) { //not playing redbook, so play midi
328 digi_play_midi_song( Songs[songnum].filename, Songs[songnum].melodic_bank_file, Songs[songnum].drum_bank_file, repeat );
330 digi_play_midi_song(songnum, repeat);
335 int current_song_level;
337 void songs_play_level_song( int levelnum )
342 Assert( levelnum != 0 );
344 if ( !Songs_initialized )
349 current_song_level = levelnum;
351 songnum = (levelnum>0)?(levelnum-1):(-levelnum);
353 if (!RBAEnabled() && Redbook_enabled && !FindArg("-noredbook"))
356 if (force_rb_register) {
357 RBARegisterCD(); //get new track list for new CD
358 force_rb_register = 0;
361 if (Redbook_enabled && RBAEnabled() && (n_tracks = RBAGetNumberOfTracks()) > 1) {
363 //try to play redbook
365 mprintf((0,"n_tracks = %d\n",n_tracks));
367 play_redbook_track(REDBOOK_FIRST_LEVEL_TRACK + (songnum % (n_tracks-REDBOOK_FIRST_LEVEL_TRACK+1)),1);
370 if (! Redbook_playing) { //not playing redbook, so play midi
372 songnum = SONG_FIRST_LEVEL_SONG + (songnum % NumLevelSongs);
375 digi_play_midi_song( Songs[songnum].filename, Songs[songnum].melodic_bank_file, Songs[songnum].drum_bank_file, 1 );
377 digi_play_midi_song( songnum, 1 );
383 //this should be called regularly to check for redbook restart
384 void songs_check_redbook_repeat()
386 static fix last_check_time;
389 if (!Redbook_playing || Config_redbook_volume==0) return;
391 current_time = timer_get_fixed_seconds();
392 if (current_time < last_check_time || (current_time - last_check_time) >= F2_0) {
393 if (!RBAPeekPlayStatus()) {
395 // if title ends, start credit music
396 // if credits music ends, restart it
397 if (Redbook_playing == REDBOOK_TITLE_TRACK || Redbook_playing == REDBOOK_CREDITS_TRACK)
398 play_redbook_track(REDBOOK_CREDITS_TRACK,0);
400 //songs_goto_next_song();
402 //new code plays all tracks to end of disk, so if disk has
403 //stopped we must be at end. So start again with level 1 song.
405 songs_play_level_song(1);
409 last_check_time = current_time;
413 //goto the next level song
414 void songs_goto_next_song()
416 if (Redbook_playing) //get correct track
417 current_song_level = RBAGetTrackNum() - REDBOOK_FIRST_LEVEL_TRACK + 1;
419 songs_play_level_song(current_song_level+1);
423 //goto the previous level song
424 void songs_goto_prev_song()
426 if (Redbook_playing) //get correct track
427 current_song_level = RBAGetTrackNum() - REDBOOK_FIRST_LEVEL_TRACK + 1;
429 if (current_song_level > 1)
430 songs_play_level_song(current_song_level-1);