home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Extras / Development / RKM_Companion_v2.04 / Clipboard / hookface.a < prev    next >
Encoding:
Text File  |  1999-10-27  |  4.0 KB  |  117 lines

  1. *
  2. * Copyright (c) 1992-1999 Amiga, Inc.
  3. * This example is provided in electronic form by Amiga, Inc. for 
  4. * use with the "Amiga ROM Kernel Reference Manual: Devices", 3rd Edition, 
  5. * published by Addison-Wesley (ISBN 0-201-56775-X).
  6. * The "Amiga ROM Kernel Reference Manual: Devices" contains additional 
  7. * information on the correct usage of the techniques and operating system 
  8. * functions presented in these examples.  The source and executable code 
  9. * of these examples may only be distributed in free electronic form, via 
  10. * bulletin board or as part of a fully non-commercial and freely 
  11. * redistributable diskette.  Both the source and executable code (including 
  12. * comments) must be included, without modification, in any copy.  This 
  13. * example may not be published in printed form or distributed with any
  14. * commercial product.  However, the programming techniques and support
  15. * routines set forth in these examples may be used in the development
  16. * of original executable software products for Amiga computers.
  17. * All other rights reserved.
  18. * This example is provided "as-is" and is subject to change; no
  19. * warranties are made.  All use is at your own risk. No liability or
  20. * responsibility is assumed.
  21. *
  22. *
  23. ****************************************************************************
  24. *
  25. *        Hookface.asm
  26. *        assembly routines for Chtest
  27. *
  28. *        Assemble with Adapt  hx68 hookface.a to hookface.o
  29. *
  30. *        Link with Changehook_Test.o as shown in Changehook_Test.c header
  31. *
  32. ****************************************************************************
  33. *
  34. *       CSECT   hookface                 ;SAS/Lattice ASM command needs this
  35. *
  36. *       INCDIR  'include:'               ;HX68 assembler needs this
  37.  
  38.     section    text,code
  39.  
  40.         INCLUDE 'exec/types.i'
  41.         INCLUDE 'utility/hooks.i'
  42.         xdef    _callHook
  43.         xdef    _callHookPkt
  44.         xdef    _hookEntry
  45.         xdef    _stubReturn
  46.  
  47. ***************************************************************************
  48. * new hook standard
  49. * use struct Hook (with minnode at the top)
  50. *
  51. * *** register calling convention: ***
  52. *       A0 - pointer to hook itself
  53. *       A1 - pointer to parameter packed ("message")
  54. *       A2 - Hook specific address data ("object," e.g, gadget )
  55. *
  56. * ***  C conventions: ***
  57. * Note that parameters are in unusual register order: a0, a2, a1.
  58. * This is to provide a performance boost for assembly language
  59. * programming (the object in a2 is most frequently untouched).
  60. * It is also no problem in "register direct" C function parameters.
  61. *
  62. * calling through a hook
  63. *       callHook( hook, object, msgid, p1, p2, ... );
  64. *       callHookPkt( hook, object, msgpkt );
  65. *
  66. * using a C function:   CFunction( hook, object, message );
  67. *       hook.h_Entry = hookEntry;
  68. *       hook.h_SubEntry = CFunction;
  69. ****************************************************************************
  70.  
  71. * C calling hook interface for prepared message packet
  72. _callHookPkt:
  73.         movem.l a2/a6,-(sp)     ; protect
  74.         move.l  12(sp),a0       ; hook
  75.         move.l  16(sp),a2       ; object
  76.         move.l  20(sp),a1       ; message
  77.         ; ------ now have registers ready, invoke function
  78.         pea.l   hreturn(pc)
  79.         move.l  h_Entry(a0),-(sp)       ; old rts-jump trick
  80.         rts
  81. hreturn:
  82.         movem.l (sp)+,a2/a6
  83.         rts
  84.  
  85. * C calling hook interface for "varargs message packet"
  86. _callHook:
  87.         movem.l a2/a6,-(sp)     ; protect
  88.         move.l  12(sp),a0       ; hook
  89.         move.l  16(sp),a2       ; object
  90.         lea.l   20(sp),a1       ; message
  91.         ; ------ now have registers ready, invoke function
  92.         pea.l   hpreturn(pc)
  93.         move.l  h_Entry(a0),-(sp)       ; old rts-jump trick
  94.         rts
  95. hpreturn:
  96.         movem.l (sp)+,a2/a6
  97.         rts
  98.  
  99. * entry interface for C code (large-code, stack parameters)
  100. _hookEntry:
  101.         move.l  a1,-(sp)
  102.         move.l  a2,-(sp)
  103.         move.l  a0,-(sp)
  104.         move.l  h_SubEntry(a0),a0       ; C entry point
  105.         jsr     (a0)
  106.         lea     12(sp),sp
  107. _stubReturn:
  108.         rts
  109. *
  110. *                                        ;SAS/Lattice ASM command needs this
  111.         END
  112.  
  113.