diff --git a/extra/dragon/bios.bin b/extra/dragon/bios.bin index b08040f..dfcdd69 100644 Binary files a/extra/dragon/bios.bin and b/extra/dragon/bios.bin differ diff --git a/extra/dss/bios/data.dss b/extra/dss/bios/data.dss index d9a1f94..e7873f6 100644 --- a/extra/dss/bios/data.dss +++ b/extra/dss/bios/data.dss @@ -77,7 +77,7 @@ @define S_REG_1 0x07 @define S_REG_2 0x08 -@define S_REG_3 0x09 +@define S_REG_OFFSET 0x09 @define INST_BIOS_NODE_TOGGLE 0x02 ## =============================================================================================== diff --git a/extra/dss/bios/entry.dss b/extra/dss/bios/entry.dss index 101083f..49173bf 100644 --- a/extra/dss/bios/entry.dss +++ b/extra/dss/bios/entry.dss @@ -26,6 +26,10 @@ mov FL, ACC ## ---- + mov reg(S_REG_OFFSET), 0x0000 ## Zero the offset register + or FL, 0b0000000000000010 ## Enable offset mode for memory addressing + mov FL, ACC + %low INST_BIOS_NODE_TOGGLE 0x00 ## Disable BIOS Mode before leaving the BIOS jmp MemoryAddresses.MBR ## Jump to start of MBR in memory hlt ## Just in case somehow execution reaches this point diff --git a/extra/dss/drake/bootsector.dss b/extra/dss/drake/bootsector.dss index 15ba6b5..8a32f4b 100644 --- a/extra/dss/drake/bootsector.dss +++ b/extra/dss/drake/bootsector.dss @@ -1,4 +1,4 @@ -.load [dynamic] +.load [dynamic, base=0x1740] .data $string "Hello BOOTSECTOR!!" diff --git a/src/debugger/Debugger.cpp b/src/debugger/Debugger.cpp index aaa9200..e3849d4 100644 --- a/src/debugger/Debugger.cpp +++ b/src/debugger/Debugger.cpp @@ -285,7 +285,7 @@ namespace dragon str.add("\n"); str.add("|---------------|------------------------------------|------------------------------------|-----|-----------|-----------|"); str.add("\n"); - str.add("| FL: |*%PREV_FL%**************************|**%CURR_FL%*************************| S3 |*%PREV_S3%*|*%CURR_S3%*|"); + str.add("| FL: |*%PREV_FL%**************************|**%CURR_FL%*************************| OF |*%PREV_OF%*|*%CURR_OF%*|"); str.add("\n"); str.add("|---------------|------------------------------------|------------------------------------|=====|===========|===========|"); str.add("\n"); @@ -833,28 +833,28 @@ namespace dragon tmp = " ", tmpStyle = ""; - tmp.add(ostd::Utils::getHexStr(minfo.previousInstructionRegisters[dragon::data::Registers::S3], true, 2)); + tmp.add(ostd::Utils::getHexStr(minfo.previousInstructionRegisters[dragon::data::Registers::OFFSET], true, 2)); tmp.addPadding(item_len, ' ', ostd::String::ePaddingBehavior::AllowOddExtraLeft); tmpStyle = "[@@style foreground:Blue]"; tmpStyle.add(tmp).add("[@@/]"); - str.replaceAll("%PREV_S3%", tmpStyle); + str.replaceAll("%PREV_OF%", tmpStyle); tmp = " "; - tmp.add(ostd::Utils::getHexStr(minfo.currentInstructionRegisters[dragon::data::Registers::S3], true, 2)); + tmp.add(ostd::Utils::getHexStr(minfo.currentInstructionRegisters[dragon::data::Registers::OFFSET], true, 2)); tmp.addPadding(item_len, ' ', ostd::String::ePaddingBehavior::AllowOddExtraLeft); - if (minfo.currentInstructionRegisters[dragon::data::Registers::S3] != minfo.previousInstructionRegisters[dragon::data::Registers::S3]) + if (minfo.currentInstructionRegisters[dragon::data::Registers::OFFSET] != minfo.previousInstructionRegisters[dragon::data::Registers::OFFSET]) tmpStyle = "[@@style foreground:Black,background:BrightRed]"; else tmpStyle = "[@@style foreground:Blue]"; tmpStyle.add(tmp).add("[@@/]"); - str.replaceAll("%CURR_S3%", tmpStyle); + str.replaceAll("%CURR_OF%", tmpStyle); } ostd::RegexRichString rgxstr(str); rgxstr.fg("InstAddr|Code|StackFrame|DBG BRK|INT Handler|BIOS Mode|SubRoutine", "Magenta"); rgxstr.fg("IP|SP|FP|RV|PP|FL|ACC", "Cyan"); rgxstr.fg("R10|R2|R3|R4|R5|R6|R7|R8|R9|R1", "BrightGreen"); - rgxstr.fg("S1|S2|S3", "BrightRed"); + rgxstr.fg("S1|S2|OF", "BrightRed"); rgxstr.fg("PREV", "Red"); rgxstr.fg("CURR", "Green"); out.pStyled(rgxstr); diff --git a/src/hardware/VirtualCPU.cpp b/src/hardware/VirtualCPU.cpp index 2424a66..5847639 100644 --- a/src/hardware/VirtualCPU.cpp +++ b/src/hardware/VirtualCPU.cpp @@ -203,6 +203,11 @@ namespace dragon m_currentExtension = nullptr; m_currentExtInst = 0x00; m_isDebugBreakPoint = false; + m_isOffsetAddressingEnabled = readFlag(data::Flags::OffsetModeEnabled); + if (m_isOffsetAddressingEnabled) + m_currentOffset = readRegister(data::Registers::OFFSET); + else + m_currentOffset = 0x0000; uint8_t inst = fetch8(); m_currentInst = inst; if (loadExtension()) diff --git a/src/hardware/VirtualCPU.hpp b/src/hardware/VirtualCPU.hpp index c9d378c..2348a72 100644 --- a/src/hardware/VirtualCPU.hpp +++ b/src/hardware/VirtualCPU.hpp @@ -47,7 +47,9 @@ namespace dragon inline int32_t 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 bool isOffsetAddressingModeEnabled(void) const { return m_isOffsetAddressingEnabled; } + inline uint16_t getCurrentOffset(void) const { return m_currentOffset; } + private: void __debug_store_stack_frame_string_on_push(void); @@ -65,6 +67,9 @@ namespace dragon bool m_debugModeEnabled { false }; int32_t m_subroutineCounter { 0 }; + bool m_isOffsetAddressingEnabled { false }; + uint16_t m_currentOffset { 0x0000 }; + data::CPUExtension* m_extensions[16]; data::CPUExtension* m_currentExtension { nullptr }; uint8_t m_currentExtInst { 0x00 }; diff --git a/src/hardware/VirtualRAM.cpp b/src/hardware/VirtualRAM.cpp index 4bb212f..3c87002 100644 --- a/src/hardware/VirtualRAM.cpp +++ b/src/hardware/VirtualRAM.cpp @@ -1,6 +1,7 @@ #include "VirtualRAM.hpp" #include "../tools/GlobalData.hpp" +#include "../runtime/DragonRuntime.hpp" namespace dragon { @@ -14,26 +15,30 @@ namespace dragon int8_t VirtualRAM::read8(uint16_t addr) { int8_t outVal = 0; - if (!m_memory.r_Byte(addr, outVal)) return 0x00; //TODO: Error + uint16_t 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) { int16_t outVal = 0; - if (!m_memory.r_Word(addr, outVal)) return 0x00; //TODO: Error + uint16_t 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) { - if (!m_memory.w_Byte(addr, value)) return 0; //TODO: Error + uint16_t 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) { - if (!m_memory.w_Word(addr, value)) return 0; //TODO: Error + uint16_t offset = DragonRuntime::cpu.getCurrentOffset(); + if (!m_memory.w_Word(addr + offset, value)) return 0; //TODO: Error return value; } diff --git a/src/tools/GlobalData.hpp b/src/tools/GlobalData.hpp index 7fa8b63..58e2f16 100644 --- a/src/tools/GlobalData.hpp +++ b/src/tools/GlobalData.hpp @@ -166,7 +166,7 @@ namespace dragon 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 S3 = 0x09; + 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; @@ -185,6 +185,7 @@ namespace dragon { public: inline static constexpr uint8_t InterruptsEnabled = 0; + inline static constexpr uint8_t OffsetModeEnabled = 1; }; class InterruptCodes