Fixed a bunch of bugs in mouse_handler; memoized mouse_column in main loop

This commit is contained in:
shikhin 2023-03-19 19:00:21 +05:30
parent 5c3580e9b5
commit e900a60d4a
1 changed files with 24 additions and 23 deletions

View File

@ -93,16 +93,18 @@ draw:
pop es pop es
call draw_wallpaper call draw_wallpaper
mov di, mouse_column
call flip_mouse_cursor call flip_mouse_cursor
mainloop: mainloop:
mov bx, [mouse_x] mov bx, [di - mouse_column + mouse_x]
shr bx, 1 shr bx, 1
mov cx, [mouse_y] mov cx, [di - mouse_column + mouse_y]
shr cx, 2 shr cx, 2
cmp [mouse_column], bl cmp [di], bl
jne .update_cursor jne .update_cursor
cmp [mouse_row], cl cmp [di - mouse_column + mouse_row], cl
jne .update_cursor jne .update_cursor
hlt hlt
@ -110,8 +112,8 @@ mainloop:
.update_cursor: .update_cursor:
call flip_mouse_cursor call flip_mouse_cursor
mov [mouse_column], bl mov [di], bl
mov [mouse_row], cl mov [di - mouse_column + mouse_row], cl
call flip_mouse_cursor call flip_mouse_cursor
jmp mainloop jmp mainloop
@ -183,6 +185,7 @@ draw_wallpaper:
ret ret
; requires: ; requires:
; di = mouse_column
; ds = 0 ; ds = 0
; es = 0xb800 ; es = 0xb800
flip_mouse_cursor: flip_mouse_cursor:
@ -190,11 +193,11 @@ flip_mouse_cursor:
; Column ; Column
xor bh, bh xor bh, bh
mov bl, [mouse_column] mov bl, [di]
shl bx, 1 shl bx, 1
; Row ; Row
mov al, [mouse_row] mov al, [di - mouse_column + mouse_row]
mov cl, COLUMNS*2 mov cl, COLUMNS*2
mul cl mul cl
add bx, ax add bx, ax
@ -377,10 +380,9 @@ Y_MAX_VALUE equ 4*ROWS-1
; cl = negative bit # in ah ; cl = negative bit # in ah
; dx = MAX_VALUE ; dx = MAX_VALUE
; out ; out
; mouse_x/mouse_y updated appropriately ; [mouse_x]/[mouse_y] updated appropriately
; si = updated [mouse_x]/[mouse_y] ; si = updated [mouse_x]/[mouse_y]
; di = di + 1 ; clobbers ax
; clobbers ah
xy_handler: xy_handler:
; X and Y coördinates are stored as 9-bit signed integers ; X and Y coördinates are stored as 9-bit signed integers
; using two's complement notation. The high bits are called ; using two's complement notation. The high bits are called
@ -408,7 +410,6 @@ xy_handler:
.not_overflow: .not_overflow:
mov [cs:di], si mov [cs:di], si
inc di
ret ret
mouse_handler: mouse_handler:
@ -418,32 +419,32 @@ mouse_handler:
mov bx, [bp+2*8+10] ; status mov bx, [bp+2*8+10] ; status
xor si, si
mov di, mouse_x
mov dx, X_MAX_VALUE
test bl, X_OVERFLOW test bl, X_OVERFLOW
jnz .x_end jnz .x_end
.x: .x:
.x_end:
xor si, si
mov di, mouse_x
mov ax, [bp+2*8+8] mov ax, [bp+2*8+8]
mov cl, 3 mov cl, 3
mov dx, X_MAX_VALUE
call xy_handler call xy_handler
.x_end:
inc di
inc di ; mouse_y
test bl, Y_OVERFLOW test bl, Y_OVERFLOW
jnz .y_end jnz .y_end
.y: .y:
inc si ; won't be zero inc si ; will be non-zero
inc di ; mouse_y
mov ax, [bp+2*8+6] mov ax, [bp+2*8+6]
mov cl, 2 mov cl, 2
;mov dx ;mov dx
mov dl, Y_MAX_VALUE mov dl, Y_MAX_VALUE
call xy_handler call xy_handler
.y_end: .y_end:
and bl, BUTTONS and bl, BUTTONS
mov [cs:di], bl ; mouse_buttons mov [cs:di - mouse_y + mouse_buttons], bl
popa popa
retf retf
@ -467,8 +468,8 @@ section .bss
_bss_start: _bss_start:
mouse_x resw 1 mouse_x resw 1
mouse_y resw 1 ; mouse_x + 2 mouse_y resw 1 ; mouse_x + 2, do not touch
mouse_buttons resb 1 ; mouse_y + 1 mouse_buttons resb 1
mouse_column resb 1 mouse_column resb 1
mouse_row resb 1 mouse_row resb 1