Debian Codegraph @

android/app/jni/extern/opn/ym3438.h

raw
1 /*
2 * Copyright (C) 2017-2021 Alexey Khokholov (Nuke.YKT)
3 *
4 * This file is part of Nuked OPN2.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library 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 GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 *
20 * Nuked OPN2(Yamaha YM3438) emulator.
21 * Thanks:
22 * Silicon Pr0n:
23 * Yamaha YM3438 decap and die shot(digshadow).
24 * OPLx decapsulated(Matthew Gambrell, Olli Niemitalo):
25 * OPL2 ROMs.
26 *
27 * version: 1.0.9
28 */
29
30 #ifndef YM3438_H
31 #define YM3438_H
32
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36
37 enum {
38 ym3438_mode_ym2612 = 0x01, /* Enables YM2612 emulation (MD1, MD2 VA2) */
39 ym3438_mode_readmode = 0x02, /* Enables status read on any port (TeraDrive, MD1 VA7, MD2, etc) */
40 ym3438_mode_opn = 0x04 /* Outputs full, unshifted signal per channel (OPN/OPNA/OPNB) */
41 };
42
43 #include <stdint.h>
44
45 typedef uintptr_t Bitu;
46 typedef intptr_t Bits;
47 typedef uint64_t Bit64u;
48 typedef int64_t Bit64s;
49 typedef uint32_t Bit32u;
50 typedef int32_t Bit32s;
51 typedef uint16_t Bit16u;
52 typedef int16_t Bit16s;
53 typedef uint8_t Bit8u;
54 typedef int8_t Bit8s;
55
56 typedef struct
57 {
58 Bit32u cycles;
59 Bit32u channel;
60 Bit16s mol, mor;
61 /* IO */
62 Bit16u write_data;
63 Bit8u write_a;
64 Bit8u write_d;
65 Bit8u write_a_en;
66 Bit8u write_d_en;
67 Bit8u write_busy;
68 Bit8u write_busy_cnt;
69 Bit8u write_fm_address;
70 Bit8u write_fm_data;
71 Bit16u write_fm_mode_a;
72 Bit16u address;
73 Bit8u data;
74 Bit8u pin_test_in;
75 Bit8u pin_irq;
76 Bit8u busy;
77 /* LFO */
78 Bit8u lfo_en;
79 Bit8u lfo_freq;
80 Bit8u lfo_pm;
81 Bit8u lfo_am;
82 Bit8u lfo_cnt;
83 Bit8u lfo_inc;
84 Bit8u lfo_quotient;
85 /* Phase generator */
86 Bit16u pg_fnum;
87 Bit8u pg_block;
88 Bit8u pg_kcode;
89 Bit32u pg_inc[24];
90 Bit32u pg_phase[24];
91 Bit8u pg_reset[24];
92 Bit32u pg_read;
93 /* Envelope generator */
94 Bit8u eg_cycle;
95 Bit8u eg_cycle_stop;
96 Bit8u eg_shift;
97 Bit8u eg_shift_lock;
98 Bit8u eg_timer_low_lock;
99 Bit16u eg_timer;
100 Bit8u eg_timer_inc;
101 Bit16u eg_quotient;
102 Bit8u eg_custom_timer;
103 Bit8u eg_rate;
104 Bit8u eg_ksv;
105 Bit8u eg_inc;
106 Bit8u eg_ratemax;
107 Bit8u eg_sl[2];
108 Bit8u eg_lfo_am;
109 Bit8u eg_tl[2];
110 Bit8u eg_state[24];
111 Bit16u eg_level[24];
112 Bit16u eg_out[24];
113 Bit8u eg_kon[24];
114 Bit8u eg_kon_csm[24];
115 Bit8u eg_kon_latch[24];
116 Bit8u eg_csm_mode[24];
117 Bit8u eg_ssg_enable[24];
118 Bit8u eg_ssg_pgrst_latch[24];
119 Bit8u eg_ssg_repeat_latch[24];
120 Bit8u eg_ssg_hold_up_latch[24];
121 Bit8u eg_ssg_dir[24];
122 Bit8u eg_ssg_inv[24];
123 Bit32u eg_read[2];
124 Bit8u eg_read_inc;
125 /* Settings */
126 Bit8u chip_type;
127 Bit8u msw;
128 /* FM */
129 Bit16s fm_op1[6][2];
130 Bit16s fm_op2[6];
131 Bit16s fm_out[24];
132 Bit16u fm_mod[24];
133 /* Channel */
134 Bit16s ch_acc[6];
135 Bit16s ch_out[6];
136 Bit16s ch_lock;
137 Bit8u ch_lock_l;
138 Bit8u ch_lock_r;
139 Bit16s ch_read;
140 /* Timer */
141 Bit16u timer_a_cnt;
142 Bit16u timer_a_reg;
143 Bit8u timer_a_load_lock;
144 Bit8u timer_a_load;
145 Bit8u timer_a_enable;
146 Bit8u timer_a_reset;
147 Bit8u timer_a_load_latch;
148 Bit8u timer_a_overflow_flag;
149 Bit8u timer_a_overflow;
150
151 Bit16u timer_b_cnt;
152 Bit8u timer_b_subcnt;
153 Bit16u timer_b_reg;
154 Bit8u timer_b_load_lock;
155 Bit8u timer_b_load;
156 Bit8u timer_b_enable;
157 Bit8u timer_b_reset;
158 Bit8u timer_b_load_latch;
159 Bit8u timer_b_overflow_flag;
160 Bit8u timer_b_overflow;
161
162 /* Register set */
163 Bit8u mode_test_21[8];
164 Bit8u mode_test_2c[8];
165 Bit8u mode_ch3;
166 Bit8u mode_kon_channel;
167 Bit8u mode_kon_operator[4];
168 Bit8u mode_kon[24];
169 Bit8u mode_csm;
170 Bit8u mode_kon_csm;
171 Bit8u dacen;
172 Bit16s dacdata;
173
174 Bit8u ks[24];
175 Bit8u ar[24];
176 Bit8u sr[24];
177 Bit8u dt[24];
178 Bit8u multi[24];
179 Bit8u sl[24];
180 Bit8u rr[24];
181 Bit8u dr[24];
182 Bit8u am[24];
183 Bit8u tl[24];
184 Bit8u ssg_eg[24];
185
186 Bit16u fnum[6];
187 Bit8u block[6];
188 Bit8u kcode[6];
189 Bit16u fnum_3ch[6];
190 Bit8u block_3ch[6];
191 Bit8u kcode_3ch[6];
192 Bit8u reg_a4;
193 Bit8u reg_ac;
194 Bit8u connect[6];
195 Bit8u fb[6];
196 Bit8u pan_l[6], pan_r[6];
197 Bit8u ams[6];
198 Bit8u pms[6];
199 Bit8u status;
200 Bit32u status_time;
201 } ym3438_t;
202
203 void OPN2_Reset(ym3438_t *chip);
204 void OPN2_SetChipType(ym3438_t *chip, Bit32u type);
205 void OPN2_SetMSW(ym3438_t *chip, Bit32u msw);
206 void OPN2_Clock(ym3438_t *chip, Bit16s *buffer);
207 void OPN2_Write(ym3438_t *chip, Bit32u port, Bit8u data);
208 void OPN2_SetTestPin(ym3438_t *chip, Bit32u value);
209 Bit32u OPN2_ReadTestPin(ym3438_t *chip);
210 Bit32u OPN2_ReadIRQPin(ym3438_t *chip);
211 Bit8u OPN2_Read(ym3438_t *chip, Bit32u port);
212
213 #ifdef __cplusplus
214 }
215 #endif
216
217 #endif