23#ifndef WAVEFORMGENERATOR_H
24#define WAVEFORMGENERATOR_H
26#include "siddefs-fp.h"
96 matrix_t* model_wave =
nullptr;
97 matrix_t* model_pulldown =
nullptr;
99 short* wave =
nullptr;
100 short* pulldown =
nullptr;
105 unsigned int shift_register = 0;
108 unsigned int shift_latch = 0;
111 int shift_pipeline = 0;
113 unsigned int ring_msb_mask = 0;
114 unsigned int no_noise = 0;
115 unsigned int noise_output = 0;
116 unsigned int no_noise_or_noise_output = 0;
117 unsigned int no_pulse = 0;
118 unsigned int pulse_output = 0;
121 unsigned int waveform = 0;
123 unsigned int waveform_output = 0;
126 unsigned int accumulator = 0x555555;
129 unsigned int freq = 0;
132 unsigned int tri_saw_pipeline = 0x555;
135 unsigned int osc3 = 0;
138 unsigned int shift_register_reset = 0;
141 unsigned int floating_output_ttl = 0;
153 bool msb_rising =
false;
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 void writeFREQ_LO(
unsigned char freq_lo) { freq = (freq & 0xff00) | (freq_lo & 0xff); }
209 void writeFREQ_HI(
unsigned char freq_hi) { freq = (freq_hi << 8 & 0xff00) | (freq & 0xff); }
216 void writePW_LO(
unsigned char pw_lo) { pw = (pw & 0xf00) | (pw_lo & 0x0ff); }
223 void writePW_HI(
unsigned char pw_hi) { pw = (pw_hi << 8 & 0xf00) | (pw & 0x0ff); }
248 unsigned char readOSC()
const {
return static_cast<unsigned char>(osc3 >> 4); }
273#if RESID_INLINING || defined(WAVEFORMGENERATOR_CPP)
283 if (unlikely(shift_register_reset != 0) && unlikely(--shift_register_reset == 0))
286 std::cout <<
"shiftregBitfade" << std::endl;
289 shift_latch = shift_register;
296 test_or_reset =
true;
299 pulse_output = 0xfff;
304 const unsigned int accumulator_old = accumulator;
305 accumulator = (accumulator + freq) & 0xffffff;
308 const unsigned int accumulator_bits_set = ~accumulator_old & accumulator;
311 msb_rising = (accumulator_bits_set & 0x800000) != 0;
315 if (unlikely((accumulator_bits_set & 0x080000) != 0))
320 else if (unlikely(shift_pipeline != 0))
322 switch (--shift_pipeline)
326 std::cout <<
"shift phase 2" << std::endl;
328 shift_phase2(waveform, waveform);
332 std::cout <<
"shift phase 1" << std::endl;
335 test_or_reset =
false;
336 shift_latch = shift_register;
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;
354 if (pulldown !=
nullptr)
355 waveform_output = pulldown[waveform_output];
360 if ((waveform & 3) && !is6581)
362 osc3 = tri_saw_pipeline & (no_pulse | pulse_output) & no_noise_or_noise_output;
363 if (pulldown !=
nullptr)
364 osc3 = pulldown[osc3];
365 tri_saw_pipeline = wave[ix];
369 osc3 = waveform_output;
374 if (is6581 && (waveform & 0x2) && ((waveform_output & 0x800) == 0))
377 accumulator &= 0x7fffff;
380 write_shift_register();
385 if (likely(floating_output_ttl != 0) && unlikely(--floating_output_ttl == 0))
403 pulse_output = ((accumulator >> 12) >= pw) ? 0xfff : 0x000;
405 return waveform_output;