comparison Plugins/Input/adplug/core/dro.cpp @ 428:15ca2ea93a30 trunk

[svn] Sync with upstream CVS. This implements RIX playback.
author chainsaw
date Sat, 14 Jan 2006 07:27:13 -0800
parents 8df427a314a8
children f12d7e208b43
comparison
equal deleted inserted replaced
427:f61e69a1a376 428:15ca2ea93a30
1 /* 1 /*
2 * Adplug - Replayer for many OPL2/OPL3 audio file formats. 2 * Adplug - Replayer for many OPL2/OPL3 audio file formats.
3 * Copyright (C) 1999 - 2004 Simon Peter, <dn.tlp@gmx.net>, et al. 3 * Copyright (C) 1999 - 2005 Simon Peter, <dn.tlp@gmx.net>, et al.
4 * 4 *
5 * This library is free software; you can redistribute it and/or 5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public 6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either 7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version. 8 * version 2.1 of the License, or (at your option) any later version.
16 * License along with this library; if not, write to the Free Software 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 17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * 18 *
19 * dro.c - DOSBox Raw OPL Player by Sjoerd van der Berg <harekiet@zophar.net> 19 * dro.c - DOSBox Raw OPL Player by Sjoerd van der Berg <harekiet@zophar.net>
20 * 20 *
21 * NOTES: 21 * upgraded by matthew gambrell <zeromus@zeromus.org>
22 * OPL3 and second opl2 writes are ignored 22 *
23 */ 23 * NOTES: 3-oct-04: the DRO format is not yet finalized. beware.
24 */
25
26 #include <stdio.h>
24 27
25 #include "dro.h" 28 #include "dro.h"
26 29
27 /*** public methods *************************************/ 30 /*** public methods *************************************/
28 31
29 CPlayer *CdroPlayer::factory(Copl *newopl) 32 CPlayer *CdroPlayer::factory(Copl *newopl)
30 { 33 {
31 return new CdroPlayer(newopl); 34 return new CdroPlayer(newopl);
32 } 35 }
33 36
37 CdroPlayer::CdroPlayer(Copl *newopl)
38 : CPlayer(newopl), data(0)
39 {
40 if(opl->gettype() == Copl::TYPE_OPL2)
41 opl3_mode = 0;
42 else
43 opl3_mode = 1;
44 }
45
34 bool CdroPlayer::load(const std::string &filename, const CFileProvider &fp) 46 bool CdroPlayer::load(const std::string &filename, const CFileProvider &fp)
35 { 47 {
36 binistream *f = fp.open(filename); if(!f) return false; 48 binistream *f = fp.open(filename); if(!f) return false;
37 char id[8];unsigned long i; 49 char id[8];
50 unsigned long i;
38 51
39 // file validation section 52 // file validation section
40 f->readString(id, 8); 53 f->readString(id, 8);
41 if(strncmp(id,"DBRAWOPL",8)) { fp.close (f); return false; } 54 if(strncmp(id,"DBRAWOPL",8)) { fp.close (f); return false; }
55 int version = f->readInt(4); // not very useful just yet
56 if(version != 0x10000) { fp.close(f); return false; }
42 57
43 // load section 58 // load section
44 mstotal = f->readInt(4); // Total milliseconds in file 59 mstotal = f->readInt(4); // Total milliseconds in file
45 length = f->readInt(4); // Total data bytes in file 60 length = f->readInt(4); // Total data bytes in file
46 mode = (OplMode)f->readInt(1); // Type of opl data this can contain 61 f->ignore(1); // Type of opl data this can contain - ignored
47 data = new unsigned char [length]; 62 data = new unsigned char [length];
48 for (i=0;i<length;i++) 63 for (i=0;i<length;i++)
49 data[i]=f->readInt(1); 64 data[i]=f->readInt(1);
50 fp.close(f); 65 fp.close(f);
51 rewind(0); 66 rewind(0);
52 return true; 67 return true;
53 } 68 }
54 69
55 bool CdroPlayer::update() 70 bool CdroPlayer::update()
56 { 71 {
57 if (delay>500) { 72 if (delay>500) {
58 delay-=500; 73 delay-=500;
59 return true; 74 return true;
60 } else delay=0; 75 } else
61 while (pos < length) 76 delay=0;
62 { 77
63 unsigned char cmd = data[pos++]; 78 while (pos < length) {
64 switch(cmd) { 79 unsigned char cmd = data[pos++];
65 case 0: 80 switch(cmd) {
66 delay = 1 + data[pos++]; 81 case 0:
67 return true; 82 delay = 1 + data[pos++];
68 case 1: 83 return true;
69 delay = 1 + data[pos] + (data[pos+1]<<8); 84 case 1:
70 pos+=2; 85 delay = 1 + data[pos] + (data[pos+1]<<8);
71 return true; 86 pos+=2;
72 case 2: 87 return true;
73 index = 0; 88 case 2:
74 break; 89 index = 0;
75 case 3: 90 opl->setchip(0);
76 index = 0; 91 break;
77 break; 92 case 3:
78 default: 93 index = 1;
79 if(!index) 94 opl->setchip(1);
80 opl->write(cmd,data[pos++]); 95 break;
81 break; 96 default:
82 } 97 if(cmd==4) cmd = data[pos++]; //data override
83 } 98 if(index == 0 || opl3_mode)
84 return pos<length; 99 opl->write(cmd,data[pos++]);
100 break;
101 }
102 }
103
104 return pos<length;
85 } 105 }
86 106
87 void CdroPlayer::rewind(int subsong) 107 void CdroPlayer::rewind(int subsong)
88 { 108 {
89 delay=1; 109 delay=1;
90 pos = index = 0; 110 pos = index = 0;
91 opl->init(); 111 opl->init();
92 opl->write(1,32); // go to OPL2 mode 112
113 //dro assumes all registers are initialized to 0
114 //registers not initialized to 0 will be corrected
115 //in the data stream
116 for(int i=0;i<256;i++)
117 opl->write(i,0);
118
119 opl->setchip(1);
120 for(int i=0;i<256;i++)
121 opl->write(i,0);
122 opl->setchip(0);
93 } 123 }
94 124
95 float CdroPlayer::getrefresh() 125 float CdroPlayer::getrefresh()
96 { 126 {
97 if (delay > 500) return 1000 / 500; 127 if (delay > 500) return 1000 / 500;
98 else return 1000 / (double)delay; 128 else return 1000 / (double)delay;
99 } 129 }