1 /* 2 * opl3.h - Definitions of the OPL-3 registers 3 * 4 * Copyright by Hannu Savolainen 1993 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 * 27 */ 28 29 /* 30 * The OPL-3 mode is switched on by writing 0x01, to the offset 5 31 * of the right side. 32 * 33 * Another special register at the right side is at offset 4. It contains 34 * a bit mask defining which voices are used as 4 OP voices. 35 * 36 * The percussive mode is implemented in the left side only. 37 * 38 * With the above exceptions the both sides can be operated independently. 39 * 40 * A 4 OP voice can be created by setting the corresponding 41 * bit at offset 4 of the right side. 42 * 43 * For example setting the rightmost bit (0x01) changes the 44 * first voice on the right side to the 4 OP mode. The fourth 45 * voice is made inaccessible. 46 * 47 * If a voice is set to the 2 OP mode, it works like 2 OP modes 48 * of the original YM3812 (AdLib). In addition the voice can 49 * be connected the left, right or both stereo channels. It can 50 * even be left unconnected. This works with 4 OP voices also. 51 * 52 * The stereo connection bits are located in the FEEDBACK_CONNECTION 53 * register of the voice (0xC0-0xC8). In 4 OP voices these bits are 54 * in the second half of the voice. 55 */ 56 57 /* 58 * Register numbers for the global registers 59 */ 60 61 #define TEST_REGISTER 0x01 62 #define ENABLE_WAVE_SELECT 0x20 63 64 #define TIMER1_REGISTER 0x02 65 #define TIMER2_REGISTER 0x03 66 #define TIMER_CONTROL_REGISTER 0x04 /* Left side */ 67 #define IRQ_RESET 0x80 68 #define TIMER1_MASK 0x40 69 #define TIMER2_MASK 0x20 70 #define TIMER1_START 0x01 71 #define TIMER2_START 0x02 72 73 #define CONNECTION_SELECT_REGISTER 0x04 /* Right side */ 74 #define RIGHT_4OP_0 0x01 75 #define RIGHT_4OP_1 0x02 76 #define RIGHT_4OP_2 0x04 77 #define LEFT_4OP_0 0x08 78 #define LEFT_4OP_1 0x10 79 #define LEFT_4OP_2 0x20 80 81 #define OPL3_MODE_REGISTER 0x05 /* Right side */ 82 #define OPL3_ENABLE 0x01 83 84 #define KBD_SPLIT_REGISTER 0x08 /* Left side */ 85 #define COMPOSITE_SINE_WAVE_MODE 0x80 /* Don't use with OPL-3? */ 86 #define KEYBOARD_SPLIT 0x40 87 88 #define PERCUSSION_REGISTER 0xbd /* Left side only */ 89 #define TREMOLO_DEPTH 0x80 90 #define VIBRATO_DEPTH 0x40 91 #define PERCUSSION_ENABLE 0x20 92 #define BASSDRUM_ON 0x10 93 #define SNAREDRUM_ON 0x08 94 #define TOMTOM_ON 0x04 95 #define CYMBAL_ON 0x02 96 #define HIHAT_ON 0x01 97 98 /* 99 * Offsets to the register banks for operators. To get the 100 * register number just add the operator offset to the bank offset 101 * 102 * AM/VIB/EG/KSR/Multiple (0x20 to 0x35) 103 */ 104 #define AM_VIB 0x20 105 #define TREMOLO_ON 0x80 106 #define VIBRATO_ON 0x40 107 #define SUSTAIN_ON 0x20 108 #define KSR 0x10 /* Key scaling rate */ 109 #define MULTIPLE_MASK 0x0f /* Frequency multiplier */ 110 111 /* 112 * KSL/Total level (0x40 to 0x55) 113 */ 114 #define KSL_LEVEL 0x40 115 #define KSL_MASK 0xc0 /* Envelope scaling bits */ 116 #define TOTAL_LEVEL_MASK 0x3f /* Strength (volume) of OP */ 117 118 /* 119 * Attack / Decay rate (0x60 to 0x75) 120 */ 121 #define ATTACK_DECAY 0x60 122 #define ATTACK_MASK 0xf0 123 #define DECAY_MASK 0x0f 124 125 /* 126 * Sustain level / Release rate (0x80 to 0x95) 127 */ 128 #define SUSTAIN_RELEASE 0x80 129 #define SUSTAIN_MASK 0xf0 130 #define RELEASE_MASK 0x0f 131 132 /* 133 * Wave select (0xE0 to 0xF5) 134 */ 135 #define WAVE_SELECT 0xe0 136 137 /* 138 * Offsets to the register banks for voices. Just add to the 139 * voice number to get the register number. 140 * 141 * F-Number low bits (0xA0 to 0xA8). 142 */ 143 #define FNUM_LOW 0xa0 144 145 /* 146 * F-number high bits / Key on / Block (octave) (0xB0 to 0xB8) 147 */ 148 #define KEYON_BLOCK 0xb0 149 #define KEYON_BIT 0x20 150 #define BLOCKNUM_MASK 0x1c 151 #define FNUM_HIGH_MASK 0x03 152 153 /* 154 * Feedback / Connection (0xc0 to 0xc8) 155 * 156 * These registers have two new bits when the OPL-3 mode 157 * is selected. These bits controls connecting the voice 158 * to the stereo channels. For 4 OP voices this bit is 159 * defined in the second half of the voice (add 3 to the 160 * register offset). 161 * 162 * For 4 OP voices the connection bit is used in the 163 * both halfs (gives 4 ways to connect the operators). 164 */ 165 #define FEEDBACK_CONNECTION 0xc0 166 #define FEEDBACK_MASK 0x0e /* Valid just for 1st OP of a voice */ 167 #define CONNECTION_BIT 0x01 168 /* 169 * In the 4 OP mode there is four possible configurations how the 170 * operators can be connected together (in 2 OP modes there is just 171 * AM or FM). The 4 OP connection mode is defined by the rightmost 172 * bit of the FEEDBACK_CONNECTION (0xC0-0xC8) on the both halfs. 173 * 174 * First half Second half Mode 175 * 176 * +---+ 177 * v | 178 * 0 0 >+-1-+--2--3--4--> 179 * 180 * 181 * 182 * +---+ 183 * | | 184 * 0 1 >+-1-+--2-+ 185 * |-> 186 * >--3----4-+ 187 * 188 * +---+ 189 * | | 190 * 1 0 >+-1-+-----+ 191 * |-> 192 * >--2--3--4-+ 193 * 194 * +---+ 195 * | | 196 * 1 1 >+-1-+--+ 197 * | 198 * >--2--3-+-> 199 * | 200 * >--4----+ 201 */ 202 #define STEREO_BITS 0x30 /* OPL-3 only */ 203 #define VOICE_TO_LEFT 0x10 204 #define VOICE_TO_RIGHT 0x20 205 206 /* 207 * Definition table for the physical voices 208 */ 209 210 struct physical_voice_info { 211 unsigned char voice_num; 212 unsigned char voice_mode; /* 0=unavailable, 2=2 OP, 4=4 OP */ 213 unsigned short ioaddr; /* I/O port (left or right side) */ 214 unsigned char op[4]; /* Operator offsets */ 215 }; 216 217 /* 218 * There is 18 possible 2 OP voices 219 * (9 in the left and 9 in the right). 220 * The first OP is the modulator and 2nd is the carrier. 221 * 222 * The first three voices in the both sides may be connected 223 * with another voice to a 4 OP voice. For example voice 0 224 * can be connected with voice 3. The operators of voice 3 are 225 * used as operators 3 and 4 of the new 4 OP voice. 226 * In this case the 2 OP voice number 0 is the 'first half' and 227 * voice 3 is the second. 228 */ 229 230 #define USE_LEFT 0 231 #define USE_RIGHT 1 232 233 static struct physical_voice_info physical_voices[18] = 234 { 235 /* No Mode Side OP1 OP2 OP3 OP4 */ 236 /* --------------------------------------------------- */ 237 { 0, 2, USE_LEFT, {0x00, 0x03, 0x08, 0x0b}}, 238 { 1, 2, USE_LEFT, {0x01, 0x04, 0x09, 0x0c}}, 239 { 2, 2, USE_LEFT, {0x02, 0x05, 0x0a, 0x0d}}, 240 241 { 3, 2, USE_LEFT, {0x08, 0x0b, 0x00, 0x00}}, 242 { 4, 2, USE_LEFT, {0x09, 0x0c, 0x00, 0x00}}, 243 { 5, 2, USE_LEFT, {0x0a, 0x0d, 0x00, 0x00}}, 244 245 { 6, 2, USE_LEFT, {0x10, 0x13, 0x00, 0x00}}, /* Used by percussive voices */ 246 { 7, 2, USE_LEFT, {0x11, 0x14, 0x00, 0x00}}, /* if the percussive mode */ 247 { 8, 2, USE_LEFT, {0x12, 0x15, 0x00, 0x00}}, /* is selected */ 248 249 { 0, 2, USE_RIGHT, {0x00, 0x03, 0x08, 0x0b}}, 250 { 1, 2, USE_RIGHT, {0x01, 0x04, 0x09, 0x0c}}, 251 { 2, 2, USE_RIGHT, {0x02, 0x05, 0x0a, 0x0d}}, 252 253 { 3, 2, USE_RIGHT, {0x08, 0x0b, 0x00, 0x00}}, 254 { 4, 2, USE_RIGHT, {0x09, 0x0c, 0x00, 0x00}}, 255 { 5, 2, USE_RIGHT, {0x0a, 0x0d, 0x00, 0x00}}, 256 257 { 6, 2, USE_RIGHT, {0x10, 0x13, 0x00, 0x00}}, 258 { 7, 2, USE_RIGHT, {0x11, 0x14, 0x00, 0x00}}, 259 { 8, 2, USE_RIGHT, {0x12, 0x15, 0x00, 0x00}} 260 };