23 #include "resid-config.h" 42 void set_chip_model(chip_model model);
45 void clock(cycle_count delta_t);
49 void writeFREQ_LO(reg8);
50 void writeFREQ_HI(reg8);
51 void writePW_LO(reg8);
52 void writePW_HI(reg8);
53 void writeCONTROL_REG(reg8);
60 void set_waveform_output();
61 void set_waveform_output(cycle_count delta_t);
64 void clock_shift_register();
65 void write_shift_register();
66 void reset_shift_register();
67 void set_noise_output();
86 cycle_count shift_register_reset;
88 cycle_count shift_pipeline;
92 unsigned short no_noise;
93 unsigned short noise_output;
94 unsigned short no_noise_or_noise_output;
95 unsigned short no_pulse;
96 unsigned short pulse_output;
108 reg12 waveform_output;
110 cycle_count floating_output_ttl;
112 chip_model sid_model;
115 unsigned short* wave;
116 static unsigned short model_wave[2][8][1 << 12];
118 static unsigned short model_dac[2][1 << 12];
131 #if RESID_INLINING || defined(RESID_WAVE_CC) 137 void WaveformGenerator::clock()
139 if (unlikely(test)) {
141 if (unlikely(shift_register_reset) && unlikely(!--shift_register_reset)) {
142 reset_shift_register();
146 pulse_output = 0xfff;
150 reg24 accumulator_next = (accumulator + freq) & 0xffffff;
151 reg24 accumulator_bits_set = ~accumulator & accumulator_next;
152 accumulator = accumulator_next;
155 msb_rising = (accumulator_bits_set & 0x800000) ?
true :
false;
159 if (unlikely(accumulator_bits_set & 0x080000)) {
163 else if (unlikely(shift_pipeline) && !--shift_pipeline) {
164 clock_shift_register();
173 void WaveformGenerator::clock(cycle_count delta_t)
175 if (unlikely(test)) {
177 if (shift_register_reset) {
178 shift_register_reset -= delta_t;
179 if (unlikely(shift_register_reset <= 0)) {
180 reset_shift_register();
185 pulse_output = 0xfff;
189 reg24 delta_accumulator = delta_t*freq;
190 reg24 accumulator_next = (accumulator + delta_accumulator) & 0xffffff;
191 reg24 accumulator_bits_set = ~accumulator & accumulator_next;
192 accumulator = accumulator_next;
195 msb_rising = (accumulator_bits_set & 0x800000) ?
true :
false;
202 reg24 shift_period = 0x100000;
204 while (delta_accumulator) {
205 if (likely(delta_accumulator < shift_period)) {
206 shift_period = delta_accumulator;
209 if (likely(shift_period <= 0x080000)) {
211 if (((accumulator - shift_period) & 0x080000) || !(accumulator & 0x080000))
218 if (((accumulator - shift_period) & 0x080000) && !(accumulator & 0x080000))
227 clock_shift_register();
229 delta_accumulator -= shift_period;
234 pulse_output = (accumulator >> 12) >= pw ? 0xfff : 0x000;
247 void WaveformGenerator::synchronize()
252 if (unlikely(msb_rising) && sync_dest->sync && !(sync && sync_source->msb_rising)) {
253 sync_dest->accumulator = 0;
312 RESID_INLINE
void WaveformGenerator::clock_shift_register()
315 reg24 bit0 = ((shift_register >> 22) ^ (shift_register >> 17)) & 0x1;
316 shift_register = ((shift_register << 1) | bit0) & 0x7fffff;
322 RESID_INLINE
void WaveformGenerator::write_shift_register()
331 ~((1<<20)|(1<<18)|(1<<14)|(1<<11)|(1<<9)|(1<<5)|(1<<2)|(1<<0)) |
332 ((waveform_output & 0x800) << 9) |
333 ((waveform_output & 0x400) << 8) |
334 ((waveform_output & 0x200) << 5) |
335 ((waveform_output & 0x100) << 3) |
336 ((waveform_output & 0x080) << 2) |
337 ((waveform_output & 0x040) >> 1) |
338 ((waveform_output & 0x020) >> 3) |
339 ((waveform_output & 0x010) >> 4);
341 noise_output &= waveform_output;
342 no_noise_or_noise_output = no_noise | noise_output;
345 RESID_INLINE
void WaveformGenerator::reset_shift_register()
347 shift_register = 0x7fffff;
348 shift_register_reset = 0;
354 RESID_INLINE
void WaveformGenerator::set_noise_output()
357 ((shift_register & 0x100000) >> 9) |
358 ((shift_register & 0x040000) >> 8) |
359 ((shift_register & 0x004000) >> 5) |
360 ((shift_register & 0x000800) >> 3) |
361 ((shift_register & 0x000200) >> 2) |
362 ((shift_register & 0x000020) << 1) |
363 ((shift_register & 0x000004) << 3) |
364 ((shift_register & 0x000001) << 4);
366 no_noise_or_noise_output = no_noise | noise_output;
449 void WaveformGenerator::set_waveform_output()
452 if (likely(waveform)) {
455 int ix = (accumulator ^ (sync_source->accumulator & ring_msb_mask)) >> 12;
457 wave[ix] & (no_pulse | pulse_output) & no_noise_or_noise_output;
458 if (unlikely(waveform > 0x8)) {
460 write_shift_register();
465 if (likely(floating_output_ttl) && unlikely(!--floating_output_ttl)) {
482 pulse_output = -((accumulator >> 12) >= pw) & 0xfff;
486 void WaveformGenerator::set_waveform_output(cycle_count delta_t)
489 if (likely(waveform)) {
492 int ix = (accumulator ^ (sync_source->accumulator & ring_msb_mask)) >> 12;
494 wave[ix] & (no_pulse | pulse_output) & no_noise_or_noise_output;
495 if (unlikely(waveform > 0x8)) {
499 write_shift_register();
503 if (likely(floating_output_ttl)) {
505 floating_output_ttl -= delta_t;
506 if (unlikely(floating_output_ttl <= 0)) {
507 floating_output_ttl = 0;
545 short WaveformGenerator::output()
549 return model_dac[sid_model][waveform_output];
552 #endif // RESID_INLINING || defined(RESID_WAVE_CC) 556 #endif // not RESID_WAVE_H