Draw mouse cursor

This commit is contained in:
Juhani Krekelä 2023-02-06 17:45:26 +02:00
parent dc0ddf3ab9
commit 0692c75eab
1 changed files with 86 additions and 24 deletions

View File

@ -3,6 +3,9 @@ bits 16
org 0x7c00
COLUMNS equ 80
ROWS equ 25
jmp 0:start
start:
cld
@ -47,7 +50,7 @@ initialize_mouse:
int 0x15
jc .error
jmp mainloop
jmp .done
.error:
; https://www.ctyme.com/intr/rb-1601.htm
@ -55,14 +58,87 @@ initialize_mouse:
int 0x15
jmp initialize_mouse
mainloop:
; TODO: everything
.done:
initialize_screen:
mov ax, 0xb800 ; VGA text video memory
mov es, ax
; Clear screen with asterisks and 15-0 background-foreground
mov ax, 0xf000 + '*'
mov cx, 25*80
xor di, di
rep stosw
; Disable text cursor
mov dx, 0x3d4
mov al, 0xa
out dx, al
inc dx
mov al, 0x20
out dx, al
xor ax, ax
call flip_mouse_cursor
mainloop:
mov bx, [mouse_x]
mov cx, [mouse_y]
cmp [mouse_x_old], bx
jne .update_cursor
cmp [mouse_y_old], cx
jne .update_cursor
hang:
hlt
;mov ax, 0x0e00 + '.'
;int 0x10
jmp hang
jmp mainloop
.update_cursor:
mov ah, [mouse_x_old]
mov al, [mouse_y_old]
call flip_mouse_cursor
mov ah, [mouse_x]
mov al, [mouse_y]
call flip_mouse_cursor
mov [mouse_x_old], bx
mov [mouse_y_old], cx
jmp mainloop
; in:
; ah = column
; al = row
flip_mouse_cursor:
push ax
push bx
push cx
push es
mov bx, 0xb800
mov es, bx
; Column
xor bh, bh
mov bl, ah
shl bx, 1
; Row
mov cl, COLUMNS*2
mul cl
add bx, ax
; Swap foreground and background colours
inc bx
mov al, [es:bx]
mov cl, 4
ror al, cl
mov [es:bx], al
pop es
pop cx
pop bx
pop ax
ret
Y_OVERFLOW equ 0x80
X_OVERFLOW equ 0x40
@ -70,8 +146,6 @@ Y_NEGATIVE equ 0x20
X_NEGATIVE equ 0x10
BUTTONS equ 0x03
COLUMNS equ 80
ROWS equ 25
X_MAX_VALUE equ COLUMNS-1
Y_MAX_VALUE equ ROWS-1
@ -108,10 +182,6 @@ mouse_handler:
jnc .x_end
mov word [mouse_x], 0
.x_end:
mov ax, [mouse_x];debg
call hexprint16;debg
mov ax, 0x0e00 + ' ';debg
int 0x10;debg
test bl, Y_OVERFLOW
jnz .y_end
@ -134,21 +204,10 @@ mouse_handler:
jb .y_end
mov word [mouse_y], Y_MAX_VALUE
.y_end
mov ax, [mouse_y];debg
call hexprint16;debg
mov ax, 0x0e00 + ' ';debg
int 0x10;debg
and bl, BUTTONS
mov [mouse_buttons], bl
mov al, [mouse_buttons];debg
call hexprint8;debg
mov ax, 0x0e00 + 13;debg
int 0x10;debg
mov ax, 0x0e00 + 10;debg
int 0x10;debg
pop ds
pop bp
pop bx
@ -195,4 +254,7 @@ mouse_x resw 1
mouse_y resw 1
mouse_buttons resb 1
mouse_x_old resw 1
mouse_y_old resw 1
_bss_end: