4545#include <speex_resampler.h>
4646#include <stdint.h>
4747#include <stdbool.h>
48- #include "snd/su .h"
48+ #include "snd/sgu .h"
4949
5050#ifdef __cplusplus
5151extern "C" {
@@ -96,79 +96,6 @@ extern "C" {
9696#define SGU1_CS (1ULL << SGU1_PIN_CS)
9797#define SGU1_SAMPLE (1ULL << SGU1_PIN_SAMPLE)
9898
99- #define SGU1_NUM_CHANNELS (8)
100- #define SGU1_NUM_CHANNEL_REGS (32)
101-
102- // control registers
103- #define SGU1_REG_CHANNEL_SELECT (0x00)
104-
105- // channel registers
106- #define SGU1_CHAN_FREQ_LO (0x00)
107- #define SGU1_CHAN_FREQ_HI (0x01)
108- #define SGU1_CHAN_VOL (0x02)
109- #define SGU1_CHAN_PAN (0x03)
110- #define SGU1_CHAN_FLAGS0 (0x04)
111- #define SGU1_CHAN_FLAGS1 (0x05)
112- #define SGU1_CHAN_CUTOFF_LO (0x06)
113- #define SGU1_CHAN_CUTOFF_HI (0x07)
114- #define SGU1_CHAN_DUTY (0x08)
115- #define SGU1_CHAN_RESON (0x09)
116- #define SGU1_CHAN_PCMPOS_LO (0x0A)
117- #define SGU1_CHAN_PCMPOS_HI (0x0B)
118- #define SGU1_CHAN_PCMBND_LO (0x0C)
119- #define SGU1_CHAN_PCMBND_HI (0x0D)
120- #define SGU1_CHAN_PCMRST_LO (0x0E)
121- #define SGU1_CHAN_PCMRST_HI (0x0F)
122- #define SGU1_CHAN_SWFREQ_SPEED_LO (0x10)
123- #define SGU1_CHAN_SWFREQ_SPEED_HI (0x11)
124- #define SGU1_CHAN_SWFREQ_AMT (0x12)
125- #define SGU1_CHAN_SWFREQ_BOUND (0x13)
126- #define SGU1_CHAN_SWVOL_SPEED_LO (0x14)
127- #define SGU1_CHAN_SWVOL_SPEED_HI (0x15)
128- #define SGU1_CHAN_SWVOL_AMT (0x16)
129- #define SGU1_CHAN_SWVOL_BOUND (0x17)
130- #define SGU1_CHAN_SWCUT_SPEED_LO (0x18)
131- #define SGU1_CHAN_SWCUT_SPEED_HI (0x19)
132- #define SGU1_CHAN_SWCUT_AMT (0x1A)
133- #define SGU1_CHAN_SWCUT_BOUND (0x1B)
134- #define SGU1_CHAN_SPECIAL1C (0x1C)
135- #define SGU1_CHAN_SPECIAL1D (0x1D)
136- #define SGU1_CHAN_RESTIMER_LO (0x1E)
137- #define SGU1_CHAN_RESTIMER_HI (0x1F)
138-
139- // channel control bits
140- #define SGU1_FLAGS0_WAVE_SHIFT (0)
141- #define SGU1_FLAGS0_WAVE_MASK (0x7 << SGU1_FLAGS0_WAVE_SHIFT)
142- #define SGU1_FLAGS0_PCM_SHIFT (3)
143- #define SGU1_FLAGS0_PCM_MASK (0x1 << SGU1_FLAGS0_PCM_SHIFT)
144- #define SGU1_FLAGS0_CONTROL_SHIFT (4)
145- #define SGU1_FLAGS0_CONTROL_MASK (0xF << SGU1_FLAGS0_CONTROL_SHIFT)
146- #define SGU1_FLAGS0_CTL_RING_MOD (1 << 4)
147- #define SGU1_FLAGS0_CTL_NSLOW (1 << 5)
148- #define SGU1_FLAGS0_CTL_NSHIGH (1 << 6)
149- #define SGU1_FLAGS0_CTL_NSBAND (1 << 7)
150-
151- #define SGU1_FLAGS0_WAVE_PULSE (0)
152- #define SGU1_FLAGS0_WAVE_SAWTOOTH (1)
153- #define SGU1_FLAGS0_WAVE_SINE (2)
154- #define SGU1_FLAGS0_WAVE_TRIANGLE (3)
155- #define SGU1_FLAGS0_WAVE_NOISE (4)
156- #define SGU1_FLAGS0_WAVE_PERIODIC_NOISE (5)
157- #define SGU1_FLAGS0_WAVE_XOR_SINE (6)
158- #define SGU1_FLAGS0_WAVE_XOR_TRIANGLE (7)
159-
160- #define SGU1_FLAGS1_PHASE_RESET (1 << 0)
161- #define SGU1_FLAGS1_FILTER_PHASE_RESET (1 << 1)
162- #define SGU1_FLAGS1_PCM_LOOP (1 << 2)
163- #define SGU1_FLAGS1_TIMER_SYNC (1 << 3)
164- #define SGU1_FLAGS1_FREQ_SWEEP (1 << 4)
165- #define SGU1_FLAGS1_VOL_SWEEP (1 << 5)
166- #define SGU1_FLAGS1_CUT_SWEEP (1 << 6)
167-
168- #define SGU1_VOL_SWEEP_INC (1 << 5)
169- #define SGU1_VOL_SWEEP_WRAP (1 << 6)
170- #define SGU1_VOL_SWEEP_BOUNCE (1 << 7)
171-
17299#define SGU1_AUDIO_CHANNELS (2)
173100#define SGU1_AUDIO_SAMPLES (1024)
174101
@@ -180,10 +107,9 @@ typedef struct {
180107
181108// tsu instance state
182109typedef struct {
183- int sound_hz ;
184110 // sound unit instance
185- SoundUnit su ;
186- uint8_t reg [ 32 ] ;
111+ struct SGU sgu ;
112+ uint8_t selected_channel ;
187113 int tick_period ;
188114 int tick_counter ;
189115 // sample generation state
@@ -193,7 +119,7 @@ typedef struct {
193119 struct {
194120 int sample_pos ;
195121 float sample_buffer [SGU1_AUDIO_SAMPLES ];
196- } voice [SGU1_NUM_CHANNELS ];
122+ } voice [SGU_CHNS ];
197123 // debug inspection
198124 uint64_t pins ;
199125} sgu1_t ;
@@ -208,6 +134,7 @@ uint64_t sgu1_tick(sgu1_t* sgu, uint64_t pins);
208134// for use by debugger
209135uint8_t sgu1_reg_read (sgu1_t * sgu , uint8_t reg );
210136void sgu1_reg_write (sgu1_t * sgu , uint8_t reg , uint8_t data );
137+ void sgu1_direct_reg_write (sgu1_t * sgu , uint16_t reg , uint8_t data );
211138
212139#ifdef __cplusplus
213140} // extern "C"
0 commit comments