From 59d9d8f910a5440d217bba6d98f915b97a3c65a5 Mon Sep 17 00:00:00 2001 From: OmniaX-Dev Date: Mon, 15 Jun 2026 05:53:31 +0200 Subject: [PATCH] Replaced int types with new short aliases --- src/assembler/Assembler.cpp | 414 ++++++++++----------- src/assembler/Assembler.hpp | 50 +-- src/assembler/DASMApp.cpp | 6 +- src/assembler/IncludePreprocessor.cpp | 2 +- src/assembler/assembler_main.cpp | 2 +- src/debugger/Debugger.cpp | 168 ++++----- src/debugger/Debugger.hpp | 36 +- src/debugger/DisassemblyLoader.cpp | 12 +- src/debugger/debugger_main.cpp | 4 +- src/hardware/CPUExtensions.cpp | 506 +++++++++++++------------- src/hardware/CPUExtensions.hpp | 126 +++---- src/hardware/IMemoryDevice.hpp | 8 +- src/hardware/MemoryMapper.cpp | 22 +- src/hardware/MemoryMapper.hpp | 18 +- src/hardware/VirtualCPU.cpp | 502 ++++++++++++------------- src/hardware/VirtualCPU.hpp | 44 +-- src/hardware/VirtualDisplay.cpp | 46 +-- src/hardware/VirtualDisplay.hpp | 60 +-- src/hardware/VirtualHardDrive.cpp | 14 +- src/hardware/VirtualHardDrive.hpp | 16 +- src/hardware/VirtualIODevices.cpp | 436 +++++++++++----------- src/hardware/VirtualIODevices.hpp | 482 ++++++++++++------------ src/hardware/VirtualMMU.hpp | 4 +- src/hardware/VirtualRAM.cpp | 20 +- src/hardware/VirtualRAM.hpp | 8 +- src/runtime/ConfigLoader.cpp | 4 +- src/runtime/ConfigLoader.hpp | 12 +- src/runtime/DragonRuntime.cpp | 88 ++--- src/runtime/DragonRuntime.hpp | 78 ++-- src/runtime/runtime_main.cpp | 2 +- src/tools/GlobalData.cpp | 4 +- src/tools/GlobalData.hpp | 450 +++++++++++------------ src/tools/Tools.cpp | 90 ++--- src/tools/Tools.hpp | 68 ++-- src/tools/Utils.cpp | 4 +- src/tools/Utils.hpp | 2 +- 36 files changed, 1904 insertions(+), 1904 deletions(-) diff --git a/src/assembler/Assembler.cpp b/src/assembler/Assembler.cpp index 1de537c..3ae5dbb 100644 --- a/src/assembler/Assembler.cpp +++ b/src/assembler/Assembler.cpp @@ -59,7 +59,7 @@ namespace dragon std::cout << "Warning: Fixed size specified but exceeded: (" << (int)m_code.size() << "/" << (int)m_fixedSize << " bytes)\n"; else if (m_fixedSize > 0 && m_code.size() < m_fixedSize) { - for (int16_t i = m_code.size(); i < m_fixedSize; i++) + for (i16 i = m_code.size(); i < m_fixedSize; i++) m_code.push_back(m_fixedFillValue); } insertHeader(); @@ -74,11 +74,11 @@ namespace dragon return m_code; } - ostd::ByteStream Assembler::assembleToVirtualDisk(String fileName, hw::VirtualHardDrive& vhdd, uint32_t address) + ostd::ByteStream Assembler::assembleToVirtualDisk(String fileName, hw::VirtualHardDrive& vhdd, u32 address) { assembleFromFile(fileName); if (m_code.size() == 0) return { }; - for (int32_t i = 0; i < m_code.size(); i++) + for (i32 i = 0; i < m_code.size(); i++) vhdd.write(address + i, m_code[i]); return m_code; } @@ -87,7 +87,7 @@ namespace dragon { if (m_code.size() == 0 || m_disassembly.size() == 0) return false; String header_string = "{ DRAGON_DEBUG_DISASSEMBLY }"; - uint64_t da_size = 0; + u64 da_size = 0; da_size += (header_string.len() + 1) * ostd::tTypeSize::BYTE; da_size += m_disassembly.size() * ostd::tTypeSize::DWORD; //Addresses da_size += m_disassembly.size() * ostd::tTypeSize::WORD; //Data Size @@ -102,7 +102,7 @@ namespace dragon { serializer.w_DWord(stream_addr, da.addr); stream_addr += ostd::tTypeSize::DWORD; - serializer.w_Word(stream_addr, (int16_t)da.size); + serializer.w_Word(stream_addr, (i16)da.size); stream_addr += ostd::tTypeSize::WORD; serializer.w_String(stream_addr, da.code); stream_addr += (da.code.len() + 1) * ostd::tTypeSize::BYTE; @@ -110,10 +110,10 @@ namespace dragon return serializer.saveToFile(fileName); } - void Assembler::printProgramInfo(int32_t verbose_level) + void Assembler::printProgramInfo(i32 verbose_level) { if (verbose_level == 0xFF) return; - int32_t symbol_len = 30; + i32 symbol_len = 30; out.nl(); if (verbose_level == 0 || verbose_level == 2) @@ -179,9 +179,9 @@ namespace dragon //TODO: Expand header functionality to allow for custom values maybe if (m_headerStr == "kernel0_boot") { - header.push_back((uint8_t)((data::DPTStructure::BootPart_ID_CODE & 0xFF00) >> 8)); - header.push_back((uint8_t)(data::DPTStructure::BootPart_ID_CODE & 0x00FF)); - for (int32_t i = 0; i < 30; i++) + header.push_back((u8)((data::DPTStructure::BootPart_ID_CODE & 0xFF00) >> 8)); + header.push_back((u8)(data::DPTStructure::BootPart_ID_CODE & 0x00FF)); + for (i32 i = 0; i < 30; i++) header.push_back(0xFF); } else @@ -301,7 +301,7 @@ namespace dragon for (auto& line : newLines) { String lineEdit(line); - for (int32_t i = defines.size() - 1; i >= 0; i--) + for (i32 i = defines.size() - 1; i >= 0; i--) lineEdit.replaceAll(defines[i].name, defines[i].value.new_trim()); line = lineEdit; } @@ -309,7 +309,7 @@ namespace dragon // { // for (auto& def : exp.second.content) // { - // for (int32_t i = defines.size() - 1; i >= 0; i--) + // for (i32 i = defines.size() - 1; i >= 0; i--) // def.value.replaceAll(defines[i].name, defines[i].value.new_trim()); // } // } @@ -391,7 +391,7 @@ namespace dragon bool in_struct = false; String struct_name = ""; tStructDefinition struct_def; - int32_t member_index = 0; + i32 member_index = 0; for (auto& line : m_lines) { lineEdit = line; @@ -463,7 +463,7 @@ namespace dragon std::cout << "Invalid definition inside struct. Member size must be numeric: " << line << "\n"; return; } - int32_t bytes = lineEdit.toInt(); + i32 bytes = lineEdit.toInt(); if (bytes < 1) { std::cout << "Invalid definition inside struct. Member must be at least 1 Byte: " << line << "\n"; @@ -474,7 +474,7 @@ namespace dragon member.name = member_name; if (member_data == "") { - for (int32_t i = 0; i < bytes; i++) + for (i32 i = 0; i < bytes; i++) member.data.push_back(0x00); } else @@ -485,8 +485,8 @@ namespace dragon String tok = tokens.next(); if (tok.isNumeric()) { - uint8_t data = (uint8_t)tok.toInt(); - for (int32_t i = 0; i < bytes; i++) + u8 data = (u8)tok.toInt(); + for (i32 i = 0; i < bytes; i++) member.data.push_back(data); } else @@ -507,7 +507,7 @@ namespace dragon String tok = tokens.next(); if (tok.isNumeric()) { - uint8_t data = (uint8_t)tok.toInt(); + u8 data = (u8)tok.toInt(); member.data.push_back(data); } else @@ -573,7 +573,7 @@ namespace dragon if (lineEdit.startsWith("<") && lineEdit.endsWith(">") && lineEdit.len() > 2) { lineEdit = lineEdit.substr(1, lineEdit.len() - 1); - std::vector init_data; + std::vector init_data; if (has_init_data) { auto tokens = initialization_data.tokenize(","); @@ -585,7 +585,7 @@ namespace dragon std::cout << "Invalid initialization data: " << lineEdit << "\n"; return; } - init_data.push_back((uint8_t)tok.toInt()); + init_data.push_back((u8)tok.toInt()); } } tStructDefinition struct_def; @@ -609,13 +609,13 @@ namespace dragon std::cout << "Structure size must match initialization data size: " << lineEdit << "\n"; return; } - int32_t data_index = 0; + i32 data_index = 0; newLines.push_back("!" + symbolName); for (auto& member : struct_def.members) { String newLine = symbolName; newLine.add(".").add(member.name).add(" "); - for (int32_t i = 0; i < member.data.size(); i++, data_index++) + for (i32 i = 0; i < member.data.size(); i++, data_index++) { if (has_init_data) newLine.add(String::getHexStr(init_data[data_index], true, 2)); @@ -783,10 +783,10 @@ namespace dragon void Assembler::parseSections(void) { - constexpr uint8_t DATA_SECTION = 0x01; - constexpr uint8_t CODE_SECTION = 0x02; + constexpr u8 DATA_SECTION = 0x01; + constexpr u8 CODE_SECTION = 0x02; - uint8_t currentSection = 0x00; + u8 currentSection = 0x00; for (auto& line : m_lines) { @@ -955,14 +955,14 @@ namespace dragon if (array) { - uint16_t array_size = lineEdit.toInt(); + u16 array_size = lineEdit.toInt(); if (array_size == 0) { std::cout << "Invalid array data entry size (must be greater than 0): " << line << "\n"; continue; } lineEdit = ""; - for (int32_t i = 0; i < array_size; i++) + for (i32 i = 0; i < array_size; i++) lineEdit.add("0x00, "); lineEdit.trim().substr(0, lineEdit.len() - 1).trim(); } @@ -970,15 +970,15 @@ namespace dragon if (lineEdit.isNumeric()) { // union valueSplit { - // uint16_t value; - // uint8_t bytes[2]; + // u16 value; + // u8 bytes[2]; // } split; // split.value = lineEdit.toInt(); // symbol.bytes.push_back(split.bytes[0]); // symbol.bytes.push_back(split.bytes[1]); // symbol.address = m_currentDataAddr; // m_currentDataAddr += 2; - int8_t value = lineEdit.toInt(); + i8 value = lineEdit.toInt(); symbol.bytes.push_back(value); symbol.address = m_currentDataAddr; m_currentDataAddr += 1; @@ -989,8 +989,8 @@ namespace dragon { lineEdit = lineEdit.substr(1, lineEdit.len() - 1); for (auto c : lineEdit) - symbol.bytes.push_back((uint8_t)c); - symbol.bytes.push_back((uint8_t)0); //NULL Termination + symbol.bytes.push_back((u8)c); + symbol.bytes.push_back((u8)0); //NULL Termination symbol.address = m_currentDataAddr; m_currentDataAddr += symbol.bytes.size(); m_symbolTable[symbolName] = symbol; @@ -1012,7 +1012,7 @@ namespace dragon std::cout << "Invalid byte in data entry: " << lineEdit << "\n"; return; } - symbol.bytes.push_back((uint8_t)lineEdit.toInt()); + symbol.bytes.push_back((u8)lineEdit.toInt()); } symbol.address = m_currentDataAddr; m_currentDataAddr += symbol.bytes.size(); @@ -1037,8 +1037,8 @@ namespace dragon for (auto& line : m_rawCodeSection) { String lineEdit(line); - uint32_t commaCount = lineEdit.count(","); - uint32_t spaceCount = lineEdit.count(" "); + u32 commaCount = lineEdit.count(","); + u32 spaceCount = lineEdit.count(" "); if (lineEdit.endsWith(":") && commaCount == 0 && spaceCount == 0) //Labels { lineEdit = lineEdit.substr(0, lineEdit.len() - 1); @@ -1052,8 +1052,8 @@ namespace dragon for (auto& line : m_rawCodeSection) { String lineEdit(line); - uint32_t commaCount = lineEdit.count(","); - uint32_t spaceCount = lineEdit.count(" "); + u32 commaCount = lineEdit.count(","); + u32 spaceCount = lineEdit.count(" "); if (lineEdit.endsWith(":") && commaCount == 0 && spaceCount == 0) //Labels { // _disassembly_line.addr = m_dataSize + m_loadAddress + m_code.size() + 3; @@ -1076,7 +1076,7 @@ namespace dragon std::cout << "Invalid code in .low directive. Must be numeric byte strem, space-separated: " << line << "\n"; return; } - m_code.push_back((int8_t)token.toInt()); + m_code.push_back((i8)token.toInt()); } _disassembly_line.code = lineEdit; _disassembly_line.code.add(" (%low)"); @@ -1170,8 +1170,8 @@ namespace dragon instEdit.trim().toLower(); String opEdit(lineEdit.new_substr(lineEdit.indexOf(" ") + 1)); opEdit.trim(); - int16_t word1 = 0x0000; - int16_t word2 = 0x0000; + i16 word1 = 0x0000; + i16 word2 = 0x0000; auto st = opEdit.tokenize(","); eOperandType opType1 = parseOperand(st.next(), word1); if (opType1 == eOperandType::Immediate) @@ -1181,8 +1181,8 @@ namespace dragon { 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)); + m_code.push_back(static_cast(word1)); + m_code.push_back(static_cast(word2)); break; default: std::cout << "Invalid operand2 type; " << line << " (" << opEdit << ")\n"; @@ -1231,7 +1231,7 @@ namespace dragon instEdit.trim().toLower(); String opEdit(lineEdit.new_substr(lineEdit.indexOf(" ") + 1)); opEdit.trim(); - int16_t word = 0x0000; + i16 word = 0x0000; if (STDVEC_CONTAINS(cpuExtensions, "extalu")) { if (instEdit == "notip") @@ -1245,7 +1245,7 @@ namespace dragon return; } m_code.push_back(hw::cpuext::ExtAlu::OpCodes::notip_reg); - m_code.push_back((uint8_t)word); + m_code.push_back((u8)word); return; } } @@ -1266,7 +1266,7 @@ namespace dragon return; } m_code.push_back(data::OpCodes::IncReg); - m_code.push_back((uint8_t)word); + m_code.push_back((u8)word); return; } else if (instEdit == "dec") @@ -1279,7 +1279,7 @@ namespace dragon return; } m_code.push_back(data::OpCodes::DecReg); - m_code.push_back((uint8_t)word); + m_code.push_back((u8)word); return; } else if (instEdit == "arg") @@ -1292,7 +1292,7 @@ namespace dragon return; } m_code.push_back(data::OpCodes::ArgReg); - m_code.push_back((uint8_t)word); + m_code.push_back((u8)word); return; } else if (instEdit == "push") @@ -1305,14 +1305,14 @@ namespace dragon // 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)); - m_code.push_back((uint8_t)(word & 0x00FF)); + m_code.push_back((u8)((word & 0xFF00) >> 8)); + m_code.push_back((u8)(word & 0x00FF)); } else if (opType == eOperandType::Register) { // m_code.push_back(data::OpCodes::PushReg); m_code[m_code.size() - 1] = data::OpCodes::PushReg; - m_code.push_back((uint8_t)word); + m_code.push_back((u8)word); } else { @@ -1331,7 +1331,7 @@ namespace dragon return; } m_code.push_back(data::OpCodes::PopReg); - m_code.push_back((uint8_t)word); + m_code.push_back((u8)word); return; } else if (instEdit == "call") @@ -1341,13 +1341,13 @@ namespace dragon if (opType == eOperandType::Immediate || opType == eOperandType::Label) { m_code[m_code.size() - 1] = data::OpCodes::CallImm; - m_code.push_back((uint8_t)((word & 0xFF00) >> 8)); - m_code.push_back((uint8_t)(word & 0x00FF)); + m_code.push_back((u8)((word & 0xFF00) >> 8)); + m_code.push_back((u8)(word & 0x00FF)); } else if (opType == eOperandType::Register) { m_code[m_code.size() - 1] = data::OpCodes::CallReg; - m_code.push_back((uint8_t)word); + m_code.push_back((u8)word); } else { @@ -1366,7 +1366,7 @@ namespace dragon return; } m_code.push_back(data::OpCodes::NotReg); - m_code.push_back((uint8_t)word); + m_code.push_back((u8)word); return; } else if (instEdit == "neg") @@ -1379,7 +1379,7 @@ namespace dragon return; } m_code.push_back(data::OpCodes::NegReg); - m_code.push_back((uint8_t)word); + m_code.push_back((u8)word); return; } else if (instEdit == "negb") @@ -1392,7 +1392,7 @@ namespace dragon return; } m_code.push_back(data::OpCodes::NegByteReg); - m_code.push_back((uint8_t)word); + m_code.push_back((u8)word); return; } else if (instEdit == "jmp") @@ -1405,8 +1405,8 @@ namespace dragon exit(0); return; } - m_code.push_back((uint8_t)((word & 0xFF00) >> 8)); - m_code.push_back((uint8_t)(word & 0x00FF)); + m_code.push_back((u8)((word & 0xFF00) >> 8)); + m_code.push_back((u8)(word & 0x00FF)); return; } else if (instEdit == "int") @@ -1419,7 +1419,7 @@ namespace dragon return; } m_code.push_back(data::OpCodes::Int); - m_code.push_back((uint8_t)word); + m_code.push_back((u8)word); return; } else if (instEdit == "zflg") @@ -1432,7 +1432,7 @@ namespace dragon return; } m_code.push_back(data::OpCodes::ZeroFlag); - m_code.push_back((uint8_t)word); + m_code.push_back((u8)word); return; } else if (instEdit == "sflg") @@ -1445,7 +1445,7 @@ namespace dragon return; } m_code.push_back(data::OpCodes::SetFlag); - m_code.push_back((uint8_t)word); + m_code.push_back((u8)word); return; } else if (instEdit == "tflg") @@ -1458,7 +1458,7 @@ namespace dragon return; } m_code.push_back(data::OpCodes::ToggleFlag); - m_code.push_back((uint8_t)word); + m_code.push_back((u8)word); return; } else @@ -1475,7 +1475,7 @@ namespace dragon instEdit.trim().toLower(); String opEdit(lineEdit.new_substr(lineEdit.indexOf(" ") + 1)); opEdit.trim(); - int16_t word = 0x0000; + i16 word = 0x0000; auto st = opEdit.tokenize(","); if (STDVEC_CONTAINS(cpuExtensions, "extalu")) { @@ -1491,7 +1491,7 @@ namespace dragon exit(0); return; } - m_code.push_back((uint8_t)word); + m_code.push_back((u8)word); opType = parseOperand(st.next(), word); if (opType == eOperandType::Immediate) @@ -1507,8 +1507,8 @@ namespace dragon else if (instEdit == "orip") m_code[m_code.size() - 2] = hw::cpuext::ExtAlu::OpCodes::orip_imm_in_reg; else if (instEdit == "andip") m_code[m_code.size() - 2] = hw::cpuext::ExtAlu::OpCodes::andip_imm_in_reg; else if (instEdit == "xorip") m_code[m_code.size() - 2] = hw::cpuext::ExtAlu::OpCodes::xorip_imm_in_reg; - m_code.push_back((uint8_t)((word & 0xFF00) >> 8)); - m_code.push_back((uint8_t)(word & 0x00FF)); + m_code.push_back((u8)((word & 0xFF00) >> 8)); + m_code.push_back((u8)(word & 0x00FF)); } else if (opType == eOperandType::Register) { @@ -1523,7 +1523,7 @@ namespace dragon else if (instEdit == "orip") m_code[m_code.size() - 2] = hw::cpuext::ExtAlu::OpCodes::orip_reg_in_reg; else if (instEdit == "andip") m_code[m_code.size() - 2] = hw::cpuext::ExtAlu::OpCodes::andip_reg_in_reg; else if (instEdit == "xorip") m_code[m_code.size() - 2] = hw::cpuext::ExtAlu::OpCodes::xorip_reg_in_reg; - m_code.push_back((uint8_t)word); + m_code.push_back((u8)word); } else { @@ -1545,33 +1545,33 @@ namespace dragon if (instEdit == "mov") { m_code.push_back(0x00); - int16_t word1 = 0x0000; - int16_t word2 = 0x0000; + i16 word1 = 0x0000; + i16 word2 = 0x0000; eOperandType opType1 = parseOperand(st.next(), word1); if (opType1 == eOperandType::Register) { - m_code.push_back((uint8_t)word1); + m_code.push_back((u8)word1); eOperandType opType2 = parseOperand(st.next(), word2); switch (opType2) { case eOperandType::Immediate: case eOperandType::Label: m_code[m_code.size() - 2] = data::OpCodes::MovImmReg; - m_code.push_back((uint8_t)((word2 & 0xFF00) >> 8)); - m_code.push_back((uint8_t)(word2 & 0x00FF)); + m_code.push_back((u8)((word2 & 0xFF00) >> 8)); + m_code.push_back((u8)(word2 & 0x00FF)); break; case eOperandType::Register: m_code[m_code.size() - 2] = data::OpCodes::MovRegReg; - m_code.push_back((uint8_t)word2); + m_code.push_back((u8)word2); break; case eOperandType::DerefMemory: m_code[m_code.size() - 2] = data::OpCodes::MovMemReg; - m_code.push_back((uint8_t)((word2 & 0xFF00) >> 8)); - m_code.push_back((uint8_t)(word2 & 0x00FF)); + m_code.push_back((u8)((word2 & 0xFF00) >> 8)); + m_code.push_back((u8)(word2 & 0x00FF)); break; case eOperandType::DerefRegister: m_code[m_code.size() - 2] = data::OpCodes::MovDerefRegReg; - m_code.push_back((uint8_t)word2); + m_code.push_back((u8)word2); return; break; default: @@ -1582,24 +1582,24 @@ namespace dragon } else if (opType1 == eOperandType::DerefMemory) { - m_code.push_back((uint8_t)((word1 & 0xFF00) >> 8)); - m_code.push_back((uint8_t)(word1 & 0x00FF)); + m_code.push_back((u8)((word1 & 0xFF00) >> 8)); + m_code.push_back((u8)(word1 & 0x00FF)); eOperandType opType2 = parseOperand(st.next(), word2); switch (opType2) { case eOperandType::Register: m_code[m_code.size() - 3] = data::OpCodes::MovRegMem; - m_code.push_back((uint8_t)word2); + m_code.push_back((u8)word2); break; case eOperandType::DerefRegister: m_code[m_code.size() - 3] = data::OpCodes::MovDerefRegMem; - m_code.push_back((uint8_t)word2); + m_code.push_back((u8)word2); break; case eOperandType::Immediate: case eOperandType::Label: m_code[m_code.size() - 3] = data::OpCodes::MovImmMem; - m_code.push_back((uint8_t)((word2 & 0xFF00) >> 8)); - m_code.push_back((uint8_t)(word2 & 0x00FF)); + m_code.push_back((u8)((word2 & 0xFF00) >> 8)); + m_code.push_back((u8)(word2 & 0x00FF)); break; default: std::cout << "Invalid operand type; " << line << " (" << opEdit << ")\n"; @@ -1609,28 +1609,28 @@ namespace dragon } else if (opType1 == eOperandType::DerefRegister) { - m_code.push_back((uint8_t)word1); + m_code.push_back((u8)word1); eOperandType opType2 = parseOperand(st.next(), word2); switch (opType2) { case eOperandType::Register: m_code[m_code.size() - 2] = data::OpCodes::MovRegDerefReg; - m_code.push_back((uint8_t)word2); + m_code.push_back((u8)word2); break; case eOperandType::DerefMemory: m_code[m_code.size() - 2] = data::OpCodes::MovMemDerefReg; - m_code.push_back((uint8_t)((word2 & 0xFF00) >> 8)); - m_code.push_back((uint8_t)(word2 & 0x00FF)); + m_code.push_back((u8)((word2 & 0xFF00) >> 8)); + m_code.push_back((u8)(word2 & 0x00FF)); break; case eOperandType::Immediate: case eOperandType::Label: m_code[m_code.size() - 2] = data::OpCodes::MovImmDerefReg; - m_code.push_back((uint8_t)((word2 & 0xFF00) >> 8)); - m_code.push_back((uint8_t)(word2 & 0x00FF)); + m_code.push_back((u8)((word2 & 0xFF00) >> 8)); + m_code.push_back((u8)(word2 & 0x00FF)); break; case eOperandType::DerefRegister: m_code[m_code.size() - 2] = data::OpCodes::MovDerefRegDerefReg; - m_code.push_back((uint8_t)word2); + m_code.push_back((u8)word2); return; break; default: @@ -1644,27 +1644,27 @@ namespace dragon else if (instEdit == "movb") { m_code.push_back(0x00); - int16_t word1 = 0x0000; - int16_t word2 = 0x0000; + i16 word1 = 0x0000; + i16 word2 = 0x0000; eOperandType opType1 = parseOperand(st.next(), word1); if (opType1 == eOperandType::DerefMemory) { - m_code.push_back((uint8_t)((word1 & 0xFF00) >> 8)); - m_code.push_back((uint8_t)(word1 & 0x00FF)); + m_code.push_back((u8)((word1 & 0xFF00) >> 8)); + m_code.push_back((u8)(word1 & 0x00FF)); eOperandType opType2 = parseOperand(st.next(), word2); switch (opType2) { case eOperandType::Immediate: m_code[m_code.size() - 3] = data::OpCodes::MovByteImmMem; - m_code.push_back((uint8_t)word2); + m_code.push_back((u8)word2); break; case eOperandType::DerefRegister: m_code[m_code.size() - 3] = data::OpCodes::MovByteDerefRegMem; - m_code.push_back((uint8_t)word2); + m_code.push_back((u8)word2); break; case eOperandType::Register: m_code[m_code.size() - 3] = data::OpCodes::MovByteRegMem; - m_code.push_back((uint8_t)word2); + m_code.push_back((u8)word2); break; default: std::cout << "Invalid operand type; " << line << " (" << opEdit << ")\n"; @@ -1674,26 +1674,26 @@ namespace dragon } else if (opType1 == eOperandType::DerefRegister) { - m_code.push_back((uint8_t)word1); + m_code.push_back((u8)word1); eOperandType opType2 = parseOperand(st.next(), word2); switch (opType2) { case eOperandType::Register: m_code[m_code.size() - 2] = data::OpCodes::MovByteRegDerefReg; - m_code.push_back((uint8_t)word2); + m_code.push_back((u8)word2); break; case eOperandType::DerefMemory: m_code[m_code.size() - 2] = data::OpCodes::MovByteMemDerefReg; - m_code.push_back((uint8_t)((word2 & 0xFF00) >> 8)); - m_code.push_back((uint8_t)(word2 & 0x00FF)); + m_code.push_back((u8)((word2 & 0xFF00) >> 8)); + m_code.push_back((u8)(word2 & 0x00FF)); break; case eOperandType::Immediate: m_code[m_code.size() - 2] = data::OpCodes::MovByteImmDerefReg; - m_code.push_back((uint8_t)word2); + m_code.push_back((u8)word2); break; case eOperandType::DerefRegister: m_code[m_code.size() - 2] = data::OpCodes::MovByteDerefRegDerefReg; - m_code.push_back((uint8_t)word2); + m_code.push_back((u8)word2); return; break; default: @@ -1704,22 +1704,22 @@ namespace dragon } else if (opType1 == eOperandType::Register) { - m_code.push_back((uint8_t)word1); + m_code.push_back((u8)word1); eOperandType opType2 = parseOperand(st.next(), word2); switch (opType2) { case eOperandType::Immediate: m_code[m_code.size() - 2] = data::OpCodes::MovByteImmReg; - m_code.push_back((uint8_t)word2); + m_code.push_back((u8)word2); break; case eOperandType::DerefMemory: m_code[m_code.size() - 2] = data::OpCodes::MovByteMemReg; - m_code.push_back((uint8_t)((word2 & 0xFF00) >> 8)); - m_code.push_back((uint8_t)(word2 & 0x00FF)); + m_code.push_back((u8)((word2 & 0xFF00) >> 8)); + m_code.push_back((u8)(word2 & 0x00FF)); break; case eOperandType::DerefRegister: m_code[m_code.size() - 2] = data::OpCodes::MovByteDerefRegReg; - m_code.push_back((uint8_t)word2); + m_code.push_back((u8)word2); return; break; default: @@ -1740,7 +1740,7 @@ namespace dragon exit(0); return; } - m_code.push_back((uint8_t)word); + m_code.push_back((u8)word); opType = parseOperand(st.next(), word); if (opType == eOperandType::Immediate) @@ -1749,8 +1749,8 @@ namespace dragon else if (instEdit == "sub") m_code[m_code.size() - 2] = data::OpCodes::SubImmReg; else if (instEdit == "mul") m_code[m_code.size() - 2] = data::OpCodes::MulImmReg; else if (instEdit == "div") m_code[m_code.size() - 2] = data::OpCodes::DivImmReg; - m_code.push_back((uint8_t)((word & 0xFF00) >> 8)); - m_code.push_back((uint8_t)(word & 0x00FF)); + m_code.push_back((u8)((word & 0xFF00) >> 8)); + m_code.push_back((u8)(word & 0x00FF)); } else if (opType == eOperandType::Register) { @@ -1758,7 +1758,7 @@ namespace dragon else if (instEdit == "sub") m_code[m_code.size() - 2] = data::OpCodes::SubRegReg; else if (instEdit == "mul") m_code[m_code.size() - 2] = data::OpCodes::MulRegReg; else if (instEdit == "div") m_code[m_code.size() - 2] = data::OpCodes::DivRegReg; - m_code.push_back((uint8_t)word); + m_code.push_back((u8)word); } else { @@ -1777,7 +1777,7 @@ namespace dragon exit(0); return; } - uint8_t regAddr = (uint8_t)word; + u8 regAddr = (u8)word; opType = parseOperand(st.next(), word); if (opType == eOperandType::Immediate) { @@ -1786,9 +1786,9 @@ namespace dragon else if (instEdit == "and") m_code.push_back(data::OpCodes::AndRegImm); else if (instEdit == "or") m_code.push_back(data::OpCodes::OrRegImm); else if (instEdit == "xor") m_code.push_back(data::OpCodes::XorRegImm); - m_code.push_back((uint8_t)((word & 0xFF00) >> 8)); - m_code.push_back((uint8_t)(word & 0x00FF)); - m_code.push_back((uint8_t)regAddr); + m_code.push_back((u8)((word & 0xFF00) >> 8)); + m_code.push_back((u8)(word & 0x00FF)); + m_code.push_back((u8)regAddr); } else if (opType == eOperandType::Register) { @@ -1797,8 +1797,8 @@ namespace dragon else if (instEdit == "and") m_code.push_back(data::OpCodes::AndRegReg); else if (instEdit == "or") m_code.push_back(data::OpCodes::OrRegReg); else if (instEdit == "xor") m_code.push_back(data::OpCodes::XorRegReg); - m_code.push_back((uint8_t)word); - m_code.push_back((uint8_t)regAddr); + m_code.push_back((u8)word); + m_code.push_back((u8)regAddr); } else { @@ -1819,8 +1819,8 @@ namespace dragon exit(0); return; } - m_code.push_back((uint8_t)((word & 0xFF00) >> 8)); - m_code.push_back((uint8_t)(word & 0x00FF)); + m_code.push_back((u8)((word & 0xFF00) >> 8)); + m_code.push_back((u8)(word & 0x00FF)); opType = parseOperand(st.next(), word); if (opType == eOperandType::Immediate) @@ -1831,8 +1831,8 @@ namespace dragon else if (instEdit == "jls") m_code[m_code.size() - 3] = data::OpCodes::JmpLessImm; else if (instEdit == "jge") m_code[m_code.size() - 3] = data::OpCodes::JmpGeImm; else if (instEdit == "jle") m_code[m_code.size() - 3] = data::OpCodes::JmpLeImm; - m_code.push_back((uint8_t)((word & 0xFF00) >> 8)); - m_code.push_back((uint8_t)(word & 0x00FF)); + m_code.push_back((u8)((word & 0xFF00) >> 8)); + m_code.push_back((u8)(word & 0x00FF)); } else if (opType == eOperandType::Register) { @@ -1842,7 +1842,7 @@ namespace dragon else if (instEdit == "jls") m_code[m_code.size() - 3] = data::OpCodes::JmpLessReg; else if (instEdit == "jge") m_code[m_code.size() - 3] = data::OpCodes::JmpGeReg; else if (instEdit == "jle") m_code[m_code.size() - 3] = data::OpCodes::JmpLeReg; - m_code.push_back((uint8_t)word); + m_code.push_back((u8)word); } else { @@ -1868,10 +1868,10 @@ namespace dragon opEdit.trim(); if (STDVEC_CONTAINS(cpuExtensions, "extmov")) { - uint16_t code_offset = 1; - int16_t word1 = 0x0000; - int16_t word2 = 0x0000; - int16_t word3 = 0x0000; + u16 code_offset = 1; + i16 word1 = 0x0000; + i16 word2 = 0x0000; + i16 word3 = 0x0000; auto st = opEdit.tokenize(","); if (instEdit == "omov") { @@ -1886,7 +1886,7 @@ namespace dragon eOperandType opType1 = parseOperand(st.next(), word1); if (opType1 == eOperandType::DerefRegister) { - m_code.push_back((uint8_t)word1); + m_code.push_back((u8)word1); code_offset++; eOperandType opType2 = parseOperand(st.next(), word2); String op3 = st.next(); @@ -1901,12 +1901,12 @@ namespace dragon { case eOperandType::Immediate: case eOperandType::Label: - m_code.push_back((uint8_t)((word2 & 0xFF00) >> 8)); - m_code.push_back((uint8_t)(word2 & 0x00FF)); + m_code.push_back((u8)((word2 & 0xFF00) >> 8)); + m_code.push_back((u8)(word2 & 0x00FF)); code_offset += 2; break; case eOperandType::DerefRegister: - m_code.push_back((uint8_t)word2); + m_code.push_back((u8)word2); code_offset++; break; default: @@ -1929,8 +1929,8 @@ namespace dragon std::cout << "Invalid operand type; " << line << " (" << opEdit << ")\n"; exit(0); } - m_code.push_back((uint8_t)((word3 & 0xFF00) >> 8)); - m_code.push_back((uint8_t)(word3 & 0x00FF)); + m_code.push_back((u8)((word3 & 0xFF00) >> 8)); + m_code.push_back((u8)(word3 & 0x00FF)); code_offset += 2; } else @@ -1944,7 +1944,7 @@ namespace dragon std::cout << "Invalid operand type; " << line << " (" << opEdit << ")\n"; exit(0); } - m_code.push_back((uint8_t)word3); + m_code.push_back((u8)word3); code_offset++; } break; @@ -1958,7 +1958,7 @@ namespace dragon std::cout << "Invalid operand type; " << line << " (" << opEdit << ")\n"; exit(0); } - m_code.push_back((uint8_t)word3); + m_code.push_back((u8)word3); code_offset++; break; default: @@ -1969,8 +1969,8 @@ namespace dragon } else if (opType1 == eOperandType::DerefMemory) { - m_code.push_back((uint8_t)((word1 & 0xFF00) >> 8)); - m_code.push_back((uint8_t)(word1 & 0x00FF)); + m_code.push_back((u8)((word1 & 0xFF00) >> 8)); + m_code.push_back((u8)(word1 & 0x00FF)); code_offset += 2; eOperandType opType2 = parseOperand(st.next(), word2); String op3 = st.next(); @@ -1985,8 +1985,8 @@ namespace dragon { case eOperandType::Immediate: case eOperandType::Label: - m_code.push_back((uint8_t)((word2 & 0xFF00) >> 8)); - m_code.push_back((uint8_t)(word2 & 0x00FF)); + m_code.push_back((u8)((word2 & 0xFF00) >> 8)); + m_code.push_back((u8)(word2 & 0x00FF)); code_offset += 2; break; default: @@ -2001,20 +2001,20 @@ namespace dragon if (word_offset) { m_code[m_code.size() - code_offset] = hw::cpuext::ExtMov::OpCodes::wimm_in_mem_immoffw; - m_code.push_back((uint8_t)((word3 & 0xFF00) >> 8)); - m_code.push_back((uint8_t)(word3 & 0x00FF)); + m_code.push_back((u8)((word3 & 0xFF00) >> 8)); + m_code.push_back((u8)(word3 & 0x00FF)); code_offset += 2; } else { m_code[m_code.size() - code_offset] = hw::cpuext::ExtMov::OpCodes::wimm_in_mem_immoffb; - m_code.push_back((uint8_t)word3); + m_code.push_back((u8)word3); code_offset++; } break; case eOperandType::Register: m_code[m_code.size() - code_offset] = hw::cpuext::ExtMov::OpCodes::wimm_in_mem_regoff; - m_code.push_back((uint8_t)word3); + m_code.push_back((u8)word3); code_offset++; break; default: @@ -2043,7 +2043,7 @@ namespace dragon eOperandType opType1 = parseOperand(st.next(), word1); if (opType1 == eOperandType::DerefRegister) { - m_code.push_back((uint8_t)word1); + m_code.push_back((u8)word1); code_offset++; eOperandType opType2 = parseOperand(st.next(), word2); String op3 = st.next(); @@ -2058,11 +2058,11 @@ namespace dragon { case eOperandType::Immediate: case eOperandType::Label: - m_code.push_back((uint8_t)word2); + m_code.push_back((u8)word2); code_offset += 1; break; case eOperandType::DerefRegister: - m_code.push_back((uint8_t)word2); + m_code.push_back((u8)word2); code_offset++; break; default: @@ -2085,8 +2085,8 @@ namespace dragon std::cout << "Invalid operand type; " << line << " (" << opEdit << ")\n"; exit(0); } - m_code.push_back((uint8_t)((word3 & 0xFF00) >> 8)); - m_code.push_back((uint8_t)(word3 & 0x00FF)); + m_code.push_back((u8)((word3 & 0xFF00) >> 8)); + m_code.push_back((u8)(word3 & 0x00FF)); code_offset += 2; } else @@ -2100,7 +2100,7 @@ namespace dragon std::cout << "Invalid operand type; " << line << " (" << opEdit << ")\n"; exit(0); } - m_code.push_back((uint8_t)word3); + m_code.push_back((u8)word3); code_offset++; } break; @@ -2114,7 +2114,7 @@ namespace dragon std::cout << "Invalid operand type; " << line << " (" << opEdit << ")\n"; exit(0); } - m_code.push_back((uint8_t)word3); + m_code.push_back((u8)word3); code_offset++; break; default: @@ -2125,8 +2125,8 @@ namespace dragon } else if (opType1 == eOperandType::DerefMemory) { - m_code.push_back((uint8_t)((word1 & 0xFF00) >> 8)); - m_code.push_back((uint8_t)(word1 & 0x00FF)); + m_code.push_back((u8)((word1 & 0xFF00) >> 8)); + m_code.push_back((u8)(word1 & 0x00FF)); code_offset += 2; eOperandType opType2 = parseOperand(st.next(), word2); String op3 = st.next(); @@ -2141,7 +2141,7 @@ namespace dragon { case eOperandType::Immediate: case eOperandType::Label: - m_code.push_back((uint8_t)word2); + m_code.push_back((u8)word2); code_offset += 1; break; default: @@ -2156,20 +2156,20 @@ namespace dragon if (word_offset) { m_code[m_code.size() - code_offset] = hw::cpuext::ExtMov::OpCodes::bimm_in_mem_immoffw; - m_code.push_back((uint8_t)((word3 & 0xFF00) >> 8)); - m_code.push_back((uint8_t)(word3 & 0x00FF)); + m_code.push_back((u8)((word3 & 0xFF00) >> 8)); + m_code.push_back((u8)(word3 & 0x00FF)); code_offset += 2; } else { m_code[m_code.size() - code_offset] = hw::cpuext::ExtMov::OpCodes::bimm_in_mem_immoffb; - m_code.push_back((uint8_t)word3); + m_code.push_back((u8)word3); code_offset++; } break; case eOperandType::Register: m_code[m_code.size() - code_offset] = hw::cpuext::ExtMov::OpCodes::bimm_in_mem_regoff; - m_code.push_back((uint8_t)word3); + m_code.push_back((u8)word3); code_offset++; break; default: @@ -2198,7 +2198,7 @@ namespace dragon eOperandType opType1 = parseOperand(st.next(), word1); if (opType1 == eOperandType::Register) { - m_code.push_back((uint8_t)word1); + m_code.push_back((u8)word1); code_offset++; eOperandType opType2 = parseOperand(st.next(), word2); String op3 = st.next(); @@ -2212,12 +2212,12 @@ namespace dragon switch (opType2) { case eOperandType::DerefMemory: - m_code.push_back((uint8_t)((word2 & 0xFF00) >> 8)); - m_code.push_back((uint8_t)(word2 & 0x00FF)); + m_code.push_back((u8)((word2 & 0xFF00) >> 8)); + m_code.push_back((u8)(word2 & 0x00FF)); code_offset += 2; break; case eOperandType::DerefRegister: - m_code.push_back((uint8_t)word2); + m_code.push_back((u8)word2); code_offset++; break; default: @@ -2240,8 +2240,8 @@ namespace dragon std::cout << "Invalid operand type; " << line << " (" << opEdit << ")\n"; exit(0); } - m_code.push_back((uint8_t)((word3 & 0xFF00) >> 8)); - m_code.push_back((uint8_t)(word3 & 0x00FF)); + m_code.push_back((u8)((word3 & 0xFF00) >> 8)); + m_code.push_back((u8)(word3 & 0x00FF)); code_offset += 2; } else @@ -2255,7 +2255,7 @@ namespace dragon std::cout << "Invalid operand type; " << line << " (" << opEdit << ")\n"; exit(0); } - m_code.push_back((uint8_t)word3); + m_code.push_back((u8)word3); code_offset++; } break; @@ -2269,7 +2269,7 @@ namespace dragon std::cout << "Invalid operand type; " << line << " (" << opEdit << ")\n"; exit(0); } - m_code.push_back((uint8_t)word3); + m_code.push_back((u8)word3); code_offset++; break; default: @@ -2280,7 +2280,7 @@ namespace dragon } else if (opType1 == eOperandType::DerefRegister) { - m_code.push_back((uint8_t)word1); + m_code.push_back((u8)word1); code_offset++; eOperandType opType2 = parseOperand(st.next(), word2); String op3 = st.next(); @@ -2294,7 +2294,7 @@ namespace dragon switch (opType2) { case eOperandType::DerefRegister: - m_code.push_back((uint8_t)word2); + m_code.push_back((u8)word2); code_offset++; break; default: @@ -2309,20 +2309,20 @@ namespace dragon if (word_offset) { m_code[m_code.size() - code_offset] = hw::cpuext::ExtMov::OpCodes::wdreg_immoffw_in_dreg; - m_code.push_back((uint8_t)((word3 & 0xFF00) >> 8)); - m_code.push_back((uint8_t)(word3 & 0x00FF)); + m_code.push_back((u8)((word3 & 0xFF00) >> 8)); + m_code.push_back((u8)(word3 & 0x00FF)); code_offset += 2; } else { m_code[m_code.size() - code_offset] = hw::cpuext::ExtMov::OpCodes::wdreg_immoffb_in_dreg; - m_code.push_back((uint8_t)word3); + m_code.push_back((u8)word3); code_offset++; } break; case eOperandType::Register: m_code[m_code.size() - code_offset] = hw::cpuext::ExtMov::OpCodes::wdreg_regoff_in_dreg; - m_code.push_back((uint8_t)word3); + m_code.push_back((u8)word3); code_offset++; break; default: @@ -2351,7 +2351,7 @@ namespace dragon eOperandType opType1 = parseOperand(st.next(), word1); if (opType1 == eOperandType::Register) { - m_code.push_back((uint8_t)word1); + m_code.push_back((u8)word1); code_offset++; eOperandType opType2 = parseOperand(st.next(), word2); String op3 = st.next(); @@ -2365,12 +2365,12 @@ namespace dragon switch (opType2) { case eOperandType::DerefMemory: - m_code.push_back((uint8_t)((word2 & 0xFF00) >> 8)); - m_code.push_back((uint8_t)(word2 & 0x00FF)); + m_code.push_back((u8)((word2 & 0xFF00) >> 8)); + m_code.push_back((u8)(word2 & 0x00FF)); code_offset += 2; break; case eOperandType::DerefRegister: - m_code.push_back((uint8_t)word2); + m_code.push_back((u8)word2); code_offset++; break; default: @@ -2393,8 +2393,8 @@ namespace dragon std::cout << "Invalid operand type; " << line << " (" << opEdit << ")\n"; exit(0); } - m_code.push_back((uint8_t)((word3 & 0xFF00) >> 8)); - m_code.push_back((uint8_t)(word3 & 0x00FF)); + m_code.push_back((u8)((word3 & 0xFF00) >> 8)); + m_code.push_back((u8)(word3 & 0x00FF)); code_offset += 2; } else @@ -2408,7 +2408,7 @@ namespace dragon std::cout << "Invalid operand type; " << line << " (" << opEdit << ")\n"; exit(0); } - m_code.push_back((uint8_t)word3); + m_code.push_back((u8)word3); code_offset++; } break; @@ -2422,7 +2422,7 @@ namespace dragon std::cout << "Invalid operand type; " << line << " (" << opEdit << ")\n"; exit(0); } - m_code.push_back((uint8_t)word3); + m_code.push_back((u8)word3); code_offset++; break; default: @@ -2433,7 +2433,7 @@ namespace dragon } else if (opType1 == eOperandType::DerefRegister) { - m_code.push_back((uint8_t)word1); + m_code.push_back((u8)word1); code_offset++; eOperandType opType2 = parseOperand(st.next(), word2); String op3 = st.next(); @@ -2447,7 +2447,7 @@ namespace dragon switch (opType2) { case eOperandType::DerefRegister: - m_code.push_back((uint8_t)word2); + m_code.push_back((u8)word2); code_offset++; break; default: @@ -2462,20 +2462,20 @@ namespace dragon if (word_offset) { m_code[m_code.size() - code_offset] = hw::cpuext::ExtMov::OpCodes::bdreg_immoffw_in_dreg; - m_code.push_back((uint8_t)((word3 & 0xFF00) >> 8)); - m_code.push_back((uint8_t)(word3 & 0x00FF)); + m_code.push_back((u8)((word3 & 0xFF00) >> 8)); + m_code.push_back((u8)(word3 & 0x00FF)); code_offset += 2; } else { m_code[m_code.size() - code_offset] = hw::cpuext::ExtMov::OpCodes::bdreg_immoffb_in_dreg; - m_code.push_back((uint8_t)word3); + m_code.push_back((u8)word3); code_offset++; } break; case eOperandType::Register: m_code[m_code.size() - code_offset] = hw::cpuext::ExtMov::OpCodes::bdreg_regoff_in_dreg; - m_code.push_back((uint8_t)word3); + m_code.push_back((u8)word3); code_offset++; break; default: @@ -2503,7 +2503,7 @@ namespace dragon void Assembler::combineDataAndCode(void) { - uint16_t entryAddr = m_dataSize + m_loadAddress + 3; + u16 entryAddr = m_dataSize + m_loadAddress + 3; if (m_entry_lbl != "") { if (m_labelTable.count("$" + m_entry_lbl) == 0) @@ -2518,20 +2518,20 @@ namespace dragon std::vector symbols; ostd::ByteStream newCode; newCode.push_back(data::OpCodes::Jmp); - newCode.push_back((uint8_t)((entryAddr & 0xFF00) >> 8)); - newCode.push_back((uint8_t)(entryAddr & 0x00FF)); + newCode.push_back((u8)((entryAddr & 0xFF00) >> 8)); + newCode.push_back((u8)(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(), { (u16)(m_loadAddress + 3), "[----------DATA_SECTION----------]" }); 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); - for (int32_t i = 0; i < d.second.bytes.size(); i++) + for (i32 i = 0; i < d.second.bytes.size(); i++) newCode.push_back(0x00); } - for (int32_t i = symbols.size() - 1; i >= 0; i--) + for (i32 i = symbols.size() - 1; i >= 0; i--) { - for (int32_t j = 0; j < symbols[i].bytes.size(); j++) + for (i32 j = 0; j < symbols[i].bytes.size(); j++) newCode[symbols[i].address - m_loadAddress + j] = symbols[i].bytes[j]; } for (auto& b : m_code) @@ -2541,7 +2541,7 @@ namespace dragon m_disassembly.push_back({ 0xFFFFFF00, "{ DATA }" }); for (auto& d : m_symbolTable) { - m_disassembly.push_back({ d.second.address, d.first, (uint16_t)d.second.bytes.size() }); + m_disassembly.push_back({ d.second.address, d.first, (u16)d.second.bytes.size() }); } m_disassembly.push_back({ 0xFFFFFF01, "{ LABELS }" }); for (auto& l : m_labelTable) @@ -2574,13 +2574,13 @@ namespace dragon { for (auto& addr : label.second.references) { - m_code[addr] = (uint8_t)((label.second.address & 0xFF00) >> 8); - m_code[addr + 1] = (uint8_t)(label.second.address & 0x00FF); + m_code[addr] = (u8)((label.second.address & 0xFF00) >> 8); + m_code[addr + 1] = (u8)(label.second.address & 0x00FF); } } } - Assembler::eOperandType Assembler::parseOperand(String op, int16_t& outOp) + Assembler::eOperandType Assembler::parseOperand(String op, i16& outOp) { String opEdit(op); bool derefReg = false; @@ -2590,10 +2590,10 @@ namespace dragon opEdit.trim(); derefReg = true; } - int8_t reg = parseRegister(opEdit); + i8 reg = parseRegister(opEdit); if (reg != data::Registers::Last) { - outOp = (int16_t)reg; + outOp = (i16)reg; if (derefReg) return eOperandType::DerefRegister; return eOperandType::Register; @@ -2607,13 +2607,13 @@ namespace dragon std::cout << "Invalid numeric value: " << opEdit << "\n"; return eOperandType::Error; } - uint8_t _reg = opEdit.toInt(); + u8 _reg = opEdit.toInt(); if (_reg >= data::Registers::Last) { std::cout << "Invalid Register: " << opEdit << "\n"; return eOperandType::Error; } - outOp = (int16_t)_reg; + outOp = (i16)_reg; if (derefReg) return eOperandType::DerefRegister; return eOperandType::Register; @@ -2625,7 +2625,7 @@ namespace dragon } if (opEdit.isNumeric()) { - outOp = (int16_t)opEdit.toInt(); + outOp = (i16)opEdit.toInt(); return eOperandType::Immediate; } if (opEdit.startsWith("$")) @@ -2635,10 +2635,10 @@ namespace dragon std::cout << "Unknown symbol: " << opEdit << "\n"; return eOperandType::Error; } - uint16_t labelAddr = m_labelTable[opEdit].address; + u16 labelAddr = m_labelTable[opEdit].address; if (labelAddr == 0x0000) m_labelTable[opEdit].references.push_back(m_code.size()); - outOp = (int16_t)labelAddr; + outOp = (i16)labelAddr; // std::cout << "LABEL: " << opEdit << "\n"; // std::cout << " : " << String::getHexStr(labelAddr, true, 2) << "\n"; // std::cout << " : " << String::getHexStr(outOp, true, 2) << "\n"; @@ -2648,7 +2648,7 @@ namespace dragon { opEdit = opEdit.substr(1, opEdit.len() - 1); opEdit.trim(); - outOp = (int16_t)ostd::MathUtils::solveIntegerExpression(opEdit); + outOp = (i16)ostd::MathUtils::solveIntegerExpression(opEdit); return eOperandType::Immediate; } if (opEdit.startsWith("[") && opEdit.endsWith("]")) @@ -2659,7 +2659,7 @@ namespace dragon { opEdit = opEdit.substr(1, opEdit.len() - 1); opEdit.trim(); - outOp = (int16_t)ostd::MathUtils::solveIntegerExpression(opEdit); + outOp = (i16)ostd::MathUtils::solveIntegerExpression(opEdit); return eOperandType::DerefMemory; } if (!opEdit.isNumeric()) @@ -2667,13 +2667,13 @@ namespace dragon std::cout << "Invalid numeric value: " << opEdit << "\n"; return eOperandType::Error; } - outOp = (int16_t)opEdit.toInt(); + outOp = (i16)opEdit.toInt(); return eOperandType::DerefMemory; } return eOperandType::Error; } - uint8_t Assembler::parseRegister(String op) + u8 Assembler::parseRegister(String op) { String opEdit(op); opEdit.trim().toLower(); diff --git a/src/assembler/Assembler.hpp b/src/assembler/Assembler.hpp index d81a50c..a709bbc 100644 --- a/src/assembler/Assembler.hpp +++ b/src/assembler/Assembler.hpp @@ -37,27 +37,27 @@ namespace dragon }; public: struct tDisassemblyLine { - uint32_t addr = 0; + u32 addr = 0; String code = ""; - uint16_t size = 1; + u16 size = 1; inline bool operator<(const tDisassemblyLine& second) const { return addr < second.addr; } inline bool operator>(const tDisassemblyLine& second) const { return addr > second.addr; } }; public: struct tSymbol { std::vector bytes; - uint16_t address { 0 }; + u16 address { 0 }; }; public: struct tLabel { - std::vector references; - uint16_t address { 0 }; + std::vector references; + u16 address { 0 }; }; public: struct tStructMember { String name; - std::vector data; - int32_t position; + std::vector data; + i32 position; inline bool operator<(const tStructMember& second) const { return position < second.position; } inline bool operator>(const tStructMember& second) const { return position > second.position; } }; @@ -65,7 +65,7 @@ namespace dragon { String name; std::vector members; - int32_t size; + i32 size; }; public: struct tExportSpec { @@ -91,7 +91,7 @@ namespace dragon String source_file_path { "" }; String dest_file_path { "" }; bool save_disassembly { false }; - int32_t verbose_level { 0xFF }; + i32 verbose_level { 0xFF }; bool debug_mode { false }; bool save_exports { true }; String disassembly_file_path { "" }; @@ -101,24 +101,24 @@ namespace dragon }; public: - static int32_t loadArguments(int argc, char** argv); + static i32 loadArguments(int argc, char** argv); static void print_application_help(void); public: inline static tCommandLineArgs args; - inline static const int32_t RETURN_VAL_EXIT_SUCCESS = 0; - inline static const int32_t RETURN_VAL_CLOSE_PROGRAM = 512; - inline static const int32_t RETURN_VAL_TOO_FEW_ARGUMENTS = 1; - inline static const int32_t RETURN_VAL_MISSING_PARAM = 2; - inline static const int32_t RETURN_VAL_INVALID_PARAM = 3; + inline static const i32 RETURN_VAL_EXIT_SUCCESS = 0; + inline static const i32 RETURN_VAL_CLOSE_PROGRAM = 512; + inline static const i32 RETURN_VAL_TOO_FEW_ARGUMENTS = 1; + inline static const i32 RETURN_VAL_MISSING_PARAM = 2; + inline static const i32 RETURN_VAL_INVALID_PARAM = 3; }; public: 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 ostd::ByteStream assembleToVirtualDisk(String fileName, hw::VirtualHardDrive& vhdd, u32 address); static bool saveDisassemblyToFile(String fileName); - static void printProgramInfo(int32_t verbose_level = 1); + static void printProgramInfo(i32 verbose_level = 1); private: static void insertHeader(void); @@ -148,8 +148,8 @@ namespace dragon static String replaceSymbols(String line); static void replaceLabelRefs(void); - static eOperandType parseOperand(String op, int16_t& outOp); - static uint8_t parseRegister(String op); + static eOperandType parseOperand(String op, i16& outOp); + static u8 parseRegister(String op); private: inline static String m_rawSource { "" }; @@ -162,12 +162,12 @@ namespace dragon 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 }; - inline static uint16_t m_loadAddress { 0x0000 }; - inline static uint16_t m_currentDataAddr { 0x0000 }; - inline static uint16_t m_dataSize { 0x0000 }; - inline static uint16_t m_programSize { 0x0000 }; + inline static u16 m_fixedSize { 0 }; + inline static u8 m_fixedFillValue { 0x00 }; + inline static u16 m_loadAddress { 0x0000 }; + inline static u16 m_currentDataAddr { 0x0000 }; + inline static u16 m_dataSize { 0x0000 }; + inline static u16 m_programSize { 0x0000 }; inline static String m_entry_lbl { "" }; inline static String m_headerStr { "" }; diff --git a/src/assembler/DASMApp.cpp b/src/assembler/DASMApp.cpp index a0e1f00..e63a6f9 100644 --- a/src/assembler/DASMApp.cpp +++ b/src/assembler/DASMApp.cpp @@ -7,7 +7,7 @@ namespace dragon { namespace code { - int32_t Assembler::Application::loadArguments(int argc, char** argv) + i32 Assembler::Application::loadArguments(int argc, char** argv) { if (argc < 2) { @@ -27,7 +27,7 @@ namespace dragon bool disable_extmov = false; bool disable_extalu = false; args.verbose_level = -1; - for (int32_t i = 2; i < argc; i++) + for (i32 i = 2; i < argc; i++) { String edit(argv[i]); if (edit == "-o") @@ -106,7 +106,7 @@ namespace dragon void Assembler::Application::print_application_help(void) { - int32_t commandLength = 46; + i32 commandLength = 46; out.nl().fg(ostd::ConsoleColors::Yellow).p("List of available parameters:").reset().nl(); String tmpCommand = "--save-disassembly "; diff --git a/src/assembler/IncludePreprocessor.cpp b/src/assembler/IncludePreprocessor.cpp index 1dbef0e..a2fe7b1 100644 --- a/src/assembler/IncludePreprocessor.cpp +++ b/src/assembler/IncludePreprocessor.cpp @@ -62,7 +62,7 @@ namespace dragon do { included = false; - uint32_t i = 0; + u32 i = 0; for ( ; i < lines.size(); i++) { String line = lines[i]; diff --git a/src/assembler/assembler_main.cpp b/src/assembler/assembler_main.cpp index af9264d..2464157 100644 --- a/src/assembler/assembler_main.cpp +++ b/src/assembler/assembler_main.cpp @@ -3,7 +3,7 @@ int main(int argc, char** argv) { - int32_t rValue = dragon::code::Assembler::Application::loadArguments(argc, argv); + i32 rValue = dragon::code::Assembler::Application::loadArguments(argc, argv); if (rValue == dragon::code::Assembler::Application::RETURN_VAL_CLOSE_PROGRAM) return dragon::code::Assembler::Application::RETURN_VAL_EXIT_SUCCESS; if (rValue != dragon::code::Assembler::Application::RETURN_VAL_EXIT_SUCCESS) diff --git a/src/debugger/Debugger.cpp b/src/debugger/Debugger.cpp index f32d5b2..e2d0531 100644 --- a/src/debugger/Debugger.cpp +++ b/src/debugger/Debugger.cpp @@ -28,13 +28,13 @@ namespace dragon //Debugger::Utils - DisassemblyList Debugger::Utils::findCodeRegion(const DisassemblyList& code, uint16_t address, uint16_t codeRegionMargin) + DisassemblyList Debugger::Utils::findCodeRegion(const DisassemblyList& code, u16 address, u16 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++) + u16 start = 0; + u16 end = (codeRegionMargin * 2); + for (i32 i = 0; i < code.size(); i++) { if (code[i].addr != address) continue; if (i + 1 <= codeRegionMargin) break; @@ -48,12 +48,12 @@ namespace dragon end = i + codeRegionMargin; break; } - for (int16_t i = start; i <= end; i++) + for (i16 i = start; i <= end; i++) codeRegion.push_back(code[i]); return codeRegion; } - String Debugger::Utils::findSymbol(const DisassemblyList& list, uint16_t address, uint16_t* outSize) + String Debugger::Utils::findSymbol(const DisassemblyList& list, u16 address, u16* outSize) { for (auto& line : list) { @@ -67,7 +67,7 @@ namespace dragon return ""; } - uint16_t Debugger::Utils::findSymbol(const DisassemblyList& list, const String& symbol, uint16_t* outSize) + u16 Debugger::Utils::findSymbol(const DisassemblyList& list, const String& symbol, u16* outSize) { for (auto& line : list) { @@ -88,11 +88,11 @@ namespace dragon void Debugger::Utils::clearConsoleLine(void) { - for (int32_t i = 0; i < ostd::BasicConsole::getConsoleWidth(); i++) + for (i32 i = 0; i < ostd::BasicConsole::getConsoleWidth(); i++) out.p("\b"); - for (int32_t i = 0; i < ostd::BasicConsole::getConsoleWidth(); i++) + for (i32 i = 0; i < ostd::BasicConsole::getConsoleWidth(); i++) out.p(" "); - for (int32_t i = 0; i < ostd::BasicConsole::getConsoleWidth(); i++) + for (i32 i = 0; i < ostd::BasicConsole::getConsoleWidth(); i++) out.p("\b"); } @@ -115,7 +115,7 @@ namespace dragon ostd::ConsoleOutputHandler& Debugger::Utils::printFullLine(char c, const ostd::ConsoleColors::tConsoleColor& foreground) { - int32_t cw = ostd::BasicConsole::getConsoleWidth(); + i32 cw = ostd::BasicConsole::getConsoleWidth(); String str = String::duplicateChar(c, cw); out.fg(foreground).p(str).reset().nl(); return out; @@ -123,17 +123,17 @@ 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(); + i32 cw = ostd::BasicConsole::getConsoleWidth(); String str = String::duplicateChar(c, cw); out.bg(background).fg(foreground).p(str).reset().nl(); return out; } - void Debugger::Utils::removeBreakPoint(uint16_t addr) + void Debugger::Utils::removeBreakPoint(u16 addr) { if (debugger.manualBreakPoints.size() == 0) return; - int32_t i = 0; + i32 i = 0; for ( ; i < debugger.manualBreakPoints.size(); i++) { if (debugger.manualBreakPoints[i] == addr) @@ -144,14 +144,14 @@ namespace dragon debugger.manualBreakPoints.erase(debugger.manualBreakPoints.begin() + i); } - bool Debugger::Utils::isBreakPoint(uint16_t addr) + bool Debugger::Utils::isBreakPoint(u16 addr) { for (const auto& b : debugger.manualBreakPoints) if (b == addr) return true; return false; } - void Debugger::Utils::addBreakPoint(uint16_t addr) + void Debugger::Utils::addBreakPoint(u16 addr) { debugger.manualBreakPoints.push_back(addr); } @@ -172,7 +172,7 @@ namespace dragon String instEdit = rgxrstr.getRawString(); for (auto& label : labelList) { - int32_t index = -1; + i32 index = -1; String labelEdit = label.code; labelEdit.trim(); while ((index = instEdit.indexOf(labelEdit, index + 1)) != -1) @@ -230,9 +230,9 @@ namespace dragon void Debugger::Display::printStep(void) { out.clear(); - int32_t codeRegionSpan = 15; + i32 codeRegionSpan = 15; auto codeRegion = Utils::findCodeRegion(debugger.code, debugger.currentAddress, codeRegionSpan); - for (int32_t i = 0; i < codeRegion.size(); i++) + for (i32 i = 0; i < codeRegion.size(); i++) { auto& _da = codeRegion[i]; bool currentLine = _da.addr == debugger.currentAddress; @@ -326,7 +326,7 @@ namespace dragon str.replaceAll("*", ""); - int32_t item_len = 36; + i32 item_len = 36; const dragon::DragonRuntime::tMachineDebugInfo& minfo = dragon::DragonRuntime::getMachineInfoDiff(); String tmp = " ", tmpStyle = ""; @@ -354,7 +354,7 @@ namespace dragon tmp = " ", tmpStyle = ""; String prevCode = " ("; prevCode.add(minfo.previousInstructionOpCode).add(") "); - for (int32_t i = 0; i < minfo.previousInstructionFootprintSize; i++) + for (i32 i = 0; i < minfo.previousInstructionFootprintSize; i++) prevCode.add(String::getHexStr(minfo.previousInstructionFootprint[i], false, 1)).add(" "); tmp.add(prevCode); tmp.addPadding(item_len, ' ', String::ePaddingBehavior::AllowOddExtraLeft); @@ -365,7 +365,7 @@ namespace dragon // tmp = " "; // String currCode = " ("; // currCode.add(minfo.currentInstructionOpCode).add(") "); - // for (int32_t i = 0; i < minfo.currentInstructionFootprintSize; i++) + // for (i32 i = 0; i < minfo.currentInstructionFootprintSize; i++) // currCode.add(String::getHexStr(minfo.currentInstructionFootprint[i], false, 1)).add(" "); // tmp.add(currCode); // tmp.addPadding(item_len, ' ', String::ePaddingBehavior::AllowOddExtraLeft); @@ -898,14 +898,14 @@ namespace dragon { out.clear(); out.fg(ostd::ConsoleColors::Yellow).p("Tracked Data: ").reset().nl(); - const int32_t symbol_len = 24; - const int32_t size_len = 8; - const int32_t addr_len = 10; - const int32_t map_len = 8; - const int32_t prev_len = 35; + const i32 symbol_len = 24; + const i32 size_len = 8; + const i32 addr_len = 10; + const i32 map_len = 8; + const i32 prev_len = 35; const dragon::DragonRuntime::tMachineDebugInfo& minfo = dragon::DragonRuntime::getMachineInfoDiff(); if (minfo.trackedAddresses.size() == 0) return; - int32_t cw = ostd::BasicConsole::getConsoleWidth(); + i32 cw = ostd::BasicConsole::getConsoleWidth(); String header = "|Symbol"; header.addRightPadding(symbol_len); header.add("|Bytes"); @@ -934,9 +934,9 @@ namespace dragon h_sep.put(symbol_len + size_len + addr_len + map_len + prev_len, '|'); h_sep.put(cw - 1, '|'); out.fg(ostd::ConsoleColors::Blue).p(h_sep).reset().nl(); - for (int32_t i = 0; i < minfo.trackedAddresses.size(); i++) + for (i32 i = 0; i < minfo.trackedAddresses.size(); i++) { - uint16_t data_size = 1; + u16 data_size = 1; auto addr = minfo.trackedAddresses[i]; String symbol = Utils::findSymbol(debugger.data, addr, &data_size); if (symbol == "") @@ -970,7 +970,7 @@ namespace dragon out.fg(ostd::ConsoleColors::Blue).p("|").fg(ostd::ConsoleColors::BrightGray).p(tmp).reset(); tmp = ""; - if (addr >= (uint16_t)DragonRuntime::cpu.readRegister(data::Registers::SP)) + if (addr >= (u16)DragonRuntime::cpu.readRegister(data::Registers::SP)) tmp.add("STACK"); else tmp.add(DragonRuntime::memMap.getMemoryRegionName(addr)); @@ -979,7 +979,7 @@ namespace dragon tmp = ""; tmp.add(String::getHexStr(minfo.previousInstructionTrackedValues[i], false, 1)); - for (int32_t j = 1; j < data_size; j++) + for (i32 j = 1; j < data_size; j++) tmp.add(".").add(String::getHexStr(minfo.previousInstructionTrackedValues[i + j], false, 1)); tmp.fixedLength(prev_len - 1); if (no_symbol) @@ -989,12 +989,12 @@ namespace dragon tmp = ""; tmp.add(String::getHexStr(minfo.currentInstructionTrackedValues[i], false, 1)); - uint32_t tmp_i = i; - for (int32_t j = 1; j < data_size; j++, i++) + u32 tmp_i = i; + for (i32 j = 1; j < data_size; j++, i++) tmp.add(".").add(String::getHexStr(minfo.currentInstructionTrackedValues[i + 1], false, 1)); tmp.fixedLength(prev_len - 1); bool data_different = false; - for (int32_t j = 0; j < data_size; j++) + for (i32 j = 0; j < data_size; j++) { if (minfo.currentInstructionTrackedValues[tmp_i + j] != minfo.previousInstructionTrackedValues[tmp_i + j]) { @@ -1027,11 +1027,11 @@ namespace dragon Utils::isEscapeKeyPressed(true); } - void Debugger::Display::printStack(uint16_t nrows) + void Debugger::Display::printStack(u16 nrows) { if (nrows == 0) nrows = 8; - uint16_t ncols = 16; - uint16_t startAddr = (0xFFFF - (ncols * nrows) + 1); + u16 ncols = 16; + u16 startAddr = (0xFFFF - (ncols * nrows) + 1); out.clear(); out.nl(); @@ -1051,7 +1051,7 @@ namespace dragon out.nl(); out.fg(ostd::ConsoleColors::Yellow).p("Stack view: ").reset().nl(); - uint16_t stack_ptr = DragonRuntime::cpu.readRegister(data::Registers::SP); + u16 stack_ptr = DragonRuntime::cpu.readRegister(data::Registers::SP); ostd::Memory::printByteStream(*DragonRuntime::ram.getByteStream(), startAddr, ncols, nrows, out, stack_ptr, 2, "Stack"); out.nl().nl().fg(ostd::ConsoleColors::Yellow).p("Pres to go back...").nl().reset(); @@ -1067,15 +1067,15 @@ namespace dragon const dragon::DragonRuntime::tMachineDebugInfo& minfo = dragon::DragonRuntime::getMachineInfoDiff(); auto& callStack = minfo.callStack; - int32_t level = -1; + i32 level = -1; String ch_ang_u = ""; //TODO: Find a fix for the UTF characters ch_ang_u.add("┌"); - // ch_ang_u.addChar((unsigned char)218); + // ch_ang_u.addChar((uchar)218); String ch_ang_l = "|"; String ch_ang_d = ""; ch_ang_d.add("└"); - // ch_ang_d.addChar((unsigned char)192); + // ch_ang_d.addChar((uchar)192); for (auto& call : callStack) { String call_info = call.info.new_trim().toLower(); @@ -1115,7 +1115,7 @@ namespace dragon } String line_str = ""; - for (int32_t i = 0; i < level; i++) + for (i32 i = 0; i < level; i++) line_str.add("| "); line_str.add(call_str); @@ -1149,7 +1149,7 @@ namespace dragon void Debugger::Display::printHelp(void) { out.clear(); - int32_t commandLength = 34; + i32 commandLength = 34; Utils::printFullLine('#', ostd::ConsoleColors::Black, ostd::ConsoleColors::Red); out.nl().fg(ostd::ConsoleColors::Yellow).p("List of available commands:").reset().nl(); @@ -1206,7 +1206,7 @@ namespace dragon } else if (debugger.command.startsWith("stack") || debugger.command.startsWith("s")) { - uint16_t default_stack_rows = 8; + u16 default_stack_rows = 8; String params = debugger.command.new_trim(); if (params == "stack" || params == "s") printStack(default_stack_rows); @@ -1214,7 +1214,7 @@ namespace dragon { params.substr(params.indexOf(" ") + 1).trim(); if (!params.isNumeric()) return ""; - default_stack_rows = (uint16_t)params.toInt(); + default_stack_rows = (u16)params.toInt(); if (default_stack_rows > 0xFFFF / 16) default_stack_rows = 8; printStack(default_stack_rows); } @@ -1255,7 +1255,7 @@ namespace dragon debugger.args.step_exec = true; } - int32_t Debugger::loadArguments(int argc, char** argv) + i32 Debugger::loadArguments(int argc, char** argv) { if (argc < 2) { @@ -1271,7 +1271,7 @@ namespace dragon print_application_help(); return DragonRuntime::RETURN_VAL_CLOSE_DEBUGGER; } - for (int32_t i = 2; i < argc; i++) + for (i32 i = 2; i < argc; i++) { String edit(argv[i]); if (edit == "--verbose-load") @@ -1296,7 +1296,7 @@ namespace dragon 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_mem_offset = (u16)edit.toInt(); debugger.args.force_load = true; } else if (edit == "--help") @@ -1309,7 +1309,7 @@ namespace dragon return DragonRuntime::RETURN_VAL_EXIT_SUCCESS; } - int32_t Debugger::initRuntime(void) + i32 Debugger::initRuntime(void) { dragon::DragonRuntime::tRuntimeInitInfo initInfo; @@ -1319,7 +1319,7 @@ namespace dragon 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); + i32 init_state = dragon::DragonRuntime::initMachine(initInfo); closeEventListener.init(); if (init_state != 0) return init_state; //TODO: Error @@ -1352,7 +1352,7 @@ namespace dragon // return cmd; } - int32_t Debugger::topLevelPrompt(void) + i32 Debugger::topLevelPrompt(void) { if (!data().args.auto_start_debug) { @@ -1413,9 +1413,9 @@ namespace dragon return DragonRuntime::RETURN_VAL_EXIT_SUCCESS; } - int32_t Debugger::executeRuntime(void) + i32 Debugger::executeRuntime(void) { - int32_t rValue = 0; + i32 rValue = 0; bool userQuit = false; output().clear().fg(ostd::ConsoleColors::Green).p("Program running...").nl(); if (!data().args.step_exec) @@ -1436,7 +1436,7 @@ namespace dragon return rValue; } - int32_t Debugger::step_execution(bool& outUserQuit, bool exec_first_step) + i32 Debugger::step_execution(bool& outUserQuit, bool exec_first_step) { if (exec_first_step && !DragonRuntime::cpu.isHalted()) DragonRuntime::runStep(data().trackedAddresses); @@ -1467,12 +1467,12 @@ namespace dragon 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; + const u8 TYPE_STRING = 0; + const u8 TYPE_BYTE = 1; + const u8 TYPE_WORD = 2; + const u8 TYPE_DWORD = 4; + const u8 TYPE_QWORD = 8; + u8 type = TYPE_WORD; if (data().command.contains(" ")) { String size_str = data().command.new_substr(0, data().command.indexOf(" ")).trim(); @@ -1487,8 +1487,8 @@ namespace dragon { if (type == TYPE_STRING) type = TYPE_WORD; - uint16_t addr = data().command.toInt(); - uint16_t end_addr = addr; + u16 addr = data().command.toInt(); + u16 end_addr = addr; String tmp = ""; tmp.add("*(").add(String::getHexStr(addr, true, 2)); if (type != TYPE_BYTE) @@ -1507,9 +1507,9 @@ namespace dragon output().pStyled(rgx); output().fg(ostd::ConsoleColors::White).p(" = "); output().fg(ostd::ConsoleColors::Gray).p("["); - for (uint16_t a = addr; a <= end_addr; a++) + for (u16 a = addr; a <= end_addr; a++) { - uint8_t value = DragonRuntime::memMap.read8(a); + u8 value = DragonRuntime::memMap.read8(a); output().fg(ostd::ConsoleColors::BrightRed).p(String::getHexStr(value, true, 1)); if (a < end_addr) output().p(" "); @@ -1519,8 +1519,8 @@ namespace dragon } else if (data().command.startsWith("$")) { - uint16_t size = 0; - uint16_t addr = Utils::findSymbol(debugger.data, data().command, &size); + u16 size = 0; + u16 addr = Utils::findSymbol(debugger.data, data().command, &size); if (addr == 0) addr = Utils::findSymbol(debugger.labels, data().command, &size); if (addr == 0) @@ -1530,7 +1530,7 @@ namespace dragon String tmp = ""; tmp.add("*(").add(String::getHexStr(addr, true, 2)); if (size > 1) - tmp.add("-").add(String::getHexStr((uint16_t)(addr + size - 1), true, 2)); + tmp.add("-").add(String::getHexStr((u16)(addr + size - 1), true, 2)); tmp.add(")"); ostd::RegexRichString rgx(tmp); rgx.fg("\\(|\\)|-", "darkgray"); @@ -1541,9 +1541,9 @@ namespace dragon output().fg(ostd::ConsoleColors::Gray).p("["); if (type == TYPE_STRING) output().fg(ostd::ConsoleColors::BrightRed).p("\""); - for (uint16_t a = addr; a < addr + size; a++) + for (u16 a = addr; a < addr + size; a++) { - uint8_t value = DragonRuntime::memMap.read8(a); + u8 value = DragonRuntime::memMap.read8(a); if (type == TYPE_STRING) { output().fg(ostd::ConsoleColors::BrightRed).pChar((char)value); @@ -1569,11 +1569,11 @@ namespace dragon else if (data().command.startsWith("b ") || data().command.startsWith("break ")) {//0x2C1D data().command.substr(data().command.indexOf(" ") + 1).trim(); - uint16_t addr = 0; + u16 addr = 0; bool valid = false; if (data().command.isNumeric()) { - addr = (uint16_t)data().command.toInt(); + addr = (u16)data().command.toInt(); valid = true; } else if (data().command.startsWith("$")) @@ -1610,10 +1610,10 @@ namespace dragon return DragonRuntime::RETURN_VAL_EXIT_SUCCESS; } - int32_t Debugger::normal_runtime(bool& outUserQuit) + i32 Debugger::normal_runtime(bool& outUserQuit) { bool result = DragonRuntime::runStep(data().trackedAddresses); - if (Utils::isBreakPoint((uint16_t)DragonRuntime::cpu.readRegister(data::Registers::IP))) + if (Utils::isBreakPoint((u16)DragonRuntime::cpu.readRegister(data::Registers::IP))) { data().args.step_exec = true; return step_execution(outUserQuit, false); @@ -1634,15 +1634,15 @@ namespace dragon data().command = addr; if (data().command.isNumeric()) { - data().trackedAddresses.push_back((uint16_t)data().command.toInt()); + data().trackedAddresses.push_back((u16)data().command.toInt()); } else if (data().command.startsWith("$")) { - uint16_t nbytes = 1; - uint16_t addr = Utils::findSymbol(data().data, data().command, &nbytes); + u16 nbytes = 1; + u16 addr = Utils::findSymbol(data().data, data().command, &nbytes); if (addr > 0) { - for (int32_t i = 0; i < nbytes; i++) + for (i32 i = 0; i < nbytes; i++) data().trackedAddresses.push_back(addr + i); } else @@ -1650,14 +1650,14 @@ namespace dragon addr = Utils::findSymbol(data().labels, data().command, &nbytes); if (addr > 0) { - for (int32_t i = 0; i < nbytes; i++) + for (i32 i = 0; i < nbytes; i++) data().trackedAddresses.push_back(addr + i); } } } else if (data().command.contains("[") && data().command.endsWith("]")) { - uint16_t nbytes = 1; + u16 nbytes = 1; 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(); @@ -1666,8 +1666,8 @@ namespace dragon if (nbytes < 1) nbytes = 1; if (data().command.isNumeric()) { - uint16_t addr = data().command.toInt(); - for (int32_t i = 0; i < nbytes; i++) + u16 addr = data().command.toInt(); + for (i32 i = 0; i < nbytes; i++) data().trackedAddresses.push_back(addr + i); } } @@ -1677,7 +1677,7 @@ namespace dragon void Debugger::print_top_level_prompt_help(void) { - int32_t commandLength = 40; + i32 commandLength = 40; Utils::printFullLine('#', ostd::ConsoleColors::Black, ostd::ConsoleColors::Red); out.nl().fg(ostd::ConsoleColors::Yellow).p("List of available commands:").reset().nl(); @@ -1709,7 +1709,7 @@ namespace dragon void Debugger::print_application_help(void) { - int32_t commandLength = 46; + i32 commandLength = 46; out.nl().fg(ostd::ConsoleColors::Yellow).p("List of available parameters:").reset().nl(); String tmpCommand = "--verbose-load"; diff --git a/src/debugger/Debugger.hpp b/src/debugger/Debugger.hpp index 5084ceb..cf9767b 100644 --- a/src/debugger/Debugger.hpp +++ b/src/debugger/Debugger.hpp @@ -22,7 +22,7 @@ namespace dragon bool track_call_stack = true; bool auto_track_all_data_symbols = true; String force_load_file = ""; - uint16_t force_load_mem_offset = 0x00; + u16 force_load_mem_offset = 0x00; }; public: struct tDebuggerData { @@ -31,13 +31,13 @@ namespace dragon DisassemblyList code; DisassemblyList labels; DisassemblyList data; - std::vector trackedAddresses; + std::vector trackedAddresses; String command; - int32_t labelLineLength { 40 }; - uint16_t currentAddress { 0 }; + i32 labelLineLength { 40 }; + u16 currentAddress { 0 }; bool userQuit { false }; String disassemblyDirectory { "disassembly" }; - std::vector manualBreakPoints; + std::vector manualBreakPoints; }; struct tCloseEventListener : public ostd::BaseObject { @@ -51,17 +51,17 @@ namespace dragon public: class Utils { public: - static DisassemblyList findCodeRegion(const DisassemblyList& code, uint16_t address, uint16_t codeRegionMargin); - 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 DisassemblyList findCodeRegion(const DisassemblyList& code, u16 address, u16 codeRegionMargin); + static String findSymbol(const DisassemblyList& labels, u16 address, u16* outSize = nullptr); + static u16 findSymbol(const DisassemblyList& labels, const String& symbol, u16* outSize = nullptr); static bool isValidLabelNameChar(char c); static void clearConsoleLine(void); static bool isEscapeKeyPressed(bool blocking = false); static ostd::ConsoleOutputHandler& printFullLine(char c, const ostd::ConsoleColors::tConsoleColor& foreground); static ostd::ConsoleOutputHandler& printFullLine(char c, const ostd::ConsoleColors::tConsoleColor& foreground, const ostd::ConsoleColors::tConsoleColor& background); - static void removeBreakPoint(uint16_t addr); - static bool isBreakPoint(uint16_t addr); - static void addBreakPoint(uint16_t addr); + static void removeBreakPoint(u16 addr); + static bool isBreakPoint(u16 addr); + static void addBreakPoint(u16 addr); }; public: class Display { @@ -72,24 +72,24 @@ namespace dragon static void printStep(void); static void printDiff(void); static void printTrackedAddresses(void); - static void printStack(uint16_t nrows); + static void printStack(u16 nrows); static void printCallStack(void); static void printHelp(void); static String changeScreen(void); }; public: static void processErrors(void); - static int32_t loadArguments(int argc, char** argv); - static int32_t initRuntime(void); + static i32 loadArguments(int argc, char** argv); + static i32 initRuntime(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); - static int32_t executeRuntime(void); + static i32 topLevelPrompt(void); + static i32 executeRuntime(void); private: - static int32_t step_execution(bool& outUserQuit, bool exec_first_step = true); - static int32_t normal_runtime(bool& outUserQuit); + static i32 step_execution(bool& outUserQuit, bool exec_first_step = true); + static i32 normal_runtime(bool& outUserQuit); static void exec_watch_command(void); static void print_top_level_prompt_help(void); static void print_application_help(void); diff --git a/src/debugger/DisassemblyLoader.cpp b/src/debugger/DisassemblyLoader.cpp index ccea7cf..77357b6 100644 --- a/src/debugger/DisassemblyLoader.cpp +++ b/src/debugger/DisassemblyLoader.cpp @@ -25,13 +25,13 @@ namespace dragon void DisassemblyTable::load_data(ostd::ByteStream& stream) { - constexpr int32_t MODE_CODE = 0, MODE_DATA = 1, MODE_LABELS = 2; - int32_t mode = MODE_CODE; + constexpr i32 MODE_CODE = 0, MODE_DATA = 1, MODE_LABELS = 2; + i32 mode = MODE_CODE; ostd::serial::SerialIO serializer(stream, ostd::serial::SerialIO::tEndianness::BigEndian); ostd::StreamIndex addr = 0; - int32_t line_addr = 0; - int16_t data_size = 1; - int8_t line_code_char = 0; + i32 line_addr = 0; + i16 data_size = 1; + i8 line_code_char = 0; String header_string = ""; serializer.r_NullTerminatedString(0, header_string); if (header_string != "{ DRAGON_DEBUG_DISASSEMBLY }") return; @@ -74,7 +74,7 @@ namespace dragon String part2 = codeEdit.new_substr(codeEdit.indexOf(" ") + 1); part1.trim(); part2.trim(); - int32_t opCodeLen = 10; + i32 opCodeLen = 10; if (part1.len() < opCodeLen) { codeEdit = part1 + String::duplicateChar(' ', opCodeLen - part1.len()) + part2; diff --git a/src/debugger/debugger_main.cpp b/src/debugger/debugger_main.cpp index 33c6221..b583a2b 100644 --- a/src/debugger/debugger_main.cpp +++ b/src/debugger/debugger_main.cpp @@ -7,7 +7,7 @@ int main(int argc, char** argv) { //Loading commandline arguments - int32_t rValue = dragon::Debugger::loadArguments(argc, argv); + i32 rValue = dragon::Debugger::loadArguments(argc, argv); if (rValue == dragon::DragonRuntime::RETURN_VAL_CLOSE_DEBUGGER) return 0; if (rValue != 0) return rValue; @@ -34,7 +34,7 @@ int main(int argc, char** argv) // debuggerInstance.setClearColor({ 5, 0, 0 }); // //Loading commandline arguments - // int32_t rValue = debuggerInstance.loadArguments(argc, argv); + // i32 rValue = debuggerInstance.loadArguments(argc, argv); // if (rValue == dragon::DragonRuntime::RETURN_VAL_CLOSE_DEBUGGER) // return 0; // if (rValue != 0) return rValue; diff --git a/src/hardware/CPUExtensions.cpp b/src/hardware/CPUExtensions.cpp index 78ac155..5be9442 100644 --- a/src/hardware/CPUExtensions.cpp +++ b/src/hardware/CPUExtensions.cpp @@ -8,7 +8,7 @@ namespace dragon { namespace cpuext { - String ExtMov::getOpCodeString(uint8_t opCode) + String ExtMov::getOpCodeString(u8 opCode) { switch (opCode) { @@ -52,7 +52,7 @@ namespace dragon } } - uint8_t ExtMov::getInstructionSIze(uint8_t opCode) + u8 ExtMov::getInstructionSIze(u8 opCode) { switch (opCode) { @@ -99,359 +99,359 @@ namespace dragon bool ExtMov::execute(VirtualCPU& vcpu) { auto& mem = DragonRuntime::memMap; - uint8_t inst = vcpu.fetch8(); + u8 inst = vcpu.fetch8(); switch (inst) { case OpCodes::wimm_in_dreg_immoffw: { - uint8_t dest_dreg = vcpu.fetch8(); - int16_t src_wimm = vcpu.fetch16(); - uint16_t offset = vcpu.fetch16(); + u8 dest_dreg = vcpu.fetch8(); + i16 src_wimm = vcpu.fetch16(); + u16 offset = vcpu.fetch16(); - uint16_t dest_mem = vcpu.readRegister(dest_dreg); + u16 dest_mem = vcpu.readRegister(dest_dreg); mem.write16(dest_mem + offset, src_wimm); } break; case OpCodes::wimm_in_dreg_regoff: { - uint8_t dest_dreg = vcpu.fetch8(); - int16_t src_wimm = vcpu.fetch16(); - uint16_t offset = vcpu.readRegister(vcpu.fetch8()); + u8 dest_dreg = vcpu.fetch8(); + i16 src_wimm = vcpu.fetch16(); + u16 offset = vcpu.readRegister(vcpu.fetch8()); - uint16_t dest_mem = vcpu.readRegister(dest_dreg); + u16 dest_mem = vcpu.readRegister(dest_dreg); mem.write16(dest_mem + offset, src_wimm); } break; case OpCodes::wimm_in_dreg_immoffb: { - uint8_t dest_dreg = vcpu.fetch8(); - int16_t src_wimm = vcpu.fetch16(); - uint8_t offset = vcpu.fetch8(); + u8 dest_dreg = vcpu.fetch8(); + i16 src_wimm = vcpu.fetch16(); + u8 offset = vcpu.fetch8(); - uint16_t dest_mem = vcpu.readRegister(dest_dreg); + u16 dest_mem = vcpu.readRegister(dest_dreg); mem.write16(dest_mem + offset, src_wimm); } break; case OpCodes::bimm_in_dreg_immoffw: { - uint8_t dest_dreg = vcpu.fetch8(); - int8_t src_bimm = vcpu.fetch8(); - uint16_t offset = vcpu.fetch16(); + u8 dest_dreg = vcpu.fetch8(); + i8 src_bimm = vcpu.fetch8(); + u16 offset = vcpu.fetch16(); - uint16_t dest_mem = vcpu.readRegister(dest_dreg); + u16 dest_mem = vcpu.readRegister(dest_dreg); mem.write8(dest_mem + offset, src_bimm); } break; case OpCodes::bimm_in_dreg_regoff: { - uint8_t dest_dreg = vcpu.fetch8(); - int8_t src_bimm = vcpu.fetch8(); - uint16_t offset = vcpu.readRegister(vcpu.fetch8()); + u8 dest_dreg = vcpu.fetch8(); + i8 src_bimm = vcpu.fetch8(); + u16 offset = vcpu.readRegister(vcpu.fetch8()); - uint16_t dest_mem = vcpu.readRegister(dest_dreg); + u16 dest_mem = vcpu.readRegister(dest_dreg); mem.write8(dest_mem + offset, src_bimm); } break; case OpCodes::bimm_in_dreg_immoffb: { - uint8_t dest_dreg = vcpu.fetch8(); - int8_t src_bimm = vcpu.fetch8(); - uint8_t offset = vcpu.fetch8(); + u8 dest_dreg = vcpu.fetch8(); + i8 src_bimm = vcpu.fetch8(); + u8 offset = vcpu.fetch8(); - uint16_t dest_mem = vcpu.readRegister(dest_dreg); + u16 dest_mem = vcpu.readRegister(dest_dreg); mem.write8(dest_mem + offset, src_bimm); } break; case OpCodes::wdreg_in_dreg_immoffw: { - uint8_t dest_dreg = vcpu.fetch8(); - int16_t src_mem = vcpu.readRegister(vcpu.fetch8()); - uint16_t offset = vcpu.fetch16(); + u8 dest_dreg = vcpu.fetch8(); + i16 src_mem = vcpu.readRegister(vcpu.fetch8()); + u16 offset = vcpu.fetch16(); - uint16_t dest_mem = vcpu.readRegister(dest_dreg); + u16 dest_mem = vcpu.readRegister(dest_dreg); mem.write16(dest_mem + offset, mem.read16(src_mem)); } break; case OpCodes::wdreg_in_dreg_regoff: { - uint8_t dest_dreg = vcpu.fetch8(); - int16_t src_mem = vcpu.readRegister(vcpu.fetch8()); - uint16_t offset = vcpu.readRegister(vcpu.fetch8()); + u8 dest_dreg = vcpu.fetch8(); + i16 src_mem = vcpu.readRegister(vcpu.fetch8()); + u16 offset = vcpu.readRegister(vcpu.fetch8()); - uint16_t dest_mem = vcpu.readRegister(dest_dreg); + u16 dest_mem = vcpu.readRegister(dest_dreg); mem.write16(dest_mem + offset, mem.read16(src_mem)); } break; case OpCodes::wdreg_in_dreg_immoffb: { - uint8_t dest_dreg = vcpu.fetch8(); - int16_t src_mem = vcpu.readRegister(vcpu.fetch8()); - uint8_t offset = vcpu.fetch8(); + u8 dest_dreg = vcpu.fetch8(); + i16 src_mem = vcpu.readRegister(vcpu.fetch8()); + u8 offset = vcpu.fetch8(); - uint16_t dest_mem = vcpu.readRegister(dest_dreg); + u16 dest_mem = vcpu.readRegister(dest_dreg); mem.write16(dest_mem + offset, mem.read16(src_mem)); } break; case OpCodes::bdreg_in_dreg_immoffw: { - uint8_t dest_dreg = vcpu.fetch8(); - int16_t src_mem = vcpu.readRegister(vcpu.fetch8()); - uint16_t offset = vcpu.fetch16(); + u8 dest_dreg = vcpu.fetch8(); + i16 src_mem = vcpu.readRegister(vcpu.fetch8()); + u16 offset = vcpu.fetch16(); - uint16_t dest_mem = vcpu.readRegister(dest_dreg); + u16 dest_mem = vcpu.readRegister(dest_dreg); mem.write8(dest_mem + offset, mem.read8(src_mem)); } break; case OpCodes::bdreg_in_dreg_regoff: { - uint8_t dest_dreg = vcpu.fetch8(); - int16_t src_mem = vcpu.readRegister(vcpu.fetch8()); - uint16_t offset = vcpu.readRegister(vcpu.fetch8()); + u8 dest_dreg = vcpu.fetch8(); + i16 src_mem = vcpu.readRegister(vcpu.fetch8()); + u16 offset = vcpu.readRegister(vcpu.fetch8()); - uint16_t dest_mem = vcpu.readRegister(dest_dreg); + u16 dest_mem = vcpu.readRegister(dest_dreg); mem.write8(dest_mem + offset, mem.read8(src_mem)); } break; case OpCodes::bdreg_in_dreg_immoffb: { - uint8_t dest_dreg = vcpu.fetch8(); - int16_t src_mem = vcpu.readRegister(vcpu.fetch8()); - uint8_t offset = vcpu.fetch8(); + u8 dest_dreg = vcpu.fetch8(); + i16 src_mem = vcpu.readRegister(vcpu.fetch8()); + u8 offset = vcpu.fetch8(); - uint16_t dest_mem = vcpu.readRegister(dest_dreg); + u16 dest_mem = vcpu.readRegister(dest_dreg); mem.write8(dest_mem + offset, mem.read8(src_mem)); } break; case OpCodes::wimm_in_mem_immoffw: { - uint16_t dest_mem = vcpu.fetch16(); - int16_t src_wimm = vcpu.fetch16(); - uint16_t offset = vcpu.fetch16(); + u16 dest_mem = vcpu.fetch16(); + i16 src_wimm = vcpu.fetch16(); + u16 offset = vcpu.fetch16(); mem.write16(dest_mem + offset, src_wimm); } break; case OpCodes::wimm_in_mem_regoff: { - uint16_t dest_mem = vcpu.fetch16(); - int16_t src_wimm = vcpu.fetch16(); - uint16_t offset = vcpu.readRegister(vcpu.fetch8()); + u16 dest_mem = vcpu.fetch16(); + i16 src_wimm = vcpu.fetch16(); + u16 offset = vcpu.readRegister(vcpu.fetch8()); mem.write16(dest_mem + offset, src_wimm); } break; case OpCodes::wimm_in_mem_immoffb: { - uint16_t dest_mem = vcpu.fetch16(); - int16_t src_wimm = vcpu.fetch16(); - uint8_t offset = vcpu.fetch8(); + u16 dest_mem = vcpu.fetch16(); + i16 src_wimm = vcpu.fetch16(); + u8 offset = vcpu.fetch8(); mem.write16(dest_mem + offset, src_wimm); } break; case OpCodes::bimm_in_mem_immoffw: { - uint16_t dest_mem = vcpu.fetch16(); - int8_t src_bimm = vcpu.fetch8(); - uint16_t offset = vcpu.fetch16(); + u16 dest_mem = vcpu.fetch16(); + i8 src_bimm = vcpu.fetch8(); + u16 offset = vcpu.fetch16(); mem.write8(dest_mem + offset, src_bimm); } break; case OpCodes::bimm_in_mem_regoff: { - uint16_t dest_mem = vcpu.fetch16(); - int8_t src_bimm = vcpu.fetch8(); - uint16_t offset = vcpu.readRegister(vcpu.fetch8()); + u16 dest_mem = vcpu.fetch16(); + i8 src_bimm = vcpu.fetch8(); + u16 offset = vcpu.readRegister(vcpu.fetch8()); mem.write8(dest_mem + offset, src_bimm); } break; case OpCodes::bimm_in_mem_immoffb: { - uint16_t dest_mem = vcpu.fetch16(); - int8_t src_bimm = vcpu.fetch8(); - uint8_t offset = vcpu.fetch8(); + u16 dest_mem = vcpu.fetch16(); + i8 src_bimm = vcpu.fetch8(); + u8 offset = vcpu.fetch8(); mem.write8(dest_mem + offset, src_bimm); } break; case OpCodes::wdreg_immoffw_in_dreg: { - uint8_t dest_dreg = vcpu.fetch8(); - uint8_t src_dreg = vcpu.fetch8(); - uint16_t offset = vcpu.fetch16(); + u8 dest_dreg = vcpu.fetch8(); + u8 src_dreg = vcpu.fetch8(); + u16 offset = vcpu.fetch16(); - uint16_t dest_mem = vcpu.readRegister(dest_dreg); - uint16_t src_mem = vcpu.readRegister(src_dreg); + u16 dest_mem = vcpu.readRegister(dest_dreg); + u16 src_mem = vcpu.readRegister(src_dreg); mem.write16(dest_mem, mem.read16(src_mem + offset)); } break; case OpCodes::wdreg_regoff_in_dreg: { - uint8_t dest_dreg = vcpu.fetch8(); - uint8_t src_dreg = vcpu.fetch8(); - uint16_t offset = vcpu.readRegister(vcpu.fetch8()); + u8 dest_dreg = vcpu.fetch8(); + u8 src_dreg = vcpu.fetch8(); + u16 offset = vcpu.readRegister(vcpu.fetch8()); - uint16_t dest_mem = vcpu.readRegister(dest_dreg); - uint16_t src_mem = vcpu.readRegister(src_dreg); + u16 dest_mem = vcpu.readRegister(dest_dreg); + u16 src_mem = vcpu.readRegister(src_dreg); mem.write16(dest_mem, mem.read16(src_mem + offset)); } break; case OpCodes::wdreg_immoffb_in_dreg: { - uint8_t dest_dreg = vcpu.fetch8(); - uint8_t src_dreg = vcpu.fetch8(); - uint8_t offset = vcpu.fetch8(); + u8 dest_dreg = vcpu.fetch8(); + u8 src_dreg = vcpu.fetch8(); + u8 offset = vcpu.fetch8(); - uint16_t dest_mem = vcpu.readRegister(dest_dreg); - uint16_t src_mem = vcpu.readRegister(src_dreg); + u16 dest_mem = vcpu.readRegister(dest_dreg); + u16 src_mem = vcpu.readRegister(src_dreg); mem.write16(dest_mem, mem.read16(src_mem + offset)); } break; case OpCodes::bdreg_immoffw_in_dreg: { - uint8_t dest_dreg = vcpu.fetch8(); - uint8_t src_dreg = vcpu.fetch8(); - uint16_t offset = vcpu.fetch16(); + u8 dest_dreg = vcpu.fetch8(); + u8 src_dreg = vcpu.fetch8(); + u16 offset = vcpu.fetch16(); - uint16_t dest_mem = vcpu.readRegister(dest_dreg); - uint16_t src_mem = vcpu.readRegister(src_dreg); + u16 dest_mem = vcpu.readRegister(dest_dreg); + u16 src_mem = vcpu.readRegister(src_dreg); mem.write8(dest_mem, mem.read8(src_mem + offset)); } break; case OpCodes::bdreg_regoff_in_dreg: { - uint8_t dest_dreg = vcpu.fetch8(); - uint8_t src_dreg = vcpu.fetch8(); - uint16_t offset = vcpu.readRegister(vcpu.fetch8()); + u8 dest_dreg = vcpu.fetch8(); + u8 src_dreg = vcpu.fetch8(); + u16 offset = vcpu.readRegister(vcpu.fetch8()); - uint16_t dest_mem = vcpu.readRegister(dest_dreg); - uint16_t src_mem = vcpu.readRegister(src_dreg); + u16 dest_mem = vcpu.readRegister(dest_dreg); + u16 src_mem = vcpu.readRegister(src_dreg); mem.write8(dest_mem, mem.read8(src_mem + offset)); } break; case OpCodes::bdreg_immoffb_in_dreg: { - uint8_t dest_dreg = vcpu.fetch8(); - uint8_t src_dreg = vcpu.fetch8(); - uint8_t offset = vcpu.fetch8(); + u8 dest_dreg = vcpu.fetch8(); + u8 src_dreg = vcpu.fetch8(); + u8 offset = vcpu.fetch8(); - uint16_t dest_mem = vcpu.readRegister(dest_dreg); - uint16_t src_mem = vcpu.readRegister(src_dreg); + u16 dest_mem = vcpu.readRegister(dest_dreg); + u16 src_mem = vcpu.readRegister(src_dreg); mem.write8(dest_mem, mem.read8(src_mem + offset)); } break; case OpCodes::wmem_immoffw_in_reg: { - uint8_t dest_reg = vcpu.fetch8(); - uint16_t src_mem = vcpu.fetch16(); - uint16_t offset = vcpu.fetch16(); + u8 dest_reg = vcpu.fetch8(); + u16 src_mem = vcpu.fetch16(); + u16 offset = vcpu.fetch16(); vcpu.writeRegister16(dest_reg, mem.read16(src_mem + offset)); } break; case OpCodes::wmem_regoff_in_reg: { - uint8_t dest_reg = vcpu.fetch8(); - uint16_t src_mem = vcpu.fetch16(); - uint16_t offset = vcpu.readRegister(vcpu.fetch8()); + u8 dest_reg = vcpu.fetch8(); + u16 src_mem = vcpu.fetch16(); + u16 offset = vcpu.readRegister(vcpu.fetch8()); vcpu.writeRegister16(dest_reg, mem.read16(src_mem + offset)); } break; case OpCodes::wmem_immoffb_in_reg: { - uint8_t dest_reg = vcpu.fetch8(); - uint16_t src_mem = vcpu.fetch16(); - uint8_t offset = vcpu.fetch8(); + u8 dest_reg = vcpu.fetch8(); + u16 src_mem = vcpu.fetch16(); + u8 offset = vcpu.fetch8(); vcpu.writeRegister16(dest_reg, mem.read16(src_mem + offset)); } break; case OpCodes::bmem_immoffw_in_reg: { - uint8_t dest_reg = vcpu.fetch8(); - uint16_t src_mem = vcpu.fetch16(); - uint16_t offset = vcpu.fetch16(); + u8 dest_reg = vcpu.fetch8(); + u16 src_mem = vcpu.fetch16(); + u16 offset = vcpu.fetch16(); vcpu.writeRegister8(dest_reg, mem.read8(src_mem + offset)); } break; case OpCodes::bmem_regoff_in_reg: { - uint8_t dest_reg = vcpu.fetch8(); - uint16_t src_mem = vcpu.fetch16(); - uint16_t offset = vcpu.readRegister(vcpu.fetch8()); + u8 dest_reg = vcpu.fetch8(); + u16 src_mem = vcpu.fetch16(); + u16 offset = vcpu.readRegister(vcpu.fetch8()); vcpu.writeRegister8(dest_reg, mem.read8(src_mem + offset)); } break; case OpCodes::bmem_immoffb_in_reg: { - uint8_t dest_reg = vcpu.fetch8(); - uint16_t src_mem = vcpu.fetch16(); - uint8_t offset = vcpu.fetch8(); + u8 dest_reg = vcpu.fetch8(); + u16 src_mem = vcpu.fetch16(); + u8 offset = vcpu.fetch8(); vcpu.writeRegister8(dest_reg, mem.read8(src_mem + offset)); } break; case OpCodes::wdreg_immoffw_in_reg: { - uint8_t dest_reg = vcpu.fetch8(); - uint8_t src_dreg = vcpu.fetch8(); - uint16_t offset = vcpu.fetch16(); + u8 dest_reg = vcpu.fetch8(); + u8 src_dreg = vcpu.fetch8(); + u16 offset = vcpu.fetch16(); - uint16_t src_mem = vcpu.readRegister(src_dreg); + u16 src_mem = vcpu.readRegister(src_dreg); vcpu.writeRegister16(dest_reg, mem.read16(src_mem + offset)); } break; case OpCodes::wdreg_regoff_in_reg: { - uint8_t dest_reg = vcpu.fetch8(); - uint8_t src_dreg = vcpu.fetch8(); - uint16_t offset = vcpu.readRegister(vcpu.fetch8()); + u8 dest_reg = vcpu.fetch8(); + u8 src_dreg = vcpu.fetch8(); + u16 offset = vcpu.readRegister(vcpu.fetch8()); - uint16_t src_mem = vcpu.readRegister(src_dreg); + u16 src_mem = vcpu.readRegister(src_dreg); vcpu.writeRegister16(dest_reg, mem.read16(src_mem + offset)); } break; case OpCodes::wdreg_immoffb_in_reg: { - uint8_t dest_reg = vcpu.fetch8(); - uint8_t src_dreg = vcpu.fetch8(); - uint8_t offset = vcpu.fetch8(); + u8 dest_reg = vcpu.fetch8(); + u8 src_dreg = vcpu.fetch8(); + u8 offset = vcpu.fetch8(); - uint16_t src_mem = vcpu.readRegister(src_dreg); + u16 src_mem = vcpu.readRegister(src_dreg); vcpu.writeRegister16(dest_reg, mem.read16(src_mem + offset)); } break; case OpCodes::bdreg_immoffw_in_reg: { - uint8_t dest_reg = vcpu.fetch8(); - uint8_t src_dreg = vcpu.fetch8(); - uint16_t offset = vcpu.fetch16(); + u8 dest_reg = vcpu.fetch8(); + u8 src_dreg = vcpu.fetch8(); + u16 offset = vcpu.fetch16(); - uint16_t src_mem = vcpu.readRegister(src_dreg); + u16 src_mem = vcpu.readRegister(src_dreg); vcpu.writeRegister8(dest_reg, mem.read8(src_mem + offset)); } break; case OpCodes::bdreg_regoff_in_reg: { - uint8_t dest_reg = vcpu.fetch8(); - uint8_t src_dreg = vcpu.fetch8(); - uint16_t offset = vcpu.readRegister(vcpu.fetch8()); + u8 dest_reg = vcpu.fetch8(); + u8 src_dreg = vcpu.fetch8(); + u16 offset = vcpu.readRegister(vcpu.fetch8()); - uint16_t src_mem = vcpu.readRegister(src_dreg); + u16 src_mem = vcpu.readRegister(src_dreg); vcpu.writeRegister8(dest_reg, mem.read8(src_mem + offset)); } break; case OpCodes::bdreg_immoffb_in_reg: { - uint8_t dest_reg = vcpu.fetch8(); - uint8_t src_dreg = vcpu.fetch8(); - uint8_t offset = vcpu.fetch8(); + u8 dest_reg = vcpu.fetch8(); + u8 src_dreg = vcpu.fetch8(); + u8 offset = vcpu.fetch8(); - uint16_t src_mem = vcpu.readRegister(src_dreg); + u16 src_mem = vcpu.readRegister(src_dreg); vcpu.writeRegister8(dest_reg, mem.read8(src_mem + offset)); } break; @@ -467,7 +467,7 @@ namespace dragon - String ExtAlu::getOpCodeString(uint8_t opCode) + String ExtAlu::getOpCodeString(u8 opCode) { switch (opCode) { @@ -491,7 +491,7 @@ namespace dragon } } - uint8_t ExtAlu::getInstructionSIze(uint8_t opCode) + u8 ExtAlu::getInstructionSIze(u8 opCode) { switch (opCode) { @@ -518,224 +518,224 @@ namespace dragon bool ExtAlu::execute(VirtualCPU& vcpu) { auto& mem = DragonRuntime::memMap; - uint8_t inst = vcpu.fetch8(); + u8 inst = vcpu.fetch8(); switch (inst) { case OpCodes::addipu_reg_in_reg: { - uint8_t dest_reg = vcpu.fetch8(); - uint8_t src_reg = vcpu.fetch8(); - uint16_t dest_val = vcpu.readRegister(dest_reg); - uint16_t src_val = vcpu.readRegister(src_reg); - uint16_t res = dest_val + src_val; - vcpu.writeRegister16(dest_reg, (int16_t)res); + u8 dest_reg = vcpu.fetch8(); + u8 src_reg = vcpu.fetch8(); + u16 dest_val = vcpu.readRegister(dest_reg); + u16 src_val = vcpu.readRegister(src_reg); + u16 res = dest_val + src_val; + vcpu.writeRegister16(dest_reg, (i16)res); } break; case OpCodes::addipu_imm_in_reg: { - uint8_t dest_reg = vcpu.fetch8(); - uint16_t src_val = vcpu.fetch16(); - uint16_t dest_val = vcpu.readRegister(dest_reg); - uint16_t res = dest_val + src_val; - vcpu.writeRegister16(dest_reg, (int16_t)res); + u8 dest_reg = vcpu.fetch8(); + u16 src_val = vcpu.fetch16(); + u16 dest_val = vcpu.readRegister(dest_reg); + u16 res = dest_val + src_val; + vcpu.writeRegister16(dest_reg, (i16)res); } break; case OpCodes::subipu_reg_in_reg: { - uint8_t dest_reg = vcpu.fetch8(); - uint8_t src_reg = vcpu.fetch8(); - uint16_t dest_val = vcpu.readRegister(dest_reg); - uint16_t src_val = vcpu.readRegister(src_reg); - uint16_t res = dest_val - src_val; - vcpu.writeRegister16(dest_reg, (int16_t)res); + u8 dest_reg = vcpu.fetch8(); + u8 src_reg = vcpu.fetch8(); + u16 dest_val = vcpu.readRegister(dest_reg); + u16 src_val = vcpu.readRegister(src_reg); + u16 res = dest_val - src_val; + vcpu.writeRegister16(dest_reg, (i16)res); } break; case OpCodes::subipu_imm_in_reg: { - uint8_t dest_reg = vcpu.fetch8(); - uint16_t src_val = vcpu.fetch16(); - uint16_t dest_val = vcpu.readRegister(dest_reg); - uint16_t res = dest_val - src_val; - vcpu.writeRegister16(dest_reg, (int16_t)res); + u8 dest_reg = vcpu.fetch8(); + u16 src_val = vcpu.fetch16(); + u16 dest_val = vcpu.readRegister(dest_reg); + u16 res = dest_val - src_val; + vcpu.writeRegister16(dest_reg, (i16)res); } break; case OpCodes::mulipu_reg_in_reg: { - uint8_t dest_reg = vcpu.fetch8(); - uint8_t src_reg = vcpu.fetch8(); - uint16_t dest_val = vcpu.readRegister(dest_reg); - uint16_t src_val = vcpu.readRegister(src_reg); - uint16_t res = dest_val * src_val; - vcpu.writeRegister16(dest_reg, (int16_t)res); + u8 dest_reg = vcpu.fetch8(); + u8 src_reg = vcpu.fetch8(); + u16 dest_val = vcpu.readRegister(dest_reg); + u16 src_val = vcpu.readRegister(src_reg); + u16 res = dest_val * src_val; + vcpu.writeRegister16(dest_reg, (i16)res); } break; case OpCodes::mulipu_imm_in_reg: { - uint8_t dest_reg = vcpu.fetch8(); - uint16_t src_val = vcpu.fetch16(); - uint16_t dest_val = vcpu.readRegister(dest_reg); - uint16_t res = dest_val * src_val; - vcpu.writeRegister16(dest_reg, (int16_t)res); + u8 dest_reg = vcpu.fetch8(); + u16 src_val = vcpu.fetch16(); + u16 dest_val = vcpu.readRegister(dest_reg); + u16 res = dest_val * src_val; + vcpu.writeRegister16(dest_reg, (i16)res); } break; case OpCodes::divipu_reg_in_reg: { - uint8_t dest_reg = vcpu.fetch8(); - uint8_t src_reg = vcpu.fetch8(); - uint16_t dest_val = vcpu.readRegister(dest_reg); - uint16_t src_val = vcpu.readRegister(src_reg); - uint16_t res = dest_val / src_val; - uint16_t rv = dest_val % src_val; - vcpu.writeRegister16(dest_reg, (int16_t)res); - vcpu.writeRegister16(data::Registers::RV, (int16_t)rv); + u8 dest_reg = vcpu.fetch8(); + u8 src_reg = vcpu.fetch8(); + u16 dest_val = vcpu.readRegister(dest_reg); + u16 src_val = vcpu.readRegister(src_reg); + u16 res = dest_val / src_val; + u16 rv = dest_val % src_val; + vcpu.writeRegister16(dest_reg, (i16)res); + vcpu.writeRegister16(data::Registers::RV, (i16)rv); } break; case OpCodes::divipu_imm_in_reg: { - uint8_t dest_reg = vcpu.fetch8(); - uint16_t src_val = vcpu.fetch16(); - uint16_t dest_val = vcpu.readRegister(dest_reg); - uint16_t res = dest_val / src_val; - uint16_t rv = dest_val % src_val; - vcpu.writeRegister16(dest_reg, (int16_t)res); - vcpu.writeRegister16(data::Registers::RV, (int16_t)rv); + u8 dest_reg = vcpu.fetch8(); + u16 src_val = vcpu.fetch16(); + u16 dest_val = vcpu.readRegister(dest_reg); + u16 res = dest_val / src_val; + u16 rv = dest_val % src_val; + vcpu.writeRegister16(dest_reg, (i16)res); + vcpu.writeRegister16(data::Registers::RV, (i16)rv); } break; case OpCodes::addip_reg_in_reg: { - uint8_t dest_reg = vcpu.fetch8(); - uint8_t src_reg = vcpu.fetch8(); - int16_t dest_val = vcpu.readRegister(dest_reg); - int16_t src_val = vcpu.readRegister(src_reg); - int16_t res = dest_val + src_val; + u8 dest_reg = vcpu.fetch8(); + u8 src_reg = vcpu.fetch8(); + i16 dest_val = vcpu.readRegister(dest_reg); + i16 src_val = vcpu.readRegister(src_reg); + i16 res = dest_val + src_val; vcpu.writeRegister16(dest_reg, res); } break; case OpCodes::addip_imm_in_reg: { - uint8_t dest_reg = vcpu.fetch8(); - uint16_t src_val = vcpu.fetch16(); - int16_t dest_val = vcpu.readRegister(dest_reg); - int16_t res = dest_val + src_val; + u8 dest_reg = vcpu.fetch8(); + u16 src_val = vcpu.fetch16(); + i16 dest_val = vcpu.readRegister(dest_reg); + i16 res = dest_val + src_val; vcpu.writeRegister16(dest_reg, res); } break; case OpCodes::subip_reg_in_reg: { - uint8_t dest_reg = vcpu.fetch8(); - uint8_t src_reg = vcpu.fetch8(); - int16_t dest_val = vcpu.readRegister(dest_reg); - int16_t src_val = vcpu.readRegister(src_reg); - int16_t res = dest_val - src_val; + u8 dest_reg = vcpu.fetch8(); + u8 src_reg = vcpu.fetch8(); + i16 dest_val = vcpu.readRegister(dest_reg); + i16 src_val = vcpu.readRegister(src_reg); + i16 res = dest_val - src_val; vcpu.writeRegister16(dest_reg, res); } break; case OpCodes::subip_imm_in_reg: { - uint8_t dest_reg = vcpu.fetch8(); - uint16_t src_val = vcpu.fetch16(); - int16_t dest_val = vcpu.readRegister(dest_reg); - int16_t res = dest_val - src_val; + u8 dest_reg = vcpu.fetch8(); + u16 src_val = vcpu.fetch16(); + i16 dest_val = vcpu.readRegister(dest_reg); + i16 res = dest_val - src_val; vcpu.writeRegister16(dest_reg, res); } break; case OpCodes::mulip_reg_in_reg: { - uint8_t dest_reg = vcpu.fetch8(); - uint8_t src_reg = vcpu.fetch8(); - int16_t dest_val = vcpu.readRegister(dest_reg); - int16_t src_val = vcpu.readRegister(src_reg); - int16_t res = dest_val * src_val; + u8 dest_reg = vcpu.fetch8(); + u8 src_reg = vcpu.fetch8(); + i16 dest_val = vcpu.readRegister(dest_reg); + i16 src_val = vcpu.readRegister(src_reg); + i16 res = dest_val * src_val; vcpu.writeRegister16(dest_reg, res); } break; case OpCodes::mulip_imm_in_reg: { - uint8_t dest_reg = vcpu.fetch8(); - uint16_t src_val = vcpu.fetch16(); - int16_t dest_val = vcpu.readRegister(dest_reg); - int16_t res = dest_val * src_val; + u8 dest_reg = vcpu.fetch8(); + u16 src_val = vcpu.fetch16(); + i16 dest_val = vcpu.readRegister(dest_reg); + i16 res = dest_val * src_val; vcpu.writeRegister16(dest_reg, res); } break; case OpCodes::divip_reg_in_reg: { - uint8_t dest_reg = vcpu.fetch8(); - uint8_t src_reg = vcpu.fetch8(); - int16_t dest_val = vcpu.readRegister(dest_reg); - int16_t src_val = vcpu.readRegister(src_reg); - int16_t res = dest_val / src_val; - int16_t rv = dest_val % src_val; + u8 dest_reg = vcpu.fetch8(); + u8 src_reg = vcpu.fetch8(); + i16 dest_val = vcpu.readRegister(dest_reg); + i16 src_val = vcpu.readRegister(src_reg); + i16 res = dest_val / src_val; + i16 rv = dest_val % src_val; vcpu.writeRegister16(dest_reg, res); vcpu.writeRegister16(data::Registers::RV, rv); } break; case OpCodes::divip_imm_in_reg: { - uint8_t dest_reg = vcpu.fetch8(); - uint16_t src_val = vcpu.fetch16(); - int16_t dest_val = vcpu.readRegister(dest_reg); - int16_t res = dest_val / src_val; - int16_t rv = dest_val % src_val; + u8 dest_reg = vcpu.fetch8(); + u16 src_val = vcpu.fetch16(); + i16 dest_val = vcpu.readRegister(dest_reg); + i16 res = dest_val / src_val; + i16 rv = dest_val % src_val; vcpu.writeRegister16(dest_reg, res); vcpu.writeRegister16(data::Registers::RV, rv); } break; case OpCodes::andip_reg_in_reg: { - uint8_t dest_reg = vcpu.fetch8(); - uint8_t src_reg = vcpu.fetch8(); - int16_t src_val = vcpu.readRegister(src_reg); - int16_t dest_val = vcpu.readRegister(dest_reg); + u8 dest_reg = vcpu.fetch8(); + u8 src_reg = vcpu.fetch8(); + i16 src_val = vcpu.readRegister(src_reg); + i16 dest_val = vcpu.readRegister(dest_reg); vcpu.writeRegister16(dest_reg, src_val & dest_val); } break; case OpCodes::andip_imm_in_reg: { - uint8_t dest_reg = vcpu.fetch8(); - uint16_t src_val = vcpu.fetch16(); - int16_t value = vcpu.readRegister(dest_reg); + u8 dest_reg = vcpu.fetch8(); + u16 src_val = vcpu.fetch16(); + i16 value = vcpu.readRegister(dest_reg); vcpu.writeRegister16(dest_reg, value & src_val); } break; case OpCodes::orip_reg_in_reg: { - uint8_t dest_reg = vcpu.fetch8(); - uint8_t src_reg = vcpu.fetch8(); - int16_t src_val = vcpu.readRegister(src_reg); - int16_t dest_val = vcpu.readRegister(dest_reg); + u8 dest_reg = vcpu.fetch8(); + u8 src_reg = vcpu.fetch8(); + i16 src_val = vcpu.readRegister(src_reg); + i16 dest_val = vcpu.readRegister(dest_reg); vcpu.writeRegister16(dest_reg, src_val | dest_val); } break; case OpCodes::orip_imm_in_reg: { - uint8_t dest_reg = vcpu.fetch8(); - uint16_t src_val = vcpu.fetch16(); - int16_t value = vcpu.readRegister(dest_reg); + u8 dest_reg = vcpu.fetch8(); + u16 src_val = vcpu.fetch16(); + i16 value = vcpu.readRegister(dest_reg); vcpu.writeRegister16(dest_reg, value | src_val); } break; case OpCodes::xorip_reg_in_reg: { - uint8_t dest_reg = vcpu.fetch8(); - uint8_t src_reg = vcpu.fetch8(); - int16_t src_val = vcpu.readRegister(src_reg); - int16_t dest_val = vcpu.readRegister(dest_reg); + u8 dest_reg = vcpu.fetch8(); + u8 src_reg = vcpu.fetch8(); + i16 src_val = vcpu.readRegister(src_reg); + i16 dest_val = vcpu.readRegister(dest_reg); vcpu.writeRegister16(dest_reg, src_val ^ dest_val); } break; case OpCodes::xorip_imm_in_reg: { - uint8_t dest_reg = vcpu.fetch8(); - uint16_t src_val = vcpu.fetch16(); - int16_t value = vcpu.readRegister(dest_reg); + u8 dest_reg = vcpu.fetch8(); + u16 src_val = vcpu.fetch16(); + i16 value = vcpu.readRegister(dest_reg); vcpu.writeRegister16(dest_reg, value ^ src_val); } break; case OpCodes::notip_reg: { - uint8_t regAddr = vcpu.fetch8(); - int16_t value = vcpu.readRegister(regAddr); + u8 regAddr = vcpu.fetch8(); + i16 value = vcpu.readRegister(regAddr); vcpu.writeRegister16(regAddr, ~value); } break; diff --git a/src/hardware/CPUExtensions.hpp b/src/hardware/CPUExtensions.hpp index 14db5c6..d3158d4 100644 --- a/src/hardware/CPUExtensions.hpp +++ b/src/hardware/CPUExtensions.hpp @@ -13,50 +13,50 @@ namespace dragon public: class OpCodes { public: - inline static constexpr uint8_t wimm_in_dreg_immoffw = 0x10; - inline static constexpr uint8_t wimm_in_dreg_regoff = 0x11; - inline static constexpr uint8_t wimm_in_dreg_immoffb = 0x12; - inline static constexpr uint8_t bimm_in_dreg_immoffw = 0x13; - inline static constexpr uint8_t bimm_in_dreg_regoff = 0x14; - inline static constexpr uint8_t bimm_in_dreg_immoffb = 0x15; - inline static constexpr uint8_t wdreg_in_dreg_immoffw = 0x16; - inline static constexpr uint8_t wdreg_in_dreg_regoff = 0x17; - inline static constexpr uint8_t wdreg_in_dreg_immoffb = 0x18; - inline static constexpr uint8_t bdreg_in_dreg_immoffw = 0x19; - inline static constexpr uint8_t bdreg_in_dreg_regoff = 0x1A; - inline static constexpr uint8_t bdreg_in_dreg_immoffb = 0x1B; + inline static constexpr u8 wimm_in_dreg_immoffw = 0x10; + inline static constexpr u8 wimm_in_dreg_regoff = 0x11; + inline static constexpr u8 wimm_in_dreg_immoffb = 0x12; + inline static constexpr u8 bimm_in_dreg_immoffw = 0x13; + inline static constexpr u8 bimm_in_dreg_regoff = 0x14; + inline static constexpr u8 bimm_in_dreg_immoffb = 0x15; + inline static constexpr u8 wdreg_in_dreg_immoffw = 0x16; + inline static constexpr u8 wdreg_in_dreg_regoff = 0x17; + inline static constexpr u8 wdreg_in_dreg_immoffb = 0x18; + inline static constexpr u8 bdreg_in_dreg_immoffw = 0x19; + inline static constexpr u8 bdreg_in_dreg_regoff = 0x1A; + inline static constexpr u8 bdreg_in_dreg_immoffb = 0x1B; - inline static constexpr uint8_t wimm_in_mem_immoffw = 0x30; - inline static constexpr uint8_t wimm_in_mem_regoff = 0x31; - inline static constexpr uint8_t wimm_in_mem_immoffb = 0x32; - inline static constexpr uint8_t bimm_in_mem_immoffw = 0x33; - inline static constexpr uint8_t bimm_in_mem_regoff = 0x34; - inline static constexpr uint8_t bimm_in_mem_immoffb = 0x35; + inline static constexpr u8 wimm_in_mem_immoffw = 0x30; + inline static constexpr u8 wimm_in_mem_regoff = 0x31; + inline static constexpr u8 wimm_in_mem_immoffb = 0x32; + inline static constexpr u8 bimm_in_mem_immoffw = 0x33; + inline static constexpr u8 bimm_in_mem_regoff = 0x34; + inline static constexpr u8 bimm_in_mem_immoffb = 0x35; - inline static constexpr uint8_t wdreg_immoffw_in_dreg = 0x40; - inline static constexpr uint8_t wdreg_regoff_in_dreg = 0x41; - inline static constexpr uint8_t wdreg_immoffb_in_dreg = 0x42; - inline static constexpr uint8_t bdreg_immoffw_in_dreg = 0x43; - inline static constexpr uint8_t bdreg_regoff_in_dreg = 0x44; - inline static constexpr uint8_t bdreg_immoffb_in_dreg = 0x45; + inline static constexpr u8 wdreg_immoffw_in_dreg = 0x40; + inline static constexpr u8 wdreg_regoff_in_dreg = 0x41; + inline static constexpr u8 wdreg_immoffb_in_dreg = 0x42; + inline static constexpr u8 bdreg_immoffw_in_dreg = 0x43; + inline static constexpr u8 bdreg_regoff_in_dreg = 0x44; + inline static constexpr u8 bdreg_immoffb_in_dreg = 0x45; - inline static constexpr uint8_t wmem_immoffw_in_reg = 0x50; - inline static constexpr uint8_t wmem_regoff_in_reg = 0x51; - inline static constexpr uint8_t wmem_immoffb_in_reg = 0x52; - inline static constexpr uint8_t bmem_immoffw_in_reg = 0x53; - inline static constexpr uint8_t bmem_regoff_in_reg = 0x54; - inline static constexpr uint8_t bmem_immoffb_in_reg = 0x55; - inline static constexpr uint8_t wdreg_immoffw_in_reg = 0x56; - inline static constexpr uint8_t wdreg_regoff_in_reg = 0x57; - inline static constexpr uint8_t wdreg_immoffb_in_reg = 0x58; - inline static constexpr uint8_t bdreg_immoffw_in_reg = 0x59; - inline static constexpr uint8_t bdreg_regoff_in_reg = 0x5A; - inline static constexpr uint8_t bdreg_immoffb_in_reg = 0x5B; + inline static constexpr u8 wmem_immoffw_in_reg = 0x50; + inline static constexpr u8 wmem_regoff_in_reg = 0x51; + inline static constexpr u8 wmem_immoffb_in_reg = 0x52; + inline static constexpr u8 bmem_immoffw_in_reg = 0x53; + inline static constexpr u8 bmem_regoff_in_reg = 0x54; + inline static constexpr u8 bmem_immoffb_in_reg = 0x55; + inline static constexpr u8 wdreg_immoffw_in_reg = 0x56; + inline static constexpr u8 wdreg_regoff_in_reg = 0x57; + inline static constexpr u8 wdreg_immoffb_in_reg = 0x58; + inline static constexpr u8 bdreg_immoffw_in_reg = 0x59; + inline static constexpr u8 bdreg_regoff_in_reg = 0x5A; + inline static constexpr u8 bdreg_immoffb_in_reg = 0x5B; }; public: inline ExtMov(void) : data::CPUExtension(data::OpCodes::Ext01, "extmov") { } - String getOpCodeString(uint8_t opCode) override; - uint8_t getInstructionSIze(uint8_t opCode) override; + String getOpCodeString(u8 opCode) override; + u8 getInstructionSIze(u8 opCode) override; bool execute(VirtualCPU& vcpu) override; }; @@ -65,37 +65,37 @@ namespace dragon public: class OpCodes { public: - inline static constexpr uint8_t addipu_reg_in_reg = 0x10; - inline static constexpr uint8_t addipu_imm_in_reg = 0x11; - inline static constexpr uint8_t subipu_reg_in_reg = 0x12; - inline static constexpr uint8_t subipu_imm_in_reg = 0x13; - inline static constexpr uint8_t mulipu_reg_in_reg = 0x14; - inline static constexpr uint8_t mulipu_imm_in_reg = 0x15; - inline static constexpr uint8_t divipu_reg_in_reg = 0x16; - inline static constexpr uint8_t divipu_imm_in_reg = 0x17; + inline static constexpr u8 addipu_reg_in_reg = 0x10; + inline static constexpr u8 addipu_imm_in_reg = 0x11; + inline static constexpr u8 subipu_reg_in_reg = 0x12; + inline static constexpr u8 subipu_imm_in_reg = 0x13; + inline static constexpr u8 mulipu_reg_in_reg = 0x14; + inline static constexpr u8 mulipu_imm_in_reg = 0x15; + inline static constexpr u8 divipu_reg_in_reg = 0x16; + inline static constexpr u8 divipu_imm_in_reg = 0x17; - inline static constexpr uint8_t addip_reg_in_reg = 0x20; - inline static constexpr uint8_t addip_imm_in_reg = 0x21; - inline static constexpr uint8_t subip_reg_in_reg = 0x22; - inline static constexpr uint8_t subip_imm_in_reg = 0x23; - inline static constexpr uint8_t mulip_reg_in_reg = 0x24; - inline static constexpr uint8_t mulip_imm_in_reg = 0x25; - inline static constexpr uint8_t divip_reg_in_reg = 0x26; - inline static constexpr uint8_t divip_imm_in_reg = 0x27; + inline static constexpr u8 addip_reg_in_reg = 0x20; + inline static constexpr u8 addip_imm_in_reg = 0x21; + inline static constexpr u8 subip_reg_in_reg = 0x22; + inline static constexpr u8 subip_imm_in_reg = 0x23; + inline static constexpr u8 mulip_reg_in_reg = 0x24; + inline static constexpr u8 mulip_imm_in_reg = 0x25; + inline static constexpr u8 divip_reg_in_reg = 0x26; + inline static constexpr u8 divip_imm_in_reg = 0x27; - inline static constexpr uint8_t andip_reg_in_reg = 0x30; - inline static constexpr uint8_t andip_imm_in_reg = 0x31; - inline static constexpr uint8_t orip_reg_in_reg = 0x32; - inline static constexpr uint8_t orip_imm_in_reg = 0x33; - inline static constexpr uint8_t xorip_reg_in_reg = 0x34; - inline static constexpr uint8_t xorip_imm_in_reg = 0x35; - inline static constexpr uint8_t notip_reg = 0x36; + inline static constexpr u8 andip_reg_in_reg = 0x30; + inline static constexpr u8 andip_imm_in_reg = 0x31; + inline static constexpr u8 orip_reg_in_reg = 0x32; + inline static constexpr u8 orip_imm_in_reg = 0x33; + inline static constexpr u8 xorip_reg_in_reg = 0x34; + inline static constexpr u8 xorip_imm_in_reg = 0x35; + inline static constexpr u8 notip_reg = 0x36; }; public: inline ExtAlu(void) : data::CPUExtension(data::OpCodes::Ext02, "extalu") { } - String getOpCodeString(uint8_t opCode) override; - uint8_t getInstructionSIze(uint8_t opCode) override; + String getOpCodeString(u8 opCode) override; + u8 getInstructionSIze(u8 opCode) override; bool execute(VirtualCPU& vcpu) override; }; } diff --git a/src/hardware/IMemoryDevice.hpp b/src/hardware/IMemoryDevice.hpp index 9f337ac..67984c9 100644 --- a/src/hardware/IMemoryDevice.hpp +++ b/src/hardware/IMemoryDevice.hpp @@ -9,10 +9,10 @@ namespace dragon class IMemoryDevice : public ostd::BaseObject { public: - virtual int8_t read8(uint16_t addr) = 0; - virtual int16_t read16(uint16_t addr) = 0; - virtual int8_t write8(uint16_t addr, int8_t value) = 0; - virtual int16_t write16(uint16_t addr, int16_t value) = 0; + virtual i8 read8(u16 addr) = 0; + virtual i16 read16(u16 addr) = 0; + virtual i8 write8(u16 addr, i8 value) = 0; + virtual i16 write16(u16 addr, i16 value) = 0; virtual inline ostd::ByteStream* getByteStream(void) = 0; }; } diff --git a/src/hardware/MemoryMapper.cpp b/src/hardware/MemoryMapper.cpp index fbebb5a..643d43e 100644 --- a/src/hardware/MemoryMapper.cpp +++ b/src/hardware/MemoryMapper.cpp @@ -11,44 +11,44 @@ namespace dragon { } - int8_t MemoryMapper::read8(uint16_t addr) + i8 MemoryMapper::read8(u16 addr) { auto region = findRegion(addr); if (region == nullptr) return 0x0000; //TODO: Error - uint16_t finalAddr = (region->remap ? addr - region->startAddress : addr); + u16 finalAddr = (region->remap ? addr - region->startAddress : addr); return region->device->read8(finalAddr); } - int16_t MemoryMapper::read16(uint16_t addr) + i16 MemoryMapper::read16(u16 addr) { auto region = findRegion(addr); if (region == nullptr) return 0x0000; //TODO: Error - uint16_t finalAddr = (region->remap ? addr - region->startAddress : addr); + u16 finalAddr = (region->remap ? addr - region->startAddress : addr); return region->device->read16(finalAddr); } - int8_t MemoryMapper::write8(uint16_t addr, int8_t value) + i8 MemoryMapper::write8(u16 addr, i8 value) { auto region = findRegion(addr); if (region == nullptr) return 0x0000; //TODO: Error - uint16_t finalAddr = (region->remap ? addr - region->startAddress : addr); + u16 finalAddr = (region->remap ? addr - region->startAddress : addr); return region->device->write8(finalAddr, value); } - int16_t MemoryMapper::write16(uint16_t addr, int16_t value) + i16 MemoryMapper::write16(u16 addr, i16 value) { auto region = findRegion(addr); if (region == nullptr) return 0x0000; //TODO: Error - uint16_t finalAddr = (region->remap ? addr - region->startAddress : addr); + u16 finalAddr = (region->remap ? addr - region->startAddress : addr); return region->device->write16(finalAddr, value); } - void MemoryMapper::mapDevice(IMemoryDevice& device, uint16_t startAddr, uint16_t endAddr, bool remap, String name) + void MemoryMapper::mapDevice(IMemoryDevice& device, u16 startAddr, u16 endAddr, bool remap, String name) { m_regions.push_back({ &device, startAddr, endAddr, remap, name }); } - String MemoryMapper::getMemoryRegionName(uint16_t address) + String MemoryMapper::getMemoryRegionName(u16 address) { tMemoryRegion* region = findRegion(address); if (region == nullptr) return "Invalid"; @@ -60,7 +60,7 @@ namespace dragon return nullptr; } - MemoryMapper::tMemoryRegion* MemoryMapper::findRegion(uint16_t address) + MemoryMapper::tMemoryRegion* MemoryMapper::findRegion(u16 address) { for (auto& region : m_regions) { diff --git a/src/hardware/MemoryMapper.hpp b/src/hardware/MemoryMapper.hpp index 101f552..77772ed 100644 --- a/src/hardware/MemoryMapper.hpp +++ b/src/hardware/MemoryMapper.hpp @@ -13,27 +13,27 @@ namespace dragon private: struct tMemoryRegion { IMemoryDevice* device { nullptr }; - uint16_t startAddress { 0x0000 }; - uint16_t endAddress { 0x0000 }; + u16 startAddress { 0x0000 }; + u16 endAddress { 0x0000 }; bool remap { false }; String name { "" }; }; public: MemoryMapper(void); - int8_t read8(uint16_t addr) override; - int16_t read16(uint16_t addr) override; - int8_t write8(uint16_t addr, int8_t value) override; - int16_t write16(uint16_t addr, int16_t value) override; + i8 read8(u16 addr) override; + i16 read16(u16 addr) override; + i8 write8(u16 addr, i8 value) override; + i16 write16(u16 addr, i16 value) override; - void mapDevice(IMemoryDevice& device, uint16_t startAddr, uint16_t endAddr, bool remap = false, String name = ""); + void mapDevice(IMemoryDevice& device, u16 startAddr, u16 endAddr, bool remap = false, String name = ""); - String getMemoryRegionName(uint16_t address); + String getMemoryRegionName(u16 address); ostd::ByteStream* getByteStream(void) override; private: - tMemoryRegion* findRegion(uint16_t address); + tMemoryRegion* findRegion(u16 address); private: std::vector m_regions; diff --git a/src/hardware/VirtualCPU.cpp b/src/hardware/VirtualCPU.cpp index 5a112d4..245abdd 100644 --- a/src/hardware/VirtualCPU.cpp +++ b/src/hardware/VirtualCPU.cpp @@ -11,55 +11,55 @@ namespace dragon { VirtualCPU::VirtualCPU(IMemoryDevice& memory) : m_memory(memory) { - writeRegister16(data::Registers::SP, (uint16_t)(0xFFFF - 1)); - writeRegister16(data::Registers::FP, (uint16_t)(0xFFFF - 1)); + writeRegister16(data::Registers::SP, (u16)(0xFFFF - 1)); + writeRegister16(data::Registers::FP, (u16)(0xFFFF - 1)); - for (int32_t i = 0; i < 16; i++) + for (i32 i = 0; i < 16; i++) m_extensions[i] = nullptr; } - int16_t VirtualCPU::readRegister(uint8_t reg) + i16 VirtualCPU::readRegister(u8 reg) { if (reg >= data::Registers::Last) return 0x0000; //TODO: Error return m_registers[reg]; } - int16_t VirtualCPU::writeRegister16(uint8_t reg, int16_t value) + i16 VirtualCPU::writeRegister16(u8 reg, i16 value) { if (reg >= data::Registers::Last) return 0x0000; //TODO: Error m_registers[reg] = value; return value; } - int8_t VirtualCPU::writeRegister8(uint8_t reg, int8_t value) + i8 VirtualCPU::writeRegister8(u8 reg, i8 value) { if (reg >= data::Registers::Last) return 0x0000; //TODO: Error m_registers[reg] = value & 0x00FF; return value; } - int8_t VirtualCPU::fetch8(void) + i8 VirtualCPU::fetch8(void) { - uint16_t nextInstAddr = readRegister(data::Registers::IP); + u16 nextInstAddr = readRegister(data::Registers::IP); m_currentAddr = nextInstAddr; - int8_t inst = m_memory.read8(nextInstAddr); + i8 inst = m_memory.read8(nextInstAddr); writeRegister16(data::Registers::IP, nextInstAddr + 1); return inst; } - int16_t VirtualCPU::fetch16(void) + i16 VirtualCPU::fetch16(void) { - uint16_t nextInstAddr = readRegister(data::Registers::IP); + u16 nextInstAddr = readRegister(data::Registers::IP); m_currentAddr = nextInstAddr; - int16_t inst = m_memory.read16(nextInstAddr); + i16 inst = m_memory.read16(nextInstAddr); writeRegister16(data::Registers::IP, nextInstAddr + 2); return inst; } - void VirtualCPU::pushToStack(int16_t value) + void VirtualCPU::pushToStack(i16 value) { - uint16_t stackAddr = readRegister(data::Registers::SP); - uint16_t stack_size = DragonRuntime::vCMOS.read16(data::CMOSRegisters::StackSize); + u16 stackAddr = readRegister(data::Registers::SP); + u16 stack_size = DragonRuntime::vCMOS.read16(data::CMOSRegisters::StackSize); if (stackAddr <= 0xFFFF - stack_size) { data::ErrorHandler::pushError(data::ErrorCodes::CPU_StackOverflow, "Stack Overflow: "); @@ -71,11 +71,11 @@ namespace dragon m_stackFrameSize += 2; } - int16_t VirtualCPU::popFromStack(void) + i16 VirtualCPU::popFromStack(void) { - uint16_t nextSP = readRegister(data::Registers::SP) + 2; + u16 nextSP = readRegister(data::Registers::SP) + 2; writeRegister16(data::Registers::SP, nextSP); - int16_t value = m_memory.read16(nextSP); + i16 value = m_memory.read16(nextSP); m_stackFrameSize -= 2; return value; } @@ -87,8 +87,8 @@ namespace dragon __debug_store_stack_frame_string_on_push(); return; } - uint16_t argStartAddr = readRegister(data::Registers::SP) + 2; - uint16_t argCount = m_memory.read16(argStartAddr); + u16 argStartAddr = readRegister(data::Registers::SP) + 2; + u16 argCount = m_memory.read16(argStartAddr); if (argCount == 0) argStartAddr = 0; else @@ -117,10 +117,10 @@ namespace dragon void VirtualCPU::popStackFrame(void) { - uint16_t framePointerAddr = readRegister(data::Registers::FP); + u16 framePointerAddr = readRegister(data::Registers::FP); writeRegister16(data::Registers::SP, framePointerAddr); m_stackFrameSize = popFromStack(); - // uint16_t tmpStackFrameSize = m_stackFrameSize; + // u16 tmpStackFrameSize = m_stackFrameSize; writeRegister16(data::Registers::FP, popFromStack()); writeRegister16(data::Registers::IP, popFromStack()); @@ -137,8 +137,8 @@ namespace dragon writeRegister16(data::Registers::R2, popFromStack()); writeRegister16(data::Registers::R1, popFromStack()); - uint16_t nArgs = popFromStack(); - for (int32_t i = 0; i < nArgs; i++) + u16 nArgs = popFromStack(); + for (i32 i = 0; i < nArgs; i++) { popFromStack(); // writeRegister(data::Registers::FP, readRegister(data::Registers::FP) - 2); @@ -147,14 +147,14 @@ namespace dragon // writeRegister(data::Registers::FP, framePointerAddr + tmpStackFrameSize); } - bool VirtualCPU::readFlag(uint8_t flg) + bool VirtualCPU::readFlag(u8 flg) { if (flg >= 16) return false; m_tempFlags.value = readRegister(data::Registers::FL); return ostd::Bits::get(m_tempFlags, flg); } - void VirtualCPU::setFlag(uint8_t flg, bool val) + void VirtualCPU::setFlag(u8 flg, bool val) { if (flg >= 16) return; m_tempFlags.value = readRegister(data::Registers::FL); @@ -162,12 +162,12 @@ namespace dragon writeRegister16(data::Registers::FL, m_tempFlags.value); } - void VirtualCPU::handleInterrupt(uint8_t intValue, bool hardware) + void VirtualCPU::handleInterrupt(u8 intValue, bool hardware) { - uint16_t entryPointer = data::MemoryMapAddresses::IntVector_Start + (intValue * 3); - uint8_t interruptStatus = m_memory.read8(entryPointer); + u16 entryPointer = data::MemoryMapAddresses::IntVector_Start + (intValue * 3); + u8 interruptStatus = m_memory.read8(entryPointer); if (interruptStatus != 0xFF) return; - uint16_t handlerAddress = m_memory.read16(entryPointer + 1); + u16 handlerAddress = m_memory.read16(entryPointer + 1); pushToStack(0); pushStackFrame(); m_subroutineCounter++; @@ -188,7 +188,7 @@ namespace dragon { if (m_currentInst < data::OpCodes::Ext01 || m_currentInst > data::OpCodes::Ext16) return false; - for (int32_t i = 0; i < 16; i++) + for (i32 i = 0; i < 16; i++) { if (m_extensions[i] == nullptr) continue; @@ -214,7 +214,7 @@ namespace dragon m_currentOffset = readRegister(data::Registers::OFFSET); else m_currentOffset = 0x0000; - uint8_t inst = fetch8(); + u8 inst = fetch8(); m_currentInst = inst; if (loadExtension()) return m_currentExtension->execute(*this); @@ -239,8 +239,8 @@ namespace dragon break; case data::OpCodes::BIOSModeImm: { - uint16_t tmpAddr = m_currentAddr; - int8_t value = fetch8(); + u16 tmpAddr = m_currentAddr; + i8 value = fetch8(); if (tmpAddr >= data::MemoryMapAddresses::BIOS_End) m_biosMode = false; else @@ -249,8 +249,8 @@ namespace dragon break; case data::OpCodes::DEBUG_StartProfile: { - int8_t id = fetch8(); - int8_t timeUnit = fetch8(); + i8 id = fetch8(); + i8 timeUnit = fetch8(); ostd::eTimeUnits tu = ostd::eTimeUnits::Milliseconds; if (static_cast(timeUnit) == eDebugProfilerTimeUnits::Micros) tu = ostd::eTimeUnits::Microseconds; @@ -271,507 +271,507 @@ namespace dragon break; case data::OpCodes::MovImmReg: { - uint8_t regAddr = fetch8(); - int16_t literal = fetch16(); + u8 regAddr = fetch8(); + i16 literal = fetch16(); writeRegister16(regAddr, literal); } break; case data::OpCodes::MovImmMem: { - uint16_t addr = fetch16(); - int16_t literal = fetch16(); + u16 addr = fetch16(); + i16 literal = fetch16(); m_memory.write16(addr, literal); } break; case data::OpCodes::MovRegReg: { - uint8_t destRegAddr = fetch8(); - uint8_t srcRegAddr = fetch8(); - int16_t value = readRegister(srcRegAddr); + u8 destRegAddr = fetch8(); + u8 srcRegAddr = fetch8(); + i16 value = readRegister(srcRegAddr); writeRegister16(destRegAddr, value); } break; case data::OpCodes::MovRegMem: { - uint16_t addr = fetch16(); - uint8_t srcRegAddr = fetch8(); - int16_t value = readRegister(srcRegAddr); + u16 addr = fetch16(); + u8 srcRegAddr = fetch8(); + i16 value = readRegister(srcRegAddr); m_memory.write16(addr, value); } break; case data::OpCodes::MovMemReg: { - uint8_t destRegAddr = fetch8(); - uint16_t addr = fetch16(); - int16_t value = m_memory.read16(addr); + u8 destRegAddr = fetch8(); + u16 addr = fetch16(); + i16 value = m_memory.read16(addr); writeRegister16(destRegAddr, value); } break; case data::OpCodes::MovDerefRegReg: { - uint8_t destRegAddr = fetch8(); - uint8_t srcRegAddr = fetch8(); - uint16_t addr = readRegister(srcRegAddr); - int16_t value = m_memory.read16(addr); + u8 destRegAddr = fetch8(); + u8 srcRegAddr = fetch8(); + u16 addr = readRegister(srcRegAddr); + i16 value = m_memory.read16(addr); writeRegister16(destRegAddr, value); } break; case data::OpCodes::MovDerefRegMem: { - uint16_t destAddr = fetch16(); - uint8_t srcRegAddr = fetch8(); - uint16_t addr = readRegister(srcRegAddr); - int16_t value = m_memory.read16(addr); + u16 destAddr = fetch16(); + u8 srcRegAddr = fetch8(); + u16 addr = readRegister(srcRegAddr); + i16 value = m_memory.read16(addr); m_memory.write16(destAddr, value); } break; // case data::OpCodes::MovImmRegOffReg: // { - // uint8_t destRegAddr = fetch8(); - // uint16_t addr = fetch16(); - // uint8_t offRegAddr = fetch8(); - // int16_t offset = readRegister(offRegAddr); - // int16_t value = m_memory.read16(addr + offset); + // u8 destRegAddr = fetch8(); + // u16 addr = fetch16(); + // u8 offRegAddr = fetch8(); + // i16 offset = readRegister(offRegAddr); + // i16 value = m_memory.read16(addr + offset); // writeRegister(destRegAddr, value); // } // break; case data::OpCodes::MovRegDerefReg: { - uint8_t destRegAddr = fetch8(); - uint8_t srcRegAddr = fetch8(); - int16_t value = readRegister(srcRegAddr); - uint16_t addr = readRegister(destRegAddr); + u8 destRegAddr = fetch8(); + u8 srcRegAddr = fetch8(); + i16 value = readRegister(srcRegAddr); + u16 addr = readRegister(destRegAddr); m_memory.write16(addr, value); } break; case data::OpCodes::MovMemDerefReg: { - uint8_t destRegAddr = fetch8(); - uint16_t srcAddr = fetch16(); - int16_t value = m_memory.read16(srcAddr); - uint16_t addr = readRegister(destRegAddr); + u8 destRegAddr = fetch8(); + u16 srcAddr = fetch16(); + i16 value = m_memory.read16(srcAddr); + u16 addr = readRegister(destRegAddr); m_memory.write16(addr, value); } break; case data::OpCodes::MovImmDerefReg: { - uint8_t destRegAddr = fetch8(); - int16_t value = fetch16(); - uint16_t addr = readRegister(destRegAddr); + u8 destRegAddr = fetch8(); + i16 value = fetch16(); + u16 addr = readRegister(destRegAddr); m_memory.write16(addr, value); } break; case data::OpCodes::MovDerefRegDerefReg: { - uint8_t destRegAddr = fetch8(); - uint8_t srcRegAddr = fetch8(); - uint16_t srcAddr = readRegister(srcRegAddr); - uint16_t destAddr = readRegister(destRegAddr); - int16_t value = m_memory.read16(srcAddr); + u8 destRegAddr = fetch8(); + u8 srcRegAddr = fetch8(); + u16 srcAddr = readRegister(srcRegAddr); + u16 destAddr = readRegister(destRegAddr); + i16 value = m_memory.read16(srcAddr); m_memory.write16(destAddr, value); } break; case data::OpCodes::MovByteImmMem: { - uint16_t addr = fetch16(); - int8_t literal = fetch8(); + u16 addr = fetch16(); + i8 literal = fetch8(); m_memory.write8(addr, literal); } break; case data::OpCodes::MovByteDerefRegMem: { - uint16_t destAddr = fetch16(); - uint8_t srcRegAddr = fetch8(); - uint16_t addr = readRegister(srcRegAddr); - int8_t value = m_memory.read8(addr); + u16 destAddr = fetch16(); + u8 srcRegAddr = fetch8(); + u16 addr = readRegister(srcRegAddr); + i8 value = m_memory.read8(addr); m_memory.write8(destAddr, value); } break; case data::OpCodes::MovByteRegDerefReg: { - uint8_t destRegAddr = fetch8(); - uint8_t srcRegAddr = fetch8(); - int16_t value = readRegister(srcRegAddr); - uint16_t addr = readRegister(destRegAddr); - m_memory.write8(addr, (int8_t)value); + u8 destRegAddr = fetch8(); + u8 srcRegAddr = fetch8(); + i16 value = readRegister(srcRegAddr); + u16 addr = readRegister(destRegAddr); + m_memory.write8(addr, (i8)value); } break; case data::OpCodes::MovByteMemDerefReg: { - uint8_t destRegAddr = fetch8(); - uint16_t srcAddr = fetch16(); - int8_t value = m_memory.read8(srcAddr); - uint16_t addr = readRegister(destRegAddr); + u8 destRegAddr = fetch8(); + u16 srcAddr = fetch16(); + i8 value = m_memory.read8(srcAddr); + u16 addr = readRegister(destRegAddr); m_memory.write8(addr, value); } break; case data::OpCodes::MovByteImmDerefReg: { - uint8_t destRegAddr = fetch8(); - int8_t value = fetch8(); - uint16_t addr = readRegister(destRegAddr); + u8 destRegAddr = fetch8(); + i8 value = fetch8(); + u16 addr = readRegister(destRegAddr); m_memory.write8(addr, value); } break; case data::OpCodes::MovByteDerefRegDerefReg: { - uint8_t destRegAddr = fetch8(); - uint8_t srcRegAddr = fetch8(); - uint16_t srcAddr = readRegister(srcRegAddr); - uint16_t destAddr = readRegister(destRegAddr); - int8_t value = m_memory.read8(srcAddr); + u8 destRegAddr = fetch8(); + u8 srcRegAddr = fetch8(); + u16 srcAddr = readRegister(srcRegAddr); + u16 destAddr = readRegister(destRegAddr); + i8 value = m_memory.read8(srcAddr); m_memory.write8(destAddr, value); } break; case data::OpCodes::MovByteMemReg: { - uint8_t destRegAddr = fetch8(); - uint16_t srcAddr = fetch16(); - int8_t value = m_memory.read8(srcAddr); + u8 destRegAddr = fetch8(); + u16 srcAddr = fetch16(); + i8 value = m_memory.read8(srcAddr); writeRegister8(destRegAddr, value); } break; case data::OpCodes::MovByteImmReg: { - uint8_t destRegAddr = fetch8(); - int8_t value = fetch8(); + u8 destRegAddr = fetch8(); + i8 value = fetch8(); writeRegister8(destRegAddr, value); } break; case data::OpCodes::MovByteDerefRegReg: { - uint8_t destRegAddr = fetch8(); - uint8_t srcRegAddr = fetch8(); - uint16_t srcAddr = readRegister(srcRegAddr); - int8_t value = m_memory.read8(srcAddr); + u8 destRegAddr = fetch8(); + u8 srcRegAddr = fetch8(); + u16 srcAddr = readRegister(srcRegAddr); + i8 value = m_memory.read8(srcAddr); writeRegister8(destRegAddr, value); } break; case data::OpCodes::MovByteRegMem: { - uint16_t addr = fetch16(); - uint8_t regAddr = fetch8(); - int16_t value = readRegister(regAddr); - m_memory.write8(addr, (int8_t)(value & 0x00FF)); + u16 addr = fetch16(); + u8 regAddr = fetch8(); + i16 value = readRegister(regAddr); + m_memory.write8(addr, (i8)(value & 0x00FF)); } break; case data::OpCodes::AddImmReg: { - uint8_t regAddr = fetch8(); - int16_t literal = fetch16(); - int16_t regValue = readRegister(regAddr); + u8 regAddr = fetch8(); + i16 literal = fetch16(); + i16 regValue = readRegister(regAddr); writeRegister16(data::Registers::ACC, regValue + literal); } break; case data::OpCodes::AddRegReg: { - uint8_t regAddr1 = fetch8(); - uint8_t regAddr2 = fetch8(); - int16_t regValue1 = readRegister(regAddr1); - int16_t regValue2 = readRegister(regAddr2); + u8 regAddr1 = fetch8(); + u8 regAddr2 = fetch8(); + i16 regValue1 = readRegister(regAddr1); + i16 regValue2 = readRegister(regAddr2); writeRegister16(data::Registers::ACC, regValue1 + regValue2); } break; case data::OpCodes::SubImmReg: { - uint8_t regAddr = fetch8(); - int16_t literal = fetch16(); - int16_t regValue = readRegister(regAddr); + u8 regAddr = fetch8(); + i16 literal = fetch16(); + i16 regValue = readRegister(regAddr); writeRegister16(data::Registers::ACC, regValue - literal); } break; case data::OpCodes::SubRegReg: { - uint8_t regAddr1 = fetch8(); - uint8_t regAddr2 = fetch8(); - int16_t regValue1 = readRegister(regAddr1); - int16_t regValue2 = readRegister(regAddr2); + u8 regAddr1 = fetch8(); + u8 regAddr2 = fetch8(); + i16 regValue1 = readRegister(regAddr1); + i16 regValue2 = readRegister(regAddr2); writeRegister16(data::Registers::ACC, regValue1 - regValue2); } break; case data::OpCodes::MulImmReg: { - uint8_t regAddr = fetch8(); - int16_t literal = fetch16(); - int16_t regValue = readRegister(regAddr); + u8 regAddr = fetch8(); + i16 literal = fetch16(); + i16 regValue = readRegister(regAddr); writeRegister16(data::Registers::ACC, regValue * literal); } break; case data::OpCodes::MulRegReg: { - uint8_t regAddr1 = fetch8(); - uint8_t regAddr2 = fetch8(); - int16_t regValue1 = readRegister(regAddr1); - int16_t regValue2 = readRegister(regAddr2); + u8 regAddr1 = fetch8(); + u8 regAddr2 = fetch8(); + i16 regValue1 = readRegister(regAddr1); + i16 regValue2 = readRegister(regAddr2); writeRegister16(data::Registers::ACC, regValue1 * regValue2); } break; case data::OpCodes::DivImmReg: //TODO: Division by zero is unhandled { - uint8_t regAddr = fetch8(); - int16_t literal = fetch16(); - int16_t regValue = readRegister(regAddr); - int16_t quotient = regValue / literal; - int16_t reminder = regValue % literal; + u8 regAddr = fetch8(); + i16 literal = fetch16(); + i16 regValue = readRegister(regAddr); + i16 quotient = regValue / literal; + i16 reminder = regValue % literal; writeRegister16(data::Registers::ACC, quotient); writeRegister16(data::Registers::RV, reminder); } break; case data::OpCodes::DivRegReg: //TODO: Division by zero is unhandled { - uint8_t regAddr1 = fetch8(); - uint8_t regAddr2 = fetch8(); - int16_t regValue1 = readRegister(regAddr1); - int16_t regValue2 = readRegister(regAddr2); - int16_t quotient = regValue1 / regValue2; - int16_t reminder = regValue1 % regValue2; + u8 regAddr1 = fetch8(); + u8 regAddr2 = fetch8(); + i16 regValue1 = readRegister(regAddr1); + i16 regValue2 = readRegister(regAddr2); + i16 quotient = regValue1 / regValue2; + i16 reminder = regValue1 % regValue2; writeRegister16(data::Registers::ACC, quotient); writeRegister16(data::Registers::RV, reminder); } break; case data::OpCodes::IncReg: { - uint8_t regAddr = fetch8(); - int16_t regValue = readRegister(regAddr); + u8 regAddr = fetch8(); + i16 regValue = readRegister(regAddr); writeRegister16(regAddr, regValue + 1); } break; case data::OpCodes::DecReg: { - uint8_t regAddr = fetch8(); - int16_t regValue = readRegister(regAddr); + u8 regAddr = fetch8(); + i16 regValue = readRegister(regAddr); writeRegister16(regAddr, regValue - 1); } break; case data::OpCodes::RShiftRegImm: { - int16_t literal = fetch16(); - uint8_t regAddr = fetch8(); - int16_t regValue = readRegister(regAddr); + i16 literal = fetch16(); + u8 regAddr = fetch8(); + i16 regValue = readRegister(regAddr); regValue = regValue >> literal; writeRegister16(regAddr, regValue); } break; case data::OpCodes::RShiftRegReg: { - uint8_t shiftRegAddr = fetch8(); - uint8_t regAddr = fetch8(); - int16_t shiftValue = readRegister(shiftRegAddr); - int16_t regValue = readRegister(regAddr); + u8 shiftRegAddr = fetch8(); + u8 regAddr = fetch8(); + i16 shiftValue = readRegister(shiftRegAddr); + i16 regValue = readRegister(regAddr); regValue = regValue >> shiftValue; writeRegister16(regAddr, regValue); } break; case data::OpCodes::LShiftRegImm: { - int16_t literal = fetch16(); - uint8_t regAddr = fetch8(); - int16_t regValue = readRegister(regAddr); + i16 literal = fetch16(); + u8 regAddr = fetch8(); + i16 regValue = readRegister(regAddr); regValue = regValue << literal; writeRegister16(regAddr, regValue); } break; case data::OpCodes::LShiftRegReg: { - uint8_t shiftRegAddr = fetch8(); - uint8_t regAddr = fetch8(); - int16_t shiftValue = readRegister(shiftRegAddr); - int16_t regValue = readRegister(regAddr); + u8 shiftRegAddr = fetch8(); + u8 regAddr = fetch8(); + i16 shiftValue = readRegister(shiftRegAddr); + i16 regValue = readRegister(regAddr); regValue = regValue << shiftValue; writeRegister16(regAddr, regValue); } break; case data::OpCodes::AndRegImm: { - int16_t literal = fetch16(); - uint8_t regAddr = fetch8(); - int16_t value = readRegister(regAddr); + i16 literal = fetch16(); + u8 regAddr = fetch8(); + i16 value = readRegister(regAddr); writeRegister16(data::Registers::ACC, value & literal); } break; case data::OpCodes::AndRegReg: { - uint8_t andRegAddr = fetch8(); - uint8_t regAddr = fetch8(); - int16_t value = readRegister(regAddr); - int16_t andValue = readRegister(andRegAddr); + u8 andRegAddr = fetch8(); + u8 regAddr = fetch8(); + i16 value = readRegister(regAddr); + i16 andValue = readRegister(andRegAddr); writeRegister16(data::Registers::ACC, value & andValue); } break; case data::OpCodes::OrRegImm: { - int16_t literal = fetch16(); - uint8_t regAddr = fetch8(); - int16_t value = readRegister(regAddr); + i16 literal = fetch16(); + u8 regAddr = fetch8(); + i16 value = readRegister(regAddr); writeRegister16(data::Registers::ACC, value | literal); } break; case data::OpCodes::OrRegReg: { - uint8_t andRegAddr = fetch8(); - uint8_t regAddr = fetch8(); - int16_t value = readRegister(regAddr); - int16_t andValue = readRegister(andRegAddr); + u8 andRegAddr = fetch8(); + u8 regAddr = fetch8(); + i16 value = readRegister(regAddr); + i16 andValue = readRegister(andRegAddr); writeRegister16(data::Registers::ACC, value | andValue); } break; case data::OpCodes::XorRegImm: { - int16_t literal = fetch16(); - uint8_t regAddr = fetch8(); - int16_t value = readRegister(regAddr); + i16 literal = fetch16(); + u8 regAddr = fetch8(); + i16 value = readRegister(regAddr); writeRegister16(data::Registers::ACC, value ^ literal); } break; case data::OpCodes::XorRegReg: { - uint8_t andRegAddr = fetch8(); - uint8_t regAddr = fetch8(); - int16_t value = readRegister(regAddr); - int16_t andValue = readRegister(andRegAddr); + u8 andRegAddr = fetch8(); + u8 regAddr = fetch8(); + i16 value = readRegister(regAddr); + i16 andValue = readRegister(andRegAddr); writeRegister16(data::Registers::ACC, value ^ andValue); } break; case data::OpCodes::NotReg: { - uint8_t regAddr = fetch8(); - int16_t value = readRegister(regAddr); + u8 regAddr = fetch8(); + i16 value = readRegister(regAddr); writeRegister16(data::Registers::ACC, ~value); } break; case data::OpCodes::NegReg: { - uint8_t regAddr = fetch8(); - int16_t value = readRegister(regAddr); + u8 regAddr = fetch8(); + i16 value = readRegister(regAddr); value *= -1; writeRegister16(regAddr, value); } break; case data::OpCodes::NegByteReg: { - uint8_t regAddr = fetch8(); - int8_t value = (int8_t)readRegister(regAddr); + u8 regAddr = fetch8(); + i8 value = (i8)readRegister(regAddr); value *= -1; writeRegister8(regAddr, value); } break; case data::OpCodes::JmpNotEqImm: { - uint16_t addr = fetch16(); - int16_t value = fetch16(); - int16_t accValue = readRegister(data::Registers::ACC); + u16 addr = fetch16(); + i16 value = fetch16(); + i16 accValue = readRegister(data::Registers::ACC); if (value != accValue) writeRegister16(data::Registers::IP, addr); } break; case data::OpCodes::JmpNotEqReg: { - uint16_t addr = fetch16(); - uint8_t regAddr = fetch8(); - int16_t value = readRegister(regAddr); - int16_t accValue = readRegister(data::Registers::ACC); + u16 addr = fetch16(); + u8 regAddr = fetch8(); + i16 value = readRegister(regAddr); + i16 accValue = readRegister(data::Registers::ACC); if (value != accValue) writeRegister16(data::Registers::IP, addr); } break; case data::OpCodes::JmpEqImm: { - uint16_t addr = fetch16(); - int16_t value = fetch16(); - int16_t accValue = readRegister(data::Registers::ACC); + u16 addr = fetch16(); + i16 value = fetch16(); + i16 accValue = readRegister(data::Registers::ACC); if (value == accValue) writeRegister16(data::Registers::IP, addr); } break; case data::OpCodes::JmpEqReg: { - uint16_t addr = fetch16(); - uint8_t regAddr = fetch8(); - int16_t value = readRegister(regAddr); - int16_t accValue = readRegister(data::Registers::ACC); + u16 addr = fetch16(); + u8 regAddr = fetch8(); + i16 value = readRegister(regAddr); + i16 accValue = readRegister(data::Registers::ACC); if (value == accValue) writeRegister16(data::Registers::IP, addr); } break; case data::OpCodes::JmpGrImm: { - uint16_t addr = fetch16(); - int16_t value = fetch16(); - int16_t accValue = readRegister(data::Registers::ACC); + u16 addr = fetch16(); + i16 value = fetch16(); + i16 accValue = readRegister(data::Registers::ACC); if (value > accValue) writeRegister16(data::Registers::IP, addr); } break; case data::OpCodes::JmpGrReg: { - uint16_t addr = fetch16(); - uint8_t regAddr = fetch8(); - int16_t value = readRegister(regAddr); - int16_t accValue = readRegister(data::Registers::ACC); + u16 addr = fetch16(); + u8 regAddr = fetch8(); + i16 value = readRegister(regAddr); + i16 accValue = readRegister(data::Registers::ACC); if (value > accValue) writeRegister16(data::Registers::IP, addr); } break; case data::OpCodes::JmpLessImm: { - uint16_t addr = fetch16(); - int16_t value = fetch16(); - int16_t accValue = readRegister(data::Registers::ACC); + u16 addr = fetch16(); + i16 value = fetch16(); + i16 accValue = readRegister(data::Registers::ACC); if (value < accValue) writeRegister16(data::Registers::IP, addr); } break; case data::OpCodes::JmpLessReg: { - uint16_t addr = fetch16(); - uint8_t regAddr = fetch8(); - int16_t value = readRegister(regAddr); - int16_t accValue = readRegister(data::Registers::ACC); + u16 addr = fetch16(); + u8 regAddr = fetch8(); + i16 value = readRegister(regAddr); + i16 accValue = readRegister(data::Registers::ACC); if (value < accValue) writeRegister16(data::Registers::IP, addr); } break; case data::OpCodes::JmpGeImm: { - uint16_t addr = fetch16(); - int16_t value = fetch16(); - int16_t accValue = readRegister(data::Registers::ACC); + u16 addr = fetch16(); + i16 value = fetch16(); + i16 accValue = readRegister(data::Registers::ACC); if (value >= accValue) writeRegister16(data::Registers::IP, addr); } break; case data::OpCodes::JmpGeReg: { - uint16_t addr = fetch16(); - uint8_t regAddr = fetch8(); - int16_t value = readRegister(regAddr); - int16_t accValue = readRegister(data::Registers::ACC); + u16 addr = fetch16(); + u8 regAddr = fetch8(); + i16 value = readRegister(regAddr); + i16 accValue = readRegister(data::Registers::ACC); if (value >= accValue) writeRegister16(data::Registers::IP, addr); } break; case data::OpCodes::JmpLeImm: { - uint16_t addr = fetch16(); - int16_t value = fetch16(); - int16_t accValue = readRegister(data::Registers::ACC); + u16 addr = fetch16(); + i16 value = fetch16(); + i16 accValue = readRegister(data::Registers::ACC); if (value <= accValue) writeRegister16(data::Registers::IP, addr); } break; case data::OpCodes::JmpLeReg: { - uint16_t addr = fetch16(); - uint8_t regAddr = fetch8(); - int16_t value = readRegister(regAddr); - int16_t accValue = readRegister(data::Registers::ACC); + u16 addr = fetch16(); + u8 regAddr = fetch8(); + i16 value = readRegister(regAddr); + i16 accValue = readRegister(data::Registers::ACC); if (value <= accValue) writeRegister16(data::Registers::IP, addr); } break; case data::OpCodes::Jmp: { - uint16_t addr = fetch16(); + u16 addr = fetch16(); writeRegister16(data::Registers::IP, addr); } break; @@ -783,27 +783,27 @@ namespace dragon break; case data::OpCodes::PushImm: { - int16_t value = fetch16(); + i16 value = fetch16(); pushToStack(value); } break; case data::OpCodes::PushReg: { - uint8_t regAddr = fetch8(); - int16_t value = readRegister(regAddr); + u8 regAddr = fetch8(); + i16 value = readRegister(regAddr); pushToStack(value); } break; case data::OpCodes::PopReg: { - uint8_t regAddr = fetch8(); - int16_t value = popFromStack(); + u8 regAddr = fetch8(); + i16 value = popFromStack(); writeRegister16(regAddr, value); } break; case data::OpCodes::CallImm: { - uint16_t subroutineAddr = fetch16(); + u16 subroutineAddr = fetch16(); pushStackFrame(); writeRegister16(data::Registers::IP, subroutineAddr); m_subroutineCounter++; @@ -811,8 +811,8 @@ namespace dragon break; case data::OpCodes::CallReg: { - uint8_t regAddr = fetch8(); - uint16_t subroutineAddr = readRegister(regAddr); + u8 regAddr = fetch8(); + u16 subroutineAddr = readRegister(regAddr); pushStackFrame(); writeRegister16(data::Registers::IP, subroutineAddr); m_subroutineCounter++; @@ -827,10 +827,10 @@ namespace dragon break; case data::OpCodes::ArgReg: { - uint8_t regAddr = fetch8(); + u8 regAddr = fetch8(); if (!isInSubRoutine()) break; - int16_t pp_val = readRegister(data::Registers::PP); - int16_t arg_data = m_memory.read16(pp_val); + i16 pp_val = readRegister(data::Registers::PP); + i16 arg_data = m_memory.read16(pp_val); writeRegister16(data::Registers::PP, pp_val - 2); writeRegister16(regAddr, arg_data); } @@ -845,7 +845,7 @@ namespace dragon break; case data::OpCodes::Int: { - uint8_t intValue = fetch8(); + u8 intValue = fetch8(); if (!readFlag(data::Flags::InterruptsEnabled)) return true; handleInterrupt(intValue, false); @@ -854,19 +854,19 @@ namespace dragon break; case data::OpCodes::ZeroFlag: { - uint8_t flag = fetch8(); + u8 flag = fetch8(); setFlag(flag, false); } break; case data::OpCodes::SetFlag: { - uint8_t flag = fetch8(); + u8 flag = fetch8(); setFlag(flag, true); } break; case data::OpCodes::ToggleFlag: { - uint8_t flag = fetch8(); + u8 flag = fetch8(); bool value = readFlag(flag); setFlag(flag, !value); } @@ -909,8 +909,8 @@ namespace dragon if (!m_debugModeEnabled) return; String stackFrameString = ""; - uint16_t argStartAddr = readRegister(data::Registers::SP) + 2; - uint16_t argCount = m_memory.read16(argStartAddr); + u16 argStartAddr = readRegister(data::Registers::SP) + 2; + u16 argCount = m_memory.read16(argStartAddr); if (argCount == 0) argStartAddr = 0; else diff --git a/src/hardware/VirtualCPU.hpp b/src/hardware/VirtualCPU.hpp index 3b3431c..7c5a45d 100644 --- a/src/hardware/VirtualCPU.hpp +++ b/src/hardware/VirtualCPU.hpp @@ -18,65 +18,65 @@ namespace dragon public: enum class eDebugProfilerTimeUnits { Millis = 0, Secs = 1, Micros = 2, Nanos = 3 }; public: VirtualCPU(IMemoryDevice& memory); - int16_t readRegister(uint8_t reg); - int16_t writeRegister16(uint8_t reg, int16_t value); - int8_t writeRegister8(uint8_t reg, int8_t value); + i16 readRegister(u8 reg); + i16 writeRegister16(u8 reg, i16 value); + i8 writeRegister8(u8 reg, i8 value); //TODO: Implement readRegister8 and readRegister16 functions - int8_t fetch8(void); - int16_t fetch16(void); + i8 fetch8(void); + i16 fetch16(void); - void pushToStack(int16_t value); - int16_t popFromStack(void); + void pushToStack(i16 value); + i16 popFromStack(void); void pushStackFrame(void); void popStackFrame(void); - bool readFlag(uint8_t flg); - void setFlag(uint8_t flg, bool val = true); + bool readFlag(u8 flg); + void setFlag(u8 flg, bool val = true); - void handleInterrupt(uint8_t intValue, bool hardware); + void handleInterrupt(u8 intValue, bool hardware); bool loadExtension(void); bool execute(void); inline bool isHalted(void) const { return m_halt; } - inline uint8_t getCurrentInstruction(void) const { return m_currentInst; } + inline u8 getCurrentInstruction(void) const { return m_currentInst; } inline bool isInDebugBreakPoint(void) const { return m_isDebugBreakPoint; } inline bool isRamDumped(void) const { return m_ramDumped; } inline bool isInBIOSMOde(void) const { return m_biosMode; } inline bool isInSubRoutine(void) const { return m_subroutineCounter > 0; } - inline int32_t getSubRoutineCounter(void) const { return m_subroutineCounter; } + inline i32 getSubRoutineCounter(void) const { return m_subroutineCounter; } inline data::CPUExtension* getCurrentCPUExtension(void) const { return m_currentExtension; } - inline uint8_t getCurrentCPUExtensionInstruction(void) const { return m_currentExtInst; } + inline u8 getCurrentCPUExtensionInstruction(void) const { return m_currentExtInst; } inline bool isOffsetAddressingModeEnabled(void) const { return m_isOffsetAddressingEnabled; } - inline uint16_t getCurrentOffset(void) const { return m_currentOffset; } + inline u16 getCurrentOffset(void) const { return m_currentOffset; } private: void __debug_store_stack_frame_string_on_push(void); private: - int16_t m_registers[20]; + i16 m_registers[20]; ostd::BitField_16 m_tempFlags; IMemoryDevice& m_memory; - uint16_t m_stackFrameSize { 0 }; + u16 m_stackFrameSize { 0 }; bool m_halt { false }; - uint8_t m_currentInst { 0x00 }; - uint8_t m_currentAddr { 0x00 }; + u8 m_currentInst { 0x00 }; + u8 m_currentAddr { 0x00 }; bool m_biosMode { true }; - int32_t m_interruptHandlerCount { 0 }; + i32 m_interruptHandlerCount { 0 }; bool m_isDebugBreakPoint { false }; bool m_ramDumped { false }; bool m_debugModeEnabled { false }; - int32_t m_subroutineCounter { 0 }; + i32 m_subroutineCounter { 0 }; bool m_debugProfilerStarted { false }; bool m_isOffsetAddressingEnabled { false }; - uint16_t m_currentOffset { 0x0000 }; + u16 m_currentOffset { 0x0000 }; data::CPUExtension* m_extensions[16]; data::CPUExtension* m_currentExtension { nullptr }; - uint8_t m_currentExtInst { 0x00 }; + u8 m_currentExtInst { 0x00 }; std::vector m_debug_stackFrameStrings; diff --git a/src/hardware/VirtualDisplay.cpp b/src/hardware/VirtualDisplay.cpp index b3d3acb..db8431e 100644 --- a/src/hardware/VirtualDisplay.cpp +++ b/src/hardware/VirtualDisplay.cpp @@ -29,18 +29,18 @@ namespace dragon if (!isVisible()) return; auto& config = DragonRuntime::machine_config; auto& mem = DragonRuntime::memMap; - uint16_t vga_addr = data::MemoryMapAddresses::VideoCardInterface_Start; - uint8_t video_mode = mem.read8(vga_addr + tRegisters::VideoMode); + u16 vga_addr = data::MemoryMapAddresses::VideoCardInterface_Start; + u8 video_mode = mem.read8(vga_addr + tRegisters::VideoMode); if (video_mode == tVideoModeValues::TextSingleColor) { - uint8_t invert_colors = mem.read8(vga_addr + tRegisters::TextSingleInvertColors); + u8 invert_colors = mem.read8(vga_addr + tRegisters::TextSingleInvertColors); if (m_refreshScreen) { if (invert_colors == 0) m_renderer.clear(config.singleColor_background); else m_renderer.clear(config.singleColor_foreground); - for (int32_t i = 0; i < m_singleTextLines.size(); i++) + for (i32 i = 0; i < m_singleTextLines.size(); i++) { auto& line = m_singleTextLines[i]; if (invert_colors == 0) @@ -55,10 +55,10 @@ namespace dragon { if (m_refreshScreen) { - uint8_t clear_color = mem.read8(vga_addr + tRegisters::ClearColor); + u8 clear_color = mem.read8(vga_addr + tRegisters::ClearColor); ostd::Color clearColor = m_text16_Currentpalette->getColor(clear_color); m_renderer.clear(clearColor); - for (int32_t i = 0; i < ogfx::PixelRenderer::TextRenderer::CONSOLE_CHARS_V * ogfx::PixelRenderer::TextRenderer::CONSOLE_CHARS_H; i++) + for (i32 i = 0; i < ogfx::PixelRenderer::TextRenderer::CONSOLE_CHARS_V * ogfx::PixelRenderer::TextRenderer::CONSOLE_CHARS_H; i++) { auto& cell = m_text16_buffer[i]; ostd::Color background = m_text16_Currentpalette->getColor(cell.backgroundColor); @@ -84,9 +84,9 @@ namespace dragon void VirtualDisplay::onUpdate(void) { auto& mem = DragonRuntime::memMap; - uint16_t vga_addr = data::MemoryMapAddresses::VideoCardInterface_Start; - uint8_t video_mode = mem.read8(vga_addr + tRegisters::VideoMode); - uint8_t signal = mem.read8(vga_addr + tRegisters::Signal); + u16 vga_addr = data::MemoryMapAddresses::VideoCardInterface_Start; + u8 video_mode = mem.read8(vga_addr + tRegisters::VideoMode); + u8 signal = mem.read8(vga_addr + tRegisters::Signal); if (signal == tSignalValues::Continue) return; if (video_mode == tVideoModeValues::TextSingleColor) { @@ -97,7 +97,7 @@ namespace dragon } else if (signal == tSignalValues::TextSingleColor_DirectPrintString) { - uint16_t first_char_addr = mem.read16(vga_addr + tRegisters::TextSingleString); + u16 first_char_addr = mem.read16(vga_addr + tRegisters::TextSingleString); char c = ' '; int h = 0; while (c != 0) @@ -143,19 +143,19 @@ namespace dragon textCell.foregroundColor = mem.read8(vga_addr + tRegisters::MemControllerFGCol); textCell.backgroundColor = mem.read8(vga_addr + tRegisters::MemControllerBGCol); textCell.character = mem.read8(vga_addr + tRegisters::MemControllerChar); - int16_t x = mem.read16(vga_addr + tRegisters::MemControllerX); - int16_t y = mem.read16(vga_addr + tRegisters::MemControllerY); + i16 x = mem.read16(vga_addr + tRegisters::MemControllerX); + i16 y = mem.read16(vga_addr + tRegisters::MemControllerY); //TODO: Remove this override used for testing purposes - // for (int32_t i = 0; i < ogfx::PixelRenderer::TextRenderer::CONSOLE_CHARS_V * ogfx::PixelRenderer::TextRenderer::CONSOLE_CHARS_H; i++) + // for (i32 i = 0; i < ogfx::PixelRenderer::TextRenderer::CONSOLE_CHARS_V * ogfx::PixelRenderer::TextRenderer::CONSOLE_CHARS_H; i++) // { // auto xy = CONVERT_1D_2D(i, ogfx::PixelRenderer::TextRenderer::CONSOLE_CHARS_H); - // DragonRuntime::vGraphicsInterface.writeVRAM_16Colors(static_cast(xy.x), static_cast(xy.y), c++, 0, 15); + // 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); + DragonRuntime::vGraphicsInterface.writeVRAM_16Colors(static_cast(x), static_cast(y), textCell.character, textCell.backgroundColor, textCell.foregroundColor); } else if (signal == tSignalValues::ClearSCreen) { @@ -189,18 +189,18 @@ namespace dragon mem.write8(vga_addr + tRegisters::Signal, tSignalValues::Continue); } - void VirtualDisplay::onFixedUpdate(double frameTime_s) + void VirtualDisplay::onFixedUpdate(f64 frameTime_s) { auto& config = DragonRuntime::machine_config; auto& mem = DragonRuntime::memMap; - uint16_t vga_addr = data::MemoryMapAddresses::VideoCardInterface_Start; - uint8_t video_mode = mem.read8(vga_addr + tRegisters::VideoMode); - uint8_t signal = mem.read8(vga_addr + tRegisters::Signal); + u16 vga_addr = data::MemoryMapAddresses::VideoCardInterface_Start; + u8 video_mode = mem.read8(vga_addr + tRegisters::VideoMode); + u8 signal = mem.read8(vga_addr + tRegisters::Signal); if (video_mode == tVideoModeValues::Text16Colors) { m_refreshScreen = true; dragon::hw::interface::Graphics::tText16_Cell outTextCell; - for (int32_t i = 0; i < ogfx::PixelRenderer::TextRenderer::CONSOLE_CHARS_V * ogfx::PixelRenderer::TextRenderer::CONSOLE_CHARS_H; i++) + for (i32 i = 0; i < ogfx::PixelRenderer::TextRenderer::CONSOLE_CHARS_V * ogfx::PixelRenderer::TextRenderer::CONSOLE_CHARS_H; i++) { auto xy = CONVERT_1D_2D(i, ogfx::PixelRenderer::TextRenderer::CONSOLE_CHARS_H); DragonRuntime::vGraphicsInterface.readVRAM_16Colors(xy.x, xy.y, outTextCell); @@ -221,8 +221,8 @@ namespace dragon { auto& config = DragonRuntime::machine_config; auto& mem = DragonRuntime::memMap; - uint16_t vga_addr = data::MemoryMapAddresses::VideoCardInterface_Start; - uint8_t invert_colors = mem.read8(vga_addr + tRegisters::TextSingleInvertColors); + u16 vga_addr = data::MemoryMapAddresses::VideoCardInterface_Start; + u8 invert_colors = mem.read8(vga_addr + tRegisters::TextSingleInvertColors); if (m_singleTextLines.size() == 0) { m_singleTextLines.push_back(String().addChar(c)); @@ -306,7 +306,7 @@ namespace dragon void VirtualDisplay::text16_init_buffer(void) { - for (int32_t i = 0; i < ogfx::PixelRenderer::TextRenderer::CONSOLE_CHARS_V * ogfx::PixelRenderer::TextRenderer::CONSOLE_CHARS_H; i++) + for (i32 i = 0; i < ogfx::PixelRenderer::TextRenderer::CONSOLE_CHARS_V * ogfx::PixelRenderer::TextRenderer::CONSOLE_CHARS_H; i++) m_text16_buffer.push_back({ 0, 0, ' ' }); } diff --git a/src/hardware/VirtualDisplay.hpp b/src/hardware/VirtualDisplay.hpp index 74c1187..f11bcd7 100644 --- a/src/hardware/VirtualDisplay.hpp +++ b/src/hardware/VirtualDisplay.hpp @@ -13,45 +13,45 @@ namespace dragon { public: struct tRegisters { - inline static constexpr uint8_t VideoMode = 0x00; - inline static constexpr uint8_t ClearColor = 0x01; - inline static constexpr uint8_t Palette = 0x02; - inline static constexpr uint8_t Signal = 0x03; - inline static constexpr uint8_t TextSingleCharacter = 0x04; - inline static constexpr uint8_t TextSingleInvertColors = 0x05; - inline static constexpr uint8_t TextSingleString = 0x06; + inline static constexpr u8 VideoMode = 0x00; + inline static constexpr u8 ClearColor = 0x01; + inline static constexpr u8 Palette = 0x02; + inline static constexpr u8 Signal = 0x03; + inline static constexpr u8 TextSingleCharacter = 0x04; + inline static constexpr u8 TextSingleInvertColors = 0x05; + inline static constexpr u8 TextSingleString = 0x06; - inline static constexpr uint8_t Flags = 0x7E; + inline static constexpr u8 Flags = 0x7E; - inline static constexpr uint8_t MemControllerX = 0x80; - inline static constexpr uint8_t MemControllerY = 0x82; - inline static constexpr uint8_t MemControllerChar = 0x84; - inline static constexpr uint8_t MemControllerBGCol = 0x85; - inline static constexpr uint8_t MemControllerFGCol = 0x86; + inline static constexpr u8 MemControllerX = 0x80; + inline static constexpr u8 MemControllerY = 0x82; + inline static constexpr u8 MemControllerChar = 0x84; + inline static constexpr u8 MemControllerBGCol = 0x85; + inline static constexpr u8 MemControllerFGCol = 0x86; }; public: struct tVideoModeValues { - inline static constexpr uint8_t TextSingleColor = 0x00; - inline static constexpr uint8_t Text16Colors = 0x01; + inline static constexpr u8 TextSingleColor = 0x00; + inline static constexpr u8 Text16Colors = 0x01; }; public: struct tSignalValues { - inline static constexpr uint8_t Continue = 0x00; + inline static constexpr u8 Continue = 0x00; - inline static constexpr uint8_t TextSingleColor_DirectPrintChar = 0x02; - inline static constexpr uint8_t TextSingleColor_StoreChar = 0x03; - inline static constexpr uint8_t TextSingleColor_DirectPrintBuffAndFlush = 0x04; - inline static constexpr uint8_t TextSingleColor_FlushBuffer = 0x05; - inline static constexpr uint8_t TextSingleColor_DirectPrintBuffNoFlush = 0x06; - inline static constexpr uint8_t TextSingleColor_DirectPrintString = 0x07; + inline static constexpr u8 TextSingleColor_DirectPrintChar = 0x02; + inline static constexpr u8 TextSingleColor_StoreChar = 0x03; + inline static constexpr u8 TextSingleColor_DirectPrintBuffAndFlush = 0x04; + inline static constexpr u8 TextSingleColor_FlushBuffer = 0x05; + inline static constexpr u8 TextSingleColor_DirectPrintBuffNoFlush = 0x06; + inline static constexpr u8 TextSingleColor_DirectPrintString = 0x07; - inline static constexpr uint8_t Text16Color_SwapBuffers = 0x10; - inline static constexpr uint8_t Text16Color_WriteMemory = 0x11; - inline static constexpr uint8_t Text16Color_Scroll = 0x12; + inline static constexpr u8 Text16Color_SwapBuffers = 0x10; + inline static constexpr u8 Text16Color_WriteMemory = 0x11; + inline static constexpr u8 Text16Color_Scroll = 0x12; - inline static constexpr uint8_t RefreshScreen = 0xE0; - inline static constexpr uint8_t ClearSCreen = 0xE1; - inline static constexpr uint8_t RedrawScreen = 0xE2; + inline static constexpr u8 RefreshScreen = 0xE0; + inline static constexpr u8 ClearSCreen = 0xE1; + inline static constexpr u8 RedrawScreen = 0xE2; }; public: inline void setFont(const String& fontPath) { m_font.init(fontPath); } @@ -60,7 +60,7 @@ namespace dragon void onDestroy(void) override; void onRender(void) override; void onUpdate(void) override; - void onFixedUpdate(double frameTime_s) override; + void onFixedUpdate(f64 frameTime_s) override; inline void redrawScreen(void) { m_redrawScreen = true; } @@ -89,7 +89,7 @@ namespace dragon std::vector m_text16_buffer; std::vector m_text16_palettes; data::IBiosVideoPalette* m_text16_Currentpalette { nullptr }; - uint8_t m_currentPaletteID { 0 }; + u8 m_currentPaletteID { 0 }; bool m_redrawScreen { true }; }; diff --git a/src/hardware/VirtualHardDrive.cpp b/src/hardware/VirtualHardDrive.cpp index 801cd39..cc186c0 100644 --- a/src/hardware/VirtualHardDrive.cpp +++ b/src/hardware/VirtualHardDrive.cpp @@ -17,13 +17,13 @@ namespace dragon } m_fileSize = m_dataFile.tellg(); m_dataFile.seekg( 0, std::ios::end ); - m_fileSize = (int64_t)m_dataFile.tellg() - m_fileSize; + m_fileSize = (i64)m_dataFile.tellg() - m_fileSize; m_dataFile.seekg( 0, std::ios::beg ); m_diskID = s_nextDiskID++; m_initialized = true; } - bool VirtualHardDrive::read(uint32_t addr, uint16_t size, ostd::ByteStream& outData) + bool VirtualHardDrive::read(u32 addr, u16 size, ostd::ByteStream& outData) { if (!m_initialized) { @@ -35,10 +35,10 @@ namespace dragon data::ErrorHandler::pushError(data::ErrorCodes::HardDrive_ReadOverflow, "Read Overflow on HardDrive."); return false; } - uint8_t cell = 0; + u8 cell = 0; outData.clear(); m_dataFile.seekg(addr); - for (int32_t i = 0; i < size; i++) + for (i32 i = 0; i < size; i++) { m_dataFile.read((char*)&cell, sizeof(cell)); outData.push_back(cell); @@ -46,7 +46,7 @@ namespace dragon return true; } - bool VirtualHardDrive::write(uint32_t addr, int8_t value) + bool VirtualHardDrive::write(u32 addr, i8 value) { if (!m_initialized) { @@ -63,7 +63,7 @@ namespace dragon return true; } - void VirtualHardDrive::bufferedWrite(int8_t value) + void VirtualHardDrive::bufferedWrite(i8 value) { if (!m_initialized) { @@ -73,7 +73,7 @@ namespace dragon m_writeBuffer.push_back(value); } - bool VirtualHardDrive::writeBuffer(uint32_t addr) + bool VirtualHardDrive::writeBuffer(u32 addr) { if (!m_initialized) { diff --git a/src/hardware/VirtualHardDrive.hpp b/src/hardware/VirtualHardDrive.hpp index dbc794e..4cb3e00 100644 --- a/src/hardware/VirtualHardDrive.hpp +++ b/src/hardware/VirtualHardDrive.hpp @@ -14,25 +14,25 @@ namespace dragon 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); - void bufferedWrite(int8_t value); - bool writeBuffer(uint32_t addr); + bool read(u32 addr, u16 size, ostd::ByteStream& outData); + bool write(u32 addr, i8 value); + void bufferedWrite(i8 value); + bool writeBuffer(u32 addr); void unmount(void); inline bool isInitialized(void) const { return m_initialized; } - inline uint64_t getSize(void) const { return m_fileSize; }; + inline u64 getSize(void) const { return m_fileSize; }; inline bool isSame(VirtualHardDrive& vhdd) { return m_diskID == vhdd.m_diskID; } private: std::fstream m_dataFile; bool m_initialized { false }; - uint64_t m_fileSize { 0 }; + u64 m_fileSize { 0 }; ostd::ByteStream m_writeBuffer; - uint32_t m_diskID { 0 }; + u32 m_diskID { 0 }; - inline static uint32_t s_nextDiskID = 0; + inline static u32 s_nextDiskID = 0; }; } } diff --git a/src/hardware/VirtualIODevices.cpp b/src/hardware/VirtualIODevices.cpp index 426d8d6..ca82fd4 100644 --- a/src/hardware/VirtualIODevices.cpp +++ b/src/hardware/VirtualIODevices.cpp @@ -27,14 +27,14 @@ namespace dragon m_initialized = true; } - int8_t VirtualBIOS::read8(uint16_t addr) + i8 VirtualBIOS::read8(u16 addr) { if (addr >= m_bios.size()) 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) + i16 VirtualBIOS::read16(u16 addr) { if (addr >= m_bios.size() - 1) data::ErrorHandler::pushError(data::ErrorCodes::BIOS_InvalidAddress, String("Invalid Word BIOS location at address: ").add(String::getHexStr(addr, true, 2))); @@ -42,13 +42,13 @@ namespace dragon | ( m_bios[addr + 1] & 0x00FFU); } - int8_t VirtualBIOS::write8(uint16_t addr, int8_t value) + i8 VirtualBIOS::write8(u16 addr, i8 value) { 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) + i16 VirtualBIOS::write16(u16 addr, i16 value) { data::ErrorHandler::pushError(data::ErrorCodes::BIOS_WriteAttempt, String("Attempting to write to BIOS memory map: ").add(String::getHexStr(addr, true, 2))); return 0x0000; @@ -65,19 +65,19 @@ namespace dragon InterruptVector::InterruptVector(void) { - uint32_t dataSize = data::MemoryMapAddresses::IntVector_End - data::MemoryMapAddresses::IntVector_Start; - for (int32_t i = 0; i < dataSize; i++) + u32 dataSize = data::MemoryMapAddresses::IntVector_End - data::MemoryMapAddresses::IntVector_Start; + for (i32 i = 0; i < dataSize; i++) m_data.push_back(0x00); } - int8_t InterruptVector::read8(uint16_t addr) + i8 InterruptVector::read8(u16 addr) { if (addr >= m_data.size()) 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) + i16 InterruptVector::read16(u16 addr) { if (addr >= m_data.size() - 1) data::ErrorHandler::pushError(data::ErrorCodes::IntVector_InvalidAddress, String("Invalid Word IntVector location at address: ").add(String::getHexStr(addr, true, 2))); @@ -85,7 +85,7 @@ namespace dragon | ( m_data[addr + 1] & 0x00FFU); } - int8_t InterruptVector::write8(uint16_t addr, int8_t value) + i8 InterruptVector::write8(u16 addr, i8 value) { if (addr >= m_data.size()) data::ErrorHandler::pushError(data::ErrorCodes::IntVector_InvalidAddress, String("Invalid Word IntVector location at address: ").add(String::getHexStr(addr, true, 2))); @@ -93,7 +93,7 @@ namespace dragon return value; } - int16_t InterruptVector::write16(uint16_t addr, int16_t value) + i16 InterruptVector::write16(u16 addr, i16 value) { if (addr >= m_data.size() - 1) data::ErrorHandler::pushError(data::ErrorCodes::IntVector_InvalidAddress, String("Invalid Word IntVector location at address: ").add(String::getHexStr(addr, true, 2))); @@ -113,8 +113,8 @@ namespace dragon void VirtualKeyboard::init(void) { - uint32_t dataSize = data::MemoryMapAddresses::Keyboard_End - data::MemoryMapAddresses::Keyboard_Start; - for (int32_t i = 0; i < dataSize; i++) + u32 dataSize = data::MemoryMapAddresses::Keyboard_End - data::MemoryMapAddresses::Keyboard_Start; + for (i32 i = 0; i < dataSize; i++) m_data.push_back(0x00); enableSignals(); validate(); @@ -123,14 +123,14 @@ namespace dragon connectSignal(ostd::BuiltinSignals::TextEntered); } - int8_t VirtualKeyboard::read8(uint16_t addr) + i8 VirtualKeyboard::read8(u16 addr) { if (addr >= m_data.size()) 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) + i16 VirtualKeyboard::read16(u16 addr) { if (addr >= m_data.size() - 1) data::ErrorHandler::pushError(data::ErrorCodes::IntVector_InvalidAddress, String("Invalid Word KeyboardController location at address: ").add(String::getHexStr(addr, true, 2))); @@ -138,7 +138,7 @@ namespace dragon | ( m_data[addr + 1] & 0x00FFU); } - int8_t VirtualKeyboard::write8(uint16_t addr, int8_t value) + i8 VirtualKeyboard::write8(u16 addr, i8 value) { if (addr >= m_data.size()) data::ErrorHandler::pushError(data::ErrorCodes::IntVector_InvalidAddress, String("Invalid Word KeyboardController location at address: ").add(String::getHexStr(addr, true, 2))); @@ -150,7 +150,7 @@ namespace dragon return __write8(addr, value); } - int16_t VirtualKeyboard::write16(uint16_t addr, int16_t value) + i16 VirtualKeyboard::write16(u16 addr, i16 value) { if (addr >= m_data.size() - 1) data::ErrorHandler::pushError(data::ErrorCodes::IntVector_InvalidAddress, String("Invalid Word KeyboardController location at address: ").add(String::getHexStr(addr, true, 2))); @@ -175,7 +175,7 @@ namespace dragon { ogfx::KeyEventData& ked = (ogfx::KeyEventData&)signal.userData; m_modifiersBitFiels = __construct_modifiers_bitfield(); - __write16(tRegisters::Modifiers, (int16_t)m_modifiersBitFiels.value); + __write16(tRegisters::Modifiers, (i16)m_modifiersBitFiels.value); __write16(tRegisters::KeyCode, __sdl_key_code_convert(ked.keyCode)); if (ked.eventType == ogfx::KeyEventData::eKeyEvent::Pressed) cpu.handleInterrupt(data::InterruptCodes::KeyPressed, true); @@ -186,8 +186,8 @@ namespace dragon { ogfx::KeyEventData& ked = (ogfx::KeyEventData&)signal.userData; m_modifiersBitFiels = __construct_modifiers_bitfield(); - __write16(tRegisters::Modifiers, (int16_t)m_modifiersBitFiels.value); - __write16(tRegisters::KeyCode, (int16_t)ked.text[0]); + __write16(tRegisters::Modifiers, (i16)m_modifiersBitFiels.value); + __write16(tRegisters::KeyCode, (i16)ked.text[0]); cpu.handleInterrupt(data::InterruptCodes::TextEntered, true); } } @@ -210,145 +210,145 @@ namespace dragon return bitfield; } - int8_t VirtualKeyboard::__write8(uint16_t addr, int8_t value) + i8 VirtualKeyboard::__write8(u16 addr, i8 value) { m_data[addr] = value; return value; } - int16_t VirtualKeyboard::__write16(uint16_t addr, int16_t value) + i16 VirtualKeyboard::__write16(u16 addr, i16 value) { m_data[addr + 0] = (value >> 8) & 0xFF; m_data[addr + 1] = value & 0xFF; return value; } - int16_t VirtualKeyboard::__sdl_key_code_convert(int32_t keyCode) + i16 VirtualKeyboard::__sdl_key_code_convert(i32 keyCode) { switch (keyCode) { - case SDLK_LCTRL: return (int16_t)eKeys::LeftCTRL; - case SDLK_LSHIFT: return (int16_t)eKeys::LeftShift; - case SDLK_LALT: return (int16_t)eKeys::LeftALT; - case SDLK_LGUI: return (int16_t)eKeys::LeftSuper; - case SDLK_RCTRL: return (int16_t)eKeys::RightCTRL; - case SDLK_RSHIFT: return (int16_t)eKeys::RightShift; - case SDLK_RGUI: return (int16_t)eKeys::RightSuper; - case SDLK_RALT: return (int16_t)eKeys::RightALT; - case SDLK_KP_DIVIDE: return (int16_t)eKeys::KeyPadDivide; - case SDLK_KP_MULTIPLY: return (int16_t)eKeys::KeyPadMultiply; - case SDLK_KP_MINUS: return (int16_t)eKeys::KeyPadMinus; - case SDLK_KP_PLUS: return (int16_t)eKeys::KeyPadPlus; - case SDLK_KP_ENTER: return (int16_t)eKeys::KeyPadEnter; - case SDLK_KP_1: return (int16_t)eKeys::KeyPad1; - case SDLK_KP_2: return (int16_t)eKeys::KeyPad2; - case SDLK_KP_3: return (int16_t)eKeys::KeyPad3; - case SDLK_KP_4: return (int16_t)eKeys::KeyPad4; - case SDLK_KP_5: return (int16_t)eKeys::KeyPad5; - case SDLK_KP_6: return (int16_t)eKeys::KeyPad6; - case SDLK_KP_7: return (int16_t)eKeys::KeyPad7; - case SDLK_KP_8: return (int16_t)eKeys::KeyPad8; - case SDLK_KP_9: return (int16_t)eKeys::KeyPad9; - case SDLK_KP_0: return (int16_t)eKeys::KeyPad0; - case SDLK_KP_PERIOD: return (int16_t)eKeys::KeyPadPeriod; - case SDLK_PRINTSCREEN: return (int16_t)eKeys::PrintScreen; - case SDLK_INSERT: return (int16_t)eKeys::Insert; - case SDLK_HOME: return (int16_t)eKeys::Home; - case SDLK_PAGEUP: return (int16_t)eKeys::PageUp; - case SDLK_END: return (int16_t)eKeys::End; - case SDLK_PAGEDOWN: return (int16_t)eKeys::PageDown; - case SDLK_RIGHT: return (int16_t)eKeys::RightArrow; - case SDLK_LEFT: return (int16_t)eKeys::LeftArrow; - case SDLK_DOWN: return (int16_t)eKeys::DownArrow; - case SDLK_UP: return (int16_t)eKeys::UpArrow; - case SDLK_CAPSLOCK: return (int16_t)eKeys::CapsLock; - case SDLK_NUMLOCKCLEAR: return (int16_t)eKeys::NumLock; - case SDLK_SCROLLLOCK: return (int16_t)eKeys::ScrollLock; - case SDLK_F1: return (int16_t)eKeys::F1; - case SDLK_F2: return (int16_t)eKeys::F2; - case SDLK_F3: return (int16_t)eKeys::F3; - case SDLK_F4: return (int16_t)eKeys::F4; - case SDLK_F5: return (int16_t)eKeys::F5; - case SDLK_F6: return (int16_t)eKeys::F6; - case SDLK_F7: return (int16_t)eKeys::F7; - case SDLK_F8: return (int16_t)eKeys::F8; - case SDLK_F9: return (int16_t)eKeys::F9; - case SDLK_F10: return (int16_t)eKeys::F10; - case SDLK_F11: return (int16_t)eKeys::F11; - case SDLK_F12: return (int16_t)eKeys::F12; - case SDLK_DELETE: return (int16_t)eKeys::Delete; - case SDLK_RETURN: return (int16_t)eKeys::Return; - case SDLK_ESCAPE: return (int16_t)eKeys::Escape; - case SDLK_BACKSPACE: return (int16_t)eKeys::Backspace; - case SDLK_TAB: return (int16_t)eKeys::Tab; - case SDLK_SPACE: return (int16_t)eKeys::Spacebar; - case SDLK_EXCLAIM: return (int16_t)eKeys::ExclamationMark; - case SDLK_DBLAPOSTROPHE: return (int16_t)eKeys::DoubleQuote; - case SDLK_HASH: return (int16_t)eKeys::Hash; - case SDLK_PERCENT: return (int16_t)eKeys::Percent; - case SDLK_DOLLAR: return (int16_t)eKeys::DollarSign; - case SDLK_AMPERSAND: return (int16_t)eKeys::Ampersand; - case SDLK_APOSTROPHE: return (int16_t)eKeys::SingleQuote; - case SDLK_LEFTPAREN: return (int16_t)eKeys::LeftParenthesis; - case SDLK_RIGHTPAREN: return (int16_t)eKeys::RightParenthesis; - case SDLK_ASTERISK: return (int16_t)eKeys::Asterisk; - case SDLK_PLUS: return (int16_t)eKeys::Plus; - case SDLK_COMMA: return (int16_t)eKeys::Comma; - case SDLK_MINUS: return (int16_t)eKeys::Minus; - case SDLK_PERIOD: return (int16_t)eKeys::Period; - case SDLK_SLASH: return (int16_t)eKeys::ForwardSlash; - case SDLK_0: return (int16_t)eKeys::Num0; - case SDLK_1: return (int16_t)eKeys::Num1; - case SDLK_2: return (int16_t)eKeys::Num2; - case SDLK_3: return (int16_t)eKeys::Num3; - case SDLK_4: return (int16_t)eKeys::Num4; - case SDLK_5: return (int16_t)eKeys::Num5; - case SDLK_6: return (int16_t)eKeys::Num6; - case SDLK_7: return (int16_t)eKeys::Num7; - case SDLK_8: return (int16_t)eKeys::Num8; - case SDLK_9: return (int16_t)eKeys::Num9; - case SDLK_COLON: return (int16_t)eKeys::Colon; - case SDLK_SEMICOLON: return (int16_t)eKeys::Semicolon; - case SDLK_LESS: return (int16_t)eKeys::LessThan; - case SDLK_EQUALS: return (int16_t)eKeys::Equals; - case SDLK_GREATER: return (int16_t)eKeys::GreaterThan; - case SDLK_QUESTION: return (int16_t)eKeys::QuestionMark; - case SDLK_AT: return (int16_t)eKeys::AtSign; - case SDLK_LEFTBRACKET: return (int16_t)eKeys::LeftBracket; - case SDLK_BACKSLASH: return (int16_t)eKeys::BackSlash; - case SDLK_RIGHTBRACKET: return (int16_t)eKeys::RightBracket; - case SDLK_CARET: return (int16_t)eKeys::Caret; - case SDLK_UNDERSCORE: return (int16_t)eKeys::Underscore; - case SDLK_GRAVE: return (int16_t)eKeys::BackQuote; - case SDLK_A: return (int16_t)eKeys::LowerCase_a; - case SDLK_B: return (int16_t)eKeys::LowerCase_b; - case SDLK_C: return (int16_t)eKeys::LowerCase_c; - case SDLK_D: return (int16_t)eKeys::LowerCase_d; - case SDLK_E: return (int16_t)eKeys::LowerCase_e; - case SDLK_F: return (int16_t)eKeys::LowerCase_f; - case SDLK_G: return (int16_t)eKeys::LowerCase_g; - case SDLK_H: return (int16_t)eKeys::LowerCase_h; - case SDLK_I: return (int16_t)eKeys::LowerCase_i; - case SDLK_J: return (int16_t)eKeys::LowerCase_j; - case SDLK_K: return (int16_t)eKeys::LowerCase_k; - case SDLK_L: return (int16_t)eKeys::LowerCase_l; - case SDLK_M: return (int16_t)eKeys::LowerCase_m; - case SDLK_N: return (int16_t)eKeys::LowerCase_n; - case SDLK_O: return (int16_t)eKeys::LowerCase_o; - case SDLK_P: return (int16_t)eKeys::LowerCase_p; - case SDLK_Q: return (int16_t)eKeys::LowerCase_q; - case SDLK_R: return (int16_t)eKeys::LowerCase_r; - case SDLK_S: return (int16_t)eKeys::LowerCase_s; - case SDLK_T: return (int16_t)eKeys::LowerCase_t; - case SDLK_U: return (int16_t)eKeys::LowerCase_u; - case SDLK_V: return (int16_t)eKeys::LowerCase_v; - case SDLK_W: return (int16_t)eKeys::LowerCase_w; - case SDLK_X: return (int16_t)eKeys::LowerCase_x; - case SDLK_Y: return (int16_t)eKeys::LowerCase_y; - case SDLK_Z: return (int16_t)eKeys::LowerCase_z; - default: return (int16_t)eKeys::UpperCase_A; + case SDLK_LCTRL: return (i16)eKeys::LeftCTRL; + case SDLK_LSHIFT: return (i16)eKeys::LeftShift; + case SDLK_LALT: return (i16)eKeys::LeftALT; + case SDLK_LGUI: return (i16)eKeys::LeftSuper; + case SDLK_RCTRL: return (i16)eKeys::RightCTRL; + case SDLK_RSHIFT: return (i16)eKeys::RightShift; + case SDLK_RGUI: return (i16)eKeys::RightSuper; + case SDLK_RALT: return (i16)eKeys::RightALT; + case SDLK_KP_DIVIDE: return (i16)eKeys::KeyPadDivide; + case SDLK_KP_MULTIPLY: return (i16)eKeys::KeyPadMultiply; + case SDLK_KP_MINUS: return (i16)eKeys::KeyPadMinus; + case SDLK_KP_PLUS: return (i16)eKeys::KeyPadPlus; + case SDLK_KP_ENTER: return (i16)eKeys::KeyPadEnter; + case SDLK_KP_1: return (i16)eKeys::KeyPad1; + case SDLK_KP_2: return (i16)eKeys::KeyPad2; + case SDLK_KP_3: return (i16)eKeys::KeyPad3; + case SDLK_KP_4: return (i16)eKeys::KeyPad4; + case SDLK_KP_5: return (i16)eKeys::KeyPad5; + case SDLK_KP_6: return (i16)eKeys::KeyPad6; + case SDLK_KP_7: return (i16)eKeys::KeyPad7; + case SDLK_KP_8: return (i16)eKeys::KeyPad8; + case SDLK_KP_9: return (i16)eKeys::KeyPad9; + case SDLK_KP_0: return (i16)eKeys::KeyPad0; + case SDLK_KP_PERIOD: return (i16)eKeys::KeyPadPeriod; + case SDLK_PRINTSCREEN: return (i16)eKeys::PrintScreen; + case SDLK_INSERT: return (i16)eKeys::Insert; + case SDLK_HOME: return (i16)eKeys::Home; + case SDLK_PAGEUP: return (i16)eKeys::PageUp; + case SDLK_END: return (i16)eKeys::End; + case SDLK_PAGEDOWN: return (i16)eKeys::PageDown; + case SDLK_RIGHT: return (i16)eKeys::RightArrow; + case SDLK_LEFT: return (i16)eKeys::LeftArrow; + case SDLK_DOWN: return (i16)eKeys::DownArrow; + case SDLK_UP: return (i16)eKeys::UpArrow; + case SDLK_CAPSLOCK: return (i16)eKeys::CapsLock; + case SDLK_NUMLOCKCLEAR: return (i16)eKeys::NumLock; + case SDLK_SCROLLLOCK: return (i16)eKeys::ScrollLock; + case SDLK_F1: return (i16)eKeys::F1; + case SDLK_F2: return (i16)eKeys::F2; + case SDLK_F3: return (i16)eKeys::F3; + case SDLK_F4: return (i16)eKeys::F4; + case SDLK_F5: return (i16)eKeys::F5; + case SDLK_F6: return (i16)eKeys::F6; + case SDLK_F7: return (i16)eKeys::F7; + case SDLK_F8: return (i16)eKeys::F8; + case SDLK_F9: return (i16)eKeys::F9; + case SDLK_F10: return (i16)eKeys::F10; + case SDLK_F11: return (i16)eKeys::F11; + case SDLK_F12: return (i16)eKeys::F12; + case SDLK_DELETE: return (i16)eKeys::Delete; + case SDLK_RETURN: return (i16)eKeys::Return; + case SDLK_ESCAPE: return (i16)eKeys::Escape; + case SDLK_BACKSPACE: return (i16)eKeys::Backspace; + case SDLK_TAB: return (i16)eKeys::Tab; + case SDLK_SPACE: return (i16)eKeys::Spacebar; + case SDLK_EXCLAIM: return (i16)eKeys::ExclamationMark; + case SDLK_DBLAPOSTROPHE: return (i16)eKeys::DoubleQuote; + case SDLK_HASH: return (i16)eKeys::Hash; + case SDLK_PERCENT: return (i16)eKeys::Percent; + case SDLK_DOLLAR: return (i16)eKeys::DollarSign; + case SDLK_AMPERSAND: return (i16)eKeys::Ampersand; + case SDLK_APOSTROPHE: return (i16)eKeys::SingleQuote; + case SDLK_LEFTPAREN: return (i16)eKeys::LeftParenthesis; + case SDLK_RIGHTPAREN: return (i16)eKeys::RightParenthesis; + case SDLK_ASTERISK: return (i16)eKeys::Asterisk; + case SDLK_PLUS: return (i16)eKeys::Plus; + case SDLK_COMMA: return (i16)eKeys::Comma; + case SDLK_MINUS: return (i16)eKeys::Minus; + case SDLK_PERIOD: return (i16)eKeys::Period; + case SDLK_SLASH: return (i16)eKeys::ForwardSlash; + case SDLK_0: return (i16)eKeys::Num0; + case SDLK_1: return (i16)eKeys::Num1; + case SDLK_2: return (i16)eKeys::Num2; + case SDLK_3: return (i16)eKeys::Num3; + case SDLK_4: return (i16)eKeys::Num4; + case SDLK_5: return (i16)eKeys::Num5; + case SDLK_6: return (i16)eKeys::Num6; + case SDLK_7: return (i16)eKeys::Num7; + case SDLK_8: return (i16)eKeys::Num8; + case SDLK_9: return (i16)eKeys::Num9; + case SDLK_COLON: return (i16)eKeys::Colon; + case SDLK_SEMICOLON: return (i16)eKeys::Semicolon; + case SDLK_LESS: return (i16)eKeys::LessThan; + case SDLK_EQUALS: return (i16)eKeys::Equals; + case SDLK_GREATER: return (i16)eKeys::GreaterThan; + case SDLK_QUESTION: return (i16)eKeys::QuestionMark; + case SDLK_AT: return (i16)eKeys::AtSign; + case SDLK_LEFTBRACKET: return (i16)eKeys::LeftBracket; + case SDLK_BACKSLASH: return (i16)eKeys::BackSlash; + case SDLK_RIGHTBRACKET: return (i16)eKeys::RightBracket; + case SDLK_CARET: return (i16)eKeys::Caret; + case SDLK_UNDERSCORE: return (i16)eKeys::Underscore; + case SDLK_GRAVE: return (i16)eKeys::BackQuote; + case SDLK_A: return (i16)eKeys::LowerCase_a; + case SDLK_B: return (i16)eKeys::LowerCase_b; + case SDLK_C: return (i16)eKeys::LowerCase_c; + case SDLK_D: return (i16)eKeys::LowerCase_d; + case SDLK_E: return (i16)eKeys::LowerCase_e; + case SDLK_F: return (i16)eKeys::LowerCase_f; + case SDLK_G: return (i16)eKeys::LowerCase_g; + case SDLK_H: return (i16)eKeys::LowerCase_h; + case SDLK_I: return (i16)eKeys::LowerCase_i; + case SDLK_J: return (i16)eKeys::LowerCase_j; + case SDLK_K: return (i16)eKeys::LowerCase_k; + case SDLK_L: return (i16)eKeys::LowerCase_l; + case SDLK_M: return (i16)eKeys::LowerCase_m; + case SDLK_N: return (i16)eKeys::LowerCase_n; + case SDLK_O: return (i16)eKeys::LowerCase_o; + case SDLK_P: return (i16)eKeys::LowerCase_p; + case SDLK_Q: return (i16)eKeys::LowerCase_q; + case SDLK_R: return (i16)eKeys::LowerCase_r; + case SDLK_S: return (i16)eKeys::LowerCase_s; + case SDLK_T: return (i16)eKeys::LowerCase_t; + case SDLK_U: return (i16)eKeys::LowerCase_u; + case SDLK_V: return (i16)eKeys::LowerCase_v; + case SDLK_W: return (i16)eKeys::LowerCase_w; + case SDLK_X: return (i16)eKeys::LowerCase_x; + case SDLK_Y: return (i16)eKeys::LowerCase_y; + case SDLK_Z: return (i16)eKeys::LowerCase_z; + default: return (i16)eKeys::UpperCase_A; } - return (int16_t)eKeys::UpperCase_A; + return (i16)eKeys::UpperCase_A; } @@ -360,22 +360,22 @@ namespace dragon { } - int8_t VirtualMouse::read8(uint16_t addr) + i8 VirtualMouse::read8(u16 addr) { return 0x00; } - int16_t VirtualMouse::read16(uint16_t addr) + i16 VirtualMouse::read16(u16 addr) { return 0x0000; } - int8_t VirtualMouse::write8(uint16_t addr, int8_t value) + i8 VirtualMouse::write8(u16 addr, i8 value) { return 0x00; } - int16_t VirtualMouse::write16(uint16_t addr, int16_t value) + i16 VirtualMouse::write16(u16 addr, i16 value) { return 0x0000; } @@ -391,18 +391,18 @@ namespace dragon VirtualBootloader::VirtualBootloader(void) { - for (int32_t i = 0; i < 512; i++) + for (i32 i = 0; i < 512; i++) m_mbr.push_back(0); } - int8_t VirtualBootloader::read8(uint16_t addr) + i8 VirtualBootloader::read8(u16 addr) { if (addr >= m_mbr.size()) 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) + i16 VirtualBootloader::read16(u16 addr) { if (addr >= m_mbr.size() - 1) data::ErrorHandler::pushError(data::ErrorCodes::BIOS_InvalidAddress, String("Invalid Word MBR location at address: ").add(String::getHexStr(addr, true, 2))); @@ -410,7 +410,7 @@ namespace dragon | ( m_mbr[addr + 1] & 0x00FFU); } - int8_t VirtualBootloader::write8(uint16_t addr, int8_t value) + i8 VirtualBootloader::write8(u16 addr, i8 value) { if (addr >= m_mbr.size()) data::ErrorHandler::pushError(data::ErrorCodes::IntVector_InvalidAddress, String("Invalid Word IntVector location at address: ").add(String::getHexStr(addr, true, 2))); @@ -418,7 +418,7 @@ namespace dragon return value; } - int16_t VirtualBootloader::write16(uint16_t addr, int16_t value) + i16 VirtualBootloader::write16(u16 addr, i16 value) { if (addr >= m_mbr.size() - 1) data::ErrorHandler::pushError(data::ErrorCodes::IntVector_InvalidAddress, String("Invalid Word IntVector location at address: ").add(String::getHexStr(addr, true, 2))); @@ -442,9 +442,9 @@ namespace dragon m_data.w_Byte(tRegisters::Signal, tSignalValues::Ignore); } - int8_t Disk::read8(uint16_t addr) + i8 Disk::read8(u16 addr) { - int8_t value = 0; + i8 value = 0; if (!m_data.r_Byte(addr, value)) { data::ErrorHandler::pushError(data::ErrorCodes::HardDrive_ControllerReadFailed, "Failed to read byte from HardDrive Controller"); @@ -453,9 +453,9 @@ namespace dragon return value; } - int16_t Disk::read16(uint16_t addr) + i16 Disk::read16(u16 addr) { - int16_t value = 0; + i16 value = 0; if (!m_data.r_Word(addr, value)) { data::ErrorHandler::pushError(data::ErrorCodes::HardDrive_ControllerReadFailed, "Failed to read word from HardDrive Controller"); @@ -464,7 +464,7 @@ namespace dragon return value; } - int8_t Disk::write8(uint16_t addr, int8_t value) + i8 Disk::write8(u16 addr, i8 value) { if (addr >= tRegisters::FirstReadOnly) { @@ -479,7 +479,7 @@ namespace dragon return value; } - int16_t Disk::write16(uint16_t addr, int16_t value) + i16 Disk::write16(u16 addr, i16 value) { if (addr >= tRegisters::FirstReadOnly) { @@ -501,8 +501,8 @@ namespace dragon void Disk::cycleStep(void) { - uint8_t signal = tSignalValues::Ignore; - m_data.r_Byte(tRegisters::Signal, (int8_t&)signal); + u8 signal = tSignalValues::Ignore; + m_data.r_Byte(tRegisters::Signal, (i8&)signal); if (m_busy) { if (signal == tSignalValues::Cancel) @@ -518,21 +518,21 @@ namespace dragon m_busy = false; return; } - uint8_t status = 0; - m_data.r_Byte(tRegisters::Status, (int8_t&)status); + u8 status = 0; + m_data.r_Byte(tRegisters::Status, (i8&)status); if (status == tStatusValues::Free) { data::ErrorHandler::pushError(data::ErrorCodes::HardDrive_InvalidConfiguration, "Invalid HardDrive configuration: register set to while busy."); m_busy = false; return; } - uint8_t currentDisk = 0; - uint16_t currentSector = 0, currentAddress = 0, restDataSize = 0, memoryAddress = 0; - m_data.r_Byte(tRegisters::CurrentDisk, (int8_t&)currentDisk); - m_data.r_Word(tRegisters::CurrentSector, (int16_t&)currentSector); - m_data.r_Word(tRegisters::CurrentAddress, (int16_t&)currentAddress); - m_data.r_Word(tRegisters::RestDataSize, (int16_t&)restDataSize); - m_data.r_Word(tRegisters::SourceData, (int16_t&)memoryAddress); + u8 currentDisk = 0; + u16 currentSector = 0, currentAddress = 0, restDataSize = 0, memoryAddress = 0; + m_data.r_Byte(tRegisters::CurrentDisk, (i8&)currentDisk); + m_data.r_Word(tRegisters::CurrentSector, (i16&)currentSector); + m_data.r_Word(tRegisters::CurrentAddress, (i16&)currentAddress); + m_data.r_Word(tRegisters::RestDataSize, (i16&)restDataSize); + m_data.r_Word(tRegisters::SourceData, (i16&)memoryAddress); if (m_connectedDisks.count((data::VDiskID)currentDisk) == 0) { data::ErrorHandler::pushError(data::ErrorCodes::HardDrive_InvalidDiskSelected, "Invalid HardDrive configuration: selected Disk not found."); @@ -540,7 +540,7 @@ namespace dragon return; } auto& disk = *m_connectedDisks[currentDisk]; - uint32_t hddAddress = 0; + u32 hddAddress = 0; if (currentAddress == 0xFFFF) { if (currentSector == 0xFFFF) @@ -566,7 +566,7 @@ namespace dragon } else if (status == tStatusValues::Writing) { - int8_t dataRead = m_memory.read8(memoryAddress); + i8 dataRead = m_memory.read8(memoryAddress); if (!disk.write(hddAddress, dataRead)) { data::ErrorHandler::pushError(data::ErrorCodes::HardDrive_WriteFailed, "HardDrive Error: Failed to write data."); @@ -598,14 +598,14 @@ namespace dragon return; } if (signal != tSignalValues::Start) return; - uint8_t mode = 0, disk = 0; - uint16_t sector = 0, address = 0, size = 0, srcAddr = 0; - m_data.r_Byte(tRegisters::ModeSelector, (int8_t&)mode); - m_data.r_Byte(tRegisters::DiskSelector, (int8_t&)disk); - m_data.r_Word(tRegisters::SectorSelector, (int16_t&)sector); - m_data.r_Word(tRegisters::AddressSelector, (int16_t&)address); - m_data.r_Word(tRegisters::DataSize, (int16_t&)size); - m_data.r_Word(tRegisters::DataSourceAddress, (int16_t&)srcAddr); + u8 mode = 0, disk = 0; + u16 sector = 0, address = 0, size = 0, srcAddr = 0; + m_data.r_Byte(tRegisters::ModeSelector, (i8&)mode); + m_data.r_Byte(tRegisters::DiskSelector, (i8&)disk); + m_data.r_Word(tRegisters::SectorSelector, (i16&)sector); + m_data.r_Word(tRegisters::AddressSelector, (i16&)address); + m_data.r_Word(tRegisters::DataSize, (i16&)size); + m_data.r_Word(tRegisters::DataSourceAddress, (i16&)srcAddr); if (mode == tModeValues::Read) m_data.w_Byte(tRegisters::Status, tStatusValues::Reading); else if (mode == tModeValues::Write) @@ -666,9 +666,9 @@ namespace dragon m_16Color_secondFrameAddr = m_vramStart + m_16Color_frameSize; } - int8_t Graphics::read8(uint16_t addr) + i8 Graphics::read8(u16 addr) { - int8_t outVal = 0; + i8 outVal = 0; if (!m_videoMemory.r_Byte(addr, outVal)) { data::ErrorHandler::pushError(data::ErrorCodes::Graphics_MemoryReadFailed, "Failed to read byte from Graphics Memory"); @@ -677,9 +677,9 @@ namespace dragon return outVal; } - int16_t Graphics::read16(uint16_t addr) + i16 Graphics::read16(u16 addr) { - int16_t outVal = 0; + i16 outVal = 0; if (!m_videoMemory.r_Word(addr, outVal)) { data::ErrorHandler::pushError(data::ErrorCodes::Graphics_MemoryReadFailed, "Failed to read word from Graphics Memory"); @@ -688,7 +688,7 @@ namespace dragon return outVal; } - int8_t Graphics::write8(uint16_t addr, int8_t value) + i8 Graphics::write8(u16 addr, i8 value) { if (!m_videoMemory.w_Byte(addr, value)) { @@ -698,7 +698,7 @@ namespace dragon return value; } - int16_t Graphics::write16(uint16_t addr, int16_t value) + i16 Graphics::write16(u16 addr, i16 value) { if (!m_videoMemory.w_Word(addr, value)) { @@ -708,20 +708,20 @@ namespace dragon return value; } - bool Graphics::readFlag(uint8_t flg) + bool Graphics::readFlag(u8 flg) { if (flg >= 16) return false; - int16_t outValue = 0; + i16 outValue = 0; if (!m_videoMemory.r_Word(VirtualDisplay::tRegisters::Flags, outValue)) return false; //TODO: Error m_tempFlags.value = outValue; return ostd::Bits::get(m_tempFlags, flg); } - void Graphics::setFlag(uint8_t flg, bool val) + void Graphics::setFlag(u8 flg, bool val) { if (flg >= 16) return; - int16_t outValue = 0; + i16 outValue = 0; if (!m_videoMemory.r_Word(VirtualDisplay::tRegisters::Flags, outValue)) return; //TODO: Error m_tempFlags.value = outValue; @@ -735,11 +735,11 @@ namespace dragon return &m_videoMemory.getData(); } - bool Graphics::readVRAM_16Colors(uint8_t x, uint8_t y, Graphics::tText16_Cell& outTextCell) + bool Graphics::readVRAM_16Colors(u8 x, u8 y, Graphics::tText16_Cell& outTextCell) { - uint16_t cellOffset = static_cast(CONVERT_2D_1D(x, y, ogfx::PixelRenderer::TextRenderer::CONSOLE_CHARS_H)) * 4; + u16 cellOffset = static_cast(CONVERT_2D_1D(x, y, ogfx::PixelRenderer::TextRenderer::CONSOLE_CHARS_H)) * 4; cellOffset += m_16Color_currentFrameAddr; - int8_t outVal = 0; + i8 outVal = 0; if (!m_videoMemory.r_Byte(cellOffset + tText16_CellStructure::character, outVal)) return false; //TODO: Error outTextCell.character = outVal; @@ -752,9 +752,9 @@ namespace dragon return true; } - bool Graphics::writeVRAM_16Colors(uint8_t x, uint8_t y, uint8_t character, uint8_t background, uint8_t foreground) + bool Graphics::writeVRAM_16Colors(u8 x, u8 y, u8 character, u8 background, u8 foreground) { - uint16_t cellOffset = static_cast(CONVERT_2D_1D(x, y, ogfx::PixelRenderer::TextRenderer::CONSOLE_CHARS_H)) * 4; + u16 cellOffset = static_cast(CONVERT_2D_1D(x, y, ogfx::PixelRenderer::TextRenderer::CONSOLE_CHARS_H)) * 4; if (!readFlag(tFlags::DoubleBufferingEnabled)) cellOffset += m_16Color_currentFrameAddr; else @@ -768,9 +768,9 @@ namespace dragon return true; } - bool Graphics::clearVRAM_16Colors(uint8_t character, uint8_t background, uint8_t foreground) + bool Graphics::clearVRAM_16Colors(u8 character, u8 background, u8 foreground) { - for (int32_t i = m_16Color_currentFrameAddr; i < m_16Color_currentFrameAddr + m_16Color_frameSize; i += 4) + for (i32 i = m_16Color_currentFrameAddr; i < m_16Color_currentFrameAddr + m_16Color_frameSize; i += 4) { m_videoMemory.w_Byte(i + tText16_CellStructure::character, character); m_videoMemory.w_Byte(i + tText16_CellStructure::background, background); @@ -783,9 +783,9 @@ namespace dragon { if (!readFlag(tFlags::DoubleBufferingEnabled)) return; - for (int32_t i = m_16Color_currentFrameAddr, j = 0; i < m_16Color_currentFrameAddr + m_16Color_frameSize; i += 4, j += 4) + for (i32 i = m_16Color_currentFrameAddr, j = 0; i < m_16Color_currentFrameAddr + m_16Color_frameSize; i += 4, j += 4) { - int8_t outByte = 0; + i8 outByte = 0; m_videoMemory.r_Byte(m_16Color_secondFrameAddr + j, outByte); m_videoMemory.w_Byte(i + tText16_CellStructure::character, outByte); m_videoMemory.r_Byte(m_16Color_secondFrameAddr + j + 1, outByte); @@ -793,18 +793,18 @@ namespace dragon m_videoMemory.r_Byte(m_16Color_secondFrameAddr + j + 2, outByte); m_videoMemory.w_Byte(i + tText16_CellStructure::foreground, outByte); } - uint16_t tmp = m_16Color_currentFrameAddr; + u16 tmp = m_16Color_currentFrameAddr; m_16Color_currentFrameAddr = m_16Color_secondFrameAddr; m_16Color_secondFrameAddr = tmp; } void Graphics::scroll_16Colors(void) { - int32_t line_len = (ogfx::PixelRenderer::TextRenderer::CONSOLE_CHARS_H * 4); - for (int32_t i = m_16Color_currentFrameAddr + line_len; i < m_16Color_currentFrameAddr + m_16Color_frameSize; i += 4) + i32 line_len = (ogfx::PixelRenderer::TextRenderer::CONSOLE_CHARS_H * 4); + for (i32 i = m_16Color_currentFrameAddr + line_len; i < m_16Color_currentFrameAddr + m_16Color_frameSize; i += 4) { - int32_t k = i; - int8_t outByte = 0; + i32 k = i; + i8 outByte = 0; m_videoMemory.r_Byte(k, outByte); m_videoMemory.w_Byte(k - line_len, outByte); k++; @@ -814,7 +814,7 @@ namespace dragon m_videoMemory.r_Byte(k, outByte); m_videoMemory.w_Byte(k - line_len, outByte); } - for (int32_t i = m_16Color_currentFrameAddr + m_16Color_frameSize - line_len; i < m_16Color_currentFrameAddr + m_16Color_frameSize; i += 4) + for (i32 i = m_16Color_currentFrameAddr + m_16Color_frameSize - line_len; i < m_16Color_currentFrameAddr + m_16Color_frameSize; i += 4) { m_videoMemory.w_Byte(i, 0x20); } @@ -828,22 +828,22 @@ namespace dragon { } - int8_t SerialPort::read8(uint16_t addr) + i8 SerialPort::read8(u16 addr) { return 0x00; } - int16_t SerialPort::read16(uint16_t addr) + i16 SerialPort::read16(u16 addr) { return 0x0000; } - int8_t SerialPort::write8(uint16_t addr, int8_t value) + i8 SerialPort::write8(u16 addr, i8 value) { return 0x00; } - int16_t SerialPort::write16(uint16_t addr, int16_t value) + i16 SerialPort::write16(u16 addr, i16 value) { return 0x0000; } @@ -868,7 +868,7 @@ namespace dragon } m_fileSize = m_dataFile.tellg(); m_dataFile.seekg( 0, std::ios::end ); - m_fileSize = (int64_t)m_dataFile.tellg() - m_fileSize; + m_fileSize = (i64)m_dataFile.tellg() - m_fileSize; m_dataFile.seekg( 0, std::ios::beg ); if (m_fileSize != m_size) { @@ -878,7 +878,7 @@ namespace dragon m_initialized = true; } - int8_t CMOS::read8(uint16_t addr) + i8 CMOS::read8(u16 addr) { if (!m_initialized) { @@ -890,13 +890,13 @@ namespace dragon 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; + i8 value = 0; m_dataFile.seekg(addr); m_dataFile.read((char*)&value, sizeof(value)); return value; } - int16_t CMOS::read16(uint16_t addr) + i16 CMOS::read16(u16 addr) { if (!m_initialized) { @@ -908,13 +908,13 @@ namespace dragon 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); - int8_t b2 = read8(addr + 1); + i8 b1 = read8(addr); + i8 b2 = read8(addr + 1); return ((b1 << 8) & 0xFF00U) | (b2 & 0x00FFU); } - int8_t CMOS::write8(uint16_t addr, int8_t value) + i8 CMOS::write8(u16 addr, i8 value) { if (!m_initialized) { @@ -936,7 +936,7 @@ namespace dragon return value; } - int16_t CMOS::write16(uint16_t addr, int16_t value) + i16 CMOS::write16(u16 addr, i16 value) { if (!m_initialized) { @@ -953,8 +953,8 @@ namespace dragon 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; - int8_t b2 = (value & 0xFF); + i8 b1 = (value >> 8) & 0xFF; + i8 b2 = (value & 0xFF); write8(addr, b1); write8(addr + 1, b2); return value; diff --git a/src/hardware/VirtualIODevices.hpp b/src/hardware/VirtualIODevices.hpp index 4b1a0c4..b00f5f7 100644 --- a/src/hardware/VirtualIODevices.hpp +++ b/src/hardware/VirtualIODevices.hpp @@ -21,10 +21,10 @@ namespace dragon inline VirtualBIOS(void) { m_initialized = 0; } 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; - int16_t write16(uint16_t addr, int16_t value) override; + i8 read8(u16 addr) override; + i16 read16(u16 addr) override; + i8 write8(u16 addr, i8 value) override; + i16 write16(u16 addr, i16 value) override; ostd::ByteStream* getByteStream(void) override; @@ -36,10 +36,10 @@ namespace dragon { public: InterruptVector(void); - int8_t read8(uint16_t addr) override; - int16_t read16(uint16_t addr) override; - int8_t write8(uint16_t addr, int8_t value) override; - int16_t write16(uint16_t addr, int16_t value) override; + i8 read8(u16 addr) override; + i16 read16(u16 addr) override; + i8 write8(u16 addr, i8 value) override; + i16 write16(u16 addr, i16 value) override; ostd::ByteStream* getByteStream(void) override; @@ -50,186 +50,186 @@ namespace dragon { public: enum class eKeys { - Delete = (int16_t)'\x7F', - Return = (int16_t)'\r', - Escape = (int16_t)'\x1B', - Backspace = (int16_t)'\b', - Tab = (int16_t)'\t', - Spacebar = (int16_t)' ', - ExclamationMark = (int16_t)'!', - DoubleQuote = (int16_t)'"', - Hash = (int16_t)'#', - Percent = (int16_t)'%', - DollarSign = (int16_t)'$', - Ampersand = (int16_t)'&', - SingleQuote = (int16_t)'\'', - LeftParenthesis = (int16_t)'(', - RightParenthesis = (int16_t)')', - Asterisk = (int16_t)'*', - Plus = (int16_t)'+', - Comma = (int16_t)',', - Minus = (int16_t)'-', - Period = (int16_t)'.', - ForwardSlash = (int16_t)'/', - Num0 = (int16_t)'0', - Num1 = (int16_t)'1', - Num2 = (int16_t)'2', - Num3 = (int16_t)'3', - Num4 = (int16_t)'4', - Num5 = (int16_t)'5', - Num6 = (int16_t)'6', - Num7 = (int16_t)'7', - Num8 = (int16_t)'8', - Num9 = (int16_t)'9', - Colon = (int16_t)':', - Semicolon = (int16_t)';', - LessThan = (int16_t)'<', - Equals = (int16_t)'=', - GreaterThan = (int16_t)'>', - QuestionMark = (int16_t)'?', - AtSign = (int16_t)'@', + Delete = (i16)'\x7F', + Return = (i16)'\r', + Escape = (i16)'\x1B', + Backspace = (i16)'\b', + Tab = (i16)'\t', + Spacebar = (i16)' ', + ExclamationMark = (i16)'!', + DoubleQuote = (i16)'"', + Hash = (i16)'#', + Percent = (i16)'%', + DollarSign = (i16)'$', + Ampersand = (i16)'&', + SingleQuote = (i16)'\'', + LeftParenthesis = (i16)'(', + RightParenthesis = (i16)')', + Asterisk = (i16)'*', + Plus = (i16)'+', + Comma = (i16)',', + Minus = (i16)'-', + Period = (i16)'.', + ForwardSlash = (i16)'/', + Num0 = (i16)'0', + Num1 = (i16)'1', + Num2 = (i16)'2', + Num3 = (i16)'3', + Num4 = (i16)'4', + Num5 = (i16)'5', + Num6 = (i16)'6', + Num7 = (i16)'7', + Num8 = (i16)'8', + Num9 = (i16)'9', + Colon = (i16)':', + Semicolon = (i16)';', + LessThan = (i16)'<', + Equals = (i16)'=', + GreaterThan = (i16)'>', + QuestionMark = (i16)'?', + AtSign = (i16)'@', - UpperCase_A = (int16_t)'A', - UpperCase_B = (int16_t)'B', - UpperCase_C = (int16_t)'C', - UpperCase_D = (int16_t)'D', - UpperCase_E = (int16_t)'E', - UpperCase_F = (int16_t)'F', - UpperCase_G = (int16_t)'G', - UpperCase_H = (int16_t)'H', - UpperCase_I = (int16_t)'I', - UpperCase_J = (int16_t)'J', - UpperCase_K = (int16_t)'K', - UpperCase_L = (int16_t)'L', - UpperCase_M = (int16_t)'M', - UpperCase_N = (int16_t)'N', - UpperCase_O = (int16_t)'O', - UpperCase_P = (int16_t)'P', - UpperCase_Q = (int16_t)'Q', - UpperCase_R = (int16_t)'R', - UpperCase_S = (int16_t)'S', - UpperCase_T = (int16_t)'T', - UpperCase_U = (int16_t)'U', - UpperCase_V = (int16_t)'V', - UpperCase_W = (int16_t)'W', - UpperCase_X = (int16_t)'X', - UpperCase_Y = (int16_t)'Y', - UpperCase_Z = (int16_t)'Z', + UpperCase_A = (i16)'A', + UpperCase_B = (i16)'B', + UpperCase_C = (i16)'C', + UpperCase_D = (i16)'D', + UpperCase_E = (i16)'E', + UpperCase_F = (i16)'F', + UpperCase_G = (i16)'G', + UpperCase_H = (i16)'H', + UpperCase_I = (i16)'I', + UpperCase_J = (i16)'J', + UpperCase_K = (i16)'K', + UpperCase_L = (i16)'L', + UpperCase_M = (i16)'M', + UpperCase_N = (i16)'N', + UpperCase_O = (i16)'O', + UpperCase_P = (i16)'P', + UpperCase_Q = (i16)'Q', + UpperCase_R = (i16)'R', + UpperCase_S = (i16)'S', + UpperCase_T = (i16)'T', + UpperCase_U = (i16)'U', + UpperCase_V = (i16)'V', + UpperCase_W = (i16)'W', + UpperCase_X = (i16)'X', + UpperCase_Y = (i16)'Y', + UpperCase_Z = (i16)'Z', - LeftBracket = (int16_t)'[', - BackSlash = (int16_t)'\\', - RightBracket = (int16_t)']', - Caret = (int16_t)'^', - Underscore = (int16_t)'_', - BackQuote = (int16_t)'`', - LowerCase_a = (int16_t)'a', - LowerCase_b = (int16_t)'b', - LowerCase_c = (int16_t)'c', - LowerCase_d = (int16_t)'d', - LowerCase_e = (int16_t)'e', - LowerCase_f = (int16_t)'f', - LowerCase_g = (int16_t)'g', - LowerCase_h = (int16_t)'h', - LowerCase_i = (int16_t)'i', - LowerCase_j = (int16_t)'j', - LowerCase_k = (int16_t)'k', - LowerCase_l = (int16_t)'l', - LowerCase_m = (int16_t)'m', - LowerCase_n = (int16_t)'n', - LowerCase_o = (int16_t)'o', - LowerCase_p = (int16_t)'p', - LowerCase_q = (int16_t)'q', - LowerCase_r = (int16_t)'r', - LowerCase_s = (int16_t)'s', - LowerCase_t = (int16_t)'t', - LowerCase_u = (int16_t)'u', - LowerCase_v = (int16_t)'v', - LowerCase_w = (int16_t)'w', - LowerCase_x = (int16_t)'x', - LowerCase_y = (int16_t)'y', - LowerCase_z = (int16_t)'z', + LeftBracket = (i16)'[', + BackSlash = (i16)'\\', + RightBracket = (i16)']', + Caret = (i16)'^', + Underscore = (i16)'_', + BackQuote = (i16)'`', + LowerCase_a = (i16)'a', + LowerCase_b = (i16)'b', + LowerCase_c = (i16)'c', + LowerCase_d = (i16)'d', + LowerCase_e = (i16)'e', + LowerCase_f = (i16)'f', + LowerCase_g = (i16)'g', + LowerCase_h = (i16)'h', + LowerCase_i = (i16)'i', + LowerCase_j = (i16)'j', + LowerCase_k = (i16)'k', + LowerCase_l = (i16)'l', + LowerCase_m = (i16)'m', + LowerCase_n = (i16)'n', + LowerCase_o = (i16)'o', + LowerCase_p = (i16)'p', + LowerCase_q = (i16)'q', + LowerCase_r = (i16)'r', + LowerCase_s = (i16)'s', + LowerCase_t = (i16)'t', + LowerCase_u = (i16)'u', + LowerCase_v = (i16)'v', + LowerCase_w = (i16)'w', + LowerCase_x = (i16)'x', + LowerCase_y = (i16)'y', + LowerCase_z = (i16)'z', - LeftCTRL = (int16_t)0x0100, - RightCTRL = (int16_t)0x0101, - LeftALT = (int16_t)0x0102, - RightALT = (int16_t)0x0103, - LeftShift = (int16_t)0x0104, - RightShift = (int16_t)0x0105, + LeftCTRL = (i16)0x0100, + RightCTRL = (i16)0x0101, + LeftALT = (i16)0x0102, + RightALT = (i16)0x0103, + LeftShift = (i16)0x0104, + RightShift = (i16)0x0105, - KeyPadDivide = (int16_t)0x0106, - KeyPadMultiply = (int16_t)0x0107, - KeyPadMinus = (int16_t)0x0108, - KeyPadPlus = (int16_t)0x0109, - KeyPadEnter = (int16_t)0x010A, - KeyPad1 = (int16_t)0x010B, - KeyPad2 = (int16_t)0x010C, - KeyPad3 = (int16_t)0x010D, - KeyPad4 = (int16_t)0x010E, - KeyPad5 = (int16_t)0x010F, - KeyPad6 = (int16_t)0x0110, - KeyPad7 = (int16_t)0x0111, - KeyPad8 = (int16_t)0x0112, - KeyPad9 = (int16_t)0x0113, - KeyPad0 = (int16_t)0x0114, - KeyPadPeriod = (int16_t)0x0115, + KeyPadDivide = (i16)0x0106, + KeyPadMultiply = (i16)0x0107, + KeyPadMinus = (i16)0x0108, + KeyPadPlus = (i16)0x0109, + KeyPadEnter = (i16)0x010A, + KeyPad1 = (i16)0x010B, + KeyPad2 = (i16)0x010C, + KeyPad3 = (i16)0x010D, + KeyPad4 = (i16)0x010E, + KeyPad5 = (i16)0x010F, + KeyPad6 = (i16)0x0110, + KeyPad7 = (i16)0x0111, + KeyPad8 = (i16)0x0112, + KeyPad9 = (i16)0x0113, + KeyPad0 = (i16)0x0114, + KeyPadPeriod = (i16)0x0115, - PrintScreen = (int16_t)0x0116, - Insert = (int16_t)0x0117, - Home = (int16_t)0x0118, - PageUp = (int16_t)0x0119, - End = (int16_t)0x011A, - PageDown = (int16_t)0x011B, - RightArrow = (int16_t)0x011C, - LeftArrow = (int16_t)0x011D, - DownArrow = (int16_t)0x011E, - UpArrow = (int16_t)0x011F, - CapsLock = (int16_t)0x0120, - NumLock = (int16_t)0x0121, - ScrollLock = (int16_t)0x0122, + PrintScreen = (i16)0x0116, + Insert = (i16)0x0117, + Home = (i16)0x0118, + PageUp = (i16)0x0119, + End = (i16)0x011A, + PageDown = (i16)0x011B, + RightArrow = (i16)0x011C, + LeftArrow = (i16)0x011D, + DownArrow = (i16)0x011E, + UpArrow = (i16)0x011F, + CapsLock = (i16)0x0120, + NumLock = (i16)0x0121, + ScrollLock = (i16)0x0122, - F1 = (int16_t)0x0123, - F2 = (int16_t)0x0124, - F3 = (int16_t)0x0125, - F4 = (int16_t)0x0126, - F5 = (int16_t)0x0127, - F6 = (int16_t)0x0128, - F7 = (int16_t)0x0129, - F8 = (int16_t)0x012A, - F9 = (int16_t)0x012B, - F10 = (int16_t)0x012C, - F11 = (int16_t)0x012D, - F12 = (int16_t)0x012E, + F1 = (i16)0x0123, + F2 = (i16)0x0124, + F3 = (i16)0x0125, + F4 = (i16)0x0126, + F5 = (i16)0x0127, + F6 = (i16)0x0128, + F7 = (i16)0x0129, + F8 = (i16)0x012A, + F9 = (i16)0x012B, + F10 = (i16)0x012C, + F11 = (i16)0x012D, + F12 = (i16)0x012E, - LeftSuper = (int16_t)0x012F, - RightSuper = (int16_t)0x0130, + LeftSuper = (i16)0x012F, + RightSuper = (i16)0x0130, }; public: struct tModifierBits { - inline static constexpr uint8_t LeftShift = 0; - inline static constexpr uint8_t LeftControl = 1; - inline static constexpr uint8_t LeftAlt = 2; - inline static constexpr uint8_t LeftSuper = 3; - inline static constexpr uint8_t RightShift = 4; - inline static constexpr uint8_t RightControl = 5; - inline static constexpr uint8_t RightAlt = 6; - inline static constexpr uint8_t RightSuper = 7; - inline static constexpr uint8_t CapsLock = 8; - inline static constexpr uint8_t NumLock = 9; - inline static constexpr uint8_t ScrolLLock = 10; + inline static constexpr u8 LeftShift = 0; + inline static constexpr u8 LeftControl = 1; + inline static constexpr u8 LeftAlt = 2; + inline static constexpr u8 LeftSuper = 3; + inline static constexpr u8 RightShift = 4; + inline static constexpr u8 RightControl = 5; + inline static constexpr u8 RightAlt = 6; + inline static constexpr u8 RightSuper = 7; + inline static constexpr u8 CapsLock = 8; + inline static constexpr u8 NumLock = 9; + inline static constexpr u8 ScrolLLock = 10; }; public: struct tRegisters { - inline static constexpr uint16_t Modifiers = 0x00; - inline static constexpr uint16_t KeyCode = 0x02; + inline static constexpr u16 Modifiers = 0x00; + inline static constexpr u16 KeyCode = 0x02; }; public: inline VirtualKeyboard(void) { } void init(void); - int8_t read8(uint16_t addr) override; - int16_t read16(uint16_t addr) override; - int8_t write8(uint16_t addr, int8_t value) override; - int16_t write16(uint16_t addr, int16_t value) override; + i8 read8(u16 addr) override; + i16 read16(u16 addr) override; + i8 write8(u16 addr, i8 value) override; + i16 write16(u16 addr, i16 value) override; ostd::ByteStream* getByteStream(void) override; @@ -237,9 +237,9 @@ namespace dragon private: ostd::BitField_16 __construct_modifiers_bitfield(void); - int8_t __write8(uint16_t addr, int8_t value); - int16_t __write16(uint16_t addr, int16_t value); - int16_t __sdl_key_code_convert(int32_t keyCode); + i8 __write8(u16 addr, i8 value); + i16 __write16(u16 addr, i16 value); + i16 __sdl_key_code_convert(i32 keyCode); private: ostd::ByteStream m_data; @@ -249,10 +249,10 @@ namespace dragon { public: VirtualMouse(void); - int8_t read8(uint16_t addr) override; - int16_t read16(uint16_t addr) override; - int8_t write8(uint16_t addr, int8_t value) override; - int16_t write16(uint16_t addr, int16_t value) override; + i8 read8(u16 addr) override; + i16 read16(u16 addr) override; + i8 write8(u16 addr, i8 value) override; + i16 write16(u16 addr, i16 value) override; ostd::ByteStream* getByteStream(void) override; @@ -262,10 +262,10 @@ namespace dragon { public: VirtualBootloader(void); - int8_t read8(uint16_t addr) override; - int16_t read16(uint16_t addr) override; - int8_t write8(uint16_t addr, int8_t value) override; - int16_t write16(uint16_t addr, int16_t value) override; + i8 read8(u16 addr) override; + i16 read16(u16 addr) override; + i8 write8(u16 addr, i8 value) override; + i16 write16(u16 addr, i16 value) override; ostd::ByteStream* getByteStream(void) override; @@ -279,52 +279,52 @@ namespace dragon { public: struct tRegisters { - inline static constexpr uint16_t Signal = 0x00; - inline static constexpr uint16_t ModeSelector = 0x01; - inline static constexpr uint16_t DiskSelector = 0x02; - inline static constexpr uint16_t SectorSelector = 0x03; - inline static constexpr uint16_t AddressSelector = 0x05; - inline static constexpr uint16_t DataSize = 0x07; - inline static constexpr uint16_t DataSourceAddress = 0x09; + inline static constexpr u16 Signal = 0x00; + inline static constexpr u16 ModeSelector = 0x01; + inline static constexpr u16 DiskSelector = 0x02; + inline static constexpr u16 SectorSelector = 0x03; + inline static constexpr u16 AddressSelector = 0x05; + inline static constexpr u16 DataSize = 0x07; + inline static constexpr u16 DataSourceAddress = 0x09; - inline static constexpr uint16_t FirstReadOnly = 0x0B; + inline static constexpr u16 FirstReadOnly = 0x0B; - inline static constexpr uint16_t Status = 0x0B; - inline static constexpr uint16_t CurrentDisk = 0x0C; - inline static constexpr uint16_t CurrentSector = 0x0D; - inline static constexpr uint16_t CurrentAddress = 0x0F; - inline static constexpr uint16_t RestDataSize = 0x11; - inline static constexpr uint16_t SourceData = 0x13; + inline static constexpr u16 Status = 0x0B; + inline static constexpr u16 CurrentDisk = 0x0C; + inline static constexpr u16 CurrentSector = 0x0D; + inline static constexpr u16 CurrentAddress = 0x0F; + inline static constexpr u16 RestDataSize = 0x11; + inline static constexpr u16 SourceData = 0x13; }; public: struct tSignalValues { - inline static constexpr uint8_t Start = 0x00; - inline static constexpr uint8_t Cancel = 0x01; + inline static constexpr u8 Start = 0x00; + inline static constexpr u8 Cancel = 0x01; - inline static constexpr uint8_t Ignore = 0xFF; + inline static constexpr u8 Ignore = 0xFF; }; public: struct tModeValues { - inline static constexpr uint8_t Read = 0x00; - inline static constexpr uint8_t Write = 0x01; + inline static constexpr u8 Read = 0x00; + inline static constexpr u8 Write = 0x01; }; public: struct tStatusValues { - inline static constexpr uint8_t Free = 0x00; - inline static constexpr uint8_t Writing = 0x01; - inline static constexpr uint8_t Reading = 0x02; + inline static constexpr u8 Free = 0x00; + inline static constexpr u8 Writing = 0x01; + inline static constexpr u8 Reading = 0x02; }; public: Disk(MemoryMapper& memory, VirtualCPU& cpu); - int8_t read8(uint16_t addr) override; - int16_t read16(uint16_t addr) override; - int8_t write8(uint16_t addr, int8_t value) override; - int16_t write16(uint16_t addr, int16_t value) override; + i8 read8(u16 addr) override; + i16 read16(u16 addr) override; + i8 write8(u16 addr, i8 value) override; + i16 write16(u16 addr, i16 value) override; ostd::ByteStream* getByteStream(void) override; @@ -348,49 +348,49 @@ namespace dragon { public: struct tText16_Cell { - uint8_t backgroundColor; - uint8_t foregroundColor; - uint8_t character; + u8 backgroundColor; + u8 foregroundColor; + u8 character; }; public: struct tText16_CellStructure { - inline static constexpr uint8_t character = 0x00; - inline static constexpr uint8_t foreground = 0x01; - inline static constexpr uint8_t background = 0x02; - inline static constexpr uint8_t reserved = 0x03; + inline static constexpr u8 character = 0x00; + inline static constexpr u8 foreground = 0x01; + inline static constexpr u8 background = 0x02; + inline static constexpr u8 reserved = 0x03; }; public: struct tFlags { - inline static constexpr uint8_t DoubleBufferingEnabled = 0; - inline static constexpr uint8_t ScreenRedrawDisabled = 1; + inline static constexpr u8 DoubleBufferingEnabled = 0; + inline static constexpr u8 ScreenRedrawDisabled = 1; }; public: Graphics(void); - int8_t read8(uint16_t addr) override; - int16_t read16(uint16_t addr) override; - int8_t write8(uint16_t addr, int8_t value) override; - int16_t write16(uint16_t addr, int16_t value) override; + i8 read8(u16 addr) override; + i16 read16(u16 addr) override; + i8 write8(u16 addr, i8 value) override; + i16 write16(u16 addr, i16 value) override; - bool readFlag(uint8_t flg); - void setFlag(uint8_t flg, bool val = true); + bool readFlag(u8 flg); + void setFlag(u8 flg, bool val = true); ostd::ByteStream* getByteStream(void) override; - inline uint16_t getVRAMStart(void) { return m_vramStart; } - bool readVRAM_16Colors(uint8_t x, uint8_t y, tText16_Cell& outTextCell); - bool writeVRAM_16Colors(uint8_t x, uint8_t y, uint8_t character = 0, uint8_t background = 0xFF, uint8_t foreground = 0xFF); - bool clearVRAM_16Colors(uint8_t character = 0, uint8_t background = 0x00, uint8_t foreground = 0xFF); + inline u16 getVRAMStart(void) { return m_vramStart; } + bool readVRAM_16Colors(u8 x, u8 y, tText16_Cell& outTextCell); + bool writeVRAM_16Colors(u8 x, u8 y, u8 character = 0, u8 background = 0xFF, u8 foreground = 0xFF); + bool clearVRAM_16Colors(u8 character = 0, u8 background = 0x00, u8 foreground = 0xFF); void swapBuffers_16Colors(void); void scroll_16Colors(void); private: ostd::serial::SerialIO m_videoMemory; - uint16_t m_vramStart { 0 }; - uint8_t m_16Color_cellSize { 4 }; - uint16_t m_16Color_frameSize { 0 }; - uint16_t m_16Color_secondFrameAddr { 0 }; - uint16_t m_16Color_currentFrameAddr { 0 }; + u16 m_vramStart { 0 }; + u8 m_16Color_cellSize { 4 }; + u16 m_16Color_frameSize { 0 }; + u16 m_16Color_secondFrameAddr { 0 }; + u16 m_16Color_currentFrameAddr { 0 }; bool m_16Color_doubleBufferingEnabled { false }; ostd::BitField_16 m_tempFlags; @@ -399,10 +399,10 @@ namespace dragon { public: SerialPort(void); - int8_t read8(uint16_t addr) override; - int16_t read16(uint16_t addr) override; - int8_t write8(uint16_t addr, int8_t value) override; - int16_t write16(uint16_t addr, int16_t value) override; + i8 read8(u16 addr) override; + i16 read16(u16 addr) override; + i8 write8(u16 addr, i8 value) override; + i16 write16(u16 addr, i16 value) override; ostd::ByteStream* getByteStream(void) override; @@ -414,19 +414,19 @@ namespace dragon inline CMOS(void) { m_initialized = false; } 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; - int16_t write16(uint16_t addr, int16_t value) override; + i8 read8(u16 addr) override; + i16 read16(u16 addr) override; + i8 write8(u16 addr, i8 value) override; + i16 write16(u16 addr, i16 value) override; ostd::ByteStream* getByteStream(void) override; private: ostd::ByteStream m_data; - uint16_t m_size { 0 }; + u16 m_size { 0 }; std::fstream m_dataFile; bool m_initialized { false }; - uint64_t m_fileSize { 0 }; + u64 m_fileSize { 0 }; }; } } diff --git a/src/hardware/VirtualMMU.hpp b/src/hardware/VirtualMMU.hpp index ac073e4..acd1b0f 100644 --- a/src/hardware/VirtualMMU.hpp +++ b/src/hardware/VirtualMMU.hpp @@ -16,8 +16,8 @@ namespace dragon ostd::serial::SerialIO m_data; public: - inline static constexpr uint16_t MMUSize = 6144; - inline static constexpr uint16_t PageSize = 512; + inline static constexpr u16 MMUSize = 6144; + inline static constexpr u16 PageSize = 512; }; } } diff --git a/src/hardware/VirtualRAM.cpp b/src/hardware/VirtualRAM.cpp index 986af3b..0feb442 100644 --- a/src/hardware/VirtualRAM.cpp +++ b/src/hardware/VirtualRAM.cpp @@ -13,32 +13,32 @@ namespace dragon m_memory.enableAutoResize(false); } - int8_t VirtualRAM::read8(uint16_t addr) + i8 VirtualRAM::read8(u16 addr) { - int8_t outVal = 0; - uint16_t offset = DragonRuntime::cpu.getCurrentOffset(); + i8 outVal = 0; + u16 offset = DragonRuntime::cpu.getCurrentOffset(); if (!m_memory.r_Byte(addr + offset, outVal)) return 0x00; //TODO: Error return outVal; } - int16_t VirtualRAM::read16(uint16_t addr) + i16 VirtualRAM::read16(u16 addr) { - int16_t outVal = 0; - uint16_t offset = DragonRuntime::cpu.getCurrentOffset(); + i16 outVal = 0; + u16 offset = DragonRuntime::cpu.getCurrentOffset(); if (!m_memory.r_Word(addr + offset, outVal)) return 0x00; //TODO: Error return outVal; } - int8_t VirtualRAM::write8(uint16_t addr, int8_t value) + i8 VirtualRAM::write8(u16 addr, i8 value) { - uint16_t offset = DragonRuntime::cpu.getCurrentOffset(); + u16 offset = DragonRuntime::cpu.getCurrentOffset(); if (!m_memory.w_Byte(addr + offset, value)) return 0; //TODO: Error return value; } - int16_t VirtualRAM::write16(uint16_t addr, int16_t value) + i16 VirtualRAM::write16(u16 addr, i16 value) { - uint16_t offset = DragonRuntime::cpu.getCurrentOffset(); + u16 offset = DragonRuntime::cpu.getCurrentOffset(); if (!m_memory.w_Word(addr + offset, value)) return 0; //TODO: Error return value; } diff --git a/src/hardware/VirtualRAM.hpp b/src/hardware/VirtualRAM.hpp index ab8f2c9..103c0fe 100644 --- a/src/hardware/VirtualRAM.hpp +++ b/src/hardware/VirtualRAM.hpp @@ -11,10 +11,10 @@ namespace dragon { public: VirtualRAM(void); - int8_t read8(uint16_t addr) override; - int16_t read16(uint16_t addr) override; - int8_t write8(uint16_t addr, int8_t value) override; - int16_t write16(uint16_t addr, int16_t value) override; + i8 read8(u16 addr) override; + i16 read16(u16 addr) override; + i8 write8(u16 addr, i8 value) override; + i16 write16(u16 addr, i16 value) override; ostd::ByteStream* getByteStream(void) override; diff --git a/src/runtime/ConfigLoader.cpp b/src/runtime/ConfigLoader.cpp index 3e91c6f..5b8539e 100644 --- a/src/runtime/ConfigLoader.cpp +++ b/src/runtime/ConfigLoader.cpp @@ -23,7 +23,7 @@ namespace dragon lineEdit = tokens.next(); tokens = lineEdit.tokenize(","); if (tokens.count() == 0) continue; //TODO: Warning - int32_t disk_nr = 0; + i32 disk_nr = 0; while (tokens.hasNext()) { lineEdit = tokens.next(); @@ -35,7 +35,7 @@ namespace dragon lineEdit = tokens.next(); tokens = lineEdit.tokenize(","); if (tokens.count() == 0) continue; //TODO: Warning - int32_t ext_nr = 0; + i32 ext_nr = 0; while (tokens.hasNext()) { if (ext_nr >= 16) break; //TODO: Warning diff --git a/src/runtime/ConfigLoader.hpp b/src/runtime/ConfigLoader.hpp index fff1bc2..0b7e9d9 100644 --- a/src/runtime/ConfigLoader.hpp +++ b/src/runtime/ConfigLoader.hpp @@ -8,17 +8,17 @@ namespace dragon { struct tMachineConfig { - std::map vdisk_paths; - std::map cpuext_list; - int32_t clock_rate_sec { 500 }; - uint8_t memory_extension_pages { 0 }; + std::map vdisk_paths; + std::map cpuext_list; + i32 clock_rate_sec { 500 }; + u8 memory_extension_pages { 0 }; bool fixed_clock { true }; String bios_path; String cmos_path; ostd::Color singleColor_background; ostd::Color singleColor_foreground; - uint8_t text16_palette { 0 }; - uint8_t screen_redraw_rate_per_second { 10 }; + u8 text16_palette { 0 }; + u8 screen_redraw_rate_per_second { 10 }; inline bool isValid(void) const { return m_valid; } inline void destroy(void) { for (auto& ptr : cpuext_list) delete ptr.second; } diff --git a/src/runtime/DragonRuntime.cpp b/src/runtime/DragonRuntime.cpp index ca87966..7a843da 100644 --- a/src/runtime/DragonRuntime.cpp +++ b/src/runtime/DragonRuntime.cpp @@ -84,7 +84,7 @@ namespace dragon return list; } - int32_t DragonRuntime::loadArguments(int argc, char** argv, tCommandLineArgs& args) + i32 DragonRuntime::loadArguments(int argc, char** argv, tCommandLineArgs& args) { if (argc < 2) { @@ -100,7 +100,7 @@ namespace dragon __print_application_help(); return DragonRuntime::RETURN_VAL_CLOSE_RUNTIME; } - for (int32_t i = 2; i < argc; i++) + for (i32 i = 2; i < argc; i++) { String edit(argv[i]); if (edit == "--verbose-load") @@ -115,7 +115,7 @@ namespace dragon edit = argv[i]; if (!edit.isNumeric()) return RETURN_VAL_PARAMETER_NOT_NUMERIC; - args.force_load_mem_offset = (uint16_t)edit.toInt(); + args.force_load_mem_offset = (u16)edit.toInt(); args.force_load = true; } else if (edit == "--help") @@ -128,7 +128,7 @@ namespace dragon return RETURN_VAL_EXIT_SUCCESS; } - int32_t DragonRuntime::initMachine(const tRuntimeInitInfo& info) + i32 DragonRuntime::initMachine(const tRuntimeInitInfo& info) { s_signalListener.init(); vKeyboard.init(); @@ -139,8 +139,8 @@ namespace dragon 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; + i32 w = ogfx::PixelRenderer::TextRenderer::CONSOLE_CHARS_H * ogfx::PixelRenderer::TextRenderer::FONT_CHAR_W; //60 * 16; + i32 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 (info.hideVirtualDisplay) @@ -279,7 +279,7 @@ namespace dragon if (info.verboseLoad) out.fg(ostd::ConsoleColors::Magenta).p(" Initializing vCPU reset sequence:").nl(); - uint16_t reset_ip_addr = 0x0000; + u16 reset_ip_addr = 0x0000; 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); @@ -309,19 +309,19 @@ namespace dragon out.fg(ostd::ConsoleColors::BrightYellow).p(" Fixed clock enabled: ").p(STR_BOOL(machine_config.fixed_clock)).nl(); if (machine_config.fixed_clock) out.fg(ostd::ConsoleColors::BrightYellow).p(" Clock speed: ").p(machine_config.clock_rate_sec).p(" Hz").nl(); - out.fg(ostd::ConsoleColors::BrightYellow).p(" Screen redraw rate: ").p((int32_t)machine_config.screen_redraw_rate_per_second).p(" Hz").nl(); + out.fg(ostd::ConsoleColors::BrightYellow).p(" Screen redraw rate: ").p((i32)machine_config.screen_redraw_rate_per_second).p(" Hz").nl(); } vCMOS.write16(data::CMOSRegisters::MemoryStart, data::MemoryMapAddresses::Memory_Start); vCMOS.write16(data::CMOSRegisters::MemorySize, data::MemoryMapAddresses::Memory_End); vCMOS.write16(data::CMOSRegisters::ClockSpeed, machine_config.clock_rate_sec); vCMOS.write8(data::CMOSRegisters::ScreenRedrawRate, machine_config.screen_redraw_rate_per_second); - vCMOS.write16(data::CMOSRegisters::ScreenWidth, static_cast(ogfx::PixelRenderer::TextRenderer::CONSOLE_CHARS_H)); - vCMOS.write16(data::CMOSRegisters::ScreenHeight, static_cast(ogfx::PixelRenderer::TextRenderer::CONSOLE_CHARS_V)); + vCMOS.write16(data::CMOSRegisters::ScreenWidth, static_cast(ogfx::PixelRenderer::TextRenderer::CONSOLE_CHARS_H)); + vCMOS.write16(data::CMOSRegisters::ScreenHeight, static_cast(ogfx::PixelRenderer::TextRenderer::CONSOLE_CHARS_V)); vCMOS.write16(data::CMOSRegisters::StackSize, 0x1000); ostd::BitField_16 disk_list_bitfield; disk_list_bitfield.value = 0; - for (int32_t i = 0; i < 16; i++) + for (i32 i = 0; i < 16; i++) { if (vDisks.count(i) > 0) ostd::Bits::set(disk_list_bitfield, i); @@ -346,12 +346,12 @@ namespace dragon void DragonRuntime::runMachine(void) { - double clock_speed_us = 1000000.0 / machine_config.clock_rate_sec; - double acc = 0; - double acc2 = 0; - uint64_t avg_count = 0; - uint64_t _time = 0; - double avg_tot = 0; + f64 clock_speed_us = 1000000.0 / machine_config.clock_rate_sec; + f64 acc = 0; + f64 acc2 = 0; + u64 avg_count = 0; + u64 _time = 0; + f64 avg_tot = 0; ostd::Counter clock_timer; bool running = true; bool fixed_clock = machine_config.fixed_clock; @@ -360,9 +360,9 @@ namespace dragon { clock_timer.startCount(ostd::eTimeUnits::Microseconds); ostd::SignalHandler::handleDelegateSignals(); - uint16_t addr = cpu.readRegister(dragon::data::Registers::IP); - uint16_t spAddr = cpu.readRegister(dragon::data::Registers::SP); - uint8_t screenRedrawRate = vCMOS.read8(data::CMOSRegisters::ScreenRedrawRate); + u16 addr = cpu.readRegister(dragon::data::Registers::IP); + u16 spAddr = cpu.readRegister(dragon::data::Registers::SP); + u8 screenRedrawRate = vCMOS.read8(data::CMOSRegisters::ScreenRedrawRate); // _timer.start(true, "Profiling", ostd::eTimeUnits::Microseconds, &out); running = cpu.execute() && vDisplay.isRunning(); // _timer.end(true); @@ -377,7 +377,7 @@ namespace dragon { avg_count++; avg_tot += _time; - s_avgInstTime = (uint64_t)std::round(avg_tot / avg_count); + s_avgInstTime = (u64)std::round(avg_tot / avg_count); // out.fg(ostd::ConsoleColors::Red).p(getAvgClockSpeed()).nl().reset(); acc = 0; } @@ -394,13 +394,13 @@ namespace dragon } } - bool DragonRuntime::runStep(std::vector trackedAddresses) + bool DragonRuntime::runStep(std::vector trackedAddresses) { std::sort(trackedAddresses.begin(), trackedAddresses.end()); __get_machine_footprint(&s_machineInfo, trackedAddresses, true); __track_call_stack(&s_machineInfo); bool running = cpu.execute() && vDisplay.isRunning(); - uint8_t screenRedrawRate = vCMOS.read8(data::CMOSRegisters::ScreenRedrawRate); + u8 screenRedrawRate = vCMOS.read8(data::CMOSRegisters::ScreenRedrawRate); vDisplay.mainLoop(); if (s_enableScreenRedrawDelay && s_stepAcc2 == (1000.0 / screenRedrawRate)) { @@ -418,12 +418,12 @@ namespace dragon return running || vDiskInterface.isBusy(); } - void DragonRuntime::forceLoad(const String& filePath, uint16_t loadAddress) + void DragonRuntime::forceLoad(const String& filePath, u16 loadAddress) { ostd::ByteStream code; ostd::Memory::loadByteStreamFromFile(filePath, code); - int16_t index = 0; + i16 index = 0; for (auto& b : code) { ram.write8(dragon::data::MemoryMapAddresses::Memory_Start + loadAddress + index, b); @@ -432,7 +432,7 @@ namespace dragon } - void DragonRuntime::__get_machine_footprint(DragonRuntime::tMachineDebugInfo* machineInfo, std::vector trackedAddresses, bool previous) + void DragonRuntime::__get_machine_footprint(DragonRuntime::tMachineDebugInfo* machineInfo, std::vector trackedAddresses, bool previous) { if (!s_trackMachineInfo || machineInfo == nullptr) return; auto& minfo = *machineInfo; @@ -444,7 +444,7 @@ namespace dragon minfo.previousInstructionTrackedValues.clear(); minfo.currentInstructionTrackedValues.clear(); - for (int32_t i = 0; i < 20; i++) + for (i32 i = 0; i < 20; i++) { if (i < 5) { @@ -459,15 +459,15 @@ namespace dragon minfo.trackedAddresses.push_back(addr); } - 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); + u16 instAddr = cpu.readRegister(data::Registers::IP); + u8 int_op_code = memMap.read8(instAddr); + u8 instSize = data::OpCodes::getInstructionSIze(int_op_code); String opCode = data::OpCodes::getOpCodeString(int_op_code); - uint16_t stackFrameSize = cpu.m_stackFrameSize; - int32_t subRoutineCounter = cpu.m_subroutineCounter; + u16 stackFrameSize = cpu.m_stackFrameSize; + i32 subRoutineCounter = cpu.m_subroutineCounter; bool debugBreak = cpu.m_isDebugBreakPoint; - int32_t intHandlerCount = cpu.m_interruptHandlerCount; + i32 intHandlerCount = cpu.m_interruptHandlerCount; bool biosMode = cpu.m_biosMode; bool isInSubRoutine = cpu.isInSubRoutine(); @@ -479,10 +479,10 @@ namespace dragon minfo.previousInstructionOpCode = opCode; minfo.previousSubRoutineCounter = subRoutineCounter; - for (int8_t i = 0; i < instSize; i++) + for (i8 i = 0; i < instSize; i++) minfo.previousInstructionFootprint[i] = memMap.read8(instAddr + i); - for (int8_t i = 0; i < 20; i++) + for (i8 i = 0; i < 20; i++) minfo.previousInstructionRegisters[i] = cpu.readRegister(i); for (auto& addr : minfo.trackedAddresses) @@ -504,10 +504,10 @@ namespace dragon minfo.currentInstructionOpCode = opCode; minfo.currentSubRoutineCounter = subRoutineCounter; - for (int8_t i = 0; i < instSize; i++) + for (i8 i = 0; i < instSize; i++) minfo.currentInstructionFootprint[i] = memMap.read8(minfo.currentInstructionAddress + i); - for (int8_t i = 0; i < 20; i++) + for (i8 i = 0; i < 20; i++) minfo.currentInstructionRegisters[i] = cpu.readRegister(i); for (auto& addr : minfo.trackedAddresses) @@ -527,23 +527,23 @@ namespace dragon bool interrupts_enabled = cpu.readFlag(data::Flags::InterruptsEnabled); - uint16_t instAddr = cpu.readRegister(data::Registers::IP); - uint8_t inst = memMap.read8(instAddr); + u16 instAddr = cpu.readRegister(data::Registers::IP); + u8 inst = memMap.read8(instAddr); if (inst == data::OpCodes::CallImm) { - uint16_t call_addr = memMap.read16(instAddr + 1); + u16 call_addr = memMap.read16(instAddr + 1); minfo.callStack.push_back({ "CALL IMM", call_addr, instAddr, !interrupts_enabled }); } else if (inst == data::OpCodes::CallReg) { - uint8_t reg_addr = memMap.read8(instAddr + 1); - uint16_t call_addr = cpu.readRegister(reg_addr); + u8 reg_addr = memMap.read8(instAddr + 1); + u16 call_addr = cpu.readRegister(reg_addr); minfo.callStack.push_back({ "CALL REG", call_addr, instAddr, !interrupts_enabled }); } else if (interrupts_enabled && inst == data::OpCodes::Int) { - uint8_t int_num = memMap.read8(instAddr + 1); + u8 int_num = memMap.read8(instAddr + 1); minfo.callStack.push_back({ "INT", int_num, instAddr, !interrupts_enabled }); } else if (inst == data::OpCodes::Ret) @@ -558,7 +558,7 @@ namespace dragon void DragonRuntime::__print_application_help(void) { - int32_t commandLength = 46; + i32 commandLength = 46; out.nl().fg(ostd::ConsoleColors::Yellow).p("List of available parameters:").reset().nl(); String tmpCommand = "--verbose-load"; diff --git a/src/runtime/DragonRuntime.hpp b/src/runtime/DragonRuntime.hpp index 5a83d04..142274b 100644 --- a/src/runtime/DragonRuntime.hpp +++ b/src/runtime/DragonRuntime.hpp @@ -23,15 +23,15 @@ namespace dragon void handleSignal(ostd::Signal& signal) override; public: - inline static const int32_t Signal_HardwareInterruptOccurred = ostd::SignalHandler::newCustomSignal(8129); + inline static const i32 Signal_HardwareInterruptOccurred = ostd::SignalHandler::newCustomSignal(8129); }; public: struct tCallInfo : public ostd::BaseObject { inline tCallInfo(void) { } - 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) { } + inline tCallInfo(const String& _info, u16 _addr, u16 _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; + u16 addr; + u16 inst_addr; bool interrupts_disabled; }; public: struct tCommandLineArgs @@ -40,7 +40,7 @@ namespace dragon bool verbose_load = false; bool force_load = false; String force_load_file = ""; - uint16_t force_load_mem_offset = 0x00; + u16 force_load_mem_offset = 0x00; }; public: struct tRuntimeInitInfo { @@ -55,28 +55,28 @@ namespace dragon { inline tMachineDebugInfo(void) { } - uint16_t previousInstructionAddress { 0x0000 }; - uint16_t currentInstructionAddress { 0x0000 }; - int8_t previousInstructionFootprintSize { 0x00 }; - int8_t currentInstructionFootprintSize { 0x00 }; - uint16_t previousInstructionStackFrameSize { 0x00 }; - uint16_t currentInstructionStackFrameSize { 0x00 }; - int32_t previousSubRoutineCounter { 0x00000000 }; - int32_t currentSubRoutineCounter { 0x00000000 }; + u16 previousInstructionAddress { 0x0000 }; + u16 currentInstructionAddress { 0x0000 }; + i8 previousInstructionFootprintSize { 0x00 }; + i8 currentInstructionFootprintSize { 0x00 }; + u16 previousInstructionStackFrameSize { 0x00 }; + u16 currentInstructionStackFrameSize { 0x00 }; + i32 previousSubRoutineCounter { 0x00000000 }; + i32 currentSubRoutineCounter { 0x00000000 }; String previousInstructionOpCode { "" }; String currentInstructionOpCode { "" }; - int8_t previousInstructionFootprint[5] { 0x00, 0x00, 0x00, 0x00, 0x00 }; - int8_t currentInstructionFootprint[5] { 0x00, 0x00, 0x00, 0x00, 0x00 }; - int16_t previousInstructionRegisters[20] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - int16_t currentInstructionRegisters[20] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - int32_t previousInstructionInterruptHandlerCount { 0 }; - int32_t currentInstructionInterruptHandlerCount { 0 }; + i8 previousInstructionFootprint[5] { 0x00, 0x00, 0x00, 0x00, 0x00 }; + i8 currentInstructionFootprint[5] { 0x00, 0x00, 0x00, 0x00, 0x00 }; + i16 previousInstructionRegisters[20] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + i16 currentInstructionRegisters[20] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + i32 previousInstructionInterruptHandlerCount { 0 }; + i32 currentInstructionInterruptHandlerCount { 0 }; - std::vector trackedAddresses; - std::vector previousInstructionTrackedValues; - std::vector currentInstructionTrackedValues; + std::vector trackedAddresses; + std::vector previousInstructionTrackedValues; + std::vector currentInstructionTrackedValues; bool previousInstructionDebugBreak { false }; bool currentInstructionDebugBreak { false }; @@ -94,20 +94,20 @@ namespace dragon static void printRegisters(hw::VirtualCPU& cpu); static void processErrors(void); static std::vector getErrorList(void); - static int32_t loadArguments(int argc, char** argv, tCommandLineArgs& args); - static int32_t initMachine(const tRuntimeInitInfo& info); + static i32 loadArguments(int argc, char** argv, tCommandLineArgs& args); + static i32 initMachine(const tRuntimeInitInfo& info); static void shutdownMachine(void); static void runMachine(void); - static bool runStep(std::vector trackedAddresses = { }); - static void forceLoad(const String& filePath, uint16_t loadAddress); + static bool runStep(std::vector trackedAddresses = { }); + static void forceLoad(const String& filePath, u16 loadAddress); inline static const tMachineDebugInfo& getMachineInfoDiff(void) { return s_machineInfo; } inline static bool hasError(void) { return data::ErrorHandler::hasError(); } inline static ostd::ConsoleOutputHandler& output(void) { return out; } - inline static uint64_t getAvgClockSpeed(void) { return (uint64_t)std::round(1000000.0 / s_avgInstTime); } + inline static u64 getAvgClockSpeed(void) { return (u64)std::round(1000000.0 / s_avgInstTime); } private: - static void __get_machine_footprint(tMachineDebugInfo* machineInfo, std::vector trackedAddresses, bool previous); + static void __get_machine_footprint(tMachineDebugInfo* machineInfo, std::vector trackedAddresses, bool previous); static void __track_call_stack(tMachineDebugInfo* machineInfo); static void __print_application_help(void); @@ -127,14 +127,14 @@ namespace dragon inline static hw::interface::Graphics vGraphicsInterface; inline static hw::interface::SerialPort vSerialInterface; - inline static std::unordered_map vDisks; + inline static std::unordered_map vDisks; inline static hw::VirtualDisplay vDisplay; inline static tMachineConfig machine_config; - inline static uint64_t s_avgInstTime { 0 }; - inline static double s_stepAcc2 { 0 }; + inline static u64 s_avgInstTime { 0 }; + inline static f64 s_stepAcc2 { 0 }; inline static bool s_enableScreenRedrawDelay { true }; private: @@ -145,14 +145,14 @@ namespace dragon public: - inline static const int32_t RETURN_VAL_CLOSE_DEBUGGER = 128; - inline static const int32_t RETURN_VAL_CLOSE_RUNTIME = 256; - inline static const int32_t RETURN_VAL_INVALID_MACHINE_CONFIG = 1; - inline static const int32_t RETURN_VAL_NO_DISK = 2; - inline static const int32_t RETURN_VAL_TOO_FEW_ARGUMENTS = 3; - inline static const int32_t RETURN_VAL_MISSING_PARAM = 4; - inline static const int32_t RETURN_VAL_PARAMETER_NOT_NUMERIC = 5; - inline static const int32_t RETURN_VAL_EXIT_SUCCESS = 0; + inline static const i32 RETURN_VAL_CLOSE_DEBUGGER = 128; + inline static const i32 RETURN_VAL_CLOSE_RUNTIME = 256; + inline static const i32 RETURN_VAL_INVALID_MACHINE_CONFIG = 1; + inline static const i32 RETURN_VAL_NO_DISK = 2; + inline static const i32 RETURN_VAL_TOO_FEW_ARGUMENTS = 3; + inline static const i32 RETURN_VAL_MISSING_PARAM = 4; + inline static const i32 RETURN_VAL_PARAMETER_NOT_NUMERIC = 5; + inline static const i32 RETURN_VAL_EXIT_SUCCESS = 0; friend class SignalListener; }; diff --git a/src/runtime/runtime_main.cpp b/src/runtime/runtime_main.cpp index 6d40bed..6b12bc5 100644 --- a/src/runtime/runtime_main.cpp +++ b/src/runtime/runtime_main.cpp @@ -5,7 +5,7 @@ int main(int argc, char** argv) { //Loading commandline arguments dragon::DragonRuntime::tCommandLineArgs args; - int32_t rValue = dragon::DragonRuntime::loadArguments(argc, argv, args); + i32 rValue = dragon::DragonRuntime::loadArguments(argc, argv, args); 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 d7dd032..5dab634 100644 --- a/src/tools/GlobalData.cpp +++ b/src/tools/GlobalData.cpp @@ -5,7 +5,7 @@ namespace dragon { namespace data { - String OpCodes::getOpCodeString(uint8_t opCode) + String OpCodes::getOpCodeString(u8 opCode) { CPUExtension* ext = DragonRuntime::cpu.getCurrentCPUExtension(); if (ext != nullptr) @@ -105,7 +105,7 @@ namespace dragon } } - uint8_t OpCodes::getInstructionSIze(uint8_t opCode) + u8 OpCodes::getInstructionSIze(u8 opCode) { CPUExtension* ext = DragonRuntime::cpu.getCurrentCPUExtension(); if (ext != nullptr) diff --git a/src/tools/GlobalData.hpp b/src/tools/GlobalData.hpp index 8b54dbb..00d2e41 100644 --- a/src/tools/GlobalData.hpp +++ b/src/tools/GlobalData.hpp @@ -9,54 +9,54 @@ namespace dragon namespace hw { class VirtualCPU; } namespace data { - typedef uint32_t VDiskID; + typedef u32 VDiskID; class ErrorCodes { public: - inline static constexpr uint64_t NoError = 0x0000000000000000; - inline static constexpr uint64_t AccessViolation_BiosModeRequired = 0x0000000000000001; + inline static constexpr u64 NoError = 0x0000000000000000; + inline static constexpr u64 AccessViolation_BiosModeRequired = 0x0000000000000001; - inline static constexpr uint64_t MM_RegionNotFound = 0x1000000000000000; - inline static constexpr uint64_t MM_AtomicNotSupported = 0x1000000000000001; + inline static constexpr u64 MM_RegionNotFound = 0x1000000000000000; + inline static constexpr u64 MM_AtomicNotSupported = 0x1000000000000001; - inline static constexpr uint64_t CPU_UnknownInstruction = 0x2000000000000000; - inline static constexpr uint64_t CPU_UnsupportedExtension = 0x2000000000000001; - inline static constexpr uint64_t CPU_StackOverflow = 0x2000000000000002; + inline static constexpr u64 CPU_UnknownInstruction = 0x2000000000000000; + inline static constexpr u64 CPU_UnsupportedExtension = 0x2000000000000001; + inline static constexpr u64 CPU_StackOverflow = 0x2000000000000002; - inline static constexpr uint64_t BIOS_FailedToLoad = 0x3000000000000000; - inline static constexpr uint64_t BIOS_InvalidSize = 0x3000000000000001; - inline static constexpr uint64_t BIOS_WriteAttempt = 0x3000000000000002; - inline static constexpr uint64_t BIOS_InvalidAddress = 0x3000000000000003; + inline static constexpr u64 BIOS_FailedToLoad = 0x3000000000000000; + inline static constexpr u64 BIOS_InvalidSize = 0x3000000000000001; + inline static constexpr u64 BIOS_WriteAttempt = 0x3000000000000002; + inline static constexpr u64 BIOS_InvalidAddress = 0x3000000000000003; - inline static constexpr uint64_t HardDrive_UnableToMount = 0x4000000000000000; - inline static constexpr uint64_t HardDrive_Uninitialized = 0x4000000000000001; - inline static constexpr uint64_t HardDrive_ReadOverflow = 0x4000000000000002; - inline static constexpr uint64_t HardDrive_WriteOverflow = 0x4000000000000003; - inline static constexpr uint64_t HardDrive_BuffWriteOverflow = 0x4000000000000004; - inline static constexpr uint64_t HardDrive_EmptyBuffer = 0x4000000000000005; - inline static constexpr uint64_t HardDrive_InvalidConfiguration = 0x4000000000000006; - inline static constexpr uint64_t HardDrive_ReadFailed = 0x4000000000000007; - inline static constexpr uint64_t HardDrive_WriteFailed = 0x4000000000000008; - inline static constexpr uint64_t HardDrive_MemoryOverflow = 0x4000000000000009; - inline static constexpr uint64_t HardDrive_InvalidDiskSelected = 0x400000000000000A; - inline static constexpr uint64_t HardDrive_EndOfDisk = 0x400000000000000B; - inline static constexpr uint64_t HardDrive_ControllerReadFailed = 0x400000000000000C; - inline static constexpr uint64_t HardDrive_ControllerWriteFailed = 0x400000000000000D; - inline static constexpr uint64_t HardDrive_DisconnectInvalid = 0x400000000000000E; - inline static constexpr uint64_t HardDrive_DiskAlreadyConnected = 0x400000000000000F; + inline static constexpr u64 HardDrive_UnableToMount = 0x4000000000000000; + inline static constexpr u64 HardDrive_Uninitialized = 0x4000000000000001; + inline static constexpr u64 HardDrive_ReadOverflow = 0x4000000000000002; + inline static constexpr u64 HardDrive_WriteOverflow = 0x4000000000000003; + inline static constexpr u64 HardDrive_BuffWriteOverflow = 0x4000000000000004; + inline static constexpr u64 HardDrive_EmptyBuffer = 0x4000000000000005; + inline static constexpr u64 HardDrive_InvalidConfiguration = 0x4000000000000006; + inline static constexpr u64 HardDrive_ReadFailed = 0x4000000000000007; + inline static constexpr u64 HardDrive_WriteFailed = 0x4000000000000008; + inline static constexpr u64 HardDrive_MemoryOverflow = 0x4000000000000009; + inline static constexpr u64 HardDrive_InvalidDiskSelected = 0x400000000000000A; + inline static constexpr u64 HardDrive_EndOfDisk = 0x400000000000000B; + inline static constexpr u64 HardDrive_ControllerReadFailed = 0x400000000000000C; + inline static constexpr u64 HardDrive_ControllerWriteFailed = 0x400000000000000D; + inline static constexpr u64 HardDrive_DisconnectInvalid = 0x400000000000000E; + inline static constexpr u64 HardDrive_DiskAlreadyConnected = 0x400000000000000F; - inline static constexpr uint64_t CMOS_InvalidAddress = 0x5000000000000000; - inline static constexpr uint64_t CMOS_UnableToMount = 0x5000000000000001; - inline static constexpr uint64_t CMOS_InvalidSize = 0x5000000000000002; - inline static constexpr uint64_t CMOS_Uninitialized = 0x5000000000000003; + inline static constexpr u64 CMOS_InvalidAddress = 0x5000000000000000; + inline static constexpr u64 CMOS_UnableToMount = 0x5000000000000001; + inline static constexpr u64 CMOS_InvalidSize = 0x5000000000000002; + inline static constexpr u64 CMOS_Uninitialized = 0x5000000000000003; - inline static constexpr uint64_t BIOSVideo_InvalidAddress = 0x6000000000000000; + inline static constexpr u64 BIOSVideo_InvalidAddress = 0x6000000000000000; - inline static constexpr uint64_t IntVector_InvalidAddress = 0x7000000000000000; + inline static constexpr u64 IntVector_InvalidAddress = 0x7000000000000000; - inline static constexpr uint64_t Graphics_MemoryReadFailed = 0x8000000000000000; - inline static constexpr uint64_t Graphics_MemoryWriteFailed = 0x8000000000000001; + inline static constexpr u64 Graphics_MemoryReadFailed = 0x8000000000000000; + inline static constexpr u64 Graphics_MemoryWriteFailed = 0x8000000000000001; }; @@ -64,12 +64,12 @@ namespace dragon { public: struct tError { - uint64_t code; + u64 code; String text; }; public: - inline static void pushError(uint64_t code, String text) { m_errorStack.push_back({ code, text }); } + inline static void pushError(u64 code, String text) { m_errorStack.push_back({ code, text }); } inline static bool hasError(void) { return m_errorStack.size() > 0; } inline static tError popError(void) { @@ -87,41 +87,41 @@ namespace dragon class MemoryMapAddresses { public: - inline static constexpr uint16_t BIOS_Start = 0x0000; - inline static constexpr uint16_t BIOS_End = 0x0FFF; + inline static constexpr u16 BIOS_Start = 0x0000; + inline static constexpr u16 BIOS_End = 0x0FFF; - inline static constexpr uint16_t CMOS_Start = 0x1000; - inline static constexpr uint16_t CMOS_End = 0x107F; + inline static constexpr u16 CMOS_Start = 0x1000; + inline static constexpr u16 CMOS_End = 0x107F; - inline static constexpr uint16_t IntVector_Start = 0x1080; - inline static constexpr uint16_t IntVector_End = 0x127F; + inline static constexpr u16 IntVector_Start = 0x1080; + inline static constexpr u16 IntVector_End = 0x127F; - inline static constexpr uint16_t Keyboard_Start = 0x1280; - inline static constexpr uint16_t Keyboard_End = 0x135F; + inline static constexpr u16 Keyboard_Start = 0x1280; + inline static constexpr u16 Keyboard_End = 0x135F; - inline static constexpr uint16_t Mouse_Start = 0x1360; - inline static constexpr uint16_t Mouse_End = 0x137F; + inline static constexpr u16 Mouse_Start = 0x1360; + inline static constexpr u16 Mouse_End = 0x137F; - inline static constexpr uint16_t MBR_Start = 0x1380; - inline static constexpr uint16_t MBR_End = 0x157F; + inline static constexpr u16 MBR_Start = 0x1380; + inline static constexpr u16 MBR_End = 0x157F; - inline static constexpr uint16_t DiskInterface_Start = 0x1580; - inline static constexpr uint16_t DiskInterface_End = 0x15FF; + inline static constexpr u16 DiskInterface_Start = 0x1580; + inline static constexpr u16 DiskInterface_End = 0x15FF; - inline static constexpr uint16_t VideoCardInterface_Start = 0x1600; - inline static constexpr uint16_t VideoCardInterface_End = 0x16FF; + inline static constexpr u16 VideoCardInterface_Start = 0x1600; + inline static constexpr u16 VideoCardInterface_End = 0x16FF; - inline static constexpr uint16_t SerialInterface_Start = 0x1700; - inline static constexpr uint16_t SerialInterface_End = 0x173F; + inline static constexpr u16 SerialInterface_Start = 0x1700; + inline static constexpr u16 SerialInterface_End = 0x173F; - inline static constexpr uint16_t Memory_Start = 0x1740; - inline static constexpr uint16_t Memory_End = 0xFFFF; + inline static constexpr u16 Memory_Start = 0x1740; + inline static constexpr u16 Memory_End = 0xFFFF; }; class IBiosVideoPalette { public: - virtual ostd::Color getColor(uint8_t col) = 0; + virtual ostd::Color getColor(u8 col) = 0; }; class BiosVideoDefaultPalette : public IBiosVideoPalette @@ -147,7 +147,7 @@ namespace dragon m_colors.push_back({ 178, 220, 239 }); // Sky } - inline ostd::Color getColor(uint8_t col) override + inline ostd::Color getColor(u8 col) override { if (col >= m_colors.size()) return { 0, 0, 0 }; return m_colors[col]; @@ -160,48 +160,48 @@ namespace dragon class Registers { public: - inline static constexpr uint8_t IP = 0x00; - inline static constexpr uint8_t SP = 0x01; - inline static constexpr uint8_t FP = 0x02; - inline static constexpr uint8_t RV = 0x03; - inline static constexpr uint8_t PP = 0x04; - inline static constexpr uint8_t FL = 0x05; - inline static constexpr uint8_t ACC = 0x06; - inline static constexpr uint8_t S1 = 0x07; - inline static constexpr uint8_t S2 = 0x08; - inline static constexpr uint8_t OFFSET = 0x09; - inline static constexpr uint8_t R1 = 0x0A; - inline static constexpr uint8_t R2 = 0x0B; - inline static constexpr uint8_t R3 = 0x0C; - inline static constexpr uint8_t R4 = 0x0D; - inline static constexpr uint8_t R5 = 0x0E; - inline static constexpr uint8_t R6 = 0x0F; - inline static constexpr uint8_t R7 = 0x10; - inline static constexpr uint8_t R8 = 0x11; - inline static constexpr uint8_t R9 = 0x12; - inline static constexpr uint8_t R10 = 0x13; + inline static constexpr u8 IP = 0x00; + inline static constexpr u8 SP = 0x01; + inline static constexpr u8 FP = 0x02; + inline static constexpr u8 RV = 0x03; + inline static constexpr u8 PP = 0x04; + inline static constexpr u8 FL = 0x05; + inline static constexpr u8 ACC = 0x06; + inline static constexpr u8 S1 = 0x07; + inline static constexpr u8 S2 = 0x08; + inline static constexpr u8 OFFSET = 0x09; + inline static constexpr u8 R1 = 0x0A; + inline static constexpr u8 R2 = 0x0B; + inline static constexpr u8 R3 = 0x0C; + inline static constexpr u8 R4 = 0x0D; + inline static constexpr u8 R5 = 0x0E; + inline static constexpr u8 R6 = 0x0F; + inline static constexpr u8 R7 = 0x10; + inline static constexpr u8 R8 = 0x11; + inline static constexpr u8 R9 = 0x12; + inline static constexpr u8 R10 = 0x13; - inline static constexpr uint8_t Last = 0x14; + inline static constexpr u8 Last = 0x14; }; class Flags { public: - inline static constexpr uint8_t InterruptsEnabled = 0; - inline static constexpr uint8_t OffsetModeEnabled = 1; + inline static constexpr u8 InterruptsEnabled = 0; + inline static constexpr u8 OffsetModeEnabled = 1; }; class InterruptCodes { public: - inline static constexpr uint8_t DiskInterfaceFFinished = 0x80; - inline static constexpr uint8_t KeyPressed = 0xA0; - inline static constexpr uint8_t KeyReleased = 0xA1; - inline static constexpr uint8_t TextEntered = 0xA2; + inline static constexpr u8 DiskInterfaceFFinished = 0x80; + inline static constexpr u8 KeyPressed = 0xA0; + inline static constexpr u8 KeyReleased = 0xA1; + inline static constexpr u8 TextEntered = 0xA2; - inline static constexpr uint8_t Text16ModeScreenRefreshed = 0xE0; + inline static constexpr u8 Text16ModeScreenRefreshed = 0xE0; - inline static String getInterruptName(uint8_t code) + inline static String getInterruptName(u8 code) { switch (code) { @@ -219,189 +219,189 @@ namespace dragon class CMOSRegisters { public: - inline static constexpr uint8_t MemoryStart = 0x00; - inline static constexpr uint8_t MemorySize = 0x02; - inline static constexpr uint8_t ClockSpeed = 0x04; - inline static constexpr uint8_t ScreenRedrawRate = 0x06; - inline static constexpr uint8_t ScreenWidth = 0x07; - inline static constexpr uint8_t ScreenHeight = 0x09; - inline static constexpr uint8_t BootDisk = 0x10; - inline static constexpr uint8_t StackSize = 0x11; + inline static constexpr u8 MemoryStart = 0x00; + inline static constexpr u8 MemorySize = 0x02; + inline static constexpr u8 ClockSpeed = 0x04; + inline static constexpr u8 ScreenRedrawRate = 0x06; + inline static constexpr u8 ScreenWidth = 0x07; + inline static constexpr u8 ScreenHeight = 0x09; + inline static constexpr u8 BootDisk = 0x10; + inline static constexpr u8 StackSize = 0x11; - inline static constexpr uint8_t DiskList = 0x7E; + inline static constexpr u8 DiskList = 0x7E; }; class DPTStructure { public: struct tFlags { - inline static constexpr uint8_t Boot = 0; + inline static constexpr u8 Boot = 0; }; public: - inline static constexpr uint16_t DPTID = 0x000; - inline static constexpr uint16_t DPTVersionMaj = 0x002; - inline static constexpr uint16_t DPTVersionMin = 0x003; - inline static constexpr uint16_t PartitionCount = 0x004; + inline static constexpr u16 DPTID = 0x000; + inline static constexpr u16 DPTVersionMaj = 0x002; + inline static constexpr u16 DPTVersionMin = 0x003; + inline static constexpr u16 PartitionCount = 0x004; - inline static constexpr uint16_t EntriesStart = 0x00C; + inline static constexpr u16 EntriesStart = 0x00C; - inline static constexpr uint16_t EntryStartAddress = 0x000; - inline static constexpr uint16_t EntryPartitionSize = 0x004; - inline static constexpr uint16_t EntryFlags = 0x008; - inline static constexpr uint16_t EntryPartitionLabel = 0x024; + inline static constexpr u16 EntryStartAddress = 0x000; + inline static constexpr u16 EntryPartitionSize = 0x004; + inline static constexpr u16 EntryFlags = 0x008; + inline static constexpr u16 EntryPartitionLabel = 0x024; - inline static constexpr uint16_t HeaderReservedSizeBytes = 7; - inline static constexpr uint16_t DiskAddress = 0x200; - inline static constexpr uint16_t DPT_ID_CODE = 0xF1CA; - inline static constexpr uint16_t EntrySizeBytes = 100; - inline static constexpr uint16_t EntryLabelSizeBytes = 64; - inline static constexpr uint16_t EntryReservedSizeBytes = 26; - inline static constexpr uint16_t HeaderSizeBytes = 12; - inline static constexpr uint16_t DPTBlockSizeBytes = 512; - inline static constexpr uint8_t CurrentDPTVersionMaj = 0x00; - inline static constexpr uint8_t CurrentDPTVersionMin = 0x02; - inline static constexpr uint32_t DiskStartAddr = 0x00000400; - inline static constexpr uint8_t MaxPartCount = 5; + inline static constexpr u16 HeaderReservedSizeBytes = 7; + inline static constexpr u16 DiskAddress = 0x200; + inline static constexpr u16 DPT_ID_CODE = 0xF1CA; + inline static constexpr u16 EntrySizeBytes = 100; + inline static constexpr u16 EntryLabelSizeBytes = 64; + inline static constexpr u16 EntryReservedSizeBytes = 26; + inline static constexpr u16 HeaderSizeBytes = 12; + inline static constexpr u16 DPTBlockSizeBytes = 512; + inline static constexpr u8 CurrentDPTVersionMaj = 0x00; + inline static constexpr u8 CurrentDPTVersionMin = 0x02; + inline static constexpr u32 DiskStartAddr = 0x00000400; + inline static constexpr u8 MaxPartCount = 5; - inline static constexpr uint16_t BootPart_IDAddr = 0x0000; - inline static constexpr uint16_t BootPart_CodeStart = 0x0020; - inline static constexpr uint16_t BootPart_ID_CODE = 0xF1C4; - inline static constexpr uint16_t BootPart_CodeSizeBytes = 1024; - inline static constexpr uint8_t BootPart_HeaderSizeBytes = 32; + inline static constexpr u16 BootPart_IDAddr = 0x0000; + inline static constexpr u16 BootPart_CodeStart = 0x0020; + inline static constexpr u16 BootPart_ID_CODE = 0xF1C4; + inline static constexpr u16 BootPart_CodeSizeBytes = 1024; + inline static constexpr u8 BootPart_HeaderSizeBytes = 32; }; class CPUExtension { public: inline virtual ~CPUExtension(void) { } - 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; + inline CPUExtension(u8 code, String name) : m_code(code), m_name(name) { } + virtual String getOpCodeString(u8 opCode) = 0; + virtual u8 getInstructionSIze(u8 opCode) = 0; virtual bool execute(hw::VirtualCPU& vcpu) = 0; public: - uint8_t m_code { 0x00 }; + u8 m_code { 0x00 }; String m_name { "" }; }; class OpCodes { public: - 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 DEBUG_DumpRAM = 0x05; + inline static constexpr u8 NoOp = 0x00; + inline static constexpr u8 DEBUG_Break = 0x01; + inline static constexpr u8 BIOSModeImm = 0x02; + inline static constexpr u8 DEBUG_StartProfile = 0x03; + inline static constexpr u8 DEBUG_StopProfile = 0x04; + inline static constexpr u8 DEBUG_DumpRAM = 0x05; - inline static constexpr uint8_t MovImmReg = 0x10; - inline static constexpr uint8_t MovRegReg = 0x11; - inline static constexpr uint8_t MovRegMem = 0x12; - inline static constexpr uint8_t MovMemReg = 0x13; - inline static constexpr uint8_t MovImmMem = 0x14; - inline static constexpr uint8_t MovDerefRegReg = 0x15; - // inline static constexpr uint8_t MovImmRegOffReg = 0x16; - inline static constexpr uint8_t MovDerefRegMem = 0x17; - inline static constexpr uint8_t MovRegDerefReg = 0x18; - inline static constexpr uint8_t MovMemDerefReg = 0x19; - inline static constexpr uint8_t MovImmDerefReg = 0x1A; - inline static constexpr uint8_t MovDerefRegDerefReg = 0x1B; + inline static constexpr u8 MovImmReg = 0x10; + inline static constexpr u8 MovRegReg = 0x11; + inline static constexpr u8 MovRegMem = 0x12; + inline static constexpr u8 MovMemReg = 0x13; + inline static constexpr u8 MovImmMem = 0x14; + inline static constexpr u8 MovDerefRegReg = 0x15; + // inline static constexpr u8 MovImmRegOffReg = 0x16; + inline static constexpr u8 MovDerefRegMem = 0x17; + inline static constexpr u8 MovRegDerefReg = 0x18; + inline static constexpr u8 MovMemDerefReg = 0x19; + inline static constexpr u8 MovImmDerefReg = 0x1A; + inline static constexpr u8 MovDerefRegDerefReg = 0x1B; - inline static constexpr uint8_t MovByteImmMem = 0x20; - inline static constexpr uint8_t MovByteDerefRegMem = 0x21; - inline static constexpr uint8_t MovByteImmDerefReg = 0x22; - inline static constexpr uint8_t MovByteRegDerefReg = 0x23; - inline static constexpr uint8_t MovByteMemDerefReg = 0x24; - inline static constexpr uint8_t MovByteDerefRegDerefReg = 0x25; - inline static constexpr uint8_t MovByteMemReg = 0x26; - inline static constexpr uint8_t MovByteImmReg = 0x27; - inline static constexpr uint8_t MovByteDerefRegReg = 0x28; - inline static constexpr uint8_t MovByteRegMem = 0x29; + inline static constexpr u8 MovByteImmMem = 0x20; + inline static constexpr u8 MovByteDerefRegMem = 0x21; + inline static constexpr u8 MovByteImmDerefReg = 0x22; + inline static constexpr u8 MovByteRegDerefReg = 0x23; + inline static constexpr u8 MovByteMemDerefReg = 0x24; + inline static constexpr u8 MovByteDerefRegDerefReg = 0x25; + inline static constexpr u8 MovByteMemReg = 0x26; + inline static constexpr u8 MovByteImmReg = 0x27; + inline static constexpr u8 MovByteDerefRegReg = 0x28; + inline static constexpr u8 MovByteRegMem = 0x29; - inline static constexpr uint8_t AddRegReg = 0x30; - inline static constexpr uint8_t AddImmReg = 0x31; - inline static constexpr uint8_t SubRegReg = 0x32; - inline static constexpr uint8_t SubImmReg = 0x33; - inline static constexpr uint8_t MulRegReg = 0x34; - inline static constexpr uint8_t MulImmReg = 0x35; - inline static constexpr uint8_t DivRegReg = 0x36; - inline static constexpr uint8_t DivImmReg = 0x37; + inline static constexpr u8 AddRegReg = 0x30; + inline static constexpr u8 AddImmReg = 0x31; + inline static constexpr u8 SubRegReg = 0x32; + inline static constexpr u8 SubImmReg = 0x33; + inline static constexpr u8 MulRegReg = 0x34; + inline static constexpr u8 MulImmReg = 0x35; + inline static constexpr u8 DivRegReg = 0x36; + inline static constexpr u8 DivImmReg = 0x37; - inline static constexpr uint8_t IncReg = 0x40; - inline static constexpr uint8_t DecReg = 0x41; + inline static constexpr u8 IncReg = 0x40; + inline static constexpr u8 DecReg = 0x41; - inline static constexpr uint8_t PushImm = 0x50; - inline static constexpr uint8_t PushReg = 0x51; - inline static constexpr uint8_t PopReg = 0x52; - inline static constexpr uint8_t CallImm = 0x53; - inline static constexpr uint8_t CallReg = 0x54; - inline static constexpr uint8_t Ret = 0x55; - inline static constexpr uint8_t ArgReg = 0x56; + inline static constexpr u8 PushImm = 0x50; + inline static constexpr u8 PushReg = 0x51; + inline static constexpr u8 PopReg = 0x52; + inline static constexpr u8 CallImm = 0x53; + inline static constexpr u8 CallReg = 0x54; + inline static constexpr u8 Ret = 0x55; + inline static constexpr u8 ArgReg = 0x56; - inline static constexpr uint8_t LShiftRegImm = 0x60; - inline static constexpr uint8_t LShiftRegReg = 0x61; - inline static constexpr uint8_t RShiftRegImm = 0x62; - inline static constexpr uint8_t RShiftRegReg = 0x63; - inline static constexpr uint8_t AndRegImm = 0x64; - inline static constexpr uint8_t AndRegReg = 0x65; - inline static constexpr uint8_t OrRegImm = 0x66; - inline static constexpr uint8_t OrRegReg = 0x67; - inline static constexpr uint8_t XorRegImm = 0x68; - inline static constexpr uint8_t XorRegReg = 0x69; - inline static constexpr uint8_t NotReg = 0x6A; - inline static constexpr uint8_t NegReg = 0x6B; - inline static constexpr uint8_t NegByteReg = 0x6C; + inline static constexpr u8 LShiftRegImm = 0x60; + inline static constexpr u8 LShiftRegReg = 0x61; + inline static constexpr u8 RShiftRegImm = 0x62; + inline static constexpr u8 RShiftRegReg = 0x63; + inline static constexpr u8 AndRegImm = 0x64; + inline static constexpr u8 AndRegReg = 0x65; + inline static constexpr u8 OrRegImm = 0x66; + inline static constexpr u8 OrRegReg = 0x67; + inline static constexpr u8 XorRegImm = 0x68; + inline static constexpr u8 XorRegReg = 0x69; + inline static constexpr u8 NotReg = 0x6A; + inline static constexpr u8 NegReg = 0x6B; + inline static constexpr u8 NegByteReg = 0x6C; - inline static constexpr uint8_t JmpNotEqImm = 0x70; - inline static constexpr uint8_t JmpNotEqReg = 0x71; - inline static constexpr uint8_t JmpEqImm = 0x72; - inline static constexpr uint8_t JmpEqReg = 0x73; - inline static constexpr uint8_t JmpGrImm = 0x74; - inline static constexpr uint8_t JmpGrReg = 0x75; - inline static constexpr uint8_t JmpLessImm = 0x76; - inline static constexpr uint8_t JmpLessReg = 0x77; - inline static constexpr uint8_t JmpGeImm = 0x78; - inline static constexpr uint8_t JmpGeReg = 0x79; - inline static constexpr uint8_t JmpLeImm = 0x7A; - inline static constexpr uint8_t JmpLeReg = 0x7B; - inline static constexpr uint8_t Jmp = 0x7C; + inline static constexpr u8 JmpNotEqImm = 0x70; + inline static constexpr u8 JmpNotEqReg = 0x71; + inline static constexpr u8 JmpEqImm = 0x72; + inline static constexpr u8 JmpEqReg = 0x73; + inline static constexpr u8 JmpGrImm = 0x74; + inline static constexpr u8 JmpGrReg = 0x75; + inline static constexpr u8 JmpLessImm = 0x76; + inline static constexpr u8 JmpLessReg = 0x77; + inline static constexpr u8 JmpGeImm = 0x78; + inline static constexpr u8 JmpGeReg = 0x79; + inline static constexpr u8 JmpLeImm = 0x7A; + inline static constexpr u8 JmpLeReg = 0x7B; + inline static constexpr u8 Jmp = 0x7C; - inline static constexpr uint8_t Ext01 = 0xE0; - inline static constexpr uint8_t Ext02 = 0xE1; - inline static constexpr uint8_t Ext03 = 0xE2; - inline static constexpr uint8_t Ext04 = 0xE3; - inline static constexpr uint8_t Ext05 = 0xE4; - inline static constexpr uint8_t Ext06 = 0xE5; - inline static constexpr uint8_t Ext07 = 0xE6; - inline static constexpr uint8_t Ext08 = 0xE7; - inline static constexpr uint8_t Ext09 = 0xE8; - inline static constexpr uint8_t Ext10 = 0xE9; - inline static constexpr uint8_t Ext11 = 0xEA; - inline static constexpr uint8_t Ext12 = 0xEB; - inline static constexpr uint8_t Ext13 = 0xEC; - inline static constexpr uint8_t Ext14 = 0xED; - inline static constexpr uint8_t Ext15 = 0xEE; - inline static constexpr uint8_t Ext16 = 0xEF; + inline static constexpr u8 Ext01 = 0xE0; + inline static constexpr u8 Ext02 = 0xE1; + inline static constexpr u8 Ext03 = 0xE2; + inline static constexpr u8 Ext04 = 0xE3; + inline static constexpr u8 Ext05 = 0xE4; + inline static constexpr u8 Ext06 = 0xE5; + inline static constexpr u8 Ext07 = 0xE6; + inline static constexpr u8 Ext08 = 0xE7; + inline static constexpr u8 Ext09 = 0xE8; + inline static constexpr u8 Ext10 = 0xE9; + inline static constexpr u8 Ext11 = 0xEA; + inline static constexpr u8 Ext12 = 0xEB; + inline static constexpr u8 Ext13 = 0xEC; + inline static constexpr u8 Ext14 = 0xED; + inline static constexpr u8 Ext15 = 0xEE; + inline static constexpr u8 Ext16 = 0xEF; - inline static constexpr uint8_t ZeroFlag = 0xF0; - inline static constexpr uint8_t SetFlag = 0xF1; - inline static constexpr uint8_t ToggleFlag = 0xF2; - inline static constexpr uint8_t RetInt = 0xFD; - inline static constexpr uint8_t Int = 0xFE; - inline static constexpr uint8_t Halt = 0xFF; + inline static constexpr u8 ZeroFlag = 0xF0; + inline static constexpr u8 SetFlag = 0xF1; + inline static constexpr u8 ToggleFlag = 0xF2; + inline static constexpr u8 RetInt = 0xFD; + inline static constexpr u8 Int = 0xFE; + inline static constexpr u8 Halt = 0xFF; - static String getOpCodeString(uint8_t opCode); - static uint8_t getInstructionSIze(uint8_t opCode); + static String getOpCodeString(u8 opCode); + static u8 getInstructionSIze(u8 opCode); }; class DefaultValues { public: - inline static constexpr uint8_t MaxMemoryExtensionPages = 255; + inline static constexpr u8 MaxMemoryExtensionPages = 255; }; } } diff --git a/src/tools/Tools.cpp b/src/tools/Tools.cpp index 6299d40..d2f1913 100644 --- a/src/tools/Tools.cpp +++ b/src/tools/Tools.cpp @@ -11,22 +11,22 @@ namespace dragon { - bool Tools::createVirtualHardDrive(uint32_t sizeInBytes, const String& dataFilePath) + bool Tools::createVirtualHardDrive(u32 sizeInBytes, const String& dataFilePath) { std::ofstream rf(dataFilePath.cpp_str(), std::ios::out | std::ios::binary); if(!rf) return false; ostd::ByteStream stream; - for (int32_t i = 0; i < sizeInBytes; i++) + for (i32 i = 0; i < sizeInBytes; i++) stream.push_back(0x00); rf.write((char*)(&stream[0]), stream.size()); rf.close(); return true; } - int32_t Tools::execute(int argc, char** argv) + i32 Tools::execute(int argc, char** argv) { String tool = ""; - int32_t rValue = get_tool(argc, argv, tool); + i32 rValue = get_tool(argc, argv, tool); if (rValue != ErrorNoError) return rValue; @@ -74,7 +74,7 @@ namespace dragon return ErrorNoError; } - int32_t Tools::tool_new_virtual_disk(int argc, char** argv) + i32 Tools::tool_new_virtual_disk(int argc, char** argv) { if (argc < 4) { @@ -101,7 +101,7 @@ namespace dragon return ErrorNoError; } - int32_t Tools::tool_load_binary(int argc, char** argv) + i32 Tools::tool_load_binary(int argc, char** argv) { if (argc < 5) { @@ -129,8 +129,8 @@ namespace dragon out.fg(ostd::ConsoleColors::Red).p("Error: Unable to load data file.").reset().nl(); return ErrorLoadProgUnableToLoadDataFile; } - int16_t index = 0; - uint32_t addr = (uint32_t)str_addr.toInt(); + i16 index = 0; + u32 addr = (u32)str_addr.toInt(); for (auto& b : code) { vHDD.write(addr + index, b); @@ -145,7 +145,7 @@ namespace dragon return ErrorNoError; } - int32_t Tools::tool_read_dpt(int argc, char** argv) + i32 Tools::tool_read_dpt(int argc, char** argv) { if (argc < 3) { @@ -173,54 +173,54 @@ namespace dragon } // ostd::Utils::printByteStream(outData, 0, 16, 32, out); ostd::serial::SerialIO dpt_block(outData); - int8_t outData8 = 0; - int16_t outData16 = 0; - int32_t outData32 = 0; + i8 outData8 = 0; + i16 outData16 = 0; + i32 outData32 = 0; //TODO: Add errors for all read calls dpt_block.r_Word(data::DPTStructure::DPTID, outData16); - uint16_t code = (uint16_t)outData16; + u16 code = (u16)outData16; if (code != data::DPTStructure::DPT_ID_CODE) { out.fg(ostd::ConsoleColors::Red).p("Error: No DPT partition table on virtual disk.").reset().nl(); return ErrorReadDPTNoPartitionTable; } dpt_block.r_Byte(data::DPTStructure::DPTVersionMaj, outData8); - uint32_t version_maj = (uint32_t)outData8; + u32 version_maj = (u32)outData8; dpt_block.r_Byte(data::DPTStructure::DPTVersionMin, outData8); - uint32_t version_min = (uint32_t)outData8; + u32 version_min = (u32)outData8; dpt_block.r_Byte(data::DPTStructure::PartitionCount, outData8); - uint32_t part_count = (uint32_t)outData8; + u32 part_count = (u32)outData8; if (part_count > data::DPTStructure::MaxPartCount) { out.fg(ostd::ConsoleColors::Red).p("Error: Too many partitions. Maximum is ").p(data::DPTStructure::MaxPartCount).p(".").reset().nl(); return ErrorReadDPTNoPartitionTable; } struct tPartitionData { - uint32_t startAddress { 0 }; - uint32_t size { 0 }; + u32 startAddress { 0 }; + u32 size { 0 }; ostd::BitField_16 flags { 0 }; String label { "" }; }; std::vector partitionList; - for (int32_t i = 0; i < part_count; i++) + for (i32 i = 0; i < part_count; i++) { tPartitionData pdata; - uint32_t entry_addr = data::DPTStructure::EntriesStart + (data::DPTStructure::EntrySizeBytes * i); + u32 entry_addr = data::DPTStructure::EntriesStart + (data::DPTStructure::EntrySizeBytes * i); dpt_block.r_DWord(entry_addr + data::DPTStructure::EntryStartAddress, outData32); - pdata.startAddress = (uint32_t)outData32; + pdata.startAddress = (u32)outData32; dpt_block.r_DWord(entry_addr + data::DPTStructure::EntryPartitionSize, outData32); - pdata.size = (uint32_t)outData32; + pdata.size = (u32)outData32; dpt_block.r_Word(entry_addr + data::DPTStructure::EntryFlags, outData16); - pdata.flags.value = (uint16_t)outData16; + pdata.flags.value = (u16)outData16; dpt_block.r_NullTerminatedString(entry_addr + data::DPTStructure::EntryPartitionLabel, pdata.label); pdata.label.trim(); partitionList.push_back(pdata); } 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; + auto print_part_size = [](u32 size, ostd::ConsoleOutputHandler& out, u16 line_len) { + f64 dsize = size; String units[4] = { " bytes", " Kb", " Mb", " Gb" }; - int32_t unit_index = 0; + i32 unit_index = 0; while (dsize > 1024 && unit_index < 3) { unit_index++; @@ -228,7 +228,7 @@ namespace dragon } out.p(String("").add(dsize, 2).add(units[unit_index]).new_fixedLength(line_len)); }; - uint16_t len = 20; + u16 len = 20; out.nl().fg(ostd::ConsoleColors::BrightGray); out.p(String("=").new_fixedLength(5 * len, '=')).nl(); out.fg(ostd::ConsoleColors::Blue); @@ -240,7 +240,7 @@ namespace dragon out.p(String("FLAGS").new_fixedLength(len)); out.nl().fg(ostd::ConsoleColors::BrightGray); out.p(String("=").new_fixedLength(5 * len, '=')).nl(); - for (int32_t i = 0; i < partitionList.size(); i++) + for (i32 i = 0; i < partitionList.size(); i++) { auto& part = partitionList[i]; if (part.label == "") @@ -251,7 +251,7 @@ namespace dragon 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++) + for (u8 bit = 0; bit < sizeof(part.flags) * 8; bit++) { if (m_dpt_flags_str.count(bit) == 0) continue; @@ -269,7 +269,7 @@ namespace dragon return ErrorNoError; } - int32_t Tools::tool_new_dpt(int argc, char** argv) + i32 Tools::tool_new_dpt(int argc, char** argv) { if (argc < 5) { @@ -284,10 +284,10 @@ namespace dragon out.fg(ostd::ConsoleColors::Red).p("Error: Unable to load virtual disk.").reset().nl(); return ErrorLoadProgUnableToLoadVDisk; } - uint64_t disk_size = vHDD.getSize(); + u64 disk_size = vHDD.getSize(); auto& _dpt_flags_str = m_dpt_flags_str; - auto get_flag_from_str = [_dpt_flags_str](const String& flag_str) -> int8_t { + auto get_flag_from_str = [_dpt_flags_str](const String& flag_str) -> i8 { for (auto& flag : _dpt_flags_str) { if (flag.second == flag_str) @@ -295,27 +295,27 @@ namespace dragon } return -1; }; - auto make_bytestream = [](uint16_t size, ostd::Byte value = 0xFF) -> ostd::ByteStream { + auto make_bytestream = [](u16 size, ostd::Byte value = 0xFF) -> ostd::ByteStream { ostd::ByteStream stream; - for (int16_t i = 0; i < size; i++) + for (i16 i = 0; i < size; i++) stream.push_back(value); return stream; }; struct tPartData { - uint32_t size { 0 }; - uint32_t address { 0 }; - std::vector flags; + u32 size { 0 }; + u32 address { 0 }; + std::vector flags; String label { "" }; }; std::vector partitions; - int32_t arg_index = 3; + i32 arg_index = 3; bool has_args = true; bool part_started = false; tPartData _part_data; - uint32_t part_start_addr = data::DPTStructure::DiskStartAddr; + u32 part_start_addr = data::DPTStructure::DiskStartAddr; while (has_args) { String arg = argv[arg_index]; @@ -347,7 +347,7 @@ namespace dragon return ErrorNewDPTNoPartitionFlag; } arg_index++; - int8_t flag = get_flag_from_str(argv[arg_index]); + i8 flag = get_flag_from_str(argv[arg_index]); if (flag < 0) { out.fg(ostd::ConsoleColors::Red).p("Error: Unknown partition flag.").reset().nl(); @@ -371,7 +371,7 @@ namespace dragon return ErrorNewDPTInvalidPartitionSize; } arg_index++; - uint32_t part_size = String(argv[arg_index]).toInt(); + u32 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(); @@ -408,7 +408,7 @@ namespace dragon addr += ostd::tTypeSize::BYTE; dpt_block.w_Byte(addr, (ostd::Byte)(partitions.size())); addr += ostd::tTypeSize::BYTE; - uint16_t reserved_size = data::DPTStructure::HeaderReservedSizeBytes; + u16 reserved_size = data::DPTStructure::HeaderReservedSizeBytes; dpt_block.w_ByteStream(addr, make_bytestream(reserved_size), false); addr += reserved_size; @@ -437,7 +437,7 @@ namespace dragon addr += data::DPTStructure::EntryLabelSizeBytes; } - int16_t index = 0; + i16 index = 0; for (auto& b : dpt_block.getData()) { vHDD.write(data::DPTStructure::DiskAddress + index, b); @@ -451,7 +451,7 @@ namespace dragon return ErrorNoError; } - int32_t Tools::tool_print_disassembly(int argc, char** argv) + i32 Tools::tool_print_disassembly(int argc, char** argv) { using TableList = std::vector; if (argc < 3) @@ -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, String& outTool) + i32 Tools::get_tool(int argc, char** argv, String& outTool) { if (argc < 2) { diff --git a/src/tools/Tools.hpp b/src/tools/Tools.hpp index ab7eec0..9ff1c6f 100644 --- a/src/tools/Tools.hpp +++ b/src/tools/Tools.hpp @@ -10,51 +10,51 @@ namespace dragon { public: static inline ostd::ConsoleOutputHandler& output(void) { return out; } - static bool createVirtualHardDrive(uint32_t sizeInBytes, const String& dataFilePath); - static int32_t execute(int argc, char** argv); + static bool createVirtualHardDrive(u32 sizeInBytes, const String& dataFilePath); + static i32 execute(int argc, char** argv); private: - static int32_t tool_new_virtual_disk(int argc, char** argv); - static int32_t tool_load_binary(int argc, char** argv); - static int32_t tool_read_dpt(int argc, char** argv); - static int32_t tool_new_dpt(int argc, char** argv); - static int32_t tool_print_disassembly(int argc, char** argv); + static i32 tool_new_virtual_disk(int argc, char** argv); + static i32 tool_load_binary(int argc, char** argv); + static i32 tool_read_dpt(int argc, char** argv); + static i32 tool_new_dpt(int argc, char** argv); + static i32 tool_print_disassembly(int argc, char** argv); static void print_application_help(void); - static int32_t get_tool(int argc, char** argv, String& outTool); + static i32 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" } }; public: - inline static constexpr int32_t ErrorNoError = 0; - inline static constexpr int32_t ErrorTopLevelTooFewArgs = 1; - inline static constexpr int32_t ErrorTopLevelUnknownTool = 2; - inline static constexpr int32_t ErrorNewVDiskTooFewArgs = 3; - inline static constexpr int32_t ErrorNewVDiskNonIntSize = 4; - inline static constexpr int32_t ErrorNewVDiskUnable = 5; - inline static constexpr int32_t ErrorLoadProgTooFewArgs = 6; - inline static constexpr int32_t ErrorLoadProgNonIntAddr = 7; - inline static constexpr int32_t ErrorLoadProgUnableToLoadVDisk = 8; - inline static constexpr int32_t ErrorLoadProgUnableToLoadDataFile = 9; - inline static constexpr int32_t ErrorReadDPTTooFewArgs = 10; - inline static constexpr int32_t ErrorReadDPTUnableToLoadVDisk = 11; - inline static constexpr int32_t ErrorReadDPTSmallDisk = 12; - inline static constexpr int32_t ErrorReadDPTUnableToRead = 13; - inline static constexpr int32_t ErrorReadDPTNoPartitionTable = 14; - inline static constexpr int32_t ErrorNewDPTNoPartitionSize = 15; - inline static constexpr int32_t ErrorNewDPTInvalidPartitionSize = 16; - inline static constexpr int32_t ErrorNewDPTNoPartitionLabel = 17; - inline static constexpr int32_t ErrorNewDPTNoPartitionFlag = 18; - inline static constexpr int32_t ErrorNewDPTDiskOverflow = 19; - inline static constexpr int32_t ErrorNewDPTUnknownFlag = 20; - inline static constexpr int32_t ErrorNewDPTTooManyPartitions = 21; - inline static constexpr int32_t ErrorPrintDisassemblyTooFewArgs = 22; - inline static constexpr int32_t ErrorPrintDisassemblyInvalidFile = 23; - inline static constexpr int32_t ErrorPrintDisassemblyInvalidArg = 24; + inline static constexpr i32 ErrorNoError = 0; + inline static constexpr i32 ErrorTopLevelTooFewArgs = 1; + inline static constexpr i32 ErrorTopLevelUnknownTool = 2; + inline static constexpr i32 ErrorNewVDiskTooFewArgs = 3; + inline static constexpr i32 ErrorNewVDiskNonIntSize = 4; + inline static constexpr i32 ErrorNewVDiskUnable = 5; + inline static constexpr i32 ErrorLoadProgTooFewArgs = 6; + inline static constexpr i32 ErrorLoadProgNonIntAddr = 7; + inline static constexpr i32 ErrorLoadProgUnableToLoadVDisk = 8; + inline static constexpr i32 ErrorLoadProgUnableToLoadDataFile = 9; + inline static constexpr i32 ErrorReadDPTTooFewArgs = 10; + inline static constexpr i32 ErrorReadDPTUnableToLoadVDisk = 11; + inline static constexpr i32 ErrorReadDPTSmallDisk = 12; + inline static constexpr i32 ErrorReadDPTUnableToRead = 13; + inline static constexpr i32 ErrorReadDPTNoPartitionTable = 14; + inline static constexpr i32 ErrorNewDPTNoPartitionSize = 15; + inline static constexpr i32 ErrorNewDPTInvalidPartitionSize = 16; + inline static constexpr i32 ErrorNewDPTNoPartitionLabel = 17; + inline static constexpr i32 ErrorNewDPTNoPartitionFlag = 18; + inline static constexpr i32 ErrorNewDPTDiskOverflow = 19; + inline static constexpr i32 ErrorNewDPTUnknownFlag = 20; + inline static constexpr i32 ErrorNewDPTTooManyPartitions = 21; + inline static constexpr i32 ErrorPrintDisassemblyTooFewArgs = 22; + inline static constexpr i32 ErrorPrintDisassemblyInvalidFile = 23; + inline static constexpr i32 ErrorPrintDisassemblyInvalidArg = 24; }; } diff --git a/src/tools/Utils.cpp b/src/tools/Utils.cpp index 563429a..6589d82 100644 --- a/src/tools/Utils.cpp +++ b/src/tools/Utils.cpp @@ -5,13 +5,13 @@ 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' }; - String Utils::genRandomName(uint8_t length) + String Utils::genRandomName(u8 length) { auto rnd_char = []() -> char { return g_symbols[ostd::Random::getui8(0, g_symbols.size())]; }; String name = ""; - for (int32_t i = 0; i < length; i++) + for (i32 i = 0; i < length; i++) name.addChar(rnd_char()); return name; } diff --git a/src/tools/Utils.hpp b/src/tools/Utils.hpp index 4d639d8..70f4503 100644 --- a/src/tools/Utils.hpp +++ b/src/tools/Utils.hpp @@ -8,6 +8,6 @@ namespace dragon class Utils { public: - static String genRandomName(uint8_t length); + static String genRandomName(u8 length); }; }