23#ifndef WAVEFORMGENERATOR_H
24#define WAVEFORMGENERATOR_H
26#include "siddefs-fp.h"
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;
164 void shift_phase2(
unsigned int waveform_old,
unsigned int waveform_new);
166 void write_shift_register();
168 void set_noise_output();
170 void set_no_noise_or_noise_output();
174 void shiftregBitfade();
177 void setWaveformModels(
matrix_t* models);
178 void setPulldownModels(
matrix_t* models);
192 void setModel(
bool is6581) { this->is6581 = is6581; }
211 void writeFREQ_LO(
unsigned char freq_lo) { freq = (freq & 0xff00) | (freq_lo & 0xff); }
218 void writeFREQ_HI(
unsigned char freq_hi) { freq = (freq_hi << 8 & 0xff00) | (freq & 0xff); }
225 void writePW_LO(
unsigned char pw_lo) { pw = (pw & 0xf00) | (pw_lo & 0x0ff); }
232 void writePW_HI(
unsigned char pw_hi) { pw = (pw_hi << 8 & 0xf00) | (pw & 0x0ff); }
256 unsigned char readOSC()
const {
return static_cast<unsigned char>(osc3 >> 4); }
281#if RESID_INLINING || defined(WAVEFORMGENERATOR_CPP)
291 if (unlikely(shift_register_reset != 0) && unlikely(--shift_register_reset == 0))
294 std::cout <<
"shiftregBitfade" << std::endl;
297 shift_latch = shift_register;
304 test_or_reset =
true;
307 pulse_output = 0xfff;
312 const unsigned int accumulator_old = accumulator;
313 accumulator = (accumulator + freq) & 0xffffff;
316 const unsigned int accumulator_bits_set = ~accumulator_old & accumulator;
319 msb_rising = (accumulator_bits_set & 0x800000) != 0;
323 if (unlikely((accumulator_bits_set & 0x080000) != 0))
328 else if (unlikely(shift_pipeline != 0))
330 switch (--shift_pipeline)
334 std::cout <<
"shift phase 2" << std::endl;
336 shift_phase2(waveform, waveform);
340 std::cout <<
"shift phase 1" << std::endl;
343 test_or_reset =
false;
344 shift_latch = shift_register;
355 if (likely(waveform != 0))
357 const unsigned int ix = (accumulator ^ (~prevVoice->accumulator & ring_msb_mask)) >> 12;
361 waveform_output = wave[ix] & (no_pulse | pulse_output) & no_noise_or_noise_output;
362 if (pulldown !=
nullptr)
363 waveform_output = pulldown[waveform_output];
368 if ((waveform & 3) && !is6581)
370 osc3 = tri_saw_pipeline & (no_pulse | pulse_output) & no_noise_or_noise_output;
371 if (pulldown !=
nullptr)
372 osc3 = pulldown[osc3];
373 tri_saw_pipeline = wave[ix];
377 osc3 = waveform_output;
382 if (is6581 && (waveform & 0x2) && ((waveform_output & 0x800) == 0))
385 accumulator &= 0x7fffff;
388 write_shift_register();
393 if (likely(floating_output_ttl != 0) && unlikely(--floating_output_ttl == 0))
411 pulse_output = ((accumulator >> 12) >= pw) ? 0xfff : 0x000;
413 return waveform_output;