|
359
|
1 /*
|
|
|
2 * Adplug - Replayer for many OPL2/OPL3 audio file formats.
|
|
|
3 * Copyright (C) 1999 - 2004 Simon Peter, <dn.tlp@gmx.net>, et al.
|
|
|
4 *
|
|
|
5 * This library is free software; you can redistribute it and/or
|
|
|
6 * modify it under the terms of the GNU Lesser General Public
|
|
|
7 * License as published by the Free Software Foundation; either
|
|
|
8 * version 2.1 of the License, or (at your option) any later version.
|
|
|
9 *
|
|
|
10 * This library is distributed in the hope that it will be useful,
|
|
|
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
13 * Lesser General Public License for more details.
|
|
|
14 *
|
|
|
15 * You should have received a copy of the GNU Lesser General Public
|
|
|
16 * License along with this library; if not, write to the Free Software
|
|
|
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
18 *
|
|
|
19 * dro.c - DOSBox Raw OPL Player by Sjoerd van der Berg <harekiet@zophar.net>
|
|
|
20 *
|
|
|
21 * NOTES:
|
|
|
22 * OPL3 and second opl2 writes are ignored
|
|
|
23 */
|
|
|
24
|
|
|
25 #include "dro.h"
|
|
|
26
|
|
|
27 /*** public methods *************************************/
|
|
|
28
|
|
|
29 CPlayer *CdroPlayer::factory(Copl *newopl)
|
|
|
30 {
|
|
|
31 return new CdroPlayer(newopl);
|
|
|
32 }
|
|
|
33
|
|
|
34 bool CdroPlayer::load(const std::string &filename, const CFileProvider &fp)
|
|
|
35 {
|
|
|
36 binistream *f = fp.open(filename); if(!f) return false;
|
|
|
37 char id[8];unsigned long i;
|
|
|
38
|
|
|
39 // file validation section
|
|
|
40 f->readString(id, 8);
|
|
|
41 if(strncmp(id,"DBRAWOPL",8)) { fp.close (f); return false; }
|
|
|
42
|
|
|
43 // load section
|
|
|
44 mstotal = f->readInt(4); // Total milliseconds in file
|
|
|
45 length = f->readInt(4); // Total data bytes in file
|
|
|
46 mode = (OplMode)f->readInt(1); // Type of opl data this can contain
|
|
|
47 data = new unsigned char [length];
|
|
|
48 for (i=0;i<length;i++)
|
|
|
49 data[i]=f->readInt(1);
|
|
|
50 fp.close(f);
|
|
|
51 rewind(0);
|
|
|
52 return true;
|
|
|
53 }
|
|
|
54
|
|
|
55 bool CdroPlayer::update()
|
|
|
56 {
|
|
|
57 if (delay>500) {
|
|
|
58 delay-=500;
|
|
|
59 return true;
|
|
|
60 } else delay=0;
|
|
|
61 while (pos < length)
|
|
|
62 {
|
|
|
63 unsigned char cmd = data[pos++];
|
|
|
64 switch(cmd) {
|
|
|
65 case 0:
|
|
|
66 delay = 1 + data[pos++];
|
|
|
67 return true;
|
|
|
68 case 1:
|
|
|
69 delay = 1 + data[pos] + (data[pos+1]<<8);
|
|
|
70 pos+=2;
|
|
|
71 return true;
|
|
|
72 case 2:
|
|
|
73 index = 0;
|
|
|
74 break;
|
|
|
75 case 3:
|
|
|
76 index = 0;
|
|
|
77 break;
|
|
|
78 default:
|
|
|
79 if(!index)
|
|
|
80 opl->write(cmd,data[pos++]);
|
|
|
81 break;
|
|
|
82 }
|
|
|
83 }
|
|
|
84 return pos<length;
|
|
|
85 }
|
|
|
86
|
|
|
87 void CdroPlayer::rewind(int subsong)
|
|
|
88 {
|
|
|
89 delay=1;
|
|
|
90 pos = index = 0;
|
|
|
91 opl->init();
|
|
|
92 opl->write(1,32); // go to OPL2 mode
|
|
|
93 }
|
|
|
94
|
|
|
95 float CdroPlayer::getrefresh()
|
|
|
96 {
|
|
|
97 if (delay > 500) return 1000 / 500;
|
|
|
98 else return 1000 / (double)delay;
|
|
|
99 }
|