libresidfp 1.3.0
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 samplingFrequency;
39 double filterCurve6581;
40 double filterRange6581;
41 double filterCurve8580;
42 CapsType caps6581;
43};
44
45class State
46{
47public:
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
63private:
64 // SID
65 int bus_value_ttl;
66 unsigned int nextVoiceSync;
67 unsigned int offset_6581;
68 ChipModel model;
70 double dacLeakage;
71 uint8_t bus_value;
72 uint8_t paddle_x;
73 uint8_t paddle_y;
74
75 // Waveform
76 uint32_t pw[3];
77 uint32_t shift_register[3];
78 uint32_t shift_latch[3];
79 uint32_t ring_msb_mask[3];
80 uint32_t no_noise[3];
81 uint32_t noise_output[3];
82 uint32_t no_noise_or_noise_output[3];
83 uint32_t no_pulse[3];
84 uint32_t pulse_output[3];
85 uint32_t waveform_output[3];
86 uint32_t accumulator[3];
87 uint32_t freq[3];
88 uint32_t tri_saw_pipeline[3];
89 uint32_t osc3[3];
90 int shift_pipeline[3];
91 unsigned int shift_register_reset[3];
92 unsigned int floating_output_ttl[3];
93 bool test[3];
94 bool sync[3];
95 bool test_or_reset[3];
96 bool msb_rising[3];
97 bool strongPS[3];
98 bool msb_pulldown[3];
99 uint8_t waveform[3];
100
101 // Envelope
102 uint16_t lfsr[3];
103 uint16_t rate[3];
104 unsigned int exponential_counter[3];
105 unsigned int exponential_counter_period[3];
106 unsigned int new_exponential_counter_period[3];
107 unsigned int state_pipeline[3];
108 unsigned int envelope_pipeline[3];
109 unsigned int exponential_pipeline[3];
110 EnvelopeGenerator::State env_state[3];
111 EnvelopeGenerator::State next_state[3];
112 bool counter_enabled[3];
113 bool gate[3];
114 bool resetLfsr[3];
115 uint8_t envelope_counter[3];
116 uint8_t attack[3];
117 uint8_t decay[3];
118 uint8_t sustain[3];
119 uint8_t release[3];
120 uint8_t env3[3];
121
122 // Filter
123 int32_t Vhp[2];
124 int32_t Vbp[2];
125 int32_t Vlp[2];
126 float extin[2];
127 uint8_t fc[2];
128 uint8_t vol[2];
129 uint8_t filt[2];
130 bool filt1[2];
131 bool filt2[2];
132 bool filt3[2];
133 bool filtE[2];
134 bool voice3off[2];
135 bool hp[2];
136 bool bp[2];
137 bool lp[2];
138 bool enabled[2];
139
140 double filterCurve6581;
141 double filterRange6581;
142 double filterCurve8580;
143 CapsType caps6581;
144
145 // Integrators
146 int32_t vx[2][2];
147 int32_t vc[2][2];
148 uint32_t nVddt_Vw_2[2];
149 uint16_t nVgt[2];
150 uint16_t n_dac[2];
151
153 int32_t exVlp;
154 int32_t exVhp;
155 double ext_res;
156
157 // Resampler
158 double clockFrequency;
159 double samplingFrequency;
160 SamplingMethod method;
161 // ZeroOrder
162 int32_t zor_cachedSample;
163 int32_t zor_outputValue;
164 int zor_sampleOffset;
165 // PassThrough
166 int pt_outputValue;
167 // TwoPassSinc
168 int tp_sampleIndex[2];
169 int tp_sampleOffset[2];
170 int32_t tp_outputValue[2];
171};
172
173
174} // namespace reSIDfp
175
176#endif
State
Definition EnvelopeGenerator.h:55
Definition SID.h:67
Definition State.h:46
static void restoreState(SID &s, char *buffer, int size)
Definition State.cpp:194
static int size(SID &s)
Definition State.cpp:355
static int saveState(SID &s, char *buffer, int size)
Definition State.cpp:35
SamplingMethod
Definition residfp_defs.h:78
CombinedWaveforms
Definition residfp_defs.h:73
ChipModel
Definition residfp_defs.h:65
CapsType
Definition residfp_defs.h:87
Definition State.h:36