; 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.
My code is not leaving the loop that starts at line 228 (called ciclo), it seems like it's not reading the mouse
52 Views Asked by Just do it At
1
Always inspect what a system function returns! This mouse function will return AX=0 if the mouse is not installed (for whatever reason), so do check if AX=-1 for a successful continuation of the program.
Never simply
cmp
BX, but rather single out the bit that represents the left mouse button. The documentation that comes with emu8086 diverges from other available references that deal with the mouse functions.'Undefined' here means that the mouse driver can use these bits for whatever purpose it likes. This can entail your
cmp bx, 01h
never to be true. Better write it as follows: