Move in char functions

This commit is contained in:
Nero 2021-12-29 00:46:02 +00:00
parent f1c414bb26
commit 9b87b9fe66
2 changed files with 145 additions and 150 deletions

View File

@ -1,140 +0,0 @@
section .data
conbx dw 7
section .text
; raw console output
; IN dl character
conout mov al, dl
mov ah, 0x0e
mov bx, [cs:conbx]
int 0x10
ret
; 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
; dummy: write to auxillary dev
auxout ret
; dummy: read from auxillary dev
auxin mov al, 0x1A
ret
; 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

View File

@ -12,6 +12,141 @@ DRVEXT equ 0x04 ; bit 2 - EBIOS supported
DIRTY equ 0x08 ; bit 3 - dskbuf dirty DIRTY equ 0x08 ; bit 3 - dskbuf dirty
DRVCHS equ 0x10 ; bit 4 - CHS geometry known DRVCHS equ 0x10 ; bit 4 - CHS geometry known
; raw console output
; IN dl character
conout xchg ax, dx
mov ah, 0x0e
mov bx, 7
int 0x10
ret
; 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
; dummy: write to auxillary dev
auxout ret
; dummy: read from auxillary dev
auxin mov al, 0x1A
ret
; 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
align 16 align 16
; IBM Interrupt Sharing Protocol structure ; IBM Interrupt Sharing Protocol structure
i13isp jmp short int13i i13isp jmp short int13i
@ -268,18 +403,18 @@ diskio mov cl, 1 ; read len
; dx = cylinder, ax = head * spt + sector ; dx = cylinder, ax = head * spt + sector
div byte [drvspt] div byte [drvspt]
; dx = cylinder, al = head, ah = sector ; dx = cylinder, al = head, ah = sector
xchg dl, dh xchg ax, dx
ror dl, 1 xchg al, ah
ror dl, 1 ror al, 1
or dl, ah ror al, 1
inc dx or al, dh
; al: head number inc ax
; dh bit 0-7: cylinder bits 0-7 ; dl: head number
; dl bit 0-5: sector bits 0-5 ; ah bit 0-7: cylinder bits 0-7
; dl bit 6-7: cylinder bits 8-9 ; al bit 0-5: sector bits 0-5
; al bit 6-7: cylinder bits 8-9
; shuffle values around for bios ; shuffle values around for bios
xchg ax, cx xchg ax, cx
xchg cx, dx
xchg dh, dl xchg dh, dl
mov bx, dskbuf mov bx, dskbuf
.do mov dl, [biosnum] .do mov dl, [biosnum]