| 1 |
/* |
| 2 |
* Copyright (C) 2023 nukeykt |
| 3 |
* |
| 4 |
* This file is part of YM3812-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 |
* YM3812 emulator |
| 17 |
* Thanks: |
| 18 |
* Travis Goodspeed: |
| 19 |
* YM3812 decap and die shot |
| 20 |
* |
| 21 |
*/ |
| 22 |
|
| 23 |
#pragma once |
| 24 |
|
| 25 |
typedef struct |
| 26 |
{ |
| 27 |
int mclk; |
| 28 |
int address; |
| 29 |
int data_i; |
| 30 |
int ic; |
| 31 |
int cs; |
| 32 |
int rd; |
| 33 |
int wr; |
| 34 |
} fmopl2_input_t; |
| 35 |
|
| 36 |
typedef struct |
| 37 |
{ |
| 38 |
fmopl2_input_t input; |
| 39 |
|
| 40 |
int mclk1; |
| 41 |
int mclk2; |
| 42 |
int clk1; |
| 43 |
int clk2; |
| 44 |
|
| 45 |
int prescaler_reset_l[2]; |
| 46 |
int prescaler_cnt[2]; |
| 47 |
int prescaler_l1[2]; |
| 48 |
int prescaler_l2[2]; |
| 49 |
|
| 50 |
int reset1; |
| 51 |
|
| 52 |
int fsm_reset_l[2]; |
| 53 |
int fsm_reset; // wire |
| 54 |
int fsm_cnt1[2]; |
| 55 |
int fsm_cnt2[2]; |
| 56 |
int fsm_cnt1_of; // wire |
| 57 |
int fsm_cnt2_of; // wire |
| 58 |
int fsm_sel[13]; |
| 59 |
int fsm_cnt; // wire |
| 60 |
int fsm_ch_out; |
| 61 |
int fsm_do_fb; |
| 62 |
int fsm_load_fb; |
| 63 |
int fsm_l1[2]; |
| 64 |
int fsm_l2[2]; |
| 65 |
int fsm_l3[2]; |
| 66 |
int fsm_l4[2]; |
| 67 |
int fsm_l5[2]; |
| 68 |
int fsm_l6[2]; |
| 69 |
int fsm_out[16]; |
| 70 |
|
| 71 |
int io_rd; |
| 72 |
int io_wr; |
| 73 |
int io_cs; |
| 74 |
int io_a0; |
| 75 |
|
| 76 |
int io_read0; |
| 77 |
int io_read1; |
| 78 |
int io_write; |
| 79 |
int io_write0; |
| 80 |
int io_write1; |
| 81 |
int io_dir; |
| 82 |
int io_data; |
| 83 |
|
| 84 |
int data_latch; |
| 85 |
|
| 86 |
int write0; |
| 87 |
int write0_sr; |
| 88 |
int write0_latch[6]; |
| 89 |
int write1; |
| 90 |
int write1_sr; |
| 91 |
int write1_latch[6]; |
| 92 |
|
| 93 |
int reg_sel1; |
| 94 |
int reg_sel2; |
| 95 |
int reg_sel3; |
| 96 |
int reg_sel4; |
| 97 |
int reg_sel8; |
| 98 |
int reg_selbd; |
| 99 |
int reg_test; |
| 100 |
int reg_timer1; |
| 101 |
int reg_timer2; |
| 102 |
int reg_notesel; |
| 103 |
int reg_csm; |
| 104 |
int reg_da; |
| 105 |
int reg_dv; |
| 106 |
int rhythm; |
| 107 |
int reg_rh_kon; |
| 108 |
int reg_sel4_wr; // wire |
| 109 |
int reg_sel4_rst; // wire |
| 110 |
int reg_t1_mask; |
| 111 |
int reg_t2_mask; |
| 112 |
int reg_t1_start; |
| 113 |
int reg_t2_start; |
| 114 |
int reg_mode_b3; |
| 115 |
int reg_mode_b4; |
| 116 |
|
| 117 |
int t1_cnt[2]; |
| 118 |
int t2_cnt[2]; |
| 119 |
int t1_of[2]; |
| 120 |
int t2_of[2]; |
| 121 |
int t1_status; |
| 122 |
int t2_status; |
| 123 |
int unk_status1; |
| 124 |
int unk_status2; |
| 125 |
int timer_st_load_l; |
| 126 |
int timer_st_load; |
| 127 |
int t1_start; |
| 128 |
int t1_start_l[2]; |
| 129 |
int t2_start_l[2]; |
| 130 |
int t1_load; // wire |
| 131 |
int csm_load_l; |
| 132 |
int csm_load; |
| 133 |
int csm_kon; |
| 134 |
int rh_sel0; |
| 135 |
int rh_sel[2]; |
| 136 |
|
| 137 |
int keyon_comb; |
| 138 |
int address; |
| 139 |
int address_valid; |
| 140 |
int address_valid_l[2]; |
| 141 |
int address_valid2; |
| 142 |
int data; |
| 143 |
int slot_cnt1[2]; |
| 144 |
int slot_cnt2[2]; |
| 145 |
int slot_cnt; |
| 146 |
int sel_ch; |
| 147 |
|
| 148 |
int ch_fnum[10][2]; |
| 149 |
int ch_block[3][2]; |
| 150 |
int ch_keyon[2]; |
| 151 |
int ch_connect[2]; |
| 152 |
int ch_fb[3][2]; |
| 153 |
int op_multi[4][2]; |
| 154 |
int op_ksr[2]; |
| 155 |
int op_egt[2]; |
| 156 |
int op_vib[2]; |
| 157 |
int op_am[2]; |
| 158 |
int op_tl[6][2]; |
| 159 |
int op_ksl[2][2]; |
| 160 |
int op_ar[4][2]; |
| 161 |
int op_dr[4][2]; |
| 162 |
int op_sl[4][2]; |
| 163 |
int op_rr[4][2]; |
| 164 |
int op_wf[2][2]; |
| 165 |
int op_mod[2]; |
| 166 |
int op_value; // wire |
| 167 |
|
| 168 |
int eg_load1_l; |
| 169 |
int eg_load1; |
| 170 |
int eg_load2_l; |
| 171 |
int eg_load2; |
| 172 |
int eg_load3_l; |
| 173 |
int eg_load3; |
| 174 |
|
| 175 |
int trem_carry[2]; |
| 176 |
int trem_value[2]; |
| 177 |
int trem_dir[2]; |
| 178 |
int trem_step; |
| 179 |
int trem_out; |
| 180 |
int trem_of[2]; |
| 181 |
|
| 182 |
int eg_timer[2]; |
| 183 |
int eg_timer_masked[2]; |
| 184 |
int eg_carry[2]; |
| 185 |
int eg_mask[2]; |
| 186 |
int eg_subcnt[2]; |
| 187 |
int eg_subcnt_l[2]; |
| 188 |
int eg_sync_l[2]; |
| 189 |
int eg_timer_low; |
| 190 |
int eg_shift; |
| 191 |
int eg_state[2][2]; |
| 192 |
int eg_level[9][2]; |
| 193 |
int eg_out[2]; |
| 194 |
int eg_dokon; // wire |
| 195 |
int eg_mute[2]; |
| 196 |
|
| 197 |
int block; |
| 198 |
int fnum; |
| 199 |
int keyon; |
| 200 |
int connect; |
| 201 |
int connect_l[2]; |
| 202 |
int fb; |
| 203 |
int fb_l[2][2]; |
| 204 |
int multi; |
| 205 |
int ksr; |
| 206 |
int egt; |
| 207 |
int vib; |
| 208 |
int am; |
| 209 |
int tl; |
| 210 |
int ksl; |
| 211 |
int ar; |
| 212 |
int dr; |
| 213 |
int sl; |
| 214 |
int rr; |
| 215 |
int wf; |
| 216 |
|
| 217 |
int lfo_cnt[2]; |
| 218 |
int t1_step; // wire |
| 219 |
int t2_step; // wire |
| 220 |
int am_step; // wire |
| 221 |
int vib_step; // wire |
| 222 |
int vib_cnt[2]; |
| 223 |
int pg_phase[19][2]; |
| 224 |
int dbg_serial[2]; |
| 225 |
|
| 226 |
int noise_lfsr[2]; |
| 227 |
|
| 228 |
int hh_load; |
| 229 |
int tc_load; |
| 230 |
int hh_bit2; |
| 231 |
int hh_bit3; |
| 232 |
int hh_bit7; |
| 233 |
int hh_bit8; |
| 234 |
int tc_bit3; |
| 235 |
int tc_bit5; |
| 236 |
int op_logsin[2]; |
| 237 |
int op_shift[2]; |
| 238 |
int op_pow[2]; |
| 239 |
int op_mute[2]; |
| 240 |
int op_sign[2]; |
| 241 |
int op_fb[2][13][2]; |
| 242 |
|
| 243 |
int pg_out; // wire |
| 244 |
int pg_out_rhy; // wire |
| 245 |
|
| 246 |
int accm_value[2]; |
| 247 |
int accm_shifter[2]; |
| 248 |
int accm_load1_l; |
| 249 |
int accm_load1; |
| 250 |
int accm_clamplow; |
| 251 |
int accm_clamphigh; |
| 252 |
int accm_top; |
| 253 |
int accm_sel[2]; |
| 254 |
int accm_mo[2]; |
| 255 |
|
| 256 |
int o_sh; |
| 257 |
int o_mo; |
| 258 |
int o_irq_pull; |
| 259 |
int o_sy; |
| 260 |
|
| 261 |
int data_o; |
| 262 |
int data_z; |
| 263 |
|
| 264 |
int o_clk1; |
| 265 |
int o_clk2; |
| 266 |
int o_reset1; |
| 267 |
int o_write0; |
| 268 |
int o_write1; |
| 269 |
int o_data_latch; |
| 270 |
|
| 271 |
int op_value_debug; |
| 272 |
|
| 273 |
} fmopl2_t; |
| 274 |
|
| 275 |
// modification |
| 276 |
void FMOPL2_Clock(fmopl2_t *chip); |