dir/ls
This commit is contained in:
parent
cd70bc96cc
commit
722cdc98e7
1 changed files with 93 additions and 66 deletions
159
debugger.cpp
159
debugger.cpp
|
@ -78,55 +78,94 @@ std::optional<disk_backend *> select_nbd_server(console *const cnsl)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
std::optional<std::string> select_host_file(console *const c)
|
void start_disk(console *const cnsl)
|
||||||
{
|
{
|
||||||
for(;;) {
|
static bool disk_started = false;
|
||||||
#if defined(linux)
|
if (disk_started)
|
||||||
DIR *dir = opendir(".");
|
return;
|
||||||
if (!dir) {
|
|
||||||
c->put_string_lf("Cannot access directory");
|
|
||||||
return { };
|
|
||||||
}
|
|
||||||
|
|
||||||
dirent *dr = nullptr;
|
#if defined(ESP32)
|
||||||
while((dr = readdir(dir))) {
|
cnsl->put_string_lf(format("MISO: %d", int(MISO)));
|
||||||
struct stat st { };
|
cnsl->put_string_lf(format("MOSI: %d", int(MOSI)));
|
||||||
|
cnsl->put_string_lf(format("SCK : %d", int(SCK )));
|
||||||
|
cnsl->put_string_lf(format("SS : %d", int(SS )));
|
||||||
|
|
||||||
if (stat(dr->d_name, &st) == 0)
|
|
||||||
c->put_string_lf(format("%s\t\t%ld", dr->d_name, st.st_size));
|
|
||||||
}
|
|
||||||
|
|
||||||
closedir(dir);
|
|
||||||
#elif defined(BUILD_FOR_RP2040)
|
|
||||||
File root = SD.open("/");
|
|
||||||
|
|
||||||
for(;;) {
|
|
||||||
auto entry = root.openNextFile();
|
|
||||||
if (!entry)
|
|
||||||
break;
|
|
||||||
|
|
||||||
if (!entry.isDirectory()) {
|
|
||||||
c->put_string(entry.name());
|
|
||||||
c->put_string("\t\t");
|
|
||||||
c->put_string_lf(format("%ld", entry.size()));
|
|
||||||
}
|
|
||||||
|
|
||||||
entry.close();
|
|
||||||
}
|
|
||||||
#elif defined(_WIN32)
|
|
||||||
#else
|
|
||||||
SD.ls("/", LS_DATE | LS_SIZE | LS_R);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
c->flush_input();
|
#if defined(SHA2017)
|
||||||
|
if (SD.begin(21, SD_SCK_MHZ(10)))
|
||||||
|
disk_started = true;
|
||||||
|
else
|
||||||
|
SD.initErrorHalt();
|
||||||
|
#elif !defined(BUILD_FOR_RP2040)
|
||||||
|
if (SD.begin(SS, SD_SCK_MHZ(15)))
|
||||||
|
disk_started = true;
|
||||||
|
else {
|
||||||
|
auto err = SD.sdErrorCode();
|
||||||
|
if (err)
|
||||||
|
cnsl->put_string_lf(format("SDerror: 0x%x, data: 0x%x", err, SD.sdErrorData()));
|
||||||
|
else
|
||||||
|
cnsl->put_string_lf("Failed to initialize SD card");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
std::string selected_file = c->read_line("Enter filename (or empty to abort): ");
|
void ls_l(console *const cnsl)
|
||||||
|
{
|
||||||
|
start_disk(cnsl);
|
||||||
|
|
||||||
|
#if defined(linux)
|
||||||
|
DIR *dir = opendir(".");
|
||||||
|
if (!dir) {
|
||||||
|
cnsl->put_string_lf("Cannot access directory");
|
||||||
|
return { };
|
||||||
|
}
|
||||||
|
|
||||||
|
dirent *dr = nullptr;
|
||||||
|
while((dr = readdir(dir))) {
|
||||||
|
struct stat st { };
|
||||||
|
|
||||||
|
if (stat(dr->d_name, &st) == 0)
|
||||||
|
cnsl->put_string_lf(format("%s\t\t%ld", dr->d_name, st.st_size));
|
||||||
|
}
|
||||||
|
|
||||||
|
closedir(dir);
|
||||||
|
#elif defined(BUILD_FOR_RP2040)
|
||||||
|
File root = SD.open("/");
|
||||||
|
|
||||||
|
for(;;) {
|
||||||
|
auto entry = root.openNextFile();
|
||||||
|
if (!entry)
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (!entry.isDirectory()) {
|
||||||
|
cnsl->put_string(entry.name());
|
||||||
|
cnsl->put_string("\t\t");
|
||||||
|
cnsl->put_string_lf(format("%ld", entry.size()));
|
||||||
|
}
|
||||||
|
|
||||||
|
entry.close();
|
||||||
|
}
|
||||||
|
#elif defined(_WIN32)
|
||||||
|
#else
|
||||||
|
SD.ls("/", LS_DATE | LS_SIZE | LS_R);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
std::optional<std::string> select_host_file(console *const cnsl)
|
||||||
|
{
|
||||||
|
for(;;) {
|
||||||
|
ls_l(cnsl);
|
||||||
|
|
||||||
|
cnsl->flush_input();
|
||||||
|
|
||||||
|
std::string selected_file = cnsl->read_line("Enter filename (or empty to abort): ");
|
||||||
|
|
||||||
if (selected_file.empty())
|
if (selected_file.empty())
|
||||||
return { };
|
return { };
|
||||||
|
|
||||||
c->put_string("Opening file: ");
|
cnsl->put_string("Opening file: ");
|
||||||
c->put_string_lf(selected_file.c_str());
|
cnsl->put_string_lf(selected_file.c_str());
|
||||||
|
|
||||||
bool can_open_file = false;
|
bool can_open_file = false;
|
||||||
|
|
||||||
|
@ -143,41 +182,23 @@ std::optional<std::string> select_host_file(console *const c)
|
||||||
if (can_open_file)
|
if (can_open_file)
|
||||||
return selected_file;
|
return selected_file;
|
||||||
|
|
||||||
c->put_string_lf("open failed");
|
cnsl->put_string_lf("open failed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// disk image files
|
// disk image files
|
||||||
std::optional<disk_backend *> select_disk_file(console *const c)
|
std::optional<disk_backend *> select_disk_file(console *const cnsl)
|
||||||
{
|
{
|
||||||
|
start_disk(cnsl);
|
||||||
|
|
||||||
#if IS_POSIX || defined(_WIN32)
|
#if IS_POSIX || defined(_WIN32)
|
||||||
c->put_string_lf("Files in current directory: ");
|
cnsl->put_string_lf("Files in current directory: ");
|
||||||
#else
|
#else
|
||||||
c->put_string_lf(format("MISO: %d", int(MISO)));
|
cnsl->put_string_lf("Files on SD-card:");
|
||||||
c->put_string_lf(format("MOSI: %d", int(MOSI)));
|
|
||||||
c->put_string_lf(format("SCK : %d", int(SCK )));
|
|
||||||
c->put_string_lf(format("SS : %d", int(SS )));
|
|
||||||
|
|
||||||
c->put_string_lf("Files on SD-card:");
|
|
||||||
|
|
||||||
#if defined(SHA2017)
|
|
||||||
if (!SD.begin(21, SD_SCK_MHZ(10)))
|
|
||||||
SD.initErrorHalt();
|
|
||||||
#elif !defined(BUILD_FOR_RP2040)
|
|
||||||
if (!SD.begin(SS, SD_SCK_MHZ(15))) {
|
|
||||||
auto err = SD.sdErrorCode();
|
|
||||||
if (err)
|
|
||||||
c->put_string_lf(format("SDerror: 0x%x, data: 0x%x", err, SD.sdErrorData()));
|
|
||||||
else
|
|
||||||
c->put_string_lf("Failed to initialize SD card");
|
|
||||||
|
|
||||||
return { };
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
for(;;) {
|
for(;;) {
|
||||||
auto selected_file = select_host_file(c);
|
auto selected_file = select_host_file(cnsl);
|
||||||
|
|
||||||
if (selected_file.has_value() == false)
|
if (selected_file.has_value() == false)
|
||||||
break;
|
break;
|
||||||
|
@ -189,8 +210,8 @@ std::optional<disk_backend *> select_disk_file(console *const c)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!temp->begin(false)) {
|
if (!temp->begin(false)) {
|
||||||
c->put_string("Cannot use: ");
|
cnsl->put_string("Cannot use: ");
|
||||||
c->put_string_lf(selected_file.value().c_str());
|
cnsl->put_string_lf(selected_file.value().c_str());
|
||||||
|
|
||||||
delete temp;
|
delete temp;
|
||||||
|
|
||||||
|
@ -1008,6 +1029,11 @@ void debugger(console *const cnsl, bus *const b, std::atomic_uint32_t *const sto
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
else if (cmd == "dir" || cmd == "ls") {
|
||||||
|
ls_l(cnsl);
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
else if (cmd == "ult") {
|
else if (cmd == "ult") {
|
||||||
tm11_unload_tape(b);
|
tm11_unload_tape(b);
|
||||||
|
|
||||||
|
@ -1066,6 +1092,7 @@ void debugger(console *const cnsl, bus *const b, std::atomic_uint32_t *const sto
|
||||||
"setmem - set memory (a=) to value (v=), both in octal, one byte",
|
"setmem - set memory (a=) to value (v=), both in octal, one byte",
|
||||||
"toggle - set switch (s=, 0...15 (decimal)) of the front panel to state (t=, 0 or 1)",
|
"toggle - set switch (s=, 0...15 (decimal)) of the front panel to state (t=, 0 or 1)",
|
||||||
"cls - clear screen",
|
"cls - clear screen",
|
||||||
|
"dir - list files",
|
||||||
"bic - run BIC/LDA file",
|
"bic - run BIC/LDA file",
|
||||||
"lt - load tape (parameter is filename)",
|
"lt - load tape (parameter is filename)",
|
||||||
"ult - unload tape",
|
"ult - unload tape",
|
||||||
|
|
Loading…
Add table
Reference in a new issue