forked from randyrossi/bmc64
-
Notifications
You must be signed in to change notification settings - Fork 0
/
viceapp.cpp
593 lines (524 loc) · 19.3 KB
/
viceapp.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
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
//
// viceapp.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 "viceapp.h"
#include "fbl.h"
#if defined(RASPI_C64)
#include "bootstat_c64.h"
#elif defined(RASPI_C128)
#include "bootstat_c128.h"
#elif defined(RASPI_VIC20)
#include "bootstat_vic20.h"
#elif defined(RASPI_PLUS4)
#include "bootstat_plus4.h"
#elif defined(RASPI_PLUS4EMU)
#include "bootstat_plus4emu.h"
#elif defined(RASPI_PET)
#include "bootstat_pet.h"
#else
#error Unknown RASPI_ variant
#endif
//
// ViceApp impl
//
bool ViceApp::Initialize(void) {
if (!mSerial.Initialize(115200)) {
return false;
}
// Initialize our replacement newlib stdio. Give it
// a pointer to our serial device so we can use printf
// to serial as soon as possible.
CGlueStdioInit(mViceOptions.SerialEnabled() ? &mSerial : nullptr);
if (!mInterrupt.Initialize()) {
return false;
}
return true;
}
int ViceApp::circle_get_machine_timing() {
// See circle.h for valid values
return mViceOptions.GetMachineTiming();
}
#if defined(RASPI_PLUS4) | defined(RASPI_PLUS4EMU)
int ViceApp::circle_cycles_per_second() {
int timing = circle_get_machine_timing();
if (timing == MACHINE_TIMING_NTSC_HDMI || timing == MACHINE_TIMING_NTSC_DPI) {
// 60hz
return 1792080;
} else if (circle_get_machine_timing() == MACHINE_TIMING_NTSC_COMPOSITE) {
// Actual C64's NTSC Composite frequency is 59.826 but the Pi's vertical
// sync frequency on composite is 60.053. See c64.h for how this is
// calculated. This keeps audio buffer to a minimum using ReSid.
return 1793672;
} else if (timing == MACHINE_TIMING_NTSC_CUSTOM_HDMI || timing == MACHINE_TIMING_NTSC_CUSTOM_DPI) {
return mViceOptions.GetCyclesPerSecond();
} else if (timing == MACHINE_TIMING_PAL_HDMI) {
// 50hz
return 1778400;
} else if (timing == MACHINE_TIMING_PAL_COMPOSITE) {
// Actual C64's PAL Composite frequency is 50.125 but the Pi's vertical
// sync frequency on composite is 50.0816. See c64.h for how this is
// calculated. This keep audio buffer to a minimum using ReSid.
return 1781245;
} else if (timing == MACHINE_TIMING_PAL_CUSTOM_HDMI || timing == MACHINE_TIMING_PAL_CUSTOM_DPI) {
return mViceOptions.GetCyclesPerSecond();
} else {
return 1778400;
}
}
#elif defined(RASPI_VIC20)
int ViceApp::circle_cycles_per_second() {
int timing = circle_get_machine_timing();
if (timing == MACHINE_TIMING_NTSC_HDMI) {
// 60hz
return 1017900;
} else if (timing == MACHINE_TIMING_NTSC_COMPOSITE) {
// Actual C64's NTSC Composite frequency is 59.826 but the Pi's vertical
// sync frequency on composite is 60.053. See c64.h for how this is
// calculated. This keeps audio buffer to a minimum using ReSid.
return 1018804;
} else if (timing == MACHINE_TIMING_NTSC_CUSTOM_HDMI || timing == MACHINE_TIMING_NTSC_CUSTOM_DPI) {
return mViceOptions.GetCyclesPerSecond();
} else if (timing == MACHINE_TIMING_PAL_HDMI) {
// 50hz
return 1107600;
} else if (timing == MACHINE_TIMING_PAL_COMPOSITE) {
// Actual C64's PAL Composite frequency is 50.125 but the Pi's vertical
// sync frequency on composite is 50.0816. See c64.h for how this is
// calculated. This keep audio buffer to a minimum using ReSid.
return 1109372;
} else if (timing == MACHINE_TIMING_PAL_CUSTOM_HDMI || timing == MACHINE_TIMING_PAL_CUSTOM_DPI) {
return mViceOptions.GetCyclesPerSecond();
} else {
return 1017900;
}
}
#elif defined(RASPI_C64) | defined(RASPI_C128)
int ViceApp::circle_cycles_per_second() {
int timing = circle_get_machine_timing();
if (timing == MACHINE_TIMING_NTSC_HDMI) {
// 60hz
return 1025700;
} else if (timing == MACHINE_TIMING_NTSC_COMPOSITE) {
// Actual C64's NTSC Composite frequency is 59.826 but the Pi's vertical
// sync frequency on composite is 60.053. See c64.h for how this is
// calculated. This keeps audio buffer to a minimum using ReSid.
return 1026611;
} else if (timing == MACHINE_TIMING_NTSC_CUSTOM_HDMI || timing == MACHINE_TIMING_NTSC_CUSTOM_DPI) {
return mViceOptions.GetCyclesPerSecond();
} else if (timing == MACHINE_TIMING_PAL_HDMI) {
// 50hz
return 982800;
} else if (timing == MACHINE_TIMING_PAL_COMPOSITE) {
// Actual C64's PAL Composite frequency is 50.125 but the Pi's vertical
// sync frequency on composite is 50.0816. See c64.h for how this is
// calculated. This keep audio buffer to a minimum using ReSid.
return 984404;
} else if (timing == MACHINE_TIMING_PAL_CUSTOM_HDMI || timing == MACHINE_TIMING_PAL_CUSTOM_DPI) {
return mViceOptions.GetCyclesPerSecond();
} else {
return 982800;
}
}
#elif defined(RASPI_PET)
int ViceApp::circle_cycles_per_second() {
int timing = circle_get_machine_timing();
if (timing == MACHINE_TIMING_NTSC_HDMI) {
// 60hz
return 1013760;
} else if (timing == MACHINE_TIMING_NTSC_COMPOSITE) {
// Actual C64's NTSC Composite frequency is 59.826 but the Pi's vertical
// sync frequency on composite is 60.053. See c64.h for how this is
// calculated. This keeps audio buffer to a minimum using ReSid.
return 1014661;
} else if (timing == MACHINE_TIMING_NTSC_CUSTOM_HDMI || timing == MACHINE_TIMING_NTSC_CUSTOM_DPI) {
return mViceOptions.GetCyclesPerSecond();
} else if (timing == MACHINE_TIMING_PAL_HDMI) {
// 50hz
return 1001600;
} else if (timing == MACHINE_TIMING_PAL_COMPOSITE) {
// Actual C64's PAL Composite frequency is 50.125 but the Pi's vertical
// sync frequency on composite is 50.0816. See c64.h for how this is
// calculated. This keep audio buffer to a minimum using ReSid.
return 1003202;
} else if (timing == MACHINE_TIMING_PAL_CUSTOM_HDMI || timing == MACHINE_TIMING_PAL_CUSTOM_DPI) {
return mViceOptions.GetCyclesPerSecond();
} else {
return 1000000;
}
}
#else
#error Unknown RASPI_ variant
#endif
//
// ViceScreenApp impl
//
bool ViceScreenApp::Initialize(void) {
if (!ViceApp::Initialize()) {
return false;
}
if (mViceOptions.SerialEnabled()) {
if (!mLogger.Initialize(&mSerial)) {
return false;
}
} else {
if (!mLogger.Initialize(&mNullDevice)) {
return false;
}
}
if (!mEmulatorCore->Init(&mViceOptions)) {
return false;
}
if (!mTimer.Initialize()) {
return false;
}
if (!mGPIOManager.Initialize()) {
return false;
}
if (!mVCHIQ.Initialize()) {
return false;
}
SetupGPIO();
FrameBufferLayer::Initialize();
return true;
}
// Setup GPIO pins for scanning keyboard, button or joysticks.
void ViceScreenApp::SetupGPIOForInput() {
// PA - Set to output-low for when scanning each
// row. Otherwise set to input-pullup.
// Note: Lines 0 and 7 are swapped. The order here is
// from keyboard connector pins 20 down to 13.
// Connector Pin 20 - PA7
gpioPins[7] =
new CGPIOPin(26, GPIOModeInputPullUp, &mGPIOManager);
// Connector Pin 19 - PA1
gpioPins[1] =
new CGPIOPin(20, GPIOModeInputPullUp, &mGPIOManager);
// Connector Pin 18 - PA2
gpioPins[2] =
new CGPIOPin(19, GPIOModeInputPullUp, &mGPIOManager);
// Connector Pin 17 - PA3
gpioPins[3] =
new CGPIOPin(16, GPIOModeInputPullUp, &mGPIOManager);
// Connector Pin 16 - PA4
gpioPins[4] =
new CGPIOPin(13, GPIOModeInputPullUp, &mGPIOManager);
// Connector Pin 15 - PA5
gpioPins[5] =
new CGPIOPin(6, GPIOModeInputPullUp, &mGPIOManager);
// Connector Pin 14 - PA6
gpioPins[6] =
new CGPIOPin(12, GPIOModeInputPullUp, &mGPIOManager);
// Connector Pin 13 - PA0
gpioPins[0] =
new CGPIOPin(5, GPIOModeInputPullUp, &mGPIOManager);
// PB - Always input-pullup for read during kbd scan or joy port 1
// Note: Lines 3 and 7 are swapped. The order here is from
// keyboard connector pins 12 down to 5
// Connector Pin 12 - PB 0
gpioPins[8] =
new CGPIOPin(8, GPIOModeInputPullUp, &mGPIOManager);
// Connector Pin 11 - PB 1
gpioPins[9] =
new CGPIOPin(25, GPIOModeInputPullUp, &mGPIOManager);
// Connector Pin 10 - PB 2
gpioPins[10] =
new CGPIOPin(24, GPIOModeInputPullUp, &mGPIOManager);
// Connector Pin 9 - PB 7
gpioPins[15] =
new CGPIOPin(22, GPIOModeInputPullUp, &mGPIOManager);
// Connector Pin 8 - PB 4
gpioPins[12] =
new CGPIOPin(23, GPIOModeInputPullUp, &mGPIOManager);
// Connector Pin 7 - PB 5
gpioPins[13] =
new CGPIOPin(27, GPIOModeInputPullUp, &mGPIOManager);
// Connector Pin 6 - PB 6
gpioPins[14] =
new CGPIOPin(17, GPIOModeInputPullUp, &mGPIOManager);
// Connector Pin 5 - PB 3
gpioPins[11] =
new CGPIOPin(18, GPIOModeInputPullUp, &mGPIOManager);
// A few more special pins
gpioPins[GPIO_KBD_RESTORE_INDEX] =
new CGPIOPin(GPIO_KBD_RESTORE, GPIOModeInputPullUp, &mGPIOManager);
gpioPins[GPIO_JS1_SELECT_INDEX] =
new CGPIOPin(GPIO_JS1_SELECT, GPIOModeInputPullUp, &mGPIOManager);
gpioPins[GPIO_JS2_SELECT_INDEX] =
new CGPIOPin(GPIO_JS2_SELECT, GPIOModeInputPullUp, &mGPIOManager);
gpioPins[NO_FIXED_PURPOSE_1_INDEX] =
new CGPIOPin(2, GPIOModeInputPullUp, &mGPIOManager);
gpioPins[NO_FIXED_PURPOSE_2_INDEX] =
new CGPIOPin(3, GPIOModeInputPullUp, &mGPIOManager);
gpioPins[NO_FIXED_PURPOSE_3_INDEX] =
new CGPIOPin(9, GPIOModeInputPullUp, &mGPIOManager);
gpioPins[NO_FIXED_PURPOSE_4_INDEX] =
new CGPIOPin(10, GPIOModeInputPullUp, &mGPIOManager);
// Convenience arrays for joysticks
config_1_joystickPins1[JOY_UP] = gpioPins[GPIO_CONFIG_1_JOY_1_UP_INDEX];
config_1_joystickPins1[JOY_DOWN] = gpioPins[GPIO_CONFIG_1_JOY_1_DOWN_INDEX];
config_1_joystickPins1[JOY_LEFT] = gpioPins[GPIO_CONFIG_1_JOY_1_LEFT_INDEX];
config_1_joystickPins1[JOY_RIGHT] = gpioPins[GPIO_CONFIG_1_JOY_1_RIGHT_INDEX];
config_1_joystickPins1[JOY_FIRE] = gpioPins[GPIO_CONFIG_1_JOY_1_FIRE_INDEX];
config_1_joystickPins2[JOY_UP] = gpioPins[GPIO_CONFIG_1_JOY_2_UP_INDEX];
config_1_joystickPins2[JOY_DOWN] = gpioPins[GPIO_CONFIG_1_JOY_2_DOWN_INDEX];
config_1_joystickPins2[JOY_LEFT] = gpioPins[GPIO_CONFIG_1_JOY_2_LEFT_INDEX];
config_1_joystickPins2[JOY_RIGHT] = gpioPins[GPIO_CONFIG_1_JOY_2_RIGHT_INDEX];
config_1_joystickPins2[JOY_FIRE] = gpioPins[GPIO_CONFIG_1_JOY_2_FIRE_INDEX];
config_0_joystickPins1[JOY_UP] = gpioPins[GPIO_CONFIG_0_JOY_1_UP_INDEX];
config_0_joystickPins1[JOY_DOWN] = gpioPins[GPIO_CONFIG_0_JOY_1_DOWN_INDEX];
config_0_joystickPins1[JOY_LEFT] = gpioPins[GPIO_CONFIG_0_JOY_1_LEFT_INDEX];
config_0_joystickPins1[JOY_RIGHT] = gpioPins[GPIO_CONFIG_0_JOY_1_RIGHT_INDEX];
config_0_joystickPins1[JOY_FIRE] = gpioPins[GPIO_CONFIG_0_JOY_1_FIRE_INDEX];
config_0_joystickPins2[JOY_UP] = gpioPins[GPIO_CONFIG_0_JOY_2_UP_INDEX];
config_0_joystickPins2[JOY_DOWN] = gpioPins[GPIO_CONFIG_0_JOY_2_DOWN_INDEX];
config_0_joystickPins2[JOY_LEFT] = gpioPins[GPIO_CONFIG_0_JOY_2_LEFT_INDEX];
config_0_joystickPins2[JOY_RIGHT] = gpioPins[GPIO_CONFIG_0_JOY_2_RIGHT_INDEX];
config_0_joystickPins2[JOY_FIRE] = gpioPins[GPIO_CONFIG_0_JOY_2_FIRE_INDEX];
config_2_joystickPins[JOY_UP] = gpioPins[GPIO_CONFIG_2_WAVESHARE_UP_INDEX];
config_2_joystickPins[JOY_DOWN] = gpioPins[GPIO_CONFIG_2_WAVESHARE_DOWN_INDEX];
config_2_joystickPins[JOY_LEFT] = gpioPins[GPIO_CONFIG_2_WAVESHARE_LEFT_INDEX];
config_2_joystickPins[JOY_RIGHT] = gpioPins[GPIO_CONFIG_2_WAVESHARE_RIGHT_INDEX];
config_2_joystickPins[JOY_FIRE] = gpioPins[GPIO_CONFIG_2_WAVESHARE_B_INDEX];
config_2_joystickPins[JOY_POTX] = gpioPins[GPIO_CONFIG_2_WAVESHARE_A_INDEX];
config_2_joystickPins[JOY_POTY] = gpioPins[GPIO_CONFIG_2_WAVESHARE_Y_INDEX];
config_3_joystickPins1[JOY_UP] = gpioPins[GPIO_CONFIG_3_JOY_1_UP_INDEX];
config_3_joystickPins1[JOY_DOWN] = gpioPins[GPIO_CONFIG_3_JOY_1_DOWN_INDEX];
config_3_joystickPins1[JOY_LEFT] = gpioPins[GPIO_CONFIG_3_JOY_1_LEFT_INDEX];
config_3_joystickPins1[JOY_RIGHT] = gpioPins[GPIO_CONFIG_3_JOY_1_RIGHT_INDEX];
config_3_joystickPins1[JOY_FIRE] = gpioPins[GPIO_CONFIG_3_JOY_1_FIRE_INDEX];
config_3_joystickPins2[JOY_UP] = gpioPins[GPIO_CONFIG_3_JOY_2_UP_INDEX];
config_3_joystickPins2[JOY_DOWN] = gpioPins[GPIO_CONFIG_3_JOY_2_DOWN_INDEX];
config_3_joystickPins2[JOY_LEFT] = gpioPins[GPIO_CONFIG_3_JOY_2_LEFT_INDEX];
config_3_joystickPins2[JOY_RIGHT] = gpioPins[GPIO_CONFIG_3_JOY_2_RIGHT_INDEX];
config_3_joystickPins2[JOY_FIRE] = gpioPins[GPIO_CONFIG_3_JOY_2_FIRE_INDEX];
config_3_userportPins[USERPORT_PB0] = gpioPins[GPIO_CONFIG_3_USERPORT_PB0_INDEX];
config_3_userportPins[USERPORT_PB1] = gpioPins[GPIO_CONFIG_3_USERPORT_PB1_INDEX];
config_3_userportPins[USERPORT_PB2] = gpioPins[GPIO_CONFIG_3_USERPORT_PB2_INDEX];
config_3_userportPins[USERPORT_PB3] = gpioPins[GPIO_CONFIG_3_USERPORT_PB3_INDEX];
config_3_userportPins[USERPORT_PB4] = gpioPins[GPIO_CONFIG_3_USERPORT_PB4_INDEX];
config_3_userportPins[USERPORT_PB5] = gpioPins[GPIO_CONFIG_3_USERPORT_PB5_INDEX];
config_3_userportPins[USERPORT_PB6] = gpioPins[GPIO_CONFIG_3_USERPORT_PB6_INDEX];
config_3_userportPins[USERPORT_PB7] = gpioPins[GPIO_CONFIG_3_USERPORT_PB7_INDEX];
}
// Setup GPIO pins for DPI
void ViceScreenApp::SetupGPIOForDPI() {
for (int i = 0; i < 28; i++) {
DPIPins[i] =
new CGPIOPin(i, GPIOModeAlternateFunction2, &mGPIOManager);
}
}
void ViceScreenApp::SetupGPIO() {
if (mViceOptions.DPIEnabled()) {
SetupGPIOForDPI();
} else {
SetupGPIOForInput();
}
}
//
// ViceStdioApp impl
//
void ViceStdioApp::InitBootStat() {
FILE *fp;
#if defined(RASPI_C64)
fp = fopen("/C64/bootstat.txt", "r");
#elif defined(RASPI_C128)
fp = fopen("/C128/bootstat.txt", "r");
#elif defined(RASPI_VIC20)
fp = fopen("/VIC20/bootstat.txt", "r");
#elif defined(RASPI_PLUS4)
fp = fopen("/PLUS4/bootstat.txt", "r");
#elif defined(RASPI_PLUS4EMU)
fp = NULL;
#elif defined(RASPI_PET)
fp = fopen("/PET/bootstat.txt", "r");
#else
#error Unknown RASPI_ variant
#endif
if (fp == NULL) {
printf("Could not find bootstat. Using default list.\n");
CGlueStdioInitBootStat(dflt_bootStatNum, dflt_bootStatWhat,
dflt_bootStatFile, dflt_bootStatSize);
return;
}
char line[80];
int num = 0;
while (fgets(line, 79, fp)) {
if (feof(fp))
break;
if (strlen(line) == 0)
continue;
if (line[0] == '#')
continue;
char *what = strtok(line, ",");
if (what == NULL)
continue;
char *file = strtok(NULL, ",");
if (file == NULL)
continue;
char *size = strtok(NULL, ",");
if (size == NULL)
continue;
if (size[strlen(size) - 1] == '\n') {
size[strlen(size) - 1] = '\0';
}
if (num >= MAX_BOOTSTAT_LINES) {
printf("Warning: bootstat.txt too long, max %d entries\n",
MAX_BOOTSTAT_LINES);
break;
}
if (strcmp(what, "stat") == 0) {
if (strcmp(file, "d1541II") == 0) {
// Ignore legacy d1541II faking found file without a fully
// qualified path.
printf("Ignoring d1541II in bootstat.txt\n");
continue;
}
mBootStatWhat[num] = BOOTSTAT_WHAT_STAT;
} else if (strcmp(what, "fail") == 0) {
if (strcmp(file, "rpi_pos.vkm") == 0) {
// Ignore legacy mistake blocking rpi_pos.vkm
printf("Ignoring rpi_pos.vkm in bootstat.txt\n");
continue;
}
mBootStatWhat[num] = BOOTSTAT_WHAT_FAIL;
} else {
printf("Ignoring unknown bootstat.txt '%s'\n", what);
continue;
}
// These never get freed...
mBootStatFile[num] = (char *) malloc(MAX_BOOTSTAT_FLEN);
strncpy(mBootStatFile[num], file, MAX_BOOTSTAT_FLEN);
mBootStatSize[num] = atoi(size);
num++;
}
fclose(fp);
CGlueStdioInitBootStat(num, mBootStatWhat, (const char **) mBootStatFile,
mBootStatSize);
}
void ViceStdioApp::DisableBootStat() {
CGlueStdioInitBootStat(0, nullptr, nullptr, nullptr);
}
bool ViceStdioApp::Initialize(void) {
if (!ViceScreenApp::Initialize()) {
return false;
}
if (!mEMMC.Initialize()) {
return false;
}
int partition = mViceOptions.GetDiskPartition();
int ss = 0;
if (partition > 4) {
// User is forcing a start sector by specifying
// a partition above 4. Tell glue code partition
// is 5 and this will set the start sector to what
// they provided when the disk is mounted.
ss = partition;
partition = 5;
}
// When mounting, fatfs gets ":" appended. But StdioInit
// does not.
const char *volumeName = mViceOptions.GetDiskVolume();
char fatFsVol[VOLUME_NAME_LEN];
strncpy(fatFsVol, volumeName, VOLUME_NAME_LEN - 2);
strcat(fatFsVol, ":");
CGlueStdioSetPartitionForVolume(volumeName, partition, ss);
if (f_mount(&mFileSystemSD, fatFsVol, 0) != FR_OK) {
mLogger.Write(GetKernelName(), LogError, "Cannot mount partition: %s",
fatFsVol);
return false;
}
InitBootStat();
// Now that emmc is initialized, launch
// the emulator main loop on CORE 1 before USBHCII.
int timing_int = mViceOptions.GetMachineTiming();
if (timing_int == MACHINE_TIMING_NTSC_HDMI ||
timing_int == MACHINE_TIMING_NTSC_CUSTOM_HDMI ||
timing_int == MACHINE_TIMING_NTSC_COMPOSITE ||
timing_int == MACHINE_TIMING_NTSC_DPI ||
timing_int == MACHINE_TIMING_NTSC_CUSTOM_DPI) {
strcpy(mTimingOption, "-ntsc");
} else {
strcpy(mTimingOption, "-pal");
}
#ifdef ARM_ALLOW_MULTI_CORE
mEmulatorCore->LaunchEmulator(mTimingOption);
#endif
// This takes 1.5 seconds to init.
if (!mUSBHCII.Initialize()) {
return false;
}
return true;
}
void ViceStdioApp::Cleanup(void) {
// When mounting, fatfs gets ":" appended. But StdioInit
// does not.
const char *volumeName = mViceOptions.GetDiskVolume();
char fatFsVol[VOLUME_NAME_LEN];
strncpy(fatFsVol, volumeName, VOLUME_NAME_LEN - 2);
strcat(fatFsVol, ":");
if (f_mount(0, fatFsVol, 0) != FR_OK) {
mLogger.Write(GetKernelName(), LogError, "Cannot unmount drive");
}
ViceScreenApp::Cleanup();
}
void ViceStdioApp::circle_find_usb(int (*usb)[3]) {
CDevice *usb1 = CDeviceNameService::Get()->GetDevice("umsd1", TRUE);
(*usb)[0] = usb1 ? 1 : 0;
CDevice *usb2 = CDeviceNameService::Get()->GetDevice("umsd2", TRUE);
(*usb)[1] = usb2 ? 1 : 0;
CDevice *usb3 = CDeviceNameService::Get()->GetDevice("umsd3", TRUE);
(*usb)[2] = usb3 ? 1 : 0;
}
int ViceStdioApp::circle_mount_usb(int usb) {
int status;
switch (usb) {
case 0:
status = f_mount(&mFileSystemUSB1, "USB:", 1);
break;
case 1:
status = f_mount(&mFileSystemUSB1, "USB2:", 1);
break;
case 2:
status = f_mount(&mFileSystemUSB1, "USB3:", 1);
break;
default:
return 0;
}
if (status != FR_OK) {
mLogger.Write(GetKernelName(), LogError, "Cannot mount usb %d", usb);
return 0;
}
return 1;
}
int ViceStdioApp::circle_unmount_usb(int usb) {
int status;
switch (usb) {
case 0:
status = f_mount(0, "USB:", 1);
break;
case 1:
status = f_mount(0, "USB2:", 1);
break;
case 2:
status = f_mount(0, "USB3:", 1);
break;
default:
return 0;
}
if (status != FR_OK) {
mLogger.Write(GetKernelName(), LogError, "Cannot unmount usb %d", usb);
return 0;
}
return 1;
}