Debian Codegraph @

android/app/jni/extern/Nuked-OPLL/opll.h

raw
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,
40 opll_patch_2,
41 opll_patch_3,
42 opll_patch_4,
43 opll_patch_5,
44 opll_patch_6,
45 opll_patch_7,
46 opll_patch_8,
47 opll_patch_9,
48 opll_patch_10,
49 opll_patch_11,
50 opll_patch_12,
51 opll_patch_13,
52 opll_patch_14,
53 opll_patch_15,
54 opll_patch_drum_0,
55 opll_patch_drum_1,
56 opll_patch_drum_2,
57 opll_patch_drum_3,
58 opll_patch_drum_4,
59 opll_patch_drum_5,
60 opll_patch_max
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;
84 const opll_patch_t *patchrom;
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;
91 uint8_t write_fm_address;
92 uint8_t write_fm_data;
93 uint8_t write_mode_address;
94 uint8_t address;
95 uint8_t data;
96 /* Envelope generator */
97 uint8_t eg_counter_state;
98 uint8_t eg_counter_state_prev;
99 uint32_t eg_timer;
100 uint8_t eg_timer_low_lock;
101 uint8_t eg_timer_carry;
102 uint8_t eg_timer_shift;
103 uint8_t eg_timer_shift_lock;
104 uint8_t eg_timer_shift_stop;
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;
145 uint8_t lfo_vib_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;
160 opll_patch_t patch;
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 int16_t output_ch[9];
195
196 } opll_t;
197
198 const opll_patch_t* OPLL_GetPatchROM(uint32_t chip_type);
199
200 void OPLL_Reset(opll_t *chip, uint32_t chip_type);
201 void OPLL_Clock(opll_t *chip, int32_t *buffer);
202 void OPLL_Write(opll_t *chip, uint32_t port, uint8_t data);
203 #endif