From e900a60d4a51d56b14c44e77f7d284aabb3b4715 Mon Sep 17 00:00:00 2001 From: shikhin Date: Sun, 19 Mar 2023 19:00:21 +0530 Subject: [PATCH] Fixed a bunch of bugs in mouse_handler; memoized mouse_column in main loop --- ponydos.asm | 47 ++++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/ponydos.asm b/ponydos.asm index efd1a9f..b69d7dc 100644 --- a/ponydos.asm +++ b/ponydos.asm @@ -93,16 +93,18 @@ draw: pop es call draw_wallpaper + + mov di, mouse_column call flip_mouse_cursor mainloop: - mov bx, [mouse_x] + mov bx, [di - mouse_column + mouse_x] shr bx, 1 - mov cx, [mouse_y] + mov cx, [di - mouse_column + mouse_y] shr cx, 2 - cmp [mouse_column], bl + cmp [di], bl jne .update_cursor - cmp [mouse_row], cl + cmp [di - mouse_column + mouse_row], cl jne .update_cursor hlt @@ -110,8 +112,8 @@ mainloop: .update_cursor: call flip_mouse_cursor - mov [mouse_column], bl - mov [mouse_row], cl + mov [di], bl + mov [di - mouse_column + mouse_row], cl call flip_mouse_cursor jmp mainloop @@ -183,6 +185,7 @@ draw_wallpaper: ret ; requires: +; di = mouse_column ; ds = 0 ; es = 0xb800 flip_mouse_cursor: @@ -190,11 +193,11 @@ flip_mouse_cursor: ; Column xor bh, bh - mov bl, [mouse_column] + mov bl, [di] shl bx, 1 ; Row - mov al, [mouse_row] + mov al, [di - mouse_column + mouse_row] mov cl, COLUMNS*2 mul cl add bx, ax @@ -377,10 +380,9 @@ Y_MAX_VALUE equ 4*ROWS-1 ; cl = negative bit # in ah ; dx = MAX_VALUE ; out -; mouse_x/mouse_y updated appropriately +; [mouse_x]/[mouse_y] updated appropriately ; si = updated [mouse_x]/[mouse_y] -; di = di + 1 -; clobbers ah +; clobbers ax xy_handler: ; X and Y coördinates are stored as 9-bit signed integers ; using two's complement notation. The high bits are called @@ -408,7 +410,6 @@ xy_handler: .not_overflow: mov [cs:di], si - inc di ret mouse_handler: @@ -418,32 +419,32 @@ mouse_handler: mov bx, [bp+2*8+10] ; status + xor si, si + mov di, mouse_x + mov dx, X_MAX_VALUE + test bl, X_OVERFLOW jnz .x_end .x: - - .x_end: - xor si, si - mov di, mouse_x mov ax, [bp+2*8+8] mov cl, 3 - mov dx, X_MAX_VALUE call xy_handler + .x_end: + inc di + inc di ; mouse_y test bl, Y_OVERFLOW jnz .y_end .y: - inc si ; won't be zero - inc di ; mouse_y + inc si ; will be non-zero mov ax, [bp+2*8+6] mov cl, 2 ;mov dx mov dl, Y_MAX_VALUE call xy_handler .y_end: - and bl, BUTTONS - mov [cs:di], bl ; mouse_buttons + mov [cs:di - mouse_y + mouse_buttons], bl popa retf @@ -467,8 +468,8 @@ section .bss _bss_start: mouse_x resw 1 -mouse_y resw 1 ; mouse_x + 2 -mouse_buttons resb 1 ; mouse_y + 1 +mouse_y resw 1 ; mouse_x + 2, do not touch +mouse_buttons resb 1 mouse_column resb 1 mouse_row resb 1