Cartridges made of several ROM files: give all the parts the same name with a different address, for example Battlezone 60.CRT and Battlezone A0.CRT; loading one of them loads all the parts.
Included programs: Arukanoido, Astro Panic, Blue Star, Dragonwing, Frogger07, Froggie, Kikstart, Kweepout, Nibbler, Omega Fury, Pooyan, Popeye, Pulse, Quikman, Spikes, Splatform, Tank Battalion, Tammerfors, Tetris+, and the demos Bah Bah, Birthday, Digit.
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#include "freertos/FreeRTOS.h"
39#include "freertos/task.h"
40#include <stdio.h>
41
45
46#include "src/machine.h"
47
48
49
50
51#include "progs/embedded/blue_star.h"
52#include "progs/embedded/omega_fury.h"
53#include "progs/embedded/quikman.h"
54#include "progs/embedded/splatform.h"
55#include "progs/embedded/demo_birthday.h"
56#include "progs/embedded/arukanoido.h"
57#include "progs/embedded/demo_bah_bah_final.h"
58#include "progs/embedded/demo_digit.h"
59#include "progs/embedded/dragonwing.h"
60#include "progs/embedded/kikstart.h"
61#include "progs/embedded/kweepoutmc.h"
62#include "progs/embedded/nibbler.h"
63#include "progs/embedded/pooyan.h"
64#include "progs/embedded/popeye.h"
65#include "progs/embedded/pulse.h"
66#include "progs/embedded/spikes.h"
67#include "progs/embedded/tank_battalion.h"
68#include "progs/embedded/tetris_plus.h"
69#include "progs/embedded/astro-panic.h"
70#include "progs/embedded/frogger07.h"
71#include "progs/embedded/froggie.h"
72#include "progs/embedded/tammerfors.h"
73
74
75#include "progs/weblist.h"
76
77
78
79#define FORMAT_ON_FAIL true
80#define SPIFFS_MOUNT_PATH "/flash"
81#define SDCARD_MOUNT_PATH "/SD"
82
83
84
85char const * basepath = nullptr;
86
87
88
89char const * EMBDIR = "VIC20Store";
90
91
92char const * DOWNDIR = "VIC20Store";
93
94
95char const * USERDIR = "VIC20Store";
96
97
98struct EmbeddedProgDef {
99 char const * filename;
100 uint8_t const * data;
101 int size;
102};
103
104
105
106
107
108
109const EmbeddedProgDef embeddedProgs[] = {
110 { arukanoido_filename, arukanoido_prg, sizeof(arukanoido_prg) },
111 { nibbler_filename, nibbler_prg, sizeof(nibbler_prg) },
112 { pooyan_filename, pooyan_prg, sizeof(pooyan_prg) },
113 { popeye_filename, popeye_prg, sizeof(popeye_prg) },
114 { tetris_plus_filename, tetris_plus_prg, sizeof(tetris_plus_prg) },
115 { spikes_filename, spikes_prg, sizeof(spikes_prg) },
116 { astro_panic_filename, astro_panic_prg, sizeof(astro_panic_prg) },
117 { splatform_filename, splatform_prg, sizeof(splatform_prg) },
118 { kweepoutmc_filename, kweepoutmc_prg, sizeof(kweepoutmc_prg) },
119 { dragonwing_filename, dragonwing_prg, sizeof(dragonwing_prg) },
120 { tank_battalion_filename, tank_battalion_prg, sizeof(tank_battalion_prg) },
121 { blue_star_filename, blue_star_prg, sizeof(blue_star_prg) },
122 { quikman_filename, quikman_prg, sizeof(quikman_prg) },
123 { frogger07_filename, frogger07_prg, sizeof(frogger07_prg) },
124 { tammerfors_filename, tammerfors_prg, sizeof(tammerfors_prg) },
125 { pulse_filename, pulse_prg, sizeof(pulse_prg) },
126 { omega_fury_filename, omega_fury_prg, sizeof(omega_fury_prg) },
127};
128
129
130#if DEBUGMACHINE
131static volatile int scycles = 0;
132static volatile bool restart = false;
133void vTimerCallback1SecExpired(xTimerHandle pxTimer)
134{
135 printf("%d - ", scycles / 5);
136 printf("Free memory (total, min, largest): %d, %d, %d\n", heap_caps_get_free_size(0), heap_caps_get_minimum_free_size(0), heap_caps_get_largest_free_block(0));
137 restart = true;
138}
139#endif
140
141
144
145
146
149
150
151
152void copyEmbeddedPrograms()
153{
155 if (!dir.exists(EMBDIR, false)) {
156
157 dir.makeDirectory(EMBDIR);
158 dir.changeDirectory(EMBDIR);
159 for (int i = 0; i < sizeof(embeddedProgs) / sizeof(EmbeddedProgDef); ++i) {
160 int fullpathlen = dir.getFullPath(embeddedProgs[i].filename);
161 char fullpath[fullpathlen];
162 dir.getFullPath(embeddedProgs[i].filename, fullpath, fullpathlen);
163 FILE * f = fopen(fullpath, "wb");
164 if (f) {
165 fwrite(embeddedProgs[i].data, 1, embeddedProgs[i].size, f);
166 fclose(f);
167 }
168 }
169 }
170}
171
172
173enum { STYLE_NONE, STYLE_LABEL, STYLE_STATICLABEL, STYLE_LABELGROUP, STYLE_BUTTON, STYLE_BUTTONHELP, STYLE_COMBOBOX, STYLE_CHECKBOX, STYLE_FILEBROWSER};
174
175
176#define BACKGROUND_COLOR RGB888(0, 0, 0)
177
178
180 void setStyle(uiObject * object, uint32_t styleClassID) {
181 switch (styleClassID) {
182 case STYLE_LABEL:
183 ((uiLabel*)object)->labelStyle().textFont = &fabgl::FONT_std_12;
184 ((uiLabel*)object)->labelStyle().backgroundColor = BACKGROUND_COLOR;
185 ((uiLabel*)object)->labelStyle().textColor = RGB888(255, 255, 255);
186 break;
187 case STYLE_STATICLABEL:
188 ((uiStaticLabel*)object)->labelStyle().textFont = &fabgl::FONT_std_12;
189 ((uiStaticLabel*)object)->labelStyle().backgroundColor = BACKGROUND_COLOR;
190 ((uiStaticLabel*)object)->labelStyle().textColor = RGB888(255, 255, 255);
191 break;
192 case STYLE_LABELGROUP:
193 ((uiStaticLabel*)object)->labelStyle().textFont = &fabgl::FONT_std_12;
194 ((uiStaticLabel*)object)->labelStyle().backgroundColor = BACKGROUND_COLOR;
195 ((uiStaticLabel*)object)->labelStyle().textColor = RGB888(255, 128, 0);
196 break;
197 case STYLE_BUTTON:
198 ((uiButton*)object)->windowStyle().borderColor = RGB888(255, 255, 255);
199 ((uiButton*)object)->buttonStyle().backgroundColor = RGB888(128, 128, 128);
200 break;
201 case STYLE_BUTTONHELP:
202 ((uiButton*)object)->windowStyle().borderColor = RGB888(255, 255, 255);
203 ((uiButton*)object)->buttonStyle().backgroundColor = RGB888(255, 255, 128);
204 break;
205 case STYLE_COMBOBOX:
206 ((uiFrame*)object)->windowStyle().borderColor = RGB888(255, 255, 255);
207 ((uiFrame*)object)->windowStyle().borderSize = 1;
208 break;
209 case STYLE_CHECKBOX:
210 ((uiFrame*)object)->windowStyle().borderColor = RGB888(255, 255, 255);
211 break;
212 case STYLE_FILEBROWSER:
213 ((uiListBox*)object)->windowStyle().borderColor = RGB888(128, 128, 128);
214 ((uiListBox*)object)->windowStyle().focusedBorderColor = RGB888(255, 255, 255);
215 ((uiListBox*)object)->listBoxStyle().backgroundColor = RGB888(0, 255, 255);
216 ((uiListBox*)object)->listBoxStyle().focusedBackgroundColor = RGB888(0, 255, 255);
217 ((uiListBox*)object)->listBoxStyle().selectedBackgroundColor = RGB888(128, 64, 0);
218 ((uiListBox*)object)->listBoxStyle().focusedSelectedBackgroundColor = RGB888(255, 128, 0);
219 ((uiListBox*)object)->listBoxStyle().textColor = RGB888(0, 0, 128);
220 ((uiListBox*)object)->listBoxStyle().selectedTextColor = RGB888(0, 0, 255);
221 ((uiListBox*)object)->listBoxStyle().textFont = &fabgl::FONT_SLANT_8x14;
222 break;
223 }
224 }
225} dialogStyle;
226
227
228
229struct DownloadProgressFrame :
public uiFrame {
230
231 uiLabel * label1;
232 uiLabel * label2;
233 uiButton * button;
234
235 DownloadProgressFrame(uiFrame * parent)
236 : uiFrame(parent, "Download", UIWINDOW_PARENTCENTER, Size(150, 110), false) {
237 frameProps().resizeable = false;
238 frameProps().moveable = false;
239 frameProps().hasCloseButton = false;
240 frameProps().hasMaximizeButton = false;
241 frameProps().hasMinimizeButton = false;
242
243 label1 =
new uiLabel(
this,
"Connecting...", Point(10, 25));
244 label2 =
new uiLabel(
this,
"", Point(10, 45));
245 button =
new uiButton(
this,
"Abort", Point(50, 75), Size(50, 20));
246 button->
onClick = [&]() { exitModal(1); };
247 }
248
249};
250
251
252
253struct HelpFame :
public uiFrame {
254
255 HelpFame(uiFrame * parent)
256 : uiFrame(parent, "Help", UIWINDOW_PARENTCENTER, Size(218, 335), false) {
257
258 auto button =
new uiButton(
this,
"OK", Point(84, 305), Size(50, 20));
259 button->
onClick = [&]() { exitModal(0); };
260
261 onPaint = [&]() {
262 auto cv = canvas();
263 cv->selectFont(&fabgl::FONT_6x8);
264 int x = 4;
265 int y = 10;
266 cv->setPenColor(Color::Green);
267 cv->drawText(x, y += 14, "Keyboard Shortcuts:");
268 cv->setPenColor(Color::Black);
269 cv->setBrushColor(Color::White);
270 cv->drawText(x, y += 14, " F12 > Run or Config");
271 cv->drawText(x, y += 14, " DEL > Delete File/Folder");
272 cv->drawText(x, y += 14, " ALT + ASWZ > Move Screen");
273 cv->setPenColor(Color::Blue);
274 cv->drawText(x, y += 18, "\"None\" Joystick Mode:");
275 cv->setPenColor(Color::Black);
276 cv->drawText(x, y += 14, " ALT + MENU > Joystick Fire");
277 cv->drawText(x, y += 14, " ALT + CURSOR > Joystick Move");
278 cv->setPenColor(Color::Red);
279 cv->drawText(x, y += 18, "\"Cursor Keys\" Joystick Mode:");
280 cv->setPenColor(Color::Black);
281 cv->drawText(x, y += 14, " MENU > Joystick Fire");
282 cv->drawText(x, y += 14, " CURSOR > Joystick Move");
283 cv->setPenColor(Color::Magenta);
284 cv->drawText(x, y += 18, "Emulated keyboard:");
285 cv->setPenColor(Color::Black);
286 cv->drawText(x, y += 14, " HOME > CLR/HOME");
287 cv->drawText(x, y += 14, " ESC > RUN/STOP");
288 cv->drawText(x, y += 14, " Left Win Key > CBM");
289 cv->drawText(x, y += 14, " DELETE > RESTORE");
290 cv->drawText(x, y += 14, " BACKSPACE > INST/DEL");
291 cv->drawText(x, y += 14, " Caret ^ > UP ARROW");
292 cv->drawText(x, y += 14, " Underscore _ > LEFT ARROW");
293 cv->drawText(x, y += 14, " Tilde ~ > M_PI");
294 };
295 }
296
297};
298
299
300
301class Menu :
public uiApp {
302
303 uiFileBrowser * fileBrowser;
304 uiComboBox * RAMExpComboBox;
305 uiComboBox * kbdComboBox;
306 uiLabel * freeSpaceLbl;
307
308
309 Machine * machine;
310
311
312 void init() {
313 machine = new Machine(&DisplayController);
314
315 setStyle(&dialogStyle);
316
317 rootWindow()->frameStyle().backgroundColor = BACKGROUND_COLOR;
318
319
320 rootWindow()->onPaint = [&]() {
321 auto cv = canvas();
322 cv->selectFont(&fabgl::FONT_SLANT_8x14);
323 cv->setPenColor(RGB888(0, 128, 255));
324 cv->drawText(136, 345, "VIC20 Emulator");
325
326 cv->selectFont(&fabgl::FONT_std_12);
327 cv->setPenColor(RGB888(255, 128, 0));
328 cv->drawText(160, 358, "www.fabgl.com");
329 cv->drawText(130, 371, "2019/26 by Fabrizio Di Vittorio");
330 };
331
332
333 fileBrowser =
new uiFileBrowser(rootWindow(), Point(5, 10), Size(140, 290),
true, STYLE_FILEBROWSER);
337 setSelectedProgramConf();
338 };
339
340
341
342
343 rootWindow()->onKeyUp = [&](uiKeyEventInfo const & key) {
344 switch (key.VK) {
345
346 case VirtualKey::VK_F1:
347 showHelp();
348 break;
349
350 case VirtualKey::VK_ESCAPE:
351 case VirtualKey::VK_F12:
352 runVIC20();
353 break;
354
355 default:
356 break;
357 }
358 };
359
360
361
362
363 fileBrowser->
onKeyUp = [&](uiKeyEventInfo
const & key) {
364 switch (key.VK) {
365
366 case VirtualKey::VK_RETURN:
367 if (!fileBrowser->
isDirectory() && loadSelectedProgram())
368 runVIC20();
369 break;
370
371 case VirtualKey::VK_DELETE:
372 if (messageBox("Delete Item", "Are you sure?", "Yes", "Cancel") == uiMessageBoxResult::Button1) {
375 updateFreeSpaceLabel();
376 }
377 break;
378
379 default:
380 break;
381 }
382 };
383
384
386 if (!fileBrowser->
isDirectory() && loadSelectedProgram())
387 runVIC20();
388 };
389
390 int x = 158;
391
392
393 auto VIC20Button =
new uiButton(rootWindow(),
"Run [F12]", Point(x, 10), Size(75, 19), uiButtonKind::Button,
true, STYLE_BUTTON);
394 VIC20Button->onClick = [&]() {
395 runVIC20();
396 };
397
398
399 auto loadButton =
new uiButton(rootWindow(),
"Load", Point(x, 35), Size(75, 19), uiButtonKind::Button,
true, STYLE_BUTTON);
400 loadButton->onClick = [&]() {
401 if (loadSelectedProgram())
402 runVIC20();
403 };
404
405
406 auto resetButton =
new uiButton(rootWindow(),
"Soft Reset", Point(x, 60), Size(75, 19), uiButtonKind::Button,
true, STYLE_BUTTON);
407 resetButton->onClick = [&]() {
408 machine->reset();
409 runVIC20();
410 };
411
412
413 auto hresetButton =
new uiButton(rootWindow(),
"Hard Reset", Point(x, 85), Size(75, 19), uiButtonKind::Button,
true, STYLE_BUTTON);
414 hresetButton->onClick = [&]() {
415 machine->removeCRT();
416 machine->reset();
417 runVIC20();
418 };
419
420
421 auto helpButton =
new uiButton(rootWindow(),
"HELP [F1]", Point(x, 110), Size(75, 19), uiButtonKind::Button,
true, STYLE_BUTTONHELP);
422 helpButton->onClick = [&]() {
423 showHelp();
424 };
425
426
427 int y = 145;
428 new uiStaticLabel(rootWindow(),
"Keyboard Layout:", Point(150, y),
true, STYLE_LABELGROUP);
429 kbdComboBox =
new uiComboBox(rootWindow(), Point(158, y + 20), Size(75, 20), 70,
true, STYLE_COMBOBOX);
430 kbdComboBox->
items().append(SupportedLayouts::names(), SupportedLayouts::count());
432 preferences.putInt(
"kbdLayout", kbdComboBox->
selectedItem());
433 updateKbdLayout();
434 };
436
437
438 y += 50;
439 new uiStaticLabel(rootWindow(),
"RAM Expansion:", Point(150, y),
true, STYLE_LABELGROUP);
440 RAMExpComboBox =
new uiComboBox(rootWindow(), Point(158, y + 20), Size(75, 19), 130,
true, STYLE_COMBOBOX);
441 char const * RAMOPTS[] = { "Unexpanded", "3K", "8K", "16K", "24K", "27K (24K+3K)", "32K", "35K (32K+3K)" };
442 for (int i = 0; i < 8; ++i)
443 RAMExpComboBox->
items().append(RAMOPTS[i]);
444 RAMExpComboBox->
selectItem((
int)machine->RAMExpansion());
446 machine->setRAMExpansion((RAMExpansionOption)(RAMExpComboBox->
selectedItem()));
447 };
448
449
450 y += 50;
451 new uiStaticLabel(rootWindow(),
"Joystick:", Point(150, y),
true, STYLE_LABELGROUP);
452 new uiStaticLabel(rootWindow(),
"None", Point(180, y + 21),
true, STYLE_STATICLABEL);
453 auto radioJNone =
new uiCheckBox(rootWindow(), Point(158, y + 20), Size(16, 16), uiCheckBoxKind::RadioButton,
true, STYLE_CHECKBOX);
454 new uiStaticLabel(rootWindow(),
"Cursor Keys", Point(180, y + 41),
true, STYLE_STATICLABEL);
455 auto radioJCurs =
new uiCheckBox(rootWindow(), Point(158, y + 40), Size(16, 16), uiCheckBoxKind::RadioButton,
true, STYLE_CHECKBOX);
456 new uiStaticLabel(rootWindow(),
"Mouse", Point(180, y + 61),
true, STYLE_STATICLABEL);
457 auto radioJMous =
new uiCheckBox(rootWindow(), Point(158, y + 60), Size(16, 16), uiCheckBoxKind::RadioButton,
true, STYLE_CHECKBOX);
458 radioJNone->setGroupIndex(1);
459 radioJCurs->setGroupIndex(1);
460 radioJMous->setGroupIndex(1);
461 radioJNone->setChecked(machine->joyEmu() == JE_None);
462 radioJCurs->setChecked(machine->joyEmu() == JE_CursorKeys);
463 radioJMous->setChecked(machine->joyEmu() == JE_Mouse);
464 radioJNone->onChange = [&]() { machine->setJoyEmu(JE_None); };
465 radioJCurs->onChange = [&]() { machine->setJoyEmu(JE_CursorKeys); };
466 radioJMous->onChange = [&]() { machine->setJoyEmu(JE_Mouse); };
467
468
469 freeSpaceLbl =
new uiLabel(rootWindow(),
"", Point(5, 304), Size(0, 0),
true, STYLE_LABEL);
470 updateFreeSpaceLabel();
471
472
473 new uiStaticLabel(rootWindow(),
"Download From:", Point(5, 326),
true, STYLE_LABELGROUP);
474
475
476 auto downloadProgsBtn =
new uiButton(rootWindow(),
"Web", Point(13, 345), Size(27, 20), uiButtonKind::Button,
true, STYLE_BUTTON);
477 downloadProgsBtn->onClick = [&]() {
478 if (checkWiFi() && messageBox("Download Programs listed in \"weblist.h\"", "Check your local laws for restrictions", "OK", "Cancel", nullptr, uiMessageBoxIcon::Warning) == uiMessageBoxResult::Button1) {
479 auto pframe = new DownloadProgressFrame(rootWindow());
480 auto modalStatus = initModalWindow(pframe);
481 processModalWindowEvents(modalStatus, 100);
482 prepareForDownload();
483 char const * const * plist = WEB_LIST;
484 int count = sizeof(WEB_LIST) / (2 * sizeof(char const *));
485 int dcount = 0;
486 for (int i = 0; i < count; ++i) {
487 char const * filename = *plist++;
488 char const * URL = *plist++;
489 pframe->label1->setText(filename);
490 if (!processModalWindowEvents(modalStatus, 100))
491 break;
492 if (downloadURL(URL, filename))
493 ++dcount;
494 pframe->label2->setTextFmt("Downloaded %d/%d", dcount, count);
495 }
496
497 pframe->button->setText("OK");
498 pframe->button->repaint();
499
500 processModalWindowEvents(modalStatus, -1);
501 endModalWindow(modalStatus);
502 destroyWindow(pframe);
504 updateFreeSpaceLabel();
505 }
507 };
508
509
510 auto downloadURLBtn =
new uiButton(rootWindow(),
"URL", Point(48, 345), Size(27, 20), uiButtonKind::Button,
true, STYLE_BUTTON);
511 downloadURLBtn->onClick = [&]() {
512 if (checkWiFi()) {
513 char * URL = new char[128];
514 char * filename = new char[25];
515 strcpy(URL, "http://");
516 if (inputBox("Download From URL", "URL", URL, 127, "OK", "Cancel") == uiMessageBoxResult::Button1) {
517 char * lastslash = strrchr(URL, '/');
518 if (lastslash) {
519 strcpy(filename, lastslash + 1);
520 if (inputBox("Download From URL", "Filename", filename, 24, "OK", "Cancel") == uiMessageBoxResult::Button1) {
521 if (downloadURL(URL, filename)) {
522 messageBox("Success", "Download OK!", "OK", nullptr, nullptr);
524 updateFreeSpaceLabel();
525 } else
526 messageBox("Error", "Download Failed!", "OK", nullptr, nullptr, uiMessageBoxIcon::Error);
527 }
528 }
529 }
530 delete [] filename;
531 delete [] URL;
533 }
534 };
535
536
537 setFocusedWindow(fileBrowser);
538 }
539
540
541 void runVIC20()
542 {
543 auto keyboard = PS2Controller.
keyboard();
544
545 enableKeyboardAndMouseEvents(false);
546 keyboard->emptyVirtualKeyQueue();
547 machine->VIC().enableAudio(true);
548
549
550 machine->fileBrowser()->setDirectory(basepath);
551 if (!machine->fileBrowser()->exists(USERDIR, false))
552 machine->fileBrowser()->makeDirectory(USERDIR);
553 machine->fileBrowser()->changeDirectory(USERDIR);
554
555 auto cv = canvas();
556 cv->setBrushColor(0, 0, 0);
557 cv->clear();
558 cv->waitCompletion();
559
560 bool run = true;
561 while (run) {
562
563 #if DEBUGMACHINE
564 int cycles = machine->run();
565 if (restart) {
566 scycles = cycles;
567 restart = false;
568 } else
569 scycles += cycles;
570 #else
571 machine->run();
572 #endif
573
574
575 if (keyboard->virtualKeyAvailable()) {
576 bool keyDown;
577 VirtualKey vk = keyboard->getNextVirtualKey(&keyDown);
578 switch (vk) {
579
580
581 case VirtualKey::VK_F12:
582 if (!keyDown)
583 run = false;
584 break;
585
586
587 default:
588
589 machine->setKeyboard(vk, keyDown);
590 break;
591 }
592 }
593
594 }
595 machine->VIC().enableAudio(false);
596 keyboard->emptyVirtualKeyQueue();
597 enableKeyboardAndMouseEvents(true);
598 rootWindow()->repaint();
599 }
600
601
602 void setSelectedProgramConf()
603 {
604 char const * fname = fileBrowser->
filename();
605 if (fname) {
606
607 static char const * EXP[8] = { "", " 3K", " 8K", " 16K", " 24K", " 27K", " 32K", " 35K" };
608 int r = 0;
609 for (int i = 1; i < 8; ++i)
610 if (strstr(fname, EXP[i])) {
611 r = i;
612 break;
613 }
615 }
616 }
617
618
619
620 int getAddress(char * filename, char * * addrPos = nullptr)
621 {
622 static char const * ASTR[] = { " 20", " 40", " 60", " a0", " A0" };
623 static const int ADDR[] = { 0x2000, 0x4000, 0x6000, 0xa000, 0xa000 };
624 for (int i = 0; i < sizeof(ADDR) / sizeof(int); ++i) {
625 auto p = strstr(filename, ASTR[i]);
626 if (p) {
627 if (addrPos)
628 *addrPos = p + 1;
629 return ADDR[i];
630 }
631 }
632 return -1;
633 }
634
635
636
637
638
639
640
641 bool loadSelectedProgram()
642 {
643 bool backToVIC = false;
644 char const * fname = fileBrowser->
filename();
645 if (fname) {
646 FileBrowser & dir = fileBrowser->
content();
647
648 bool isPRG = strstr(fname, ".PRG") || strstr(fname, ".prg");
649 bool isCRT = strstr(fname, ".CRT") || strstr(fname, ".crt");
650
651 if (isPRG || isCRT) {
652
653 machine->removeCRT();
654
656 char fullpath[fullpathlen];
658
659 if (isPRG) {
660
661 machine->loadPRG(fullpath, true, true);
662 } else if (isCRT) {
663
664 char * addrPos = nullptr;
665 int addr = getAddress(fullpath, &addrPos);
666 if (addrPos) {
667
668 static const char * POS = { "246Aa" };
669 for (int i = 0; i < sizeof(POS); ++i) {
670 *addrPos = POS[i];
671 machine->loadCRT(fullpath, true, getAddress(fullpath));
672 }
673 } else {
674
675 machine->loadCRT(fullpath, true, addr);
676 }
677 }
678 backToVIC = true;
679 }
680 }
681 return backToVIC;
682 }
683
684
685 bool checkWiFi() {
687 return true;
688 char SSID[32] = "";
689 char psw[32] = "";
690 if (!preferences.
getString(
"SSID", SSID,
sizeof(SSID)) || !preferences.
getString(
"WiFiPsw", psw,
sizeof(psw))) {
691
692 if (inputBox("WiFi Connect", "WiFi Name", SSID, sizeof(SSID), "OK", "Cancel") == uiMessageBoxResult::Button1 &&
693 inputBox("WiFi Connect", "Password", psw, sizeof(psw), "OK", "Cancel") == uiMessageBoxResult::Button1) {
694 preferences.putString("SSID", SSID);
695 preferences.putString("WiFiPsw", psw);
696 } else
697 return false;
698 }
700 if (!connected) {
701 messageBox("Network Error", "Failed to connect WiFi. Try again!", "OK", nullptr, nullptr, uiMessageBoxIcon::Error);
702 preferences.
remove(
"WiFiPsw");
703 }
704 return connected;
705 }
706
707
708 void prepareForDownload()
709 {
710 FileBrowser & dir = fileBrowser->
content();
714 }
715
716
717 bool downloadURL(char const * URL, char const * filename)
718 {
719
720 FileBrowser & dir = fileBrowser->
content();
721 if (dir.
exists(filename,
false)) {
722 return true;
723 }
724 bool success = false;
725 fabgl::HTTPRequest http;
726 int httpCode = http.
open(URL);
727 if (httpCode == 200) {
728
730 char fullpath[fullpathLen];
732 FILE * f = fopen(fullpath, "wb");
733
734 if (f) {
736 constexpr int BUFSIZE = 1024;
737 uint8_t * buf = (uint8_t*) malloc(BUFSIZE);
738 int dsize = 0;
739 while (len > 0 || len == -1) {
740 int c = http.
read(buf, BUFSIZE);
741 if (c <= 0)
742 break;
743 fwrite(buf, c, 1, f);
744 dsize += c;
745 if (len > 0)
746 len -= c;
747 }
748 free(buf);
749 fclose(f);
750 success = (len == 0 || (len == -1 && dsize > 0));
751 if (!success)
752 remove(fullpath);
753 }
754 }
755
756 return success;
757 }
758
759
760 void updateFreeSpaceLabel() {
761 int64_t total, used;
763 freeSpaceLbl->
setTextFmt(
"%lld KiB Free", (total - used) / 1024);
765 }
766
767 int updateKbdLayout() {
768 auto curLayoutIdx = preferences.getInt("kbdLayout", 3);
770 return curLayoutIdx;
771 }
772
773 void showHelp() {
774 auto hframe = new HelpFame(rootWindow());
775 showModalWindow(hframe);
776 destroyWindow(hframe);
777 }
778
779
780};
781
782
783
786
787
788
789
790void setup()
791{
792 #if DEBUG
793 vTaskDelay(pdMS_TO_TICKS(500)); printf("\n\n\nReset\n");
794 #endif
795
796 preferences.
begin(
"VIC20",
false);
797
798
799 PS2Controller.
begin(PS2Preset::KeyboardPort0_MousePort1, KbdMode::CreateVirtualKeysQueue);
800
801 DisplayController.
begin();
803
804
805
806
807
808
809
810 Canvas cv(&DisplayController);
811 cv.selectFont(&fabgl::FONT_6x8);
812
813 cv.clear();
814 cv.drawText(25, 10, "Initializing...");
815 cv.waitCompletion();
816
818 basepath = SDCARD_MOUNT_PATH;
820 basepath = SPIFFS_MOUNT_PATH;
821
822 cv.drawText(25, 30, "Copying embedded programs...");
823 cv.waitCompletion();
824 copyEmbeddedPrograms();
825}
826
827
828void loop()
829{
830 #if DEBUGMACHINE
831 TimerHandle_t xtimer = xTimerCreate("", pdMS_TO_TICKS(5000), pdTRUE, (void*)0, vTimerCallback1SecExpired);
832 xTimerStart(xtimer, 0);
833 #endif
834
835 auto menu = new Menu;
836 menu->run(&DisplayController);
837}
838
839
840extern "C" void app_main()
841{
842 setup();
843 while (true)
844 loop();
845}
Provides a set of drawing methods.
static bool mountSPIFFS(bool formatOnFail, char const *mountPath, size_t maxFiles=4)
Mounts the SPIFFS (Flash) filesystem.
void changeDirectory(const char *subdir)
Changes to a directory relative to the current one.
static bool mountSDCard(bool formatOnFail, char const *mountPath, size_t maxFiles=4, int allocationUnitSize=16 *1024, int MISO=16, int MOSI=17, int CLK=14, int CS=13)
Mounts the filesystem of the SD Card.
bool setDirectory(const char *path)
Sets the absolute directory path.
int getFullPath(char const *name, char *outPath=nullptr, int maxlen=0)
Builds the full file path of a relative name.
void remove(char const *name)
Removes a file or directory.
DriveType getCurrentDriveType()
Returns the drive type of the current directory.
bool exists(char const *name, bool caseSensitive=true)
Determines whether a file or directory exists.
static bool getFSInfo(DriveType driveType, int drive, int64_t *total, int64_t *used)
Gets the total and used space of a filesystem.
void makeDirectory(char const *dirname)
Creates a directory.
FileBrowser provides basic file system operations (directory listing, mkdir, remove and rename).
bool remove(char const *key)
Removes the specified key.
size_t getString(char const *key, char *value, size_t maxLen)
Gets a string.
bool begin(char const *name, bool readOnly=false)
Opens the specified namespace.
Simple key/value storage in non-volatile flash (NVS).
int open(char const *URL, int64_t rangeStart=0)
Opens a streaming GET request (follows redirects).
int contentLength()
Gets the content length.
int read(void *buffer, int length)
Reads content after a successful open().
void setLayout(KeyboardLayout const *layout)
Sets the keyboard layout.
static Keyboard * keyboard()
Returns the Keyboard object automatically created by PS2Controller.
static void begin(gpio_num_t port0_clkGPIO, gpio_num_t port0_datGPIO, gpio_num_t port1_clkGPIO=GPIO_UNUSED, gpio_num_t port1_datGPIO=GPIO_UNUSED)
Initializes the PS/2 device controller.
void begin(gpio_num_t redGPIO, gpio_num_t greenGPIO, gpio_num_t blueGPIO, gpio_num_t HSyncGPIO, gpio_num_t VSyncGPIO)
Initializer for 8 colors (5 GPIOs).
VGA bitmapped display controller (64 colors).
WiFiConnectionState connect(char const *ssid, char const *password, int waitConnectionTimeOutMS=10000)
Tries to connect to a WiFi network.
WiFiConnectionState state()
Returns the connection state.
void disconnect()
Disconnects from the WiFi network.
WiFi connection helper class.
Delegate onChange
Change event delegate.
int selectedItem()
Represents currently selected item.
void selectItem(int index)
Selects an item.
Delegate onChange
Change event delegate.
Delegate< uiKeyEventInfo const & > onKeyUp
Key-up event delegate.
Delegate onDblClick
Mouse double click event delegate.
Represents the whole application base class.
uiCheckBox(uiWindow *parent, const Point &pos, const Size &size, uiCheckBoxKind kind=uiCheckBoxKind::CheckBox, bool visible=true, uint32_t styleClassID=0)
Creates an instance of the object.
StringList & items()
A list of strings representing items of the combobox.
uiComboBox(uiWindow *parent, const Point &pos, const Size &size, int listHeight, bool visible=true, uint32_t styleClassID=0)
Creates an instance of the object.
FileBrowser & content()
Contains current directory representation.
void changeDirectory(char const *path)
Changes current directory as relative path.
void setDirectory(char const *path)
Sets current directory as absolute path.
char const * filename()
Currently selected filename.
bool isDirectory()
Determines whether currently selected item is a directory.
void update()
Reloads current directory content and repaints.
uiFileBrowser(uiWindow *parent, const Point &pos, const Size &size, bool visible=true, uint32_t styleClassID=0)
Creates an instance of the object.
A frame is a window with a title bar, maximize/minimize/close buttons and that is resizable or movabl...
void setTextFmt(const char *format,...)
Sets label formatted text.
uiLabel(uiWindow *parent, char const *text, const Point &pos, const Size &size=Size(0, 0), bool visible=true, uint32_t styleClassID=0)
Creates an instance of the object.
void update()
Updates the label content.
uiStaticLabel(uiWindow *parent, char const *text, const Point &pos, bool visible=true, uint32_t styleClassID=0)
Creates an instance of the object.
VirtualKey
Represents each possible real or derived (SHIFT + real) key.
Single include file of the FabGL library.
This file contains utility classes and functions.
This file contains the fabgl::WiFiScanner, fabgl::WiFiConnection, fabgl::HTTPRequest and fabgl::TCPCl...
Base class for application styles.