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 call disk_parm_init
mov dl, 0x00 mov dx, 0x7F
call disk_select mov byte [0x7F], 0x7F
mov byte [0x80], 2
call read_buffer
int3
cli cli
.halt: .halt:
@ -35,26 +39,24 @@ init:
init_program: init_program:
db "HELLO.COM", 0 db "HELLO.COM", 0
cpm_syscall: ; helper function for idle loops
cmp cl, 0 idle:
je init pushf
cmp cl, 1 sti
je console_input hlt
cmp cl, 2 popf
je console_output
cmp cl, 9
je print_string
cmp cl, 10
je read_buffer
stc
ret ret
%include "char.asm" %include "syscall.asm"
%include "con86.asm"
%include "exec.asm" %include "exec.asm"
%include "fdc.asm" %include "fdc.asm"
%include "fcb.asm" %include "fcb.asm"
%include "fcbparse.asm" %include "fcbparse.asm"
%include "disk.asm" %include "disk.asm"
%include "log2.asm" %include "log2.asm"
%include "dump.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: console_input:
xor ax, ax push dx
int 0x16 mov dl, 0xFF
; loop until we got >0 call console_io
pop dx
jz console_input.loop
test al, al test al, al
jz console_input jz console_input.loop
push ax push dx
push bx mov dl, al
jmp console_output.shortcut call console_output
console_output: pop dx
push ax
push bx
mov al, dl
.shortcut:
mov ah, 0x0e
xor bx, bx
int 0x10
pop bx
pop ax
ret 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: print_string:
push si push si
mov si, dx mov si, dx
@ -33,7 +50,12 @@ print_string:
pop si pop si
ret ret
.chain:
cmp cl, 10
jne read_buffer.chain
read_buffer: read_buffer:
push dx
push bx push bx
push si push si
xor bx, bx xor bx, bx
@ -51,8 +73,11 @@ read_buffer:
.end: .end:
mov byte [si+bx+2], 0x0D mov byte [si+bx+2], 0x0D
mov [si+1], bl mov [si+1], bl
mov dl, 0x0A
call console_output
pop si pop si
pop bx pop bx
pop dx
ret ret
.bs: .bs:
test bx, bx test bx, bx
@ -63,3 +88,7 @@ read_buffer:
call console_output call console_output
dec bx dec bx
jmp .loop jmp .loop
.chain:
stc
ret