23#ifndef WAVEFORMGENERATOR_H
24#define WAVEFORMGENERATOR_H
26#include "siddefs-fp.h"
105 unsigned int shift_register;
108 unsigned int shift_latch;
113 unsigned int ring_msb_mask;
114 unsigned int no_noise;
115 unsigned int noise_output;
116 unsigned int no_noise_or_noise_output;
117 unsigned int no_pulse;
118 unsigned int pulse_output;
121 unsigned int waveform;
123 unsigned int waveform_output;
126 unsigned int accumulator;
132 unsigned int tri_saw_pipeline;
138 unsigned int shift_register_reset;
141 unsigned int floating_output_ttl;
158 void shift_phase2(
unsigned int waveform_old,
unsigned int waveform_new);
160 void write_shift_register();
162 void set_noise_output();
164 void set_no_noise_or_noise_output();
168 void shiftregBitfade();
171 void setWaveformModels(
matrix_t* models);
172 void setPulldownModels(
matrix_t* models);
180 void setModel(
bool is6581) { this->is6581 = is6581; }
202 model_pulldown(nullptr),
211 no_noise_or_noise_output(0),
216 accumulator(0x555555),
218 tri_saw_pipeline(0x555),
220 shift_register_reset(0),
221 floating_output_ttl(0),
231 void writeFREQ_LO(
unsigned char freq_lo) { freq = (freq & 0xff00) | (freq_lo & 0xff); }
238 void writeFREQ_HI(
unsigned char freq_hi) { freq = (freq_hi << 8 & 0xff00) | (freq & 0xff); }
245 void writePW_LO(
unsigned char pw_lo) { pw = (pw & 0xf00) | (pw_lo & 0x0ff); }
252 void writePW_HI(
unsigned char pw_hi) { pw = (pw_hi << 8 & 0xf00) | (pw & 0x0ff); }
277 unsigned char readOSC()
const {
return static_cast<unsigned char>(osc3 >> 4); }
302#if RESID_INLINING || defined(WAVEFORMGENERATOR_CPP)
312 if (unlikely(shift_register_reset != 0) && unlikely(--shift_register_reset == 0))
315 std::cout <<
"shiftregBitfade" << std::endl;
318 shift_latch = shift_register;
325 test_or_reset =
true;
328 pulse_output = 0xfff;
333 const unsigned int accumulator_old = accumulator;
334 accumulator = (accumulator + freq) & 0xffffff;
337 const unsigned int accumulator_bits_set = ~accumulator_old & accumulator;
340 msb_rising = (accumulator_bits_set & 0x800000) != 0;
344 if (unlikely((accumulator_bits_set & 0x080000) != 0))
349 else if (unlikely(shift_pipeline != 0))
351 switch (--shift_pipeline)
355 std::cout <<
"shift phase 2" << std::endl;
357 shift_phase2(waveform, waveform);
361 std::cout <<
"shift phase 1" << std::endl;
364 test_or_reset =
false;
365 shift_latch = shift_register;
376 if (likely(waveform != 0))
378 const unsigned int ix = (accumulator ^ (~ringModulator->accumulator & ring_msb_mask)) >> 12;
382 waveform_output = wave[ix] & (no_pulse | pulse_output) & no_noise_or_noise_output;
383 if (pulldown !=
nullptr)
384 waveform_output = pulldown[waveform_output];
389 if ((waveform & 3) && !is6581)
391 osc3 = tri_saw_pipeline & (no_pulse | pulse_output) & no_noise_or_noise_output;
392 if (pulldown !=
nullptr)
393 osc3 = pulldown[osc3];
394 tri_saw_pipeline = wave[ix];
398 osc3 = waveform_output;
405 && ((waveform_output & 0x800) == 0))
406 accumulator &= 0x7fffff;
408 write_shift_register();
413 if (likely(floating_output_ttl != 0) && unlikely(--floating_output_ttl == 0))
431 pulse_output = ((accumulator >> 12) >= pw) ? 0xfff : 0x000;
433 return waveform_output;