annotate Plugins/Input/adplug/core/realopl.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 0a73d1faeb4e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
359
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
1 /*
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
2 * Adplug - Replayer for many OPL2/OPL3 audio file formats.
428
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
3 * Copyright (C) 1999 - 2005 Simon Peter, <dn.tlp@gmx.net>, et al.
359
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
4 *
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
5 * This library is free software; you can redistribute it and/or
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
6 * modify it under the terms of the GNU Lesser General Public
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
7 * License as published by the Free Software Foundation; either
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
8 * version 2.1 of the License, or (at your option) any later version.
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
9 *
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
10 * This library is distributed in the hope that it will be useful,
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
13 * Lesser General Public License for more details.
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
14 *
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
16 * License along with this library; if not, write to the Free Software
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
18 *
428
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
19 * realopl.cpp - Real hardware OPL, by Simon Peter <dn.tlp@gmx.net>
359
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
20 */
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
21
428
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
22 #ifdef _MSC_VER // Microsoft Visual C++
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
23 # include <conio.h>
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
24 # define INP _inp
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
25 # define OUTP _outp
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
26 #elif defined(__WATCOMC__) // Watcom C/C++ and OpenWatcom
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
27 # include <conio.h>
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
28 # define INP inp
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
29 # define OUTP outp
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
30 #elif defined(WIN32) && defined(__MSVCRT__) && defined(__MINGW32__)
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
31 /*
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
32 int __cdecl _inp(unsigned short);
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
33 int __cdecl _outp(unsigned short, int);
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
34 # define INP _inp
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
35 # define OUTP _outp
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
36 */
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
37 # define INP inb
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
38 # define OUTP(reg, val) outb(val, reg)
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
39 #else // no support on other platforms
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
40 # define INP(reg) 0
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
41 # define OUTP(reg, val)
359
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
42 #endif
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
43
428
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
44 #include "realopl.h"
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
45
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
46 #define SHORTDELAY 6 // short delay in I/O port-reads after OPL hardware output
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
47 #define LONGDELAY 35 // long delay in I/O port-reads after OPL hardware output
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
48
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
49 const unsigned char CRealopl::op_table[9] =
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
50 {0x00, 0x01, 0x02, 0x08, 0x09, 0x0a, 0x10, 0x11, 0x12};
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
51
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
52 #if defined(WIN32) && defined(__MINGW32__)
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
53 static __inline unsigned char
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
54 inb (unsigned short int port)
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
55 {
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
56 unsigned char _v;
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
57
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
58 __asm__ __volatile__ ("inb %w1,%0":"=a" (_v):"Nd" (port));
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
59 return _v;
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
60 }
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
61
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
62 static __inline void
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
63 outb (unsigned char value, unsigned short int port)
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
64 {
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
65 __asm__ __volatile__ ("outb %b0,%w1": :"a" (value), "Nd" (port));
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
66 }
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
67 #endif
359
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
68
428
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
69 CRealopl::CRealopl(unsigned short initport)
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
70 : adlport(initport), hardvol(0), bequiet(false), nowrite(false)
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
71 {
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
72 for(int i=0;i<22;i++) {
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
73 hardvols[0][i][0] = 0;
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
74 hardvols[0][i][1] = 0;
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
75 hardvols[1][i][0] = 0;
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
76 hardvols[1][i][1] = 0;
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
77 }
359
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
78
428
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
79 currType = TYPE_OPL3;
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
80 }
359
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
81
428
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
82 bool CRealopl::harddetect()
359
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
83 {
428
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
84 unsigned char stat1, stat2, i;
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
85 unsigned short adp = (currChip == 0 ? adlport : adlport + 2);
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
86
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
87 hardwrite(4,0x60); hardwrite(4,0x80);
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
88 stat1 = INP(adp);
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
89 hardwrite(2,0xff); hardwrite(4,0x21);
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
90 for(i=0;i<80;i++) // wait for adlib
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
91 INP(adp);
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
92 stat2 = INP(adp);
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
93 hardwrite(4,0x60); hardwrite(4,0x80);
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
94
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
95 if(((stat1 & 0xe0) == 0) && ((stat2 & 0xe0) == 0xc0))
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
96 return true;
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
97 else
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
98 return false;
359
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
99 }
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
100
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
101 bool CRealopl::detect()
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
102 {
428
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
103 unsigned char stat;
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
104
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
105 setchip(0);
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
106 if(harddetect()) {
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
107 // is at least OPL2, check for OPL3
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
108 currType = TYPE_OPL2;
359
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
109
428
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
110 stat = INP(adlport);
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
111 if(stat & 6) {
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
112 // not OPL3, try dual-OPL2
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
113 setchip(1);
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
114 if(harddetect())
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
115 currType = TYPE_DUAL_OPL2;
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
116 } else
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
117 currType = TYPE_OPL3;
359
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
118
428
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
119 setchip(0);
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
120 return true;
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
121 } else
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
122 return false;
359
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
123 }
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
124
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
125 void CRealopl::setvolume(int volume)
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
126 {
428
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
127 int i, j;
359
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
128
428
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
129 hardvol = volume;
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
130 for(j = 0; j < 2; j++)
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
131 for(i = 0; i < 9; i++) {
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
132 hardwrite(0x43+op_table[i],((hardvols[j][op_table[i]+3][0] & 63) + volume) > 63 ? 63 : hardvols[j][op_table[i]+3][0] + volume);
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
133 if(hardvols[j][i][1] & 1) // modulator too?
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
134 hardwrite(0x40+op_table[i],((hardvols[j][op_table[i]][0] & 63) + volume) > 63 ? 63 : hardvols[j][op_table[i]][0] + volume);
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
135 }
359
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
136 }
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
137
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
138 void CRealopl::setquiet(bool quiet)
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
139 {
428
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
140 bequiet = quiet;
359
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
141
428
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
142 if(quiet) {
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
143 oldvol = hardvol;
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
144 setvolume(63);
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
145 } else
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
146 setvolume(oldvol);
359
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
147 }
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
148
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
149 void CRealopl::hardwrite(int reg, int val)
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
150 {
428
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
151 int i;
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
152 unsigned short adp = (currChip == 0 ? adlport : adlport + 2);
359
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
153
428
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
154 OUTP(adp,reg); // set register
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
155 for(i=0;i<SHORTDELAY;i++) // wait for adlib
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
156 INP(adp);
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
157 OUTP(adp+1,val); // set value
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
158 for(i=0;i<LONGDELAY;i++) // wait for adlib
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
159 INP(adp);
359
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
160 }
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
161
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
162 void CRealopl::write(int reg, int val)
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
163 {
428
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
164 int i;
359
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
165
428
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
166 if(nowrite)
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
167 return;
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
168
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
169 if(currType == TYPE_OPL2 && currChip > 0)
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
170 return;
359
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
171
428
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
172 if(bequiet && (reg >= 0xb0 && reg <= 0xb8)) // filter all key-on commands
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
173 val &= ~32;
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
174 if(reg >= 0x40 && reg <= 0x55) // cache volumes
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
175 hardvols[currChip][reg-0x40][0] = val;
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
176 if(reg >= 0xc0 && reg <= 0xc8)
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
177 hardvols[currChip][reg-0xc0][1] = val;
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
178 if(hardvol) // reduce volume
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
179 for(i=0;i<9;i++) {
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
180 if(reg == 0x43 + op_table[i])
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
181 val = ((val & 63) + hardvol) > 63 ? 63 : val + hardvol;
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
182 else
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
183 if((reg == 0x40 + op_table[i]) && (hardvols[currChip][i][1] & 1))
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
184 val = ((val & 63) + hardvol) > 63 ? 63 : val + hardvol;
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
185 }
359
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
186
428
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
187 hardwrite(reg,val);
359
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
188 }
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
189
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
190 void CRealopl::init()
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
191 {
428
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
192 int i, j;
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
193
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
194 for(j = 0; j < 2; j++) {
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
195 setchip(j);
359
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
196
428
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
197 for(i=0;i<9;i++) { // stop instruments
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
198 hardwrite(0xb0 + i,0); // key off
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
199 hardwrite(0x80 + op_table[i],0xff); // fastest release
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
200 }
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
201
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
202 hardwrite(0xbd,0); // clear misc. register
15ca2ea93a30 [svn] Sync with upstream CVS. This implements RIX playback.
chainsaw
parents: 359
diff changeset
203 }
359
8df427a314a8 [svn] Adlib synthesizer (AdPlug) support.
chainsaw
parents:
diff changeset
204 }