23#ifndef WAVEFORMGENERATOR_H
24#define WAVEFORMGENERATOR_H
26#include "siddefs-fp.h"
97 short* wave =
nullptr;
98 short* pulldown =
nullptr;
103 unsigned int shift_register = 0;
106 unsigned int shift_latch = 0;
109 int shift_pipeline = 0;
111 unsigned int ring_msb_mask = 0;
112 unsigned int no_noise = 0;
113 unsigned int noise_output = 0;
114 unsigned int no_noise_or_noise_output = 0;
115 unsigned int no_pulse = 0;
116 unsigned int pulse_output = 0;
119 unsigned int waveform = 0;
121 unsigned int waveform_output = 0;
124 unsigned int accumulator = 0x555555;
127 unsigned int freq = 0;
130 unsigned int tri_saw_pipeline = 0x555;
133 unsigned int osc3 = 0;
136 unsigned int shift_register_reset = 0;
139 unsigned int floating_output_ttl = 0;
151 bool msb_rising =
false;
162 void shift_phase2(
unsigned int waveform_old,
unsigned int waveform_new);
164 void write_shift_register();
166 void set_noise_output();
168 void set_no_noise_or_noise_output();
172 void shiftregBitfade();
175 void setWaveformModels(
matrix_t* models);
176 void setPulldownModels(
matrix_t* models);
190 void setModel(
bool is6581) { this->is6581 = is6581; }
209 void writeFREQ_LO(
unsigned char freq_lo) { freq = (freq & 0xff00) | (freq_lo & 0xff); }
216 void writeFREQ_HI(
unsigned char freq_hi) { freq = (freq_hi << 8 & 0xff00) | (freq & 0xff); }
223 void writePW_LO(
unsigned char pw_lo) { pw = (pw & 0xf00) | (pw_lo & 0x0ff); }
230 void writePW_HI(
unsigned char pw_hi) { pw = (pw_hi << 8 & 0xf00) | (pw & 0x0ff); }
254 unsigned char readOSC()
const {
return static_cast<unsigned char>(osc3 >> 4); }
279#if RESIDFP_INLINING || defined(WAVEFORMGENERATOR_CPP)
289 if (unlikely(shift_register_reset != 0) && unlikely(--shift_register_reset == 0))
292 std::cout <<
"shiftregBitfade" << std::endl;
295 shift_latch = shift_register;
302 test_or_reset =
true;
305 pulse_output = 0xfff;
310 const unsigned int accumulator_old = accumulator;
311 accumulator = (accumulator + freq) & 0xffffff;
314 const unsigned int accumulator_bits_set = ~accumulator_old & accumulator;
317 msb_rising = (accumulator_bits_set & 0x800000) != 0;
321 if (unlikely((accumulator_bits_set & 0x080000) != 0))
326 else if (unlikely(shift_pipeline != 0))
328 switch (--shift_pipeline)
332 std::cout <<
"shift phase 2" << std::endl;
334 shift_phase2(waveform, waveform);
338 std::cout <<
"shift phase 1" << std::endl;
341 test_or_reset =
false;
342 shift_latch = shift_register;
353 if (likely(waveform != 0))
355 const unsigned int ix = (accumulator ^ (~prevVoice->accumulator & ring_msb_mask)) >> 12;
359 waveform_output = wave[ix] & (no_pulse | pulse_output) & no_noise_or_noise_output;
360 if (pulldown !=
nullptr)
361 waveform_output = pulldown[waveform_output];
366 if ((waveform & 3) && !is6581)
368 osc3 = tri_saw_pipeline & (no_pulse | pulse_output) & no_noise_or_noise_output;
369 if (pulldown !=
nullptr)
370 osc3 = pulldown[osc3];
371 tri_saw_pipeline = wave[ix];
375 osc3 = waveform_output;
380 if (is6581 && (waveform & 0x2) && ((waveform_output & 0x800) == 0))
383 accumulator &= 0x7fffff;
386 write_shift_register();
391 if (likely(floating_output_ttl != 0) && unlikely(--floating_output_ttl == 0))
409 pulse_output = ((accumulator >> 12) >= pw) ? 0xfff : 0x000;
411 return waveform_output;