1 /* Project 16 Source Code~
2 * Copyright (C) 2012-2015 sparky4 & pngwen & andrius4669
4 * This file is part of Project 16.
6 * Project 16 is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * Project 16 is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>, or
19 * write to the Free Software Foundation, Inc., 51 Franklin Street,
20 * Fifth Floor, Boston, MA 02110-1301 USA.
24 #include "src/lib/16_snd.h"
26 void opl2out(word reg, word data)
31 mov dx,word ptr [ADLIB_FM_ADDRESS]
\r
49 void opl3out(word reg, word data)
54 mov dx,word ptr [ADLIB_FM_ADDRESS]
\r
69 void opl3exp(word data)
74 mov dx,word ptr [ADLIB_FM_ADDRESS]
\r
89 /* Function: FMResest *******************************************************
\r
91 * Description: quick and dirty sound card reset (zeros all
\r
95 void FMReset(void/*int percusiveMode*/)
99 /* zero all registers */
\r
100 for(i = MIN_REGISTER; i < MAX_REGISTER+1; i++) opl2out(i, 0);
\r
102 /* allow FM chips to control the waveform of each operator */
\r
103 opl2out(0x01, 0x20);
\r
105 /* set rhythm enabled (6 melodic voices, 5 percussive) */
\r
106 opl2out(0xBD, 0x20);
\r
108 //FMSetPercusiveMode(percusiveMode);
\r
109 } /* End of FMReset */
111 /* Function: FMKeyOff *******************************************************
\r
113 * Parameters: voice - which voice to turn off.
\r
115 * Description: turns off the specified voice.
\r
118 void FMKeyOff(int voice)
122 /* turn voice off */
\r
123 regNum = 0xB0 + voice % 11;//NUMVOICE;
\r
124 opl2out(regNum, 0x0E);
\r
125 } /* End of FMKeyOff */
\r
127 /* Function: FMKeyOn *******************************************************
\r
129 * Parameters: voice - which voice to turn on.
\r
130 * freq - its frequency (note).
\r
131 * octave - its octave.
\r
133 * Description: turns on a voice of specfied frequency and
\r
137 void FMKeyOn(int voice, int freq, int octave)
141 regNum = 0xA0 + voice % 11;//NUMVOICE;
\r
142 opl2out(regNum, freq & 0xff);
\r
143 regNum = 0xB0 + voice % 11;//NUMVOICE;
\r
144 tmp = (freq >> 8) | (octave << 2) | 0x20;
145 opl2out(regNum, tmp);
\r
146 } /* End of FMKeyOn */
148 /* Function: FMSetVoice *****************************************************
\r
150 * Parameters: voiceNum - which voice to set.
\r
151 * ins - instrument to set voice.
\r
153 * Description: sets the instrument of a voice.
\r
156 void FMSetVoice(int voiceNum, FMInstrument *ins){
\r
157 int opCellNum, cellOffset;
\r
159 voiceNum %= 11;//NUMVOICE;
\r
160 cellOffset = voiceNum % 3 + ((voiceNum / 3) << 3);
\r
162 /* set sound characteristic */
\r
163 opCellNum = 0x20 + (char)cellOffset;
\r
164 opl2out(opCellNum, ins->SoundCharacteristic[0]);
\r
166 opl2out(opCellNum, ins->SoundCharacteristic[1]);
\r
168 /* set level/output */
\r
169 opCellNum = 0x40 + (char)cellOffset;
\r
170 opl2out(opCellNum, ins->Level[0]);
\r
172 opl2out(opCellNum, ins->Level[1]);
\r
174 /* set Attack/Decay */
\r
175 opCellNum = 0x60 + (char)cellOffset;
\r
176 opl2out(opCellNum, ins->AttackDecay[0]);
\r
178 opl2out(opCellNum, ins->AttackDecay[1]);
\r
180 /* set Sustain/Release */
\r
181 opCellNum = 0x80 + (char)cellOffset;
\r
182 opl2out(opCellNum, ins->SustainRelease[0]);
\r
184 opl2out(opCellNum, ins->SustainRelease[1]);
\r
186 /* set Wave Select */
\r
187 opCellNum = 0xE0 + (char)cellOffset;
\r
188 opl2out(opCellNum, ins->WaveSelect[0]);
\r
190 opl2out(opCellNum, ins->WaveSelect[1]);
\r
192 /* set Feedback/Selectivity */
\r
193 opCellNum = (byte)0xC0 + (byte)voiceNum;
\r
194 opl2out(opCellNum, ins->Feedback);
\r
195 } /* End of FMSetVoice */