1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
|
// ---------------------------------------------------------------------------
// This file is part of reSID, a MOS6581 SID emulator engine.
// Copyright (C) 2004 Dag Lem <resid@nimrod.no>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
// ---------------------------------------------------------------------------
#define __WAVE_CC__
#include "wave.h"
// ----------------------------------------------------------------------------
// Constructor.
// ----------------------------------------------------------------------------
WaveformGenerator::WaveformGenerator()
{
sync_source = this;
set_chip_model(MOS6581);
reset();
}
// ----------------------------------------------------------------------------
// Set sync source.
// ----------------------------------------------------------------------------
void WaveformGenerator::set_sync_source(WaveformGenerator* source)
{
sync_source = source;
source->sync_dest = this;
}
// ----------------------------------------------------------------------------
// Set chip model.
// ----------------------------------------------------------------------------
void WaveformGenerator::set_chip_model(chip_model model)
{
if (model == MOS6581) {
wave__ST = wave6581__ST;
wave_P_T = wave6581_P_T;
wave_PS_ = wave6581_PS_;
wave_PST = wave6581_PST;
}
else {
wave__ST = wave8580__ST;
wave_P_T = wave8580_P_T;
wave_PS_ = wave8580_PS_;
wave_PST = wave8580_PST;
}
}
// ----------------------------------------------------------------------------
// Register functions.
// ----------------------------------------------------------------------------
void WaveformGenerator::writeFREQ_LO(reg8 freq_lo)
{
freq = ( freq & 0xff00 ) | ( freq_lo & 0x00ff );
}
void WaveformGenerator::writeFREQ_HI(reg8 freq_hi)
{
freq = ( (freq_hi << 8) & 0xff00 ) | ( freq & 0x00ff );
}
void WaveformGenerator::writePW_LO(reg8 pw_lo)
{
pw = ( pw & 0xf00 ) | ( pw_lo & 0x0ff );
}
void WaveformGenerator::writePW_HI(reg8 pw_hi)
{
pw = ( (pw_hi << 8) & 0xf00 ) | ( pw & 0x0ff );
}
void WaveformGenerator::writeCONTROL_REG(reg8 control)
{
waveform = (control >> 4) & 0x0f;
ring_mod = control & 0x04;
sync = control & 0x02;
reg8 test_next = control & 0x08;
// Test bit set.
// The accumulator and the shift register are both cleared.
// NB! The shift register is not really cleared immediately. It seems like
// the individual bits in the shift register start to fade down towards
// zero when test is set. All bits reach zero within approximately
// $2000 - $4000 cycles.
// This is not modeled. There should fortunately be little audible output
// from this peculiar behavior.
if (test_next) {
accumulator = 0;
shift_register = 0;
}
// Test bit cleared.
// The accumulator starts counting, and the shift register is reset to
// the value 0x7ffff8.
// NB! The shift register will not actually be set to this exact value if the
// shift register bits have not had time to fade to zero.
// This is not modeled.
else if (test) {
shift_register = 0x7ffff8;
}
test = test_next;
// The gate bit is handled by the EnvelopeGenerator.
}
reg8 WaveformGenerator::readOSC()
{
return output() >> 4;
}
// ----------------------------------------------------------------------------
// SID reset.
// ----------------------------------------------------------------------------
void WaveformGenerator::reset()
{
accumulator = 0;
shift_register = 0x7ffff8;
freq = 0;
pw = 0;
test = 0;
ring_mod = 0;
sync = 0;
msb_rising = false;
}
|