59 lines
1.5 KiB
NASM
59 lines
1.5 KiB
NASM
|
|
[BITS 16]
|
||
|
|
|
||
|
|
global _print_char
|
||
|
|
global _get_char
|
||
|
|
global _check_key
|
||
|
|
global _set_cursor
|
||
|
|
global _get_cursor_pos
|
||
|
|
global _set_cursor_pos
|
||
|
|
segment _TEXT class=CODE
|
||
|
|
|
||
|
|
_print_char:
|
||
|
|
push bp
|
||
|
|
mov bp, sp
|
||
|
|
mov ah, 0x0E ; BIOS TTY write
|
||
|
|
mov al, [bp+4] ; first arg: char c
|
||
|
|
xor bh, bh ; page 0
|
||
|
|
int 0x10
|
||
|
|
pop bp
|
||
|
|
ret
|
||
|
|
_get_char:
|
||
|
|
; Returns: AL = ASCII char, AH = scancode
|
||
|
|
; Blocks until a key is pressed
|
||
|
|
xor ah, ah ; Function 0: wait for keypress
|
||
|
|
int 0x16
|
||
|
|
xor ah, ah
|
||
|
|
ret
|
||
|
|
|
||
|
|
_check_key:
|
||
|
|
; Non-blocking: returns ZF=1 if no key waiting
|
||
|
|
mov ah, 0x01 ; Function 1: check buffer
|
||
|
|
int 0x16
|
||
|
|
jz .empty
|
||
|
|
mov ax, 1
|
||
|
|
ret ; ZF=0 means key available, AL/AH = key
|
||
|
|
.empty:
|
||
|
|
xor ax, ax
|
||
|
|
ret
|
||
|
|
_set_cursor:
|
||
|
|
mov ah, 0x01
|
||
|
|
mov cx, 0x0607
|
||
|
|
ret
|
||
|
|
_get_cursor_pos:
|
||
|
|
mov ah, 0x03
|
||
|
|
xor bh, bh
|
||
|
|
int 0x10 ; DH = row, DL = col
|
||
|
|
mov ax, dx ; DH->AH, DL->AL in one shot
|
||
|
|
ret
|
||
|
|
|
||
|
|
_set_cursor_pos:
|
||
|
|
push bp
|
||
|
|
mov bp, sp
|
||
|
|
mov ah, 0x02 ; AH=02h: set cursor position
|
||
|
|
xor bh, bh ; page 0
|
||
|
|
mov dh, [bp+4] ; row
|
||
|
|
mov dl, [bp+6] ; col
|
||
|
|
int 0x10
|
||
|
|
pop bp
|
||
|
|
ret
|