|
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 * raw.c - RAW Player by Simon Peter <dn.tlp@gmx.net>
|
|
|
20 *
|
|
|
21 * NOTES:
|
|
|
22 * OPL3 register writes are ignored (not possible with AdLib).
|
|
|
23 */
|
|
|
24
|
|
|
25 #include "raw.h"
|
|
|
26
|
|
|
27 /*** public methods *************************************/
|
|
|
28
|
|
|
29 CPlayer *CrawPlayer::factory(Copl *newopl)
|
|
|
30 {
|
|
|
31 return new CrawPlayer(newopl);
|
|
|
32 }
|
|
|
33
|
|
|
34 bool CrawPlayer::load(const std::string &filename, const CFileProvider &fp)
|
|
|
35 {
|
|
|
36 binistream *f = fp.open(filename); if(!f) return false;
|
|
|
37 char id[8];
|
|
|
38 unsigned long i;
|
|
|
39
|
|
|
40 // file validation section
|
|
|
41 f->readString(id, 8);
|
|
|
42 if(strncmp(id,"RAWADATA",8)) { fp.close (f); return false; }
|
|
|
43
|
|
|
44 // load section
|
|
|
45 clock = f->readInt(2); // clock speed
|
|
|
46 length = (fp.filesize(f) - 10) / 2;
|
|
|
47 data = new Tdata [length];
|
|
|
48 for(i = 0; i < length; i++) {
|
|
|
49 data[i].param = f->readInt(1);
|
|
|
50 data[i].command = f->readInt(1);
|
|
|
51 }
|
|
|
52
|
|
|
53 fp.close(f);
|
|
|
54 rewind(0);
|
|
|
55 return true;
|
|
|
56 }
|
|
|
57
|
|
|
58 bool CrawPlayer::update()
|
|
|
59 {
|
|
|
60 bool setspeed;
|
|
|
61
|
|
|
62 if(pos >= length) return false;
|
|
|
63
|
|
|
64 if(del) {
|
|
|
65 del--;
|
|
|
66 return !songend;
|
|
|
67 }
|
|
|
68
|
|
|
69 do {
|
|
|
70 setspeed = false;
|
|
|
71 switch(data[pos].command) {
|
|
|
72 case 0: del = data[pos].param - 1; break;
|
|
|
73 case 2:
|
|
|
74 if(!data[pos].param) {
|
|
|
75 pos++;
|
|
|
76 speed = data[pos].param + (data[pos].command << 8);
|
|
|
77 setspeed = true;
|
|
|
78 } else
|
|
|
79 opl3 = data[pos].param - 1;
|
|
|
80 break;
|
|
|
81 case 0xff:
|
|
|
82 if(data[pos].param == 0xff) {
|
|
|
83 rewind(0); // auto-rewind song
|
|
|
84 songend = true;
|
|
|
85 return !songend;
|
|
|
86 }
|
|
|
87 break;
|
|
|
88 default:
|
|
|
89 if(!opl3)
|
|
|
90 opl->write(data[pos].command,data[pos].param);
|
|
|
91 break;
|
|
|
92 }
|
|
|
93 } while(data[pos++].command || setspeed);
|
|
|
94
|
|
|
95 return !songend;
|
|
|
96 }
|
|
|
97
|
|
|
98 void CrawPlayer::rewind(int subsong)
|
|
|
99 {
|
|
|
100 pos = del = opl3 = 0; speed = clock; songend = false;
|
|
|
101 opl->init(); opl->write(1,32); // go to OPL2 mode
|
|
|
102 }
|
|
|
103
|
|
|
104 float CrawPlayer::getrefresh()
|
|
|
105 {
|
|
|
106 return 1193180.0 / (speed ? speed : 0xffff); // timer oscillator speed / wait register = clock frequency
|
|
|
107 }
|