Store and update mouse location

This commit is contained in:
Juhani Krekelä 2023-02-06 17:15:47 +02:00
parent 42932c472f
commit dc0ddf3ab9
1 changed files with 85 additions and 51 deletions

View File

@ -18,6 +18,12 @@ start:
sti
; Clear BSS
mov di, _bss_start
mov cx, _bss_end - _bss_start
xor al, al
rep stosb
initialize_mouse:
; Initialize mouse
; https://www.ctyme.com/intr/rb-1601.htm
@ -58,73 +64,92 @@ hang:
;int 0x10
jmp hang
Y_OVERFLOW equ 0x80
X_OVERFLOW equ 0x40
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
mouse_handler:
push ax
push bx
push bp
push ds
mov ax, cs
mov ds, ax
mov bp, sp
; status
mov bx, [bp+16]
mov bx, [bp+18] ; status
; X negative
test bl, 0x10
jz .no_x_negative
mov ax, 0x0e00 + '-'
int 0x10
.no_x_negative:
test bl, X_OVERFLOW
jnz .x_end
.x:
mov ax, [bp+16] ; X
; X overflow
test bl, 0x40
jz .no_x_overflow
mov ax, 0x0e00 + 'o'
.no_x_overflow:
test bl, X_NEGATIVE
jnz .x_negative
.x_nonnegative:
add [mouse_x], ax
cmp word [mouse_x], X_MAX_VALUE
jb .x_end
mov word [mouse_x], X_MAX_VALUE
jmp .x_end
; X
mov ax, [bp+14]
call hexprint8
mov ax, 0x0e00 + ' '
int 0x10
.x_negative:
neg al
sub [mouse_x], ax
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
; Y negative
test bl, 0x20
jz .no_y_negative
mov ax, 0x0e00 + '-'
int 0x10
.no_y_negative:
test bl, Y_OVERFLOW
jnz .y_end
.y:
mov ax, [bp+14] ; Y
; Y overflow
test bl, 0x80
jz .no_y_overflow
mov ax, 0x0e00 + 'o'
.no_y_overflow:
test bl, Y_NEGATIVE
jnz .y_negative
.y_nonnegative:
; Y-axis is inverted
sub [mouse_y], ax
jnc .y_end
mov word [mouse_y], 0
jmp .y_end
; Y
mov ax, [bp+12]
call hexprint8
mov ax, 0x0e00 + ' '
int 0x10
.y_negative:
neg al
add [mouse_y], ax
cmp word [mouse_y], Y_MAX_VALUE
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
; Left mouse
test bl, 0x01
jz .no_lmb
mov ax, 0x0e00 + 'L'
int 0x10
.no_lmb:
and bl, BUTTONS
mov [mouse_buttons], bl
; Right mouse
test bl, 0x02
jz .no_rmb
mov ax, 0x0e00 + 'R'
int 0x10
.no_rmb
mov ax, 0x0e00 + 13
int 0x10
mov ax, 0x0e00 + 10
int 0x10
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
pop ax
@ -162,3 +187,12 @@ hexprint4:
times 510-($-$$) db 0
db 0x55
db 0xaa
section .bss
_bss_start:
mouse_x resw 1
mouse_y resw 1
mouse_buttons resb 1
_bss_end: