home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / RGASM.RAR / ASMCODE.EXE / CHAPT10 / PMOUSE1.ASM < prev    next >
Encoding:
Assembly Source File  |  1993-05-10  |  10.2 KB  |  200 lines

  1. ;***********************************************************************
  2. ;  Program PMouse1 ( Chapter 10 )
  3. ;
  4. ;  The demo program for mouse (Text Mode)
  5. ;
  6. ;  Author:  A.I.Sopin, Voronezh University. 1993
  7. ;
  8. ;  The interrupt 33h (mouse service) is used
  9. ;
  10. ;  The mouse driver required
  11. ;
  12. ;***********************************************************************
  13.     EXTRN   INSYM4 : FAR
  14.     .MODEL  SMALL
  15.     .STACK
  16. ;----------------------------------------------------------
  17.     .DATA
  18. BELL    EQU     07      ;  sound signal
  19. LF      EQU     10      ;  Line Feed
  20. CR      EQU     13      ;  Carriage Return
  21. TEXT0   DB      " The MOUSE demo program  (INT 33h). "
  22.     DB      "  Press any key to continue...", BELL, CR, LF, "$"
  23. TEXT1   DB      " The mouse driver is not installed !!!."
  24.     DB      "  Press any key...", BELL, CR, LF, "$"
  25. TEXT2   DB      " An active mouse driver found."
  26.     DB      "  Press any key...", BELL, CR, LF, "$"
  27. TXT0    DB      " Function 0 - initialize mouse."
  28.     DB      "  Press any key...", BELL, "$"
  29. TXT1    DB      CR, " Function 1 - show mouse cursor."
  30.     DB      "  Press any key...", BELL, "$"
  31. TXT2    DB      CR, " Function 2 - hide mouse cursor."
  32.     DB      "  Press any key...", BELL, "$"
  33. TXT3    DB      CR, " Function 3 - press mouse key.   (Enter -Exit).        "
  34.     DB      BELL, CR, LF, "$"
  35. TXT3L   DB      CR, " Left button pressed.   CODE=0X."
  36.     DB      " COL=XXXX. ROW=XXXX.", BELL, "$"
  37. TXT3R   DB      CR, " Right button pressed.  CODE=0X."
  38.     DB      " COL=XXXX. ROW=XXXX.", BELL, "$"
  39. TXT3M   DB      CR, " Middle buttom pressed. CODE=0X."
  40.     DB      " COL=XXXX. ROW=XXXX.", BELL, "$"
  41. TXT10   DB      CR, " Function 10 - define text cursor.  Press any key..."
  42.     DB      BELL, CR, LF, "$"
  43. VMODE   DB      0                       ;  video mode saved
  44. ATTR    DB      0                       ;
  45. ROW0    DB      0
  46. CX0     DW      0
  47. DX0     DW      0
  48. Eight   DW      8
  49. ;----------------------------------------------------------
  50.     .CODE
  51. OutMsg  macro   Txt
  52.     lea     dx,Txt                  ;  addres of message
  53.     mov     ah,09h                  ;  function 09h - output text string
  54.     int     21h                     ;  DOS  service call
  55.     endm
  56. WaitKey macro
  57.     mov     ah,0                    ;  function 0 - wait for key pressed
  58.     int     16h                     ;  BIOS keyboard service
  59.     endm
  60. SetCurs MACRO   Row,Column
  61.     mov     ah,2                    ;  function 02h - set cursor
  62.     xor     bh,bh                   ;  video page 0 is used
  63.     mov     dh,&Row                 ;  cursor row
  64.     mov     dl,&Column              ;  cursor column
  65.     int     10h                     ;  BIOS video service call
  66.     ENDM
  67. ;----------------------------------------------------------
  68. .STARTUP
  69.     mov     ah,0Fh                  ;  function 0Fh - get video mode
  70.     int     10h                     ;  BIOS video service call
  71.     mov     VMODE,al                ;  save current video mode
  72.     mov     ah,0                    ;  function 0 - set video mode
  73.     mov     al,3                    ;  80x25  Text
  74.     int     10h                     ;  BIOS video service call
  75. ;  Output initial message
  76.     OutMsg  TEXT0                   ;  output initial message
  77.     WaitKey
  78. ;  check for mouse driver present
  79.     mov     ax, 03533h              ;  function 35h - get interrupt vector
  80.     int     21h                     ;  DOS service call
  81.     mov     ax,es                   ;  segment address of handler
  82.     or      ax,bx                   ;  AX - segment .OR. offset of int 33
  83.     jz      Nomouse                 ;  if full addres is 0 - no mouse
  84.     mov     bl,es:[bx]              ;  get first instrucyion of handler
  85.     cmp     bl,0CFh                 ;  is this IRET instruction?
  86.     jne     Begin                   ;  if not - driver installed
  87. Nomouse:OutMsg  TEXT1                   ;  output message "driver not found"
  88.     WaitKey                         ;  wait for key pressed
  89.     jmp     Exit                    ;  Exit program
  90. ;-------------------------------------------------------------------
  91. Begin:  OutMsg  TEXT2                   ;  output message "driver installed"
  92.     WaitKey                         ;  wait for key pressed
  93. ;-------------------------------------------------------------------
  94. ;  Initialize mouse and report status (function 0 of INT 33h)
  95. Func0:  OutMsg  TXT0                    ;  output message "function 0"
  96.     WaitKey
  97.     xor     ax,ax                   ;  Initialize mouse
  98.     int     33h                     ;  mouse service call
  99.     cmp     ax,0                    ;  is mouse installed?
  100.     jnz     Func1                   ;  if so, pass to function 1
  101.     jz      Exit                    ;  if not, exit program
  102. ;-------------------------------------------------------------------
  103. ;  Function 1 - show the mouse cursor
  104. Func1:  OutMsg  TXT1                    ;  output message "function 1"
  105.     mov     ax,1                    ;  function 01 - show mouse cursor
  106.     int     33h                     ;  mouse service call
  107.     WaitKey
  108. ;-------------------------------------------------------------------
  109. ;  Function 2 - hide cursor
  110. Func2:  OutMsg  TXT2                    ;  output message "function 2"
  111.     mov     ax,2                    ;  function 02 - hide mouse cursor
  112.     int     33h                     ;  mouse service call
  113.     WaitKey
  114. ;-------------------------------------------------------------------
  115. ;  Function 10 - set text cursor
  116. Func10: OutMsg  TXT10                   ;  output message "function 10"
  117.     WaitKey
  118.     mov     ax,10                   ;  function 10 - Define Text Cursor
  119.     xor     bx,bx                   ;  software cursor will be used
  120.     mov     cx,0FFFFh               ;  screen Mask
  121.     mov     dx,4700h                ;  cursor Mask
  122.     int     33h                     ;  mouse service call
  123.     mov     ax,1                    ;  function 01 - show mouse cursor
  124.     int     33h                     ;  mouse service call
  125. ;  Output colored strips on screen
  126.     mov     cx,15                   ;  number of lines to be output
  127.     mov     ATTR,17h                ;  bacground for first line (blue)
  128.     mov     ROW0,9                  ;  first line painted is line 9
  129. Str15:  SetCurs ROW0,0                  ;  function 02h - set cursor position
  130.     mov     ah,9                    ;  function 09 - output char+attr
  131.     mov     al,20h                  ;  character to be output - blank
  132.     mov     bh,0                    ;  video page 0
  133.     push    cx                      ;  save line counter
  134.     mov     cx,80                   ;  CX - number of characters output
  135.     mov     bl,ATTR                 ;  background/character attribute
  136.     int     10h                     ;  BIOS video service
  137.     add     ATTR,10h                ;  change background
  138.     inc     ROW0                    ;  to next line
  139.     pop     cx                      ;  restore lines counter
  140.     loop    Str15                   ;  next step (draw next line)
  141. ;-------------------------------------------------------------------
  142. ;  Function 03 - report cursor location and key status
  143. Func3:  SetCurs 3,0                     ;  function 02h - set cursor position
  144.     OutMsg  TXT3                    ;  output message "function 3"
  145. ChkKBD: mov     ah,1                    ;  function 01h - check keyboard buffer
  146.     int     16h                     ;  BIOS keyboard service
  147.     jz      ContF3                  ;  if no key pressed, continue
  148.     jmp     Exit                    ;  exit if key pressed
  149. ;  determining mouse keys pressed
  150. ContF3: mov     ax,3                    ;  func. 03 - button status and location
  151.     int     33h                     ;  mouse service call
  152.     mov     CX0,cx                  ;  save  X coordinate (column)
  153.     mov     DX0,dx                  ;  save  Y coordinate (row)
  154.     test    bx,1                    ;  left button pressed?
  155.     jnz     M3L                     ;
  156.     test    bx,2                    ;  right button pressed?
  157.     jnz     M3R                     ;
  158.     test    bx,4                    ;  middle button pressed ?
  159.     jnz     M3M                     ;
  160.     jmp     short ChkKBD            ;  no button pressed - check again
  161. M3L:    lea     dx,TXT3L                ;  address of message "left button"
  162.     jmp     short   M3MES           ;  to output message
  163. M3R:    lea     dx,TXT3R                ;  address of message "right button"
  164.     jmp     short   M3MES           ;  to output message
  165. M3M:    lea     dx,TXT3M                ;  address of message "miiddle button"
  166. ;  Output number and code of mouse key pressed
  167. M3MES:  or      bl,30h                  ;  convert key number into ASCII code
  168.     mov     di,dx                   ;  address of message into DI
  169.     mov     ds:[di+31],bl           ;  place ASCII code of key pressed
  170.     push    dx                      ;  save address of message
  171.     mov     si,4                    ;  lehgth of variable to be edited
  172.     lea     bp,[di+38]              ;  address for placing edited text
  173.     mov     ax,CX0                  ;  low part is column
  174.     mov     cl,3                    ;  Numbers of Shift
  175.     shr     ax,cl                   ;  divide value in pixel by 8 to get X
  176.     xor     dx,dx                   ;  high part of number to be edited
  177.     Call    INSYM4                  ;  convert number in DX:AX to string
  178.     mov     si,4                    ;  lehgth of variable to be edited
  179.     lea     bp,[di+48]              ;  address for placing edited text
  180.     mov     ax,DX0                  ;  low part is row
  181.     mov     cl,3                    ;  Numbers of Shift
  182.     shr     ax,cl                   ;  divide value in pixel by 8 to get Y
  183.     xor     dx,dx                   ;  high part of number to be edited
  184.     Call    INSYM4                  ;  convert number in DX:AX to string
  185. ;  Output cursor coordinates and key code
  186.     pop     dx                      ;  address of text buffer
  187.     mov     ah,9                    ;  Output message to screen
  188.     int     21h                     ;  DOS service call
  189.     jmp     ChkKBD                  ;  check whether key was pressed
  190. ;-------------------------------------------------------------------
  191. ;  Terminate program and exit to DOS
  192. Exit:   mov     al,VMODE                ;  remember video mode on entry
  193.     mov     ah,0                    ;  function 0 - set video mode
  194.     int     10h                     ;  BIOS video service
  195.     mov     ah,0Ch                  ;  function 0Ch - flash keyboard buffer
  196.     int     21h                     ;  DOS service call
  197.     mov     ax,4C00h                ;  function 4Ch - terminate process
  198.     int     21h                     ;  DOS service call
  199.     END
  200.