From 1206dddd530ee5c1be91e967089a9bf30f4f2c19 Mon Sep 17 00:00:00 2001 From: OmniaX Date: Tue, 17 Sep 2024 10:12:59 +0200 Subject: [PATCH] Started work on Drake bootmanager --- build.nr | 2 +- extra/dragon/bios.bin | Bin 4096 -> 4096 bytes extra/dragon/cmos.dr | Bin 128 -> 128 bytes extra/dragon/disk1.dr | Bin 4194304 -> 4194304 bytes extra/dss/bios/data.dss | 6 + extra/dss/bios/display.dss | 3 +- extra/dss/bios/entry.dss | 5 +- extra/dss/bios_api.dss | 15 +- extra/dss/drake/bootsector.dss | 236 ++++++++++++++++++++++-------- extra/info/info | 2 + src/hardware/VirtualDisplay.cpp | 3 + src/hardware/VirtualIODevices.cpp | 13 +- src/runtime/DragonRuntime.cpp | 5 +- src/tools/GlobalData.hpp | 2 + 14 files changed, 218 insertions(+), 74 deletions(-) diff --git a/build.nr b/build.nr index 871215b..0b2057f 100644 --- a/build.nr +++ b/build.nr @@ -1 +1 @@ -1618 +1619 diff --git a/extra/dragon/bios.bin b/extra/dragon/bios.bin index 5390afe734c1dbf189f8ac4467fa81e9c302c277..3cdc918b7792be98aaf13ed576a8879521773eb4 100644 GIT binary patch delta 513 zcmYk2ze)o^5XQf|&CbTXGv-z}L7O`xambYGG**tbG9y z8=t^VY_!lSDSQEY#ohR~*qv`?XMQuYhsj|gdgaq=u`l}%@L0aUXZZ@j@*O3n5Rz#D z#Iy{>w1P6zDyEp$p_y6;nD!7dF;b>;EHYi9#&m@xraO$7?lJDsV?8dJBo@AvNnFxa z3M(^h?1S_C++=++h3yRcP*w2TrUh?H?R>f7pZg7S1Y1h>l)j|2=8q{X(<1Gp4!KOR zENB-puhA9qI&87>v^pBAW@T8Yol(w9v?PPpz?91IBX%J&pt#ZQ-KH=5$lng6Zlk(#QlK zjjR&pm0DPdNEfc47S3!tREG-H{e=x!4gSIAziHh~)70*>>UO~iVK6*UZypc#$}8T* J%~^RveFAyBX+!`3 delta 489 zcmZ9Iu}T9$5QhJ|&CZ^CXUMI1sf0U&l88mX$}ZMMFbSryOJ^aR)7S)JVPPp8mcD?U z*l6JkSZjX)pTNpW+)X5k#WMfQ?Eme|UZfYP7zZc!;!I9n;IVvz&$5JI`H2dXf@DfS zOc@l@1_GvSEHUjsGwmZ}8X;mjMaFcEb*5W1nC?(A-D5hY$5v7?X(D_p)1;!U6jnC1 zu??5`9n&O}%W?wPMoq!*nL~I3wL4G6pY#Xj2-ZsWROV9J@XHi)rXA8DHz|=h9Rq11 zz1el?$|fN424A6~Dx3bwrShlk)m6=jfp1Af_INB{r; diff --git a/extra/dragon/cmos.dr b/extra/dragon/cmos.dr index df39cdf378285a3238c296db78f9137b81f83cf6..f12d726fe6b7993e67646a00c643d772f3f748da 100644 GIT binary patch literal 128 WcmWf4`2SzHLxdrUL6l(t03!gc#{+c$ literal 128 ScmWf4`2SzHLxf>~03!f-=>rA; diff --git a/extra/dragon/disk1.dr b/extra/dragon/disk1.dr index 2f5e452463490088287083a674aeb8c68069fa77..bf22e3c2eb89f166e56b839380a2c575b93a32f8 100644 GIT binary patch delta 526 zcmZ{fy;9py5QVRdEfMKjmaGKMy~>Y-9k3ujj>&%@q@fgC#^8!P0~A2TOgt1P58&Yy zQfDTUM@Wjig(pqglxaw=hNPfKu`@g8JG*;!JRaA^wmufFGng#9N1NSjPB=zLBb=dr zo4E7kq4s`$GeQj0q0ze1)z?!U8Ff(g>1u`aiB*0lZu{&|cbuikzPI+SP+NYXw*5?% zS(J!w)K=w1e=k#}k*S?prnXv{+LjitCvoIWJF)PMDtBTdYD4|~uTNf;>X)PCsg;cg zDr*`{^H?+rW#S6{1G^R38~LLkmi{!CVy4%WHb)+}{fmAtlyAb03tN+iJ z=E3CL%Ojgi*h{u9KbU-RN1r}>?^|ae9HK_d5OtzKxP(W{64wZy2nb0uiI8X!5fKw@ zA|b95H;6f6p0Ilqp^22ZN!%iC6L*M=$cY7_Lv)F|#3Hdo^oW93CRT`h#C_rc@sQ{f hkB9-WN<1c>5KoC`#B<^W@sfB&tP$(P>kruY@dp^faqj>C delta 363 zcmYj}yD|e|0EKsjO{^dnm+xQ1Mo1)Xalggw0m5P^wF-q4N;4wGsm-LNRh#h+3VJV~ z(Ru-FMx!`0XXbq0sn_dm^)OFG$DVJNoU6ivKVaEuXRuoH&c0p)?;^15WAoyh!1B#u znEiI&99Yd<>~!ziI}gld3-I2<{*!i6jhc6F7xJz-Dw@Czjd*B8TZV6{d%JGY9Jz_K zl})5f^}F2sa4MO9*O3+&&SS}>`$wES-^Olwn|HCd2ErC?A|l#Fhj2tx#6+iXMVE++ zZqXxpMM5M+N~A@f=obTGP=r55cw$HlixH6#qrw+iF(z_iTug|(D2Pc>6eTewrp1hy i6?392=EZ_o6iZ@RtcX>yCf3D<*c279CAJ^g`TPZGtXIMS diff --git a/extra/dss/bios/data.dss b/extra/dss/bios/data.dss index 4ee11e8..983b4ac 100644 --- a/extra/dss/bios/data.dss +++ b/extra/dss/bios/data.dss @@ -22,15 +22,21 @@ @raw_export_end @export_comment BIOS_API " --\n" +@export_comment BIOS_API " These are the addresses of CMOS data." +@raw_export_start BIOS_API @group CMOS_Settings MEM_START { MemoryAddresses.CMOS + 0x0000 } MEM_SIZE { MemoryAddresses.CMOS + 0x0002 } CLOCK_SPEED { MemoryAddresses.CMOS + 0x0004 } SCREEN_REDRAW_RATE { MemoryAddresses.CMOS + 0x0006 } + SCREEN_WIDTH { MemoryAddresses.CMOS + 0x0007 } + SCREEN_HEIGHT { MemoryAddresses.CMOS + 0x0009 } BOOT_DISK { MemoryAddresses.CMOS + 0x0010 } DISK_LIST { MemoryAddresses.CMOS + 0x007E } @end +@raw_export_end +@export_comment BIOS_API " --\n" diff --git a/extra/dss/bios/display.dss b/extra/dss/bios/display.dss index 67e8516..bb4ea41 100644 --- a/extra/dss/bios/display.dss +++ b/extra/dss/bios/display.dss @@ -27,6 +27,7 @@ _print_integer_text16: ## _print_integer_text16(int16_t number, TextCell16* cel arg R2 ## @Param: cell mov R3, R2 addip R3, 3 ## R3 is now a pointer to the X coord in the cell + movb R6, *R3 ## Save original X coord in R6 mov R1, 0 jne $_print_integer_text16_loop, 0 push 48 ## '0' ASCII is 48 @@ -46,12 +47,12 @@ _print_integer_text16_loop_end: mov R10, 0x21 ## int 0x30 param for write vram mov R9, R2 ## int 0x30 param for textCell16 int 0x30 - debug_break movb R5, *R3 ## Retrieve current X coord from cell inc R5 ## Increment X coord movb *R3, R5 ## Store new X coord in cell mov ACC, R1 jne $_print_integer_text16_loop_end, 0 + movb *R3, R6 ## Restore original X coord ret diff --git a/extra/dss/bios/entry.dss b/extra/dss/bios/entry.dss index feac823..710574b 100644 --- a/extra/dss/bios/entry.dss +++ b/extra/dss/bios/entry.dss @@ -1,5 +1,6 @@ .load 0x0000 ## BIOS is mapped to address 0x0000 in memory .entry _bios_entry_point +.fixed 4096, 0xFF ## BIOS Needs to be 4096 Bytes exactly @include @include @@ -35,6 +36,4 @@ _bios_entry_point: %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 -## ======================================================================== - -.fixed 4096, 0xFF ## BIOS Needs to be 4096 Bytes exactly +## ======================================================================== \ No newline at end of file diff --git a/extra/dss/bios_api.dss b/extra/dss/bios_api.dss index 8dbfc86..9ca0c90 100644 --- a/extra/dss/bios_api.dss +++ b/extra/dss/bios_api.dss @@ -1,5 +1,5 @@ ## -- -## -- This file is automatically generated by the DragonAssembler (version 0.4.1617) +## -- This file is automatically generated by the DragonAssembler (version 0.4.1618) ## -- Please do not modify this file in any way. ## -- @@ -15,6 +15,19 @@ @end ## -- +## These are the addresses of CMOS data. +@group CMOS_Settings + MEM_START { MemoryAddresses.CMOS + 0x0000 } + MEM_SIZE { MemoryAddresses.CMOS + 0x0002 } + CLOCK_SPEED { MemoryAddresses.CMOS + 0x0004 } + SCREEN_REDRAW_RATE { MemoryAddresses.CMOS + 0x0006 } + SCREEN_WIDTH { MemoryAddresses.CMOS + 0x0007 } + SCREEN_HEIGHT { MemoryAddresses.CMOS + 0x0009 } + BOOT_DISK { MemoryAddresses.CMOS + 0x0010 } + DISK_LIST { MemoryAddresses.CMOS + 0x007E } +@end +## -- + ## These are the Hardware Interrupt codes of this machine. @group HW_Int DISK_INTERFACE_FINISHED 0x80 diff --git a/extra/dss/drake/bootsector.dss b/extra/dss/drake/bootsector.dss index 80f7353..441fb3b 100644 --- a/extra/dss/drake/bootsector.dss +++ b/extra/dss/drake/bootsector.dss @@ -1,5 +1,6 @@ .load 0x1740 .entry _drake_bootsector_entry_point +.fixed 5120, 0xFF @include <../bios_api.dss> @include @@ -7,6 +8,7 @@ +## ========================================================================================================================= .data ## Disk data structures $ddd @@ -17,68 +19,46 @@ $current_char 65 $dpt_version_str "DPT Version " - $drake_version_str "Drake 0.1 -- " + $drake_version_str "Drake 0.2 -- " $invalid_dpt_block_str "Error: Invalid DPT Block..." +## ========================================================================================================================= + + + .code - - +## ========================================================================================================================= _drake_bootsector_entry_point: ## 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 + + ## Clear screen + push DefaultPalette.DarkBlue + push 1 + call $_clear_screen + ## Validate DPT Block mov ACC, [$dpt_block] jne $_invalid_dpt_block, 0xF1CA + + ## Print system info + push 0 + call $_print_system_info + ## Init Keyboard driver push $_key_pressed ## KeyPressed handler address passed to the _init_keyboard subroutine push 1 call $_init_keyboard - - movb [$textCell.CoordX], 0 - movb [$textCell.CoordY], 0 - movb [$textCell.Foreground], DefaultPalette.Pink - movb [$textCell.Background], DefaultPalette.Black - - mov R10, 0x22 - mov R8, $drake_version_str - mov R9, $textCell - int 0x30 - - movb [$textCell.CoordX], 13 - mov R10, 0x22 - 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 + ## @call(_clear_screen, DefaultPalette.DarkBlue) + ## @_clear_screen(DefaultPalette.DarkBlue) ## mov R10, 0x22 @@ -92,33 +72,30 @@ _invalid_dpt_block: push 1 call $_print_error_msg _endless_loop: + + ## Draw main box + push 0 + call $_print_main_box + 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 +## ========================================================================================================================= + +## ========================================================================================================================= _load_dpt_block: ## _load_dpt_block(DiskDriverData* ddd, DPTBlock* dpt_block) arg R1 ## @Param: ddd arg R2 ## @Param: dpt_block @@ -138,8 +115,116 @@ _load_dpt_block: ## _load_dpt_block(DiskDriverData* ddd, DPTBlock* dpt_block) mov R10, 0x12 ## int 0x20 parameter for load_from_ddd_blocking int 0x20 ## Bios interrupt ret - +## ========================================================================================================================= + + +## ========================================================================================================================= +_clear_screen: ## _clear_screen(int8_t color) + arg R1 + movb [$textCell.Foreground], R1 + movb [$textCell.Background], R1 + movb [$textCell.Character], 0x20 + mov R10, 0x24 + mov R9, $textCell + int 0x30 + ret +## ========================================================================================================================= + + + + +## ========================================================================================================================= +_print_main_box: + movb [$textCell.CoordX], 5 + movb [$textCell.CoordY], 2 + movb [$textCell.Foreground], DefaultPalette.Sky + movb [$textCell.Background], DefaultPalette.DarkBlue + movb [$textCell.Character], 0x3D + + mov R8, [CMOS_Settings.SCREEN_WIDTH] + subip R8, 10 + + push $textCell + push R8 + push 2 + call $_draw_horizontal_line + + movb [$textCell.CoordX], 5 + movb [$textCell.CoordY], 12 + push $textCell + push R8 + push 2 + call $_draw_horizontal_line + + movb [$textCell.CoordX], 4 + movb [$textCell.CoordY], 2 + movb [$textCell.Character], 0x7C + push $textCell + push 11 + push 2 + call $_draw_vertical_line + + addip R8, 5 + movb [$textCell.CoordX], R8 + movb [$textCell.CoordY], 2 + push $textCell + push 11 + push 2 + call $_draw_vertical_line + ret +## ========================================================================================================================= + + + + +## ========================================================================================================================= +_draw_horizontal_line: ## _draw_horizontal_line(TextCell16* cell, int8_t length) + arg R1 ## @Param: cell + arg R2 ## @Param: length + mov R3, R1 + addip R3, 3 + movb R4, *R3 + + mov R10, 0x21 + mov R9, R1 +_draw_horizontal_line_loop: + int 0x30 + movb R5, *R3 + inc R5 + movb *R3, R5 + sub R5, R4 + jgr $_draw_horizontal_line_loop, R2 + ret +## ========================================================================================================================= + + + + +## ========================================================================================================================= +_draw_vertical_line: ## _draw_line(TextCell16* cell, int8_t length) + arg R1 ## @Param: cell + arg R2 ## @Param: length + mov R3, R1 + addip R3, 4 + movb R4, *R3 + + mov R10, 0x21 + mov R9, R1 +_draw_vertical_line_loop: + int 0x30 + movb R5, *R3 + inc R5 + movb *R3, R5 + sub R5, R4 + jgr $_draw_vertical_line_loop, R2 + ret +## ========================================================================================================================= + + + + +## ========================================================================================================================= _print_error_msg: ## _print_error_msg(string* error_msg) arg R1 ## @Param: error_msg ## TODO: Clear the screen @@ -152,7 +237,40 @@ _print_error_msg: ## _print_error_msg(string* error_msg) mov R9, $textCell int 0x30 ret +## ========================================================================================================================= -.fixed 5120, 0xFF + +## ========================================================================================================================= +_print_system_info: + movb [$textCell.CoordX], 0 + movb [$textCell.CoordY], 0 + movb [$textCell.Foreground], DefaultPalette.Sky + movb [$textCell.Background], DefaultPalette.DarkBlue + mov R10, 0x22 + mov R8, $drake_version_str + mov R9, $textCell + int 0x30 + movb [$textCell.CoordX], 13 + mov R10, 0x22 + 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 + ret +## ========================================================================================================================= \ No newline at end of file diff --git a/extra/info/info b/extra/info/info index e0b4b4e..6a33bec 100644 --- a/extra/info/info +++ b/extra/info/info @@ -9,6 +9,8 @@ MemSize: (2 bytes) 0x0002 ClockSpeed: (2 bytes) 0x0004 DisplayRedrawRate: (1 bytes) 0x0006 + ScreenWidth: (2 bytes) 0x0007 + ScreenHeight: (2 bytes) 0x0009 BootDisk: 0x0010 DiskList: (2 bytes) 0x007E diff --git a/src/hardware/VirtualDisplay.cpp b/src/hardware/VirtualDisplay.cpp index fd8cf8a..975aed8 100644 --- a/src/hardware/VirtualDisplay.cpp +++ b/src/hardware/VirtualDisplay.cpp @@ -166,6 +166,9 @@ namespace dragon textCell.character = mem.read8(vga_addr + tRegisters::MemControllerChar); DragonRuntime::vGraphicsInterface.clearVRAM_16Colors(textCell.character, textCell.backgroundColor, textCell.foregroundColor); + + m_redrawScreen = true; + m_refreshScreen = true; } } else return; diff --git a/src/hardware/VirtualIODevices.cpp b/src/hardware/VirtualIODevices.cpp index f6047b5..be41ba4 100644 --- a/src/hardware/VirtualIODevices.cpp +++ b/src/hardware/VirtualIODevices.cpp @@ -700,7 +700,7 @@ namespace dragon { if (!m_videoMemory.w_Word(addr, value)) { - data::ErrorHandler::pushError(data::ErrorCodes::Graphics_MemoryWriteFailed, "Failed to word byte to Graphics Memory"); + data::ErrorHandler::pushError(data::ErrorCodes::Graphics_MemoryWriteFailed, "Failed to write word to Graphics Memory"); return 0; } return value; @@ -743,14 +743,11 @@ namespace dragon 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++) + for (int32_t i = m_vramStart; i < m_vramStart + (RawTextRenderer::CONSOLE_CHARS_H * RawTextRenderer::CONSOLE_CHARS_V) * 4; i += 4) { - 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 + m_videoMemory.w_Byte(i + tText16_CellStructure::character, character); + m_videoMemory.w_Byte(i + tText16_CellStructure::background, background); + m_videoMemory.w_Byte(i + tText16_CellStructure::foreground, foreground); } return true; } diff --git a/src/runtime/DragonRuntime.cpp b/src/runtime/DragonRuntime.cpp index 236b1c0..f7dcfd7 100644 --- a/src/runtime/DragonRuntime.cpp +++ b/src/runtime/DragonRuntime.cpp @@ -319,7 +319,9 @@ namespace dragon 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.write8(data::CMOSRegisters::ScreenRedrawRate, machine_config.screen_redraw_rate_per_second); + vCMOS.write16(data::CMOSRegisters::ScreenWidth, static_cast(RawTextRenderer::CONSOLE_CHARS_H)); + vCMOS.write16(data::CMOSRegisters::ScreenHeight, static_cast(RawTextRenderer::CONSOLE_CHARS_V)); ostd::BitField_16 disk_list_bitfield; disk_list_bitfield.value = 0; for (int32_t i = 0; i < 16; i++) @@ -333,6 +335,7 @@ namespace dragon + out.nl().nl(); s_trackMachineInfo = trackMachineInfoDiff; s_trackCallStack = trackCallStack; diff --git a/src/tools/GlobalData.hpp b/src/tools/GlobalData.hpp index 5b856bc..b3bed5b 100644 --- a/src/tools/GlobalData.hpp +++ b/src/tools/GlobalData.hpp @@ -220,6 +220,8 @@ namespace dragon 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 DiskList = 0x7E;