From 7ba68e13f7d89454803599ce3ab8f6502cc2bc1f Mon Sep 17 00:00:00 2001 From: Ain <41307858+nero@users.noreply.github.com> Date: Tue, 8 Oct 2019 19:53:41 +0000 Subject: [PATCH] Implement CP/M basic char io --- kernel/char.asm | 65 +++++++++++++++++++++++++++++++++++++++++++++++++ kernel/fcb.asm | 1 - kernel/main.asm | 49 +++++++++++++++---------------------- 3 files changed, 85 insertions(+), 30 deletions(-) create mode 100644 kernel/char.asm diff --git a/kernel/char.asm b/kernel/char.asm new file mode 100644 index 0000000..0e7d269 --- /dev/null +++ b/kernel/char.asm @@ -0,0 +1,65 @@ +console_input: + xor ax, ax + int 0x16 + ; loop until we got >0 + 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 + ret + +print_string: + push si + mov si, dx +.loop: + mov dl, BYTE [si] + cmp dl, '$' + jz .end + call console_output + inc si + jmp .loop +.end: + pop si + ret + +read_buffer: + push bx + push si + xor bx, bx + mov si, dx +.loop: + call console_input + cmp al, 0x0D + je .end + cmp al, 8 + je .bs + mov [si+bx+2], al + inc bx + cmp bl, [si] + jc .loop +.end: + mov byte [si+bx+2], 0x0D + mov [si+1], bl + pop si + pop bx + ret +.bs: + test bx, bx + jz .loop + mov dl, 0x20 + call console_output + mov dl, 8 + call console_output + dec bx + jmp .loop diff --git a/kernel/fcb.asm b/kernel/fcb.asm index ddc6185..b17064d 100644 --- a/kernel/fcb.asm +++ b/kernel/fcb.asm @@ -24,7 +24,6 @@ fcb_open_rootdir: cmp byte [bx], 0 jne .drivedone mov al, default_drive - inc al mov [bx], al .drivedone: mov dl, [bx] diff --git a/kernel/main.asm b/kernel/main.asm index 648c02c..83a0e6c 100644 --- a/kernel/main.asm +++ b/kernel/main.asm @@ -19,28 +19,20 @@ org self jmp init banner: - db "RDOS 2019-09", 0x0A, 0x0D, 0 - -print_banner: - mov cl, 2 - mov si, banner -.loop: - mov dl, BYTE [si] - test dl, dl - jz .end - call cpm_syscall - inc si - jmp .loop -.end: - ret + db "RDOS 2019-09", 0x0A, 0x0D, '$', 0 init: mov sp, stack + mov default_drive, 0x01 - call print_banner + mov dx, banner + call print_string - mov si, init_program - call exec + mov dx, 0x79 + mov byte [0x79], 0x7F + call read_buffer + mov ax, [0x79] + int3 cli .halt: @@ -51,21 +43,20 @@ init_program: db "HELLO.COM", 0 cpm_syscall: - cmp cl, 0x02 - je putc + 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 ret -putc: - push ax - push bx - mov al, dl - mov ah, 0x0e - mov bx, 0x0000 - int 0x10 - pop bx - pop ax - ret +%include "char.asm" %include "exec.asm" %include "fcb.asm"