assembly 我的代码没有离开从第228行开始的循环(称为ciclo),它似乎没有阅读鼠标

m4pnthwp  于 5个月前  发布在  其他
关注(0)|答案(1)|浏览(49)
; multi-segment executable file template.

data segment
    ; add your data here!
    
   ; Escolhas inícias
   stringjogar db "JOGAR$",0 
   stringtop5 db "TOP 5$",0
   stringcreditos db "CREDITOS$",0
   stringsair db "SAIR$",0   
   
   
   ;coordenadas 
   x1 dw ?
   x2 dw ?
   y1 dw ?
   y2 dw ?    
   
   ;Cores para a moldura e texto do menu
   cor_frame db 0Ah                ; cor da moldura do menu
   cor_texto db 0Fh                ; cor do texto do menu   
   
   ;Menu coordinates
   x_menu dw 180, 180, 180, 180, 180    ; x coordinates for the menu
   y_menu dw 20, 40, 60, 80, 100        ; y coordinates for the menu      
                          
                          
   ;Variáveis de controle
   contagem dw ?
   conta_char dw ? 
   
   
   stringjogador db "Nome jogador: $", 0    
   stringnome db 50 dup(?) , 0
   
    
    
ends     



stack segment
    dw   128  dup(0)
ends



code segment
start:
    ; set segment registers:
    mov ax, data
    mov ds, ax
    mov es, ax

    ; add your code here 
    
    call opcoes_iniciais ;vai mostrar o menu     
    call vamos_jogar 
    
                 
    mov ax, 4c00h ; exit to operating system.
    int 21h           
             
             
             
             
; desenha as molduras a volta das opcoes
        frame proc
            
            mov cx, x1
            mov dx, y1
            mov ah, 0Ch ; mudar cor de um pixel
            
        ;desenhar 1 linha
        linha1:    
            inc cx  ; DX linha
            int 10h
            
            cmp cx, x2 ;valor máximo da coluna
            jne linha1
        
        
        ;desenhar 1ª coluna    
        coluna1:
            inc dx   ; CX coluna
            int 10h
            
            cmp dx, y2 ;valor máximo da coluna
            jne coluna1 
            
        ;desenhar 2ªlinha
        linha2:
        
           dec cx ;Dx linha cx=cx-1
           int 10h
           
           cmp cx, x1; fazer pixeis ate x2 ser igual a x1
           jne linha2
           
        ;desenhar 2ªcoluna
        coluna2: 
        
           dec dx ;cx coluna dx=dx-1
           int 10h
           
           cmp dx, y1 ; fazer pixeis ate y2 ser igual a y1
           jne coluna2
           
        ret
        endp             
             
             
             
            
    
    ;_______________________________________________________________________________
             
    ; Function to show initial options    
    opcoes_iniciais proc    
         
       
        mov ah, 0  ; Define video mode
        mov al, 13h ; Graphics mode, 320x200 pixels, 256 colors
        int 10h  
        
        ; Mouse initialization
        mov ax, 0h 
        int 33h       
            
                                            
        mov ah, 7 ; deixar letra grande
        int 21h             
                     
                     
              
        ; Present the initial options
        
        ; Jogar
        mov dh, 3   ; Cursor for the 3rd line
        mov dl, 16  ; Cursor for the 1th column
        mov bh, 0
        mov ah, 2
        int 10h    
        
        mov ah, 9h                 ; AH = 9h - "Write String" function
        mov dx, offset stringjogar ; DX points to the string to be printed
        int 21h                    ; Call the BIOS interrupt for string output
                                            
        mov al, 0Ah ; Decide frame color
        mov x1, 120                                 
        mov x2, 175
        mov y1, 20     ; Jogar frame
        mov y2, 35
        call frame  
            
            
     ;---------------------------------   
        mov dh, 6
        mov dl, 16
        mov bh, 0      ;set o cursor
        mov ah, 2
        int 10h  
        
        mov dx, offset stringtop5
        mov ah, 09h ; print top5
        int 21h
        
        mov al, 0bh ; cor frame
        mov x1, 120;115
        mov x2, 175;187
        mov y1, 42    ;frame top5
        mov y2, 57
        call frame        
     
     
     ;---------------------------------                
                                  
        mov dh,9   
        mov dl, 16
        mov bh,0       ;set cursor
        mov ah, 2
        int 10h
        
        mov dx, offset stringcreditos
        mov ah, 09h ;print stringcreditos
        int 21h
        
        mov al, 0ch ;cor frame
        mov x1, 120    
        mov x2, 195
        mov y1, 67
        mov y2, 82      ;frame stringcreditos
        call frame
        
        
      ;------------------------                           
                                  
        mov dh, 12
        mov dl, 16
        mov bh, 0        ;set cursor
        mov ah, 2
        int 10h
        
        mov dx, offset stringsair
        mov ah, 09h ;print TOP 5
        int 21h
        
        mov al, 0dh ; cor frame
        mov x1, 120
        mov x2, 175
        mov y1, 90        ;frame stringsair
        mov y2, 105
        call frame
        
        ;-------------------------- 
             
                 
        
        ; detetar o input do rato  
    
        mov ax, 01h ; mostrar o mouse pointer
        int 33h    
        
        
        ciclo:
           mov ax, 03h ;    get mouse position and status of its buttons
           int 33h
           
           cmp bx, 01h ;if left button is down: BX=1 
           je clique ;if right button is down: BX=2 
           jmp ciclo ;if both buttons are down: BX=3
                     ;CX = x 
                     ;DX = y              
                                  

     
       ;----------------------------------------
       ; Ir para opcao escolhida  
       
       clique:
       
          Jogo: 
          cmp dx, 20
          ja ciclo
        
          cmp dx, 35
          ;jb top5      ;ve se o jogador clicou em jogar
        
          cmp cx, 120   ;se clicou vai para a funcao vamos jogar
          jb ciclo
        
          cmp cx, 175
          ja ciclo
            
          jmp vamos_jogar    
                     
    ret                
                  
    endp        
        
    
    
    vamos_jogar proc
         
         call escolhanome    
            
        
    ret
    endp                
                
        
        
    ;jogador escreve o seu nome   
      
    escolhanome proc
        
        mov ah, 0  ;definir modo de video
        mov al, 13h ;modo grafico, 320x200 pixeis, 256 cores
        int 10h
        
        mov ah, 0ch  ;limpar buffer
        int 21h 
             
        
        mov dh, 8   ;set cursor para a 8ª linha
        mov dl, 16   ;set cursor para a 16ª coluna
        mov bh, 0     
        mov ah, 2
        int 10h      
                      
        mov dx, offset stringjogador  ; output "nome jogador" 
        mov ah, 09h
        int 21h
        
        mov dh, 12     ;set cursor para a 2ª linha
        mov dl, 17     ;set cursor para a 20ª coluna
        mov bh, 0     
        mov ah, 2
        int 10h     
        mov si, offset stringnome      ;utilizador escreve o seu nome
        call scanf                     ; na stringnome
        
            
    ret    
    endp   

        
        ;*****************************************************************
        ; scanf - scan input
        ; descricao: rotina que le o input do teclado
        ; input - teclado 
        ; output - nenhum
        ; destroi - al, si
        ;*****************************************************************      
        scanf proc 
            
            L2: call ci 
            
                cmp al, 0dh
                je fimscanf                  ;escreve para uma string usando o ci
                mov byte ptr [si],al
                inc si
                inc contagem
                cmp contagem,10
                je fimscanf
                jmp L2 
                
            fimscanf:
                mov ax, contagem
                mov conta_char, ax
                mov contagem, 0
                mov si, offset stringnome ; coloca nome nesta string
                ret 
            
                
        scanf endp
        
        
        ;*****************************************************************
        ; ci - caracter intput
        ; descricao: rotina que le o input do teclado
        ; input - nenhum
        ; output - al-caracter lido
        ; destroi - nada
        ;*****************************************************************
        ci proc
        mov ah,01h  ;read with echo
        int 21h
        
        ret
        endp 
          

ends

end start ; Set entry point and stop the assembler.

字符串

xvw2m8pv

xvw2m8pv1#

; Mouse initialization
mov ax, 0h
int 33h

字符串

始终检查系统函数返回的内容!如果鼠标未安装(无论出于何种原因),此鼠标函数将返回AX=0,因此请检查AX=-1是否成功继续程序。

ciclo:
  mov ax, 03h ;    get mouse position and status of its buttons
  int 33h

  cmp bx, 01h ;if left button is down: BX=1 
  je  clique  ;if right button is down: BX=2 
  jmp ciclo   ;if both buttons are down: BX=3
              ;CX = x 
              ;DX = y

永远不要简单的cmp BX,而是要挑出代表鼠标左键的位。emu 8086附带的文档与其他处理鼠标功能的参考文献不同。

the bits in BX
FEDCBA9876543210
...............0  Left button up
...............1  Left button down
..............0.  Right button up
..............1.  Right button down
.............0..  Middle button up
.............1..  Middle button down
xxxxxxxxxxxxx...  Undefined


这里的“Undefined”意味着鼠标驱动程序可以将这些位用于任何它喜欢的目的。这可能会导致cmp bx, 01h永远不为true。最好这样写:

ciclo:
    mov  ax, 03h   ; MOUSE.GetMousePosition
    int  33h       ; -> BX CX DX
    and  bx, 0001h ; Single out the left button
    jz   ciclo
clique:

相关问题