comparison src/adplug/core/diskopl.cxx @ 12:3da1b8942b8b trunk

[svn] - remove src/Input src/Output src/Effect src/General src/Visualization src/Container
author nenolod
date Mon, 18 Sep 2006 03:14:20 -0700
parents src/Input/adplug/core/diskopl.cxx@13389e613d67
children 4709ce4e209e
comparison
equal deleted inserted replaced
11:cff1d04026ae 12:3da1b8942b8b
1 /*
2 * Adplug - Replayer for many OPL2/OPL3 audio file formats.
3 * Copyright (C) 1999 - 2005 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 *
19 * diskopl.cpp - Disk Writer OPL, by Simon Peter <dn.tlp@gmx.net>
20 */
21
22 #include "diskopl.h"
23
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};
26
27 CDiskopl::CDiskopl(std::string filename)
28 : old_freq(0.0f), del(1), nowrite(false)
29 {
30 unsigned short clock = 0xffff;
31
32 currType = TYPE_OPL3;
33 f = fopen(filename.c_str(),"wb");
34 fwrite("RAWADATA",8,1,f);
35 fwrite(&clock,sizeof(clock),1,f);
36 }
37
38 CDiskopl::~CDiskopl()
39 {
40 fclose(f);
41 }
42
43 void CDiskopl::update(CPlayer *p)
44 {
45 unsigned short clock;
46 unsigned int wait;
47
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);
53 fwrite(&clock,2,1,f);
54 }
55 if(!nowrite) {
56 fputc(del+1,f);
57 fputc(0,f);
58 }
59 }
60
61 void CDiskopl::setchip(int n)
62 {
63 Copl::setchip(n);
64
65 if(!nowrite) {
66 fputc(currChip + 1, f);
67 fputc(2, f);
68 }
69 }
70
71 void CDiskopl::write(int reg, int val)
72 {
73 if(!nowrite)
74 diskwrite(reg,val);
75 }
76
77 void CDiskopl::init()
78 {
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
82 }
83 diskwrite(0xbd,0); // clear misc. register
84 }
85
86 void CDiskopl::diskwrite(int reg, int val)
87 {
88 fputc(val,f);
89 fputc(reg,f);
90 }