Debian Codegraph @

src/engine/platform/sound/atomicssg/ssg.h

raw
1 /*
2 * Copyright (C) 2023-2024 nukeykt
3 * Copyright (C) 2024 tildearrow
4 *
5 * This file is part of AtomicSSG.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * SSG (AY-3-8910/YM2149) emulator.
18 * based on YM2608-LLE by nukeykt.
19 *
20 */
21 typedef struct {
22 int clk;
23 int ic; // neg
24 int cs; // neg
25 int wr; // neg
26 int rd; // neg
27 int a0;
28 int data;
29 int test; // set to 1
30 int gpio_a;
31 int gpio_b;
32 }
33 ssg_input_t;
34
35 typedef struct {
36 ssg_input_t input;
37
38 // bitfield
39 // bit 0: AY-3-8910 (16-step envelope)
40 // bit 1: AY-3-8914 (different register map and envelope volume)
41 // bit 2: AY8930 (TODO)
42 int type;
43
44 int ic;
45
46 int ic_latch1[2];
47 int ic_latch2[2];
48 int ic_latch3[2];
49 int ic_check1;
50 int ic_check3;
51 int prescaler_latch[2];
52 int ic_check2;
53 int prescaler_sel[2];
54 int pssel_l[15][2];
55 int ic_latch_fm[2];
56
57 int clk1;
58 int clk2;
59
60 int ssg_write0;
61 int ssg_write1;
62 int ssg_read1;
63
64 int write2;
65 int write3;
66
67 int read2;
68 int read3;
69
70 int read0;
71
72 int write0_trig0;
73 int write0_trig1;
74 int write0_l[3];
75 int write0_en;
76
77 int write1_trig0;
78 int write1_trig1;
79 int write1_l[3];
80 int write1_en;
81
82 int write2_trig0;
83 int write2_trig1;
84 int write2_l[3];
85 int write2_en;
86
87 int write3_trig0;
88 int write3_trig1;
89 int write3_l[3];
90 int write3_en;
91
92 int data_l;
93
94 int data_bus1;
95 int data_bus2; // inverted
96
97 int read_bus;
98
99 int ssg_clk1;
100 int ssg_clk2;
101 int ssg_ssg_addr;
102 int ssg_address;
103 int ssg_freq_a[2];
104 int ssg_freq_b[2];
105 int ssg_freq_c[2];
106 int ssg_noise;
107 int ssg_mode;
108 int ssg_level_a;
109 int ssg_level_b;
110 int ssg_level_c;
111 int ssg_env[2];
112 int ssg_envmode;
113 int ssg_envadd;
114 int ssg_envcnt[2];
115 int ssg_dir[2];
116 int ssg_hold[2];
117 int ssg_t2[2];
118 int ssg_egtrig;
119 int ssg_egtrig_s;
120 int ssg_egtrig_rst;
121 int ssg_eg_sel_l;
122 int ssg_sel[2];
123 int ssg_sel_freq;
124 int ssg_freq_cnt[8];
125 int ssg_cnt_of[2];
126 int ssg_sign[2];
127 int ssg_sign_toggle;
128 int ssg_cnt_of_l;
129 int ssg_freq_cnt2[8];
130 int ssg_sel_freq_l;
131 int ssg_cnt2_add;
132 int ssg_sel_eg_l[2];
133 int ssg_ch_of;
134 int ssg_cnt_reload;
135 int ssg_eg_of[2];
136 int ssg_fr_rst_l;
137 int ssg_noise_add;
138 int ssg_noise_cnt[2];
139 int ssg_noise_of_low;
140 int ssg_noise_of;
141 int ssg_test;
142 int ssg_noise_step;
143 int ssg_noise_lfsr[2];
144 int ssg_noise_bit;
145
146 int o_gpio_a;
147 int o_gpio_a_d;
148 int o_gpio_b;
149 int o_gpio_b_d;
150
151 int o_analog[3];
152
153 int o_data;
154 int o_data_d;
155 }
156 ssg_t;
157
158 void SSG_SetType(ssg_t* chip, int type);
159 void SSG_Reset(ssg_t* chip);
160 void SSG_Clock(ssg_t* chip, int clk);
161 void SSG_Write(ssg_t* chip, unsigned char addr, unsigned char val);