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