Implement common char i/o functions
This commit is contained in:
parent
d7c1781d2f
commit
a91fb3de0d
@ -3,36 +3,35 @@
|
||||
jmp init
|
||||
|
||||
%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/char.asm"
|
||||
%include "inc/bpb.asm"
|
||||
%include "kernel/drive.asm"
|
||||
|
||||
section .text
|
||||
|
||||
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
|
||||
|
||||
mov dl, 0
|
||||
call logdrv
|
||||
mov dx, banner
|
||||
call puts
|
||||
|
||||
xor ax, ax
|
||||
xor dx, dx
|
||||
call maprd
|
||||
mov byte [testbuf], 5
|
||||
mov dx, testbuf
|
||||
call gets
|
||||
|
||||
inc word [dskbuf+0x80]
|
||||
call dirty
|
||||
call flush
|
||||
mov ax, [testbuf]
|
||||
mov cx, [testbuf+2]
|
||||
mov dx, [testbuf+4]
|
||||
mov bx, [testbuf+6]
|
||||
|
||||
int 3
|
||||
|
||||
hlt: hlt
|
||||
jmp hlt
|
||||
|
||||
section .bss
|
||||
|
||||
testbuf resb 130
|
||||
|
144
kernel/char.asm
144
kernel/char.asm
@ -1,30 +1,140 @@
|
||||
section .data
|
||||
|
||||
conbx dw 7
|
||||
|
||||
section .text
|
||||
|
||||
getc: call conin
|
||||
test al, al
|
||||
jz getc
|
||||
ret
|
||||
|
||||
putc: ; flag checking here
|
||||
conout: mov al, dl
|
||||
; raw console output
|
||||
; IN dl character
|
||||
conout mov al, dl
|
||||
mov ah, 0x0e
|
||||
xor bx, bx
|
||||
mov bx, [conbx]
|
||||
int 0x10
|
||||
ret
|
||||
|
||||
conio: cmp dl, 0xFF
|
||||
jne conout
|
||||
conin: call const
|
||||
; check if character has characters ready
|
||||
; OUT al 0xFF if data, 0 if none
|
||||
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
|
||||
jz .ret
|
||||
mov al, 0
|
||||
int 0x16
|
||||
.ret: ret
|
||||
.ret ret
|
||||
|
||||
const: mov ah, 1
|
||||
int 0x16
|
||||
jz .emp
|
||||
.rdy: mov ax, 0xFF
|
||||
; dummy: write to auxillary dev
|
||||
auxout ret
|
||||
|
||||
; dummy: read from auxillary dev
|
||||
auxin mov al, 0x1A
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user