Multitasking - Multisession CP/M 3 compatible system. Supports directories and FAT32 file system with SD Cards.
#include "src/supervisor.h"
#include "src/programs.h"
#define FORMAT_ON_FAIL true
#define SPIFFS_MOUNT_PATH "/flash"
#define SDCARD_MOUNT_PATH "/SD"
#define MAXFILES 6 // SDCARD: each file takes about 4K of RAM!
Supervisor supervisor(&DisplayController);
char const * basepath = nullptr;
String driveA_path;
String driveB_path;
void setup()
{
disableCore0WDT();
disableCore1WDT();
PS2Controller.
begin(PS2Preset::KeyboardPort0_MousePort1);
DisplayController.
begin();
term->
begin(&DisplayController);
term->connectLocally();
term->clear();
term->write("Initializing...\r");
term->flush();
if (FileBrowser::mountSDCard(FORMAT_ON_FAIL, SDCARD_MOUNT_PATH, MAXFILES))
basepath = SDCARD_MOUNT_PATH;
else if (FileBrowser::mountSPIFFS(FORMAT_ON_FAIL, SPIFFS_MOUNT_PATH, MAXFILES))
basepath = SPIFFS_MOUNT_PATH;
driveA_path = String(basepath) + String("/driveA");
driveB_path = String(basepath) + String("/driveB");
FileBrowser fb;
fb.setDirectory(basepath);
if (!fb.exists("driveA")) {
fb.makeDirectory("driveA");
for (int i = 0; i < sizeof(programs) / sizeof(Program); ++i) {
term->printf("Creating %s\\%s\r\n", programs[i].path, programs[i].filename);
term->flush();
fb.setDirectory(driveA_path.c_str());
if (!fb.exists(programs[i].path))
fb.makeDirectory(programs[i].path);
fb.changeDirectory(programs[i].path);
FILE * f = fb.openFile(programs[i].filename, "wb");
if (f) {
fwrite(programs[i].
data, 1, programs[i].size, f);
fclose(f);
} else {
term->write(" FAILED!\r\n");
}
}
}
fb.setDirectory(basepath);
if (!fb.exists("driveB"))
fb.makeDirectory("driveB");
delete term;
supervisor.onNewSession = [&](HAL * hal) {
hal->mountDrive(0, driveA_path.c_str());
hal->mountDrive(1, driveB_path.c_str());
hal->setSerial(0, &Serial);
};
if (keyDown) {
}
}
};
}
void loop()
{
supervisor.activateSession(0);
vTaskDelete(NULL);
}