rdos/kernel/char.asm

141 lines
1.9 KiB
NASM
Raw Permalink Normal View History

2021-02-19 09:57:21 +01:00
section .data
2021-02-19 09:57:21 +01:00
conbx dw 7
2021-02-19 09:57:21 +01:00
section .text
; raw console output
; IN dl character
conout mov al, dl
mov ah, 0x0e
2021-02-19 20:41:24 +01:00
mov bx, [cs:conbx]
int 0x10
ret
2021-02-19 09:57:21 +01:00
; 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
2021-02-19 09:57:21 +01:00
.ret ret
2021-02-19 09:57:21 +01:00
; dummy: write to auxillary dev
auxout ret
; dummy: read from auxillary dev
auxin mov al, 0x1A
ret
2021-02-19 09:57:21 +01:00
; 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