1 /* 2 * opl3.h - Definitions of the OPL-3 registers 3 */ 4 /* 5 * Copyright by Hannu Savolainen 1993-1996 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions are 9 * met: 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 2. 11 * Redistributions in binary form must reproduce the above copyright notice, 12 * this list of conditions and the following disclaimer in the documentation 13 * and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY 16 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 19 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 * 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 * The OPL-3 mode is switched on by writing 0x01, to the offset 5 30 * of the right side. 31 * 32 * Another special register at the right side is at offset 4. It contains 33 * a bit mask defining which voices are used as 4 OP voices. 34 * 35 * The percussive mode is implemented in the left side only. 36 * 37 * With the above exeptions the both sides can be operated independently. 38 * 39 * A 4 OP voice can be created by setting the corresponding 40 * bit at offset 4 of the right side. 41 * 42 * For example setting the rightmost bit (0x01) changes the 43 * first voice on the right side to the 4 OP mode. The fourth 44 * voice is made inaccessible. 45 * 46 * If a voice is set to the 2 OP mode, it works like 2 OP modes 47 * of the original YM3812 (AdLib). In addition the voice can 48 * be connected the left, right or both stereo channels. It can 49 * even be left unconnected. This works with 4 OP voices also. 50 * 51 * The stereo connection bits are located in the FEEDBACK_CONNECTION 52 * register of the voice (0xC0-0xC8). In 4 OP voices these bits are 53 * in the second half of the voice. 54 */ 55 56 /* 57 * Register numbers for the global registers 58 */ 59 60 #define TEST_REGISTER 0x01 61 #define ENABLE_WAVE_SELECT 0x20 62 63 #define TIMER1_REGISTER 0x02 64 #define TIMER2_REGISTER 0x03 65 #define TIMER_CONTROL_REGISTER 0x04 /* Left side */ 66 #define IRQ_RESET 0x80 67 #define TIMER1_MASK 0x40 68 #define TIMER2_MASK 0x20 69 #define TIMER1_START 0x01 70 #define TIMER2_START 0x02 71 72 #define CONNECTION_SELECT_REGISTER 0x04 /* Right side */ 73 #define RIGHT_4OP_0 0x01 74 #define RIGHT_4OP_1 0x02 75 #define RIGHT_4OP_2 0x04 76 #define LEFT_4OP_0 0x08 77 #define LEFT_4OP_1 0x10 78 #define LEFT_4OP_2 0x20 79 80 #define OPL3_MODE_REGISTER 0x05 /* Right side */ 81 #define OPL3_ENABLE 0x01 82 #define OPL4_ENABLE 0x02 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 pv_map[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 };