home *** CD-ROM | disk | FTP | other *** search
/ Megahits 4 / MegaHits_Vol.4.iso / mui / dev / e / amiga-e / source / installhook.e < prev    next >
Encoding:
Text File  |  1994-10-24  |  1.1 KB  |  39 lines

  1. /*
  2. ** installhook() - Use it like this:
  3. **
  4. **   MODULE 'utility/hooks'
  5. **
  6. **   PROC main()
  7. **      DEF myhook:hook
  8. **      installhook(myhook, {myhookfunc})
  9. **      /* do something with myhook */
  10. **   ENDPROC
  11. **
  12. **   PROC myhookfunc(hook,obj,msg)
  13. **      WriteF('hook:$\h, obj:\d, msg:\d\n',hook,obj,msg)
  14. **   ENDPROC
  15. */
  16.  
  17. PROC installhook(hook,func)
  18.    DEF r
  19.    MOVE.L hook,A0
  20.    MOVE.L func,12(A0)    /* store address of func in hook.subentry */
  21.    LEA hookentry(PC),A1
  22.    MOVE.L A1,8(A0)       /* store address of hookentry in hook.entry */
  23.    MOVE.L A4,16(A0)      /* store ptr to vars in hook.data */
  24.    MOVE.L A0,r
  25. ENDPROC r
  26.  
  27. hookentry:
  28.   MOVEM.L D2-D7/A2-A6,-(A7)
  29.   MOVE.L 16(A0),A4      /* move ptr to vars to A4 */
  30.   MOVE.L A0,-(A7)       /* move ptr to hookstructure to the stack */
  31.   MOVE.L A2,-(A7)       /* move ptr to obj to the stack */
  32.   MOVE.L A1,-(A7)       /* move msg to the stack */
  33.   MOVE.L 12(A0),A0      /* move addr. of hookfunc. to A0 */
  34.   JSR (A0)              /* call hookfunc. */
  35.   LEA 12(A7),A7         /* remove the above from the stack */
  36.   MOVEM.L (A7)+,D2-D7/A2-A6
  37.   RTS                   /* go back to the caller (MUI) */
  38.  
  39.