diff --git a/kernel/con86.asm b/kernel/con86.asm new file mode 100644 index 0000000..1da3f8b --- /dev/null +++ b/kernel/con86.asm @@ -0,0 +1,56 @@ +console_hide_cursor: + push ax + push cx + mov ah, 1 + mov cx, 0x1F1F + int 0x10 + pop cx + pop ax + ret + +console_show_cursor: + push ax + push cx + mov ah, 1 + mov cx, 0x001F + int 0x10 + pop cx + pop ax + ret + +; Raw console i/o without echo +; IN DL character to output or FF +; OUT ZF if DL=FF: zero if character input +; AL if not ZF: ascii char, otherwise corrupt +console_io: + cmp dl, 0xFF + je .read + push ax + push bx + mov al, dl + mov ah, 0x0e + xor bx, bx + int 0x10 + pop bx + pop ax + ret +.read: + call console_show_cursor + + ; if no character avail, exit with leaving + ; cursor displayed + mov ah, 1 + int 0x16 + jz .end + pushf + + ; actually read character + xor ax, ax + int 0x16 + + call console_hide_cursor + + ; restore zero flag + popf +.end: + ret diff --git a/kernel/main.asm b/kernel/main.asm index 0abe31e..eaac4cc 100644 --- a/kernel/main.asm +++ b/kernel/main.asm @@ -24,8 +24,12 @@ init: call disk_parm_init - mov dl, 0x00 - call disk_select + mov dx, 0x7F + mov byte [0x7F], 0x7F + mov byte [0x80], 2 + call read_buffer + + int3 cli .halt: @@ -35,26 +39,24 @@ init: init_program: db "HELLO.COM", 0 -cpm_syscall: - cmp cl, 0 - je init - cmp cl, 1 - je console_input - cmp cl, 2 - je console_output - cmp cl, 9 - je print_string - cmp cl, 10 - je read_buffer - stc +; helper function for idle loops +idle: + pushf + sti + hlt + popf ret -%include "char.asm" +%include "syscall.asm" + +%include "con86.asm" %include "exec.asm" %include "fdc.asm" %include "fcb.asm" %include "fcbparse.asm" + %include "disk.asm" + %include "log2.asm" %include "dump.asm" diff --git a/kernel/char.asm b/kernel/syscall.asm similarity index 52% rename from kernel/char.asm rename to kernel/syscall.asm index 0e7d269..27327c8 100644 --- a/kernel/char.asm +++ b/kernel/syscall.asm @@ -1,24 +1,41 @@ +cpm_syscall: + cmp cl, 0 + je init + + cmp cl, 1 + jne console_input.chain + +console_input.loop: + call idle console_input: - xor ax, ax - int 0x16 - ; loop until we got >0 + push dx + mov dl, 0xFF + call console_io + pop dx + jz console_input.loop test al, al - jz console_input - push ax - push bx - jmp console_output.shortcut -console_output: - push ax - push bx - mov al, dl -.shortcut: - mov ah, 0x0e - xor bx, bx - int 0x10 - pop bx - pop ax + jz console_input.loop + push dx + mov dl, al + call console_output + pop dx ret +.chain: + cmp cl, 2 + jne console_output.chain + +console_output: + cmp dl, 0xFF + je .end + call console_io +.end: + ret + +.chain: + cmp cl, 9 + jne print_string.chain + print_string: push si mov si, dx @@ -33,7 +50,12 @@ print_string: pop si ret +.chain: + cmp cl, 10 + jne read_buffer.chain + read_buffer: + push dx push bx push si xor bx, bx @@ -51,8 +73,11 @@ read_buffer: .end: mov byte [si+bx+2], 0x0D mov [si+1], bl + mov dl, 0x0A + call console_output pop si pop bx + pop dx ret .bs: test bx, bx @@ -63,3 +88,7 @@ read_buffer: call console_output dec bx jmp .loop + +.chain: + stc + ret