Debian Codegraph @

BambooTracker/chip/nuked/ym3438.h

raw
1 /*
2 * Copyright (C) 2017-2018 Alexey Khokholov (Nuke.YKT)
3 * Copyright (C) 2019 Jean Pierre Cimalando
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 *
19 *
20 * Nuked OPN2-MOD emulator, with OPNA functionality added.
21 * Thanks:
22 * Silicon Pr0n:
23 * Yamaha YM3438 decap and die shot(digshadow).
24 * OPLx decapsulated(Matthew Gambrell, Olli Niemitalo):
25 * OPL2 ROMs.
26 *
27 * version: 1.0.9
28 *
29 * OPN-MOD additions:
30 * - Jean Pierre Cimalando 2019-04-06: add SSG control interface
31 * - Jean Pierre Cimalando 2019-04-06: add 6-channel FM flag
32 * - Jean Pierre Cimalando 2019-04-06: add ADPCM rhythm channels
33 * - Jean Pierre Cimalando 2019-04-07: raise the channel clipping threshold
34 */
35
36 #ifndef YM3438_H
37 #define YM3438_H
38
39 #include "../chip_defs.h"
40 #include "../mame/ymdeltat.h"
41
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45
46 /*EXTRA*/
47 #define RSM_FRAC 10
48 #define OPN_WRITEBUF_SIZE 2048
49 #define OPN_WRITEBUF_DELAY 15
50
51 enum {
52 ym3438_mode_ym2612 = 0x01, /* Enables YM2612 emulation (MD1, MD2 VA2) */
53 ym3438_mode_readmode = 0x02 /* Enables status read on any port (TeraDrive, MD1 VA7, MD2, etc) */
54 };
55
56 #include <stdint.h>
57
58 typedef uintptr_t Bitu;
59 typedef intptr_t Bits;
60 typedef uint64_t Bit64u;
61 typedef int64_t Bit64s;
62 typedef uint32_t Bit32u;
63 typedef int32_t Bit32s;
64 typedef uint16_t Bit16u;
65 typedef int16_t Bit16s;
66 typedef uint8_t Bit8u;
67 typedef int8_t Bit8s;
68
69 /*EXTRA*/
70 typedef struct _opn2_writebuf {
71 Bit64u time;
72 Bit8u port;
73 Bit8u data;
74 Bit8u reserved[6];
75 } opn2_writebuf;
76
77 typedef struct
78 {
79 Bit32u cycles;
80 Bit32u channel;
81 Bit16s mol, mor;
82 /*OPN-MOD: Rhythm channel outputs*/
83 Bit16s rhythml[6];
84 Bit16s rhythmr[6];
85 /*OPN-MOD: DeltaT channel outputs*/
86 Bit16s deltaTl[6];
87 Bit16s deltaTr[6];
88 /* IO */
89 Bit16u write_data;
90 Bit8u write_a;
91 Bit8u write_d;
92 Bit8u write_a_en;
93 Bit8u write_d_en;
94 Bit8u write_busy;
95 Bit8u write_busy_cnt;
96 Bit8u write_fm_address;
97 Bit8u write_fm_data;
98 Bit8u write_fm_mode_a;
99 Bit16u address;
100 Bit8u data;
101 Bit8u pin_test_in;
102 Bit8u pin_irq;
103 Bit8u busy;
104 /* LFO */
105 Bit8u lfo_en;
106 Bit8u lfo_freq;
107 Bit8u lfo_pm;
108 Bit8u lfo_am;
109 Bit8u lfo_cnt;
110 Bit8u lfo_inc;
111 Bit8u lfo_quotient;
112 /* Phase generator */
113 Bit16u pg_fnum;
114 Bit8u pg_block;
115 Bit8u pg_kcode;
116 Bit32u pg_inc[24];
117 Bit32u pg_phase[24];
118 Bit8u pg_reset[24];
119 Bit32u pg_read;
120 /* Envelope generator */
121 Bit8u eg_cycle;
122 Bit8u eg_cycle_stop;
123 Bit8u eg_shift;
124 Bit8u eg_shift_lock;
125 Bit8u eg_timer_low_lock;
126 Bit16u eg_timer;
127 Bit8u eg_timer_inc;
128 Bit16u eg_quotient;
129 Bit8u eg_custom_timer;
130 Bit8u eg_rate;
131 Bit8u eg_ksv;
132 Bit8u eg_inc;
133 Bit8u eg_ratemax;
134 Bit8u eg_sl[2];
135 Bit8u eg_lfo_am;
136 Bit8u eg_tl[2];
137 Bit8u eg_state[24];
138 Bit16u eg_level[24];
139 Bit16u eg_out[24];
140 Bit8u eg_kon[24];
141 Bit8u eg_kon_csm[24];
142 Bit8u eg_kon_latch[24];
143 Bit8u eg_csm_mode[24];
144 Bit8u eg_ssg_enable[24];
145 Bit8u eg_ssg_pgrst_latch[24];
146 Bit8u eg_ssg_repeat_latch[24];
147 Bit8u eg_ssg_hold_up_latch[24];
148 Bit8u eg_ssg_dir[24];
149 Bit8u eg_ssg_inv[24];
150 Bit32u eg_read[2];
151 Bit8u eg_read_inc;
152 /* FM */
153 Bit16s fm_op1[6][2];
154 Bit16s fm_op2[6];
155 Bit16s fm_out[24];
156 Bit16u fm_mod[24];
157 /* Channel */
158 Bit16s ch_acc[6];
159 Bit16s ch_out[6];
160 Bit16s ch_lock;
161 Bit8u ch_lock_l;
162 Bit8u ch_lock_r;
163 Bit16s ch_read;
164 /*OPNA: Rhythm channel*/
165 Bit8u rhythm_tl;
166 Bit8u rhythm_key[6];
167 Bit8u rhythm_pan[6];
168 Bit8u rhythm_level[6];
169 Bit16u rhythm_addr[6];
170 Bit8u rhythm_data[6];
171 Bit32u rhythm_step[6];
172 Bit32u rhythm_now_step[6];
173 Bit32s rhythm_adpcm_step[6];
174 Bit32s rhythm_adpcm_acc[6];
175 Bit8s rhythm_vol_mul[6];
176 Bit8u rhythm_vol_shift[6];
177 /* Timer */
178 Bit16u timer_a_cnt;
179 Bit16u timer_a_reg;
180 Bit8u timer_a_load_lock;
181 Bit8u timer_a_load;
182 Bit8u timer_a_enable;
183 Bit8u timer_a_reset;
184 Bit8u timer_a_load_latch;
185 Bit8u timer_a_overflow_flag;
186 Bit8u timer_a_overflow;
187
188 Bit16u timer_b_cnt;
189 Bit8u timer_b_subcnt;
190 Bit16u timer_b_reg;
191 Bit8u timer_b_load_lock;
192 Bit8u timer_b_load;
193 Bit8u timer_b_enable;
194 Bit8u timer_b_reset;
195 Bit8u timer_b_load_latch;
196 Bit8u timer_b_overflow_flag;
197 Bit8u timer_b_overflow;
198
199 /* Register set */
200 Bit8u mode_test_21[8];
201 Bit8u mode_test_2c[8];
202 Bit8u mode_ch3;
203 Bit8u mode_kon_channel;
204 Bit8u mode_kon_operator[4];
205 Bit8u mode_kon[24];
206 Bit8u mode_csm;
207 Bit8u mode_kon_csm;
208 Bit8u dacen;
209 Bit16s dacdata;
210
211 /*OPN-MOD: 6 FM channel flag*/
212 Bit8u mode_fm6ch;
213
214 Bit8u ks[24];
215 Bit8u ar[24];
216 Bit8u sr[24];
217 Bit8u dt[24];
218 Bit8u multi[24];
219 Bit8u sl[24];
220 Bit8u rr[24];
221 Bit8u dr[24];
222 Bit8u am[24];
223 Bit8u tl[24];
224 Bit8u ssg_eg[24];
225
226 Bit16u fnum[6];
227 Bit8u block[6];
228 Bit8u kcode[6];
229 Bit16u fnum_3ch[6];
230 Bit8u block_3ch[6];
231 Bit8u kcode_3ch[6];
232 Bit8u reg_a4;
233 Bit8u reg_ac;
234 Bit8u connect[6];
235 Bit8u fb[6];
236 Bit8u pan_l[6], pan_r[6];
237 Bit8u ams[6];
238 Bit8u pms[6];
239 Bit8u status;
240 Bit32u status_time;
241
242 /*EXTRA*/
243 Bit64u writebuf_samplecnt;
244 Bit32u writebuf_cur;
245 Bit32u writebuf_last;
246 Bit64u writebuf_lasttime;
247 opn2_writebuf writebuf[OPN_WRITEBUF_SIZE];
248
249 /*OPN-MOD*/
250 const struct OPN2mod_psg_callbacks *psg;
251 void *psgdata;
252
253 /*OPN-MOD*/
254 YM_DELTAT deltaT;
255 Bit32s out_deltaT[4];
256 } ym3438_t;
257
258 void OPN2_Reset(ym3438_t *chip, Bit32u clock, const struct OPN2mod_psg_callbacks *psg, void *psgdata, Bit32u dramsize);
259 void OPN2_Destroy(ym3438_t *chip);
260 void OPN2_SetChipType(Bit32u type);
261 void OPN2_Clock(ym3438_t *chip, Bit16s *buffer);
262 void OPN2_Write(ym3438_t *chip, Bit32u port, Bit8u data);
263 void OPN2_SetTestPin(ym3438_t *chip, Bit32u value);
264 Bit32u OPN2_ReadTestPin(ym3438_t *chip);
265 Bit32u OPN2_ReadIRQPin(ym3438_t *chip);
266 Bit8u OPN2_Read(ym3438_t *chip, Bit32u port);
267
268 /*EXTRA*/
269 void OPN2_WriteBuffered(ym3438_t *chip, Bit32u port, Bit8u data);
270 void OPN2_FlushBuffer(ym3438_t *chip);
271 void OPN2_Generate(ym3438_t *chip, sample *samples);
272
273 /*OPN-MOD*/
274 struct OPN2mod_psg_callbacks
275 {
276 void (*SetClock)(void *param, int clock);
277 void (*Write)(void *param, int address, int data);
278 int (*Read)(void *param);
279 void (*Reset)(void *param);
280 };
281
282 #ifdef __cplusplus
283 }
284 #endif
285
286 #endif