Implement CP/M basic char io

This commit is contained in:
Nero 2019-10-08 19:53:41 +00:00
parent 7877809bc1
commit 7ba68e13f7
3 changed files with 85 additions and 30 deletions

65
kernel/char.asm Normal file
View File

@ -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

View File

@ -24,7 +24,6 @@ fcb_open_rootdir:
cmp byte [bx], 0 cmp byte [bx], 0
jne .drivedone jne .drivedone
mov al, default_drive mov al, default_drive
inc al
mov [bx], al mov [bx], al
.drivedone: .drivedone:
mov dl, [bx] mov dl, [bx]

View File

@ -19,28 +19,20 @@ org self
jmp init jmp init
banner: banner:
db "RDOS 2019-09", 0x0A, 0x0D, 0 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
init: init:
mov sp, stack mov sp, stack
mov default_drive, 0x01
call print_banner mov dx, banner
call print_string
mov si, init_program mov dx, 0x79
call exec mov byte [0x79], 0x7F
call read_buffer
mov ax, [0x79]
int3
cli cli
.halt: .halt:
@ -51,21 +43,20 @@ init_program:
db "HELLO.COM", 0 db "HELLO.COM", 0
cpm_syscall: cpm_syscall:
cmp cl, 0x02 cmp cl, 0
je putc 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 stc
ret ret
putc: %include "char.asm"
push ax
push bx
mov al, dl
mov ah, 0x0e
mov bx, 0x0000
int 0x10
pop bx
pop ax
ret
%include "exec.asm" %include "exec.asm"
%include "fcb.asm" %include "fcb.asm"