home *** CD-ROM | disk | FTP | other *** search
/ ftp.update.uu.se / ftp.update.uu.se.2014.03.zip / ftp.update.uu.se / pub / rainbow / msdos / decus / RB140 / grlib03a.arj / MSINT.ASM < prev    next >
Assembly Source File  |  1988-12-08  |  8KB  |  255 lines

  1. TITLE MSINT.ASM Microsoft Mouse interrupt service
  2. PAGE    ,132
  3. ;***********************************************
  4. ;                                              *
  5. ;   Microuse Mouse hardware dependent code     *
  6. ;   Copyright (C) 1983,1984 by Microsoft Inc.  *
  7. ;   Copyright (C) 1984 by Digital Equipment Co.*
  8. ;                                              *
  9. ;***********************************************
  10.  
  11. include asmms.h
  12. include asmc.h
  13.  
  14. ;**********************************************
  15. ; Static data internal to interrupt handler   *
  16. ;**********************************************
  17. int_cond        DW  0               ; temp store - state check
  18. tdelta_x        DB  0
  19. tdelta_y        DB  0
  20. mstate          DB  0               ; zero means looking for sync bit
  21. m_buffer    DD  0               ; ADR Communications input circular buffer
  22. Mpacket        DD  0               ; ADR MOUSE control packet  "MOUSE_PACKET"
  23. Cpacket        DD  0               ; ADR MOUSE int. cond. "CONDITION_PACKET"
  24.  
  25. SUBTTL Comms Port Interrupt Handler
  26. PAGE
  27. ;**********************************************
  28. ;   Serial Mouse hardware interrupt service   *
  29. ;**********************************************
  30.  
  31.     PUBLIC    MSint_, _Chaddr
  32.  
  33. Msint_    PROC    FAR
  34.  
  35.     Cld                ;preserve machine state
  36.     Push    DS
  37.     Push    ES
  38.     Push    AX
  39.     Push    BX
  40.     Push    CX
  41.     Push    DX
  42.     Push    DI
  43.     Push    SI
  44. ;
  45. ;  get a delta x in bx, delta y in cx
  46. ;
  47.     call    getchar            ;get a character from ring buffer
  48.     Lds    SI,CS:Mpacket        ;DS:SI = MOUSE_PACKET
  49.     Les    DI,CS:Cpacket        ;ES:DI = CONDITION_PACKET
  50.         test    al,01000000b            ;sync bit set?
  51.         jnz     first_byte
  52.         jmp     xory
  53.  
  54. ;------------------------------------
  55. ; first byte of new 3 byte packet
  56. ;  process button information
  57. ;------------------------------------
  58. ;
  59. ;    first byte
  60. ;
  61. ;    +----+----+----+----+----+----+----+----+
  62. ;    | D7 | D6 | D5 | D4 | D3 | D2 | D1 | D0 |
  63. ;    +----+----+----+----+----+----+----+----+
  64. ;      |    |    |    |    |    |    |    |
  65. ;      |    |    |    |    |    |    |    +---- X6
  66. ;      |    |    |    |    |    |    +--------- X7
  67. ;      |    |    |    |    |    +-------------- Y6
  68. ;      |    |    |    |    +------------------- Y7
  69. ;      |    |    |    +------------------------ RIGHT MOUSE BUTTON
  70. ;      |    |    +----------------------------- LEFT MOUSE BUTTON
  71. ;      |    +---------------------------------- 1 = FIRST BYTE (SYNCHRONIZE)
  72. ;      +--------------------------------------- 7 BIT ASCII (MUST MASK)
  73. ;
  74. first_byte:
  75.         xor     dx,dx               ; indicate primary button up
  76.         mov     CS:[int_cond],dx       ; zero interrupt conditions
  77.         mov     dl,al               ; get local copy of button state
  78.         mov     cl,5            ; isolate the left mouse button 
  79.         shr     dl,cl               ;    low bit has p button state
  80.         mov     cx,1                ;    set up mask
  81.         and     dx,cx            ;    mask off low bit
  82.         not     cx                        ; invert
  83.         and     cx,[SI].Bstate         ; get all other bits
  84.         or      dx,cx                     ; dx = new button states
  85.         xchg    [SI].Bstate,dx         ; move in current state get old state
  86.         cmp     [SI].Bstate,dx         ; has it changed?
  87.     sti                ;INTS OFF while we update
  88.         jz      no_pb_change
  89.         ja      pb_down
  90. ;
  91. ; primary button just released
  92. ;
  93.         or      CS:byte ptr [int_cond],00000100b
  94.     inc    ES:WORD PTR [DI].P_button_rel
  95.         jmp     short no_pb_change
  96. ;
  97. ; primary button just pressed
  98. ;
  99. pb_down:
  100.         or      CS:byte ptr [int_cond],00000010b
  101.     inc    ES:WORD PTR [DI].P_button_dep
  102. no_pb_change:
  103.     cli                ;INTS ON now done
  104.         mov     dl,al               ; get local copy of button state
  105.         mov     cl,3
  106.         shr     dl,cl               ; low bit has s button state
  107.         mov     cx,2                ; mask off low bit
  108.         and     dx,cx
  109.         not     cx                  ; invert
  110.         and     cx,[SI].Bstate      ; get all other bits
  111.         or      dx,cx               ; dx = new button states
  112.         xchg    [SI].Bstate,dx      ; move in current state get old state
  113.         cmp     [SI].Bstate,dx      ; has it changed
  114.     sti                ;INTS OFF while we update
  115.         jz      no_sb_change
  116.         ja      sb_down
  117. ;
  118. ; secondary button just released
  119. ;
  120.         or      CS:byte ptr [int_cond],00010000b
  121.     inc    ES:WORD PTR [DI].S_button_rel
  122.         jmp     short no_sb_change
  123. ;
  124. ; secondary button just pressed
  125. ;
  126. sb_down:
  127.         or      CS:byte ptr [int_cond],00001000b
  128.     inc    ES:WORD PTR [DI].S_button_dep
  129. no_sb_change:
  130.     cli                ;INTS ON now done
  131.         mov     bx,ax               ; save first byte info
  132.         mov     cl,4
  133.         shl     ax,cl
  134.         and     al,11000000b
  135.         mov     CS:[tdelta_y],al    ; save hibits of delta Y
  136.         mov     cl,6
  137.         shl     bx,cl
  138.         and     bl,11000000b
  139.         mov     CS:[tdelta_x],bl    ; save hibits of delta X
  140.         mov     CS:[mstate],1      ; now we are looking for x...
  141.         jmp     short ignore
  142.  
  143. ;------------------------------------
  144. ;Process non SYNC byte
  145. ;------------------------------------
  146. xory:
  147.         and     al,00111111b
  148.         cmp     CS:[mstate],1              ; are we looking for x (byte 2)
  149.         jb      ignore                  ; if zero, ignore, we want sync
  150.         ja      do_tdelta_y              ; if above, must be for y (byte 3)
  151.         or      CS:[tdelta_x],al
  152.         mov     CS:[mstate],2          ; now we are looking for y...
  153.  
  154. ignore:
  155.         xor     ax,ax
  156.         jmp     short ack
  157.  
  158. ;------------------------------------
  159. ;Process end of packet
  160. ;------------------------------------
  161. do_tdelta_y:
  162.         or      al,CS:[tdelta_y]
  163.         cbw
  164.         mov     cx,ax            ;Delta Y in CX
  165.         mov     al,CS:[tdelta_x]
  166.         cbw
  167.         mov     bx,ax            ;Delta X in BX
  168.         mov     CS:[mstate],0
  169.         mov     ax,bx                   ; get horizontal motion
  170.         or      ax,cx                   ; or in vertical motion
  171.         jz      nomove                  ; if zero, cursor didnt move
  172.     sti                ;INTS OFF while we update
  173.     add    [SI].Deltax,bx            ; update Delta X
  174.     add    [SI].Deltay,cx            ; update delta Y
  175.         or      CS:byte ptr [int_cond],00000001b   ; cursor moved..remember
  176.     cli                ;INTS ON now done
  177. nomove: mov     ax,CS:[int_cond]        ; ax=reason for calling MS-WIN
  178.  
  179. ack:
  180.     Pop    SI        ;restore state
  181.     Pop    DI
  182.     Pop    DX
  183.     Pop    CX
  184.     Pop    BX
  185.     Pop    AX
  186.     Pop    ES
  187.     Pop    DS
  188.         ret
  189.  
  190. ;GETCHAR - routine to fetch next character out of m_buffer
  191.  
  192. getchar    PROC    NEAR
  193.     Lds    SI,CS:m_buffer        ;DS:SI = M_buffer
  194.     mov    ax,[SI].count        ;pick up char count
  195.     and    ax,ax            ;any char avail?
  196.     jz    getcha3
  197.     sti                ;INTS OFF while we update
  198.     dec    ax            ;decrement char count
  199.     mov    [SI].count,ax        ;update buffer count
  200.     mov    BX,[SI].opntr        ;character pntr
  201.     mov    ax,[BX]
  202.     cmp    BX,[SI].tail        ;at end?
  203.     jnz    getcha1
  204.     mov    BX,[SI].head        ;yes - point at head
  205.     jmp short getcha2
  206.  
  207. getcha1:
  208.     inc    BX            ;step to next char
  209.     inc    BX
  210. getcha2:
  211.     mov    [SI].opntr,BX        ;save new pntr
  212.     cli                ;INTS ON now done
  213. getcha3:
  214.     ret                ;return (char in AX)
  215.  
  216. getchar    ENDP
  217.  
  218. MSint_   ENDP
  219.  
  220. SUBTTL establish links with C program
  221. PAGE
  222.     ASSUME    ES:NOTHING
  223. ;***********************************************
  224. ;Return Address for C program
  225. ;***********************************************
  226.  
  227. ; CS:OFFSET = _Chaddr(mptr,cptr,buffer);
  228. ; CONDITION_PACKET *mptr;
  229. ; MOUSE_PACKET *cptr
  230. ; char *buffer;
  231.  
  232.     PROCDEF    _Chaddr
  233.  
  234.     Push    BP
  235.     Mov    BP,SP
  236.     Mov    AX,@AB[BP]        ;  Mpacket = mptr
  237.     Mov    CS:WORD PTR Mpacket,AX
  238.     Mov    CS:WORD PTR Mpacket+2, DS
  239.     Mov    AX,@AB+2[BP]        ;  Cpacket = cptr
  240.     Mov    CS:WORD PTR Cpacket,AX
  241.     Mov    CS:WORD PTR Cpacket+2, DS
  242.     Mov    AX,@AB+4[BP]        ;  m_buffer = buffer
  243.     Mov    CS:WORD PTR m_buffer,AX
  244.     Mov    CS:WORD PTR m_buffer+2, DS
  245.     Mov    AX, CS:Cloc        ;  return interrupt offset
  246.     Mov    SP,BP
  247.     Pop    BP
  248.     Ret
  249. Cloc    Dw    MSint_
  250.     PROCEND    _Chaddr
  251.  
  252. include epilogue.h
  253.     END
  254. 
  255.