home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 2 / goldfish_vol2_cd1.bin / files / dev / c / rkrm / clipboard / hookface.a < prev    next >
Text File  |  1992-09-03  |  4KB  |  114 lines

  1. *
  2. * Copyright (c) 1992 Commodore-Amiga, Inc.
  3. * This example is provided in electronic form by Commodore-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 Commodore 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.         INCLUDE 'exec/types.i'
  38.         INCLUDE 'utility/hooks.i'
  39.         xdef    _callHook
  40.         xdef    _callHookPkt
  41.         xdef    _hookEntry
  42.         xdef    _stubReturn
  43.  
  44. ***************************************************************************
  45. * new hook standard
  46. * use struct Hook (with minnode at the top)
  47. *
  48. * *** register calling convention: ***
  49. *       A0 - pointer to hook itself
  50. *       A1 - pointer to parameter packed ("message")
  51. *       A2 - Hook specific address data ("object," e.g, gadget )
  52. *
  53. * ***  C conventions: ***
  54. * Note that parameters are in unusual register order: a0, a2, a1.
  55. * This is to provide a performance boost for assembly language
  56. * programming (the object in a2 is most frequently untouched).
  57. * It is also no problem in "register direct" C function parameters.
  58. *
  59. * calling through a hook
  60. *       callHook( hook, object, msgid, p1, p2, ... );
  61. *       callHookPkt( hook, object, msgpkt );
  62. *
  63. * using a C function:   CFunction( hook, object, message );
  64. *       hook.h_Entry = hookEntry;
  65. *       hook.h_SubEntry = CFunction;
  66. ****************************************************************************
  67.  
  68. * C calling hook interface for prepared message packet
  69. _callHookPkt:
  70.         movem.l a2/a6,-(sp)     ; protect
  71.         move.l  12(sp),a0       ; hook
  72.         move.l  16(sp),a2       ; object
  73.         move.l  20(sp),a1       ; message
  74.         ; ------ now have registers ready, invoke function
  75.         pea.l   hreturn(pc)
  76.         move.l  h_Entry(a0),-(sp)       ; old rts-jump trick
  77.         rts
  78. hreturn:
  79.         movem.l (sp)+,a2/a6
  80.         rts
  81.  
  82. * C calling hook interface for "varargs message packet"
  83. _callHook:
  84.         movem.l a2/a6,-(sp)     ; protect
  85.         move.l  12(sp),a0       ; hook
  86.         move.l  16(sp),a2       ; object
  87.         lea.l   20(sp),a1       ; message
  88.         ; ------ now have registers ready, invoke function
  89.         pea.l   hpreturn(pc)
  90.         move.l  h_Entry(a0),-(sp)       ; old rts-jump trick
  91.         rts
  92. hpreturn:
  93.         movem.l (sp)+,a2/a6
  94.         rts
  95.  
  96. * entry interface for C code (large-code, stack parameters)
  97. _hookEntry:
  98.         move.l  a1,-(sp)
  99.         move.l  a2,-(sp)
  100.         move.l  a0,-(sp)
  101.         move.l  h_SubEntry(a0),a0       ; C entry point
  102.         jsr     (a0)
  103.         lea     12(sp),sp
  104. _stubReturn:
  105.         rts
  106. *
  107. *                                        ;SAS/Lattice ASM command needs this
  108. *       END
  109.  
  110.