2 * Adplug - Replayer for many OPL2/OPL3 audio file formats.
3 * Copyright (C) 1999 - 2007 Simon Peter, <dn.tlp@gmx.net>, et al.
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.
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.
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
19 * dro.c - DOSBox Raw OPL Player by Sjoerd van der Berg <harekiet@zophar.net>
21 * upgraded by matthew gambrell <zeromus@zeromus.org>
23 * NOTES: 3-oct-04: the DRO format is not yet finalized. beware.
31 /*** public methods *************************************/
33 CPlayer *CdroPlayer::factory(Copl *newopl)
35 return new CdroPlayer(newopl);
38 CdroPlayer::CdroPlayer(Copl *newopl)
39 : CPlayer(newopl), data(0)
41 if(opl->gettype() == Copl::TYPE_OPL2)
47 bool CdroPlayer::load(const std::string &filename, const CFileProvider &fp)
49 binistream *f = fp.open(filename); if(!f) return false;
53 // file validation section
55 if(strncmp(id,"DBRAWOPL",8)) { fp.close (f); return false; }
56 int version = f->readInt(4); // not very useful just yet
57 if(version != 0x10000) { fp.close(f); return false; }
60 mstotal = f->readInt(4); // Total milliseconds in file
61 length = f->readInt(4); // Total data bytes in file
62 data = new unsigned char [length];
64 f->ignore(1); // Type of opl data this can contain - ignored
66 data[i]=f->readInt(1);
68 if ((data[0] == 0) || (data[1] == 0) || (data[2] == 0)) {
69 // Some early .DRO files only used one byte for the hardware type, then
70 // later changed to four bytes with no version number change. If we're
71 // here then this is a later (more popular) file with the full four bytes
72 // for the hardware-type.
73 i = 0; // so ignore the three bytes we just read and start again
76 data[i]=f->readInt(1);
82 bool CdroPlayer::update()
90 while (pos < length) {
91 unsigned char cmd = data[pos++];
94 delay = 1 + data[pos++];
97 delay = 1 + data[pos] + (data[pos+1]<<8);
109 if(cmd==4) cmd = data[pos++]; //data override
110 if(index == 0 || opl3_mode)
111 opl->write(cmd,data[pos++]);
119 void CdroPlayer::rewind(int subsong)
125 //dro assumes all registers are initialized to 0
126 //registers not initialized to 0 will be corrected
128 for(int i=0;i<256;i++)
132 for(int i=0;i<256;i++)
137 float CdroPlayer::getrefresh()
139 if (delay > 500) return 1000 / 500;
140 else return 1000 / (double)delay;