Combine x and y handling in mouse_handler
This commit is contained in:
parent
91c56547e5
commit
d675597120
106
ponydos.asm
106
ponydos.asm
|
@ -374,6 +374,48 @@ BUTTONS equ 0x03
|
|||
X_MAX_VALUE equ 2*COLUMNS-1
|
||||
Y_MAX_VALUE equ 4*ROWS-1
|
||||
|
||||
; in:
|
||||
; si = non-zero for Y
|
||||
; di = &mouse_x/&mouse_y
|
||||
; ax = X/Y
|
||||
; bx = status
|
||||
; cl = negative bit # in ah
|
||||
; dx = MAX_VALUE
|
||||
; out
|
||||
; mouse_x/mouse_y updated appropriately
|
||||
; si = updated [mouse_x]/[mouse_y]
|
||||
; di = di + 1
|
||||
; clobbers ah
|
||||
xy_handler:
|
||||
; X and Y coördinates are stored as 9-bit signed integers
|
||||
; using two's complement notation. The high bits are called
|
||||
; "X negative" and "Y negative".
|
||||
mov ah, bl
|
||||
shl ah, cl ; Shift negative bit to sign position
|
||||
sar ah, 7 ; Fill entire byte with sign bit's value
|
||||
|
||||
test si, si
|
||||
jz .not_y
|
||||
neg ax
|
||||
|
||||
.not_y:
|
||||
mov si, [cs:di]
|
||||
add si, ax
|
||||
|
||||
;cmp si, 0
|
||||
jge .not_underflow
|
||||
xor si, si
|
||||
.not_underflow:
|
||||
|
||||
cmp si, dx
|
||||
jle .not_overflow
|
||||
mov si, dx
|
||||
.not_overflow:
|
||||
|
||||
mov [cs:di], si
|
||||
inc di
|
||||
ret
|
||||
|
||||
mouse_handler:
|
||||
pusha
|
||||
|
||||
|
@ -384,61 +426,29 @@ mouse_handler:
|
|||
test bl, X_OVERFLOW
|
||||
jnz .x_end
|
||||
.x:
|
||||
mov si, [cs:mouse_x]
|
||||
|
||||
mov ax, [bp+2*8+8] ; X
|
||||
|
||||
; X and Y coördinates are stored as 9-bit signed integers
|
||||
; using two's complement notation. The high bits are called
|
||||
; "X negative" and "Y negative".
|
||||
mov ah, bl
|
||||
shl ah, 3 ; X negative is bit 4, shift it to sign position
|
||||
sar ah, 7 ; Fill entire byte with sign bit's value
|
||||
|
||||
add si, ax
|
||||
|
||||
;cmp si, 0
|
||||
jge .not_x_underflow
|
||||
xor si, si
|
||||
.not_x_underflow:
|
||||
|
||||
cmp si, X_MAX_VALUE
|
||||
jle .not_x_overflow
|
||||
mov si, X_MAX_VALUE
|
||||
.not_x_overflow:
|
||||
|
||||
mov [cs:mouse_x], si
|
||||
.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
|
||||
|
||||
test bl, Y_OVERFLOW
|
||||
jnz .y_end
|
||||
.y:
|
||||
mov si, [cs:mouse_y]
|
||||
|
||||
mov ax, [bp+2*8+6] ; Y
|
||||
|
||||
mov ah, bl
|
||||
shl ah, 2 ; Y negative is bit 5
|
||||
sar ah, 7
|
||||
|
||||
; Y direction is flipped compared to our coöridinate space
|
||||
sub si, ax
|
||||
|
||||
;cmp si, 0
|
||||
jge .not_y_underflow
|
||||
xor si, si
|
||||
.not_y_underflow:
|
||||
|
||||
cmp si, Y_MAX_VALUE
|
||||
jl .not_y_overflow
|
||||
mov si, Y_MAX_VALUE
|
||||
.not_y_overflow:
|
||||
|
||||
mov [cs:mouse_y], si
|
||||
inc si ; won't be zero
|
||||
inc di ; mouse_y
|
||||
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:mouse_buttons], bl
|
||||
mov [cs:di], bl ; mouse_buttons
|
||||
|
||||
popa
|
||||
retf
|
||||
|
@ -462,8 +472,8 @@ section .bss
|
|||
_bss_start:
|
||||
|
||||
mouse_x resw 1
|
||||
mouse_y resw 1
|
||||
mouse_buttons resb 1
|
||||
mouse_y resw 1 ; mouse_x + 2
|
||||
mouse_buttons resb 1 ; mouse_y + 1
|
||||
|
||||
mouse_column resb 1
|
||||
mouse_row resb 1
|
||||
|
|
Loading…
Reference in New Issue