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 * diskopl.cpp - Disk Writer OPL, by Simon Peter <dn.tlp@gmx.net>
24 //static const unsigned short note_table[12] = {363,385,408,432,458,485,514,544,577,611,647,686};
25 const unsigned char CDiskopl::op_table[9] = {0x00, 0x01, 0x02, 0x08, 0x09, 0x0a, 0x10, 0x11, 0x12};
27 CDiskopl::CDiskopl(std::string filename)
28 : old_freq(0.0f), del(1), nowrite(false)
30 unsigned short clock = 0xffff;
33 f = fopen(filename.c_str(),"wb");
34 fwrite("RAWADATA",8,1,f);
35 fwrite(&clock,sizeof(clock),1,f);
43 void CDiskopl::update(CPlayer *p)
48 if(p->getrefresh() != old_freq) {
49 old_freq = p->getrefresh();
50 del = wait = (unsigned int)(18.2f / old_freq);
51 clock = (unsigned short)(1192737/(old_freq*(wait+1)));
52 fputc(0,f); fputc(2,f);
61 void CDiskopl::setchip(int n)
66 fputc(currChip + 1, f);
71 void CDiskopl::write(int reg, int val)
79 for (int i=0;i<9;i++) { // stop instruments
80 diskwrite(0xb0 + i,0); // key off
81 diskwrite(0x80 + op_table[i],0xff); // fastest release
83 diskwrite(0xbd,0); // clear misc. register
86 void CDiskopl::diskwrite(int reg, int val)