鼠标和输出装置出现问题

问题描述 投票:0回答:1

我想允许用户单击他选择的潜艇(已经定位:)),然后他在屏幕上再次单击,潜艇就会出现在那里。由于某种原因,无论我点击什么或同一艘潜艇(潜艇 4)出现在哪里,在我移动鼠标后,其中一些就会消失。此外,我做了一个应该运行 5 次的循环,但在一次迭代之后,我的代码继续前进。

proc UseMouse
push ax ; mouse register
push cx ; x cordinates (for future submarine)
push dx ; y cordinates (for future submarine)
push bx
;mov ax,0h
;int 33h
;shr cx,1
wait_for_leftclick:
;mov ax,1h
;int 33h
mov ax,3h
int 33h
cmp bx, 01h
je loop3
jmp wait_for_leftclick ; This begin loop works for sure
loop3:
    
    Tnai1:
    mov ax,3h
    int 33h
    cmp bx, 01h
    jne wait_for_leftclick
    mov ah,0Dh
    int 10h
    cmp al, 4
    je Printsub1
    jmp Tnai2
    
    Tnai2:
    mov ax,3h
    int 33h
    cmp bx, 01h
    jne wait_for_leftclick
    mov ah,0Dh
    int 10h
    cmp al, 5
    je printsub2
    jmp Tnai3
    
    Tnai3:
    mov ax,3h
    int 33h
    cmp bx, 01h
    jne wait_for_leftclick
    mov ah,0Dh
    int 10h
    cmp al, 6
    je printsub3
    jmp printsub4
    
    Tnai4:
    mov ax,3h
    int 33h
    cmp bx, 01h
    jne wait_for_leftclick
    mov ah,0Dh
    int 10h
    cmp al, 7
    je Printsub4
    jmp Tnai5
    
    Tnai5:
    mov ax,3h
    int 33h
    cmp bx, 01h
    jne wait_for_leftclick
    mov ah,0Dh
    int 10h
    cmp al, 8
    je Printsub5
    jmp Finish

Printsub1:
;shr cx, 1
;mov ax,1h
;int 33h
wait_click1:
mov ax, 3h
int 33h
cmp bx, 01h
jne wait_click1
shr cx, 1
mov [Var1], cx
mov [Var2], dx
push 23
push 40
push 4
push [Var2]
push [Var1]
push offset submarine1
call Sprite_Figure
jmp Finish


printsub2:
;shr cx, 1
;mov ax,1h
;int 33h
wait_click2:
mov ax, 3h
int 33h
cmp bx, 01h
jne wait_click2
shr cx, 1
mov [Var1], cx
mov [Var2], dx
push 23
push 40
push 5
push [Var2]
push [Var1]
push offset submarine2
call Sprite_Figure
jmp Finish

printsub3:
;shr cx, 1
;mov ax,1h
;int 33h
wait_click3:
mov ax, 3h
int 33h
cmp bx, 01h
jne wait_click3
shr cx, 1
mov [Var1], cx
mov [Var2], dx
push 23
push 40
push 6
push [Var2]
push [Var1]
push offset submarine3
call Sprite_Figure
jmp Finish

printsub4:
call setPixel
;shr cx, 1
;mov ax,1h
;int 33h
wait_click4:
mov ax, 3h
int 33h
cmp bx, 01h
jne wait_click4 ; we know for sure this works

shr cx,1
push 23
push 40
push 7
push dx
push cx
push offset submarine4
call Sprite_Figure
jmp Finish


Printsub5:
;shr cx, 1
;mov ax,1h
;int 33h
wait_click5:
mov ax, 3h
int 33h
cmp bx, 01h
jne wait_click5
shr cx, 1
mov [var1], cx
mov [var2], dx
push 23
push 40
push 8
push [Var2]
push [Var1]
push offset submarine5
call Sprite_Figure
jmp Finish

Finish:
pop bx
pop dx
pop cx
pop ax
ret
endp UseMouse

功能

mov ah, 5
timeX5:
dec ah
call UseMouse
cmp ah, 0
jne timeX5

我如何调用该函数

我尝试在网上寻找一些线索并询问一些朋友,但没有运气。预先感谢:)

assembly graphics mouse x86-16 tasm
1个回答
0
投票

我想允许用户单击他选择的潜艇(已经定位:)),然后他再次单击屏幕上,潜艇就会出现在那里。

  • 这清楚地表明,您需要的是一个等待鼠标左键被单击并释放然后程序继续运行的程序。
    您目前在 wait_for_leftclick: 的代码,您正确地声明它“肯定有效”,后面跟着的代码根本不等待鼠标左键的释放。

  • 所有 Printsub... 代码都使用此

    shr cx,1
    指令来补偿鼠标驱动程序处理屏幕的方式。这当然很好,但是在从屏幕上读取像素之前,您不应该也使用此指令吗?

; IN () OUT (CX,DX) MOD (AX,BX)
WaitLeftClick:
  mov  ax, 0003h
  int  33h            ; -> BX CX DX
  test bx, 0001h
  jz   WaitLeftClick
WaitLeftClickRelease:
  mov  ax, 0003h
  int  33h            ; -> BX CX DX
  test bx, 0001h
  jnz  WaitLeftClickRelease
  ret

上下文:

proc UseMouse
  push ax
  push cx
  push dx
  push bx
  call WaitLeftClick   ; -> CX DX (AX BX)
  shr  cx, 1
  mov  bh, 0
  mov  ah, 0Dh         ; BIOS.ReadPixel
  int  10h             ; -> AL
  cmp  al, 4
  je   Printsub1
  cmp  al, 5
  je   Printsub2
  cmp  al, 6
  je   Printsub3
  cmp  al, 7
  je   Printsub4
  cmp  al, 8
  je   Printsub5
  jmp  Finish
  
  ...
  
Printsub4:
  call setPixel        ; ????
  call WaitLeftClick   ; -> CX DX (AX BX)
  shr  cx, 1
  push 23
  push 40
  push 7
  push dx
  push cx
  push offset submarine4
  call Sprite_Figure
  jmp  Finish
  
  ...
  
Finish:
  pop  bx
  pop  dx
  pop  cx
  pop  ax
  ret
endp UseMouse

此外,我还创建了一个应该运行 5 次的循环,但在一次迭代之后,我的代码将继续运行。

您确定 Sprite_Figure 过程返回时会从堆栈中删除这 6 个单词吗?

© www.soinside.com 2019 - 2024. All rights reserved.