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 <stdint.h>
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 typedef struct {
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 } opll_patch_t;
79 
80 typedef struct {
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 } opll_t;
195 
196 void OPLL_Reset(opll_t *chip, uint32_t chip_type);
197 void OPLL_Clock(opll_t *chip, int32_t *buffer);
198 void OPLL_Write(opll_t *chip, uint32_t port, uint8_t data);
199 #endif
opll_t::eg_out
uint8_t eg_out
Definition: opll.hh:118
opll_t::rm_hh_bit8
uint8_t rm_hh_bit8
Definition: opll.hh:187
opll_t::rm_hh_bit2
uint8_t rm_hh_bit2
Definition: opll.hh:184
opll_patch_5
@ opll_patch_5
Definition: opll.hh:43
opll_t::op_mod
int16_t op_mod
Definition: opll.hh:131
opll_patch_drum_2
@ opll_patch_drum_2
Definition: opll.hh:56
opll_t::pg_block
uint8_t pg_block
Definition: opll.hh:122
opll_t::patchrom
const opll_patch_t * patchrom
Definition: opll.hh:84
opll_t::write_d
uint8_t write_d
Definition: opll.hh:88
opll_t::eg_dokon
uint32_t eg_dokon
Definition: opll.hh:108
opll_type_ym2413b
@ opll_type_ym2413b
Definition: opll.hh:31
opll_patch_15
@ opll_patch_15
Definition: opll.hh:53
opll_t::rm_hh_bit3
uint8_t rm_hh_bit3
Definition: opll.hh:185
opll_t::lfo_am_car
uint8_t lfo_am_car
Definition: opll.hh:149
opll_t::write_d_en
uint8_t write_d_en
Definition: opll.hh:90
opll_t::rm_noise
uint32_t rm_noise
Definition: opll.hh:182
opll_t::c_et
uint8_t c_et
Definition: opll.hh:169
opll_t::rm_tc_bit5
uint8_t rm_tc_bit5
Definition: opll.hh:189
opll_t::pg_out
uint16_t pg_out
Definition: opll.hh:123
opll_patch_drum_0
@ opll_patch_drum_0
Definition: opll.hh:54
opll_patch_9
@ opll_patch_9
Definition: opll.hh:47
opll_t::eg_ksltl
uint16_t eg_ksltl
Definition: opll.hh:117
opll_t::write_a
uint8_t write_a
Definition: opll.hh:87
opll_t::c_op
uint8_t c_op
Definition: opll.hh:162
opll_t::c_ksl_block
uint8_t c_ksl_block
Definition: opll.hh:173
opll_t::testmode
uint8_t testmode
Definition: opll.hh:159
opll_patch_4
@ opll_patch_4
Definition: opll.hh:42
opll_t::eg_timer_shift_stop
uint8_t eg_timer_shift_stop
Definition: opll.hh:104
opll_patch_3
@ opll_patch_3
Definition: opll.hh:41
opll_patch_10
@ opll_patch_10
Definition: opll.hh:48
opll_t::lfo_am_dir
uint8_t lfo_am_dir
Definition: opll.hh:148
opll_t::eg_timer_shift
uint8_t eg_timer_shift
Definition: opll.hh:102
opll_t::c_fb
uint8_t c_fb
Definition: opll.hh:166
opll_t::eg_inc_hi
uint8_t eg_inc_hi
Definition: opll.hh:114
opll_t::write_fm_data
uint8_t write_fm_data
Definition: opll.hh:92
opll_type_ymf281
@ opll_type_ymf281
Definition: opll.hh:32
opll_t::c_ksl
uint8_t c_ksl
Definition: opll.hh:175
opll_t::address
uint8_t address
Definition: opll.hh:94
opll_t::eg_silent
uint8_t eg_silent
Definition: opll.hh:119
opll_patch_t::dc
uint8_t dc
Definition: opll.hh:65
opll_patch_drum_4
@ opll_patch_drum_4
Definition: opll.hh:58
opll_t::lfo_vib_counter
uint8_t lfo_vib_counter
Definition: opll.hh:145
opll_t::eg_timer_low_lock
uint8_t eg_timer_low_lock
Definition: opll.hh:100
opll_t::data
uint8_t data
Definition: opll.hh:95
opll_t::eg_counter_state
uint8_t eg_counter_state
Definition: opll.hh:97
opll_t::eg_kon
uint8_t eg_kon
Definition: opll.hh:107
opll_t::rm_hh_bit7
uint8_t rm_hh_bit7
Definition: opll.hh:186
opll_t::c_multi
uint8_t c_multi
Definition: opll.hh:174
opll_patch_drum_5
@ opll_patch_drum_5
Definition: opll.hh:59
opll_t::c_instr
uint8_t c_instr
Definition: opll.hh:161
opll_t::ch_out
int16_t ch_out
Definition: opll.hh:137
opll_t::pg_inc
uint32_t pg_inc
Definition: opll.hh:124
opll_t::c_ksr
uint8_t c_ksr
Definition: opll.hh:170
opll_t::cycles
uint32_t cycles
Definition: opll.hh:82
opll_patch_8
@ opll_patch_8
Definition: opll.hh:46
opll_patch_t
Definition: opll.hh:63
opll_type_ymf281b
@ opll_type_ymf281b
Definition: opll.hh:33
opll_t::eg_rate_hi
uint8_t eg_rate_hi
Definition: opll.hh:115
opll_patch_drum_3
@ opll_patch_drum_3
Definition: opll.hh:57
opll_t::c_ksl_freq
uint8_t c_ksl_freq
Definition: opll.hh:172
opll_patch_11
@ opll_patch_11
Definition: opll.hh:49
opll_type_ds1001
@ opll_type_ds1001
Definition: opll.hh:30
opll_t::c_dm
uint8_t c_dm
Definition: opll.hh:165
opll_type_ym2420
@ opll_type_ym2420
Definition: opll.hh:34
opll_t::ch_out_hh
int16_t ch_out_hh
Definition: opll.hh:138
opll_t::ch_out_bd
int16_t ch_out_bd
Definition: opll.hh:140
opll_t::rm_select
uint32_t rm_select
Definition: opll.hh:183
opll_t::ch_out_tc
int16_t ch_out_tc
Definition: opll.hh:142
opll_patch_1
@ opll_patch_1
Definition: opll.hh:39
opll_t::ch_out_sd
int16_t ch_out_sd
Definition: opll.hh:141
opll_t::op_exp_s
uint16_t op_exp_s
Definition: opll.hh:135
opll_t::eg_sl
uint16_t eg_sl
Definition: opll.hh:116
opll_t::c_dc
uint8_t c_dc
Definition: opll.hh:164
opll_t::write_mode_address
uint8_t write_mode_address
Definition: opll.hh:93
opll_t::op_neg
uint8_t op_neg
Definition: opll.hh:132
opll_t::c_tl
uint8_t c_tl
Definition: opll.hh:163
opll_t::pg_phase_next
uint32_t pg_phase_next
Definition: opll.hh:126
opll_patch_12
@ opll_patch_12
Definition: opll.hh:50
OPLL_Reset
void OPLL_Reset(opll_t *chip, uint32_t chip_type)
Definition: opll.cc:294
opll_t::op_exp_m
uint16_t op_exp_m
Definition: opll.hh:134
opll_t::chip_type
uint32_t chip_type
Definition: opll.hh:81
opll_t::pg_fnum
uint16_t pg_fnum
Definition: opll.hh:121
opll_t::c_am
uint8_t c_am
Definition: opll.hh:167
opll_patch_max
@ opll_patch_max
Definition: opll.hh:60
opll_t::lfo_counter
uint16_t lfo_counter
Definition: opll.hh:144
opll_t::lfo_am_counter
uint16_t lfo_am_counter
Definition: opll.hh:146
opll_t::write_fm_address
uint8_t write_fm_address
Definition: opll.hh:91
opll_type_ym2423
@ opll_type_ym2423
Definition: opll.hh:35
opll_t
Definition: opll.hh:80
opll_t::c_fnum
uint16_t c_fnum
Definition: opll.hh:178
opll_patch_13
@ opll_patch_13
Definition: opll.hh:51
opll_t::write_data
uint8_t write_data
Definition: opll.hh:86
opll_patch_t::tl
uint8_t tl
Definition: opll.hh:64
opll_t::op_fbsum
int16_t op_fbsum
Definition: opll.hh:130
opll_t::eg_counter_state_prev
uint8_t eg_counter_state_prev
Definition: opll.hh:98
opll_t::c_sl
uint8_t c_sl
Definition: opll.hh:177
opll_type_ym2413
@ opll_type_ym2413
Definition: opll.hh:29
opll_patch_7
@ opll_patch_7
Definition: opll.hh:45
opll_t::eg_off
uint8_t eg_off
Definition: opll.hh:109
opll_t::c_vib
uint8_t c_vib
Definition: opll.hh:168
opll_t::eg_timer_shift_lock
uint8_t eg_timer_shift_lock
Definition: opll.hh:103
opll_t::c_block
uint16_t c_block
Definition: opll.hh:179
opll_t::output_r
int16_t output_r
Definition: opll.hh:192
opll_patch_6
@ opll_patch_6
Definition: opll.hh:44
opll_t::output_m
int16_t output_m
Definition: opll.hh:191
opll_patch_t::dm
uint8_t dm
Definition: opll.hh:66
opll_patch_2
@ opll_patch_2
Definition: opll.hh:40
opll_t::ch_out_tm
int16_t ch_out_tm
Definition: opll.hh:139
OPLL_Write
void OPLL_Write(opll_t *chip, uint32_t port, uint8_t data)
Definition: opll.cc:1109
opll_t::eg_maxrate
uint8_t eg_maxrate
Definition: opll.hh:111
opll_t::rm_tc_bit3
uint8_t rm_tc_bit3
Definition: opll.hh:188
OPLL_Clock
void OPLL_Clock(opll_t *chip, int32_t *buffer)
Definition: opll.cc:1070
opll_t::slot
uint32_t slot
Definition: opll.hh:83
opll_t::rm_enable
int8_t rm_enable
Definition: opll.hh:181
opll_patch_t::fb
uint8_t fb
Definition: opll.hh:67
opll_t::eg_timer_carry
uint8_t eg_timer_carry
Definition: opll.hh:101
opll_t::write_a_en
uint8_t write_a_en
Definition: opll.hh:89
opll_t::op_logsin
uint16_t op_logsin
Definition: opll.hh:133
opll_t::eg_inc_lo
uint8_t eg_inc_lo
Definition: opll.hh:113
opll_t::eg_zerorate
uint8_t eg_zerorate
Definition: opll.hh:112
opll_t::c_ksr_freq
uint8_t c_ksr_freq
Definition: opll.hh:171
opll_patch_drum_1
@ opll_patch_drum_1
Definition: opll.hh:55
opll_t::eg_timer
uint32_t eg_timer
Definition: opll.hh:99
opll_t::eg_rate
uint8_t eg_rate
Definition: opll.hh:110
opll_t::rhythm
uint8_t rhythm
Definition: opll.hh:158
opll_t::patch
opll_patch_t patch
Definition: opll.hh:160
opll_patch_14
@ opll_patch_14
Definition: opll.hh:52
opll_t::lfo_am_step
uint8_t lfo_am_step
Definition: opll.hh:147
opll_t::lfo_am_out
uint8_t lfo_am_out
Definition: opll.hh:150