Skip to content

Commit

Permalink
Fixed BUGs in Curses of CR to LF Translation, added forced CR to LF t…
Browse files Browse the repository at this point in the history
…ranslation
  • Loading branch information
Anivice committed Feb 6, 2025
1 parent b7c72f6 commit 0c4a894
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
10 changes: 8 additions & 2 deletions src/SysdarftConsole/SysdarftMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ uint64_t boot_sysdarft(
const uint16_t port,
const std::string & log_path,
const bool headless,
const bool gui)
const bool gui,
const bool cr_to_lf)
{
std::ifstream file(bios, std::ios::in | std::ios::binary);
std::vector<uint8_t> bios_code;
Expand Down Expand Up @@ -170,6 +171,8 @@ uint64_t boot_sysdarft(
debug_server = std::make_unique<RemoteDebugServer>(ip, port, CPUInstance, log_path);
}

CPUInstance.translate_cr_to_lf = cr_to_lf;

ret = CPUInstance.Boot(headless, gui);
} catch (...) {
throw;
Expand Down Expand Up @@ -415,6 +418,8 @@ int main(int argc, char** argv)
return EXIT_SUCCESS;
}

const bool cr_to_lf = parsed_options.contains("cr-to-lf");

// boot system
return static_cast<int>(boot_sysdarft(
memory_size,
Expand All @@ -428,7 +433,8 @@ int main(int argc, char** argv)
port,
log_file,
headless,
gui));
gui,
cr_to_lf));
}

std::cout << "If you see this message, that means you have provided one or more arguments,\n"
Expand Down
5 changes: 5 additions & 0 deletions src/SysdarftCursesUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,11 @@ void SysdarftCursesUI::monitor_console_input(std::atomic < bool > & running)
default:
{
std::lock_guard lock(input_mutex);
if (translate_cr_to_lf && key == ASCII_CR) {
captured_input.emplace_back(ASCII_LF);
return;
}

captured_input.emplace_back(key);
}
}
Expand Down
13 changes: 11 additions & 2 deletions src/include/SysdarftCursesUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,25 @@ class SYSDARFT_EXPORT_SYMBOL SysdarftCursesUI : public SysdarftCPUMemoryAccess
public:
explicit SysdarftCursesUI(uint64_t memory, const std::string & font_name);
~SysdarftCursesUI() override;
void initialize();

protected:
void cleanup();
void start_again();
void initialize();
void set_cursor(int x, int y);
void set_cursor_visibility(bool visible);
void teletype(char text);
void newline();

public:
void handle_resize();
void start_again();

protected:
void ringbell();

public:
std::atomic<bool> translate_cr_to_lf = false;

protected:
// External halt is handled at upper level
std::atomic<bool> SystemHalted = false; // TODO: Shutdown should be an interruption
Expand Down
1 change: 1 addition & 0 deletions src/include/SysdarftMain.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ const option_complicated long_options[] = {
{"memory", required_argument, nullptr, 'M', "Specify memory size (in MB)\n"
"Left unset and the default size is 32MB"},
{"boot", no_argument, nullptr, 'S', "Boot the system"},
{"cr-to-lf", no_argument, nullptr, 'E', "Translate ASCII CR('\\r', carriage ret) to LF('\\n', new line)"},
{"debug", required_argument, nullptr, 'D', "Boot the system with remote debug console\n"
"The system will not be started unless the debug console is connected\n"
"Disconnecting debug console will cause system to immediately halt,\n"
Expand Down

0 comments on commit 0c4a894

Please sign in to comment.