Mouse stuff
This commit is contained in:
parent
7e0b8ad4e1
commit
750e9a73f5
3 changed files with 77 additions and 5 deletions
3
main.asm
3
main.asm
|
@ -33,10 +33,11 @@ main:
|
|||
|
||||
|
||||
cli
|
||||
|
||||
mov bx, [mouseX]
|
||||
sti
|
||||
|
||||
call print_hex
|
||||
call print_sint
|
||||
call print_nl
|
||||
|
||||
jmp lp
|
||||
|
|
|
@ -98,6 +98,42 @@ mouse_disable:
|
|||
pop es
|
||||
ret
|
||||
|
||||
clamp_mouse_bounds:
|
||||
pusha
|
||||
|
||||
cli
|
||||
mov ax, [mouseX]
|
||||
mov bx, [mouseY]
|
||||
sti
|
||||
|
||||
test ax, 0x8000
|
||||
jnz .x0
|
||||
mov ax, 0
|
||||
.x0:
|
||||
|
||||
test bx, 0x8000
|
||||
jnz .y0
|
||||
mov bx, 0
|
||||
.y0:
|
||||
|
||||
cmp bx, 320
|
||||
jle .x1
|
||||
mov bx, 320
|
||||
.x1:
|
||||
|
||||
cmp ax, 200
|
||||
jle .y1
|
||||
mov ax, 200
|
||||
.y1:
|
||||
|
||||
cli
|
||||
mov [mouseX], ax
|
||||
mov [mouseY], bx
|
||||
sti
|
||||
|
||||
popa
|
||||
ret
|
||||
|
||||
; Function: mouse_callback (FAR)
|
||||
; called by the interrupt handler to process a mouse data packet
|
||||
; All registers that are modified must be saved and restored
|
||||
|
@ -143,6 +179,28 @@ mouse_callback:
|
|||
mov cx, [mouseX]
|
||||
add ax, cx ; AX = new mouse X_coord
|
||||
|
||||
; clamp values
|
||||
|
||||
test ax, 0x8000
|
||||
jz .x0
|
||||
mov ax, 0
|
||||
.x0:
|
||||
|
||||
test bx, 0x8000
|
||||
jz .y0
|
||||
mov bx, 0
|
||||
.y0:
|
||||
|
||||
cmp ax, 320
|
||||
jle .x1
|
||||
mov ax, 320
|
||||
.x1:
|
||||
|
||||
cmp bx, 200
|
||||
jle .y1
|
||||
mov bx, 200
|
||||
.y1:
|
||||
|
||||
; Status
|
||||
mov [curStatus], bl ; Update the current status with the new bits
|
||||
mov [mouseX], ax ; Update current virtual mouseX coord
|
||||
|
|
|
@ -1,8 +1,13 @@
|
|||
%macro print_ch 1
|
||||
push ax
|
||||
push bx
|
||||
|
||||
mov bx, 0x000F
|
||||
mov al, %1
|
||||
mov ah, 0x0e
|
||||
int 0x10
|
||||
|
||||
pop bx
|
||||
pop ax
|
||||
%endmacro
|
||||
|
||||
|
@ -14,14 +19,15 @@
|
|||
int 0x10 ; Graphics services
|
||||
%endmacro
|
||||
|
||||
; bx = string to print
|
||||
print:
|
||||
pusha
|
||||
|
||||
|
||||
.loop:
|
||||
mov al, [bx]
|
||||
cmp al, 0
|
||||
je .end ; go to end if char == 0
|
||||
|
||||
|
||||
mov ah, 0x0e
|
||||
int 0x10
|
||||
|
||||
|
@ -74,8 +80,11 @@ print_hex_digit:
|
|||
.skip_alpha:
|
||||
add al, 0x30 ; Add ASCII '0'
|
||||
|
||||
push bx
|
||||
mov bx, 0x000F
|
||||
mov ah, 0x0e
|
||||
int 0x10
|
||||
pop bx
|
||||
|
||||
popa
|
||||
ret
|
||||
|
@ -135,7 +144,8 @@ print_bin:
|
|||
|
||||
popa
|
||||
ret
|
||||
|
||||
|
||||
; bx = number to print
|
||||
print_uint:
|
||||
pusha
|
||||
|
||||
|
@ -160,8 +170,11 @@ print_uint:
|
|||
pop ax ; 16-bit value
|
||||
mov ah, 0x0e
|
||||
;add al, 0x30
|
||||
push bx
|
||||
mov bx, 0x000F
|
||||
int 0x10
|
||||
|
||||
pop bx
|
||||
|
||||
cmp bx, 0
|
||||
jnz .print_loop
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue