openMSX
opll.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2019 Nuke.YKT
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  *
15  * Yamaha YM2413 emulator
16  * Thanks:
17  * siliconpr0n.org(digshadow, John McMaster):
18  * VRC VII decap and die shot.
19  *
20  * version: 1.0.1
21  */
22 
23 #ifndef OPLL_H
24 #define OPLL_H
25 
26 #include <cstdint>
27 
28 enum {
29  opll_type_ym2413 = 0x00, /* Yamaha YM2413 */
30  opll_type_ds1001, /* Konami VRC VII */
31  opll_type_ym2413b, /* Yamaha YM2413B */
32  opll_type_ymf281, /* Yamaha YMF281 */
33  opll_type_ymf281b, /* Yamaha YMF281B */
34  opll_type_ym2420, /* Yamaha YM2420 */
35  opll_type_ym2423, /* Yamaha YM2423 */
36 };
37 
38 enum {
39  opll_patch_1 = 0x00,
61 };
62 
63 struct opll_patch_t {
64  uint8_t tl;
65  uint8_t dc;
66  uint8_t dm;
67  uint8_t fb;
68  uint8_t am[2];
69  uint8_t vib[2];
70  uint8_t et[2];
71  uint8_t ksr[2];
72  uint8_t multi[2];
73  uint8_t ksl[2];
74  uint8_t ar[2];
75  uint8_t dr[2];
76  uint8_t sl[2];
77  uint8_t rr[2];
78 };
79 
80 struct opll_t {
81  uint32_t chip_type;
82  uint32_t cycles;
83  uint32_t slot;
85  /* IO */
86  uint8_t write_data;
87  uint8_t write_a;
88  uint8_t write_d;
89  uint8_t write_a_en;
90  uint8_t write_d_en;
92  uint8_t write_fm_data;
94  uint8_t address;
95  uint8_t data;
96  /* Envelope generator */
99  uint32_t eg_timer;
101  uint8_t eg_timer_carry;
102  uint8_t eg_timer_shift;
105  uint8_t eg_state[18];
106  uint8_t eg_level[18];
107  uint8_t eg_kon;
108  uint32_t eg_dokon;
109  uint8_t eg_off;
110  uint8_t eg_rate;
111  uint8_t eg_maxrate;
112  uint8_t eg_zerorate;
113  uint8_t eg_inc_lo;
114  uint8_t eg_inc_hi;
115  uint8_t eg_rate_hi;
116  uint16_t eg_sl;
117  uint16_t eg_ksltl;
118  uint8_t eg_out;
119  uint8_t eg_silent;
120  /* Phase generator */
121  uint16_t pg_fnum;
122  uint8_t pg_block;
123  uint16_t pg_out;
124  uint32_t pg_inc;
125  uint32_t pg_phase[18];
126  uint32_t pg_phase_next;
127  /* Operator */
128  int16_t op_fb1[9];
129  int16_t op_fb2[9];
130  int16_t op_fbsum;
131  int16_t op_mod;
132  uint8_t op_neg;
133  uint16_t op_logsin;
134  uint16_t op_exp_m;
135  uint16_t op_exp_s;
136  /* Channel */
137  int16_t ch_out;
138  int16_t ch_out_hh;
139  int16_t ch_out_tm;
140  int16_t ch_out_bd;
141  int16_t ch_out_sd;
142  int16_t ch_out_tc;
143  /* LFO */
144  uint16_t lfo_counter;
146  uint16_t lfo_am_counter;
147  uint8_t lfo_am_step;
148  uint8_t lfo_am_dir;
149  uint8_t lfo_am_car;
150  uint8_t lfo_am_out;
151  /* Register set */
152  uint16_t fnum[9];
153  uint8_t block[9];
154  uint8_t kon[9];
155  uint8_t son[9];
156  uint8_t vol[9];
157  uint8_t inst[9];
158  uint8_t rhythm;
159  uint8_t testmode;
161  uint8_t c_instr;
162  uint8_t c_op;
163  uint8_t c_tl;
164  uint8_t c_dc;
165  uint8_t c_dm;
166  uint8_t c_fb;
167  uint8_t c_am;
168  uint8_t c_vib;
169  uint8_t c_et;
170  uint8_t c_ksr;
171  uint8_t c_ksr_freq;
172  uint8_t c_ksl_freq;
173  uint8_t c_ksl_block;
174  uint8_t c_multi;
175  uint8_t c_ksl;
176  uint8_t c_adrr[3];
177  uint8_t c_sl;
178  uint16_t c_fnum;
179  uint16_t c_block;
180  /* Rhythm mode */
181  int8_t rm_enable;
182  uint32_t rm_noise;
183  uint32_t rm_select;
184  uint8_t rm_hh_bit2;
185  uint8_t rm_hh_bit3;
186  uint8_t rm_hh_bit7;
187  uint8_t rm_hh_bit8;
188  uint8_t rm_tc_bit3;
189  uint8_t rm_tc_bit5;
190 
191  int16_t output_m;
192  int16_t output_r;
193 };
194 
195 void OPLL_Reset(opll_t *chip, uint32_t chip_type);
196 void OPLL_Clock(opll_t *chip, int32_t *buffer);
197 void OPLL_Write(opll_t *chip, uint32_t port, uint8_t data);
198 
199 #endif
@ opll_type_ym2413b
Definition: opll.hh:31
@ opll_type_ym2420
Definition: opll.hh:34
@ opll_type_ds1001
Definition: opll.hh:30
@ opll_type_ymf281b
Definition: opll.hh:33
@ opll_type_ymf281
Definition: opll.hh:32
@ opll_type_ym2423
Definition: opll.hh:35
@ opll_type_ym2413
Definition: opll.hh:29
void OPLL_Reset(opll_t *chip, uint32_t chip_type)
Definition: opll.cc:293
void OPLL_Write(opll_t *chip, uint32_t port, uint8_t data)
Definition: opll.cc:1101
void OPLL_Clock(opll_t *chip, int32_t *buffer)
Definition: opll.cc:1062
@ opll_patch_6
Definition: opll.hh:44
@ opll_patch_14
Definition: opll.hh:52
@ opll_patch_drum_3
Definition: opll.hh:57
@ opll_patch_15
Definition: opll.hh:53
@ opll_patch_9
Definition: opll.hh:47
@ opll_patch_8
Definition: opll.hh:46
@ opll_patch_drum_2
Definition: opll.hh:56
@ opll_patch_drum_4
Definition: opll.hh:58
@ opll_patch_1
Definition: opll.hh:39
@ opll_patch_drum_1
Definition: opll.hh:55
@ opll_patch_12
Definition: opll.hh:50
@ opll_patch_7
Definition: opll.hh:45
@ opll_patch_5
Definition: opll.hh:43
@ opll_patch_10
Definition: opll.hh:48
@ opll_patch_4
Definition: opll.hh:42
@ opll_patch_11
Definition: opll.hh:49
@ opll_patch_2
Definition: opll.hh:40
@ opll_patch_3
Definition: opll.hh:41
@ opll_patch_max
Definition: opll.hh:60
@ opll_patch_drum_0
Definition: opll.hh:54
@ opll_patch_drum_5
Definition: opll.hh:59
@ opll_patch_13
Definition: opll.hh:51
uint8_t tl
Definition: opll.hh:64
uint8_t rr[2]
Definition: opll.hh:77
uint8_t ar[2]
Definition: opll.hh:74
uint8_t vib[2]
Definition: opll.hh:69
uint8_t dm
Definition: opll.hh:66
uint8_t fb
Definition: opll.hh:67
uint8_t dc
Definition: opll.hh:65
uint8_t sl[2]
Definition: opll.hh:76
uint8_t dr[2]
Definition: opll.hh:75
uint8_t am[2]
Definition: opll.hh:68
uint8_t multi[2]
Definition: opll.hh:72
uint8_t et[2]
Definition: opll.hh:70
uint8_t ksl[2]
Definition: opll.hh:73
uint8_t ksr[2]
Definition: opll.hh:71
Definition: opll.hh:80
uint8_t rm_hh_bit7
Definition: opll.hh:186
uint8_t c_tl
Definition: opll.hh:163
uint8_t address
Definition: opll.hh:94
uint8_t eg_timer_shift_stop
Definition: opll.hh:104
uint8_t write_a_en
Definition: opll.hh:89
uint8_t c_sl
Definition: opll.hh:177
uint16_t c_fnum
Definition: opll.hh:178
uint16_t lfo_counter
Definition: opll.hh:144
uint8_t c_ksl_freq
Definition: opll.hh:172
uint8_t eg_timer_low_lock
Definition: opll.hh:100
uint8_t c_instr
Definition: opll.hh:161
uint8_t son[9]
Definition: opll.hh:155
uint32_t pg_phase[18]
Definition: opll.hh:125
uint8_t lfo_vib_counter
Definition: opll.hh:145
uint8_t eg_off
Definition: opll.hh:109
uint8_t write_fm_data
Definition: opll.hh:92
uint8_t c_op
Definition: opll.hh:162
uint8_t c_vib
Definition: opll.hh:168
uint8_t c_am
Definition: opll.hh:167
uint8_t inst[9]
Definition: opll.hh:157
uint8_t lfo_am_car
Definition: opll.hh:149
int16_t op_fb1[9]
Definition: opll.hh:128
uint32_t eg_timer
Definition: opll.hh:99
uint8_t eg_counter_state
Definition: opll.hh:97
uint8_t eg_timer_shift_lock
Definition: opll.hh:103
int16_t ch_out_bd
Definition: opll.hh:140
uint8_t rm_hh_bit3
Definition: opll.hh:185
uint8_t pg_block
Definition: opll.hh:122
uint16_t op_logsin
Definition: opll.hh:133
uint16_t op_exp_m
Definition: opll.hh:134
uint32_t rm_noise
Definition: opll.hh:182
uint8_t write_d
Definition: opll.hh:88
uint8_t c_fb
Definition: opll.hh:166
int16_t ch_out_tc
Definition: opll.hh:142
uint32_t cycles
Definition: opll.hh:82
opll_patch_t patch
Definition: opll.hh:160
uint16_t lfo_am_counter
Definition: opll.hh:146
uint8_t testmode
Definition: opll.hh:159
uint8_t eg_rate_hi
Definition: opll.hh:115
int16_t op_fbsum
Definition: opll.hh:130
uint8_t lfo_am_step
Definition: opll.hh:147
int16_t ch_out_hh
Definition: opll.hh:138
uint16_t eg_sl
Definition: opll.hh:116
uint8_t c_multi
Definition: opll.hh:174
uint8_t lfo_am_out
Definition: opll.hh:150
uint32_t eg_dokon
Definition: opll.hh:108
uint8_t rm_hh_bit2
Definition: opll.hh:184
uint8_t c_adrr[3]
Definition: opll.hh:176
uint16_t eg_ksltl
Definition: opll.hh:117
uint8_t c_ksl_block
Definition: opll.hh:173
uint8_t rm_hh_bit8
Definition: opll.hh:187
int8_t rm_enable
Definition: opll.hh:181
uint8_t eg_level[18]
Definition: opll.hh:106
uint8_t write_a
Definition: opll.hh:87
uint8_t rhythm
Definition: opll.hh:158
int16_t op_mod
Definition: opll.hh:131
uint8_t rm_tc_bit3
Definition: opll.hh:188
uint16_t fnum[9]
Definition: opll.hh:152
int16_t ch_out
Definition: opll.hh:137
uint16_t pg_fnum
Definition: opll.hh:121
uint16_t c_block
Definition: opll.hh:179
uint8_t c_ksl
Definition: opll.hh:175
uint8_t eg_state[18]
Definition: opll.hh:105
uint32_t pg_phase_next
Definition: opll.hh:126
uint8_t op_neg
Definition: opll.hh:132
uint8_t eg_maxrate
Definition: opll.hh:111
uint8_t write_d_en
Definition: opll.hh:90
uint8_t eg_silent
Definition: opll.hh:119
uint32_t rm_select
Definition: opll.hh:183
uint8_t rm_tc_bit5
Definition: opll.hh:189
uint8_t eg_timer_carry
Definition: opll.hh:101
uint8_t eg_kon
Definition: opll.hh:107
int16_t output_r
Definition: opll.hh:192
uint8_t lfo_am_dir
Definition: opll.hh:148
uint32_t chip_type
Definition: opll.hh:81
int16_t ch_out_sd
Definition: opll.hh:141
uint8_t eg_timer_shift
Definition: opll.hh:102
uint8_t write_fm_address
Definition: opll.hh:91
uint8_t eg_zerorate
Definition: opll.hh:112
uint16_t op_exp_s
Definition: opll.hh:135
uint16_t pg_out
Definition: opll.hh:123
uint8_t block[9]
Definition: opll.hh:153
uint8_t data
Definition: opll.hh:95
uint32_t pg_inc
Definition: opll.hh:124
uint8_t c_ksr
Definition: opll.hh:170
uint8_t eg_counter_state_prev
Definition: opll.hh:98
uint8_t eg_out
Definition: opll.hh:118
int16_t op_fb2[9]
Definition: opll.hh:129
const opll_patch_t * patchrom
Definition: opll.hh:84
uint8_t c_et
Definition: opll.hh:169
uint8_t write_data
Definition: opll.hh:86
uint8_t c_ksr_freq
Definition: opll.hh:171
uint8_t c_dc
Definition: opll.hh:164
uint8_t write_mode_address
Definition: opll.hh:93
uint32_t slot
Definition: opll.hh:83
uint8_t eg_inc_lo
Definition: opll.hh:113
uint8_t eg_inc_hi
Definition: opll.hh:114
uint8_t c_dm
Definition: opll.hh:165
uint8_t eg_rate
Definition: opll.hh:110
uint8_t kon[9]
Definition: opll.hh:154
uint8_t vol[9]
Definition: opll.hh:156
int16_t output_m
Definition: opll.hh:191
int16_t ch_out_tm
Definition: opll.hh:139