assembly 检查是否在装配中单击了鼠标右键,然后又“取消单击”

yfwxisqw  于 2022-11-24  发布在  其他
关注(0)|答案(1)|浏览(232)

我有一个相对简单的TASM程序,它需要使用鼠标左键进行绘制,显示光标坐标和改变颜色的鼠标右键点击。问题是它跳过一些颜色,如果你按住按钮。所以我需要检测,如果我们已经点击,然后取消点击我们的鼠标。尝试添加一个功能来检查这种行为,但在右键点击它崩溃的程序或使只有1个像素或不我什么都不做。我现在使用的代码是

.model small
.stack 256
.data
.386
stat db ?
col  dw ?
row  dw ?
color db 3
flag db 1
rezult db '000$'
mult10 db 10
mesx db 'x =$'
mesy db 'y =$'
mes_er db 'мышь не установлена',13,10,'$'
mes    db 'пpогpамма завеpшена',13,10,'$'
mask_m dw 16 dup(0ffffh)
       dw 07c0h,0c60h,1830h,3018h
       dw 6ccch,6ccch,600ch,600ch
       dw 644ch,3398h,1860h,0c60h
       dw 07c0h,0000h,0000h,0000h
.code
cursor_on proc near
      mov ax,01
      int 33h
      ret
cursor_on endp

cursor_off proc near
      mov ax,2
      int 33h
      ret
cursor_off endp

mouse_stat proc near
      mov ax,3
      int 33h
      ret
mouse_stat endp

pixel   proc near
        call cursor_off
    mov ah,0Ch
    mov al,color
    mov bh,0
        int 10h
        call cursor_on
        ret
pixel   endp

speed proc near
     mov ax,000fh
     mov cx,64
     mov dx,64
     int 33h
     mov ax,0013h
     mov dx,64
     int 33h
     ret
speed endp

text_curc proc near
    mov ax,000AH
    mov bx,01
    int 33h
    ret
text_curc endp

write   proc near
    mov bx,3
cicle:
    idiv mult10
    add ah,30h
    mov [si+bx-1],ah
    mov ah,0
    dec bx
    jnz cicle
    mov ah,09
    mov dx,offset rezult
    int 21h
    ret
write   endp

go:  mov ax,@data
     mov ds,ax
     mov ax,0
     int 33h
     cmp ax,0
     jne ner
     jmp er
ner:
     mov ax,10h
     int 10h
     mov ax,9
     xor bx,bx
     xor cx,cx
     push ds
     pop es
     lea dx,mask_m
     int 33h
     call speed
     call cursor_on
     call mouse_stat
     mov col,cx
     mov row,dx

    mov ah,02
    mov bh,00
    mov dx,0000h
    int 10h
    mov ah,9
        lea dx,mesx
    int 21h  
    mov ah,02
    mov bh,00
    mov dx,0009h
    int 10h
    mov ah,9
        lea dx,mesy
    int 21h  

next:
    mov ah,02
    mov bh,00
    mov dx,0004h
    int 10h
    mov ax,col
    lea si,rezult
    call write
    mov ah,02
    mov bh,0
    mov dx,000Dh
    int 10h
    mov ax,row
    call write
    mov dx,row
    mov cx,col

    mov ah,1
    int 16h
    jz nosym    
    mov ah,0
    int 16h
    cmp al,27
    je ex
    
    mov ah,1
    int 16h
    cmp al,32
    je nextc

nosym:
     mov flag,0
     call mouse_stat
     mov stat,bl
     cmp col,cx
     je  rov_lab
     mov col, cx
     mov flag ,1
rov_lab:
     cmp row,dx
     je pix
      mov row ,dx
      mov flag,1
pix:
    mov bl,stat
    and bl,2
    cmp bl,2
    ;je nextc is what was in the original program instead of 'je check'
    je check
       mov bl,stat
       and bl,1
       cmp bl,1
       jne next
       cmp flag,0
       je next
       call pixel
       jmp next
check: ; tried to write it myself but it doesn't work the way it needs to
    mov ax, 06h
    mov bx, 01h
    int 33h
    cmp ax, 02h
    je nextc
        
ex:
      call cursor_off
      lea dx,mes
       jmp exit
nextc:
    inc color
    jmp next
er:
     lea dx,mes_er
exit:
      mov ax,3
      int 10h
      mov ah,9
      int 21h
      mov ax,4c00h
      int 21h

End go
aamkag61

aamkag611#

并在鼠标右键单击时改变颜色。问题是如果你按住按钮,它会跳过一些颜色。
当程序检测到鼠标右键点击时,你可以开始运行一个紧循环,只要鼠标右键不再被按下就停止。然后旋转颜色并继续主程序循环。
第一个
显然,你还想在用户按空格键时旋转颜色。你应该删除上面我标记的两行。键盘函数00h已经检索到了键,并且由于程序运行得太快,不太可能有第二个键可用。第二次使用键盘函数01h将返回ZF=1,但它也可能破坏AL,这将使与32的比较毫无意义。

mov  ah, 01h
  int  16h            ; -> AX ZF
  jz   nosym    
  mov  ah, 00h
  int  16h            ; -> AX
  cmp  al, 27         ; <ESC>
  je   ex
  cmp  al, 32         ; <SPC>
  je   keybNextColor
nosym:

  ...

pix:
  test stat, 2        ; Right button ?
  jnz  mouseNextColor ; Yes
  test stat, 1        ; Left button ?
  jz   next           ; No
  cmp  flag, 0
  je   next
  call pixel
  jmp  next
ex:
  call cursor_off
  lea  dx,mes
  jmp  exit
mouseNextColor:
  call mouse_stat     ; -> BX CX DX
  test bl, 2
  jnz  mouseNextColor ; Right button is still down
keybNextColor:
  inc  color
  jmp  next

相关问题