| 1 |
/* |
| 2 |
* Copyright (C) 2022-2023 nukeykt |
| 3 |
* |
| 4 |
* This file is part of YMF276-LLE. |
| 5 |
* |
| 6 |
* This program is free software; you can redistribute it and/or |
| 7 |
* modify it under the terms of the GNU General Public License |
| 8 |
* as published by the Free Software Foundation; either version 2 |
| 9 |
* of the License, or (at your option) any later version. |
| 10 |
* |
| 11 |
* This program 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 |
* |
| 16 |
* YMF276/YM3438 emulator. |
| 17 |
* Thanks: |
| 18 |
* John McMaster (siliconpr0n.org): |
| 19 |
* Yamaha YM3438 & YM2610 decap and die shot. |
| 20 |
* org, andkorzh, HardWareMan (emu-russia): |
| 21 |
* help & support, YMF276 and YM2612 decap. |
| 22 |
* |
| 23 |
*/ |
| 24 |
|
| 25 |
#pragma once |
| 26 |
#include <stdint.h> |
| 27 |
|
| 28 |
enum { |
| 29 |
fmopn2_flags_ym3438 = 1, |
| 30 |
}; |
| 31 |
|
| 32 |
typedef struct { |
| 33 |
int phi; |
| 34 |
int ic; |
| 35 |
} fmopn2_prescaler_input_t; |
| 36 |
|
| 37 |
typedef struct { |
| 38 |
int phi_phase; |
| 39 |
int ic; |
| 40 |
int rd; |
| 41 |
int wr; |
| 42 |
int cs; |
| 43 |
int address; |
| 44 |
int data; |
| 45 |
int test; |
| 46 |
int i_fsm_reset; // (chip->ic_check_latch[1] & 16) != 0; |
| 47 |
} fmopn2_input_t; |
| 48 |
|
| 49 |
typedef struct { |
| 50 |
int flags; |
| 51 |
// input |
| 52 |
fmopn2_input_t input_old, input; |
| 53 |
int i_phi1; |
| 54 |
int i_phi2; |
| 55 |
|
| 56 |
fmopn2_prescaler_input_t pinput, pinput_old; |
| 57 |
|
| 58 |
// clock |
| 59 |
int ic_latch[2]; // 12 |
| 60 |
int ic_check_latch[2]; // 4 |
| 61 |
int prescaler_latch[2]; // 6 |
| 62 |
int phi1_latch[2]; |
| 63 |
int phi2_latch[2]; |
| 64 |
int dphi1_latch[4]; |
| 65 |
int dphi2_latch[3]; |
| 66 |
int dclk1; |
| 67 |
int dclk2; |
| 68 |
int fsm_reset; |
| 69 |
|
| 70 |
// output |
| 71 |
int dac_val; |
| 72 |
int out_l; |
| 73 |
int out_r; |
| 74 |
|
| 75 |
// added by LTVA for Furnace tracker per-channel oscilloscopes! |
| 76 |
int osc_out; |
| 77 |
|
| 78 |
// io |
| 79 |
int write_addr_trig; |
| 80 |
int write_addr_trig_sync; |
| 81 |
int write_addr_dlatch; |
| 82 |
int write_addr_sr[2]; |
| 83 |
int write_data_trig; |
| 84 |
int write_data_trig_sync; |
| 85 |
int write_data_dlatch; |
| 86 |
int write_data_sr[2]; |
| 87 |
|
| 88 |
int data_latch; |
| 89 |
int bank_latch; |
| 90 |
|
| 91 |
int busy_cnt[2]; |
| 92 |
int busy_latch[2]; |
| 93 |
|
| 94 |
int io_ic_latch[2]; |
| 95 |
|
| 96 |
int write_fm_address[2]; |
| 97 |
int fm_address[2]; |
| 98 |
int write_fm_data[2]; |
| 99 |
int fm_data[2]; |
| 100 |
int status_timer_a_dlatch; |
| 101 |
int status_timer_b_dlatch; |
| 102 |
|
| 103 |
// mode registers |
| 104 |
int write_mode_21[2]; |
| 105 |
int write_mode_22[2]; |
| 106 |
int write_mode_24[2]; |
| 107 |
int write_mode_25[2]; |
| 108 |
int write_mode_26[2]; |
| 109 |
int write_mode_27[2]; |
| 110 |
int write_mode_28[2]; |
| 111 |
int write_mode_2a[2]; |
| 112 |
int write_mode_2b[2]; |
| 113 |
int write_mode_2c[2]; |
| 114 |
|
| 115 |
int mode_test_21[2]; |
| 116 |
int mode_lfo_en[2]; |
| 117 |
int mode_lfo_freq[2]; |
| 118 |
int mode_timer_a_reg[2]; |
| 119 |
int mode_timer_b_reg[2]; |
| 120 |
int mode_ch3[2]; |
| 121 |
int mode_timer_a_load[2]; |
| 122 |
int mode_timer_a_enable[2]; |
| 123 |
int mode_timer_a_reset[2]; |
| 124 |
int mode_timer_b_load[2]; |
| 125 |
int mode_timer_b_enable[2]; |
| 126 |
int mode_timer_b_reset[2]; |
| 127 |
int mode_kon_operator[2]; |
| 128 |
int mode_kon_channel[2]; |
| 129 |
int mode_dac_data[2]; |
| 130 |
int mode_dac_en[2]; |
| 131 |
int mode_test_2c[2]; |
| 132 |
|
| 133 |
int mode_kon[4][2]; |
| 134 |
|
| 135 |
// operator registers |
| 136 |
int slot_multi[2][4][2]; |
| 137 |
int slot_dt[2][3][2]; |
| 138 |
int slot_tl[2][7][2]; |
| 139 |
int slot_ar[2][5][2]; |
| 140 |
int slot_ks[2][2][2]; |
| 141 |
int slot_dr[2][5][2]; |
| 142 |
int slot_am[2][1][2]; |
| 143 |
int slot_sr[2][5][2]; |
| 144 |
int slot_rr[2][4][2]; |
| 145 |
int slot_sl[2][4][2]; |
| 146 |
int slot_ssg_eg[2][4][2]; |
| 147 |
// channel registers |
| 148 |
int chan_fnum[11][2]; |
| 149 |
int chan_fnum_ch3[11][2]; |
| 150 |
int chan_block[3][2]; |
| 151 |
int chan_block_ch3[3][2]; |
| 152 |
int chan_a4[2]; |
| 153 |
int chan_ac[2]; |
| 154 |
int chan_connect[3][2]; |
| 155 |
int chan_fb[3][2]; |
| 156 |
int chan_pms[3][2]; |
| 157 |
int chan_ams[2][2]; |
| 158 |
int chan_pan[2][2]; |
| 159 |
|
| 160 |
int reg_cnt1[2]; |
| 161 |
int reg_cnt2[2]; |
| 162 |
|
| 163 |
// lfo |
| 164 |
|
| 165 |
int lfo_cnt1[2]; |
| 166 |
int lfo_cnt2[2]; |
| 167 |
|
| 168 |
int lfo_dlatch; |
| 169 |
int lfo_dlatch_load; |
| 170 |
int lfo_inc_latch[2]; |
| 171 |
|
| 172 |
// pg |
| 173 |
int pg_fnum[2][2]; |
| 174 |
int pg_kcode[2][2]; |
| 175 |
int pg_fnum_lfo1; |
| 176 |
int pg_fnum_lfo2; |
| 177 |
int pg_lfo_shift; |
| 178 |
int pg_lfo_sign; |
| 179 |
int pg_lfo; |
| 180 |
int pg_freq1; |
| 181 |
int pg_freq2; |
| 182 |
int pg_freq3; |
| 183 |
int pg_freq4; |
| 184 |
int pg_freq5[2]; |
| 185 |
int pg_freq6; |
| 186 |
int pg_freq_m1; |
| 187 |
int pg_block; |
| 188 |
int pg_dt[2]; |
| 189 |
int pg_detune[2]; |
| 190 |
int pg_multi[2][2]; |
| 191 |
int pg_multi2; |
| 192 |
int pg_inc[2]; |
| 193 |
int pg_inc_mask[2]; |
| 194 |
int pg_phase[20][2]; |
| 195 |
int pg_reset_latch[2]; |
| 196 |
int pg_debug[2]; |
| 197 |
int pg_reset[2]; |
| 198 |
|
| 199 |
// eg |
| 200 |
int eg_prescaler[2]; |
| 201 |
int eg_prescaler_clock_l[2]; |
| 202 |
int eg_prescaler_l; |
| 203 |
int eg_clock_delay[2]; |
| 204 |
int eg_step[2]; |
| 205 |
int eg_timer_load; |
| 206 |
int eg_timer[2]; |
| 207 |
int eg_timer_carry[2]; |
| 208 |
int eg_timer_mask[2]; |
| 209 |
int eg_timer_masked[2]; |
| 210 |
int eg_timer_low_lock; |
| 211 |
int eg_shift_lock; |
| 212 |
int eg_level[10][2]; |
| 213 |
int eg_level_latch[2]; |
| 214 |
int eg_level_latch_inv; |
| 215 |
int eg_state[2][2]; |
| 216 |
int eg_ssg_dir[2]; |
| 217 |
int eg_ssg_inv[2]; |
| 218 |
int eg_ssg_holdup[2]; |
| 219 |
int eg_ssg_enable[2]; |
| 220 |
int eg_ssg_pgreset[2]; |
| 221 |
int eg_ssg_pgrepeat[2]; |
| 222 |
int eg_key[2]; |
| 223 |
int eg_rate_nonzero[2]; |
| 224 |
int eg_rate; |
| 225 |
int eg_ksv; |
| 226 |
int eg_rate2; |
| 227 |
int eg_inc1; |
| 228 |
int eg_inc2; |
| 229 |
int eg_rate12; |
| 230 |
int eg_rate13; |
| 231 |
int eg_rate14; |
| 232 |
int eg_rate15; |
| 233 |
int eg_maxrate[2]; |
| 234 |
int eg_incsh0; |
| 235 |
int eg_incsh1; |
| 236 |
int eg_incsh2; |
| 237 |
int eg_incsh3; |
| 238 |
int eg_incsh_nonzero[2]; |
| 239 |
int eg_inc_total; |
| 240 |
int eg_level_ssg[2]; |
| 241 |
int eg_sl[2][2]; |
| 242 |
int eg_nextlevel[2]; |
| 243 |
int eg_kon_csm[2]; |
| 244 |
int eg_kon_latch[2]; |
| 245 |
int eg_tl[2][2]; |
| 246 |
int eg_ams; |
| 247 |
int eg_lfo[2]; |
| 248 |
int eg_ch3_latch[2]; |
| 249 |
int eg_out; |
| 250 |
int eg_out_tl; |
| 251 |
int eg_out_total; |
| 252 |
int eg_debug[2]; |
| 253 |
|
| 254 |
// op |
| 255 |
int op_mod[10][2]; |
| 256 |
int op_phase[2]; |
| 257 |
int op_logsin_base[2]; |
| 258 |
int op_logsin_delta[2]; |
| 259 |
int op_logsin_add_delta[2]; |
| 260 |
int op_atten[2]; |
| 261 |
int op_env[2]; |
| 262 |
int op_pow_base[2]; |
| 263 |
int op_pow_delta[2]; |
| 264 |
int op_pow_add_delta[2]; |
| 265 |
int op_shift[2]; |
| 266 |
int op_sign[2]; |
| 267 |
int op_output[2]; |
| 268 |
int op_op1[2][14][2]; |
| 269 |
int op_op2[14][2]; |
| 270 |
int op_mod_sum[2]; |
| 271 |
int op_dofeedback[2]; |
| 272 |
|
| 273 |
// accumulator |
| 274 |
|
| 275 |
int ch_accm[14][2]; |
| 276 |
int ch_out[9][2]; |
| 277 |
int ch_out_dlatch; |
| 278 |
int ch_out_pan_dlatch; |
| 279 |
int ch_dac_load; |
| 280 |
int ch_out_debug[2]; |
| 281 |
int ch_accm_l[2]; |
| 282 |
int ch_accm_r[2]; |
| 283 |
|
| 284 |
// timers |
| 285 |
int timer_dlatch; |
| 286 |
int timer_a_cnt[2]; |
| 287 |
int timer_a_load_latch[2]; |
| 288 |
int timer_a_load_old[2]; |
| 289 |
int timer_a_load_dlatch; |
| 290 |
int timer_a_of[2]; |
| 291 |
int timer_a_status[2]; |
| 292 |
int timer_b_subcnt[2]; |
| 293 |
int timer_b_subcnt_of[2]; |
| 294 |
int timer_b_cnt[2]; |
| 295 |
int timer_b_load_latch[2]; |
| 296 |
int timer_b_load_old[2]; |
| 297 |
int timer_b_load_dlatch; |
| 298 |
int timer_b_of[2]; |
| 299 |
int timer_b_status[2]; |
| 300 |
int timer_csm_key_dlatch; |
| 301 |
|
| 302 |
// fm algorithm |
| 303 |
int alg_mod_op1_0; |
| 304 |
int alg_mod_op1_1; |
| 305 |
int alg_mod_op2; |
| 306 |
int alg_mod_prev_0; |
| 307 |
int alg_mod_prev_1; |
| 308 |
int alg_output; |
| 309 |
int alg_mod_op1_0_l; |
| 310 |
int alg_mod_op1_1_l; |
| 311 |
int alg_mod_op2_l; |
| 312 |
int alg_mod_prev_0_l; |
| 313 |
int alg_mod_prev_1_l; |
| 314 |
int alg_output_l; |
| 315 |
|
| 316 |
// fsm |
| 317 |
int fsm_cnt1[2]; |
| 318 |
int fsm_cnt2[2]; |
| 319 |
// fsm table output |
| 320 |
int fsm_clock_eg; |
| 321 |
int fsm_clock_timers1; |
| 322 |
int fsm_clock_timers; |
| 323 |
int fsm_op4_sel; |
| 324 |
int fsm_op1_sel; |
| 325 |
int fsm_op2_sel; |
| 326 |
int fsm_op3_sel; |
| 327 |
int fsm_sel2; |
| 328 |
int fsm_sel23; |
| 329 |
int fsm_ch3_sel; |
| 330 |
int fsm_dac_load; |
| 331 |
int fsm_dac_out_sel; |
| 332 |
int fsm_dac_ch6; |
| 333 |
|
| 334 |
// ymf276 |
| 335 |
int fsm_clock_eg_l; |
| 336 |
int fsm_op1_sel_l; |
| 337 |
int fsm_sel1_l; |
| 338 |
int fsm_sel2_l; |
| 339 |
int fsm_sel23_l; |
| 340 |
int fsm_ch3_sel_l; |
| 341 |
int fsm_dac_load_l; |
| 342 |
int fsm_dac_out_sel_l; |
| 343 |
int fsm_dac_ch6_l; |
| 344 |
int fsm_lro_l[2]; |
| 345 |
int fsm_wco_l[2]; |
| 346 |
int fsm_lro_l2[2]; |
| 347 |
int fsm_wco_l2[2]; |
| 348 |
int fsm_op1_sel_l2[2]; |
| 349 |
int fsm_op1_sel_l3[2]; |
| 350 |
int fsm_shifter_ctrl[2]; |
| 351 |
int fsm_load_l; |
| 352 |
int fsm_load_r; |
| 353 |
|
| 354 |
int dac_shifter[2]; |
| 355 |
int dac_so_l[2]; |
| 356 |
int o_bco; |
| 357 |
int o_wco; |
| 358 |
int o_lro; |
| 359 |
int o_so; |
| 360 |
} fmopn2_t; |
| 361 |
|
| 362 |
|
| 363 |
int FMOPN2_ReadStatus(fmopn2_t *chip); |
| 364 |
|
| 365 |
void FMOPN2_Clock(fmopn2_t *chip, int phi); |