home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / CLIPPER / MISC / MSMOUSE1.ZIP / ASM.ZIP / ATEST.ASM < prev    next >
Encoding:
Assembly Source File  |  1989-02-10  |  6.4 KB  |  257 lines

  1. ;---------------------------------------------------------------
  2. ; Program:      ATEST.ASM
  3. ;
  4. ; Description:  Uses Mouse Function 11 to detect vertical motion
  5. ;               of the mouse.
  6. ;
  7. ; To Run:       MASM ATEST;
  8. ;               LINK ATEST;
  9. ;               ATEST;
  10. ; Note: Program assumes mouse and mouse driver are installed.
  11. ;---------------------------------------------------------------
  12.  
  13. .MODEL  LARGE
  14. .STACK  100h
  15. .DATA
  16.  
  17. msg0    db   "Error: Mouse not found ","$"
  18.  
  19. msg1    db   "ATEST - Mouse demonstration using MASM",0dh,0ah
  20.         db   "Use mouse to highlight a menu item.",0dh,0ah
  21.         db   "Press either button to make selection.","$"
  22.  
  23. msg2    db   0dh,0ah,"Left button was used to select option ","$"
  24. msg3    db   0dh,0ah,"Right button was used to select option ","$"
  25.  
  26. msg4    db   "1","$"
  27. msg5    db   "2","$"
  28. msg6    db   "3","$"
  29.  
  30. menu1   db   " 1. First menu option ",0
  31. menu2   db   " 2. Second option     ",0
  32. menu3   db   " 3. Third option      ",0
  33.  
  34. row     db   ?
  35. column  db   ?
  36.  
  37. menuptr dw   1
  38. motion  dw   0
  39. wflag   db   1
  40. attr    dw   ?
  41.  
  42. .CODE
  43.         assume ds:@DATA
  44.  
  45. menuline    proc
  46.  
  47.         mov attr, 07h   ;Normal attribute
  48.         or  ax, ax      ;Check if line is pointed at
  49.         jnz line1
  50.         mov attr, 70h   ;Inverse attribute
  51.  
  52. line1:
  53.  
  54.         push bx         ;Save the character pointer
  55.         mov al, column  ;Get the current character column
  56.         mov dl, al
  57.         inc ax          ;Increment the character column
  58.         mov column, al  ;Column
  59.         mov al, row
  60.         mov dh, al      ;Row
  61.         mov ah, 2       ;Set cursor position
  62.         xor bh, bh      ;Page 0
  63.         int 10h         ;Video function - set cursor position
  64.         pop bx          ;Get character pointer
  65.         mov al, [bx]    ;Get next character from menu item
  66.         or  al, al      ;Check for end of string
  67.         jz  line1b      ;At the end of menu item?
  68.         push bx         ;Save the character pointer
  69.         mov bx, attr    ;Attribute into BX
  70.         mov ah, 9       ;Write character and attribute
  71.         mov cx, 1       ;Just one repetition
  72.         int 10h         ;Video interrupt
  73.         pop bx          ;Restore the character pointer
  74.         inc bx          ;Bump the pointer
  75.         jmp short line1 ;Loop back for next character
  76.  
  77. line1b:
  78.  
  79.         ret
  80.  
  81. menuline    endp
  82.  
  83. ;----------------------------------------
  84.  
  85. start:
  86.  
  87.         mov ax,@DATA    ; Set up DS for the data segment
  88.         mov ds,ax
  89.  
  90.         assume ds:@DATA
  91.  
  92.         ; Clear the screen
  93.         mov ax,600h     ; Scroll up, clear whole window
  94.         mov bh,7        ; Use normal attribute
  95.         xor cx, cx      ; Rows and columns start at 0
  96.         mov dx,184Fh    ; Rows 0 to 24, Columns 0 to 79
  97.         int 10h         ; Video interrupt
  98.  
  99.         ; Place cursor in upper-left corner
  100.         mov ah, 2
  101.         xor dx, dx      ;Row 0, Column 0
  102.         mov bh, dh      ;Page 0
  103.         int 10h         ;Video function - set cursor position
  104.  
  105.         ; Mouse Reset and Status
  106.         xor ax, ax
  107.         int 33h
  108.  
  109.         ; Was mouse reset okay?
  110.         or  ax, ax
  111.         mov ah, 9
  112.         jnz continue
  113.  
  114.         ; Display message 0
  115.         mov dx, offset msg0
  116.         int 21h
  117.  
  118.         ; Exit with return of 1
  119.         mov ax, 4C01h
  120.         int 21h
  121.  
  122. continue:
  123.  
  124.         ; Display message 1
  125.         mov dx, offset msg1
  126.         int 21h
  127.  
  128. mainloop:
  129.  
  130.         ; Accumulate vertical mouse motion counts
  131.         mov ax, 11
  132.         int 33h
  133.         mov ax, motion
  134.         add ax, dx
  135.         mov motion, ax
  136.  
  137.         ; Move up the menu if enough mouse motion
  138.         cmp ax, -17
  139.         jge mcheck2     ;Not enough up motion
  140.         mov motion,0    ;Clear the motion counts
  141.         mov ax, menuptr
  142.         cmp ax, 1
  143.         jle mcheck2     ;Menu pointer can't go below 1
  144.         dec ax
  145.         mov menuptr, ax
  146.         mov wflag, al   ;Set flag to update the menu
  147.         jmp short mcheck3
  148.  
  149. mcheck2:
  150.  
  151.         ; Move down the menu if enough mouse motion
  152.         cmp ax, 17
  153.         jle mcheck3     ;Not enough down motion
  154.         mov motion,0    ;Clear the motion counts
  155.         mov ax, menuptr
  156.         cmp ax, 3
  157.         jge mcheck3     ;Menu pointer can't go above 3
  158.         inc ax
  159.         mov menuptr, ax
  160.         mov wflag, al   ;Set flag to update the menu
  161.  
  162. mcheck3:
  163.  
  164.         ; Update the menu if indicated
  165.         xor ax, ax
  166.         cmp wflag, al
  167.         je  chkbuttons  ;No need to update
  168.  
  169.         mov wflag, al   ;Reset the update flag
  170.  
  171.         ; First line of menu
  172.         mov column, 28
  173.         mov row, 9
  174.         mov bx, offset menu1
  175.         mov ax, menuptr
  176.         dec ax
  177.         call menuline
  178.  
  179.         ; Second line of menu
  180.         mov column, 28
  181.         mov row, 10
  182.         mov bx, offset menu2
  183.         mov ax, menuptr
  184.         dec ax
  185.         dec ax
  186.         call menuline
  187.  
  188.         ;Third line of menu
  189.         mov column, 28
  190.         mov row, 11
  191.         mov bx, offset menu3
  192.         mov ax, menuptr
  193.         sub ax, 3
  194.         call menuline
  195.  
  196. chkbuttons:
  197.  
  198.         ; Check if left button has been pressed
  199.         mov ax, 5       ;Mouse Function 5
  200.         xor bx, bx      ;Get left button press information
  201.         int 33h         ;Mouse interrupt
  202.         or  bx, bx
  203.         jnz leftbutton
  204.  
  205.         ; Check if right button has been pressed
  206.         mov ax, 5       ;Mouse Function 5
  207.         mov bx, 1       ;Get right button press information
  208.         int 33h         ;Mouse interrupt
  209.         or  bx, bx
  210.         jnz rightbutton
  211.  
  212.         ; Loop back until a button press is detected
  213.         jmp mainloop
  214.  
  215. leftbutton:
  216.  
  217.         ; Display message 2
  218.         mov dx, offset msg2
  219.         mov ah, 09h     ;Output message to screen
  220.         int 21h
  221.         jmp short selection
  222.  
  223. rightbutton:
  224.  
  225.         ; Display message 3
  226.         mov dx, offset msg3
  227.         mov ah, 09h     ;Output message to screen
  228.         int 21h
  229.  
  230. selection:
  231.  
  232.         mov ax, menuptr
  233.         mov dx, offset msg4
  234.         cmp ax, 1
  235.         je select
  236.         mov dx, offset msg5
  237.         cmp ax, 2
  238.         je select
  239.         mov dx, offset msg6
  240.  
  241. select:
  242.  
  243.         mov ah, 09h     ;Output message to screen
  244.         int 21h
  245.  
  246. reset:
  247.         ; Reset the mouse
  248.         xor ax, ax
  249.         int 33h
  250.  
  251.         ; Exit to MS-DOS
  252.         mov ax,4C00h
  253.         int 21h
  254.  
  255. END     start
  256.         END
  257.