diff --git a/build.sh b/build.sh index 663e049..4ecfd5f 100644 --- a/build.sh +++ b/build.sh @@ -20,7 +20,7 @@ nasm -fbin src/fs/edit.asm -o build/edit.bin cat build/calc.bin build/edit.bin > build/files.bin # Final binary -cat build/bootloader.bin build/kernel.bin build/files.bin > build/os.bin +cat build/bootloader.bin build/kernel.bin build/files.bin > build/kern.bin # Run QEMU -qemu-system-x86_64 -drive format=raw,file="./build/os.bin",index=0,media=disk -m 256M +qemu-system-x86_64 -drive format=raw,file="./build/kern.bin",index=0,media=disk -m 256M diff --git a/src/filetable.asm b/src/filetable.asm index 6bad737..f53c21c 100644 --- a/src/filetable.asm +++ b/src/filetable.asm @@ -17,6 +17,6 @@ filetable: db 'filetable',0, 'txt',0,2,1 ; filetable.txt - start: 2, size: 1 db 'kernel',0,0,0,0, 'bin',0,3,3 ; kernel.bin - start: 3, size: 3 db 'calc',0,0,0,0,0,0, 'bin',0,6,1 ; calc.bin - start: 6, size: 1 - db 'edit',0,0,0,0,0,0, 'bin',0,7,1 ; edit.bin - start: 6, size: 1 + db 'edit',0,0,0,0,0,0, 'bin',0,7,2 ; edit.bin - start: 6, size: 2 times 512-($-$$) db 0 diff --git a/src/fs/edit.asm b/src/fs/edit.asm index e69de29..025e0e9 100644 --- a/src/fs/edit.asm +++ b/src/fs/edit.asm @@ -0,0 +1,101 @@ +[bits 16] + +launch: + call resetTextMode + mov si, headerMsg + call print + xor cx, cx + mov di, hexCode + +getHexCh: + xor ax, ax + int 0x16 + cmp al, '$' ; Check for end of input (Denoted by a "$") + je .runInput + cmp al, '!' ; End editor, Exit back to kernel + je return + cmp al, 0x08 ; Backspace + je .backspace + + xor ah, ah + call asciiToHex ; Get the hex digit into bx + + cmp ax, 15 ; Check if it's a hex character + jg getHexCh ; If not, ignore it + + inc cx + cmp cx, 2 ; Check if we've gotten a whole byte (2 hex digits/nibbles) + je .putByte + mov [hexByte], al + jmp getHexCh +.putByte: + cmp di, hexCode+256 + jge getHexCh ; Max length reached + rol byte [hexByte], 4 + or byte [hexByte], al + mov al, [hexByte] + mov [di], al + mov dx, [hexByte] + call printHexByte + inc di + xor cx, cx + mov al, ' ' + mov ah, 0x0e + int 0x10 + jmp getHexCh +.backspace: + mov byte [hexByte], 0 + xor cx, cx + cmp di, hexByte ; Check if there's anything to delete + je getHexCh ; If not, ignore + mov byte [di], 0 + dec di + mov si, backChars + call print + jmp getHexCh +.runInput: + mov si, runMsg + call print + call hexBegin ; Call the code + jmp launch + +; Expects al to contain an ASCII character, will set bx to it's hex equivalent +asciiToHex: + cmp al, '9' + jle .getHex + sub al, 7 +.getHex: + sub al, '0' + ret + +return: + mov ax, 0x2000 + mov ds, ax + mov es, ax + mov fs, ax + mov gs, ax + mov ss, ax + + jmp 0x2000:0x0000 + +; - Includes - +%include "./src/lib/screen.asm" +%include "./src/lib/print.asm" +; ------------ + +headerMsg: db " - EDITOR - ", ENDL, \ + "Type '$' to run your code or '!' to exit", ENDL, ENDL, 0 +runMsg: db ENDL, " -- Executing -- ", ENDL, ENDL, 0 + +backChars: db 8, 8, 8, ' ', 8, 8, 0 + +hexByte: db 0 + +hexBegin: ; The label we jump to + pusha +hexCode: times 256 db 0 ; Code buffer (user input code) +hexEnd: + popa + ret + +times 2*512-($-$$) db 0 diff --git a/temp.bin b/temp.bin deleted file mode 100644 index e69de29..0000000 diff --git a/test/test b/test/test new file mode 100644 index 0000000..be55df0 --- /dev/null +++ b/test/test @@ -0,0 +1 @@ +¸AÍ1ÀÍÃ \ No newline at end of file diff --git a/test/test.asm b/test/test.asm new file mode 100644 index 0000000..7d10127 --- /dev/null +++ b/test/test.asm @@ -0,0 +1,5 @@ +mov ax, 0x0e41 +int 0x10 +xor ax, ax +int 0x16 +ret \ No newline at end of file