| 1 |
/* Nuked OPL3 |
| 2 |
* Copyright (C) 2013-2020 Nuke.YKT |
| 3 |
* |
| 4 |
* This file is part of Nuked OPL3. |
| 5 |
* |
| 6 |
* Nuked OPL3 is free software: you can redistribute it and/or modify |
| 7 |
* it under the terms of the GNU Lesser General Public License as |
| 8 |
* published by the Free Software Foundation, either version 2.1 |
| 9 |
* of the License, or (at your option) any later version. |
| 10 |
* |
| 11 |
* Nuked OPL3 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 Lesser General Public License for more details. |
| 15 |
* |
| 16 |
* You should have received a copy of the GNU Lesser General Public License |
| 17 |
* along with Nuked OPL3. If not, see <https://www.gnu.org/licenses/>. |
| 18 |
|
| 19 |
* Nuked OPL3 emulator. |
| 20 |
* Thanks: |
| 21 |
* MAME Development Team(Jarek Burczynski, Tatsuyuki Satoh): |
| 22 |
* Feedback and Rhythm part calculation information. |
| 23 |
* forums.submarine.org.uk(carbon14, opl3): |
| 24 |
* Tremolo and phase generator calculation information. |
| 25 |
* OPLx decapsulated(Matthew Gambrell, Olli Niemitalo): |
| 26 |
* OPL2 ROMs. |
| 27 |
* siliconpr0n.org(John McMaster, digshadow): |
| 28 |
* YMF262 and VRC VII decaps and die shots. |
| 29 |
* |
| 30 |
* version: 1.8 |
| 31 |
*/ |
| 32 |
|
| 33 |
#ifndef OPL_OPL3_H |
| 34 |
#define OPL_OPL3_H |
| 35 |
|
| 36 |
#ifdef __cplusplus |
| 37 |
extern "C" { |
| 38 |
#endif |
| 39 |
|
| 40 |
#include <inttypes.h> |
| 41 |
|
| 42 |
#ifndef OPL_ENABLE_STEREOEXT |
| 43 |
#define OPL_ENABLE_STEREOEXT 0 |
| 44 |
#endif |
| 45 |
|
| 46 |
#define OPL_WRITEBUF_SIZE 1024 |
| 47 |
#define OPL_WRITEBUF_DELAY 2 |
| 48 |
|
| 49 |
typedef struct _opl3_slot opl3_slot; |
| 50 |
typedef struct _opl3_channel opl3_channel; |
| 51 |
typedef struct _opl3_chip opl3_chip; |
| 52 |
|
| 53 |
struct _opl3_slot { |
| 54 |
opl3_channel *channel; |
| 55 |
opl3_chip *chip; |
| 56 |
int16_t out; |
| 57 |
int16_t fbmod; |
| 58 |
int16_t *mod; |
| 59 |
int16_t prout; |
| 60 |
uint16_t eg_rout; |
| 61 |
uint16_t eg_out; |
| 62 |
uint8_t eg_inc; |
| 63 |
uint8_t eg_gen; |
| 64 |
uint8_t eg_rate; |
| 65 |
uint8_t eg_ksl; |
| 66 |
uint8_t *trem; |
| 67 |
uint8_t reg_vib; |
| 68 |
uint8_t reg_type; |
| 69 |
uint8_t reg_ksr; |
| 70 |
uint8_t reg_mult; |
| 71 |
uint8_t reg_ksl; |
| 72 |
uint8_t reg_tl; |
| 73 |
uint8_t reg_ar; |
| 74 |
uint8_t reg_dr; |
| 75 |
uint8_t reg_sl; |
| 76 |
uint8_t reg_rr; |
| 77 |
uint8_t reg_wf; |
| 78 |
uint8_t key; |
| 79 |
uint32_t pg_reset; |
| 80 |
uint32_t pg_phase; |
| 81 |
uint16_t pg_phase_out; |
| 82 |
uint8_t slot_num; |
| 83 |
}; |
| 84 |
|
| 85 |
struct _opl3_channel { |
| 86 |
opl3_slot *slots[2]; |
| 87 |
opl3_channel *pair; |
| 88 |
opl3_chip *chip; |
| 89 |
int16_t *out[4]; |
| 90 |
|
| 91 |
#if OPL_ENABLE_STEREOEXT |
| 92 |
int32_t leftpan; |
| 93 |
int32_t rightpan; |
| 94 |
#endif |
| 95 |
|
| 96 |
uint8_t chtype; |
| 97 |
uint16_t f_num; |
| 98 |
uint8_t block; |
| 99 |
uint8_t fb; |
| 100 |
uint8_t con; |
| 101 |
uint8_t alg; |
| 102 |
uint8_t ksv; |
| 103 |
uint16_t cha, chb; |
| 104 |
uint16_t chc, chd; |
| 105 |
uint8_t ch_num; |
| 106 |
uint8_t muted; |
| 107 |
}; |
| 108 |
|
| 109 |
typedef struct _opl3_writebuf { |
| 110 |
uint64_t time; |
| 111 |
uint16_t reg; |
| 112 |
uint8_t data; |
| 113 |
} opl3_writebuf; |
| 114 |
|
| 115 |
struct _opl3_chip { |
| 116 |
opl3_channel channel[18]; |
| 117 |
opl3_slot slot[36]; |
| 118 |
uint16_t timer; |
| 119 |
uint64_t eg_timer; |
| 120 |
uint8_t eg_timerrem; |
| 121 |
uint8_t eg_state; |
| 122 |
uint8_t eg_add; |
| 123 |
uint8_t newm; |
| 124 |
uint8_t nts; |
| 125 |
uint8_t rhy; |
| 126 |
uint8_t vibpos; |
| 127 |
uint8_t vibshift; |
| 128 |
uint8_t tremolo; |
| 129 |
uint8_t tremolopos; |
| 130 |
uint8_t tremoloshift; |
| 131 |
uint32_t noise; |
| 132 |
int16_t zeromod; |
| 133 |
int32_t mixbuff[4]; |
| 134 |
uint8_t rm_hh_bit2; |
| 135 |
uint8_t rm_hh_bit3; |
| 136 |
uint8_t rm_hh_bit7; |
| 137 |
uint8_t rm_hh_bit8; |
| 138 |
uint8_t rm_tc_bit3; |
| 139 |
uint8_t rm_tc_bit5; |
| 140 |
|
| 141 |
#if OPL_ENABLE_STEREOEXT |
| 142 |
uint8_t stereoext; |
| 143 |
#endif |
| 144 |
|
| 145 |
/* OPL3L */ |
| 146 |
int32_t rateratio; |
| 147 |
int32_t samplecnt; |
| 148 |
int16_t oldsamples[4]; |
| 149 |
int16_t samples[4]; |
| 150 |
|
| 151 |
uint64_t writebuf_samplecnt; |
| 152 |
uint32_t writebuf_cur; |
| 153 |
uint32_t writebuf_last; |
| 154 |
uint64_t writebuf_lasttime; |
| 155 |
opl3_writebuf writebuf[OPL_WRITEBUF_SIZE]; |
| 156 |
}; |
| 157 |
|
| 158 |
void OPL3_Generate(opl3_chip *chip, int16_t *buf); |
| 159 |
void OPL3_GenerateResampled(opl3_chip *chip, int16_t *buf); |
| 160 |
void OPL3_Reset(opl3_chip *chip, uint32_t samplerate); |
| 161 |
void OPL3_Resample(opl3_chip *chip, uint32_t samplerate); |
| 162 |
void OPL3_WriteReg(opl3_chip *chip, uint16_t reg, uint8_t v); |
| 163 |
void OPL3_WriteRegBuffered(opl3_chip *chip, uint16_t reg, uint8_t v); |
| 164 |
void OPL3_GenerateStream(opl3_chip *chip, int16_t *sndptr, uint32_t numsamples); |
| 165 |
|
| 166 |
void OPL3_Generate4Ch(opl3_chip *chip, int16_t *buf4); |
| 167 |
void OPL3_Generate4ChResampled(opl3_chip *chip, int16_t *buf4); |
| 168 |
void OPL3_Generate4ChStream(opl3_chip *chip, int16_t *sndptr1, int16_t *sndptr2, uint32_t numsamples); |
| 169 |
|
| 170 |
#ifdef __cplusplus |
| 171 |
} |
| 172 |
#endif |
| 173 |
|
| 174 |
#endif |