Implement common char i/o functions

This commit is contained in:
Nero 2021-02-19 08:57:21 +00:00
parent d7c1781d2f
commit a91fb3de0d
2 changed files with 144 additions and 35 deletions

View File

@ -3,36 +3,35 @@
jmp init jmp init
%defstr V VERSION %defstr V VERSION
banner: db "RDOS ", V, 0x0A, 0x0D, 0, 0x1A banner: db "RDOS KERNEL ", V, 0x0A, 0x0D, '$', 0x1A
%include "kernel/far.asm" %include "kernel/far.asm"
%include "kernel/char.asm"
%include "inc/bpb.asm" %include "inc/bpb.asm"
%include "kernel/drive.asm" %include "kernel/drive.asm"
section .text section .text
init: call rstseg init: call rstseg
mov si, banner
.l01: lodsb
test al, al
jz .l02
mov ah, 0x0e
xor bx, bx
int 0x10
jmp .l01
.l02:
call dinit call dinit
mov dl, 0 mov dx, banner
call logdrv call puts
xor ax, ax mov byte [testbuf], 5
xor dx, dx mov dx, testbuf
call maprd call gets
inc word [dskbuf+0x80] mov ax, [testbuf]
call dirty mov cx, [testbuf+2]
call flush mov dx, [testbuf+4]
mov bx, [testbuf+6]
int 3
hlt: hlt hlt: hlt
jmp hlt jmp hlt
section .bss
testbuf resb 130

View File

@ -1,30 +1,140 @@
section .data
conbx dw 7
section .text section .text
getc: call conin ; raw console output
test al, al ; IN dl character
jz getc conout mov al, dl
ret
putc: ; flag checking here
conout: mov al, dl
mov ah, 0x0e mov ah, 0x0e
xor bx, bx mov bx, [conbx]
int 0x10 int 0x10
ret ret
conio: cmp dl, 0xFF ; check if character has characters ready
jne conout ; OUT al 0xFF if data, 0 if none
conin: call const const mov ah, 1
int 0x16
jz .emp
mov ax, 0xFF
ret
.emp mov al, 0
ret
; read character from console
; OUT al character or zero
conin call const
test al, al test al, al
jz .ret jz .ret
mov al, 0 mov al, 0
int 0x16 int 0x16
.ret: ret .ret ret
const: mov ah, 1 ; dummy: write to auxillary dev
int 0x16 auxout ret
jz .emp
.rdy: mov ax, 0xFF ; dummy: read from auxillary dev
auxin mov al, 0x1A
ret ret
.emp: mov al, 0
; dummy: lister out
lstout ret
; character input with echo
; OUT al character
getc call const
test al, al
jz getc
call conin
push ax
mov dl, al
call putc
pop ax
ret
; character input without echo
readc call const
test al, al
jz readc
jmp conin
; character output
; IN dl character
putc jmp conout
; direct console I/O
; IN dl character to output or 0xFF if input
; OUT al character to read
dcon cmp dl, 0xFF
je conin
jmp conout
; output character string
; IN ds:dx far ptr to string, '$'-terminated
puts push si
mov si, dx
.loop lodsb
cmp al, '$'
je .ret
mov dl, al
call putc
jmp .loop
.ret pop si
ret
; send a beep ctl to console
beep mov dl, 0x07
jmp conout
; buffered input
; IN ds:dx far ptr to buffer
gets mov si, dx
mov cx, [si]
mov ch, 0
; ch = actual number of chars
; cl = maximum number of chars
.loop call readc
cmp al, 0x0D
je .cr
cmp al, 0x08
je .bs
cmp al, 0x20
jc .loop
; check if there is space in the buffer
; emit a beep if not
mov dl, cl
dec dl
cmp ch, dl
jc .append
call beep
jmp .loop
; append to buffer
.append mov bh, 0
mov bl, ch
mov [si+2+bx], al
inc ch
mov dl, al
call putc
jmp .loop
; handle backspace
.bs: test ch, ch
jz .loop
mov dl, 0x08
call putc
mov dl, 0x20
call putc
mov dl, 0x08
call putc
dec ch
jmp .loop
; handle carriage return
.cr mov bx, 0
mov bl, ch
mov [si+2+bx], al
mov [si], cx
mov dl, 0x0A
call putc
mov dl, 0x0D
call putc
ret ret