From e0059c85204db23278b4caa1265606867f250aa1 Mon Sep 17 00:00:00 2001 From: OmniaX Date: Thu, 5 Sep 2024 00:40:36 +0200 Subject: [PATCH] Added debug_profiler instructions --- .vscode/settings.json | 26 ++++++++------ build.nr | 2 +- extra/config/testMachine.dvm | 2 +- extra/dragon/disk1.dr | Bin 4194304 -> 4194304 bytes extra/dss/bios/data.dss | 12 +++++++ extra/dss/bios_api.dss | 11 +++++- extra/dss/drake/disk.dss | 2 ++ extra/dss/drake/loader.dss | 2 +- extra/info/info | 2 +- extra/scripts/bios_flash | 3 +- extra/scripts/build_drake | 6 ++-- src/assembler/Assembler.cpp | 60 +++++++++++++++++++++++++++++-- src/assembler/Assembler.hpp | 4 ++- src/assembler/DASMApp.cpp | 49 +++++++++++++++++-------- src/assembler/assembler_main.cpp | 1 + src/hardware/VirtualCPU.cpp | 22 ++++++++++++ src/hardware/VirtualCPU.hpp | 4 +++ src/hardware/VirtualDisplay.cpp | 13 ++++++- src/runtime/DragonRuntime.cpp | 6 ++-- src/tools/GlobalData.cpp | 4 +++ src/tools/GlobalData.hpp | 2 ++ src/tools/Utils.cpp | 13 +++++++ src/tools/Utils.hpp | 4 ++- 23 files changed, 209 insertions(+), 41 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 00d2997..f15ab3c 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -106,22 +106,23 @@ }, "workbench.colorCustomizations": { - "editor.background": "#131313", - "tab.hoverBackground": "#111", + // "editor.background": "#131313", + "tab.hoverBackground": "#022809", "tab.inactiveBackground": "#000", - "tab.activeBackground": "#1b1b1b", - "tab.activeBorder": "#bb5400", + "tab.activeBackground": "#001804", + "editor.foldBackground": "#20070bcc", + "tab.activeBorder": "#15ff00", "editorIndentGuide.background1": "#252525", "editorWhitespace.foreground": "#683700", "editor.lineHighlightBorder": "#1a1a1a", - "editor.lineHighlightBackground": "#490050", + "editor.lineHighlightBackground": "#0a200a", "editorBracketMatch.background": "#444", "editorBracketMatch.border": "#b80318", - "editor.selectionBackground": "#3b3b3b", - "editor.selectionHighlightBackground": "#702900e8", - "statusBar.background": "#2e2850", - "minimap.background" : "#1b1b1b", - "sideBar.background": "#1b1b1b" + "editor.selectionBackground": "#0e3616", + "editor.selectionHighlightBackground": "#9c3e08c5", + // "statusBar.background": "#2e2850", + "minimap.background" : "#0f0f0f", + "sideBar.background": "#0b0b0b" }, "workbench.editor.wrapTabs": true, @@ -166,5 +167,8 @@ "python.languageServer": "None", - "files.eol": "\r\n" + "files.eol": "\r\n", + + "workbench.iconTheme": "material-icon-theme", + "workbench.colorTheme": "Aramok's GLX Black" } diff --git a/build.nr b/build.nr index 74d36ca..480d250 100644 --- a/build.nr +++ b/build.nr @@ -1 +1 @@ -1603 +1610 diff --git a/extra/config/testMachine.dvm b/extra/config/testMachine.dvm index 42e22d6..877a95b 100644 --- a/extra/config/testMachine.dvm +++ b/extra/config/testMachine.dvm @@ -3,7 +3,7 @@ Bios = dragon/bios.bin CMOS = dragon/cmos.dr cpuext = extmov, extalu -fixed_clock = true +fixed_clock = false clock_rate_sec = 644 memory_extension_pages = 16 diff --git a/extra/dragon/disk1.dr b/extra/dragon/disk1.dr index 07194b3122d7c6ac81367092d194e1bad03f82f3..29a386e1804ebcdbf97f62b9d618b3b0856cae79 100644 GIT binary patch delta 234 zcmX}kIaa~|002=FLPSIb5gbrl5D`~!0Ts7r;l1)KrlI5x)I2G?4y6a6pp=SYnqN$k zBw?~>{263Y)0JXe8brgd;P)q-MN62>?!)l22ps6f5JG1zey-(FL8fJ{qsvAi6tjNCM1!(Ov;o@OF@b< zBePNxq%0Mw%AC|>UKXS-4Ox^WS(X)9l{INfOV(vWHf2lNvMoEZD|^zBeL0XrIg(>J ckyAO7bGeX9xstB* diff --git a/extra/info/info b/extra/info/info index 59e826a..34430fd 100644 --- a/extra/info/info +++ b/extra/info/info @@ -236,4 +236,4 @@ boot-ssector 5 kb 5120 bytes (0x1400) 0x0000.0400 -> 0x0000.17FF Unallocated 90 kb 92160 bytes (0x16800) 0x0000.1800 -> 0x0001.7FFF DragonOS 2000 kb 2048000 bytes (0x1F4000) 0x0001.8000 -> 0x0020.BFFF - Test Partition 2000 kb 2048000 bytes ( 0x1F4000) 0x0020.C000 -> 0x0040.0000 + Test Partition 2000 kb 2048000 bytes (0x1F4000) 0x0020.C000 -> 0x0040.0000 diff --git a/extra/scripts/bios_flash b/extra/scripts/bios_flash index f11cb3f..bb19ac3 100644 --- a/extra/scripts/bios_flash +++ b/extra/scripts/bios_flash @@ -6,5 +6,6 @@ clear='\033[0m' printf "${green}Reloading BIOS...\n${clear}" cd .. cp ../extra/dss/bios/* ./dss/bios/ -./dasm dss/bios/entry.dss -o dragon/bios.bin --extalu --save-disassembly disassembly/bios.dds --verbose --save-exports +./dasm dss/bios/entry.dss -o dragon/bios.bin -D +# ./dasm dss/bios/entry.dss -o dragon/bios.bin --extalu --save-disassembly disassembly/bios.dds --verbose --save-exports cp dragon/bios.bin ../extra/dragon/bios.bin diff --git a/extra/scripts/build_drake b/extra/scripts/build_drake index 4e7ce0e..dd5ba7a 100644 --- a/extra/scripts/build_drake +++ b/extra/scripts/build_drake @@ -8,11 +8,13 @@ cd .. cp ../extra/dss/drake/* ./dss/drake/ printf "\n${green}1) loader.dss\n${clear}" -./dasm dss/drake/loader.dss -o dragon/drake_loader.bin --extalu --save-disassembly disassembly/drake_loader.dds --verbose +./dasm dss/drake/loader.dss -o dragon/drake_loader.bin -D +# ./dasm dss/drake/loader.dss -o dragon/drake_loader.bin --extalu --save-disassembly disassembly/drake_loader.dds --verbose ./dtools load-binary dragon/disk1.dr dragon/drake_loader.bin 0x00000000 printf "\n${green}2) bootsector.dss\n${clear}" -./dasm dss/drake/bootsector.dss -o dragon/drake_bootsector.bin --extalu --save-disassembly disassembly/drake_bootsector.dds --verbose +./dasm dss/drake/bootsector.dss -o dragon/drake_bootsector.bin -D +# ./dasm dss/drake/bootsector.dss -o dragon/drake_bootsector.bin --extalu --save-disassembly disassembly/drake_bootsector.dds --verbose ./dtools load-binary dragon/disk1.dr dragon/drake_bootsector.bin 0x00000400 printf "\n" diff --git a/src/assembler/Assembler.cpp b/src/assembler/Assembler.cpp index 498877b..db06589 100644 --- a/src/assembler/Assembler.cpp +++ b/src/assembler/Assembler.cpp @@ -994,7 +994,11 @@ namespace dragon { _disassembly_line.addr = m_dataSize + m_loadAddress + m_code.size() + 3; lineEdit = replaceSymbols(lineEdit); - parse1Operand(lineEdit); + ostd::String _tmp_edit(lineEdit); + if (_tmp_edit.toLower().trim().startsWith("debug_")) + parseDebugOperands(lineEdit); + else + parse1Operand(lineEdit); _disassembly_line.code = lineEdit; m_disassembly.push_back(_disassembly_line); continue; @@ -1003,7 +1007,11 @@ namespace dragon { _disassembly_line.addr = m_dataSize + m_loadAddress + m_code.size() + 3; lineEdit = replaceSymbols(lineEdit); - parse2Operand(lineEdit); + ostd::String _tmp_edit(lineEdit); + if (_tmp_edit.toLower().trim().startsWith("debug_")) + parseDebugOperands(lineEdit); + else + parse2Operand(lineEdit); _disassembly_line.code = lineEdit; m_disassembly.push_back(_disassembly_line); continue; @@ -1012,7 +1020,11 @@ namespace dragon { _disassembly_line.addr = m_dataSize + m_loadAddress + m_code.size() + 3; lineEdit = replaceSymbols(lineEdit); - parse3Operand(lineEdit); + ostd::String _tmp_edit(lineEdit); + if (_tmp_edit.toLower().trim().startsWith("debug_")) + parseDebugOperands(lineEdit); + else + parse3Operand(lineEdit); _disassembly_line.code = lineEdit; m_disassembly.push_back(_disassembly_line); continue; @@ -1029,11 +1041,53 @@ namespace dragon void Assembler::parseDebugOperands(ostd::String line) { + if (!debugMode) + return; if (ostd::String(line).toLower().startsWith("debug_break")) { m_code.push_back(data::OpCodes::DEBUG_Break); return; } + else if (ostd::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")) + { + ostd::String lineEdit(line); + ostd::String instEdit(lineEdit.new_substr(0, lineEdit.indexOf(" "))); + instEdit.trim().toLower(); + ostd::String opEdit(lineEdit.new_substr(lineEdit.indexOf(" ") + 1)); + opEdit.trim(); + int16_t word1 = 0x0000; + int16_t word2 = 0x0000; + auto st = opEdit.tokenize(","); + eOperandType opType1 = parseOperand(st.next(), word1); + if (opType1 == eOperandType::Immediate) + { + eOperandType opType2 = parseOperand(st.next(), word2); + switch (opType2) + { + case eOperandType::Immediate: + m_code.push_back(data::OpCodes::DEBUG_StartProfile); + m_code.push_back(static_cast(word1)); + m_code.push_back(static_cast(word2)); + break; + default: + std::cout << "Invalid operand2 type; " << line << " (" << opEdit << ")\n"; + exit(0); + break; + } + } + else + { + std::cout << "Invalid operand1 type; " << line << " (" << opEdit << ")\n"; + exit(0); + } + + return; + } } void Assembler::parse0Operand(ostd::String line) diff --git a/src/assembler/Assembler.hpp b/src/assembler/Assembler.hpp index ab3fe80..ee30ac1 100644 --- a/src/assembler/Assembler.hpp +++ b/src/assembler/Assembler.hpp @@ -92,7 +92,8 @@ namespace dragon ostd::String dest_file_path { "" }; bool save_disassembly { false }; bool verbose { false }; - bool save_exports { false }; + bool debug_mode { false }; + bool save_exports { true }; ostd::String disassembly_file_path { "" }; std::vector cpu_extensions; }; @@ -171,6 +172,7 @@ namespace dragon public: inline static bool saveExports { false }; + inline static bool debugMode { false }; inline static std::vector cpuExtensions; }; } diff --git a/src/assembler/DASMApp.cpp b/src/assembler/DASMApp.cpp index a589a1d..3cd540f 100644 --- a/src/assembler/DASMApp.cpp +++ b/src/assembler/DASMApp.cpp @@ -1,4 +1,6 @@ #include "Assembler.hpp" +#include "../tools/Utils.hpp" +#include namespace dragon { @@ -20,6 +22,9 @@ namespace dragon print_application_help(); return RETURN_VAL_CLOSE_PROGRAM; } + args.disassembly_file_path = ""; + bool disable_extmov = false; + bool disable_extalu = false; for (int32_t i = 2; i < argc; i++) { ostd::String edit(argv[i]); @@ -43,42 +48,58 @@ namespace dragon print_application_help(); return RETURN_VAL_CLOSE_PROGRAM; } - else if (edit == "--extmov") - args.cpu_extensions.push_back("extmov"); - else if (edit == "--extalu") - args.cpu_extensions.push_back("extalu"); + else if (edit == "-D" || edit == "--debug") + args.debug_mode = true; + else if (edit == "--disable-extmov") + disable_extmov = true; + else if (edit == "--disable-extalu") + disable_extalu = true; else if (edit == "--verbose") args.verbose = true; - else if (edit == "--save-exports") - args.save_exports = true; + else if (edit == "--disable-exports") + args.save_exports = false; } + if (args.debug_mode) + { + // args.verbose = true; + args.save_disassembly = true; + } + if (!disable_extalu) + args.cpu_extensions.push_back("extalu"); + if (!disable_extmov) + args.cpu_extensions.push_back("extmov"); + if (args.save_disassembly && args.disassembly_file_path == "") + args.disassembly_file_path = "disassembly/" + ostd::Utils::md5(args.dest_file_path) + ".dds"; } return RETURN_VAL_EXIT_SUCCESS; } - void Assembler::Application::print_application_help(void) + void Assembler::Application::print_application_help(void) { int32_t commandLength = 46; out.nl().fg(ostd::ConsoleColors::Yellow).p("List of available parameters:").reset().nl(); ostd::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.").reset().nl(); + 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 = "--verbose"; tmpCommand.addRightPadding(commandLength); out.fg(ostd::ConsoleColors::Blue).p(tmpCommand).fg(ostd::ConsoleColors::Green).p("Shows more information about the assembled program.").reset().nl(); tmpCommand = "-o "; tmpCommand.addRightPadding(commandLength); out.fg(ostd::ConsoleColors::Blue).p(tmpCommand).fg(ostd::ConsoleColors::Green).p("Used to specify the output binary file.").reset().nl(); - tmpCommand = "--save-exports"; + tmpCommand = "--disable-exports"; tmpCommand.addRightPadding(commandLength); - out.fg(ostd::ConsoleColors::Blue).p(tmpCommand).fg(ostd::ConsoleColors::Green).p("Used to save any specified exports in the code.").reset().nl(); - tmpCommand = "--extmov"; + out.fg(ostd::ConsoleColors::Blue).p(tmpCommand).fg(ostd::ConsoleColors::Green).p("Used to disable any specified exports in the code.").reset().nl(); + tmpCommand = "--disable-extmov"; tmpCommand.addRightPadding(commandLength); - out.fg(ostd::ConsoleColors::Blue).p(tmpCommand).fg(ostd::ConsoleColors::Green).p("Enables mnemonics for the CPU extension.").reset().nl(); - tmpCommand = "--extalu"; + out.fg(ostd::ConsoleColors::Blue).p(tmpCommand).fg(ostd::ConsoleColors::Green).p("Disables mnemonics for the CPU extension.").reset().nl(); + tmpCommand = "--disable-extalu"; tmpCommand.addRightPadding(commandLength); - out.fg(ostd::ConsoleColors::Blue).p(tmpCommand).fg(ostd::ConsoleColors::Green).p("Enables mnemonics for the CPU extension.").reset().nl(); + out.fg(ostd::ConsoleColors::Blue).p(tmpCommand).fg(ostd::ConsoleColors::Green).p("Disables mnemonics for the CPU extension.").reset().nl(); + tmpCommand = "--debug, -D"; + tmpCommand.addRightPadding(commandLength); + out.fg(ostd::ConsoleColors::Blue).p(tmpCommand).fg(ostd::ConsoleColors::Green).p("Used to enable debug mode.").reset().nl(); tmpCommand = "--help"; tmpCommand.addRightPadding(commandLength); out.fg(ostd::ConsoleColors::Blue).p(tmpCommand).fg(ostd::ConsoleColors::Green).p("Displays this help message.").reset().nl(); diff --git a/src/assembler/assembler_main.cpp b/src/assembler/assembler_main.cpp index b1699b0..9d4224e 100644 --- a/src/assembler/assembler_main.cpp +++ b/src/assembler/assembler_main.cpp @@ -9,6 +9,7 @@ int main(int argc, char** argv) return rValue; auto& args = dragon::code::Assembler::Application::args; dragon::code::Assembler::saveExports = args.save_exports; + dragon::code::Assembler::debugMode = args.debug_mode; dragon::code::Assembler::cpuExtensions = args.cpu_extensions; dragon::code::Assembler::assembleToFile(args.source_file_path, args.dest_file_path); if (args.verbose) diff --git a/src/hardware/VirtualCPU.cpp b/src/hardware/VirtualCPU.cpp index 5847639..6994729 100644 --- a/src/hardware/VirtualCPU.cpp +++ b/src/hardware/VirtualCPU.cpp @@ -234,6 +234,28 @@ namespace dragon m_biosMode = value != 0; } break; + case data::OpCodes::DEBUG_StartProfile: + { + int8_t id = fetch8(); + int8_t timeUnit = fetch8(); + ostd::eTimeUnits tu = ostd::eTimeUnits::Milliseconds; + if (static_cast(timeUnit) == eDebugProfilerTimeUnits::Micros) + tu = ostd::eTimeUnits::Microseconds; + else if (static_cast(timeUnit) == eDebugProfilerTimeUnits::Nanos) + tu = ostd::eTimeUnits::Nanoseconds; + else if (static_cast(timeUnit) == eDebugProfilerTimeUnits::Secs) + tu = ostd::eTimeUnits::Seconds; + m_profilerTimer.start(true, ostd::String("DebugProfiler [").add(ostd::Utils::getHexStr(id, true, 1)).add("]"), tu); + m_debugProfilerStarted = true; + } + break; + case data::OpCodes::DEBUG_StopProfile: + { + if (m_debugProfilerStarted) + m_profilerTimer.end(true); + m_debugProfilerStarted = false; + } + break; case data::OpCodes::MovImmReg: { uint8_t regAddr = fetch8(); diff --git a/src/hardware/VirtualCPU.hpp b/src/hardware/VirtualCPU.hpp index 2348a72..3c3e8f9 100644 --- a/src/hardware/VirtualCPU.hpp +++ b/src/hardware/VirtualCPU.hpp @@ -15,6 +15,7 @@ namespace dragon { class VirtualCPU { + public: enum class eDebugProfilerTimeUnits { Millis = 0, Secs = 1, Micros = 2, Nanos = 3 }; public: VirtualCPU(IMemoryDevice& memory); int16_t readRegister(uint8_t reg); @@ -66,6 +67,7 @@ namespace dragon bool m_isDebugBreakPoint { false }; bool m_debugModeEnabled { false }; int32_t m_subroutineCounter { 0 }; + bool m_debugProfilerStarted { false }; bool m_isOffsetAddressingEnabled { false }; uint16_t m_currentOffset { 0x0000 }; @@ -76,6 +78,8 @@ namespace dragon std::vector m_debug_stackFrameStrings; + ostd::Timer m_profilerTimer; + friend class dragon::DragonRuntime; friend class dragon::Debugger::Display; friend class dragon::Debugger; diff --git a/src/hardware/VirtualDisplay.cpp b/src/hardware/VirtualDisplay.cpp index 3edf1dd..4101086 100644 --- a/src/hardware/VirtualDisplay.cpp +++ b/src/hardware/VirtualDisplay.cpp @@ -74,6 +74,8 @@ namespace dragon m_renderer.displayBuffer(); } + static char c = 'A'; + void VirtualDisplay::onUpdate(void) { auto& mem = DragonRuntime::memMap; @@ -143,7 +145,16 @@ namespace dragon int16_t x = mem.read16(vga_addr + tRegisters::MemControllerX); int16_t y = mem.read16(vga_addr + tRegisters::MemControllerY); - DragonRuntime::vGraphicsInterface.writeVRAM_16Colors(static_cast(x), static_cast(y), textCell.character, textCell.backgroundColor, textCell.foregroundColor); + //TODO: Remove this override used for testing purposes + for (int32_t i = 0; i < RawTextRenderer::CONSOLE_CHARS_V * RawTextRenderer::CONSOLE_CHARS_H; i++) + { + auto xy = CONVERT_1D_2D(i, RawTextRenderer::CONSOLE_CHARS_H); + DragonRuntime::vGraphicsInterface.writeVRAM_16Colors(static_cast(xy.x), static_cast(xy.y), c++, 0, 15); + if (c > 'Z') + c = 'A'; + } + + // DragonRuntime::vGraphicsInterface.writeVRAM_16Colors(static_cast(x), static_cast(y), textCell.character, textCell.backgroundColor, textCell.foregroundColor); } } else return; diff --git a/src/runtime/DragonRuntime.cpp b/src/runtime/DragonRuntime.cpp index ef3879d..bae5ef5 100644 --- a/src/runtime/DragonRuntime.cpp +++ b/src/runtime/DragonRuntime.cpp @@ -352,20 +352,22 @@ namespace dragon ostd::Timer clock_timer; bool running = true; bool fixed_clock = machine_config.fixed_clock; + // ostd::Timer _timer; while (running || vDiskInterface.isBusy()) { clock_timer.startCount(ostd::eTimeUnits::Microseconds); ostd::SignalHandler::refresh(); uint16_t addr = cpu.readRegister(dragon::data::Registers::IP); uint16_t spAddr = cpu.readRegister(dragon::data::Registers::SP); + // _timer.start(true, "Profiling", ostd::eTimeUnits::Microseconds, &out); running = cpu.execute() && vDisplay.isRunning(); + // _timer.end(true); vDisplay.update(); - cpu.getCurrentInstruction(); vDiskInterface.cycleStep(); if (dragon::data::ErrorHandler::hasError()) { processErrors(); - break; + break; } if (acc == 500) { diff --git a/src/tools/GlobalData.cpp b/src/tools/GlobalData.cpp index 3079a47..df74083 100644 --- a/src/tools/GlobalData.cpp +++ b/src/tools/GlobalData.cpp @@ -15,6 +15,8 @@ namespace dragon case data::OpCodes::NoOp: return "NoOp"; case data::OpCodes::DEBUG_Break: return "debug_break"; case data::OpCodes::BIOSModeImm: return "BIOSModeImm"; + case data::OpCodes::DEBUG_StartProfile: return "debug_start_profile"; + case data::OpCodes::DEBUG_StopProfile: return "debug_stop_profile"; case data::OpCodes::MovImmReg: return "MovImmReg"; case data::OpCodes::MovImmMem: return "MovImmMem"; case data::OpCodes::MovRegReg: return "MovRegReg"; @@ -113,6 +115,8 @@ namespace dragon case data::OpCodes::NoOp: return 1; case data::OpCodes::DEBUG_Break: return 1; case data::OpCodes::BIOSModeImm: return 2; + case data::OpCodes::DEBUG_StartProfile: return 1; + case data::OpCodes::DEBUG_StopProfile: return 1; case data::OpCodes::MovImmReg: return 4; case data::OpCodes::MovImmMem: return 5; case data::OpCodes::MovRegReg: return 3; diff --git a/src/tools/GlobalData.hpp b/src/tools/GlobalData.hpp index 2139591..74bfe6e 100644 --- a/src/tools/GlobalData.hpp +++ b/src/tools/GlobalData.hpp @@ -279,6 +279,8 @@ namespace dragon inline static constexpr uint8_t NoOp = 0x00; inline static constexpr uint8_t DEBUG_Break = 0x01; inline static constexpr uint8_t BIOSModeImm = 0x02; + inline static constexpr uint8_t DEBUG_StartProfile = 0x03; + inline static constexpr uint8_t DEBUG_StopProfile = 0x04; inline static constexpr uint8_t MovImmReg = 0x10; inline static constexpr uint8_t MovRegReg = 0x11; diff --git a/src/tools/Utils.cpp b/src/tools/Utils.cpp index 6f0e150..74b0ee2 100644 --- a/src/tools/Utils.cpp +++ b/src/tools/Utils.cpp @@ -1,7 +1,20 @@ #include "Utils.hpp" #include #include +#include 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) + { + auto rnd_char = []() -> char { + return g_symbols[ostd::Random::getui8(0, g_symbols.size())]; + }; + ostd::String name = ""; + for (int32_t i = 0; i < length; i++) + name.addChar(rnd_char()); + return name; + } } \ No newline at end of file diff --git a/src/tools/Utils.hpp b/src/tools/Utils.hpp index ac76547..9ae90a7 100644 --- a/src/tools/Utils.hpp +++ b/src/tools/Utils.hpp @@ -1,11 +1,13 @@ #pragma once #include +#include namespace dragon { class Utils { public: - }; + static ostd::String genRandomName(uint8_t length); + }; } \ No newline at end of file