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
jne .drivedone
mov al, default_drive
inc al
mov [bx], al
.drivedone:
mov dl, [bx]

View File

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