From dc20f5cf3965e663c84691f826df8465fa38e9b7 Mon Sep 17 00:00:00 2001 From: OmniaX-Dev Date: Tue, 17 Sep 2024 07:32:24 +0200 Subject: [PATCH] Sync push --- build.nr | 2 +- extra/dragon/bios.bin | Bin 4096 -> 4096 bytes extra/dragon/disk1.dr | Bin 4194304 -> 4194304 bytes extra/dss/bios/data.dss | 12 +++ extra/dss/bios/display.dss | 33 ++++++++ extra/dss/bios/drivers.dss | 27 +++++-- extra/dss/bios_api.dss | 10 ++- extra/dss/drake/bootsector.dss | 119 +++++++++++++++++++++++----- extra/dss/drake/keyboard_driver.dss | 10 +++ extra/info/info | 6 +- src/assembler/Assembler.cpp | 74 +++++++++++++---- src/hardware/VirtualDisplay.cpp | 10 +++ src/hardware/VirtualIODevices.cpp | 18 ++++- src/hardware/VirtualIODevices.hpp | 1 + 14 files changed, 273 insertions(+), 49 deletions(-) create mode 100644 extra/dss/drake/keyboard_driver.dss diff --git a/build.nr b/build.nr index f800fc8..871215b 100644 --- a/build.nr +++ b/build.nr @@ -1 +1 @@ -1617 +1618 diff --git a/extra/dragon/bios.bin b/extra/dragon/bios.bin index 7a15e061eeaec0dae64e5d77861ef27d144e28b2..5390afe734c1dbf189f8ac4467fa81e9c302c277 100644 GIT binary patch delta 626 zcmZ8dJ&)5s5PkM~XM^oT@t*8-$R+|g5=Eq|=zJa0U2(bS($Iy9f+Ly&8cPWu2cknt zO+`m{qB(^41N8KX#2=uexro{La!5$KJMYczdpk3We37fV_2fcrg84%vtPf#XPXN}B z;nn)ANMG8@7U?TFd+BStE-d_BdcFhicHq6u(*;B!Yh;h%je~s$6G!}U@a;N}hFvAJ z$NC36)<5C1USY0S|3ScHpqVldQvt(t7cHjyxW%-Okm(Q+(-bk&Qxr@eaEIw5`b?j( zV!FV(rprMV*gR9dz&r~=fl6Q*TDfq{uWU(nCZ9s`T?1c=oJ+~(LBmzk!IoZ|IR}xF z?4W^K!aq;dcuJAZ^B!e-Mvs6z)86*Ec4?cDE6fNivNvw9+1u@TZmZ>UN(Ps^dC^yS zb3=Y@EtKm`h$AILgCCQPMy(&X6ER|YRYE%zg1eBqZ4}&x(N-WtF3&x d49#!9HCkSo+wEuF1j9{!42;c-FJY6r9}NzB|tkax1wYs9Z!OViWKO7!koT8nm#oQNb_5!!lr0L~RXrc3Rkq zjbJ18Vr!Y$*lL%?=vyzMu)A;O?d*Q$nijPFfgR;*{O{P9F*T45^>>BT}rN;IMvy zV!ihcm-QDkQy++F03Op2e5O%!F-;&~nn5?yGJ2R+kz+c+2-7(lOc!WY>2f@BO&lpl zU>v!DKqW9A7`d>_DVjW)iu?!Zr#(1HSb7$^CS3jF9W(17Pf50$KrQ9ZQzf2~&w7qg zq$?!zizA)-k!#yF5!qm#!1^|g3|{_DhOT}@%BB}V!wT*wKXnZ(rUPJ!D)b5&TcH?K zsm0U+npr~73>6CV%64BD%yeMWj>``r1r=)5cfAkCd#kVe!@XPS5QTPJ0?JnGX|5k zP%~e!=KjxYzW?gXsh05#c!&P+hN0Wv(mXhHmV$i{7GV=ZM2|v)=ZN!!A|{C`Vw$)>TqH`w3~`Al6PJlA r#8sj~B*ZnMO3V`1i5tXC;udk6xI^3}=7@RX9&w*|Ks@|{N5B69dToS{ delta 379 zcmXBMIZ8uO7>41KYxKrM@4a!#dmK+3qH&&QO~6LPB47qBEbRobvolzH8;EPL7F>Zl zuy+GCZb7}6;`{mGfw$Rgdd+yRUebR)y}7-;b8iVE@3EdP+D5vbDcZ}7vsLG8%|wAQ zMOzOFp>34I*u$vbbl)r#>h?6(^-iTJDh-wS)?Y{PT* zGG5Jhwr=9UWR%UFv?H;m+B#S>G5c-iyv@I@Yk%+U-7iJ05C8KCkr1Bf5J}M~x`Z!M zqFbazM)ZhY5r|MkA}jhtzZejMVo2mf+_7R @include +@include .data - $string "Hello " + ## Disk data structures $ddd $dpt_block - $textCell + + $textCell + $counter 0x00 + $current_char 65 + + $dpt_version_str "DPT Version " + $drake_version_str "Drake 0.1 -- " + $invalid_dpt_block_str "Error: Invalid DPT Block..." .code _drake_bootsector_entry_point: - push $ddd - push $dpt_block + ## Load DPT block from disk 0 + push $ddd ## Empty DiskDriverData used to load from disk + push $dpt_block ## Empty DPT Block to store the partition table push 2 call $_load_dpt_block - + ## Enable Text16 Video Mode movb [VGA_Registers.VIDEO_MODE], VGA_VideoModes.TEXT_16_COLORS - - push 2 + ## Validate DPT Block + mov ACC, [$dpt_block] + jne $_invalid_dpt_block, 0xF1CA + ## Init Keyboard driver + push $_key_pressed ## KeyPressed handler address passed to the _init_keyboard subroutine push 1 - push 2 - call $_draw_palette + call $_init_keyboard - - movb [$textCell.CoordX], 2 - movb [$textCell.CoordY], 2 - movb [$textCell.Foreground], DefaultPalette.Orange + movb [$textCell.CoordX], 0 + movb [$textCell.CoordY], 0 + movb [$textCell.Foreground], DefaultPalette.Pink movb [$textCell.Background], DefaultPalette.Black mov R10, 0x22 - mov R8, $string + mov R8, $drake_version_str mov R9, $textCell int 0x30 - - movb [$textCell.CoordX], 8 - movb [$textCell.CoordY], 2 - movb [$textCell.Foreground], DefaultPalette.Black - movb [$textCell.Background], DefaultPalette.Orange - + movb [$textCell.CoordX], 13 mov R10, 0x22 - mov R8, { $dpt_block + DPTStructure.ENTRIES_START + (2 * DPTStructure.ENTRY_SIZE_B) + DPTStructure.ENTRY_PART_LBL } + mov R8, $dpt_version_str mov R9, $textCell int 0x30 + movb [$textCell.CoordX], 26 + mov R10, 0x23 + movb R8, [{ $dpt_block + 2 }] + mov R9, $textCell + int 0x30 + + movb [$textCell.CoordX], 27 + movb [$textCell.Character], 0x2E + mov R10, 0x21 + mov R9, $textCell + int 0x30 + + movb [$textCell.CoordX], 28 + mov R10, 0x23 + movb R8, [{ $dpt_block + 3 }] + mov R9, $textCell + int 0x30 + + ## mov R10, 0x23 + ## mov R9, $textCell + ## mov R8, 2341 + ## int 0x30 - hlt + ## mov R10, 0x22 + ## mov R8, { $dpt_block + DPTStructure.ENTRIES_START + (2 * DPTStructure.ENTRY_SIZE_B) + DPTStructure.ENTRY_PART_LBL } + ## mov R9, $textCell + ## int 0x30 + + jmp $_endless_loop +_invalid_dpt_block: + push $invalid_dpt_block_str + push 1 + call $_print_error_msg +_endless_loop: + jmp $_endless_loop + hlt + + +_key_pressed: + mov ACC, [Keyboard_Registers.KEYCODE] + jne $_key_pressed_end, 0x0127 + + movb R1, [$counter] + movb [$textCell.CoordX], R1 + movb [$textCell.CoordY], 12 + movb [$textCell.Foreground], DefaultPalette.Orange + movb [$textCell.Background], DefaultPalette.Black + movb [$textCell.Character], 65 + + inc R1 + movb [$counter], R1 + + mov R10, 0x21 + mov R9, $textCell + int 0x30 + +_key_pressed_end: + ret @@ -79,5 +140,19 @@ _load_dpt_block: ## _load_dpt_block(DiskDriverData* ddd, DPTBlock* dpt_block) ret +_print_error_msg: ## _print_error_msg(string* error_msg) + arg R1 ## @Param: error_msg + ## TODO: Clear the screen + movb [$textCell.CoordX], 0 + movb [$textCell.CoordY], 0 + movb [$textCell.Foreground], DefaultPalette.Red + movb [$textCell.Background], DefaultPalette.Black + mov R10, 0x22 + mov R8, R1 + mov R9, $textCell + int 0x30 + ret + + .fixed 5120, 0xFF diff --git a/extra/dss/drake/keyboard_driver.dss b/extra/dss/drake/keyboard_driver.dss new file mode 100644 index 0000000..6caee03 --- /dev/null +++ b/extra/dss/drake/keyboard_driver.dss @@ -0,0 +1,10 @@ +@guard _KEYBOARD_DRIVER_DSS_ + +.code + +_init_keyboard: ## _init_keyboard(func_ptr* key_pressed_handler) + arg R9 ## @Param: key_pressed_handler + mov R10, 0x00 ## int 0x20 param for set_interrupt_handler + mov R8, 0xA0 ## 0xA0 is the hardware interrupt for KeyPressed + int 0x20 + ret \ No newline at end of file diff --git a/extra/info/info b/extra/info/info index 9f5c855..e0b4b4e 100644 --- a/extra/info/info +++ b/extra/info/info @@ -129,6 +129,8 @@ 0x00: Set Interrupt Handler 0x01: Clear Interrupt Handler 0x10: Disk Interface + 0x11: Disk Interface - Get disk list + 0x12: Disk Interface - Load from DDD - BLOCKING 0x30: BIOS Video Interrupt (Uses R10 register for specific functionality) 0x01: Print Char in Text Single Mode (char stored in R9 register) 0x02: New Line in Text Single Mode @@ -142,8 +144,10 @@ 0x0A: Store Null-Terminated String in buffer in Text Single Mode (string address stored in R9 register) 0x0B: Toggles inverted colors in Text Single Mode - 0x20: Read VRAM in Text16 Colors Mode (Cell address stored in R9) 0x21: Write VRAM in Text16 Colors Mode (Cell address stored in R9) + 0x22: Print String in Text16 Colors Mode (String address stored in R8, Cell address stored in R9) + 0x23: Print Integer in Text16 Colors Mode (Integer stored in R8, Cell address stored in R9) + 0x24: Clear Screen in Text16 Colors Mode (Cell address stored in R9) 0xE0: Refresh Screen 0xE1: Clear Screen diff --git a/src/assembler/Assembler.cpp b/src/assembler/Assembler.cpp index 8bed21c..b5d0664 100644 --- a/src/assembler/Assembler.cpp +++ b/src/assembler/Assembler.cpp @@ -503,16 +503,13 @@ namespace dragon { std::vector newLines; ostd::String lineEdit; - bool in_group = false; - ostd::String group_name = ""; for (auto& line : m_rawDataSection) { lineEdit = line; lineEdit.trim(); - if (!lineEdit.startsWith("$") || lineEdit.indexOf(" ") < 2) + if (!lineEdit.startsWith("$")) { - std::cout << "Invalid data entry: " << lineEdit << "\n"; - return; + continue; } ostd::String symbolName = lineEdit.new_substr(0, lineEdit.indexOf(" ")); symbolName.trim(); @@ -853,6 +850,8 @@ namespace dragon { ostd::String lineEdit(line); tSymbol symbol; + ostd::String symbolName = ""; + bool array = false; if (lineEdit.startsWith("!")) { if (lineEdit.contains(" ")) @@ -866,15 +865,52 @@ namespace dragon m_symbolTable[lineEdit] = symbol; continue; } - if (!lineEdit.startsWith("$") || lineEdit.indexOf(" ") < 2) + if (!lineEdit.startsWith("$")) { - std::cout << "Invalid data entry: " << lineEdit << "\n"; + std::cout << "Invalid data entry (name must start with $): " << line << "\n"; continue; } - ostd::String symbolName = lineEdit.new_substr(0, lineEdit.indexOf(" ")); - symbolName.trim(); - lineEdit.substr(lineEdit.indexOf(" ") + 1); - lineEdit.trim(); + if (lineEdit.contains(":") && (!lineEdit.contains("\"") || lineEdit.indexOf(":") < lineEdit.indexOf("\""))) + { + if (lineEdit.indexOf(":") < 2 || lineEdit.indexOf(":") == lineEdit.len() - 1) + { + std::cout << "Invalid array data entry: " << line << "\n"; + continue; + } + symbolName = lineEdit.new_substr(0, lineEdit.indexOf(":")).trim(); + lineEdit.substr(lineEdit.indexOf(":") + 1).trim(); + if (!lineEdit.isNumeric()) + { + std::cout << "Invalid array data entry size (must be numeric): " << line << "\n"; + continue; + } + array = true; + } + else if (lineEdit.indexOf(" ") >= 2) + { + symbolName = lineEdit.new_substr(0, lineEdit.indexOf(" ")).trim(); + lineEdit.substr(lineEdit.indexOf(" ") + 1).trim(); + } + else + { + std::cout << "Invalid data entry1: " << line << "\n"; + continue; + } + + if (array) + { + uint16_t 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++) + lineEdit.add("0x00, "); + lineEdit.trim().substr(0, lineEdit.len() - 1).trim(); + } + if (lineEdit.isNumeric()) { // union valueSplit { @@ -909,7 +945,7 @@ namespace dragon auto tokens = lineEdit.tokenize(","); if (tokens.count() < 2) { - std::cout << "Invalid data entry: " << lineEdit << "\n"; + std::cout << "Invalid data entry2: " << line << "\n"; return; } for (auto& token : tokens) @@ -929,7 +965,7 @@ namespace dragon } else { - std::cout << "Invalid data entry: " << lineEdit << "\n"; + std::cout << "Invalid data entry3: " << line << "\n"; continue; } } @@ -1176,16 +1212,21 @@ namespace dragon } else if (instEdit == "push") { + m_code.push_back(0x00); eOperandType opType = parseOperand(opEdit, word); if (opType == eOperandType::Immediate || opType == eOperandType::Label) { - m_code.push_back(data::OpCodes::PushImm); + // if (opType == eOperandType::Label) + // std::cout << ostd::Utils::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)); } else if (opType == eOperandType::Register) { - m_code.push_back(data::OpCodes::PushReg); + // m_code.push_back(data::OpCodes::PushReg); + m_code[m_code.size() - 1] = data::OpCodes::PushReg; m_code.push_back((uint8_t)word); } else @@ -2467,6 +2508,9 @@ namespace dragon if (labelAddr == 0x0000) m_labelTable[opEdit].references.push_back(m_code.size()); outOp = (int16_t)labelAddr; + // std::cout << "LABEL: " << opEdit << "\n"; + // std::cout << " : " << ostd::Utils::getHexStr(labelAddr, true, 2) << "\n"; + // std::cout << " : " << ostd::Utils::getHexStr(outOp, true, 2) << "\n"; return eOperandType::Label; } if (opEdit.startsWith("{") && opEdit.endsWith("}")) diff --git a/src/hardware/VirtualDisplay.cpp b/src/hardware/VirtualDisplay.cpp index f2b60ad..fd8cf8a 100644 --- a/src/hardware/VirtualDisplay.cpp +++ b/src/hardware/VirtualDisplay.cpp @@ -157,6 +157,16 @@ namespace dragon DragonRuntime::vGraphicsInterface.writeVRAM_16Colors(static_cast(x), static_cast(y), textCell.character, textCell.backgroundColor, textCell.foregroundColor); } + else if (signal == tSignalValues::ClearSCreen) + { + hw::interface::Graphics::tText16_Cell textCell; + + textCell.foregroundColor = mem.read8(vga_addr + tRegisters::MemControllerFGCol); + textCell.backgroundColor = mem.read8(vga_addr + tRegisters::MemControllerBGCol); + textCell.character = mem.read8(vga_addr + tRegisters::MemControllerChar); + + DragonRuntime::vGraphicsInterface.clearVRAM_16Colors(textCell.character, textCell.backgroundColor, textCell.foregroundColor); + } } else return; mem.write8(vga_addr + tRegisters::Signal, tSignalValues::Continue); diff --git a/src/hardware/VirtualIODevices.cpp b/src/hardware/VirtualIODevices.cpp index f7e18fd..f6047b5 100644 --- a/src/hardware/VirtualIODevices.cpp +++ b/src/hardware/VirtualIODevices.cpp @@ -45,13 +45,13 @@ namespace dragon int8_t VirtualBIOS::write8(uint16_t addr, int8_t value) { - data::ErrorHandler::pushError(data::ErrorCodes::BIOS_WriteAttempt, ostd::String("Attempting to write to BIOS memory map.").add(addr)); + data::ErrorHandler::pushError(data::ErrorCodes::BIOS_WriteAttempt, ostd::String("Attempting to write to BIOS memory map: ").add(ostd::Utils::getHexStr(addr, true, 2))); return 0x00; } int16_t VirtualBIOS::write16(uint16_t addr, int16_t value) { - data::ErrorHandler::pushError(data::ErrorCodes::BIOS_WriteAttempt, ostd::String("Attempting to write to BIOS memory map.").add(addr)); + data::ErrorHandler::pushError(data::ErrorCodes::BIOS_WriteAttempt, ostd::String("Attempting to write to BIOS memory map: ").add(ostd::Utils::getHexStr(addr, true, 2))); return 0x0000; } @@ -741,6 +741,20 @@ namespace dragon return true; } + bool Graphics::clearVRAM_16Colors(uint8_t character, uint8_t background, uint8_t foreground) + { + for (int32_t i = m_vramStart; i < m_vramStart + (RawTextRenderer::CONSOLE_CHARS_H * RawTextRenderer::CONSOLE_CHARS_V); i++) + { + if (!m_videoMemory.w_Byte(i + tText16_CellStructure::character, character)) + return false; //TODO: Error + if (!m_videoMemory.w_Byte(i + tText16_CellStructure::background, background)) + return false; //TODO: Error + if (!m_videoMemory.w_Byte(i + tText16_CellStructure::foreground, foreground)) + return false; //TODO: Error + } + return true; + } + diff --git a/src/hardware/VirtualIODevices.hpp b/src/hardware/VirtualIODevices.hpp index e3c0246..8cf827d 100644 --- a/src/hardware/VirtualIODevices.hpp +++ b/src/hardware/VirtualIODevices.hpp @@ -370,6 +370,7 @@ namespace dragon 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); private: ostd::serial::SerialIO m_videoMemory;