diff --git a/debugger.cpp b/debugger.cpp index bda975d..3b22212 100644 --- a/debugger.cpp +++ b/debugger.cpp @@ -78,55 +78,94 @@ std::optional select_nbd_server(console *const cnsl) } #endif -std::optional select_host_file(console *const c) +void start_disk(console *const cnsl) { - for(;;) { -#if defined(linux) - DIR *dir = opendir("."); - if (!dir) { - c->put_string_lf("Cannot access directory"); - return { }; - } + static bool disk_started = false; + if (disk_started) + return; - dirent *dr = nullptr; - while((dr = readdir(dir))) { - struct stat st { }; +#if defined(ESP32) + cnsl->put_string_lf(format("MISO: %d", int(MISO))); + 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 - 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 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()) return { }; - c->put_string("Opening file: "); - c->put_string_lf(selected_file.c_str()); + cnsl->put_string("Opening file: "); + cnsl->put_string_lf(selected_file.c_str()); bool can_open_file = false; @@ -143,41 +182,23 @@ std::optional select_host_file(console *const c) if (can_open_file) return selected_file; - c->put_string_lf("open failed"); + cnsl->put_string_lf("open failed"); } } // disk image files -std::optional select_disk_file(console *const c) +std::optional select_disk_file(console *const cnsl) { + start_disk(cnsl); + #if IS_POSIX || defined(_WIN32) - c->put_string_lf("Files in current directory: "); + cnsl->put_string_lf("Files in current directory: "); #else - c->put_string_lf(format("MISO: %d", int(MISO))); - 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 + cnsl->put_string_lf("Files on SD-card:"); #endif for(;;) { - auto selected_file = select_host_file(c); + auto selected_file = select_host_file(cnsl); if (selected_file.has_value() == false) break; @@ -189,8 +210,8 @@ std::optional select_disk_file(console *const c) #endif if (!temp->begin(false)) { - c->put_string("Cannot use: "); - c->put_string_lf(selected_file.value().c_str()); + cnsl->put_string("Cannot use: "); + cnsl->put_string_lf(selected_file.value().c_str()); delete temp; @@ -1008,6 +1029,11 @@ void debugger(console *const cnsl, bus *const b, std::atomic_uint32_t *const sto continue; } + else if (cmd == "dir" || cmd == "ls") { + ls_l(cnsl); + + continue; + } else if (cmd == "ult") { 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", "toggle - set switch (s=, 0...15 (decimal)) of the front panel to state (t=, 0 or 1)", "cls - clear screen", + "dir - list files", "bic - run BIC/LDA file", "lt - load tape (parameter is filename)", "ult - unload tape",