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