Move out console interfacing into separate file

This commit is contained in:
Nero 2019-10-20 19:11:44 +00:00
parent e86b1ba004
commit f3a6ae338f
3 changed files with 119 additions and 32 deletions

56
kernel/con86.asm Normal file
View File

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

View File

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

View File

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