2 * Adplug - Replayer for many OPL2/OPL3 audio file formats.
3 * Copyright (C) 1999 - 2005 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 * raw.c - RAW Player by Simon Peter <dn.tlp@gmx.net>
25 /*** public methods *************************************/
27 CPlayer *CrawPlayer::factory(Copl *newopl)
29 return new CrawPlayer(newopl);
32 bool CrawPlayer::load(const std::string &filename, const CFileProvider &fp)
34 binistream *f = fp.open(filename); if(!f) return false;
38 // file validation section
40 if(strncmp(id,"RAWADATA",8)) { fp.close (f); return false; }
43 clock = f->readInt(2); // clock speed
44 length = (fp.filesize(f) - 10) / 2;
45 data = new Tdata [length];
46 for(i = 0; i < length; i++) {
47 data[i].param = f->readInt(1);
48 data[i].command = f->readInt(1);
56 bool CrawPlayer::update()
60 if(pos >= length) return false;
69 switch(data[pos].command) {
70 case 0: del = data[pos].param - 1; break;
72 if(!data[pos].param) {
74 speed = data[pos].param + (data[pos].command << 8);
77 opl->setchip(data[pos].param - 1);
80 if(data[pos].param == 0xff) {
81 rewind(0); // auto-rewind song
87 opl->write(data[pos].command,data[pos].param);
90 } while(data[pos++].command || setspeed);
95 void CrawPlayer::rewind(int subsong)
97 pos = del = 0; speed = clock; songend = false;
98 opl->init(); opl->write(1, 32); // go to 9 channel mode
101 float CrawPlayer::getrefresh()
103 return 1193180.0 / (speed ? speed : 0xffff); // timer oscillator speed / wait register = clock frequency