From 488b58b2d6be64403c14f7e9a9df66c900a37269 Mon Sep 17 00:00:00 2001 From: maelstrom Date: Wed, 24 Jul 2024 18:41:52 +0300 Subject: [PATCH] Starting point copied from guess-os --- README.md | 0 input_util.asm | 57 +++++++++++++++++ main.asm | 33 ++++++++++ main.bin | Bin 0 -> 512 bytes mouse_util.asm | 163 +++++++++++++++++++++++++++++++++++++++++++++++++ num_util.asm | 43 +++++++++++++ print_util.asm | 121 ++++++++++++++++++++++++++++++++++++ run.sh | 2 + 8 files changed, 419 insertions(+) create mode 100644 README.md create mode 100644 input_util.asm create mode 100644 main.asm create mode 100644 main.bin create mode 100644 mouse_util.asm create mode 100644 num_util.asm create mode 100644 print_util.asm create mode 100755 run.sh diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/input_util.asm b/input_util.asm new file mode 100644 index 0000000..03c0b6c --- /dev/null +++ b/input_util.asm @@ -0,0 +1,57 @@ +read_line: + pusha + + mov bx, read_buffer + .loop: + mov ah, 0x00 + int 0x16 ; Read char + + cmp al, 0x0D ; Is enter? + jne .enter_end + jmp .end + .enter_end: + + cmp al, 0x08 ; Is backspace? + jne .backspace_end + ; Don't do anything if we're at col == 0 + cmp bx, read_buffer + jle .backspace_end + + sub bx, 1 + mov ah, 0x0 + mov [bx], ah + + ; Erase the character on screen + mov ah, 0x0e + mov al, 0x08 ; Back one + int 0x10 + mov al, 0x20 ; Erase it + int 0x10 + mov al, 0x08 ; Back one more + int 0x10 + + jmp .loop + .backspace_end + + ; Don't add any characters if over the limit + cmp bx, read_buffer + 20 + jge .loop + + ; Add char to bx and incr + mov [bx], al + add bx, 1 + + ; Display the character + mov ah, 0x0e + int 0x10 + + jmp .loop + .end: + + mov al, 0x0 + mov [bx], al ; Null terminater + + popa + ret + +read_buffer: resb 20 diff --git a/main.asm b/main.asm new file mode 100644 index 0000000..6ccdf92 --- /dev/null +++ b/main.asm @@ -0,0 +1,33 @@ +[org 0x7c00] + +main: + ; Video mode + mov ax, 0x13 + int 0x10 + + call mouse_initialize + call mouse_enable + +lp: + cli + mov bx, [mouseX] + call print_hex + mov bx, [mouseY] + sti + + jmp lp + +jmp $ ; Halt + +; Make sure includes are done last, otherwise the first include will become main +%include "print_util.asm" +;%include "input_util.asm" +;%include "num_util.asm" +%include "mouse_util.asm" + +; Make sure data is *inside* the boot sector, or it will not be copied to the right place +; in memory. + + +times 510-($-$$) db 0 +dw 0xaa55 diff --git a/main.bin b/main.bin new file mode 100644 index 0000000000000000000000000000000000000000..41d33889810600b2dcee5f6e5e363e4693eb12b3 GIT binary patch literal 512 zcmdlX%y3rV#WIE$7a4wa%emCP@MY+hbF2OR`s3?=30>?q3?-af_|6J6A7*_0G4XK1 z4lW>P2QQESa$em1kHYV`v6)}th7DH@6AL?w0Z1EAQRj_=uX$cP`rmo@;A@T-x4<;Z zi%UTI#o7Nr`JD_5%|8W7l)oQlXei|g-psUxZ-c>Ef#}y9>!Iz;XGM!7b}&O2{Cw=Yoojcn9|8(8|9H*#GnyT!`h^GsP@DrI zzJuY=cE+=!U= 0xA, then we need to add to the alphabetical block of the ascii table + cmp al, 0x0A + jl .skip_alpha ; If the number is not at least 0xA, then skip this step + add al, 0x07 ; 'A' == 0x41, '0' == 0x30, 0x41 - 0x30 == 0x11 + ; Ignore ^^^^^^^ THIS ^^^^^^ actually. + ; It works and i've not got a clue why. Oh well. Such is life. + + .skip_alpha: + add al, 0x30 ; Add ASCII '0' + + mov ah, 0x0e + int 0x10 + + popa + ret + +print_hex: + pusha + + mov ax, bx + + shr bx, 12 + call print_hex_digit + + mov bx, ax + shr bx, 8 + call print_hex_digit + + mov bx, ax + shr bx, 4 + call print_hex_digit + + mov bx, ax + call print_hex_digit + + popa + ret + +print_bin: + pusha + + mov cx, 0 + .loop: + cmp cx, 16 + je .end + + test bx, 0x8000 + jnz .one + push bx + mov bl, 0x02 + mov ah, 0x0e + mov al, 0x30 + int 0x10 + pop bx + jmp .continue + .one: + push bx + mov bl, 0x03 + mov ah, 0x0e + mov al, 0x31 + int 0x10 + pop bx + .continue: + + shl bx, 1 + add cx, 1 + jmp .loop + .end: + + popa + ret \ No newline at end of file diff --git a/run.sh b/run.sh new file mode 100755 index 0000000..3a62e0b --- /dev/null +++ b/run.sh @@ -0,0 +1,2 @@ +nasm -f bin main.asm -o main.bin +qemu-system-x86_64 main.bin \ No newline at end of file