libresidfp 1.1.1
State.h
1/*
2 * This file is part of libsidplayfp, a SID player engine.
3 *
4 * Copyright 2026 Leandro Nini <drfiemost@users.sourceforge.net>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 */
20
21#ifndef STATE_H
22#define STATE_H
23
24#include "EnvelopeGenerator.h"
25#include "resample/TwoPassSincResampler.h"
27
28#include <cstdint>
29
30namespace reSIDfp
31{
32
33class SID;
34
35struct Params
36{
37 SamplingMethod method;
38 double clockFrequency;
39 double samplingFrequency;
40 double filterCurve6581;
41 double filterRange6581;
42 double filterCurve8580;
43 bool old6581caps;
44};
45
46struct State
47{
51 static int saveState(SID &s, char* buffer, int size);
52
56 static void restoreState(SID &s, char* buffer, int size);
57
61 static int size(SID &s);
62
63 // SID
64 int bus_value_ttl;
65 unsigned int nextVoiceSync;
66 ChipModel model;
68 uint8_t bus_value;
69 uint8_t paddle_x;
70 uint8_t paddle_y;
71
72 // Waveform
73 uint32_t pw[3];
74 uint32_t shift_register[3];
75 uint32_t shift_latch[3];
76 uint32_t ring_msb_mask[3];
77 uint32_t no_noise[3];
78 uint32_t noise_output[3];
79 uint32_t no_noise_or_noise_output[3];
80 uint32_t no_pulse[3];
81 uint32_t pulse_output[3];
82 uint32_t waveform_output[3];
83 uint32_t accumulator[3];
84 uint32_t freq[3];
85 uint32_t tri_saw_pipeline[3];
86 uint32_t osc3[3];
87 int shift_pipeline[3];
88 unsigned int shift_register_reset[3];
89 unsigned int floating_output_ttl[3];
90 bool test[3];
91 bool sync[3];
92 bool test_or_reset[3];
93 bool msb_rising[3];
94 uint8_t waveform[3];
95
96 // Envelope
97 uint16_t lfsr[3];
98 uint16_t rate[3];
99 unsigned int exponential_counter[3];
100 unsigned int exponential_counter_period[3];
101 unsigned int new_exponential_counter_period[3];
102 unsigned int state_pipeline[3];
103 unsigned int envelope_pipeline[3];
104 unsigned int exponential_pipeline[3];
105 EnvelopeGenerator::State env_state[3];
106 EnvelopeGenerator::State next_state[3];
107 bool counter_enabled[3];
108 bool gate[3];
109 bool resetLfsr[3];
110 uint8_t envelope_counter[3];
111 uint8_t attack[3];
112 uint8_t decay[3];
113 uint8_t sustain[3];
114 uint8_t release[3];
115 uint8_t env3[3];
116
117 // Filter
118 int32_t Vhp[2];
119 int32_t Vbp[2];
120 int32_t Vlp[2];
121 float extin[2];
122 uint8_t fc[2];
123 uint8_t vol[2];
124 uint8_t filt[2];
125 bool filt1[2];
126 bool filt2[2];
127 bool filt3[2];
128 bool filtE[2];
129 bool voice3off[2];
130 bool hp[2];
131 bool bp[2];
132 bool lp[2];
133 bool enabled[2];
134
135 double filterCurve6581;
136 double filterRange6581;
137 double filterCurve8580;
138 bool old6581caps;
139
140 // Integrators
141 int32_t vx[2][2];
142 int32_t vc[2][2];
143 uint32_t nVddt_Vw_2[2];
144 uint16_t nVgt[2];
145 uint16_t n_dac[2];
146
148 int32_t exVlp;
149 int32_t exVhp;
150
151 // Resampler
152 double clockFrequency;
153 double samplingFrequency;
154 SamplingMethod method;
155 // ZeroOrder
156 int32_t zor_cachedSample;
157 int32_t zor_outputValue;
158 int zor_sampleOffset;
159 // PassThrough
160 int pt_outputValue;
161 // TwoPassSinc
162 int tp_sampleIndex[2];
163 int tp_sampleOffset[2];
164 int32_t tp_outputValue[2];
165};
166
167
168} // namespace reSIDfp
169
170#endif
State
Definition EnvelopeGenerator.h:55
Definition SID.h:64
SamplingMethod
Definition residfp_defs.h:67
CombinedWaveforms
Definition residfp_defs.h:62
ChipModel
Definition residfp_defs.h:54
Definition State.h:36
Definition State.h:47
int32_t exVlp
External filter.
Definition State.h:148
static void restoreState(SID &s, char *buffer, int size)
Definition State.cpp:189
static int size(SID &s)
Definition State.cpp:342
static int saveState(SID &s, char *buffer, int size)
Definition State.cpp:35