home *** CD-ROM | disk | FTP | other *** search
/ Computer Select (Limited Edition) / Computer Select.iso / dobbs / v17n03 / oopasm.exe / DISPATCH.ASM < prev    next >
Encoding:
Assembly Source File  |  1990-07-13  |  4.4 KB  |  175 lines

  1.     .MODEL    SMALL
  2.  
  3.     INCLUDE    equates.inc
  4.     INCLUDE    instance.inc
  5.     INCLUDE    messages.inc
  6.     INCLUDE    objects.inc
  7.  
  8. IF1
  9.     INCLUDE    macros.mac
  10.     INCLUDE    objects.mac
  11. ENDIF
  12.  
  13.     EXTRN    clrNextContext:NEAR
  14.     EXTRN    sendMsg:NEAR
  15.  
  16.     EXTRN    Hardware:WORD
  17.     EXTRN    KeyBoard:WORD
  18.     EXTRN    Mouse:WORD
  19.     EXTRN    Self:WORD
  20.  
  21.     .CODE
  22.  
  23.     PUBLIC    readEvent
  24. COMMENT    %
  25. ==============================================================================
  26. Dispatches keyboard events to appropriate handler.
  27.  
  28. =============================================================================%
  29. readEvent    PROC    NEAR
  30. rdt1:    push        Self
  31.     send        Hardware,Refresh    ;Update devices' status
  32.     send        Hardware,Read        ;Read input devices
  33.     pop        Self
  34.     getInst        al,?NewState,Mouse    ;Get new state flag
  35.     identity    al,rdt2            ;Jump if new state
  36.     getInst        ah,ScanCode,Keyboard    ;Get scan code
  37.     null        ah,rdt1            ;Loop if no key pressed
  38.  
  39.     call        findKeyHandler        ;Find handler from key event
  40.     jmp        rdt3
  41.  
  42. rdt2:    call        findMouseHandler    ;Find handler from mouse event
  43.  
  44. rdt3:    call        passMsg            ;Pass message
  45.     null        bx,rdt1            ;Nil? - Keep reading
  46.  
  47.     mov        Wptr[Self],bx        ;Get new Self
  48.     jmp        rdt1            ;Keep reading
  49.     ret
  50. readEvent    ENDP
  51.  
  52.  
  53.  
  54. COMMENT    %
  55. ==============================================================================
  56. Finds appropriate handler for given keyboard event.
  57.  
  58. Passed:    si - Pointer to Keyboard instance variable structure
  59.  
  60. Passes:    si - Pointer to event handler record
  61.  
  62. =============================================================================%
  63. findKeyHandler    PROC    NEAR
  64.     getInst        al,AsciiCode        ;Get ASCII code
  65.     getInst        si,DispTbl,Self        ;Pointer to dispatch tbl
  66.  
  67. fkh1:    eq        al,Bptr[si],fkh3    ;Jump if match on ASCII code
  68. fkh2:    add        si,10            ;Point to next entry
  69.     identity    Bptr[si],fkh1,fkh4    ;Loop if more else use default
  70.  
  71. fkh3:    neq        ah,Bptr[si+1],fkh2    ;Jump if no match
  72. fkh4:    ret
  73. findKeyHandler    ENDP
  74.  
  75.  
  76.  
  77. COMMENT    %
  78. ==============================================================================
  79. Finds appropriate handler for given mouse event.
  80.  
  81. Passed:    si - Pointer to Mouse instance variable structure
  82.  
  83. Passes:    si - Pointer to event handler record
  84.  
  85. =============================================================================%
  86. findMouseHandler    PROC    NEAR
  87.     getInst        al,Row1            ;Get mouse row
  88.     getInst        ah,Col1            ;Get mouse column
  89.     getInst        bl,Status        ;Get button status
  90.     getInst        si,DispTbl,Self        ;Pointer to dispatch tbl
  91.  
  92. fmh1:    null        Bptr[si+2],fmh3        ;Jump on don't care status
  93.     eq        bl,Bptr[si+2],fmh3    ;Else jump on status match
  94. fmh2:    add        si,10            ;Point to next entry
  95.     identity    Bptr[si+3],fmh1,fmh7    ;Loop if more else use default
  96.  
  97. fmh3:    moreThanEq    al,Bptr[si+3],fmh4    ;Jump if >= upper row
  98.     jmp        fmh2
  99.  
  100. fmh4:    lessThanEq    al,Bptr[si+5],fmh5     ;Jump if <= lower row
  101.     jmp        fmh2
  102.  
  103. fmh5:    moreThanEq    ah,Bptr[si+4],fmh6    ;Jump if >= left column
  104.     jmp        fmh2
  105.  
  106. fmh6:    moreThan    ah,Bptr[si+6],fmh2    ;Jump if > right column
  107. fmh7:    ret
  108. findMouseHandler    ENDP
  109.  
  110.  
  111.  
  112. COMMENT    %
  113. ==============================================================================
  114. Passes message to object in a dispatch table entry.
  115.  
  116. Passed:    si - Pointer to dispatch table entry
  117.  
  118. Passes:    bx - Pointer to next object providing dispatch table
  119.  
  120. =============================================================================%
  121. passMsg    PROC    NEAR
  122.     sendLoop    si,7,8            ;Send messages
  123.     getInst        bx,NextContext,Dispatch    ;Get next obj
  124.     setInst        NextContext,Nil,,2    ;Clear next obj
  125.     ret
  126. passMsg    ENDP
  127.  
  128.  
  129.  
  130. COMMENT    %
  131. ==============================================================================
  132. Sets the next object to be the dispatch table source.
  133.  
  134. =============================================================================%
  135. setNextContext    PROC    NEAR
  136.     mov        ax,Wptr[Self]        ;Get current object
  137.     setInst        NextContext,ax,Dispatch    ;Set it as next context
  138.     ret
  139. setNextContext    ENDP
  140.  
  141.  
  142.  
  143. COMMENT    %
  144. ==============================================================================
  145. Updates hardware to return devices to normal state.
  146.  
  147. =============================================================================%
  148. updateHardware    PROC    NEAR
  149.     push        Self
  150.     send        Hardware,Update        ;Update devices
  151.     pop        Self
  152.     ret
  153. updateHardware    ENDP
  154.  
  155.     
  156.     .DATA
  157.  
  158. defMsg    Dispatch,\
  159.     Read,\
  160.     <,,setNextContext>
  161.  
  162. defMsg    Dispatch,\
  163.     Clear,\
  164.     <updateHardware,,clrNextContext>
  165.  
  166. defObj    Dispatch,\
  167.     <>,\
  168.     <NextContext,2,Nil>,\
  169.     <Read,Clear>
  170.  
  171.  
  172.  
  173.     END
  174. 
  175.