23#ifndef WAVEFORMGENERATOR_H
24#define WAVEFORMGENERATOR_H
26#include "siddefs-fp.h"
98 unsigned int shift_register;
103 unsigned int ring_msb_mask;
104 unsigned int no_noise;
105 unsigned int noise_output;
106 unsigned int no_noise_or_noise_output;
107 unsigned int no_pulse;
108 unsigned int pulse_output;
111 unsigned int waveform;
113 unsigned int waveform_output;
116 unsigned int accumulator;
122 unsigned int tri_saw_pipeline;
128 unsigned int shift_register_reset;
131 unsigned int floating_output_ttl;
145 void clock_shift_register(
unsigned int bit0);
147 unsigned int get_noise_writeback();
149 void write_shift_register();
151 void set_noise_output();
153 void set_no_noise_or_noise_output();
157 void shiftregBitfade();
160 void setWaveformModels(
matrix_t* models);
161 void setPulldownModels(
matrix_t* models);
169 void setModel(
bool is6581) { this->is6581 = is6581; }
191 model_pulldown(nullptr),
200 no_noise_or_noise_output(0),
205 accumulator(0x555555),
207 tri_saw_pipeline(0x555),
209 shift_register_reset(0),
210 floating_output_ttl(0),
220 void writeFREQ_LO(
unsigned char freq_lo) { freq = (freq & 0xff00) | (freq_lo & 0xff); }
227 void writeFREQ_HI(
unsigned char freq_hi) { freq = (freq_hi << 8 & 0xff00) | (freq & 0xff); }
234 void writePW_LO(
unsigned char pw_lo) { pw = (pw & 0xf00) | (pw_lo & 0x0ff); }
241 void writePW_HI(
unsigned char pw_hi) { pw = (pw_hi << 8 & 0xf00) | (pw & 0x0ff); }
266 unsigned char readOSC()
const {
return static_cast<unsigned char>(osc3 >> 4); }
291#if RESID_INLINING || defined(WAVEFORMGENERATOR_CPP)
301 if (unlikely(shift_register_reset != 0) && unlikely(--shift_register_reset == 0))
310 pulse_output = 0xfff;
315 const unsigned int accumulator_old = accumulator;
316 accumulator = (accumulator + freq) & 0xffffff;
319 const unsigned int accumulator_bits_set = ~accumulator_old & accumulator;
322 msb_rising = (accumulator_bits_set & 0x800000) != 0;
326 if (unlikely((accumulator_bits_set & 0x080000) != 0))
331 else if (unlikely(shift_pipeline != 0) && --shift_pipeline == 0)
334 clock_shift_register(((shift_register << 22) ^ (shift_register << 17)) & (1u << 22));
343 if (likely(waveform != 0))
345 const unsigned int ix = (accumulator ^ (~ringModulator->accumulator & ring_msb_mask)) >> 12;
349 waveform_output = wave[ix] & (no_pulse | pulse_output) & no_noise_or_noise_output;
350 if (pulldown !=
nullptr)
351 waveform_output = pulldown[waveform_output];
356 if ((waveform & 3) && !is6581)
358 osc3 = tri_saw_pipeline & (no_pulse | pulse_output) & no_noise_or_noise_output;
359 if (pulldown !=
nullptr)
360 osc3 = pulldown[osc3];
361 tri_saw_pipeline = wave[ix];
365 osc3 = waveform_output;
372 && ((waveform_output & 0x800) == 0))
373 accumulator &= 0x7fffff;
375 write_shift_register();
380 if (likely(floating_output_ttl != 0) && unlikely(--floating_output_ttl == 0))
398 pulse_output = ((accumulator >> 12) >= pw) ? 0xfff : 0x000;
400 return waveform_output;