public State read_state() {
		State state = new State();
		int i, j;

		for (i = 0, j = 0; i < 3; i++, j += 7) {
			WaveformGenerator wave = voice[i].wave;
			EnvelopeGenerator envelope = voice[i].envelope;
			state.sid_register[j + 0] = (char) (wave.freq & 0xff);
			state.sid_register[j + 1] = (char) (wave.freq >> 8);
			state.sid_register[j + 2] = (char) (wave.pw & 0xff);
			state.sid_register[j + 3] = (char) (wave.pw >> 8);
			state.sid_register[j + 4] = (char) ((wave.waveform << 4)
					| ((wave.test != 0) ? 0x08 : 0)
					| ((wave.ring_mod != 0) ? 0x04 : 0)
					| ((wave.sync != 0) ? 0x02 : 0) | ((envelope.gate != 0) ? 0x01
					: 0));
			state.sid_register[j + 5] = (char) ((envelope.attack << 4) | envelope.decay);
			state.sid_register[j + 6] = (char) ((envelope.sustain << 4) | envelope.release);
		}

		state.sid_register[j++] = (char) (filter.fc & 0x007);
		state.sid_register[j++] = (char) (filter.fc >> 3);
		state.sid_register[j++] = (char) ((filter.res << 4) | filter.filt);
		state.sid_register[j++] = (char) (((filter.voice3off != 0) ? 0x80 : 0)
				| (filter.hp_bp_lp << 4) | filter.vol);

		// These registers are superfluous, but included for completeness.
		for (; j < 0x1d; j++) {
			state.sid_register[j] = (char) (read(j));
		}
		for (; j < 0x20; j++) {
			state.sid_register[j] = 0;
		}

		state.bus_value = bus_value;
		state.bus_value_ttl = bus_value_ttl;

		for (i = 0; i < 3; i++) {
			state.accumulator[i] = voice[i].wave.accumulator;
			state.shift_register[i] = voice[i].wave.shift_register;
			state.rate_counter[i] = voice[i].envelope.rate_counter;
			state.rate_counter_period[i] = voice[i].envelope.rate_period;
			state.exponential_counter[i] = voice[i].envelope.exponential_counter;
			state.exponential_counter_period[i] = voice[i].envelope.exponential_counter_period;
			state.envelope_counter[i] = voice[i].envelope.envelope_counter;
			state.envelope_state[i] = voice[i].envelope.state;
			state.hold_zero[i] = voice[i].envelope.hold_zero;
		}

		return state;
	}