23 #ifndef WAVEFORMGENERATOR_H
24 #define WAVEFORMGENERATOR_H
26 #include "siddefs-fp.h"
96 unsigned int shift_register;
101 unsigned int ring_msb_mask;
102 unsigned int no_noise;
103 unsigned int noise_output;
104 unsigned int no_noise_or_noise_output;
105 unsigned int no_pulse;
106 unsigned int pulse_output;
109 unsigned int waveform;
111 unsigned int waveform_output;
114 unsigned int accumulator;
120 unsigned int tri_saw_pipeline;
124 unsigned int shift_register_reset;
126 unsigned int floating_output_ttl;
142 void clock_shift_register(
unsigned int bit0);
144 unsigned int get_noise_writeback();
146 void write_shift_register();
148 void set_noise_output();
152 void shiftregBitfade();
155 void setWaveformModels(
matrix_t* models);
193 no_noise_or_noise_output(no_noise | noise_output),
198 accumulator(0x555555),
200 tri_saw_pipeline(0x555),
202 shift_register_reset(0),
203 floating_output_ttl(0),
214 void writeFREQ_LO(
unsigned char freq_lo) { freq = (freq & 0xff00) | (freq_lo & 0xff); }
221 void writeFREQ_HI(
unsigned char freq_hi) { freq = (freq_hi << 8 & 0xff00) | (freq & 0xff); }
228 void writePW_LO(
unsigned char pw_lo) { pw = (pw & 0xf00) | (pw_lo & 0x0ff); }
235 void writePW_HI(
unsigned char pw_hi) { pw = (pw_hi << 8 & 0xf00) | (pw & 0x0ff); }
260 unsigned char readOSC()
const {
return static_cast<unsigned char>(osc3 >> 4); }
285 #if RESID_INLINING || defined(WAVEFORMGENERATOR_CPP)
295 if (unlikely(shift_register_reset != 0) && unlikely(--shift_register_reset == 0))
304 pulse_output = 0xfff;
309 const unsigned int accumulator_old = accumulator;
310 accumulator = (accumulator + freq) & 0xffffff;
313 const unsigned int accumulator_bits_set = ~accumulator_old & accumulator;
316 msb_rising = (accumulator_bits_set & 0x800000) != 0;
320 if (unlikely((accumulator_bits_set & 0x080000) != 0))
325 else if (unlikely(shift_pipeline != 0) && --shift_pipeline == 0)
328 clock_shift_register(((shift_register << 22) ^ (shift_register << 17)) & (1 << 22));
333 static unsigned int noise_pulse6581(
unsigned int noise)
335 return (noise < 0xf00) ? 0x000 : noise & (noise << 1) & (noise << 2);
338 static unsigned int noise_pulse8580(
unsigned int noise)
340 return (noise < 0xfc0) ? noise & (noise << 1) : 0xfc0;
347 if (likely(waveform != 0))
349 const unsigned int ix = (accumulator ^ (~ringModulator->accumulator & ring_msb_mask)) >> 12;
353 waveform_output = wave[ix] & (no_pulse | pulse_output) & no_noise_or_noise_output;
356 if (unlikely((waveform & 0xc) == 0xc))
357 waveform_output = is6581 ? noise_pulse6581(waveform_output) : noise_pulse8580(waveform_output);
361 if ((waveform & 3) && !is6581)
363 osc3 = tri_saw_pipeline & (no_pulse | pulse_output) & no_noise_or_noise_output;
364 tri_saw_pipeline = wave[ix];
368 osc3 = waveform_output;
374 if ((waveform & 2) && unlikely(waveform & 0xd) && is6581)
375 accumulator &= (waveform_output << 12) | 0x7fffff;
377 write_shift_register();
382 if (likely(floating_output_ttl != 0) && unlikely(--floating_output_ttl == 0))
400 pulse_output = ((accumulator >> 12) >= pw) ? 0xfff : 0x000;
404 return dac[waveform_output];