home *** CD-ROM | disk | FTP | other *** search
- ;---------------------------------------------------------------
- ; Program: ATEST.ASM
- ;
- ; Description: Uses Mouse Function 11 to detect vertical motion
- ; of the mouse.
- ;
- ; To Run: MASM ATEST;
- ; LINK ATEST;
- ; ATEST;
- ; Note: Program assumes mouse and mouse driver are installed.
- ;---------------------------------------------------------------
-
- .MODEL LARGE
- .STACK 100h
- .DATA
-
- msg0 db "Error: Mouse not found ","$"
-
- msg1 db "ATEST - Mouse demonstration using MASM",0dh,0ah
- db "Use mouse to highlight a menu item.",0dh,0ah
- db "Press either button to make selection.","$"
-
- msg2 db 0dh,0ah,"Left button was used to select option ","$"
- msg3 db 0dh,0ah,"Right button was used to select option ","$"
-
- msg4 db "1","$"
- msg5 db "2","$"
- msg6 db "3","$"
-
- menu1 db " 1. First menu option ",0
- menu2 db " 2. Second option ",0
- menu3 db " 3. Third option ",0
-
- row db ?
- column db ?
-
- menuptr dw 1
- motion dw 0
- wflag db 1
- attr dw ?
-
- .CODE
- assume ds:@DATA
-
- menuline proc
-
- mov attr, 07h ;Normal attribute
- or ax, ax ;Check if line is pointed at
- jnz line1
- mov attr, 70h ;Inverse attribute
-
- line1:
-
- push bx ;Save the character pointer
- mov al, column ;Get the current character column
- mov dl, al
- inc ax ;Increment the character column
- mov column, al ;Column
- mov al, row
- mov dh, al ;Row
- mov ah, 2 ;Set cursor position
- xor bh, bh ;Page 0
- int 10h ;Video function - set cursor position
- pop bx ;Get character pointer
- mov al, [bx] ;Get next character from menu item
- or al, al ;Check for end of string
- jz line1b ;At the end of menu item?
- push bx ;Save the character pointer
- mov bx, attr ;Attribute into BX
- mov ah, 9 ;Write character and attribute
- mov cx, 1 ;Just one repetition
- int 10h ;Video interrupt
- pop bx ;Restore the character pointer
- inc bx ;Bump the pointer
- jmp short line1 ;Loop back for next character
-
- line1b:
-
- ret
-
- menuline endp
-
- ;----------------------------------------
-
- start:
-
- mov ax,@DATA ; Set up DS for the data segment
- mov ds,ax
-
- assume ds:@DATA
-
- ; Clear the screen
- mov ax,600h ; Scroll up, clear whole window
- mov bh,7 ; Use normal attribute
- xor cx, cx ; Rows and columns start at 0
- mov dx,184Fh ; Rows 0 to 24, Columns 0 to 79
- int 10h ; Video interrupt
-
- ; Place cursor in upper-left corner
- mov ah, 2
- xor dx, dx ;Row 0, Column 0
- mov bh, dh ;Page 0
- int 10h ;Video function - set cursor position
-
- ; Mouse Reset and Status
- xor ax, ax
- int 33h
-
- ; Was mouse reset okay?
- or ax, ax
- mov ah, 9
- jnz continue
-
- ; Display message 0
- mov dx, offset msg0
- int 21h
-
- ; Exit with return of 1
- mov ax, 4C01h
- int 21h
-
- continue:
-
- ; Display message 1
- mov dx, offset msg1
- int 21h
-
- mainloop:
-
- ; Accumulate vertical mouse motion counts
- mov ax, 11
- int 33h
- mov ax, motion
- add ax, dx
- mov motion, ax
-
- ; Move up the menu if enough mouse motion
- cmp ax, -17
- jge mcheck2 ;Not enough up motion
- mov motion,0 ;Clear the motion counts
- mov ax, menuptr
- cmp ax, 1
- jle mcheck2 ;Menu pointer can't go below 1
- dec ax
- mov menuptr, ax
- mov wflag, al ;Set flag to update the menu
- jmp short mcheck3
-
- mcheck2:
-
- ; Move down the menu if enough mouse motion
- cmp ax, 17
- jle mcheck3 ;Not enough down motion
- mov motion,0 ;Clear the motion counts
- mov ax, menuptr
- cmp ax, 3
- jge mcheck3 ;Menu pointer can't go above 3
- inc ax
- mov menuptr, ax
- mov wflag, al ;Set flag to update the menu
-
- mcheck3:
-
- ; Update the menu if indicated
- xor ax, ax
- cmp wflag, al
- je chkbuttons ;No need to update
-
- mov wflag, al ;Reset the update flag
-
- ; First line of menu
- mov column, 28
- mov row, 9
- mov bx, offset menu1
- mov ax, menuptr
- dec ax
- call menuline
-
- ; Second line of menu
- mov column, 28
- mov row, 10
- mov bx, offset menu2
- mov ax, menuptr
- dec ax
- dec ax
- call menuline
-
- ;Third line of menu
- mov column, 28
- mov row, 11
- mov bx, offset menu3
- mov ax, menuptr
- sub ax, 3
- call menuline
-
- chkbuttons:
-
- ; Check if left button has been pressed
- mov ax, 5 ;Mouse Function 5
- xor bx, bx ;Get left button press information
- int 33h ;Mouse interrupt
- or bx, bx
- jnz leftbutton
-
- ; Check if right button has been pressed
- mov ax, 5 ;Mouse Function 5
- mov bx, 1 ;Get right button press information
- int 33h ;Mouse interrupt
- or bx, bx
- jnz rightbutton
-
- ; Loop back until a button press is detected
- jmp mainloop
-
- leftbutton:
-
- ; Display message 2
- mov dx, offset msg2
- mov ah, 09h ;Output message to screen
- int 21h
- jmp short selection
-
- rightbutton:
-
- ; Display message 3
- mov dx, offset msg3
- mov ah, 09h ;Output message to screen
- int 21h
-
- selection:
-
- mov ax, menuptr
- mov dx, offset msg4
- cmp ax, 1
- je select
- mov dx, offset msg5
- cmp ax, 2
- je select
- mov dx, offset msg6
-
- select:
-
- mov ah, 09h ;Output message to screen
- int 21h
-
- reset:
- ; Reset the mouse
- xor ax, ax
- int 33h
-
- ; Exit to MS-DOS
- mov ax,4C00h
- int 21h
-
- END start
- END
-