forked from randyrossi/bmc64
-
Notifications
You must be signed in to change notification settings - Fork 0
/
viceoptions.cpp
294 lines (244 loc) · 8.97 KB
/
viceoptions.cpp
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
//
// viceoptions.cpp
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "viceoptions.h"
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <circle/logger.h>
#include <circle/sysconfig.h>
#include <circle/util.h>
extern "C" {
#include "third_party/common/circle.h"
}
#define INVALID_VALUE ((unsigned)-1)
ViceOptions *ViceOptions::s_pThis = 0;
ViceOptions::ViceOptions(void)
: m_nMachineTiming(MACHINE_TIMING_PAL_HDMI),
m_bDemoEnabled(false), m_bSerialEnabled(true),
m_bGPIOOutputsEnabled(false), m_nCyclesPerSecond(0),
m_audioOut(VCHIQSoundDestinationAuto), m_bDPIEnabled(false),
m_scaling_param_fbw{0,0}, m_scaling_param_fbh{0,0},
m_scaling_param_sx{0,0}, m_scaling_param_sy{0,0},
m_raster_skip(false), m_raster_skip2(false) {
s_pThis = this;
// Set the default volume we mount for fatfs
m_disk_partition = 0; // this tells fatfs 'auto'
strcpy(m_disk_volume, "SD");
CBcmPropertyTags Tags;
if (!Tags.GetTag(PROPTAG_GET_COMMAND_LINE, &m_TagCommandLine,
sizeof m_TagCommandLine)) {
return;
}
if (m_TagCommandLine.Tag.nValueLength >= sizeof m_TagCommandLine.String) {
return;
}
m_TagCommandLine.String[m_TagCommandLine.Tag.nValueLength] = '\0';
m_pOptions = (char *)m_TagCommandLine.String;
char *pOption;
while ((pOption = GetToken()) != 0) {
char *pValue = GetOptionValue(pOption);
if (!pValue) continue;
if (strcmp(pOption, "machine_timing") == 0) {
if (strcmp(pValue, "ntsc") == 0 || strcmp(pValue, "ntsc-hdmi") == 0) {
m_nMachineTiming = MACHINE_TIMING_NTSC_HDMI;
} else if (strcmp(pValue, "ntsc-dpi") == 0) {
m_nMachineTiming = MACHINE_TIMING_NTSC_DPI;
} else if (strcmp(pValue, "ntsc-composite") == 0) {
m_nMachineTiming = MACHINE_TIMING_NTSC_COMPOSITE;
} else if (strcmp(pValue, "ntsc-custom") == 0) {
m_nMachineTiming = MACHINE_TIMING_NTSC_CUSTOM_HDMI;
} else if (strcmp(pValue, "pal") == 0 || strcmp(pValue, "pal-hdmi") == 0) {
m_nMachineTiming = MACHINE_TIMING_PAL_HDMI;
} else if (strcmp(pValue, "pal-dpi") == 0) {
m_nMachineTiming = MACHINE_TIMING_PAL_DPI;
} else if (strcmp(pValue, "pal-composite") == 0) {
m_nMachineTiming = MACHINE_TIMING_PAL_COMPOSITE;
} else if (strcmp(pValue, "pal-custom") == 0) {
m_nMachineTiming = MACHINE_TIMING_PAL_CUSTOM_HDMI;
}
} else if (strcmp(pOption, "enable_demo") == 0) {
if (strcmp(pValue,"true") == 0 || strcmp(pValue, "1") == 0) {
m_bDemoEnabled = true;
} else {
m_bDemoEnabled = false;
}
} else if (strcmp(pOption, "enable_serial") == 0) {
if (strcmp(pValue,"true") == 0 || strcmp(pValue, "1") == 0) {
m_bSerialEnabled = true;
} else {
m_bSerialEnabled = false;
}
} else if (strcmp(pOption, "enable_gpio_outputs") == 0) {
// Unless this is true, OUTPUT HIGH should not be allowed on any pin.
if (strcmp(pValue,"true") == 0 || strcmp(pValue, "1") == 0) {
m_bGPIOOutputsEnabled = true;
} else {
m_bGPIOOutputsEnabled = false;
}
} else if (strcmp(pOption, "disk_partition") == 0) {
m_disk_partition = atoi(pValue);
if (m_disk_partition < 0)
m_disk_partition = 0;
} else if (strcmp(pOption, "cycles_per_refresh") == 0 || strcmp(pOption, "cycles_per_second") == 0) {
// This was named incorrectly in earlier versions. Keeping the old bad name working.
m_nCyclesPerSecond = atol(pValue);
} else if (strcmp(pOption, "audio_out") == 0) {
if (strcmp(pValue, "hdmi") == 0 || strcmp(pValue, "ntsc-hdmi") == 0) {
m_audioOut = VCHIQSoundDestinationHDMI;
} else if (strcmp(pValue, "analog") == 0) {
m_audioOut = VCHIQSoundDestinationHeadphones;
} else if (strcmp(pValue, "auto") == 0) {
m_audioOut = VCHIQSoundDestinationAuto;
}
} else if (strcmp(pOption, "enable_dpi") == 0) {
if (strcmp(pValue, "true") == 0 || strcmp(pValue, "1") == 0) {
m_bDPIEnabled = true;
} else {
m_bDPIEnabled = false;
}
} else if (strcmp(pOption, "scaling_params") == 0 ||
strcmp(pOption, "scaling_params2") == 0) {
int num = 0;
if (strcmp(pOption, "scaling_params2") == 0) {
num = 1;
}
char* fbw_s = strtok(pValue, ",");
if (!fbw_s) continue;
char* fbh_s = strtok(NULL, ",");
if (!fbh_s) continue;
char* sx_s = strtok(NULL, ",");
if (!sx_s) continue;
char* sy_s = strtok(NULL, ",");
if (!sy_s) continue;
m_scaling_param_fbw[num] = atoi(fbw_s);
m_scaling_param_fbh[num] = atoi(fbh_s);
m_scaling_param_sx[num] = atoi(sx_s);
m_scaling_param_sy[num] = atoi(sy_s);
} else if (strcmp(pOption, "raster_skip") == 0) {
if (strcmp(pValue, "true") == 0 || strcmp(pValue, "1") == 0) {
m_raster_skip = true;
} else {
m_raster_skip = false;
}
} else if (strcmp(pOption, "raster_skip2") == 0) {
if (strcmp(pValue, "true") == 0 || strcmp(pValue, "1") == 0) {
m_raster_skip2 = true;
} else {
m_raster_skip2 = false;
}
}
}
// When DPI is enabled, use the DPI versions of constants. Behavior
// is identical. It's just used for display purposes.
if (m_nMachineTiming == MACHINE_TIMING_PAL_CUSTOM_HDMI &&
m_bDPIEnabled) {
m_nMachineTiming = MACHINE_TIMING_PAL_CUSTOM_DPI;
} else if (m_nMachineTiming == MACHINE_TIMING_NTSC_CUSTOM_HDMI &&
m_bDPIEnabled) {
m_nMachineTiming = MACHINE_TIMING_NTSC_CUSTOM_DPI;
}
if (m_nMachineTiming == MACHINE_TIMING_PAL_CUSTOM_HDMI &&
m_nCyclesPerSecond == 0) {
m_nMachineTiming = MACHINE_TIMING_PAL_HDMI;
} else if (m_nMachineTiming == MACHINE_TIMING_NTSC_CUSTOM_HDMI &&
m_nCyclesPerSecond == 0) {
m_nMachineTiming = MACHINE_TIMING_NTSC_HDMI;
} else if (m_nMachineTiming == MACHINE_TIMING_NTSC_CUSTOM_DPI &&
m_nCyclesPerSecond == 0) {
m_nMachineTiming = MACHINE_TIMING_NTSC_DPI;
} else if (m_nMachineTiming == MACHINE_TIMING_NTSC_CUSTOM_DPI &&
m_nCyclesPerSecond == 0) {
m_nMachineTiming = MACHINE_TIMING_NTSC_DPI;
}
if (m_bDPIEnabled) {
m_bSerialEnabled = false;
}
}
ViceOptions::~ViceOptions(void) { s_pThis = 0; }
unsigned ViceOptions::GetMachineTiming(void) const { return m_nMachineTiming; }
bool ViceOptions::DemoEnabled(void) const { return m_bDemoEnabled; }
bool ViceOptions::SerialEnabled(void) const { return m_bSerialEnabled; }
bool ViceOptions::GPIOOutputsEnabled(void) const { return m_bGPIOOutputsEnabled; }
bool ViceOptions::DPIEnabled(void) const { return m_bDPIEnabled; }
int ViceOptions::GetDiskPartition(void) const { return m_disk_partition; }
void ViceOptions::GetScalingParams(int display, int *fbw, int *fbh, int *sx, int *sy) const {
if (display >=0 && display < 2) {
*fbw = m_scaling_param_fbw[display];
*fbh = m_scaling_param_fbh[display];
*sx = m_scaling_param_sx[display];
*sy = m_scaling_param_sy[display];
}
}
bool ViceOptions::GetRasterSkip(void) const { return m_raster_skip; }
bool ViceOptions::GetRasterSkip2(void) const { return m_raster_skip2; }
const char *ViceOptions::GetDiskVolume(void) const { return m_disk_volume; }
unsigned long ViceOptions::GetCyclesPerSecond(void) const {
return m_nCyclesPerSecond;
}
TVCHIQSoundDestination ViceOptions::GetAudioOut(void) const {
return m_audioOut;
}
ViceOptions *ViceOptions::Get(void) { return s_pThis; }
char *ViceOptions::GetToken(void) {
while (*m_pOptions != '\0') {
if (*m_pOptions != ' ') {
break;
}
m_pOptions++;
}
if (*m_pOptions == '\0') {
return 0;
}
char *pToken = m_pOptions;
while (*m_pOptions != '\0') {
if (*m_pOptions == ' ') {
*m_pOptions++ = '\0';
break;
}
m_pOptions++;
}
return pToken;
}
char *ViceOptions::GetOptionValue(char *pOption) {
while (*pOption != '\0') {
if (*pOption == '=') {
break;
}
pOption++;
}
if (*pOption == '\0') {
return 0;
}
*pOption++ = '\0';
return pOption;
}
unsigned ViceOptions::GetDecimal(char *pString) {
if (pString == 0 || *pString == '\0') {
return INVALID_VALUE;
}
unsigned nResult = 0;
char chChar;
while ((chChar = *pString++) != '\0') {
if (!('0' <= chChar && chChar <= '9')) {
return INVALID_VALUE;
}
unsigned nPrevResult = nResult;
nResult = nResult * 10 + (chChar - '0');
if (nResult < nPrevResult || nResult == INVALID_VALUE) {
return INVALID_VALUE;
}
}
return nResult;
}