96 rc_matrix_t model_wave;
97 rc_matrix_t model_pulldown;
99 int16_t* wave =
nullptr;
100 int16_t* pulldown =
nullptr;
105 uint32_t shift_register = 0;
108 uint32_t shift_latch = 0;
111 int shift_pipeline = 0;
113 uint32_t ring_msb_mask = 0;
114 uint32_t no_noise = 0;
115 uint32_t noise_output = 0;
116 uint32_t no_noise_or_noise_output = 0;
117 uint32_t no_pulse = 0;
118 uint32_t pulse_output = 0;
120 uint32_t waveform_output = 0;
123 uint32_t accumulator = 0x555555;
129 uint32_t tri_saw_pipeline = 0x555;
135 unsigned int shift_register_reset = 0;
138 unsigned int floating_output_ttl = 0;
141 uint8_t waveform = 0;
153 bool msb_rising =
false;
157 bool strongPS =
false;
158 bool msb_pulldown =
false;
167 void shift_phase2(uint8_t waveform_old, uint8_t waveform_new);
169 void write_shift_register();
171 void set_noise_output();
173 void set_no_noise_or_noise_output();
177 void shiftregBitfade();
179 inline void setWave() { wave = (*model_wave)[waveform & 0x3]; }
181 inline void setPulldown()
185 switch (waveform & 0x7)
188 pulldown = (*model_pulldown)[0];
191 pulldown = (waveform & 0x8) ? (*model_pulldown)[4] :
nullptr;
194 pulldown = (*model_pulldown)[1];
197 pulldown = (*model_pulldown)[2];
200 pulldown = (*model_pulldown)[3];
208 void setWaveformModels(rc_matrix_t models);
209 void setPulldownModels(rc_matrix_t models);
211 inline void setStrongPS(
bool sps) { strongPS = sps; }
225 void setModel(
bool new_is6581) { is6581 = new_is6581; }
244 void writeFREQ_LO(uint8_t freq_lo) { freq = (freq & 0xff00) | (freq_lo & 0xff); }
251 void writeFREQ_HI(uint8_t freq_hi) { freq = (freq_hi << 8 & 0xff00) | (freq & 0xff); }
258 void writePW_LO(uint8_t pw_lo) { pw = (pw & 0xf00) | (pw_lo & 0x0ff); }
265 void writePW_HI(uint8_t pw_hi) { pw = (pw_hi << 8 & 0xf00) | (pw & 0x0ff); }
289 uint8_t
readOSC()
const {
return static_cast<uint8_t
>(osc3 >> 4); }
324 if (unlikely(shift_register_reset != 0) && unlikely(--shift_register_reset == 0))
327 std::cout <<
"shiftregBitfade" << std::endl;
330 shift_latch = shift_register;
337 test_or_reset =
true;
340 pulse_output = 0xfff;
345 const uint32_t accumulator_old = accumulator;
346 accumulator = (accumulator + freq) & 0xffffff;
349 const uint32_t accumulator_bits_set = ~accumulator_old & accumulator;
352 msb_rising = (accumulator_bits_set & 0x800000) != 0;
356 if (unlikely((accumulator_bits_set & 0x080000) != 0))
361 else if (unlikely(shift_pipeline != 0))
363 switch (--shift_pipeline)
367 std::cout <<
"shift phase 2" << std::endl;
369 shift_phase2(waveform, waveform);
373 std::cout <<
"shift phase 1" << std::endl;
376 test_or_reset =
false;
377 shift_latch = shift_register;
388 if (likely(waveform != 0))
390 const uint32_t ix = (accumulator ^ (~prevVoice->accumulator & ring_msb_mask)) >> 12;
394 waveform_output = wave[ix] & (no_pulse | pulse_output) & no_noise_or_noise_output;
395 if (pulldown !=
nullptr)
396 waveform_output = pulldown[waveform_output];
401 if (!is6581 && (waveform & 3))
403 osc3 = tri_saw_pipeline & (no_pulse | pulse_output) & no_noise_or_noise_output;
404 if (pulldown !=
nullptr)
405 osc3 = pulldown[osc3];
406 tri_saw_pipeline = wave[ix];
410 osc3 = waveform_output;
416 if (msb_pulldown && ((waveform_output & 0x800) == 0))
419 accumulator &= 0x7fffff;
422 write_shift_register();
427 if (likely(floating_output_ttl != 0) && unlikely(--floating_output_ttl == 0))
445 pulse_output = ((accumulator >> 12) >= pw) ? 0xfff : 0x000;
447 return waveform_output;