From 0fecd6f3d1fc3ac60535ed4ede6de45d4c563524 Mon Sep 17 00:00:00 2001 From: OmniaX-Dev Date: Mon, 15 Jun 2026 05:29:03 +0200 Subject: [PATCH] Started preliminary work on new debugger --- CMakeLists.txt | 1 - extra/dss/sdk/bios_api.dss | 2 +- src/assembler/Assembler.cpp | 232 ++++---- src/assembler/Assembler.hpp | 82 +-- src/assembler/DASMApp.cpp | 8 +- src/assembler/IncludePreprocessor.cpp | 26 +- src/debugger/Debugger.cpp | 345 ++++++------ src/debugger/Debugger.hpp | 22 +- src/debugger/DebuggerNew.cpp | 768 -------------------------- src/debugger/DebuggerNew.hpp | 237 -------- src/debugger/DisassemblyLoader.cpp | 18 +- src/debugger/DisassemblyLoader.hpp | 10 +- src/hardware/CPUExtensions.cpp | 4 +- src/hardware/CPUExtensions.hpp | 4 +- src/hardware/MemoryMapper.cpp | 6 +- src/hardware/MemoryMapper.hpp | 6 +- src/hardware/VirtualCPU.cpp | 40 +- src/hardware/VirtualCPU.hpp | 2 +- src/hardware/VirtualDisplay.cpp | 18 +- src/hardware/VirtualDisplay.hpp | 6 +- src/hardware/VirtualHardDrive.cpp | 4 +- src/hardware/VirtualHardDrive.hpp | 4 +- src/hardware/VirtualIODevices.cpp | 56 +- src/hardware/VirtualIODevices.hpp | 8 +- src/runtime/ConfigLoader.cpp | 4 +- src/runtime/ConfigLoader.hpp | 8 +- src/runtime/DragonRuntime.cpp | 159 +++--- src/runtime/DragonRuntime.hpp | 30 +- src/runtime/runtime_main.cpp | 5 +- src/tools/GlobalData.cpp | 2 +- src/tools/GlobalData.hpp | 14 +- src/tools/Tools.cpp | 72 +-- src/tools/Tools.hpp | 6 +- src/tools/Utils.cpp | 4 +- src/tools/Utils.hpp | 2 +- 35 files changed, 607 insertions(+), 1608 deletions(-) delete mode 100644 src/debugger/DebuggerNew.cpp delete mode 100644 src/debugger/DebuggerNew.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 63482ef..79c6063 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,7 +50,6 @@ list(APPEND DEBUGGER_SOURCE_FILES ${CMAKE_CURRENT_LIST_DIR}/src/debugger/debugger_main.cpp ${CMAKE_CURRENT_LIST_DIR}/src/debugger/DisassemblyLoader.cpp ${CMAKE_CURRENT_LIST_DIR}/src/debugger/Debugger.cpp - ${CMAKE_CURRENT_LIST_DIR}/src/debugger/DebuggerNew.cpp ${CMAKE_CURRENT_LIST_DIR}/src/hardware/VirtualCPU.cpp ${CMAKE_CURRENT_LIST_DIR}/src/hardware/VirtualRAM.cpp diff --git a/extra/dss/sdk/bios_api.dss b/extra/dss/sdk/bios_api.dss index a780608..e2f542b 100644 --- a/extra/dss/sdk/bios_api.dss +++ b/extra/dss/sdk/bios_api.dss @@ -1,5 +1,5 @@ ## -- -## -- This file is automatically generated by the DragonAssembler (version 0.4.1649) +## -- This file is automatically generated by the DragonAssembler (version 0.4.1650) ## -- Please do not modify this file in any way. ## -- diff --git a/src/assembler/Assembler.cpp b/src/assembler/Assembler.cpp index bfa70ef..1de537c 100644 --- a/src/assembler/Assembler.cpp +++ b/src/assembler/Assembler.cpp @@ -16,7 +16,7 @@ namespace dragon { namespace code { - ostd::ByteStream Assembler::assembleFromFile(ostd::String fileName) + ostd::ByteStream Assembler::assembleFromFile(String fileName) { m_rawSource = ""; m_code.clear(); @@ -66,7 +66,7 @@ namespace dragon return m_code; } - ostd::ByteStream Assembler::assembleToFile(ostd::String sourceFileName, ostd::String binaryFileName) + ostd::ByteStream Assembler::assembleToFile(String sourceFileName, String binaryFileName) { assembleFromFile(sourceFileName); if (m_code.size() == 0) return { }; @@ -74,7 +74,7 @@ namespace dragon return m_code; } - ostd::ByteStream Assembler::assembleToVirtualDisk(ostd::String fileName, hw::VirtualHardDrive& vhdd, uint32_t address) + ostd::ByteStream Assembler::assembleToVirtualDisk(String fileName, hw::VirtualHardDrive& vhdd, uint32_t address) { assembleFromFile(fileName); if (m_code.size() == 0) return { }; @@ -83,10 +83,10 @@ namespace dragon return m_code; } - bool Assembler::saveDisassemblyToFile(ostd::String fileName) + bool Assembler::saveDisassemblyToFile(String fileName) { if (m_code.size() == 0 || m_disassembly.size() == 0) return false; - ostd::String header_string = "{ DRAGON_DEBUG_DISASSEMBLY }"; + String header_string = "{ DRAGON_DEBUG_DISASSEMBLY }"; uint64_t da_size = 0; da_size += (header_string.len() + 1) * ostd::tTypeSize::BYTE; da_size += m_disassembly.size() * ostd::tTypeSize::DWORD; //Addresses @@ -122,11 +122,11 @@ namespace dragon out.fg(ostd::ConsoleColors::Yellow).p("Symbols:").nl(); for (auto& symbol : m_symbolTable) { - out.fg(ostd::ConsoleColors::Red).p(ostd::String::getHexStr(symbol.second.address, true, 2)); + out.fg(ostd::ConsoleColors::Red).p(String::getHexStr(symbol.second.address, true, 2)); out.fg(ostd::ConsoleColors::Magenta).p(" ").p(symbol.first); out.fg(ostd::ConsoleColors::Blue).nl().p(" "); for (auto& b : symbol.second.bytes) - out.p(ostd::String::getHexStr(b, false, 1)).p("."); + out.p(String::getHexStr(b, false, 1)).p("."); out.nl(); } if (m_symbolTable.size() > 0) @@ -137,7 +137,7 @@ namespace dragon for (auto& label : m_labelTable) { out.fg(ostd::ConsoleColors::Magenta).p(label.first.new_fixedLength(symbol_len)); - out.fg(ostd::ConsoleColors::Red).p(ostd::String::getHexStr(label.second.address, true, 2)).nl(); + out.fg(ostd::ConsoleColors::Red).p(String::getHexStr(label.second.address, true, 2)).nl(); } if (m_labelTable.size() > 0) out.nl(); @@ -156,12 +156,12 @@ namespace dragon if (verbose_level == 0 || verbose_level == 1) { out.fg(ostd::ConsoleColors::Yellow).p("Program data:").nl(); - out.fg(ostd::ConsoleColors::Cyan).p(ostd::String("Fixed Size: ").new_fixedLength(symbol_len)).fg(ostd::ConsoleColors::BrightRed).p((int)m_fixedSize).p(" bytes").nl(); - out.fg(ostd::ConsoleColors::Cyan).p(ostd::String("Program Size:").new_fixedLength(symbol_len)).fg(ostd::ConsoleColors::BrightRed).p((int)m_programSize).p(" bytes").nl(); - out.fg(ostd::ConsoleColors::Cyan).p(ostd::String("Data Size: ").new_fixedLength(symbol_len)).fg(ostd::ConsoleColors::BrightRed).p((int)m_dataSize).p(" bytes").nl(); - out.fg(ostd::ConsoleColors::Cyan).p(ostd::String("Fixed Fill: ").new_fixedLength(symbol_len)).fg(ostd::ConsoleColors::BrightRed).p(ostd::String::getHexStr(m_fixedFillValue, true, 1)).nl(); - out.fg(ostd::ConsoleColors::Cyan).p(ostd::String("Load Address:").new_fixedLength(symbol_len)).fg(ostd::ConsoleColors::BrightRed).p(ostd::String::getHexStr(m_loadAddress, true, 2)).nl(); - out.fg(ostd::ConsoleColors::Cyan).p(ostd::String("Entry Point: ").new_fixedLength(symbol_len)).fg(ostd::ConsoleColors::BrightRed).p(ostd::String::getHexStr(m_dataSize + m_loadAddress + 3, true, 2)).nl(); + out.fg(ostd::ConsoleColors::Cyan).p(String("Fixed Size: ").new_fixedLength(symbol_len)).fg(ostd::ConsoleColors::BrightRed).p((int)m_fixedSize).p(" bytes").nl(); + out.fg(ostd::ConsoleColors::Cyan).p(String("Program Size:").new_fixedLength(symbol_len)).fg(ostd::ConsoleColors::BrightRed).p((int)m_programSize).p(" bytes").nl(); + out.fg(ostd::ConsoleColors::Cyan).p(String("Data Size: ").new_fixedLength(symbol_len)).fg(ostd::ConsoleColors::BrightRed).p((int)m_dataSize).p(" bytes").nl(); + out.fg(ostd::ConsoleColors::Cyan).p(String("Fixed Fill: ").new_fixedLength(symbol_len)).fg(ostd::ConsoleColors::BrightRed).p(String::getHexStr(m_fixedFillValue, true, 1)).nl(); + out.fg(ostd::ConsoleColors::Cyan).p(String("Load Address:").new_fixedLength(symbol_len)).fg(ostd::ConsoleColors::BrightRed).p(String::getHexStr(m_loadAddress, true, 2)).nl(); + out.fg(ostd::ConsoleColors::Cyan).p(String("Entry Point: ").new_fixedLength(symbol_len)).fg(ostd::ConsoleColors::BrightRed).p(String::getHexStr(m_dataSize + m_loadAddress + 3, true, 2)).nl(); } out.nl(); @@ -197,8 +197,8 @@ namespace dragon void Assembler::removeComments(void) { - std::vector newLines; - ostd::String lineEdit; + std::vector newLines; + String lineEdit; for (auto& line : m_lines) { lineEdit = line; @@ -214,7 +214,7 @@ namespace dragon void Assembler::replaceDefines(void) { - auto listContainsDefine = [](const std::vector& list, const ostd::String& name) -> bool { + auto listContainsDefine = [](const std::vector& list, const String& name) -> bool { for (auto& def : list) { if (def.name == name) @@ -222,19 +222,19 @@ namespace dragon } return false; }; - // auto exportExists = [](const std::unordered_map& exports, const ostd::String& name) -> bool { + // auto exportExists = [](const std::unordered_map& exports, const String& name) -> bool { // return exports.count(name) > 0; // }; std::vector defines; - std::vector newLines; - ostd::String lineEdit; - ostd::String tmpLineEdit; + std::vector newLines; + String lineEdit; + String tmpLineEdit; for (auto& line : m_lines) { lineEdit = line; lineEdit.trim(); tmpLineEdit = lineEdit; - // ostd::String export_name = ""; + // String export_name = ""; // if (tmpLineEdit.toLower().startsWith("@export_comment ")) // { // lineEdit.substr(16).trim(); @@ -277,8 +277,8 @@ namespace dragon std::cout << "Invalid @define directive: " << line << "\n"; return; } - ostd::String define_name = lineEdit.new_substr(0, lineEdit.indexOf(" ")).trim(); - ostd::String define_value = lineEdit.new_substr(lineEdit.indexOf(" ") + 1).trim(); + String define_name = lineEdit.new_substr(0, lineEdit.indexOf(" ")).trim(); + String define_value = lineEdit.new_substr(lineEdit.indexOf(" ") + 1).trim(); if (listContainsDefine(defines, define_name)) { std::cout << "Redefinition of @define value: " << line << "\n"; @@ -300,7 +300,7 @@ namespace dragon } for (auto& line : newLines) { - ostd::String lineEdit(line); + String lineEdit(line); for (int32_t i = defines.size() - 1; i >= 0; i--) lineEdit.replaceAll(defines[i].name, defines[i].value.new_trim()); line = lineEdit; @@ -319,11 +319,11 @@ namespace dragon void Assembler::replaceGroupDefines(void) { - std::vector newLines; - ostd::String lineEdit; + std::vector newLines; + String lineEdit; bool in_group = false; - ostd::String group_name = ""; - ostd::String export_name = ""; + String group_name = ""; + String export_name = ""; for (auto& line : m_lines) { lineEdit = line; @@ -376,7 +376,7 @@ namespace dragon std::cout << "Invalid definition inside group: " << line << "\n"; return; } - ostd::String newLine = "@define " + export_name + " "; + String newLine = "@define " + export_name + " "; newLine.add(group_name).add(".").add(lineEdit); newLines.push_back(newLine); } @@ -386,10 +386,10 @@ namespace dragon void Assembler::parseStructures(void) { - std::vector newLines; - ostd::String lineEdit; + std::vector newLines; + String lineEdit; bool in_struct = false; - ostd::String struct_name = ""; + String struct_name = ""; tStructDefinition struct_def; int32_t member_index = 0; for (auto& line : m_lines) @@ -428,9 +428,9 @@ namespace dragon struct_def.size += data.data.size(); std::sort(struct_def.members.begin(), struct_def.members.end()); m_structDefs.push_back(struct_def); - ostd::String size_def = "@define "; + String size_def = "@define "; size_def.add(struct_def.name).add(".").add("SIZE").add(" "); - size_def.add(ostd::String::getHexStr(struct_def.size, true, 2)); + size_def.add(String::getHexStr(struct_def.size, true, 2)); newLines.push_back(size_def); in_struct = false; continue; @@ -445,8 +445,8 @@ namespace dragon std::cout << "Invalid definition inside struct. Size specification missing: " << line << "\n"; return; } - ostd::String member_name = lineEdit.new_substr(0, lineEdit.indexOf(":")).trim(); - ostd::String member_data = ""; + String member_name = lineEdit.new_substr(0, lineEdit.indexOf(":")).trim(); + String member_data = ""; lineEdit.substr(lineEdit.indexOf(":") + 1).trim(); if (member_name.contains(" ")) { @@ -482,7 +482,7 @@ namespace dragon auto tokens = member_data.tokenize(","); if (tokens.count() == 1) { - ostd::String tok = tokens.next(); + String tok = tokens.next(); if (tok.isNumeric()) { uint8_t data = (uint8_t)tok.toInt(); @@ -504,7 +504,7 @@ namespace dragon } while (tokens.hasNext()) { - ostd::String tok = tokens.next(); + String tok = tokens.next(); if (tok.isNumeric()) { uint8_t data = (uint8_t)tok.toInt(); @@ -530,7 +530,7 @@ namespace dragon // { // std::cout << " " << d.first << " "; // for (auto& b : d.second) - // std::cout << ostd::String::getHexStr(b) << " "; + // std::cout << String::getHexStr(b) << " "; // } // std::cout << "\n"; // } @@ -539,8 +539,8 @@ namespace dragon void Assembler::parseStructInstances(void) { - std::vector newLines; - ostd::String lineEdit; + std::vector newLines; + String lineEdit; for (auto& line : m_rawDataSection) { lineEdit = line; @@ -549,11 +549,11 @@ namespace dragon { continue; } - ostd::String symbolName = lineEdit.new_substr(0, lineEdit.indexOf(" ")); + String symbolName = lineEdit.new_substr(0, lineEdit.indexOf(" ")); symbolName.trim(); lineEdit.substr(lineEdit.indexOf(" ") + 1); lineEdit.trim(); - ostd::String initialization_data = ""; + String initialization_data = ""; bool has_init_data = false; if (lineEdit.startsWith("<") && lineEdit.contains("=")) { @@ -579,7 +579,7 @@ namespace dragon auto tokens = initialization_data.tokenize(","); while (tokens.hasNext()) { - ostd::String tok = tokens.next(); + String tok = tokens.next(); if (!tok.isNumeric()) { std::cout << "Invalid initialization data: " << lineEdit << "\n"; @@ -613,14 +613,14 @@ namespace dragon newLines.push_back("!" + symbolName); for (auto& member : struct_def.members) { - ostd::String newLine = symbolName; + String newLine = symbolName; newLine.add(".").add(member.name).add(" "); for (int32_t i = 0; i < member.data.size(); i++, data_index++) { if (has_init_data) - newLine.add(ostd::String::getHexStr(init_data[data_index], true, 2)); + newLine.add(String::getHexStr(init_data[data_index], true, 2)); else - newLine.add(ostd::String::getHexStr(member.data[i], true, 2)); + newLine.add(String::getHexStr(member.data[i], true, 2)); newLine.add(","); } newLine.substr(0, newLine.len() - 1); @@ -638,8 +638,8 @@ namespace dragon void Assembler::parseExportSpecifications(void) { - std::vector newLines; - ostd::String lineEdit; + std::vector newLines; + String lineEdit; for (auto& line : m_lines) { lineEdit = line; @@ -654,8 +654,8 @@ namespace dragon std::cout << "Invalid @export directive: " << line << "\n"; return; } - ostd::String exportName = lineEdit.new_substr(0, lineEdit.indexOf(" ")).trim(); - ostd::String exportPath = lineEdit.new_substr(lineEdit.indexOf(" ") + 1).trim(); + String exportName = lineEdit.new_substr(0, lineEdit.indexOf(" ")).trim(); + String exportPath = lineEdit.new_substr(lineEdit.indexOf(" ") + 1).trim(); m_exports[exportName] = { exportPath, { } }; } m_lines.clear(); @@ -664,13 +664,13 @@ namespace dragon void Assembler::createExports(void) { - std::vector newLines; - ostd::String lineEdit; - auto exportExists = [](const std::unordered_map& exportList, const ostd::String& exportName) -> bool { + std::vector newLines; + String lineEdit; + auto exportExists = [](const std::unordered_map& exportList, const String& exportName) -> bool { return exportList.count(exportName) > 0; }; bool export_start = false; - ostd::String open_export = ""; + String open_export = ""; for (auto& line : m_lines) { lineEdit = line; @@ -688,8 +688,8 @@ namespace dragon std::cout << "Invalid @export_comment directive: " << line << "\n"; return; } - ostd::String exportName = lineEdit.new_substr(0, lineEdit.indexOf(" ")).trim(); - ostd::String exportComment = lineEdit.new_substr(lineEdit.indexOf(" ") + 1).trim(); + String exportName = lineEdit.new_substr(0, lineEdit.indexOf(" ")).trim(); + String exportComment = lineEdit.new_substr(lineEdit.indexOf(" ") + 1).trim(); if (!exportExists(m_exports, exportName)) { std::cout << "Invalid export name in @export_comment directive: " << line << "\n"; @@ -701,7 +701,7 @@ namespace dragon return; } exportComment.substr(1, exportComment.len() - 1).replaceAll("\\n", "\n"); - m_exports[exportName].lines.push_back(ostd::String("##").add(exportComment)); + m_exports[exportName].lines.push_back(String("##").add(exportComment)); } else if (lineEdit.startsWith("@raw_export_start ")) { @@ -748,8 +748,8 @@ namespace dragon void Assembler::replaceExportBuiltinVars(void) { if (!saveExports) return; - auto getVersionStr = []() -> ostd::String { - return ostd::String("").add(MAJ_V).add(".").add(MIN_V).add(".").add(BUILD_NR); + auto getVersionStr = []() -> String { + return String("").add(MAJ_V).add(".").add(MIN_V).add(".").add(BUILD_NR); }; for (auto&[name, exportSpec] : m_exports) { @@ -790,7 +790,7 @@ namespace dragon for (auto& line : m_lines) { - ostd::String lineEdit(line); + String lineEdit(line); lineEdit.trim(); if (lineEdit.startsWith(".data")) currentSection = DATA_SECTION; @@ -812,7 +812,7 @@ namespace dragon std::cout << "Invalid .fixed value: " << lineEdit << "\n"; return; } - ostd::String fixedSizeEdit = lineEdit.new_substr(0, lineEdit.indexOf(",")); + String fixedSizeEdit = lineEdit.new_substr(0, lineEdit.indexOf(",")); fixedSizeEdit.trim(); lineEdit = lineEdit.substr(lineEdit.indexOf(",") + 1); lineEdit.trim(); @@ -904,9 +904,9 @@ namespace dragon // std::cout << line << "\n"; for (auto& line : m_rawDataSection) { - ostd::String lineEdit(line); + String lineEdit(line); tSymbol symbol; - ostd::String symbolName = ""; + String symbolName = ""; bool array = false; if (lineEdit.startsWith("!")) { @@ -1036,7 +1036,7 @@ namespace dragon { for (auto& line : m_rawCodeSection) { - ostd::String lineEdit(line); + String lineEdit(line); uint32_t commaCount = lineEdit.count(","); uint32_t spaceCount = lineEdit.count(" "); if (lineEdit.endsWith(":") && commaCount == 0 && spaceCount == 0) //Labels @@ -1051,7 +1051,7 @@ namespace dragon tDisassemblyLine _disassembly_line; for (auto& line : m_rawCodeSection) { - ostd::String lineEdit(line); + String lineEdit(line); uint32_t commaCount = lineEdit.count(","); uint32_t spaceCount = lineEdit.count(" "); if (lineEdit.endsWith(":") && commaCount == 0 && spaceCount == 0) //Labels @@ -1086,7 +1086,7 @@ namespace dragon else if (commaCount == 0 && spaceCount <= 0) //0 Operands { _disassembly_line.addr = m_dataSize + m_loadAddress + m_code.size() + 3; - ostd::String _tmp_edit(lineEdit); + String _tmp_edit(lineEdit); if (_tmp_edit.toLower().trim().startsWith("debug_")) parseDebugOperands(lineEdit); else @@ -1099,7 +1099,7 @@ namespace dragon { _disassembly_line.addr = m_dataSize + m_loadAddress + m_code.size() + 3; lineEdit = replaceSymbols(lineEdit); - ostd::String _tmp_edit(lineEdit); + String _tmp_edit(lineEdit); if (_tmp_edit.toLower().trim().startsWith("debug_")) parseDebugOperands(lineEdit); else @@ -1112,7 +1112,7 @@ namespace dragon { _disassembly_line.addr = m_dataSize + m_loadAddress + m_code.size() + 3; lineEdit = replaceSymbols(lineEdit); - ostd::String _tmp_edit(lineEdit); + String _tmp_edit(lineEdit); if (_tmp_edit.toLower().trim().startsWith("debug_")) parseDebugOperands(lineEdit); else @@ -1125,7 +1125,7 @@ namespace dragon { _disassembly_line.addr = m_dataSize + m_loadAddress + m_code.size() + 3; lineEdit = replaceSymbols(lineEdit); - ostd::String _tmp_edit(lineEdit); + String _tmp_edit(lineEdit); if (_tmp_edit.toLower().trim().startsWith("debug_")) parseDebugOperands(lineEdit); else @@ -1144,31 +1144,31 @@ namespace dragon - void Assembler::parseDebugOperands(ostd::String line) + void Assembler::parseDebugOperands(String line) { if (!debugMode) return; - if (ostd::String(line).toLower().startsWith("debug_break")) + if (String(line).toLower().startsWith("debug_break")) { m_code.push_back(data::OpCodes::DEBUG_Break); return; } - else if (ostd::String(line).toLower().startsWith("debug_ram_dump")) + else if (String(line).toLower().startsWith("debug_ram_dump")) { m_code.push_back(data::OpCodes::DEBUG_DumpRAM); return; } - else if (ostd::String(line).toLower().startsWith("debug_profile_stop")) + else if (String(line).toLower().startsWith("debug_profile_stop")) { m_code.push_back(data::OpCodes::DEBUG_StopProfile); return; } - else if (ostd::String(line).toLower().startsWith("debug_profile_start")) + else if (String(line).toLower().startsWith("debug_profile_start")) { - ostd::String lineEdit(line); - ostd::String instEdit(lineEdit.new_substr(0, lineEdit.indexOf(" "))); + String lineEdit(line); + String instEdit(lineEdit.new_substr(0, lineEdit.indexOf(" "))); instEdit.trim().toLower(); - ostd::String opEdit(lineEdit.new_substr(lineEdit.indexOf(" ") + 1)); + String opEdit(lineEdit.new_substr(lineEdit.indexOf(" ") + 1)); opEdit.trim(); int16_t word1 = 0x0000; int16_t word2 = 0x0000; @@ -1200,36 +1200,36 @@ namespace dragon } } - void Assembler::parse0Operand(ostd::String line) + void Assembler::parse0Operand(String line) { - if (ostd::String(line).toLower().startsWith("nop")) + if (String(line).toLower().startsWith("nop")) { m_code.push_back(data::OpCodes::NoOp); return; } - else if (ostd::String(line).toLower().startsWith("ret")) + else if (String(line).toLower().startsWith("ret")) { m_code.push_back(data::OpCodes::Ret); return; } - else if (ostd::String(line).toLower().startsWith("rti")) + else if (String(line).toLower().startsWith("rti")) { m_code.push_back(data::OpCodes::RetInt); return; } - else if (ostd::String(line).toLower().startsWith("hlt")) + else if (String(line).toLower().startsWith("hlt")) { m_code.push_back(data::OpCodes::Halt); return; } } - void Assembler::parse1Operand(ostd::String line) + void Assembler::parse1Operand(String line) { - ostd::String lineEdit(line); - ostd::String instEdit(lineEdit.new_substr(0, lineEdit.indexOf(" "))); + String lineEdit(line); + String instEdit(lineEdit.new_substr(0, lineEdit.indexOf(" "))); instEdit.trim().toLower(); - ostd::String opEdit(lineEdit.new_substr(lineEdit.indexOf(" ") + 1)); + String opEdit(lineEdit.new_substr(lineEdit.indexOf(" ") + 1)); opEdit.trim(); int16_t word = 0x0000; if (STDVEC_CONTAINS(cpuExtensions, "extalu")) @@ -1302,7 +1302,7 @@ namespace dragon if (opType == eOperandType::Immediate || opType == eOperandType::Label) { // if (opType == eOperandType::Label) - // std::cout << ostd::String::getHexStr(word, true, 2) << "\n"; + // std::cout << String::getHexStr(word, true, 2) << "\n"; m_code[m_code.size() - 1] = data::OpCodes::PushImm; // m_code.push_back(data::OpCodes::PushImm); m_code.push_back((uint8_t)((word & 0xFF00) >> 8)); @@ -1468,12 +1468,12 @@ namespace dragon } } - void Assembler::parse2Operand(ostd::String line) + void Assembler::parse2Operand(String line) { - ostd::String lineEdit(line); - ostd::String instEdit(lineEdit.new_substr(0, lineEdit.indexOf(" "))); + String lineEdit(line); + String instEdit(lineEdit.new_substr(0, lineEdit.indexOf(" "))); instEdit.trim().toLower(); - ostd::String opEdit(lineEdit.new_substr(lineEdit.indexOf(" ") + 1)); + String opEdit(lineEdit.new_substr(lineEdit.indexOf(" ") + 1)); opEdit.trim(); int16_t word = 0x0000; auto st = opEdit.tokenize(","); @@ -1859,12 +1859,12 @@ namespace dragon } } - void Assembler::parse3Operand(ostd::String line) + void Assembler::parse3Operand(String line) { - ostd::String lineEdit(line); - ostd::String instEdit(lineEdit.new_substr(0, lineEdit.indexOf(" "))); + String lineEdit(line); + String instEdit(lineEdit.new_substr(0, lineEdit.indexOf(" "))); instEdit.trim().toLower(); - ostd::String opEdit(lineEdit.new_substr(lineEdit.indexOf(" ") + 1)); + String opEdit(lineEdit.new_substr(lineEdit.indexOf(" ") + 1)); opEdit.trim(); if (STDVEC_CONTAINS(cpuExtensions, "extmov")) { @@ -1889,7 +1889,7 @@ namespace dragon m_code.push_back((uint8_t)word1); code_offset++; eOperandType opType2 = parseOperand(st.next(), word2); - ostd::String op3 = st.next(); + String op3 = st.next(); bool word_offset = false; if (op3.startsWith("word")) { @@ -1973,7 +1973,7 @@ namespace dragon m_code.push_back((uint8_t)(word1 & 0x00FF)); code_offset += 2; eOperandType opType2 = parseOperand(st.next(), word2); - ostd::String op3 = st.next(); + String op3 = st.next(); bool word_offset = false; if (op3.startsWith("word")) { @@ -2046,7 +2046,7 @@ namespace dragon m_code.push_back((uint8_t)word1); code_offset++; eOperandType opType2 = parseOperand(st.next(), word2); - ostd::String op3 = st.next(); + String op3 = st.next(); bool word_offset = false; if (op3.startsWith("word")) { @@ -2129,7 +2129,7 @@ namespace dragon m_code.push_back((uint8_t)(word1 & 0x00FF)); code_offset += 2; eOperandType opType2 = parseOperand(st.next(), word2); - ostd::String op3 = st.next(); + String op3 = st.next(); bool word_offset = false; if (op3.startsWith("word")) { @@ -2201,7 +2201,7 @@ namespace dragon m_code.push_back((uint8_t)word1); code_offset++; eOperandType opType2 = parseOperand(st.next(), word2); - ostd::String op3 = st.next(); + String op3 = st.next(); bool word_offset = false; if (op3.startsWith("word")) { @@ -2283,7 +2283,7 @@ namespace dragon m_code.push_back((uint8_t)word1); code_offset++; eOperandType opType2 = parseOperand(st.next(), word2); - ostd::String op3 = st.next(); + String op3 = st.next(); bool word_offset = false; if (op3.startsWith("word")) { @@ -2354,7 +2354,7 @@ namespace dragon m_code.push_back((uint8_t)word1); code_offset++; eOperandType opType2 = parseOperand(st.next(), word2); - ostd::String op3 = st.next(); + String op3 = st.next(); bool word_offset = false; if (op3.startsWith("word")) { @@ -2436,7 +2436,7 @@ namespace dragon m_code.push_back((uint8_t)word1); code_offset++; eOperandType opType2 = parseOperand(st.next(), word2); - ostd::String op3 = st.next(); + String op3 = st.next(); bool word_offset = false; if (op3.startsWith("word")) { @@ -2522,7 +2522,7 @@ namespace dragon newCode.push_back((uint8_t)(entryAddr & 0x00FF)); if (m_dataSize > 0) m_disassembly.insert(m_disassembly.begin(), { (uint16_t)(m_loadAddress + 3), "[----------DATA_SECTION----------]" }); - m_disassembly.insert(m_disassembly.begin(), { m_loadAddress, ostd::String("jmp ").add(ostd::String::getHexStr(entryAddr, true, 2)) }); + m_disassembly.insert(m_disassembly.begin(), { m_loadAddress, String("jmp ").add(String::getHexStr(entryAddr, true, 2)) }); for (auto& d : m_symbolTable) { symbols.push_back(d.second); @@ -2552,17 +2552,17 @@ namespace dragon - ostd::String Assembler::replaceSymbols(ostd::String line) + String Assembler::replaceSymbols(String line) { - ostd::String lineEdit(line); + String lineEdit(line); for (auto& symbol : m_symbolTable) { - ostd::String regex = "\\" + symbol.first.new_regexReplace("\\.", "\\.") + "(?!\\.)(?!\\w)"; + String regex = "\\" + symbol.first.new_regexReplace("\\.", "\\.") + "(?!\\.)(?!\\w)"; // std::cout << "SYMBOL: " << symbol.first << "\n"; // std::cout << "LINE: " << lineEdit << "\n"; // std::cout << "REGEX: " << regex << "\n"; - lineEdit.regexReplace(regex, ostd::String::getHexStr(symbol.second.address, true, 2), false); + lineEdit.regexReplace(regex, String::getHexStr(symbol.second.address, true, 2), false); // std::cout << "NEW_LINE: " << lineEdit << "\n\n"; } return lineEdit; @@ -2580,9 +2580,9 @@ namespace dragon } } - Assembler::eOperandType Assembler::parseOperand(ostd::String op, int16_t& outOp) + Assembler::eOperandType Assembler::parseOperand(String op, int16_t& outOp) { - ostd::String opEdit(op); + String opEdit(op); bool derefReg = false; if (opEdit.startsWith("*")) { @@ -2640,8 +2640,8 @@ namespace dragon m_labelTable[opEdit].references.push_back(m_code.size()); outOp = (int16_t)labelAddr; // std::cout << "LABEL: " << opEdit << "\n"; - // std::cout << " : " << ostd::String::getHexStr(labelAddr, true, 2) << "\n"; - // std::cout << " : " << ostd::String::getHexStr(outOp, true, 2) << "\n"; + // std::cout << " : " << String::getHexStr(labelAddr, true, 2) << "\n"; + // std::cout << " : " << String::getHexStr(outOp, true, 2) << "\n"; return eOperandType::Label; } if (opEdit.startsWith("{") && opEdit.endsWith("}")) @@ -2673,9 +2673,9 @@ namespace dragon return eOperandType::Error; } - uint8_t Assembler::parseRegister(ostd::String op) + uint8_t Assembler::parseRegister(String op) { - ostd::String opEdit(op); + String opEdit(op); opEdit.trim().toLower(); if (opEdit == "r1") return data::Registers::R1; if (opEdit == "r2") return data::Registers::R2; diff --git a/src/assembler/Assembler.hpp b/src/assembler/Assembler.hpp index 75d4b31..d81a50c 100644 --- a/src/assembler/Assembler.hpp +++ b/src/assembler/Assembler.hpp @@ -15,30 +15,30 @@ namespace dragon class IncludePreprocessor { public: - static std::vector loadEntryFile(const ostd::String& filePath); + static std::vector loadEntryFile(const String& filePath); private: - static bool __can_file_be_included(std::vector& lines); + static bool __can_file_be_included(std::vector& lines); static bool __include_loop(void); - static std::vector __load_file(const ostd::String& filePath); + static std::vector __load_file(const String& filePath); private: - inline static std::vector m_lines; - inline static std::vector m_guards; - inline static ostd::String m_directory { "" }; + inline static std::vector m_lines; + inline static std::vector m_guards; + inline static String m_directory { "" }; }; class Assembler { public: struct tDefine { - ostd::String name; - ostd::String value; + String name; + String value; }; public: struct tDisassemblyLine { uint32_t addr = 0; - ostd::String code = ""; + String code = ""; uint16_t size = 1; inline bool operator<(const tDisassemblyLine& second) const { return addr < second.addr; } inline bool operator>(const tDisassemblyLine& second) const { return addr > second.addr; } @@ -55,7 +55,7 @@ namespace dragon }; public: struct tStructMember { - ostd::String name; + String name; std::vector data; int32_t position; inline bool operator<(const tStructMember& second) const { return position < second.position; } @@ -63,14 +63,14 @@ namespace dragon }; public: struct tStructDefinition { - ostd::String name; + String name; std::vector members; int32_t size; }; public: struct tExportSpec { - ostd::String fileName { "" }; - std::vector lines; + String fileName { "" }; + std::vector lines; }; public: enum class eOperandType { @@ -88,16 +88,16 @@ namespace dragon public: struct tCommandLineArgs { inline tCommandLineArgs(void) { } - ostd::String source_file_path { "" }; - ostd::String dest_file_path { "" }; + String source_file_path { "" }; + String dest_file_path { "" }; bool save_disassembly { false }; int32_t verbose_level { 0xFF }; bool debug_mode { false }; bool save_exports { true }; - ostd::String disassembly_file_path { "" }; - ostd::String final_stage_path { "" }; - std::vector cpu_extensions; - std::vector include_directories; + String disassembly_file_path { "" }; + String final_stage_path { "" }; + std::vector cpu_extensions; + std::vector include_directories; }; public: @@ -114,10 +114,10 @@ namespace dragon }; public: - static ostd::ByteStream assembleFromFile(ostd::String fileName); - static ostd::ByteStream assembleToFile(ostd::String sourceFileName, ostd::String binaryFileName); - static ostd::ByteStream assembleToVirtualDisk(ostd::String fileName, hw::VirtualHardDrive& vhdd, uint32_t address); - static bool saveDisassemblyToFile(ostd::String fileName); + static ostd::ByteStream assembleFromFile(String fileName); + static ostd::ByteStream assembleToFile(String sourceFileName, String binaryFileName); + static ostd::ByteStream assembleToVirtualDisk(String fileName, hw::VirtualHardDrive& vhdd, uint32_t address); + static bool saveDisassemblyToFile(String fileName); static void printProgramInfo(int32_t verbose_level = 1); private: @@ -139,28 +139,28 @@ namespace dragon static void parseDataSection(void); static void parseCodeSection(void); - static void parseDebugOperands(ostd::String line); - static void parse0Operand(ostd::String line); - static void parse1Operand(ostd::String line); - static void parse2Operand(ostd::String line); - static void parse3Operand(ostd::String line); + static void parseDebugOperands(String line); + static void parse0Operand(String line); + static void parse1Operand(String line); + static void parse2Operand(String line); + static void parse3Operand(String line); static void combineDataAndCode(void); - static ostd::String replaceSymbols(ostd::String line); + static String replaceSymbols(String line); static void replaceLabelRefs(void); - static eOperandType parseOperand(ostd::String op, int16_t& outOp); - static uint8_t parseRegister(ostd::String op); + static eOperandType parseOperand(String op, int16_t& outOp); + static uint8_t parseRegister(String op); private: - inline static ostd::String m_rawSource { "" }; + inline static String m_rawSource { "" }; inline static ostd::ByteStream m_code; - inline static std::vector m_lines; - inline static std::vector m_rawDataSection; - inline static std::vector m_rawCodeSection; + inline static std::vector m_lines; + inline static std::vector m_rawDataSection; + inline static std::vector m_rawCodeSection; - inline static std::unordered_map m_symbolTable; - inline static std::unordered_map m_labelTable; + inline static std::unordered_map m_symbolTable; + inline static std::unordered_map m_labelTable; inline static uint16_t m_fixedSize { 0 }; inline static uint8_t m_fixedFillValue { 0x00 }; @@ -168,20 +168,20 @@ namespace dragon inline static uint16_t m_currentDataAddr { 0x0000 }; inline static uint16_t m_dataSize { 0x0000 }; inline static uint16_t m_programSize { 0x0000 }; - inline static ostd::String m_entry_lbl { "" }; - inline static ostd::String m_headerStr { "" }; + inline static String m_entry_lbl { "" }; + inline static String m_headerStr { "" }; inline static std::vector m_structDefs; inline static std::vector m_disassembly; - inline static std::unordered_map m_exports; + inline static std::unordered_map m_exports; inline static ostd::ConsoleOutputHandler out; public: inline static bool saveExports { false }; inline static bool debugMode { false }; - inline static std::vector cpuExtensions; + inline static std::vector cpuExtensions; }; } } diff --git a/src/assembler/DASMApp.cpp b/src/assembler/DASMApp.cpp index 8eada0e..a0e1f00 100644 --- a/src/assembler/DASMApp.cpp +++ b/src/assembler/DASMApp.cpp @@ -29,7 +29,7 @@ namespace dragon args.verbose_level = -1; for (int32_t i = 2; i < argc; i++) { - ostd::String edit(argv[i]); + String edit(argv[i]); if (edit == "-o") { if (i == argc - 1) @@ -42,7 +42,7 @@ namespace dragon if (i == argc - 1) return RETURN_VAL_MISSING_PARAM; i++; - ostd::String _include = argv[i]; + String _include = argv[i]; _include.trim(); if (!_include.endsWith("/")) _include.add("/"); @@ -63,7 +63,7 @@ namespace dragon if (i == argc - 1) return RETURN_VAL_MISSING_PARAM; i++; - ostd::String final_path = argv[i]; + String final_path = argv[i]; if (!ostd::FileSystem::ensureFile(final_path)) return RETURN_VAL_INVALID_PARAM; args.final_stage_path = final_path; @@ -109,7 +109,7 @@ namespace dragon int32_t commandLength = 46; out.nl().fg(ostd::ConsoleColors::Yellow).p("List of available parameters:").reset().nl(); - ostd::String tmpCommand = "--save-disassembly "; + String tmpCommand = "--save-disassembly "; tmpCommand.addRightPadding(commandLength); out.fg(ostd::ConsoleColors::Blue).p(tmpCommand).fg(ostd::ConsoleColors::Green).p("Saves debug information in the destination directory. (Enabled by default in debug mode.)").reset().nl(); tmpCommand = "--save-final-stage "; diff --git a/src/assembler/IncludePreprocessor.cpp b/src/assembler/IncludePreprocessor.cpp index 7e833ba..1dbef0e 100644 --- a/src/assembler/IncludePreprocessor.cpp +++ b/src/assembler/IncludePreprocessor.cpp @@ -7,7 +7,7 @@ namespace dragon { namespace code { - std::vector IncludePreprocessor::loadEntryFile(const ostd::String& filePath) + std::vector IncludePreprocessor::loadEntryFile(const String& filePath) { m_guards.clear(); m_lines.clear(); @@ -20,10 +20,10 @@ namespace dragon if (!__can_file_be_included(m_lines)) return { }; //TODO: Error if (!__include_loop()) return { }; //TODO: Error - std::vector newLines; + std::vector newLines; for (auto& line : m_lines) { - ostd::String lineEdit = line.new_trim(); + String lineEdit = line.new_trim(); if (lineEdit != "") newLines.push_back(line); } @@ -32,12 +32,12 @@ namespace dragon return m_lines; } - bool IncludePreprocessor::__can_file_be_included(std::vector& lines) + bool IncludePreprocessor::__can_file_be_included(std::vector& lines) { - ostd::String guard_name = ""; + String guard_name = ""; for (auto& line : lines) { - ostd::String lineEdit = line.new_trim(); + String lineEdit = line.new_trim(); if (lineEdit.new_toLower().startsWith("@guard ")) { guard_name = lineEdit.new_substr(7).trim(); @@ -57,7 +57,7 @@ namespace dragon bool IncludePreprocessor::__include_loop(void) { - std::vector lines = m_lines; + std::vector lines = m_lines; bool included = false; do { @@ -65,7 +65,7 @@ namespace dragon uint32_t i = 0; for ( ; i < lines.size(); i++) { - ostd::String line = lines[i]; + String line = lines[i]; line.trim(); if (line.new_toLower().startsWith("@include") && line.len() > 8) { @@ -90,15 +90,15 @@ namespace dragon return true; } - std::vector IncludePreprocessor::__load_file(const ostd::String& filePath) + std::vector IncludePreprocessor::__load_file(const String& filePath) { const auto& include_dirs = Assembler::Application::args.include_directories; if (ostd::FileSystem::fileExists(m_directory + filePath)) { ostd::TextFileBuffer file(m_directory + filePath); - ostd::String source = file.rawContent(); - return ostd::String(source.replaceAll("\t", " ")).tokenize("\n", false).getRawData(); + String source = file.rawContent(); + return String(source.replaceAll("\t", " ")).tokenize("\n", false).getRawData(); } for (const auto& dir : include_dirs) @@ -106,8 +106,8 @@ namespace dragon if (ostd::FileSystem::fileExists(dir + filePath)) { ostd::TextFileBuffer file(dir + filePath); - ostd::String source = file.rawContent(); - return ostd::String(source.replaceAll("\t", " ")).tokenize("\n", false).getRawData(); + String source = file.rawContent(); + return String(source.replaceAll("\t", " ")).tokenize("\n", false).getRawData(); } } diff --git a/src/debugger/Debugger.cpp b/src/debugger/Debugger.cpp index ddddfef..f32d5b2 100644 --- a/src/debugger/Debugger.cpp +++ b/src/debugger/Debugger.cpp @@ -53,7 +53,7 @@ namespace dragon return codeRegion; } - ostd::String Debugger::Utils::findSymbol(const DisassemblyList& list, uint16_t address, uint16_t* outSize) + String Debugger::Utils::findSymbol(const DisassemblyList& list, uint16_t address, uint16_t* outSize) { for (auto& line : list) { @@ -67,7 +67,7 @@ namespace dragon return ""; } - uint16_t Debugger::Utils::findSymbol(const DisassemblyList& list, const ostd::String& symbol, uint16_t* outSize) + uint16_t Debugger::Utils::findSymbol(const DisassemblyList& list, const String& symbol, uint16_t* outSize) { for (auto& line : list) { @@ -116,7 +116,7 @@ namespace dragon ostd::ConsoleOutputHandler& Debugger::Utils::printFullLine(char c, const ostd::ConsoleColors::tConsoleColor& foreground) { int32_t cw = ostd::BasicConsole::getConsoleWidth(); - ostd::String str = ostd::String::duplicateChar(c, cw); + String str = String::duplicateChar(c, cw); out.fg(foreground).p(str).reset().nl(); return out; } @@ -124,7 +124,7 @@ namespace dragon ostd::ConsoleOutputHandler& Debugger::Utils::printFullLine(char c, const ostd::ConsoleColors::tConsoleColor& foreground, const ostd::ConsoleColors::tConsoleColor& background) { int32_t cw = ostd::BasicConsole::getConsoleWidth(); - ostd::String str = ostd::String::duplicateChar(c, cw); + String str = String::duplicateChar(c, cw); out.bg(background).fg(foreground).p(str).reset().nl(); return out; } @@ -161,7 +161,7 @@ namespace dragon //Debugger::Display - void Debugger::Display::colorizeInstructionBody(const ostd::String& instBody, bool currentLine, const DisassemblyList& labelList) + void Debugger::Display::colorizeInstructionBody(const String& instBody, bool currentLine, const DisassemblyList& labelList) { ostd::RegexRichString rgxrstr(instBody); rgxrstr.fg("\\{|\\}|\\+|\\*|\\-|\\/|\\(|\\)|\\[|\\]", "Red"); //Operators @@ -169,18 +169,18 @@ namespace dragon rgxrstr.fg("(? ").reset(); out.pStyled(rgx).nl().reset(); @@ -1153,7 +1153,7 @@ namespace dragon Utils::printFullLine('#', ostd::ConsoleColors::Black, ostd::ConsoleColors::Red); out.nl().fg(ostd::ConsoleColors::Yellow).p("List of available commands:").reset().nl(); - ostd::String tmpCommand = "(d)iff-view"; + String tmpCommand = "(d)iff-view"; tmpCommand.addRightPadding(commandLength); out.fg(ostd::ConsoleColors::Blue).p(tmpCommand).fg(ostd::ConsoleColors::Green).p("Used to show the state of the machine, comparing the current cycle with the last.").reset().nl(); tmpCommand = "(q)uit"; @@ -1188,7 +1188,7 @@ namespace dragon Utils::isEscapeKeyPressed(true); } - ostd::String Debugger::Display::changeScreen(void) + String Debugger::Display::changeScreen(void) { if (debugger.command == "diff-view" || debugger.command == "d") { @@ -1207,7 +1207,7 @@ namespace dragon else if (debugger.command.startsWith("stack") || debugger.command.startsWith("s")) { uint16_t default_stack_rows = 8; - ostd::String params = debugger.command.new_trim(); + String params = debugger.command.new_trim(); if (params == "stack" || params == "s") printStack(default_stack_rows); else if (params.contains(" ")) @@ -1250,7 +1250,7 @@ namespace dragon while (dragon::data::ErrorHandler::hasError()) { auto err = dragon::data::ErrorHandler::popError(); - out.nl().fg(ostd::ConsoleColors::Red).p("Error ").p(ostd::String::getHexStr(err.code, true, 8).cpp_str()).p(": ").p(err.text.cpp_str()).nl(); + out.nl().fg(ostd::ConsoleColors::Red).p("Error ").p(String::getHexStr(err.code, true, 8).cpp_str()).p(": ").p(err.text.cpp_str()).nl(); } debugger.args.step_exec = true; } @@ -1273,7 +1273,7 @@ namespace dragon } for (int32_t i = 2; i < argc; i++) { - ostd::String edit(argv[i]); + String edit(argv[i]); if (edit == "--verbose-load") debugger.args.verbose_load = true; else if (edit == "--step-exec") @@ -1311,12 +1311,15 @@ namespace dragon int32_t Debugger::initRuntime(void) { - int32_t init_state = dragon::DragonRuntime::initMachine(debugger.args.machine_config_path, - debugger.args.verbose_load, - debugger.args.track_step_diff, - debugger.args.hide_virtual_display, - debugger.args.track_call_stack, - true); //CPU Debug Mode Enabled + + dragon::DragonRuntime::tRuntimeInitInfo initInfo; + initInfo.configFilePath = debugger.args.machine_config_path; + initInfo.verboseLoad = debugger.args.verbose_load; + initInfo.trackMachineInfoDiff = debugger.args.track_step_diff; + initInfo.hideVirtualDisplay = debugger.args.hide_virtual_display; + initInfo.trackCallStack = debugger.args.track_call_stack; + initInfo.debugModeEnabled = true; + int32_t init_state = dragon::DragonRuntime::initMachine(initInfo); closeEventListener.init(); if (init_state != 0) return init_state; //TODO: Error @@ -1331,9 +1334,9 @@ namespace dragon return DragonRuntime::RETURN_VAL_EXIT_SUCCESS; } - ostd::String Debugger::getCommandInput(void) + String Debugger::getCommandInput(void) { - ostd::String cmd; + String cmd; ostd::KeyboardController kbc; ostd::eKeys key = ostd::eKeys::NoKeyPressed; @@ -1344,7 +1347,7 @@ namespace dragon } return kbc.getInputString(); - // ostd::String cmd; + // String cmd; // std::getline(std::cin, cmd.cpp_str_ref()); // return cmd; } @@ -1472,7 +1475,7 @@ namespace dragon uint8_t type = TYPE_WORD; if (data().command.contains(" ")) { - ostd::String size_str = data().command.new_substr(0, data().command.indexOf(" ")).trim(); + String size_str = data().command.new_substr(0, data().command.indexOf(" ")).trim(); data().command.substr(data().command.indexOf(" ") + 1).trim(); if (size_str == "byte") type = TYPE_BYTE; else if (size_str == "word") type = TYPE_WORD; @@ -1486,15 +1489,15 @@ namespace dragon type = TYPE_WORD; uint16_t addr = data().command.toInt(); uint16_t end_addr = addr; - ostd::String tmp = ""; - tmp.add("*(").add(ostd::String::getHexStr(addr, true, 2)); + String tmp = ""; + tmp.add("*(").add(String::getHexStr(addr, true, 2)); if (type != TYPE_BYTE) { end_addr = addr + type - 1; if (end_addr < addr) end_addr = addr; else - tmp.add("-").add(ostd::String::getHexStr(end_addr, true, 2)); + tmp.add("-").add(String::getHexStr(end_addr, true, 2)); } tmp.add(")"); ostd::RegexRichString rgx(tmp); @@ -1507,7 +1510,7 @@ namespace dragon for (uint16_t a = addr; a <= end_addr; a++) { uint8_t value = DragonRuntime::memMap.read8(a); - output().fg(ostd::ConsoleColors::BrightRed).p(ostd::String::getHexStr(value, true, 1)); + output().fg(ostd::ConsoleColors::BrightRed).p(String::getHexStr(value, true, 1)); if (a < end_addr) output().p(" "); } @@ -1524,10 +1527,10 @@ namespace dragon output().fg(ostd::ConsoleColors::Red).p("Unknown symbol for command.").reset().nl(); else { - ostd::String tmp = ""; - tmp.add("*(").add(ostd::String::getHexStr(addr, true, 2)); + String tmp = ""; + tmp.add("*(").add(String::getHexStr(addr, true, 2)); if (size > 1) - tmp.add("-").add(ostd::String::getHexStr((uint16_t)(addr + size - 1), true, 2)); + tmp.add("-").add(String::getHexStr((uint16_t)(addr + size - 1), true, 2)); tmp.add(")"); ostd::RegexRichString rgx(tmp); rgx.fg("\\(|\\)|-", "darkgray"); @@ -1546,7 +1549,7 @@ namespace dragon output().fg(ostd::ConsoleColors::BrightRed).pChar((char)value); continue; } - output().fg(ostd::ConsoleColors::BrightRed).p(ostd::String::getHexStr(value, true, 1)); + output().fg(ostd::ConsoleColors::BrightRed).p(String::getHexStr(value, true, 1)); if (a < addr + size - 1) output().p(" "); } @@ -1590,12 +1593,12 @@ namespace dragon if (Utils::isBreakPoint(addr)) { Utils::removeBreakPoint(addr); - output().fg(ostd::ConsoleColors::Yellow).p("Breakpoint removed at address: ").p(ostd::String::getHexStr(addr, true, 2)).reset().nl(); + output().fg(ostd::ConsoleColors::Yellow).p("Breakpoint removed at address: ").p(String::getHexStr(addr, true, 2)).reset().nl(); } else { Utils::addBreakPoint(addr); - output().fg(ostd::ConsoleColors::Yellow).p("Breakpoint set at address: ").p(ostd::String::getHexStr(addr, true, 2)).reset().nl(); + output().fg(ostd::ConsoleColors::Yellow).p("Breakpoint set at address: ").p(String::getHexStr(addr, true, 2)).reset().nl(); } } Display::printPrompt(); @@ -1655,7 +1658,7 @@ namespace dragon else if (data().command.contains("[") && data().command.endsWith("]")) { uint16_t nbytes = 1; - ostd::String str_nbytes = data().command.new_substr(data().command.indexOf("[") + 1).trim(); + String str_nbytes = data().command.new_substr(data().command.indexOf("[") + 1).trim(); str_nbytes.substr(0, str_nbytes.len() - 1); data().command.substr(0, data().command.indexOf("[")).trim(); if (str_nbytes.isNumeric()) @@ -1678,7 +1681,7 @@ namespace dragon Utils::printFullLine('#', ostd::ConsoleColors::Black, ostd::ConsoleColors::Red); out.nl().fg(ostd::ConsoleColors::Yellow).p("List of available commands:").reset().nl(); - ostd::String tmpCommand = "(r)un"; + String tmpCommand = "(r)un"; tmpCommand.addRightPadding(commandLength); out.fg(ostd::ConsoleColors::Blue).p(tmpCommand).fg(ostd::ConsoleColors::Green).p("Used to start the runtime.").reset().nl(); tmpCommand = "(q)uit"; @@ -1709,7 +1712,7 @@ namespace dragon int32_t commandLength = 46; out.nl().fg(ostd::ConsoleColors::Yellow).p("List of available parameters:").reset().nl(); - ostd::String tmpCommand = "--verbose-load"; + String tmpCommand = "--verbose-load"; tmpCommand.addRightPadding(commandLength); out.fg(ostd::ConsoleColors::Blue).p(tmpCommand).fg(ostd::ConsoleColors::Green).p("Used to show more information while loading the virtual machine.").reset().nl(); tmpCommand = "--step-exec"; diff --git a/src/debugger/Debugger.hpp b/src/debugger/Debugger.hpp index b28192b..5084ceb 100644 --- a/src/debugger/Debugger.hpp +++ b/src/debugger/Debugger.hpp @@ -12,7 +12,7 @@ namespace dragon public: struct tCommandLineArgs { inline tCommandLineArgs(void) { } - ostd::String machine_config_path = ""; + String machine_config_path = ""; bool verbose_load = false; bool force_load = false; bool step_exec = false; @@ -21,7 +21,7 @@ namespace dragon bool hide_virtual_display = true; bool track_call_stack = true; bool auto_track_all_data_symbols = true; - ostd::String force_load_file = ""; + String force_load_file = ""; uint16_t force_load_mem_offset = 0x00; }; public: struct tDebuggerData @@ -32,11 +32,11 @@ namespace dragon DisassemblyList labels; DisassemblyList data; std::vector trackedAddresses; - ostd::String command; + String command; int32_t labelLineLength { 40 }; uint16_t currentAddress { 0 }; bool userQuit { false }; - ostd::String disassemblyDirectory { "disassembly" }; + String disassemblyDirectory { "disassembly" }; std::vector manualBreakPoints; }; struct tCloseEventListener : public ostd::BaseObject @@ -52,8 +52,8 @@ namespace dragon { public: static DisassemblyList findCodeRegion(const DisassemblyList& code, uint16_t address, uint16_t codeRegionMargin); - static ostd::String findSymbol(const DisassemblyList& labels, uint16_t address, uint16_t* outSize = nullptr); - static uint16_t findSymbol(const DisassemblyList& labels, const ostd::String& symbol, uint16_t* outSize = nullptr); + static String findSymbol(const DisassemblyList& labels, uint16_t address, uint16_t* outSize = nullptr); + static uint16_t findSymbol(const DisassemblyList& labels, const String& symbol, uint16_t* outSize = nullptr); static bool isValidLabelNameChar(char c); static void clearConsoleLine(void); static bool isEscapeKeyPressed(bool blocking = false); @@ -66,8 +66,8 @@ namespace dragon public: class Display { public: - static void colorizeInstructionBody(const ostd::String& instBody, bool currentLine, const DisassemblyList& labelList); - static void colorCodeInstructions(const ostd::String& inst, bool currentLine, const DisassemblyList& labelList); + static void colorizeInstructionBody(const String& instBody, bool currentLine, const DisassemblyList& labelList); + static void colorCodeInstructions(const String& inst, bool currentLine, const DisassemblyList& labelList); static void printPrompt(void); static void printStep(void); static void printDiff(void); @@ -75,13 +75,13 @@ namespace dragon static void printStack(uint16_t nrows); static void printCallStack(void); static void printHelp(void); - static ostd::String changeScreen(void); + static String changeScreen(void); }; public: static void processErrors(void); static int32_t loadArguments(int argc, char** argv); static int32_t initRuntime(void); - static ostd::String getCommandInput(void); + static String getCommandInput(void); static inline tDebuggerData& data(void) { return debugger; } static inline ostd::ConsoleOutputHandler& output(void) { return out; } static int32_t topLevelPrompt(void); @@ -100,6 +100,6 @@ namespace dragon static tCloseEventListener closeEventListener; public: - inline static const ostd::String InputCommandQuit = "//quit//"; + inline static const String InputCommandQuit = "//quit//"; }; } diff --git a/src/debugger/DebuggerNew.cpp b/src/debugger/DebuggerNew.cpp deleted file mode 100644 index f6616c0..0000000 --- a/src/debugger/DebuggerNew.cpp +++ /dev/null @@ -1,768 +0,0 @@ -#include "DebuggerNew.hpp" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "DisassemblyLoader.hpp" -#include "../runtime/DragonRuntime.hpp" - -namespace ogfx -{ - namespace gui - { - CustomButton::EventListener::EventListener(CustomButton& _parent) : parent(_parent) - { - connectSignal(ostd::BuiltinSignals::KeyPressed); - connectSignal(ostd::BuiltinSignals::KeyReleased); - connectSignal(ostd::BuiltinSignals::MouseMoved); - connectSignal(ostd::BuiltinSignals::MousePressed); - connectSignal(ostd::BuiltinSignals::MouseReleased); - connectSignal(ostd::BuiltinSignals::OnGuiEvent); - connectSignal(ostd::BuiltinSignals::WindowResized); - } - - void CustomButton::EventListener::handleSignal(ostd::Signal& signal) - { - if (signal.ID == ostd::BuiltinSignals::KeyPressed) - { - if (m_lastEvent != eEventType::KeyPressed) - { - m_lastEvent = eEventType::KeyPressed; - } - auto& data = (ogfx::KeyEventData&)signal.userData; - if (data.keyCode == SDLK_BACKSPACE) - { - } - else if (data.keyCode == SDLK_LEFT) - { - } - else if (data.keyCode == SDLK_RIGHT) - { - } - else if (data.keyCode == SDLK_RETURN) - { - } - else if (data.keyCode == SDLK_TAB) - { - } - } - else if (signal.ID == ostd::BuiltinSignals::MouseMoved) - { - auto& data = (ogfx::MouseEventData&)signal.userData; - if (parent.contains((float)data.position_x, (float)data.position_y)) - parent.m_mouseInside = true; - else - parent.m_mouseInside = false; - } - else if (signal.ID == ostd::BuiltinSignals::MousePressed) - { - auto& data = (ogfx::MouseEventData&)signal.userData; - if (data.button == ogfx::MouseEventData::eButton::Left && parent.m_gfx != nullptr && parent.m_mouseInside) - { - ostd::String text = parent.m_text; - ostd::Vec2 relativePosition = { (float)data.position_x, (float)data.position_y }; - relativePosition -= (parent.getPosition()); - parent.m_pressed = true; - } - } - else if (signal.ID == ostd::BuiltinSignals::MouseReleased) - { - auto& data = (ogfx::MouseEventData&)signal.userData; - if (data.button == ogfx::MouseEventData::eButton::Left && parent.m_gfx != nullptr) - { - if (parent.m_pressed) - { - ActionEventData aed(parent, parent.getName(), eActionEventType::Pressed, ostd::BaseObject::InvalidRef()); - ostd::SignalHandler::emitSignal(CustomButton::actionEventSignalID, ostd::Signal::Priority::RealTime, aed); - } - parent.m_pressed = false; - } - } - onSignalHandled(signal); - } - - - - - - CustomButton& CustomButton::create(const ostd::Vec2& position, const ostd::Vec2& size, const ostd::String& name) - { - setPosition(position); - setSize(size); - m_name = name; - m_eventListener = new EventListener(*this); //TODO: Delete -- Memory Leak - m_theme = tDefaultThemes::DefaultTheme; - return *this; - } - - void CustomButton::render(ogfx::BasicRenderer2D& gfx) - { - m_gfx = &gfx; - ostd::Color backgroundColor = m_theme.backgroundColor; - ostd::Color borderColor = m_theme.borderColor; - ostd::Color textColor = m_theme.textColor; - if (m_pressed) - { - backgroundColor = m_theme.backgroundColor_Pressed; - borderColor = m_theme.borderColor_Pressed; - textColor = m_theme.textColor_Pressed; - } - else if (m_mouseInside) - { - backgroundColor = m_theme.backgroundColor_Hover; - borderColor = m_theme.borderColor_Hover; - textColor = m_theme.textColor_Hover; - } - gfx.outlinedRect(*this, backgroundColor, borderColor, 2); - if (m_text.len() > 0) - { - ostd::IPoint strSize = gfx.getStringDimensions(m_text, m_theme.fontSize); - ostd::Vec2 txtPos = getPosition() + ostd::Vec2 { (getw() / 2.0f) - (strSize.x / 2.0f), (geth() / 2.0f) - (strSize.y / 2.0f) }; - gfx.drawString(m_text, txtPos, textColor, m_theme.fontSize); - } - onRender(gfx); - } - - void CustomButton::update(void) - { - onUpdate(); - } - - void CustomButton::fixedUpdate(void) - { - onFixedUpdate(); - } - - void CustomButton::setText(const ostd::String& text) - { - m_text = text; - } - - void CustomButton::appendText(const ostd::String& text) - { - m_text.add(text); - } - - void CustomButton::setTheme(Theme theme) - { - m_theme = theme; - } - } -} - - - - -namespace dragon -{ - //DebuggerNew::Utils - DisassemblyList DebuggerNew::findCodeRegion(const DisassemblyList& code, uint16_t address, uint16_t codeRegionMargin) - { - if (code.size() <= (codeRegionMargin * 2) + 1) return code; - std::vector codeRegion; - uint16_t start = 0; - uint16_t end = (codeRegionMargin * 2); - for (int32_t i = 0; i < code.size(); i++) - { - if (code[i].addr != address) continue; - if (i + 1 <= codeRegionMargin) break; - if (code.size() - (i + 1) < codeRegionMargin) - { - end = code.size() - 1; - start = end - ((codeRegionMargin * 2) + 1); - break; - } - start = i - codeRegionMargin; - end = i + codeRegionMargin; - break; - } - for (int16_t i = start; i <= end; i++) - codeRegion.push_back(code[i]); - return codeRegion; - } - - ostd::String DebuggerNew::findSymbol(const DisassemblyList& list, uint16_t address, uint16_t* outSize) - { - for (auto& line : list) - { - if (line.addr == address) - { - if (outSize != nullptr) - *outSize = line.size; - return line.code; - } - } - return ""; - } - - uint16_t DebuggerNew::findSymbol(const DisassemblyList& list, const ostd::String& symbol, uint16_t* outSize) - { - for (auto& line : list) - { - if (line.code == symbol) - { - if (outSize != nullptr) - *outSize = line.size; - return line.addr; - } - } - return 0x0000; - } - - bool DebuggerNew::isValidLabelNameChar(char c) - { - return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c == '_'); - } - - void DebuggerNew::removeBreakPoint(uint16_t addr) - { - if (debugger.manualBreakPoints.size() == 0) - return; - int32_t i = 0; - for ( ; i < debugger.manualBreakPoints.size(); i++) - { - if (debugger.manualBreakPoints[i] == addr) - break; - } - if (i >= debugger.manualBreakPoints.size()) - return; - debugger.manualBreakPoints.erase(debugger.manualBreakPoints.begin() + i); - } - - bool DebuggerNew::isBreakPoint(uint16_t addr) - { - for (const auto& b : debugger.manualBreakPoints) - if (b == addr) return true; - return false; - } - - void DebuggerNew::addBreakPoint(uint16_t addr) - { - debugger.manualBreakPoints.push_back(addr); - } - - - - - //Debugger - void DebuggerNew::processErrors(void) - { - if (!dragon::DragonRuntime::hasError()) return; - while (dragon::data::ErrorHandler::hasError()) - { - auto err = dragon::data::ErrorHandler::popError(); - out().nl().fg(ostd::ConsoleColors::Red).p("Error ").p(ostd::String::getHexStr(err.code, true, 8).cpp_str()).p(": ").p(err.text.cpp_str()).nl(); - } - debugger.args.step_exec = true; - } - - int32_t DebuggerNew::loadArguments(int argc, char** argv) - { - if (argc < 2) - { - out().fg(ostd::ConsoleColors::Red).p("Error: too few arguments.").nl(); - out().fg(ostd::ConsoleColors::Red).p("Use the --help option for more info.").reset().nl(); - return DragonRuntime::RETURN_VAL_TOO_FEW_ARGUMENTS; - } - else - { - debugger.args.machine_config_path = argv[1]; - if (debugger.args.machine_config_path == "--help") - { - // print_application_help(); - return DragonRuntime::RETURN_VAL_CLOSE_DEBUGGER; - } - for (int32_t i = 2; i < argc; i++) - { - ostd::String edit(argv[i]); - if (edit == "--verbose-load") - debugger.args.verbose_load = true; - else if (edit == "--step-exec") - debugger.args.step_exec = true; - else if (edit == "--track-step-diff-off") - debugger.args.track_step_diff = false; - else if (edit == "--auto-track-data-off") - debugger.args.auto_track_all_data_symbols = false; - else if (edit == "--hide-vdisplay") - debugger.args.hide_virtual_display = true; - else if (edit == "--auto-start") - debugger.args.auto_start_debug = true; - else if (edit == "--force-load") - { - if ((argc - 1) - i < 2) - return DragonRuntime::RETURN_VAL_MISSING_PARAM; - i++; - debugger.args.force_load_file = argv[i]; - i++; - edit = argv[i]; - if (!edit.isNumeric()) - return DragonRuntime::RETURN_VAL_PARAMETER_NOT_NUMERIC; - debugger.args.force_load_mem_offset = (uint16_t)edit.toInt(); - debugger.args.force_load = true; - } - else if (edit == "--help") - { - // print_application_help(); - return DragonRuntime::RETURN_VAL_CLOSE_DEBUGGER; - } - } - } - return DragonRuntime::RETURN_VAL_EXIT_SUCCESS; - } - - int32_t DebuggerNew::initRuntime(void) - { - int32_t init_state = dragon::DragonRuntime::initMachine(debugger.args.machine_config_path, - debugger.args.verbose_load, - debugger.args.track_step_diff, - debugger.args.hide_virtual_display, - debugger.args.track_call_stack, - true); //CPU Debug Mode Enabled - // closeEventListener.init(); - if (init_state != 0) return init_state; //TODO: Error - - if (debugger.args.force_load) - dragon::DragonRuntime::forceLoad(debugger.args.force_load_file, debugger.args.force_load_mem_offset); - - dragon::DisassemblyLoader::loadDirectory(debugger.disassemblyDirectory); - debugger.code = dragon::DisassemblyLoader::getCodeTable(); - debugger.labels = dragon::DisassemblyLoader::getLabelTable(); - debugger.data = dragon::DisassemblyLoader::getDataTable(); - - return DragonRuntime::RETURN_VAL_EXIT_SUCCESS; - } - - ostd::String DebuggerNew::getCommandInput(void) - { - // ostd::String cmd; - // ostd::KeyboardController kbc; - // ostd::eKeys key = ostd::eKeys::NoKeyPressed; - - // while ((key = kbc.getPressedKey()) != ostd::eKeys::Enter) - // { - // if (key == ostd::eKeys::Escape) - // return InputCommandQuit; - // } - // return kbc.getInputString(); - - return ""; - } - - int32_t DebuggerNew::executeRuntime(void) - { - int32_t rValue = 0; - bool userQuit = false; - out().clear().fg(ostd::ConsoleColors::Green).p("Program running...").nl(); - if (!data().args.step_exec) - out().fg(ostd::ConsoleColors::Yellow).p("Press to enter in step-execution mode...").reset().nl(); - while (!userQuit) - { - ostd::SignalHandler::handleDelegateSignals(); - // if (closeEventListener.hasHappened()) - // userQuit = true; - data().command.clr(); - if (!userQuit && data().args.step_exec) - rValue = step_execution(userQuit, true); - else if (!userQuit) - rValue = normal_runtime(userQuit); - data().currentAddress = DragonRuntime::cpu.readRegister(data::Registers::IP); - } - out().nl().fg(ostd::ConsoleColors::Yellow).p("Execution terminated.").nl().nl().reset(); - return rValue; - } - - int32_t DebuggerNew::step_execution(bool& outUserQuit, bool exec_first_step) - { - if (exec_first_step && !DragonRuntime::cpu.isHalted()) - DragonRuntime::runStep(data().trackedAddresses); - // Display::printStep(); - processErrors(); - if (DragonRuntime::cpu.isInDebugBreakPoint()) - out().fg(ostd::ConsoleColors::Red).p("Reached Debug Break Point.").reset().nl(); - // Display::printPrompt(); - data().command = getCommandInput(); - data().command.trim().toLower(); - while (data().command != "") - { - if (data().command == "q" || data().command == "quit" || data().command == InputCommandQuit) - { - out().nl(); - outUserQuit = true; - data().command = ""; - } - else if (data().command == "c" || data().command == "continue") - { - data().args.step_exec = false; - data().command = ""; - out().clear().fg(ostd::ConsoleColors::Green).p("Program running...").nl(); - out().fg(ostd::ConsoleColors::Yellow).p("Press to enter in step-execution mode...").reset().nl(); - } - else if (data().command.startsWith("p ") || data().command.startsWith("print ")) - { - data().command.substr(data().command.indexOf(" ") + 1).trim(); - const uint8_t TYPE_STRING = 0; - const uint8_t TYPE_BYTE = 1; - const uint8_t TYPE_WORD = 2; - const uint8_t TYPE_DWORD = 4; - const uint8_t TYPE_QWORD = 8; - uint8_t type = TYPE_WORD; - if (data().command.contains(" ")) - { - ostd::String size_str = data().command.new_substr(0, data().command.indexOf(" ")).trim(); - data().command.substr(data().command.indexOf(" ") + 1).trim(); - if (size_str == "byte") type = TYPE_BYTE; - else if (size_str == "word") type = TYPE_WORD; - else if (size_str == "dword") type = TYPE_DWORD; - else if (size_str == "qword") type = TYPE_QWORD; - else if (size_str == "string") type = TYPE_STRING; - } - if (data().command.isNumeric()) - { - if (type == TYPE_STRING) - type = TYPE_WORD; - uint16_t addr = data().command.toInt(); - uint16_t end_addr = addr; - ostd::String tmp = ""; - tmp.add("*(").add(ostd::String::getHexStr(addr, true, 2)); - if (type != TYPE_BYTE) - { - end_addr = addr + type - 1; - if (end_addr < addr) - end_addr = addr; - else - tmp.add("-").add(ostd::String::getHexStr(end_addr, true, 2)); - } - tmp.add(")"); - ostd::RegexRichString rgx(tmp); - rgx.fg("\\(|\\)|-", "darkgray"); - rgx.fg("\\*", "red"); - rgx.fg("0x[0-9A-Fa-f]+|0b[0-1]+|(? command.").reset().nl(); - else - { - ostd::String tmp = ""; - tmp.add("*(").add(ostd::String::getHexStr(addr, true, 2)); - if (size > 1) - tmp.add("-").add(ostd::String::getHexStr((uint16_t)(addr + size - 1), true, 2)); - tmp.add(")"); - ostd::RegexRichString rgx(tmp); - rgx.fg("\\(|\\)|-", "darkgray"); - rgx.fg("\\*", "red"); - rgx.fg("0x[0-9A-Fa-f]+|0b[0-1]+|(? command.").reset().nl(); - } - // Display::printPrompt(); - data().command = getCommandInput(); - } - else if (data().command.startsWith("b ") || data().command.startsWith("break ")) - {//0x2C1D - data().command.substr(data().command.indexOf(" ") + 1).trim(); - uint16_t addr = 0; - bool valid = false; - if (data().command.isNumeric()) - { - addr = (uint16_t)data().command.toInt(); - valid = true; - } - else if (data().command.startsWith("$")) - { - addr = findSymbol(debugger.labels, data().command); - if (addr == 0x0000 || addr == 0xFFFF) - out().fg(ostd::ConsoleColors::Red).p("Invalid symbol: ").p(data().command).reset().nl(); - else - valid = true; - } - else - { - out().fg(ostd::ConsoleColors::Red).p("Invalid value for command.").reset().nl(); - } - if (valid) - { - if (isBreakPoint(addr)) - { - removeBreakPoint(addr); - out().fg(ostd::ConsoleColors::Yellow).p("Breakpoint removed at address: ").p(ostd::String::getHexStr(addr, true, 2)).reset().nl(); - } - else - { - addBreakPoint(addr); - out().fg(ostd::ConsoleColors::Yellow).p("Breakpoint set at address: ").p(ostd::String::getHexStr(addr, true, 2)).reset().nl(); - } - } - // Display::printPrompt(); - data().command = getCommandInput(); - } - else - data().command = "";//Display::changeScreen(); - } - return DragonRuntime::RETURN_VAL_EXIT_SUCCESS; - } - - int32_t DebuggerNew::normal_runtime(bool& outUserQuit) - { - bool result = DragonRuntime::runStep(data().trackedAddresses); - if (isBreakPoint((uint16_t)DragonRuntime::cpu.readRegister(data::Registers::IP))) - { - data().args.step_exec = true; - return step_execution(outUserQuit, false); - } - bool hasError = DragonRuntime::hasError(); - bool enableStepExec = !result || hasError || DragonRuntime::cpu.isInDebugBreakPoint(); - data().args.step_exec = enableStepExec; - if (enableStepExec) - return step_execution(outUserQuit, false); - return DragonRuntime::RETURN_VAL_EXIT_SUCCESS; - } - - - - - //Display - void DebuggerNew::colorizeInstructionBody(const ostd::String& instBody, bool currentLine, const DisassemblyList& labelList) - { - ostd::RegexRichString rgxrstr(instBody); - rgxrstr.fg("\\{|\\}|\\+|\\*|\\-|\\/|\\(|\\)|\\[|\\]", "Red"); //Operators - rgxrstr.fg("0x[0-9A-Fa-f]+|0b[0-1]+|(? -#include -#include -#include -#include -#include -#include -#include -#include "../assembler/Assembler.hpp" - - -namespace ogfx -{ - namespace gui - { - class CustomButton : public ostd::Rectangle - { - public: class EventListener : public ostd::BaseObject - { - public: enum class eEventType { None = 0, MousePressed, KeyPressed, KeyReleased }; - public: - EventListener(CustomButton& _parent); - virtual void handleSignal(ostd::Signal& signal) override; - inline virtual void onSignalHandled(ostd::Signal& signal) { } - inline CustomButton& getParent(void) { return parent; } - - private: - CustomButton& parent; - eEventType m_lastEvent { eEventType::None }; - }; - public: class Theme - { - public: - ostd::Color textColor { 0, 0, 0, 0 }; - ostd::Color borderColor { 0, 0, 0, 0 }; - ostd::Color backgroundColor { 0, 0, 0, 0 }; - - ostd::Color textColor_Hover { 0, 0, 0, 0 }; - ostd::Color borderColor_Hover { 0, 0, 0, 0 }; - ostd::Color backgroundColor_Hover { 0, 0, 0, 0 }; - - ostd::Color textColor_Pressed { 0, 0, 0, 0 }; - ostd::Color borderColor_Pressed { 0, 0, 0, 0 }; - ostd::Color backgroundColor_Pressed { 0, 0, 0, 0 }; - - int32_t fontSize { 0 }; - }; - public: struct tDefaultThemes - { - inline static const Theme DebugTheme { - { 220, 220, 255 }, //Text Color - { 10, 20, 120 }, //Border Color - { 0, 0, 22 }, //Background Color - - { 220, 220, 255 }, //Text Color Hover - { 10, 20, 120 }, //Border Color Hover - { 0, 0, 22 }, //Background Color Hover - - { 220, 220, 255 }, //Text Color Pressed - { 10, 20, 120 }, //Border Color Pressed - { 0, 0, 22 }, //Background Color Pressed - - 20 //Font Size - }; - inline static const Theme DefaultTheme { - { 120, 120, 180 }, //Text Color - { 10, 20, 120 }, //Border Color - { 0, 2, 10 }, //Background Color - - { 120, 120, 210 }, //Text Color Hover - { 10, 20, 180 }, //Border Color Hover - { 0, 2, 50 }, //Background Color Hover - - { 120, 120, 120 }, //Text Color Pressed - { 10, 20, 60 }, //Border Color Pressed - { 0, 2, 0 }, //Background Color Pressed - - 20 //Font Size - }; - }; - public: enum eActionEventType { None = 0, Pressed }; - public: class ActionEventData : public ostd::BaseObject - { - public: - inline ActionEventData(CustomButton& _sender, const ostd::String& _senderName, eActionEventType _eventType, ostd::BaseObject& _userData) : - sender(_sender), - senderName(_senderName), - eventType(_eventType), - userData(_userData) - { - setTypeName("ogfx::gui::CustomButton::ActionEventData"); - validate(); - } - - public: - CustomButton& sender; - ostd::String senderName { "" }; - eActionEventType eventType { eActionEventType::None }; - ostd::BaseObject& userData { ostd::BaseObject::InvalidRef() }; - }; - - public: - inline CustomButton(void) { create({ 0.0f, 0.0f }, { 200.0f, 30.0f }, "UnnamedButton"); } - inline CustomButton(const ostd::Vec2& position, const ostd::Vec2& size, const ostd::String& name) { create(position, size, name); } - CustomButton& create(const ostd::Vec2& position, const ostd::Vec2& size, const ostd::String& name); - - virtual void render(ogfx::BasicRenderer2D& gfx); - virtual void update(void); - virtual void fixedUpdate(void); - - virtual inline void onRender(ogfx::BasicRenderer2D& gfx) { } - virtual inline void onUpdate(void) { } - virtual inline void onFixedUpdate(void) { } - - void setText(const ostd::String& text); - void appendText(const ostd::String& text); - void setTheme(Theme theme); - - inline void setEventListener(EventListener& evtl) { m_eventListener = &evtl; } - inline void setName(const ostd::String& name) { m_name = name; } - - inline EventListener* getEventListener(void) const { return m_eventListener; } - inline ostd::String getText(void) const { return m_text; } - inline Theme& getTheme(void) { return m_theme; } - inline ostd::String getName(void) const { return m_name; } - inline bool isMouseInside(void) const { return m_mouseInside; } - inline bool isPressed(void) const { return m_pressed; } - - private: - EventListener* m_eventListener { nullptr }; - ogfx::BasicRenderer2D* m_gfx { nullptr }; - - protected: - ostd::String m_name { "" }; - ostd::String m_text { "" }; - Theme m_theme; - bool m_mouseInside { false }; - bool m_pressed { false }; - - public: - inline static const uint32_t actionEventSignalID { ostd::SignalHandler::newCustomSignal(12400) }; - }; - } -} - -namespace dragon -{ - typedef std::vector DisassemblyList; - - class DebuggerNew : public ogfx::GraphicsWindow - { - public: struct tCommandLineArgs - { - inline tCommandLineArgs(void) { } - ostd::String machine_config_path = ""; - bool verbose_load = false; - bool force_load = false; - bool step_exec = false; - bool track_step_diff = true; - bool auto_start_debug = false; - bool hide_virtual_display = true; - bool track_call_stack = true; - bool auto_track_all_data_symbols = true; - ostd::String force_load_file = ""; - uint16_t force_load_mem_offset = 0x00; - }; - public: struct tDebuggerData - { - inline tDebuggerData(void) { } - tCommandLineArgs args; - DisassemblyList code; - DisassemblyList labels; - DisassemblyList data; - std::vector trackedAddresses; - ostd::String command; - int32_t labelLineLength { 40 }; - uint16_t currentAddress { 0 }; - bool userQuit { false }; - ostd::String disassemblyDirectory { "disassembly" }; - std::vector manualBreakPoints; - }; - public: - //Utils - DisassemblyList findCodeRegion(const DisassemblyList& code, uint16_t address, uint16_t codeRegionMargin); - ostd::String findSymbol(const DisassemblyList& labels, uint16_t address, uint16_t* outSize = nullptr); - uint16_t findSymbol(const DisassemblyList& labels, const ostd::String& symbol, uint16_t* outSize = nullptr); - bool isValidLabelNameChar(char c); - void removeBreakPoint(uint16_t addr); - bool isBreakPoint(uint16_t addr); - void addBreakPoint(uint16_t addr); - - //Debugger - void processErrors(void); - int32_t loadArguments(int argc, char** argv); - int32_t initRuntime(void); - ostd::String getCommandInput(void); - inline tDebuggerData& data(void) { return debugger; } - int32_t executeRuntime(void); - int32_t step_execution(bool& outUserQuit, bool exec_first_step = true); - int32_t normal_runtime(bool& outUserQuit); - - //Display - void colorizeInstructionBody(const ostd::String& instBody, bool currentLine, const DisassemblyList& labelList); - void colorCodeInstructions(const ostd::String& inst, bool currentLine, const DisassemblyList& labelList); - void printStep(void); - - //General - inline DebuggerNew(void) : m_sigHandler(m_textInput, *this), m_btnSigHandler(m_testBtn) { } - void onInitialize(void) override; - void handleSignal(ostd::Signal& signal) override; - void onRender(void) override; - void onFixedUpdate(double frameTime_s) override; - void onUpdate(void) override; - - private: - tDebuggerData debugger; - ogfx::gui::RawTextInput m_textInput; - ogfx::BasicRenderer2D m_gfx; - ogfx::gui::RawTextInputEventListener m_sigHandler; - ogfx::gui::RawTextInputNumberCharacterFilter m_numCharFilter; - - ogfx::gui::CustomButton m_testBtn; - ogfx::gui::CustomButton::EventListener m_btnSigHandler; - - ogfx::GraphicsWindowOutputHandler m_wout; - ostd::IPoint m_consoleSize { 300, 50 }; - ostd::Vec2 m_consolePosition { 650, 8 }; - // std::vector m_codeTable; - // int32_t m_codeRandomIndex { 0 }; - ostd::ByteStream m_test; - - public: - inline static const ostd::String InputCommandQuit = "//quit//"; - }; -} diff --git a/src/debugger/DisassemblyLoader.cpp b/src/debugger/DisassemblyLoader.cpp index 853704f..ccea7cf 100644 --- a/src/debugger/DisassemblyLoader.cpp +++ b/src/debugger/DisassemblyLoader.cpp @@ -12,7 +12,7 @@ namespace dragon { const DisassemblyTable DisassemblyTable::DefaultObject; - void DisassemblyTable::init(const ostd::String& filePath) + void DisassemblyTable::init(const String& filePath) { ostd::ByteStream stream; if (!ostd::Memory::loadByteStreamFromFile(filePath, stream)) @@ -32,7 +32,7 @@ namespace dragon int32_t line_addr = 0; int16_t data_size = 1; int8_t line_code_char = 0; - ostd::String header_string = ""; + String header_string = ""; serializer.r_NullTerminatedString(0, header_string); if (header_string != "{ DRAGON_DEBUG_DISASSEMBLY }") return; addr += (header_string.len() + 1) * ostd::tTypeSize::BYTE; @@ -42,7 +42,7 @@ namespace dragon addr += ostd::tTypeSize::DWORD; serializer.r_Word(addr, data_size); addr += ostd::tTypeSize::WORD; - ostd::String code_line = ""; + String code_line = ""; serializer.r_NullTerminatedString(addr, code_line); addr += (code_line.len() + 1) * ostd::tTypeSize::BYTE; if (code_line == "{ DATA }") @@ -66,18 +66,18 @@ namespace dragon line.size = data_size; if (mode == MODE_CODE) { - ostd::String codeEdit(line.code); + String codeEdit(line.code); codeEdit.trim(); if (codeEdit.contains(" ")) { - ostd::String part1 = codeEdit.new_substr(0, codeEdit.indexOf(" ")); - ostd::String part2 = codeEdit.new_substr(codeEdit.indexOf(" ") + 1); + String part1 = codeEdit.new_substr(0, codeEdit.indexOf(" ")); + String part2 = codeEdit.new_substr(codeEdit.indexOf(" ") + 1); part1.trim(); part2.trim(); int32_t opCodeLen = 10; if (part1.len() < opCodeLen) { - codeEdit = part1 + ostd::String::duplicateChar(' ', opCodeLen - part1.len()) + part2; + codeEdit = part1 + String::duplicateChar(' ', opCodeLen - part1.len()) + part2; line.code = codeEdit; } } @@ -93,14 +93,14 @@ namespace dragon - void DisassemblyLoader::loadDirectory(const ostd::String& directoryPath) + void DisassemblyLoader::loadDirectory(const String& directoryPath) { auto list = ostd::FileSystem::listFilesInDirectory(directoryPath); for (auto& path : list) loadFile(path.string()); } - const DisassemblyTable& DisassemblyLoader::loadFile(const ostd::String& filePath) + const DisassemblyTable& DisassemblyLoader::loadFile(const String& filePath) { DisassemblyTable table(filePath); if (!table.isInitialized()) return DisassemblyTable::DefaultObject; //TODO: Error diff --git a/src/debugger/DisassemblyLoader.hpp b/src/debugger/DisassemblyLoader.hpp index 7a210d9..33de6f2 100644 --- a/src/debugger/DisassemblyLoader.hpp +++ b/src/debugger/DisassemblyLoader.hpp @@ -10,8 +10,8 @@ namespace dragon { public: inline DisassemblyTable(void) { m_initialized = false; } - inline DisassemblyTable(const ostd::String& filePath) { init(filePath); } - void init(const ostd::String& filePath); + inline DisassemblyTable(const String& filePath) { init(filePath); } + void init(const String& filePath); inline const std::vector& getCodeTable(void) const { return m_code; } inline const std::vector& getDataTable(void) const { return m_data; } @@ -27,7 +27,7 @@ namespace dragon std::vector m_labels; std::vector m_data; bool m_initialized { false }; - ostd::String m_filePath { "" }; + String m_filePath { "" }; public: static const DisassemblyTable DefaultObject; @@ -36,8 +36,8 @@ namespace dragon class DisassemblyLoader { public: - static void loadDirectory(const ostd::String& directoryPath); - static const DisassemblyTable& loadFile(const ostd::String& filePath); + static void loadDirectory(const String& directoryPath); + static const DisassemblyTable& loadFile(const String& filePath); static std::vector getCodeTable(void); static std::vector getDataTable(void); diff --git a/src/hardware/CPUExtensions.cpp b/src/hardware/CPUExtensions.cpp index 14f8d4c..78ac155 100644 --- a/src/hardware/CPUExtensions.cpp +++ b/src/hardware/CPUExtensions.cpp @@ -8,7 +8,7 @@ namespace dragon { namespace cpuext { - ostd::String ExtMov::getOpCodeString(uint8_t opCode) + String ExtMov::getOpCodeString(uint8_t opCode) { switch (opCode) { @@ -467,7 +467,7 @@ namespace dragon - ostd::String ExtAlu::getOpCodeString(uint8_t opCode) + String ExtAlu::getOpCodeString(uint8_t opCode) { switch (opCode) { diff --git a/src/hardware/CPUExtensions.hpp b/src/hardware/CPUExtensions.hpp index 2cc87b1..14db5c6 100644 --- a/src/hardware/CPUExtensions.hpp +++ b/src/hardware/CPUExtensions.hpp @@ -55,7 +55,7 @@ namespace dragon }; public: inline ExtMov(void) : data::CPUExtension(data::OpCodes::Ext01, "extmov") { } - ostd::String getOpCodeString(uint8_t opCode) override; + String getOpCodeString(uint8_t opCode) override; uint8_t getInstructionSIze(uint8_t opCode) override; bool execute(VirtualCPU& vcpu) override; }; @@ -94,7 +94,7 @@ namespace dragon }; public: inline ExtAlu(void) : data::CPUExtension(data::OpCodes::Ext02, "extalu") { } - ostd::String getOpCodeString(uint8_t opCode) override; + String getOpCodeString(uint8_t opCode) override; uint8_t getInstructionSIze(uint8_t opCode) override; bool execute(VirtualCPU& vcpu) override; }; diff --git a/src/hardware/MemoryMapper.cpp b/src/hardware/MemoryMapper.cpp index 7e18e1f..fbebb5a 100644 --- a/src/hardware/MemoryMapper.cpp +++ b/src/hardware/MemoryMapper.cpp @@ -43,12 +43,12 @@ namespace dragon return region->device->write16(finalAddr, value); } - void MemoryMapper::mapDevice(IMemoryDevice& device, uint16_t startAddr, uint16_t endAddr, bool remap, ostd::String name) + void MemoryMapper::mapDevice(IMemoryDevice& device, uint16_t startAddr, uint16_t endAddr, bool remap, String name) { m_regions.push_back({ &device, startAddr, endAddr, remap, name }); } - ostd::String MemoryMapper::getMemoryRegionName(uint16_t address) + String MemoryMapper::getMemoryRegionName(uint16_t address) { tMemoryRegion* region = findRegion(address); if (region == nullptr) return "Invalid"; @@ -67,7 +67,7 @@ namespace dragon if (address >= region.startAddress && address <= region.endAddress) return ®ion; } - data::ErrorHandler::pushError(data::ErrorCodes::MM_RegionNotFound, ostd::String("Memory device not found for address: ").add(ostd::String::getHexStr(address, true, 2))); + data::ErrorHandler::pushError(data::ErrorCodes::MM_RegionNotFound, String("Memory device not found for address: ").add(String::getHexStr(address, true, 2))); return nullptr; //TODO: Error } } diff --git a/src/hardware/MemoryMapper.hpp b/src/hardware/MemoryMapper.hpp index 9479cba..101f552 100644 --- a/src/hardware/MemoryMapper.hpp +++ b/src/hardware/MemoryMapper.hpp @@ -16,7 +16,7 @@ namespace dragon uint16_t startAddress { 0x0000 }; uint16_t endAddress { 0x0000 }; bool remap { false }; - ostd::String name { "" }; + String name { "" }; }; public: @@ -26,9 +26,9 @@ namespace dragon int8_t write8(uint16_t addr, int8_t value) override; int16_t write16(uint16_t addr, int16_t value) override; - void mapDevice(IMemoryDevice& device, uint16_t startAddr, uint16_t endAddr, bool remap = false, ostd::String name = ""); + void mapDevice(IMemoryDevice& device, uint16_t startAddr, uint16_t endAddr, bool remap = false, String name = ""); - ostd::String getMemoryRegionName(uint16_t address); + String getMemoryRegionName(uint16_t address); ostd::ByteStream* getByteStream(void) override; diff --git a/src/hardware/VirtualCPU.cpp b/src/hardware/VirtualCPU.cpp index 7f25830..5a112d4 100644 --- a/src/hardware/VirtualCPU.cpp +++ b/src/hardware/VirtualCPU.cpp @@ -258,7 +258,7 @@ namespace dragon tu = ostd::eTimeUnits::Nanoseconds; else if (static_cast(timeUnit) == eDebugProfilerTimeUnits::Secs) tu = ostd::eTimeUnits::Seconds; - m_profilerTimer.start(true, ostd::String("DebugProfiler [").add(ostd::String::getHexStr(id, true, 1)).add("]"), tu); + m_profilerTimer.start(true, String("DebugProfiler [").add(String::getHexStr(id, true, 1)).add("]"), tu); m_debugProfilerStarted = true; } break; @@ -888,14 +888,14 @@ namespace dragon case data::OpCodes::Ext15: case data::OpCodes::Ext16: { - data::ErrorHandler::pushError(data::ErrorCodes::CPU_UnsupportedExtension, ostd::String("Unsupported Extension: ").add(ostd::String::getHexStr(inst, true, 1))); + data::ErrorHandler::pushError(data::ErrorCodes::CPU_UnsupportedExtension, String("Unsupported Extension: ").add(String::getHexStr(inst, true, 1))); m_halt = true; return false; } break; default: { - data::ErrorHandler::pushError(data::ErrorCodes::CPU_UnknownInstruction, ostd::String("Unknown instruction: ").add(ostd::String::getHexStr(inst, true, 1))); + data::ErrorHandler::pushError(data::ErrorCodes::CPU_UnknownInstruction, String("Unknown instruction: ").add(String::getHexStr(inst, true, 1))); m_halt = true; return false; } @@ -907,7 +907,7 @@ namespace dragon void VirtualCPU::__debug_store_stack_frame_string_on_push(void) { if (!m_debugModeEnabled) return; - ostd::String stackFrameString = ""; + String stackFrameString = ""; uint16_t argStartAddr = readRegister(data::Registers::SP) + 2; uint16_t argCount = m_memory.read16(argStartAddr); @@ -916,44 +916,44 @@ namespace dragon else argStartAddr += (argCount * 2); - stackFrameString.add("args: ").add(ostd::String::getHexStr(argStartAddr, true, 2)).add(", argc: ").add(argCount).add("\n"); + stackFrameString.add("args: ").add(String::getHexStr(argStartAddr, true, 2)).add(", argc: ").add(argCount).add("\n"); pushToStack(readRegister(data::Registers::R1)); - stackFrameString.add("R1: ").add(ostd::String::getHexStr(readRegister(data::Registers::R1), true, 2)); + stackFrameString.add("R1: ").add(String::getHexStr(readRegister(data::Registers::R1), true, 2)); pushToStack(readRegister(data::Registers::R2)); - stackFrameString.add(" R2: ").add(ostd::String::getHexStr(readRegister(data::Registers::R2), true, 2)); + stackFrameString.add(" R2: ").add(String::getHexStr(readRegister(data::Registers::R2), true, 2)); pushToStack(readRegister(data::Registers::R3)); - stackFrameString.add(" R3: ").add(ostd::String::getHexStr(readRegister(data::Registers::R3), true, 2)); + stackFrameString.add(" R3: ").add(String::getHexStr(readRegister(data::Registers::R3), true, 2)); pushToStack(readRegister(data::Registers::R4)); - stackFrameString.add(" R4: ").add(ostd::String::getHexStr(readRegister(data::Registers::R4), true, 2)); + stackFrameString.add(" R4: ").add(String::getHexStr(readRegister(data::Registers::R4), true, 2)); pushToStack(readRegister(data::Registers::R5)); - stackFrameString.add(" R5: ").add(ostd::String::getHexStr(readRegister(data::Registers::R5), true, 2)); + stackFrameString.add(" R5: ").add(String::getHexStr(readRegister(data::Registers::R5), true, 2)); pushToStack(readRegister(data::Registers::R6)); - stackFrameString.add(" R6: ").add(ostd::String::getHexStr(readRegister(data::Registers::R6), true, 2)); + stackFrameString.add(" R6: ").add(String::getHexStr(readRegister(data::Registers::R6), true, 2)); pushToStack(readRegister(data::Registers::R7)); - stackFrameString.add(" R7: ").add(ostd::String::getHexStr(readRegister(data::Registers::R7), true, 2)); + stackFrameString.add(" R7: ").add(String::getHexStr(readRegister(data::Registers::R7), true, 2)); pushToStack(readRegister(data::Registers::R8)); - stackFrameString.add(" R8: ").add(ostd::String::getHexStr(readRegister(data::Registers::R8), true, 2)); + stackFrameString.add(" R8: ").add(String::getHexStr(readRegister(data::Registers::R8), true, 2)); pushToStack(readRegister(data::Registers::R9)); - stackFrameString.add(" R9: ").add(ostd::String::getHexStr(readRegister(data::Registers::R9), true, 2)); + stackFrameString.add(" R9: ").add(String::getHexStr(readRegister(data::Registers::R9), true, 2)); pushToStack(readRegister(data::Registers::R10)); - stackFrameString.add(" R10: ").add(ostd::String::getHexStr(readRegister(data::Registers::R10), true, 2)); + stackFrameString.add(" R10: ").add(String::getHexStr(readRegister(data::Registers::R10), true, 2)); stackFrameString.add("\n"); pushToStack(readRegister(data::Registers::PP)); - stackFrameString.add("PP: ").add(ostd::String::getHexStr(readRegister(data::Registers::PP), true, 2)); + stackFrameString.add("PP: ").add(String::getHexStr(readRegister(data::Registers::PP), true, 2)); pushToStack(readRegister(data::Registers::ACC)); - stackFrameString.add(" ACC: ").add(ostd::String::getHexStr(readRegister(data::Registers::ACC), true, 2)); + stackFrameString.add(" ACC: ").add(String::getHexStr(readRegister(data::Registers::ACC), true, 2)); pushToStack(readRegister(data::Registers::IP)); - stackFrameString.add(" IP: ").add(ostd::String::getHexStr(readRegister(data::Registers::IP), true, 2)); + stackFrameString.add(" IP: ").add(String::getHexStr(readRegister(data::Registers::IP), true, 2)); pushToStack(readRegister(data::Registers::FP)); - stackFrameString.add(" FP: ").add(ostd::String::getHexStr(readRegister(data::Registers::FP), true, 2)); + stackFrameString.add(" FP: ").add(String::getHexStr(readRegister(data::Registers::FP), true, 2)); stackFrameString.add("\n"); pushToStack(m_stackFrameSize); stackFrameString.add("StackFrame: ").add(m_stackFrameSize).add(", "); writeRegister16(data::Registers::PP, argStartAddr); writeRegister16(data::Registers::FP, readRegister(data::Registers::SP)); - stackFrameString.add("New FP: ").add(ostd::String::getHexStr(readRegister(data::Registers::FP), true, 2)); + stackFrameString.add("New FP: ").add(String::getHexStr(readRegister(data::Registers::FP), true, 2)); m_stackFrameSize = 0; m_debug_stackFrameStrings.push_back(stackFrameString); diff --git a/src/hardware/VirtualCPU.hpp b/src/hardware/VirtualCPU.hpp index 744332b..3b3431c 100644 --- a/src/hardware/VirtualCPU.hpp +++ b/src/hardware/VirtualCPU.hpp @@ -78,7 +78,7 @@ namespace dragon data::CPUExtension* m_currentExtension { nullptr }; uint8_t m_currentExtInst { 0x00 }; - std::vector m_debug_stackFrameStrings; + std::vector m_debug_stackFrameStrings; ostd::Counter m_profilerTimer; diff --git a/src/hardware/VirtualDisplay.cpp b/src/hardware/VirtualDisplay.cpp index 92672a3..b3d3acb 100644 --- a/src/hardware/VirtualDisplay.cpp +++ b/src/hardware/VirtualDisplay.cpp @@ -65,7 +65,7 @@ namespace dragon ostd::Color foreground = m_text16_Currentpalette->getColor(cell.foregroundColor); char character = static_cast(cell.character); auto xy = CONVERT_1D_2D(i, ogfx::PixelRenderer::TextRenderer::CONSOLE_CHARS_H); - ogfx::PixelRenderer::TextRenderer::drawString(ostd::String().addChar(character), xy.x, xy.y, m_renderer.getScreenPixels(), getWindowWidth(), getWindowHeight(), m_font.m_fontPixels, foreground, background); + ogfx::PixelRenderer::TextRenderer::drawString(String().addChar(character), xy.x, xy.y, m_renderer.getScreenPixels(), getWindowWidth(), getWindowHeight(), m_font.m_fontPixels, foreground, background); } m_refreshScreen = false; } @@ -225,11 +225,11 @@ namespace dragon uint8_t invert_colors = mem.read8(vga_addr + tRegisters::TextSingleInvertColors); if (m_singleTextLines.size() == 0) { - m_singleTextLines.push_back(ostd::String().addChar(c)); + m_singleTextLines.push_back(String().addChar(c)); if (invert_colors == 0) - ogfx::PixelRenderer::TextRenderer::drawString(ostd::String().addChar(c), 0, 0, m_renderer.getScreenPixels(), getWindowWidth(), getWindowHeight(), m_font.m_fontPixels, config.singleColor_foreground, config.singleColor_background); + ogfx::PixelRenderer::TextRenderer::drawString(String().addChar(c), 0, 0, m_renderer.getScreenPixels(), getWindowWidth(), getWindowHeight(), m_font.m_fontPixels, config.singleColor_foreground, config.singleColor_background); else - ogfx::PixelRenderer::TextRenderer::drawString(ostd::String().addChar(c), 0, 0, m_renderer.getScreenPixels(), getWindowWidth(), getWindowHeight(), m_font.m_fontPixels, config.singleColor_background, config.singleColor_foreground); + ogfx::PixelRenderer::TextRenderer::drawString(String().addChar(c), 0, 0, m_renderer.getScreenPixels(), getWindowWidth(), getWindowHeight(), m_font.m_fontPixels, config.singleColor_background, config.singleColor_foreground); return; } auto& line = m_singleTextLines[m_singleTextLines.size() - 1]; @@ -239,20 +239,20 @@ namespace dragon { if (line.len() == ogfx::PixelRenderer::TextRenderer::CONSOLE_CHARS_H) { - m_singleTextLines.push_back(ostd::String().addChar(c)); + m_singleTextLines.push_back(String().addChar(c)); auto& line = m_singleTextLines[m_singleTextLines.size() - 1]; if (invert_colors == 0) - ogfx::PixelRenderer::TextRenderer::drawString(ostd::String().addChar(c), line.len() - 1, m_singleTextLines.size() - 1, m_renderer.getScreenPixels(), getWindowWidth(), getWindowHeight(), m_font.m_fontPixels, config.singleColor_foreground, config.singleColor_background); + ogfx::PixelRenderer::TextRenderer::drawString(String().addChar(c), line.len() - 1, m_singleTextLines.size() - 1, m_renderer.getScreenPixels(), getWindowWidth(), getWindowHeight(), m_font.m_fontPixels, config.singleColor_foreground, config.singleColor_background); else - ogfx::PixelRenderer::TextRenderer::drawString(ostd::String().addChar(c), line.len() - 1, m_singleTextLines.size() - 1, m_renderer.getScreenPixels(), getWindowWidth(), getWindowHeight(), m_font.m_fontPixels, config.singleColor_background, config.singleColor_foreground); + ogfx::PixelRenderer::TextRenderer::drawString(String().addChar(c), line.len() - 1, m_singleTextLines.size() - 1, m_renderer.getScreenPixels(), getWindowWidth(), getWindowHeight(), m_font.m_fontPixels, config.singleColor_background, config.singleColor_foreground); } else { line.addChar(c); if (invert_colors == 0) - ogfx::PixelRenderer::TextRenderer::drawString(ostd::String().addChar(c), line.len() - 1, m_singleTextLines.size() - 1, m_renderer.getScreenPixels(), getWindowWidth(), getWindowHeight(), m_font.m_fontPixels, config.singleColor_foreground, config.singleColor_background); + ogfx::PixelRenderer::TextRenderer::drawString(String().addChar(c), line.len() - 1, m_singleTextLines.size() - 1, m_renderer.getScreenPixels(), getWindowWidth(), getWindowHeight(), m_font.m_fontPixels, config.singleColor_foreground, config.singleColor_background); else - ogfx::PixelRenderer::TextRenderer::drawString(ostd::String().addChar(c), line.len() - 1, m_singleTextLines.size() - 1, m_renderer.getScreenPixels(), getWindowWidth(), getWindowHeight(), m_font.m_fontPixels, config.singleColor_background, config.singleColor_foreground); + ogfx::PixelRenderer::TextRenderer::drawString(String().addChar(c), line.len() - 1, m_singleTextLines.size() - 1, m_renderer.getScreenPixels(), getWindowWidth(), getWindowHeight(), m_font.m_fontPixels, config.singleColor_background, config.singleColor_foreground); } } else return; diff --git a/src/hardware/VirtualDisplay.hpp b/src/hardware/VirtualDisplay.hpp index 5623410..74c1187 100644 --- a/src/hardware/VirtualDisplay.hpp +++ b/src/hardware/VirtualDisplay.hpp @@ -54,7 +54,7 @@ namespace dragon inline static constexpr uint8_t RedrawScreen = 0xE2; }; public: - inline void setFont(const ostd::String& fontPath) { m_font.init(fontPath); } + inline void setFont(const String& fontPath) { m_font.init(fontPath); } void onInitialize(void) override; void onDestroy(void) override; @@ -83,8 +83,8 @@ namespace dragon ogfx::PixelRenderer m_renderer; ogfx::PixelRenderer::Font m_font; - std::vector m_singleTextLines; - ostd::String m_singleTextBuffer { "" }; + std::vector m_singleTextLines; + String m_singleTextBuffer { "" }; std::vector m_text16_buffer; std::vector m_text16_palettes; diff --git a/src/hardware/VirtualHardDrive.cpp b/src/hardware/VirtualHardDrive.cpp index a264c32..801cd39 100644 --- a/src/hardware/VirtualHardDrive.cpp +++ b/src/hardware/VirtualHardDrive.cpp @@ -7,12 +7,12 @@ namespace dragon { namespace hw { - void VirtualHardDrive::init(const ostd::String& dataFilePath) + void VirtualHardDrive::init(const String& dataFilePath) { m_dataFile.open(dataFilePath.cpp_str(), std::ios::out | std::ios::in | std::ios::binary); if(!m_dataFile) { - data::ErrorHandler::pushError(data::ErrorCodes::HardDrive_UnableToMount, ostd::String("Unable to mount virtual HardDrive: ").add(dataFilePath)); + data::ErrorHandler::pushError(data::ErrorCodes::HardDrive_UnableToMount, String("Unable to mount virtual HardDrive: ").add(dataFilePath)); return; } m_fileSize = m_dataFile.tellg(); diff --git a/src/hardware/VirtualHardDrive.hpp b/src/hardware/VirtualHardDrive.hpp index 36aa9d8..dbc794e 100644 --- a/src/hardware/VirtualHardDrive.hpp +++ b/src/hardware/VirtualHardDrive.hpp @@ -11,8 +11,8 @@ namespace dragon { public: inline VirtualHardDrive(void) { m_initialized = false; } - inline VirtualHardDrive(const ostd::String& dataFilePath) { init(dataFilePath); } - void init(const ostd::String& dataFilePath); + inline VirtualHardDrive(const String& dataFilePath) { init(dataFilePath); } + void init(const String& dataFilePath); bool read(uint32_t addr, uint16_t size, ostd::ByteStream& outData); bool write(uint32_t addr, int8_t value); diff --git a/src/hardware/VirtualIODevices.cpp b/src/hardware/VirtualIODevices.cpp index 884d20c..426d8d6 100644 --- a/src/hardware/VirtualIODevices.cpp +++ b/src/hardware/VirtualIODevices.cpp @@ -17,40 +17,40 @@ namespace dragon { namespace hw { - void VirtualBIOS::init(const ostd::String& biosFilePath) + void VirtualBIOS::init(const String& biosFilePath) { bool loaded = ostd::Memory::loadByteStreamFromFile(biosFilePath, m_bios); if (!loaded) data::ErrorHandler::pushError(data::ErrorCodes::BIOS_FailedToLoad, "Failed to load BIOS data."); if (m_bios.size() != 4096) //TODO: Hardcoded - data::ErrorHandler::pushError(data::ErrorCodes::BIOS_InvalidSize, ostd::String("Invalid BIOS size: ").add(ostd::String::getHexStr(m_bios.size(), true, 2))); + data::ErrorHandler::pushError(data::ErrorCodes::BIOS_InvalidSize, String("Invalid BIOS size: ").add(String::getHexStr(m_bios.size(), true, 2))); m_initialized = true; } int8_t VirtualBIOS::read8(uint16_t addr) { if (addr >= m_bios.size()) - data::ErrorHandler::pushError(data::ErrorCodes::BIOS_InvalidAddress, ostd::String("Invalid Byte BIOS location at address: ").add(ostd::String::getHexStr(addr, true, 2))); + data::ErrorHandler::pushError(data::ErrorCodes::BIOS_InvalidAddress, String("Invalid Byte BIOS location at address: ").add(String::getHexStr(addr, true, 2))); return m_bios[addr]; } int16_t VirtualBIOS::read16(uint16_t addr) { if (addr >= m_bios.size() - 1) - data::ErrorHandler::pushError(data::ErrorCodes::BIOS_InvalidAddress, ostd::String("Invalid Word BIOS location at address: ").add(ostd::String::getHexStr(addr, true, 2))); + data::ErrorHandler::pushError(data::ErrorCodes::BIOS_InvalidAddress, String("Invalid Word BIOS location at address: ").add(String::getHexStr(addr, true, 2))); return ((m_bios[addr + 0] << 8) & 0xFF00U) | ( m_bios[addr + 1] & 0x00FFU); } int8_t VirtualBIOS::write8(uint16_t addr, int8_t value) { - data::ErrorHandler::pushError(data::ErrorCodes::BIOS_WriteAttempt, ostd::String("Attempting to write to BIOS memory map: ").add(ostd::String::getHexStr(addr, true, 2))); + data::ErrorHandler::pushError(data::ErrorCodes::BIOS_WriteAttempt, String("Attempting to write to BIOS memory map: ").add(String::getHexStr(addr, true, 2))); return 0x00; } int16_t VirtualBIOS::write16(uint16_t addr, int16_t value) { - data::ErrorHandler::pushError(data::ErrorCodes::BIOS_WriteAttempt, ostd::String("Attempting to write to BIOS memory map: ").add(ostd::String::getHexStr(addr, true, 2))); + data::ErrorHandler::pushError(data::ErrorCodes::BIOS_WriteAttempt, String("Attempting to write to BIOS memory map: ").add(String::getHexStr(addr, true, 2))); return 0x0000; } @@ -73,14 +73,14 @@ namespace dragon int8_t InterruptVector::read8(uint16_t addr) { if (addr >= m_data.size()) - data::ErrorHandler::pushError(data::ErrorCodes::IntVector_InvalidAddress, ostd::String("Invalid Byte IntVector location at address: ").add(ostd::String::getHexStr(addr, true, 2))); + data::ErrorHandler::pushError(data::ErrorCodes::IntVector_InvalidAddress, String("Invalid Byte IntVector location at address: ").add(String::getHexStr(addr, true, 2))); return m_data[addr]; } int16_t InterruptVector::read16(uint16_t addr) { if (addr >= m_data.size() - 1) - data::ErrorHandler::pushError(data::ErrorCodes::IntVector_InvalidAddress, ostd::String("Invalid Word IntVector location at address: ").add(ostd::String::getHexStr(addr, true, 2))); + data::ErrorHandler::pushError(data::ErrorCodes::IntVector_InvalidAddress, String("Invalid Word IntVector location at address: ").add(String::getHexStr(addr, true, 2))); return ((m_data[addr + 0] << 8) & 0xFF00U) | ( m_data[addr + 1] & 0x00FFU); } @@ -88,7 +88,7 @@ namespace dragon int8_t InterruptVector::write8(uint16_t addr, int8_t value) { if (addr >= m_data.size()) - data::ErrorHandler::pushError(data::ErrorCodes::IntVector_InvalidAddress, ostd::String("Invalid Word IntVector location at address: ").add(ostd::String::getHexStr(addr, true, 2))); + data::ErrorHandler::pushError(data::ErrorCodes::IntVector_InvalidAddress, String("Invalid Word IntVector location at address: ").add(String::getHexStr(addr, true, 2))); m_data[addr] = value; return value; } @@ -96,7 +96,7 @@ namespace dragon int16_t InterruptVector::write16(uint16_t addr, int16_t value) { if (addr >= m_data.size() - 1) - data::ErrorHandler::pushError(data::ErrorCodes::IntVector_InvalidAddress, ostd::String("Invalid Word IntVector location at address: ").add(ostd::String::getHexStr(addr, true, 2))); + data::ErrorHandler::pushError(data::ErrorCodes::IntVector_InvalidAddress, String("Invalid Word IntVector location at address: ").add(String::getHexStr(addr, true, 2))); m_data[addr + 0] = (value >> 8) & 0xFF; m_data[addr + 1] = value & 0xFF; return value; @@ -126,14 +126,14 @@ namespace dragon int8_t VirtualKeyboard::read8(uint16_t addr) { if (addr >= m_data.size()) - data::ErrorHandler::pushError(data::ErrorCodes::IntVector_InvalidAddress, ostd::String("Invalid Byte KeyboardController location at address: ").add(ostd::String::getHexStr(addr, true, 2))); + data::ErrorHandler::pushError(data::ErrorCodes::IntVector_InvalidAddress, String("Invalid Byte KeyboardController location at address: ").add(String::getHexStr(addr, true, 2))); return m_data[addr]; } int16_t VirtualKeyboard::read16(uint16_t addr) { if (addr >= m_data.size() - 1) - data::ErrorHandler::pushError(data::ErrorCodes::IntVector_InvalidAddress, ostd::String("Invalid Word KeyboardController location at address: ").add(ostd::String::getHexStr(addr, true, 2))); + data::ErrorHandler::pushError(data::ErrorCodes::IntVector_InvalidAddress, String("Invalid Word KeyboardController location at address: ").add(String::getHexStr(addr, true, 2))); return ((m_data[addr + 0] << 8) & 0xFF00U) | ( m_data[addr + 1] & 0x00FFU); } @@ -141,10 +141,10 @@ namespace dragon int8_t VirtualKeyboard::write8(uint16_t addr, int8_t value) { if (addr >= m_data.size()) - data::ErrorHandler::pushError(data::ErrorCodes::IntVector_InvalidAddress, ostd::String("Invalid Word KeyboardController location at address: ").add(ostd::String::getHexStr(addr, true, 2))); + data::ErrorHandler::pushError(data::ErrorCodes::IntVector_InvalidAddress, String("Invalid Word KeyboardController location at address: ").add(String::getHexStr(addr, true, 2))); if (!DragonRuntime::cpu.isInBIOSMOde()) { - data::ErrorHandler::pushError(data::ErrorCodes::AccessViolation_BiosModeRequired, ostd::String("Attempting to write byte to KeyboardController while not in BIOS mode. Address: ").add(ostd::String::getHexStr(addr, true, 2))); + data::ErrorHandler::pushError(data::ErrorCodes::AccessViolation_BiosModeRequired, String("Attempting to write byte to KeyboardController while not in BIOS mode. Address: ").add(String::getHexStr(addr, true, 2))); return 0; } return __write8(addr, value); @@ -153,10 +153,10 @@ namespace dragon int16_t VirtualKeyboard::write16(uint16_t addr, int16_t value) { if (addr >= m_data.size() - 1) - data::ErrorHandler::pushError(data::ErrorCodes::IntVector_InvalidAddress, ostd::String("Invalid Word KeyboardController location at address: ").add(ostd::String::getHexStr(addr, true, 2))); + data::ErrorHandler::pushError(data::ErrorCodes::IntVector_InvalidAddress, String("Invalid Word KeyboardController location at address: ").add(String::getHexStr(addr, true, 2))); if (!DragonRuntime::cpu.isInBIOSMOde()) { - data::ErrorHandler::pushError(data::ErrorCodes::AccessViolation_BiosModeRequired, ostd::String("Attempting to write word to KeyboardController while not in BIOS mode. Address: ").add(ostd::String::getHexStr(addr, true, 2))); + data::ErrorHandler::pushError(data::ErrorCodes::AccessViolation_BiosModeRequired, String("Attempting to write word to KeyboardController while not in BIOS mode. Address: ").add(String::getHexStr(addr, true, 2))); return 0; } return __write16(addr, value); @@ -398,14 +398,14 @@ namespace dragon int8_t VirtualBootloader::read8(uint16_t addr) { if (addr >= m_mbr.size()) - data::ErrorHandler::pushError(data::ErrorCodes::BIOS_InvalidAddress, ostd::String("Invalid Byte MBR location at address: ").add(ostd::String::getHexStr(addr, true, 2))); + data::ErrorHandler::pushError(data::ErrorCodes::BIOS_InvalidAddress, String("Invalid Byte MBR location at address: ").add(String::getHexStr(addr, true, 2))); return m_mbr[addr]; } int16_t VirtualBootloader::read16(uint16_t addr) { if (addr >= m_mbr.size() - 1) - data::ErrorHandler::pushError(data::ErrorCodes::BIOS_InvalidAddress, ostd::String("Invalid Word MBR location at address: ").add(ostd::String::getHexStr(addr, true, 2))); + data::ErrorHandler::pushError(data::ErrorCodes::BIOS_InvalidAddress, String("Invalid Word MBR location at address: ").add(String::getHexStr(addr, true, 2))); return ((m_mbr[addr + 0] << 8) & 0xFF00U) | ( m_mbr[addr + 1] & 0x00FFU); } @@ -413,7 +413,7 @@ namespace dragon int8_t VirtualBootloader::write8(uint16_t addr, int8_t value) { if (addr >= m_mbr.size()) - data::ErrorHandler::pushError(data::ErrorCodes::IntVector_InvalidAddress, ostd::String("Invalid Word IntVector location at address: ").add(ostd::String::getHexStr(addr, true, 2))); + data::ErrorHandler::pushError(data::ErrorCodes::IntVector_InvalidAddress, String("Invalid Word IntVector location at address: ").add(String::getHexStr(addr, true, 2))); m_mbr[addr] = value; return value; } @@ -421,7 +421,7 @@ namespace dragon int16_t VirtualBootloader::write16(uint16_t addr, int16_t value) { if (addr >= m_mbr.size() - 1) - data::ErrorHandler::pushError(data::ErrorCodes::IntVector_InvalidAddress, ostd::String("Invalid Word IntVector location at address: ").add(ostd::String::getHexStr(addr, true, 2))); + data::ErrorHandler::pushError(data::ErrorCodes::IntVector_InvalidAddress, String("Invalid Word IntVector location at address: ").add(String::getHexStr(addr, true, 2))); m_mbr[addr + 0] = (value >> 8) & 0xFF; m_mbr[addr + 1] = value & 0xFF; return value; @@ -857,7 +857,7 @@ namespace dragon - void CMOS::init(const ostd::String& cmosFilePath) + void CMOS::init(const String& cmosFilePath) { m_size = data::MemoryMapAddresses::CMOS_End - data::MemoryMapAddresses::CMOS_Start + 1; m_dataFile.open(cmosFilePath.cpp_str(), std::ios::out | std::ios::in | std::ios::binary); @@ -872,7 +872,7 @@ namespace dragon m_dataFile.seekg( 0, std::ios::beg ); if (m_fileSize != m_size) { - data::ErrorHandler::pushError(data::ErrorCodes::CMOS_InvalidSize, ostd::String("Invalid virtual CMOS chhip size: ").add(m_fileSize)); + data::ErrorHandler::pushError(data::ErrorCodes::CMOS_InvalidSize, String("Invalid virtual CMOS chhip size: ").add(m_fileSize)); return; } m_initialized = true; @@ -887,7 +887,7 @@ namespace dragon } if (addr >= m_size) { - data::ErrorHandler::pushError(data::ErrorCodes::CMOS_InvalidAddress, ostd::String("Invalid Byte CMOS location at address: ").add(ostd::String::getHexStr(addr, true, 2))); + data::ErrorHandler::pushError(data::ErrorCodes::CMOS_InvalidAddress, String("Invalid Byte CMOS location at address: ").add(String::getHexStr(addr, true, 2))); return false; } int8_t value = 0; @@ -905,7 +905,7 @@ namespace dragon } if (addr >= m_size - 1) { - data::ErrorHandler::pushError(data::ErrorCodes::CMOS_InvalidAddress, ostd::String("Invalid Word CMOS location at address: ").add(ostd::String::getHexStr(addr, true, 2))); + data::ErrorHandler::pushError(data::ErrorCodes::CMOS_InvalidAddress, String("Invalid Word CMOS location at address: ").add(String::getHexStr(addr, true, 2))); return 0; } int8_t b1 = read8(addr); @@ -923,12 +923,12 @@ namespace dragon } if (addr >= m_size) { - data::ErrorHandler::pushError(data::ErrorCodes::CMOS_InvalidAddress, ostd::String("Invalid Byte CMOS location at address: ").add(ostd::String::getHexStr(addr, true, 2))); + data::ErrorHandler::pushError(data::ErrorCodes::CMOS_InvalidAddress, String("Invalid Byte CMOS location at address: ").add(String::getHexStr(addr, true, 2))); return 0; } if (!DragonRuntime::cpu.isInBIOSMOde()) { - data::ErrorHandler::pushError(data::ErrorCodes::AccessViolation_BiosModeRequired, ostd::String("Attempting to write byte to CMOS while not in BIOS mode. Address: ").add(ostd::String::getHexStr(addr, true, 2))); + data::ErrorHandler::pushError(data::ErrorCodes::AccessViolation_BiosModeRequired, String("Attempting to write byte to CMOS while not in BIOS mode. Address: ").add(String::getHexStr(addr, true, 2))); return 0; } m_dataFile.seekp(addr); @@ -945,12 +945,12 @@ namespace dragon } if (addr >= m_size - 1) { - data::ErrorHandler::pushError(data::ErrorCodes::CMOS_InvalidAddress, ostd::String("Invalid Word CMOS location at address: ").add(ostd::String::getHexStr(addr, true, 2))); + data::ErrorHandler::pushError(data::ErrorCodes::CMOS_InvalidAddress, String("Invalid Word CMOS location at address: ").add(String::getHexStr(addr, true, 2))); return 0; } if (!DragonRuntime::cpu.isInBIOSMOde()) { - data::ErrorHandler::pushError(data::ErrorCodes::AccessViolation_BiosModeRequired, ostd::String("Attempting to write word to CMOS while not in BIOS mode. Address: ").add(ostd::String::getHexStr(addr, true, 2))); + data::ErrorHandler::pushError(data::ErrorCodes::AccessViolation_BiosModeRequired, String("Attempting to write word to CMOS while not in BIOS mode. Address: ").add(String::getHexStr(addr, true, 2))); return 0; } int8_t b1 = (value >> 8) & 0xFF; diff --git a/src/hardware/VirtualIODevices.hpp b/src/hardware/VirtualIODevices.hpp index b06162d..4b1a0c4 100644 --- a/src/hardware/VirtualIODevices.hpp +++ b/src/hardware/VirtualIODevices.hpp @@ -19,8 +19,8 @@ namespace dragon { public: inline VirtualBIOS(void) { m_initialized = 0; } - inline VirtualBIOS(const ostd::String& biosFilePath) { init(biosFilePath); } - void init(const ostd::String& biosFilePath); + inline VirtualBIOS(const String& biosFilePath) { init(biosFilePath); } + void init(const String& biosFilePath); int8_t read8(uint16_t addr) override; int16_t read16(uint16_t addr) override; int8_t write8(uint16_t addr, int8_t value) override; @@ -412,8 +412,8 @@ namespace dragon { public: inline CMOS(void) { m_initialized = false; } - inline CMOS(const ostd::String& cmosFilePath) { init(cmosFilePath); } - void init(const ostd::String& cmosFilePath); + inline CMOS(const String& cmosFilePath) { init(cmosFilePath); } + void init(const String& cmosFilePath); int8_t read8(uint16_t addr) override; int16_t read16(uint16_t addr) override; int8_t write8(uint16_t addr, int8_t value) override; diff --git a/src/runtime/ConfigLoader.cpp b/src/runtime/ConfigLoader.cpp index 31b52ec..3e91c6f 100644 --- a/src/runtime/ConfigLoader.cpp +++ b/src/runtime/ConfigLoader.cpp @@ -4,7 +4,7 @@ namespace dragon { - const tMachineConfig MachineConfigLoader::loadConfig(const ostd::String& configFilePath) + const tMachineConfig MachineConfigLoader::loadConfig(const String& configFilePath) { tMachineConfig config; ostd::TextFileBuffer file(configFilePath.cpp_str()); @@ -12,7 +12,7 @@ namespace dragon auto lines = file.getLines(); for (auto& line : lines) { - ostd::String lineEdit = line; + String lineEdit = line; if (!lineEdit.contains("=")) continue; //TODO: Warning auto tokens = lineEdit.tokenize("="); if (tokens.count() != 2) continue; //TODO: Warning diff --git a/src/runtime/ConfigLoader.hpp b/src/runtime/ConfigLoader.hpp index 0f36a84..fff1bc2 100644 --- a/src/runtime/ConfigLoader.hpp +++ b/src/runtime/ConfigLoader.hpp @@ -8,13 +8,13 @@ namespace dragon { struct tMachineConfig { - std::map vdisk_paths; + std::map vdisk_paths; std::map cpuext_list; int32_t clock_rate_sec { 500 }; uint8_t memory_extension_pages { 0 }; bool fixed_clock { true }; - ostd::String bios_path; - ostd::String cmos_path; + String bios_path; + String cmos_path; ostd::Color singleColor_background; ostd::Color singleColor_foreground; uint8_t text16_palette { 0 }; @@ -32,7 +32,7 @@ namespace dragon class MachineConfigLoader { public: - static const tMachineConfig loadConfig(const ostd::String& configFilePath); + static const tMachineConfig loadConfig(const String& configFilePath); private: static const tMachineConfig& validate_machine_config(tMachineConfig& config); diff --git a/src/runtime/DragonRuntime.cpp b/src/runtime/DragonRuntime.cpp index 56bc912..ca87966 100644 --- a/src/runtime/DragonRuntime.cpp +++ b/src/runtime/DragonRuntime.cpp @@ -27,39 +27,39 @@ namespace dragon void DragonRuntime::printRegisters(dragon::hw::VirtualCPU& cpu) { - out.fg("green").p("IP: ").fg("white").p(ostd::String::getHexStr(cpu.readRegister(dragon::data::Registers::IP), true, 2).cpp_str()); + out.fg("green").p("IP: ").fg("white").p(String::getHexStr(cpu.readRegister(dragon::data::Registers::IP), true, 2).cpp_str()); out.p(" "); - out.fg("yellow").p("R1: ").fg("white").p(ostd::String::getHexStr(cpu.readRegister(dragon::data::Registers::R1), true, 2).cpp_str()); + out.fg("yellow").p("R1: ").fg("white").p(String::getHexStr(cpu.readRegister(dragon::data::Registers::R1), true, 2).cpp_str()); out.p(" "); - out.fg("yellow").p("R2: ").fg("white").p(ostd::String::getHexStr(cpu.readRegister(dragon::data::Registers::R2), true, 2).cpp_str()).nl(); + out.fg("yellow").p("R2: ").fg("white").p(String::getHexStr(cpu.readRegister(dragon::data::Registers::R2), true, 2).cpp_str()).nl(); - out.fg("green").p("SP: ").fg("white").p(ostd::String::getHexStr(cpu.readRegister(dragon::data::Registers::SP), true, 2).cpp_str()); + out.fg("green").p("SP: ").fg("white").p(String::getHexStr(cpu.readRegister(dragon::data::Registers::SP), true, 2).cpp_str()); out.p(" "); - out.fg("yellow").p("R3: ").fg("white").p(ostd::String::getHexStr(cpu.readRegister(dragon::data::Registers::R3), true, 2).cpp_str()); + out.fg("yellow").p("R3: ").fg("white").p(String::getHexStr(cpu.readRegister(dragon::data::Registers::R3), true, 2).cpp_str()); out.p(" "); - out.fg("yellow").p("R4: ").fg("white").p(ostd::String::getHexStr(cpu.readRegister(dragon::data::Registers::R4), true, 2).cpp_str()).nl(); + out.fg("yellow").p("R4: ").fg("white").p(String::getHexStr(cpu.readRegister(dragon::data::Registers::R4), true, 2).cpp_str()).nl(); - out.fg("green").p("FP: ").fg("white").p(ostd::String::getHexStr(cpu.readRegister(dragon::data::Registers::FP), true, 2).cpp_str()); + out.fg("green").p("FP: ").fg("white").p(String::getHexStr(cpu.readRegister(dragon::data::Registers::FP), true, 2).cpp_str()); out.p(" "); - out.fg("yellow").p("R5: ").fg("white").p(ostd::String::getHexStr(cpu.readRegister(dragon::data::Registers::R5), true, 2).cpp_str()); + out.fg("yellow").p("R5: ").fg("white").p(String::getHexStr(cpu.readRegister(dragon::data::Registers::R5), true, 2).cpp_str()); out.p(" "); - out.fg("yellow").p("R6: ").fg("white").p(ostd::String::getHexStr(cpu.readRegister(dragon::data::Registers::R6), true, 2).cpp_str()).nl(); + out.fg("yellow").p("R6: ").fg("white").p(String::getHexStr(cpu.readRegister(dragon::data::Registers::R6), true, 2).cpp_str()).nl(); - out.fg("green").p("RV: ").fg("white").p(ostd::String::getHexStr(cpu.readRegister(dragon::data::Registers::RV), true, 2).cpp_str()); + out.fg("green").p("RV: ").fg("white").p(String::getHexStr(cpu.readRegister(dragon::data::Registers::RV), true, 2).cpp_str()); out.p(" "); - out.fg("yellow").p("R7: ").fg("white").p(ostd::String::getHexStr(cpu.readRegister(dragon::data::Registers::R7), true, 2).cpp_str()); + out.fg("yellow").p("R7: ").fg("white").p(String::getHexStr(cpu.readRegister(dragon::data::Registers::R7), true, 2).cpp_str()); out.p(" "); - out.fg("yellow").p("R8: ").fg("white").p(ostd::String::getHexStr(cpu.readRegister(dragon::data::Registers::R8), true, 2).cpp_str()).nl(); + out.fg("yellow").p("R8: ").fg("white").p(String::getHexStr(cpu.readRegister(dragon::data::Registers::R8), true, 2).cpp_str()).nl(); - out.fg("green").p("PP: ").fg("white").p(ostd::String::getHexStr(cpu.readRegister(dragon::data::Registers::PP), true, 2).cpp_str()); + out.fg("green").p("PP: ").fg("white").p(String::getHexStr(cpu.readRegister(dragon::data::Registers::PP), true, 2).cpp_str()); out.p(" "); - out.fg("yellow").p("R9: ").fg("white").p(ostd::String::getHexStr(cpu.readRegister(dragon::data::Registers::R9), true, 2).cpp_str()); + out.fg("yellow").p("R9: ").fg("white").p(String::getHexStr(cpu.readRegister(dragon::data::Registers::R9), true, 2).cpp_str()); out.p(" "); - out.fg("yellow").p("R10: ").fg("white").p(ostd::String::getHexStr(cpu.readRegister(dragon::data::Registers::R10), true, 2).cpp_str()).nl(); + out.fg("yellow").p("R10: ").fg("white").p(String::getHexStr(cpu.readRegister(dragon::data::Registers::R10), true, 2).cpp_str()).nl(); - out.fg("green").p("ACC: ").fg("white").p(ostd::String::getHexStr(cpu.readRegister(dragon::data::Registers::ACC), true, 2).cpp_str()); + out.fg("green").p("ACC: ").fg("white").p(String::getHexStr(cpu.readRegister(dragon::data::Registers::ACC), true, 2).cpp_str()); out.p(" "); - out.fg("yellow").p("FL: ").fg("white").p(ostd::String::getBinStr(cpu.readRegister(dragon::data::Registers::FL), true, 2).cpp_str()); + out.fg("yellow").p("FL: ").fg("white").p(String::getBinStr(cpu.readRegister(dragon::data::Registers::FL), true, 2).cpp_str()); } void DragonRuntime::processErrors(void) @@ -67,7 +67,7 @@ namespace dragon while (dragon::data::ErrorHandler::hasError()) { auto err = dragon::data::ErrorHandler::popError(); - out.nl().fg(ostd::ConsoleColors::Red).p("Error ").p(ostd::String::getHexStr(err.code, true, 8).cpp_str()).p(": ").p(err.text.cpp_str()).nl(); + out.nl().fg(ostd::ConsoleColors::Red).p("Error ").p(String::getHexStr(err.code, true, 8).cpp_str()).p(": ").p(err.text.cpp_str()).nl(); } } @@ -102,7 +102,7 @@ namespace dragon } for (int32_t i = 2; i < argc; i++) { - ostd::String edit(argv[i]); + String edit(argv[i]); if (edit == "--verbose-load") args.verbose_load = true; else if (edit == "--force-load") @@ -128,188 +128,183 @@ namespace dragon return RETURN_VAL_EXIT_SUCCESS; } - int32_t DragonRuntime::initMachine(const ostd::String& configFilePath, - bool verbose, - bool trackMachineInfoDiff, - bool hideVirtualDisplay, - bool trackCallStack, - bool debugModeEnabled) + int32_t DragonRuntime::initMachine(const tRuntimeInitInfo& info) { s_signalListener.init(); vKeyboard.init(); - if (verbose) - out.fg(ostd::ConsoleColors::Magenta).p("Loading machine config: ").fg(ostd::ConsoleColors::BrightYellow).p(configFilePath.cpp_str()).nl(); - machine_config = dragon::MachineConfigLoader::loadConfig(configFilePath); + if (info.verboseLoad) + out.fg(ostd::ConsoleColors::Magenta).p("Loading machine config: ").fg(ostd::ConsoleColors::BrightYellow).p(info.configFilePath.cpp_str()).nl(); + machine_config = dragon::MachineConfigLoader::loadConfig(info.configFilePath); if (!machine_config.isValid()) return RETURN_VAL_INVALID_MACHINE_CONFIG; //TODO: Error - if (verbose) + if (info.verboseLoad) out.fg(ostd::ConsoleColors::Magenta).p(" Initializing virtual display:").nl(); int32_t w = ogfx::PixelRenderer::TextRenderer::CONSOLE_CHARS_H * ogfx::PixelRenderer::TextRenderer::FONT_CHAR_W; //60 * 16; int32_t h = ogfx::PixelRenderer::TextRenderer::CONSOLE_CHARS_V * ogfx::PixelRenderer::TextRenderer::FONT_CHAR_H; //60 * 9; vDisplay.initialize(w, h, "DragonVM"); vDisplay.setFont("font.bmp"); - if (hideVirtualDisplay) + if (info.hideVirtualDisplay) vDisplay.hide(); - if (verbose) + if (info.verboseLoad) { out.fg(ostd::ConsoleColors::BrightYellow); out.p(" Done. (").p(w).p("x").p(h).p(")"); - if (hideVirtualDisplay) + if (info.hideVirtualDisplay) out.p(" - HIDDEN").nl(); else out.nl(); } if (machine_config.vdisk_paths.size() == 0) return RETURN_VAL_NO_DISK; //TODO: Error - if (verbose) + if (info.verboseLoad) out.fg(ostd::ConsoleColors::Magenta).p(" Initializing virtual disks:").nl(); for (auto const& disk_path : machine_config.vdisk_paths) { vDisks[disk_path.first] = dragon::hw::VirtualHardDrive(disk_path.second); vDiskInterface.connectDisk(vDisks[disk_path.first], disk_path.first); - if (verbose) + if (info.verboseLoad) out.fg(ostd::ConsoleColors::BrightYellow).p(" Disk").p(disk_path.first).p(" connected: ").p(disk_path.second.cpp_str()).nl(); } - if (verbose) + if (info.verboseLoad) out.fg(ostd::ConsoleColors::Magenta).p(" Loading vBIOS file: ").fg(ostd::ConsoleColors::BrightYellow).p(machine_config.bios_path.cpp_str()).nl(); vBIOS.init(machine_config.bios_path); - if (verbose) + if (info.verboseLoad) out.fg(ostd::ConsoleColors::Magenta).p(" Loading vCMOS file: ").fg(ostd::ConsoleColors::BrightYellow).p(machine_config.cmos_path.cpp_str()).nl(); vCMOS.init(machine_config.cmos_path); - if (verbose) + if (info.verboseLoad) { out.fg(ostd::ConsoleColors::Magenta).p(" Initializing Memory Mapper:").nl(); out.fg(ostd::ConsoleColors::Magenta).p(" vBIOS: "); out.fg(ostd::ConsoleColors::BrightYellow); - out.p(ostd::String::getHexStr(dragon::data::MemoryMapAddresses::BIOS_Start, true, 2).cpp_str()); + out.p(String::getHexStr(dragon::data::MemoryMapAddresses::BIOS_Start, true, 2).cpp_str()); out.p(" to "); - out.p(ostd::String::getHexStr(dragon::data::MemoryMapAddresses::BIOS_End, true, 2).cpp_str()); + out.p(String::getHexStr(dragon::data::MemoryMapAddresses::BIOS_End, true, 2).cpp_str()); out.p(" (remap=false)").nl(); } memMap.mapDevice(vBIOS, dragon::data::MemoryMapAddresses::BIOS_Start, dragon::data::MemoryMapAddresses::BIOS_End, false, "BIOS"); - if (verbose) + if (info.verboseLoad) { out.fg(ostd::ConsoleColors::Magenta).p(" vCMOS: "); out.fg(ostd::ConsoleColors::BrightYellow); - out.p(ostd::String::getHexStr(dragon::data::MemoryMapAddresses::CMOS_Start, true, 2).cpp_str()); + out.p(String::getHexStr(dragon::data::MemoryMapAddresses::CMOS_Start, true, 2).cpp_str()); out.p(" to "); - out.p(ostd::String::getHexStr(dragon::data::MemoryMapAddresses::CMOS_End, true, 2).cpp_str()); + out.p(String::getHexStr(dragon::data::MemoryMapAddresses::CMOS_End, true, 2).cpp_str()); out.p(" (remap=true)").nl(); } memMap.mapDevice(vCMOS, dragon::data::MemoryMapAddresses::CMOS_Start, dragon::data::MemoryMapAddresses::CMOS_End, true, "CMOS"); - if (verbose) + if (info.verboseLoad) { out.fg(ostd::ConsoleColors::Magenta).p(" intVec: "); out.fg(ostd::ConsoleColors::BrightYellow); - out.p(ostd::String::getHexStr(dragon::data::MemoryMapAddresses::IntVector_Start, true, 2).cpp_str()); + out.p(String::getHexStr(dragon::data::MemoryMapAddresses::IntVector_Start, true, 2).cpp_str()); out.p(" to "); - out.p(ostd::String::getHexStr(dragon::data::MemoryMapAddresses::IntVector_End, true, 2).cpp_str()); + out.p(String::getHexStr(dragon::data::MemoryMapAddresses::IntVector_End, true, 2).cpp_str()); out.p(" (remap=true)").nl(); } memMap.mapDevice(intVec, dragon::data::MemoryMapAddresses::IntVector_Start, dragon::data::MemoryMapAddresses::IntVector_End, true, "intVec"); - if (verbose) + if (info.verboseLoad) { out.fg(ostd::ConsoleColors::Magenta).p(" vKeyboard: "); out.fg(ostd::ConsoleColors::BrightYellow); - out.p(ostd::String::getHexStr(dragon::data::MemoryMapAddresses::Keyboard_Start, true, 2).cpp_str()); + out.p(String::getHexStr(dragon::data::MemoryMapAddresses::Keyboard_Start, true, 2).cpp_str()); out.p(" to "); - out.p(ostd::String::getHexStr(dragon::data::MemoryMapAddresses::Keyboard_End, true, 2).cpp_str()); + out.p(String::getHexStr(dragon::data::MemoryMapAddresses::Keyboard_End, true, 2).cpp_str()); out.p(" (remap=false)").nl(); } memMap.mapDevice(vKeyboard, dragon::data::MemoryMapAddresses::Keyboard_Start, dragon::data::MemoryMapAddresses::Keyboard_End, true, "Keyb."); - if (verbose) + if (info.verboseLoad) { out.fg(ostd::ConsoleColors::Magenta).p(" vMouse: "); out.fg(ostd::ConsoleColors::BrightYellow); - out.p(ostd::String::getHexStr(dragon::data::MemoryMapAddresses::Mouse_Start, true, 2).cpp_str()); + out.p(String::getHexStr(dragon::data::MemoryMapAddresses::Mouse_Start, true, 2).cpp_str()); out.p(" to "); - out.p(ostd::String::getHexStr(dragon::data::MemoryMapAddresses::Mouse_End, true, 2).cpp_str()); + out.p(String::getHexStr(dragon::data::MemoryMapAddresses::Mouse_End, true, 2).cpp_str()); out.p(" (remap=false)").nl(); } memMap.mapDevice(vMouse, dragon::data::MemoryMapAddresses::Mouse_Start, dragon::data::MemoryMapAddresses::Mouse_End, false, "Mouse"); - if (verbose) + if (info.verboseLoad) { out.fg(ostd::ConsoleColors::Magenta).p(" vMBR: "); out.fg(ostd::ConsoleColors::BrightYellow); - out.p(ostd::String::getHexStr(dragon::data::MemoryMapAddresses::MBR_Start, true, 2).cpp_str()); + out.p(String::getHexStr(dragon::data::MemoryMapAddresses::MBR_Start, true, 2).cpp_str()); out.p(" to "); - out.p(ostd::String::getHexStr(dragon::data::MemoryMapAddresses::MBR_End, true, 2).cpp_str()); + out.p(String::getHexStr(dragon::data::MemoryMapAddresses::MBR_End, true, 2).cpp_str()); out.p(" (remap=true)").nl(); } memMap.mapDevice(vMBR, dragon::data::MemoryMapAddresses::MBR_Start, dragon::data::MemoryMapAddresses::MBR_End, true, "MBR"); - if (verbose) + if (info.verboseLoad) { out.fg(ostd::ConsoleColors::Magenta).p(" vDiskInterface: "); out.fg(ostd::ConsoleColors::BrightYellow); - out.p(ostd::String::getHexStr(dragon::data::MemoryMapAddresses::DiskInterface_Start, true, 2).cpp_str()); + out.p(String::getHexStr(dragon::data::MemoryMapAddresses::DiskInterface_Start, true, 2).cpp_str()); out.p(" to "); - out.p(ostd::String::getHexStr(dragon::data::MemoryMapAddresses::DiskInterface_End, true, 2).cpp_str()); + out.p(String::getHexStr(dragon::data::MemoryMapAddresses::DiskInterface_End, true, 2).cpp_str()); out.p(" (remap=true)").nl(); } memMap.mapDevice(vDiskInterface, dragon::data::MemoryMapAddresses::DiskInterface_Start, dragon::data::MemoryMapAddresses::DiskInterface_End, true, "Disk"); - if (verbose) + if (info.verboseLoad) { out.fg(ostd::ConsoleColors::Magenta).p(" vGraphicsInterface: "); out.fg(ostd::ConsoleColors::BrightYellow); - out.p(ostd::String::getHexStr(dragon::data::MemoryMapAddresses::VideoCardInterface_Start, true, 2).cpp_str()); + out.p(String::getHexStr(dragon::data::MemoryMapAddresses::VideoCardInterface_Start, true, 2).cpp_str()); out.p(" to "); - out.p(ostd::String::getHexStr(dragon::data::MemoryMapAddresses::VideoCardInterface_End, true, 2).cpp_str()); + out.p(String::getHexStr(dragon::data::MemoryMapAddresses::VideoCardInterface_End, true, 2).cpp_str()); out.p(" (remap=true)").nl(); } memMap.mapDevice(vGraphicsInterface, dragon::data::MemoryMapAddresses::VideoCardInterface_Start, dragon::data::MemoryMapAddresses::VideoCardInterface_End, true, "VGA"); - if (verbose) + if (info.verboseLoad) { out.fg(ostd::ConsoleColors::Magenta).p(" vSerialInterface: "); out.fg(ostd::ConsoleColors::BrightYellow); - out.p(ostd::String::getHexStr(dragon::data::MemoryMapAddresses::SerialInterface_Start, true, 2).cpp_str()); + out.p(String::getHexStr(dragon::data::MemoryMapAddresses::SerialInterface_Start, true, 2).cpp_str()); out.p(" to "); - out.p(ostd::String::getHexStr(dragon::data::MemoryMapAddresses::SerialInterface_End, true, 2).cpp_str()); + out.p(String::getHexStr(dragon::data::MemoryMapAddresses::SerialInterface_End, true, 2).cpp_str()); out.p(" (remap=true)").nl(); } memMap.mapDevice(vSerialInterface, dragon::data::MemoryMapAddresses::SerialInterface_Start, dragon::data::MemoryMapAddresses::SerialInterface_End, true, "serial"); - if (verbose) + if (info.verboseLoad) { out.fg(ostd::ConsoleColors::Magenta).p(" RAM: "); out.fg(ostd::ConsoleColors::BrightYellow); - out.p(ostd::String::getHexStr(dragon::data::MemoryMapAddresses::Memory_Start, true, 2).cpp_str()); + out.p(String::getHexStr(dragon::data::MemoryMapAddresses::Memory_Start, true, 2).cpp_str()); out.p(" to "); - out.p(ostd::String::getHexStr(dragon::data::MemoryMapAddresses::Memory_End, true, 2).cpp_str()); + out.p(String::getHexStr(dragon::data::MemoryMapAddresses::Memory_End, true, 2).cpp_str()); out.p(" (remap=false)").nl(); } memMap.mapDevice(ram, dragon::data::MemoryMapAddresses::Memory_Start, dragon::data::MemoryMapAddresses::Memory_End, false, "RAM"); - if (verbose) + if (info.verboseLoad) out.fg(ostd::ConsoleColors::Magenta).p(" Initializing vCPU reset sequence:").nl(); uint16_t reset_ip_addr = 0x0000; - if (verbose) - out.fg(ostd::ConsoleColors::BrightYellow).p(" Reset IP register: ").p(ostd::String::getHexStr(reset_ip_addr, true, 2).cpp_str()).nl(); + if (info.verboseLoad) + out.fg(ostd::ConsoleColors::BrightYellow).p(" Reset IP register: ").p(String::getHexStr(reset_ip_addr, true, 2).cpp_str()).nl(); cpu.writeRegister16(dragon::data::Registers::IP, reset_ip_addr); - if (verbose) - out.fg(ostd::ConsoleColors::BrightYellow).p(" Debug mode enabled: ").p(STR_BOOL(debugModeEnabled)).nl(); - cpu.m_debugModeEnabled = debugModeEnabled; + if (info.verboseLoad) + out.fg(ostd::ConsoleColors::BrightYellow).p(" Debug mode enabled: ").p(STR_BOOL(info.debugModeEnabled)).nl(); + cpu.m_debugModeEnabled = info.debugModeEnabled; - if (verbose) + if (info.verboseLoad) out.fg(ostd::ConsoleColors::BrightYellow).p(" BIOS mode enabled").nl(); cpu.m_biosMode = true; if (machine_config.cpuext_list.size() > 0) { - if (verbose) + if (info.verboseLoad) out.fg(ostd::ConsoleColors::BrightYellow).p(" Loading CPU Extensions").nl(); for (auto& ext : machine_config.cpuext_list) { cpu.m_extensions[ext.first] = ext.second; - if (verbose) + if (info.verboseLoad) out.fg(ostd::ConsoleColors::BrightYellow).p(" ").p(ext.first + 1).p(": ").p(ext.second->m_name).nl(); } } - if (verbose) + if (info.verboseLoad) { out.fg(ostd::ConsoleColors::BrightYellow).p(" Fixed clock enabled: ").p(STR_BOOL(machine_config.fixed_clock)).nl(); if (machine_config.fixed_clock) @@ -332,15 +327,15 @@ namespace dragon ostd::Bits::set(disk_list_bitfield, i); } vCMOS.write16(data::CMOSRegisters::DiskList, disk_list_bitfield.value); - if (verbose) + if (info.verboseLoad) out.fg(ostd::ConsoleColors::BrightYellow).p(" Loading CMOS Machine info").nl(); out.nl().nl(); - s_trackMachineInfo = trackMachineInfoDiff; - s_trackCallStack = trackCallStack; + s_trackMachineInfo = info.trackMachineInfoDiff; + s_trackCallStack = info.trackCallStack; return RETURN_VAL_EXIT_SUCCESS; } @@ -423,7 +418,7 @@ namespace dragon return running || vDiskInterface.isBusy(); } - void DragonRuntime::forceLoad(const ostd::String& filePath, uint16_t loadAddress) + void DragonRuntime::forceLoad(const String& filePath, uint16_t loadAddress) { ostd::ByteStream code; ostd::Memory::loadByteStreamFromFile(filePath, code); @@ -467,7 +462,7 @@ namespace dragon uint16_t instAddr = cpu.readRegister(data::Registers::IP); uint8_t int_op_code = memMap.read8(instAddr); uint8_t instSize = data::OpCodes::getInstructionSIze(int_op_code); - ostd::String opCode = data::OpCodes::getOpCodeString(int_op_code); + String opCode = data::OpCodes::getOpCodeString(int_op_code); uint16_t stackFrameSize = cpu.m_stackFrameSize; int32_t subRoutineCounter = cpu.m_subroutineCounter; @@ -566,7 +561,7 @@ namespace dragon int32_t commandLength = 46; out.nl().fg(ostd::ConsoleColors::Yellow).p("List of available parameters:").reset().nl(); - ostd::String tmpCommand = "--verbose-load"; + String tmpCommand = "--verbose-load"; tmpCommand.addRightPadding(commandLength); out.fg(ostd::ConsoleColors::Blue).p(tmpCommand).fg(ostd::ConsoleColors::Green).p("Used to show more information while loading the virtual machine.").reset().nl(); tmpCommand = "--force-load "; diff --git a/src/runtime/DragonRuntime.hpp b/src/runtime/DragonRuntime.hpp index 90266aa..5a83d04 100644 --- a/src/runtime/DragonRuntime.hpp +++ b/src/runtime/DragonRuntime.hpp @@ -28,20 +28,29 @@ namespace dragon public: struct tCallInfo : public ostd::BaseObject { inline tCallInfo(void) { } - inline tCallInfo(const ostd::String& _info, uint16_t _addr, uint16_t _inst_addr, bool ints_disabled) : info(_info), addr(_addr), inst_addr(_inst_addr), interrupts_disabled(ints_disabled) { } - ostd::String info; + inline tCallInfo(const String& _info, uint16_t _addr, uint16_t _inst_addr, bool ints_disabled) : info(_info), addr(_addr), inst_addr(_inst_addr), interrupts_disabled(ints_disabled) { } + String info; uint16_t addr; uint16_t inst_addr; bool interrupts_disabled; }; public: struct tCommandLineArgs { - ostd::String machine_config_path = ""; + String machine_config_path = ""; bool verbose_load = false; bool force_load = false; - ostd::String force_load_file = ""; + String force_load_file = ""; uint16_t force_load_mem_offset = 0x00; }; + public: struct tRuntimeInitInfo + { + String configFilePath; + bool verboseLoad { false }; + bool trackMachineInfoDiff { false }; + bool hideVirtualDisplay { false }; + bool trackCallStack { false }; + bool debugModeEnabled { false }; + }; public: struct tMachineDebugInfo { inline tMachineDebugInfo(void) { } @@ -55,8 +64,8 @@ namespace dragon int32_t previousSubRoutineCounter { 0x00000000 }; int32_t currentSubRoutineCounter { 0x00000000 }; - ostd::String previousInstructionOpCode { "" }; - ostd::String currentInstructionOpCode { "" }; + String previousInstructionOpCode { "" }; + String currentInstructionOpCode { "" }; int8_t previousInstructionFootprint[5] { 0x00, 0x00, 0x00, 0x00, 0x00 }; int8_t currentInstructionFootprint[5] { 0x00, 0x00, 0x00, 0x00, 0x00 }; @@ -86,16 +95,11 @@ namespace dragon static void processErrors(void); static std::vector getErrorList(void); static int32_t loadArguments(int argc, char** argv, tCommandLineArgs& args); - static int32_t initMachine(const ostd::String& configFilePath, - bool verbose = false, - bool trackMachineInfoDiff = false, - bool hideVirtualDisplay = false, - bool rackCallStack = false, - bool debugModeEnabled = false); + static int32_t initMachine(const tRuntimeInitInfo& info); static void shutdownMachine(void); static void runMachine(void); static bool runStep(std::vector trackedAddresses = { }); - static void forceLoad(const ostd::String& filePath, uint16_t loadAddress); + static void forceLoad(const String& filePath, uint16_t loadAddress); inline static const tMachineDebugInfo& getMachineInfoDiff(void) { return s_machineInfo; } inline static bool hasError(void) { return data::ErrorHandler::hasError(); } diff --git a/src/runtime/runtime_main.cpp b/src/runtime/runtime_main.cpp index cdaaefa..6d40bed 100644 --- a/src/runtime/runtime_main.cpp +++ b/src/runtime/runtime_main.cpp @@ -11,7 +11,10 @@ int main(int argc, char** argv) if (rValue != 0) return rValue; //Initializing the runtime - rValue = dragon::DragonRuntime::initMachine(args.machine_config_path, args.verbose_load); + dragon::DragonRuntime::tRuntimeInitInfo initInfo; + initInfo.configFilePath = args.machine_config_path; + initInfo.verboseLoad = args.verbose_load; + rValue = dragon::DragonRuntime::initMachine(initInfo); if (rValue == dragon::DragonRuntime::RETURN_VAL_CLOSE_RUNTIME) return 0; if (rValue != 0) return rValue; diff --git a/src/tools/GlobalData.cpp b/src/tools/GlobalData.cpp index df74083..d7dd032 100644 --- a/src/tools/GlobalData.cpp +++ b/src/tools/GlobalData.cpp @@ -5,7 +5,7 @@ namespace dragon { namespace data { - ostd::String OpCodes::getOpCodeString(uint8_t opCode) + String OpCodes::getOpCodeString(uint8_t opCode) { CPUExtension* ext = DragonRuntime::cpu.getCurrentCPUExtension(); if (ext != nullptr) diff --git a/src/tools/GlobalData.hpp b/src/tools/GlobalData.hpp index 1b1e5c1..8b54dbb 100644 --- a/src/tools/GlobalData.hpp +++ b/src/tools/GlobalData.hpp @@ -65,11 +65,11 @@ namespace dragon public: struct tError { uint64_t code; - ostd::String text; + String text; }; public: - inline static void pushError(uint64_t code, ostd::String text) { m_errorStack.push_back({ code, text }); } + inline static void pushError(uint64_t code, String text) { m_errorStack.push_back({ code, text }); } inline static bool hasError(void) { return m_errorStack.size() > 0; } inline static tError popError(void) { @@ -201,7 +201,7 @@ namespace dragon inline static constexpr uint8_t Text16ModeScreenRefreshed = 0xE0; - inline static ostd::String getInterruptName(uint8_t code) + inline static String getInterruptName(uint8_t code) { switch (code) { @@ -278,14 +278,14 @@ namespace dragon { public: inline virtual ~CPUExtension(void) { } - inline CPUExtension(uint8_t code, ostd::String name) : m_code(code), m_name(name) { } - virtual ostd::String getOpCodeString(uint8_t opCode) = 0; + inline CPUExtension(uint8_t code, String name) : m_code(code), m_name(name) { } + virtual String getOpCodeString(uint8_t opCode) = 0; virtual uint8_t getInstructionSIze(uint8_t opCode) = 0; virtual bool execute(hw::VirtualCPU& vcpu) = 0; public: uint8_t m_code { 0x00 }; - ostd::String m_name { "" }; + String m_name { "" }; }; class OpCodes @@ -394,7 +394,7 @@ namespace dragon inline static constexpr uint8_t Int = 0xFE; inline static constexpr uint8_t Halt = 0xFF; - static ostd::String getOpCodeString(uint8_t opCode); + static String getOpCodeString(uint8_t opCode); static uint8_t getInstructionSIze(uint8_t opCode); }; diff --git a/src/tools/Tools.cpp b/src/tools/Tools.cpp index 21b4e8a..6299d40 100644 --- a/src/tools/Tools.cpp +++ b/src/tools/Tools.cpp @@ -11,7 +11,7 @@ namespace dragon { - bool Tools::createVirtualHardDrive(uint32_t sizeInBytes, const ostd::String& dataFilePath) + bool Tools::createVirtualHardDrive(uint32_t sizeInBytes, const String& dataFilePath) { std::ofstream rf(dataFilePath.cpp_str(), std::ios::out | std::ios::binary); if(!rf) return false; @@ -25,7 +25,7 @@ namespace dragon int32_t Tools::execute(int argc, char** argv) { - ostd::String tool = ""; + String tool = ""; int32_t rValue = get_tool(argc, argv, tool); if (rValue != ErrorNoError) return rValue; @@ -82,8 +82,8 @@ namespace dragon out.fg(ostd::ConsoleColors::Red).p(" Usage: ./dtools new-vdisk ").reset().nl(); return ErrorNewVDiskTooFewArgs; } - ostd::String dest = argv[2]; - ostd::String str_size = argv[3]; + String dest = argv[2]; + String str_size = argv[3]; if (!str_size.isInt()) { out.fg(ostd::ConsoleColors::Red).p("Error: parameter must be integer.").reset().nl(); @@ -109,9 +109,9 @@ namespace dragon out.fg(ostd::ConsoleColors::Red).p(" Usage: ./dtools load-binary ").reset().nl(); return ErrorLoadProgTooFewArgs; } - ostd::String vdisk_file = argv[2]; - ostd::String data_file = argv[3]; - ostd::String str_addr = argv[4]; + String vdisk_file = argv[2]; + String data_file = argv[3]; + String str_addr = argv[4]; if (!str_addr.isInt()) { out.fg(ostd::ConsoleColors::Red).p("Error: parameter must be integer.").reset().nl(); @@ -140,7 +140,7 @@ namespace dragon out.nl().fg(ostd::ConsoleColors::Green).p("Success. Data written to Virtual Disk:").nl(); out.p(" Data Path: ").p(data_file.cpp_str()).nl(); out.p(" Disk Path: ").p(vdisk_file.cpp_str()).nl(); - out.p(" Data Address: ").p(ostd::String::getHexStr(addr, true, 4).cpp_str()).nl(); + out.p(" Data Address: ").p(String::getHexStr(addr, true, 4).cpp_str()).nl(); out.p(" Size: ").p(code.size()).reset().nl(); return ErrorNoError; } @@ -153,7 +153,7 @@ namespace dragon out.fg(ostd::ConsoleColors::Red).p(" Usage: ./dtools read-dpt ").reset().nl(); return ErrorReadDPTTooFewArgs; } - ostd::String vdisk_file = argv[2]; + String vdisk_file = argv[2]; dragon::hw::VirtualHardDrive vHDD(vdisk_file); if (!vHDD.isInitialized()) { @@ -199,7 +199,7 @@ namespace dragon uint32_t startAddress { 0 }; uint32_t size { 0 }; ostd::BitField_16 flags { 0 }; - ostd::String label { "" }; + String label { "" }; }; std::vector partitionList; for (int32_t i = 0; i < part_count; i++) @@ -219,27 +219,27 @@ namespace dragon out.fg(ostd::ConsoleColors::BrightRed).p("Disk: ").p(vdisk_file).p(" (").p(vHDD.getSize()).p(" bytes)").nl(); auto print_part_size = [](uint32_t size, ostd::ConsoleOutputHandler& out, uint16_t line_len) { double dsize = size; - ostd::String units[4] = { " bytes", " Kb", " Mb", " Gb" }; + String units[4] = { " bytes", " Kb", " Mb", " Gb" }; int32_t unit_index = 0; while (dsize > 1024 && unit_index < 3) { unit_index++; dsize /= 1024.0; } - out.p(ostd::String("").add(dsize, 2).add(units[unit_index]).new_fixedLength(line_len)); + out.p(String("").add(dsize, 2).add(units[unit_index]).new_fixedLength(line_len)); }; uint16_t len = 20; out.nl().fg(ostd::ConsoleColors::BrightGray); - out.p(ostd::String("=").new_fixedLength(5 * len, '=')).nl(); + out.p(String("=").new_fixedLength(5 * len, '=')).nl(); out.fg(ostd::ConsoleColors::Blue); out.p(" "); - out.p(ostd::String("LABEL").new_fixedLength(len)); - out.p(ostd::String("SIZE").new_fixedLength(len)); - out.p(ostd::String("START").new_fixedLength(len)); - out.p(ostd::String("END").new_fixedLength(len)); - out.p(ostd::String("FLAGS").new_fixedLength(len)); + out.p(String("LABEL").new_fixedLength(len)); + out.p(String("SIZE").new_fixedLength(len)); + out.p(String("START").new_fixedLength(len)); + out.p(String("END").new_fixedLength(len)); + out.p(String("FLAGS").new_fixedLength(len)); out.nl().fg(ostd::ConsoleColors::BrightGray); - out.p(ostd::String("=").new_fixedLength(5 * len, '=')).nl(); + out.p(String("=").new_fixedLength(5 * len, '=')).nl(); for (int32_t i = 0; i < partitionList.size(); i++) { auto& part = partitionList[i]; @@ -248,9 +248,9 @@ namespace dragon out.fg(ostd::ConsoleColors::Cyan).p(" "); out.p(part.label.new_fixedLength(len)); print_part_size(part.size, out, len); - out.p(ostd::String::getHexStr(part.startAddress, true, 4).new_fixedLength(len)); - out.p(ostd::String::getHexStr(part.startAddress + part.size, true, 4).new_fixedLength(len)); - ostd::String flags_str = ""; + out.p(String::getHexStr(part.startAddress, true, 4).new_fixedLength(len)); + out.p(String::getHexStr(part.startAddress + part.size, true, 4).new_fixedLength(len)); + String flags_str = ""; for (uint8_t bit = 0; bit < sizeof(part.flags) * 8; bit++) { if (m_dpt_flags_str.count(bit) == 0) @@ -264,7 +264,7 @@ namespace dragon out.fg(ostd::ConsoleColors::Yellow).p(flags_str).fg(ostd::ConsoleColors::Cyan).nl(); } out.fg(ostd::ConsoleColors::BrightGray); - out.p(ostd::String("=").new_fixedLength(5 * len, '=')).nl(); + out.p(String("=").new_fixedLength(5 * len, '=')).nl(); out.reset().nl(); return ErrorNoError; } @@ -277,7 +277,7 @@ namespace dragon out.fg(ostd::ConsoleColors::Red).p(" Usage: ./dtools new-dpt -p -s SIZE [-l LABEL] [-f FLAG1] [-f FLAG2] [-p SIZE ...]").reset().nl(); return ErrorLoadProgTooFewArgs; } - ostd::String vdisk_file = argv[2]; + String vdisk_file = argv[2]; dragon::hw::VirtualHardDrive vHDD(vdisk_file); if (!vHDD.isInitialized()) { @@ -287,7 +287,7 @@ namespace dragon uint64_t disk_size = vHDD.getSize(); auto& _dpt_flags_str = m_dpt_flags_str; - auto get_flag_from_str = [_dpt_flags_str](const ostd::String& flag_str) -> int8_t { + auto get_flag_from_str = [_dpt_flags_str](const String& flag_str) -> int8_t { for (auto& flag : _dpt_flags_str) { if (flag.second == flag_str) @@ -306,7 +306,7 @@ namespace dragon uint32_t size { 0 }; uint32_t address { 0 }; std::vector flags; - ostd::String label { "" }; + String label { "" }; }; std::vector partitions; @@ -318,7 +318,7 @@ namespace dragon uint32_t part_start_addr = data::DPTStructure::DiskStartAddr; while (has_args) { - ostd::String arg = argv[arg_index]; + String arg = argv[arg_index]; arg.trim(); if (part_started) { @@ -365,13 +365,13 @@ namespace dragon out.fg(ostd::ConsoleColors::Red).p("Error: No partition size specified.").reset().nl(); return ErrorNewDPTNoPartitionSize; } - else if (!ostd::String(argv[arg_index + 1]).isInt()) + else if (!String(argv[arg_index + 1]).isInt()) { out.fg(ostd::ConsoleColors::Red).p("Error: Partition size must be an integer.").reset().nl(); return ErrorNewDPTInvalidPartitionSize; } arg_index++; - uint32_t part_size = ostd::String(argv[arg_index]).toInt(); + uint32_t part_size = String(argv[arg_index]).toInt(); if (part_start_addr + part_size > disk_size) { out.fg(ostd::ConsoleColors::Red).p("Error: Not enough space on disk.").reset().nl(); @@ -446,7 +446,7 @@ namespace dragon vHDD.unmount(); out.nl().fg(ostd::ConsoleColors::Green).p("Success. DPT Block created on Virtual Disk:").nl(); out.p(" Disk Path: ").p(vdisk_file.cpp_str()).nl(); - out.p(" DPT Block Address: ").p(ostd::String::getHexStr(data::DPTStructure::DiskAddress, true, 4).cpp_str()).nl(); + out.p(" DPT Block Address: ").p(String::getHexStr(data::DPTStructure::DiskAddress, true, 4).cpp_str()).nl(); out.p(" DPT Block Size: ").p(data::DPTStructure::DPTBlockSizeBytes).nl(); return ErrorNoError; } @@ -460,7 +460,7 @@ namespace dragon out.fg(ostd::ConsoleColors::Red).p(" Usage: ./dtools print-disassembly ").reset().nl(); return ErrorPrintDisassemblyTooFewArgs; } - ostd::String arg1 = argv[2]; + String arg1 = argv[2]; arg1.trim(); TableList codeTable; TableList labelTable; @@ -499,7 +499,7 @@ namespace dragon out.bg(ostd::ConsoleColors::White).fg(ostd::ConsoleColors::Black).p("DATA:").reset().nl(); for (const auto& line : dataTable) { - out.fg(ostd::ConsoleColors::BrightGray).p(ostd::String::getHexStr(line.addr, true, 2)).p("\t\t"); + out.fg(ostd::ConsoleColors::BrightGray).p(String::getHexStr(line.addr, true, 2)).p("\t\t"); out.fg(ostd::ConsoleColors::Green).p(line.code).p("\t\t"); out.fg(ostd::ConsoleColors::Blue).p(line.size).p(" bytes\t\t"); out.reset().nl(); @@ -508,7 +508,7 @@ namespace dragon out.bg(ostd::ConsoleColors::White).fg(ostd::ConsoleColors::Black).p("LABELS:").reset().nl(); for (const auto& line : labelTable) { - out.fg(ostd::ConsoleColors::BrightGray).p(ostd::String::getHexStr(line.addr, true, 2)).p("\t\t"); + out.fg(ostd::ConsoleColors::BrightGray).p(String::getHexStr(line.addr, true, 2)).p("\t\t"); out.fg(ostd::ConsoleColors::Green).p(line.code).p("\t\t"); out.reset().nl(); } @@ -516,7 +516,7 @@ namespace dragon out.bg(ostd::ConsoleColors::White).fg(ostd::ConsoleColors::Black).p("CODE:").reset().nl(); for (const auto& line : codeTable) { - out.fg(ostd::ConsoleColors::BrightGray).p(ostd::String::getHexStr(line.addr, true, 2)).p("\t\t"); + out.fg(ostd::ConsoleColors::BrightGray).p(String::getHexStr(line.addr, true, 2)).p("\t\t"); out.fg(ostd::ConsoleColors::Green).p(line.code).p("\t\t"); out.reset().nl(); } @@ -561,7 +561,7 @@ namespace dragon out.fg(ostd::ConsoleColors::Magenta).p("Usage: ./dtools [...arguments...]").nl().nl().reset(); } - int32_t Tools::get_tool(int argc, char** argv, ostd::String& outTool) + int32_t Tools::get_tool(int argc, char** argv, String& outTool) { if (argc < 2) { @@ -569,7 +569,7 @@ namespace dragon out.fg(ostd::ConsoleColors::Red).p("Use the --help option for more info.").reset().nl(); return ErrorTopLevelTooFewArgs; } - ostd::String tool = argv[1]; + String tool = argv[1]; tool = tool.trim().toLower(); outTool = tool; return ErrorNoError; diff --git a/src/tools/Tools.hpp b/src/tools/Tools.hpp index c5146cf..ab7eec0 100644 --- a/src/tools/Tools.hpp +++ b/src/tools/Tools.hpp @@ -10,7 +10,7 @@ namespace dragon { public: static inline ostd::ConsoleOutputHandler& output(void) { return out; } - static bool createVirtualHardDrive(uint32_t sizeInBytes, const ostd::String& dataFilePath); + static bool createVirtualHardDrive(uint32_t sizeInBytes, const String& dataFilePath); static int32_t execute(int argc, char** argv); private: @@ -20,12 +20,12 @@ namespace dragon static int32_t tool_new_dpt(int argc, char** argv); static int32_t tool_print_disassembly(int argc, char** argv); static void print_application_help(void); - static int32_t get_tool(int argc, char** argv, ostd::String& outTool); + static int32_t get_tool(int argc, char** argv, String& outTool); private: inline static ostd::ConsoleOutputHandler out; - inline static std::unordered_map m_dpt_flags_str { + inline static std::unordered_map m_dpt_flags_str { { data::DPTStructure::tFlags::Boot, "boot" } }; diff --git a/src/tools/Utils.cpp b/src/tools/Utils.cpp index 59e9d8d..563429a 100644 --- a/src/tools/Utils.cpp +++ b/src/tools/Utils.cpp @@ -5,12 +5,12 @@ namespace dragon { static const std::vector g_symbols = { '_', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', '0', '1', '2', '3', '4', '5', '6', '7', '8' }; - ostd::String Utils::genRandomName(uint8_t length) + String Utils::genRandomName(uint8_t length) { auto rnd_char = []() -> char { return g_symbols[ostd::Random::getui8(0, g_symbols.size())]; }; - ostd::String name = ""; + String name = ""; for (int32_t i = 0; i < length; i++) name.addChar(rnd_char()); return name; diff --git a/src/tools/Utils.hpp b/src/tools/Utils.hpp index 48e9928..4d639d8 100644 --- a/src/tools/Utils.hpp +++ b/src/tools/Utils.hpp @@ -8,6 +8,6 @@ namespace dragon class Utils { public: - static ostd::String genRandomName(uint8_t length); + static String genRandomName(uint8_t length); }; }