Skip to content

Commit

Permalink
Work on workspaces
Browse files Browse the repository at this point in the history
dirkwhoffmann committed Jan 30, 2025
1 parent 64e7afc commit e57c9ac
Showing 10 changed files with 128 additions and 98 deletions.
50 changes: 27 additions & 23 deletions Emulator/Base/CoreComponent.cpp
Original file line number Diff line number Diff line change
@@ -365,32 +365,36 @@ CoreComponent::exportConfig(std::ostream& ss, bool diff) const
{
bool first = true;

for (auto &opt: getOptions()) {

auto current = getOption(opt);
auto fallback = getFallback(opt);

if (!diff || current != fallback) {

if (first) {

ss << "# " << description() << std::endl << std::endl;
first = false;
if (string(shellName()) != "") {

auto cmd = "try " + string(shellName());

for (auto &opt: getOptions()) {

auto current = getOption(opt);
auto fallback = getFallback(opt);

if (!diff || current != fallback) {

if (first) {

ss << "# " << description() << std::endl << std::endl;
first = false;
}

auto currentStr = OptionParser::asPlainString(opt, current);
auto fallbackStr = OptionParser::asPlainString(opt, fallback);

string line = cmd + " set " + OptEnum::key(opt) + " " + currentStr;
string comment = diff ? fallbackStr : OptEnum::help(opt);

ss << std::setw(40) << std::left << line << " # " << comment << std::endl;
}

auto cmd = "try " + string(shellName());
auto currentStr = OptionParser::asPlainString(opt, current);
auto fallbackStr = OptionParser::asPlainString(opt, fallback);

string line = cmd + " set " + OptEnum::key(opt) + " " + currentStr;
string comment = diff ? fallbackStr : OptEnum::help(opt);

ss << std::setw(40) << std::left << line << " # " << comment << std::endl;
}

if (!first) ss << std::endl;
}

if (!first) ss << std::endl;


for (auto &sub: subComponents) {

sub->exportConfig(ss, diff);
2 changes: 1 addition & 1 deletion Emulator/Base/CoreComponentTypes.h
Original file line number Diff line number Diff line change
@@ -55,7 +55,7 @@ enum class Class : long
ZorroManager,

// Ports
AudipPort,
AudioPort,
ControlPort,
SerialPort,
VideoPort,
76 changes: 50 additions & 26 deletions Emulator/Components/Amiga.cpp
Original file line number Diff line number Diff line change
@@ -310,46 +310,67 @@ Amiga::setOption(Opt option, i64 value)
void
Amiga::loadWorkspace(const fs::path &path)
{
std::stringstream ss;

auto exec = [&](const string &cmd) {

retroShell.asyncExec("try " + cmd);
ss << "try " << cmd << "\n";
};
auto importADF = [&](FloppyDrive& drive, string file) {
auto importScript = [&](const fs::path &path) {

exec("df0 insert " + (path / file).string());
// try { ADFFile adf(file); drive.insertMediaFile(adf, false); } catch (...) { }
if (fs::exists(path)) {
Script script(path); script.writeToStream(ss);
}
};
auto importHDF = [&](HardDrive& drive, string file) {

exec("hd0 attach " + (path / file).string());
auto importRom = [&](const string type, const fs::path &path) {

if (fs::exists(path)) {
exec("mem load " + type + " " + path.string());
}
};
auto importADF = [&](FloppyDrive& drive, const fs::path &path) {

if (fs::exists(path)) {
exec(string(drive.shellName()) + " insert " + path.string());
}
};
auto importHDF = [&](HardDrive& drive, const fs::path &path) {

if (fs::exists(path)) {
exec(string(drive.shellName()) + " attach " + path.string());
}
};

try {

// Prepare the setup script...

// Power off the Amiga
exec("amiga power off");
// Configure the emulator by applying the workspace script
Script script(path / "config.ini"); retroShell.asyncExecScript(script);

// Read the config script
importScript(path / "config.ini");

// Load ROMs
exec("mem load ROM " + (path / "rom.bin").string());
exec("mem load WOM " + (path / "wom.bin").string());
exec("mem load EXT " + (path / "ext.bin").string());
importRom("rom", path / "rom.bin");
importRom("ext", path / "ext.bin");

// Load media
importADF(df0, "df0.adf");
importADF(df1, "df1.adf");
importADF(df2, "df2.adf");
importADF(df3, "df3.adf");
importHDF(hd0, "hd0.hdf");
importHDF(hd1, "hd1.hdf");
importHDF(hd2, "hd2.hdf");
importHDF(hd3, "hd3.hdf");
importADF(df0, path / "df0.adf");
importADF(df1, path / "df1.adf");
importADF(df2, path / "df2.adf");
importADF(df3, path / "df3.adf");
importHDF(hd0, path / "hd0.hdf");
importHDF(hd1, path / "hd1.hdf");
importHDF(hd2, path / "hd2.hdf");
importHDF(hd3, path / "hd3.hdf");

// Power on the Amiga
exec("amiga power on");

// Execute the setup script
retroShell.asyncExecScript(ss);

} catch (...) { }

}
@@ -370,12 +391,15 @@ Amiga::saveWorkspace(const fs::path &path)
}
};

// If a file with the specified name exists, replace it by a directoy
// If a file with the specified name exists, delete it
if (fs::exists(path) && !fs::is_directory(path)) fs::remove(path);

// Create the directory if it does not exist
// Create the directory if necessary
if (!fs::exists(path)) fs::create_directories(path);

// Remove old files
for (const auto& entry : fs::directory_iterator(path)) fs::remove_all(entry.path());

// Save ROMs
if (mem.hasRom()) mem.saveRom(path / "rom.bin");
if (mem.hasWom()) mem.saveWom(path / "wom.bin");
@@ -424,10 +448,10 @@ Amiga::exportConfig(std::ostream &stream, bool diff) const
{
stream << "# vAmiga " << Amiga::build() << "\n";
stream << "\n";
stream << "amiga power off\n";
stream << "\n";
// stream << "amiga power off\n";
// stream << "\n";
CoreComponent::exportConfig(stream, diff);
stream << "amiga power on\n";
// stream << "amiga power on\n";
}

void
2 changes: 1 addition & 1 deletion Emulator/Components/Paula/Audio/AudioFilter.h
Original file line number Diff line number Diff line change
@@ -117,7 +117,7 @@ class AudioFilter final : public SubComponent {
.type = Class::AudioFilter,
.name = "AudioFilter",
.description = "Audio Filter",
.shell = "filter"
.shell = "audio filter"
},
{
.type = Class::AudioFilter,
2 changes: 1 addition & 1 deletion Emulator/Components/Paula/DiskController/DiskController.h
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@ class DiskController final : public SubComponent, public Inspectable<DiskControl
.type = Class::DiskController,
.name = "DiskController",
.description = "Disk Controller",
.shell = "dc"
.shell = "paula dc"
}};

ConfigOptions options = {
4 changes: 2 additions & 2 deletions Emulator/Components/Ports/AudioPort.h
Original file line number Diff line number Diff line change
@@ -48,13 +48,13 @@ class AudioPort final : public SubComponent {

Descriptions descriptions = {
{
.type = Class::AudipPort,
.type = Class::AudioPort,
.name = "AudioPort",
.description = "Audio Port",
.shell = "audio"
},
{
.type = Class::AudipPort,
.type = Class::AudioPort,
.name = "RecAudioPort",
.description = "Audio Port (Recorder)",
.shell = ""
1 change: 1 addition & 0 deletions Emulator/Media/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@ MediaFile.cpp
AmigaFile.cpp
Snapshot.cpp
Script.cpp
Workspace.cpp

)

8 changes: 4 additions & 4 deletions Emulator/Misc/RemoteServers/RemoteServer.h
Original file line number Diff line number Diff line change
@@ -25,19 +25,19 @@ class RemoteServer : public SubComponent {

.name = "SerServer",
.description = "Serial Port Server",
.shell = "serial"
.shell = "server serial"
}, {
.name = "RshServer",
.description = "Remote Shell Server",
.shell = "rshell"
.shell = "server rshell"
}, {
.name = "PromServer",
.description = "Prometheus Server",
.shell = "prom"
.shell = "server prom"
}, {
.name = "GdbServer",
.description = "GDB Remote Server",
.shell = "gdb"
.shell = "server gdb"
}};

ConfigOptions options = {
72 changes: 35 additions & 37 deletions Emulator/Misc/RetroShell/CommandConsole.cpp
Original file line number Diff line number Diff line change
@@ -276,7 +276,7 @@ CommandConsole::initCommands(RetroShellCmd &root)
//

cmd = registerComponent(paula);
cmd = registerComponent(diskController, root / cmd);
cmd = registerComponent(diskController);


//
@@ -350,7 +350,8 @@ CommandConsole::initCommands(RetroShellCmd &root)
//

cmd = registerComponent(audioPort);
cmd = registerComponent(audioPort.filter, root / cmd);
cmd = registerComponent(audioPort.filter);
// cmd = registerComponent(audioPort.filter, root / cmd);


//
@@ -602,33 +603,30 @@ CommandConsole::initCommands(RetroShellCmd &root)

cmd = registerComponent(*hd[i]);

if (i != 4) {
root.add({cmd, "connect"},
"Connects the hard drive",
[this](Arguments& argv, long value) {

root.add({cmd, ""},
"Displays the current configuration",
[this](Arguments& argv, long value) {

dump(*amiga.hd[value], Category::Config);

}, i);
emulator.set(Opt::HDC_CONNECT, true, {value});

root.add({cmd, "connect"},
"Connects the hard drive",
[this](Arguments& argv, long value) {

emulator.set(Opt::HDC_CONNECT, true, {value});

}, i);
}, i);

root.add({cmd, "disconnect"},
"Disconnects the hard drive",
[this](Arguments& argv, long value) {

root.add({cmd, "disconnect"},
"Disconnects the hard drive",
[this](Arguments& argv, long value) {

emulator.set(Opt::HDC_CONNECT, false, {value});

}, i);
emulator.set(Opt::HDC_CONNECT, false, {value});

}
}, i);

root.add({cmd, "attach"}, { Arg::path },
"Attaches a hard drive image",
[this](Arguments& argv, long value) {

auto path = argv.front();
amiga.hd[value]->init(path);

}, i);

root.add({cmd, "geometry"}, { "<cylinders>", "<heads>", "<sectors>" },
"Changes the disk geometry",
@@ -697,64 +695,64 @@ CommandConsole::initCommands(RetroShellCmd &root)
dump(remoteManager, Category::Status);
});

cmd = registerComponent(remoteManager.serServer, root / "server");
cmd = registerComponent(remoteManager.serServer);

cmd = registerComponent(remoteManager.rshServer, root / "server");
cmd = registerComponent(remoteManager.rshServer);

root.add({"server", cmd, "start"},
root.add({cmd, "start"},
"Starts the retro shell server",
[this](Arguments& argv, long value) {

remoteManager.rshServer.start();
});

root.add({"server", cmd, "stop"},
root.add({cmd, "stop"},
"Stops the retro shell server",
[this](Arguments& argv, long value) {

remoteManager.rshServer.stop();
});

root.add({"server", cmd, "disconnect"},
root.add({cmd, "disconnect"},
"Disconnects a client",
[this](Arguments& argv, long value) {

remoteManager.rshServer.disconnect();
});

cmd = registerComponent(remoteManager.promServer, root / "server");
cmd = registerComponent(remoteManager.promServer);

root.add({"server", cmd, "start"},
root.add({cmd, "start"},
"Starts the Prometheus server",
[this](Arguments& argv, long value) {

remoteManager.promServer.start();
});

root.add({"server", cmd, "stop"},
root.add({cmd, "stop"},
"Stops the Prometheus server",
[this](Arguments& argv, long value) {

remoteManager.promServer.stop();
});

root.add({"server", cmd, "disconnect"},
root.add({cmd, "disconnect"},
"Disconnects a client",
[this](Arguments& argv, long value) {

remoteManager.promServer.disconnect();
});

cmd = registerComponent(remoteManager.gdbServer, root / "server");
cmd = registerComponent(remoteManager.gdbServer);

root.add({"server", cmd, "attach"}, { Arg::process },
root.add({cmd, "attach"}, { Arg::process },
"Attaches the GDB server to a process",
[this](Arguments& argv, long value) {

remoteManager.gdbServer.attach(argv.front());
});

root.add({"server", cmd, "detach"},
root.add({cmd, "detach"},
"Detaches the GDB server from a process",
[this](Arguments& argv, long value) {

9 changes: 6 additions & 3 deletions Emulator/Misc/RetroShell/RetroShellCmd.cpp
Original file line number Diff line number Diff line change
@@ -18,10 +18,11 @@ namespace vamiga {
string RetroShellCmd::currentGroup;

void
RetroShellCmd::add(const std::vector<string> &tokens,
RetroShellCmd::add(const std::vector<string> &rawtokens,
const string &help,
std::function<void (Arguments&, long)> func, long param)
{
auto tokens = util::split(rawtokens, ' ');
add(tokens, { }, { }, { tokens.back(), help }, func, param);
}

@@ -34,11 +35,12 @@ RetroShellCmd::add(const std::vector<string> &tokens,
}

void
RetroShellCmd::add(const std::vector<string> &tokens,
RetroShellCmd::add(const std::vector<string> &rawtokens,
const std::vector<string> &arguments,
const string &help,
std::function<void (Arguments&, long)> func, long param)
{
auto tokens = util::split(rawtokens, ' ');
add(tokens, arguments, { }, { tokens.back(), help }, func, param);
}

@@ -52,12 +54,13 @@ RetroShellCmd::add(const std::vector<string> &tokens,
}

void
RetroShellCmd::add(const std::vector<string> &tokens,
RetroShellCmd::add(const std::vector<string> &rawtokens,
const std::vector<string> &requiredArgs,
const std::vector<string> &optionalArgs,
const string &help,
std::function<void (Arguments&, long)> func, long param)
{
auto tokens = util::split(rawtokens, ' ');
add(tokens, requiredArgs, optionalArgs, { tokens.back(), help }, func, param);
}

0 comments on commit e57c9ac

Please sign in to comment.