home *** CD-ROM | disk | FTP | other *** search
/ Stars of Shareware: Programmierung / SOURCE.mdf / programm / msdos / asm / 3dvect25 / xmouse.asm < prev    next >
Encoding:
Assembly Source File  |  1993-09-06  |  4.9 KB  |  186 lines

  1.          .386p
  2. code32   segment para public use32
  3.          assume cs:code32, ds:code32
  4.  
  5.          include pmode.inc       ; protected mode externals
  6.          include xmode.inc  ; include externals for xmode routines
  7.          include macros.inc
  8.          include equ.inc
  9.  
  10.          public show_mouse
  11.          public get_mouse_position
  12.          public plot_mouse
  13.          public instant_mouse
  14.          public remove_mouse
  15.          public mousex
  16.          public mousey
  17.          public mbuttons
  18.  
  19. ; x-mode mouse routines in protected mode for 3d vectors source
  20. ;
  21. ; show_mouse (int x, int y)
  22. ; get_mouse_position
  23. ; plot_mouse
  24. ; remove_mouse
  25. ; instant_mouse
  26. ;
  27. ; after ploting mouse, sync_display is called to avoid flickering
  28.  
  29. mousewidth  equ 6
  30. mouseheight equ 6
  31.  
  32. ismouse  db -1
  33.  
  34. mousemap:
  35.          dw mousewidth,mouseheight
  36.          db 9,9,9,9,9,0
  37.          db 9,9,9,9,0,0
  38.          db 9,9,9,9,0,0
  39.          db 9,9,9,9,9,0
  40.          db 9,0,0,9,9,9
  41.          db 0,0,0,0,9,0
  42.  
  43. sm_stack  struc
  44.                 dd  ?   ; ebp
  45.                 dd  ?   ; caller
  46.     setm_ypos   dw  ?   ; y pos of mouse
  47.     setm_xpos   dw  ?   ; x pos of mouse
  48. sm_stack  ends
  49.  
  50. show_mouse:
  51.         push ebp
  52.         call remove_mouse
  53.         mov v86r_ax,0                   ; enable mouse
  54.         mov al,33h
  55.         int 33h
  56.         mov ah,v86r_ah                  ; check if hardware/driver installed
  57.         xor ah,255
  58.         mov ismouse, ah
  59.         jne sm_nomouse                  ; no mouse, exit
  60.  
  61.         mov ebp, esp                    ; set up stack frame
  62.         mov cx, [ebp].setm_xpos
  63.         mov dx, [ebp].setm_ypos
  64.  
  65.         mov v86r_ax,4                   ; position mouse
  66.         mov v86r_cx,cx
  67.         mov v86r_dx,dx
  68.         int 33h
  69.  
  70.         mov v86r_ax,7                   ; set screen size
  71.         mov v86r_cx,0
  72.         mov v86r_dx,(xactual-mousewidth)*2
  73.         int 33h                         ; *2 gives greater resolution!!!!!
  74.  
  75.         mov v86r_ax,8
  76.         mov v86r_cx,0
  77.         mov v86r_dx,(yactual-mouseheight)*2
  78.         int 33h
  79.  
  80.         mov v86r_ax,15                  ; set mouse mickeys (8 = default)
  81.         mov v86r_cx,8
  82.         mov v86r_dx,8
  83.         int 33h
  84.  
  85. sm_nomouse:
  86.         mov firstcall,0                 ; first call to mouse routines, reset
  87.         pop ebp
  88.         ret 4
  89.  
  90. get_mouse_position:
  91.         cmp ismouse,0
  92.         jne gm_nomouse
  93.         mov v86r_ax,3                   ; call bios routines
  94.         mov al,33h
  95.         int 33h
  96.         mov bx,v86r_bx                  ; button status, mid right left=%111
  97.         mov cx,v86r_cx                  ; coloum
  98.         mov dx,v86r_dx                  ; row
  99.         mov mbuttons,bx                 ; save button status
  100.         shr cx,1                        ; compensate for resolution!!!
  101.         shr dx,1
  102.         mov mousex,cx
  103.         mov mousey,dx
  104. gm_nomouse:
  105.         ret
  106.  
  107. ; plot mouse at new location. must be called often because DOS fuctions cannot
  108. ; plot new mouse in x-mode and protected mode cannot handle re-routing of
  109. ; interrupt.  routine is slow but we must wait for a vga sync anyway.
  110.  
  111. savedmap  dw mousewidth,mouseheight
  112.           db mousewidth*mouseheight dup (?)
  113. mousex    dw 0
  114. mousey    dw 0
  115. mbuttons  dw 0
  116. firstcall db 0
  117.  
  118. plot_mouse:
  119.         cmp ismouse,0                   ; plot mouse may need modification
  120.         jne pm_nomouse                  ; if used with page flipping, (save
  121.                                         ; more than one page)
  122.         call remove_mouse
  123.         mov firstcall,1
  124.  
  125.         call get_mouse_position         ; get new mouse location
  126.  
  127.         mov bx, mouseheight             ; counters
  128.         mov ax, mousewidth
  129.         mov si, 4                       ; indexer to bitmap saved data
  130.  
  131. pl_morew:                               ; save data under new cursor
  132.         pusha
  133.         push cx dx
  134.         call read_point
  135.         mov b savedmap[si],al
  136.         popa
  137.         inc si
  138.         inc cx
  139.         dec ax
  140.         cmp ax,0
  141.         jne pl_morew
  142.  
  143.         inc dx
  144.         mov cx,mousex
  145.         mov ax,mousewidth
  146.         dec bx
  147.         cmp bx,0
  148.         jne pl_morew
  149.  
  150.         push o mousemap
  151.         pushw mousex
  152.         pushw mousey
  153.         call tdraw_bitmap               ; draw new mouse
  154. pm_nomouse:
  155.         call sync_display
  156.         ret
  157.  
  158. instant_mouse:
  159.         cmp ismouse,0
  160.         jne im_nomouse
  161.  
  162.         call get_mouse_position         ; get new mouse location
  163.  
  164.         push o mousemap
  165.         pushw mousex
  166.         pushw mousey
  167.         call tdraw_bitmap               ; draw new mouse
  168. im_nomouse:
  169.         ret
  170.  
  171. remove_mouse:
  172.         cmp firstcall,0                ; check if mouse on screen
  173.         je  pl_dontsave
  174.  
  175.         push o savedmap
  176.         pushw mousex
  177.         pushw mousey
  178.         call draw_bitmap                ; restore old data under cursor
  179.         mov firstcall,0                 ; mouse is gone, say so
  180.  
  181. pl_dontsave:
  182.         ret
  183.  
  184. code32  ends
  185.         end
  186.