home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Extras / Development / Example_Code_v37 / Libraries / Intuition / boopsi / classface.asm < prev    next >
Encoding:
Assembly Source File  |  1996-03-17  |  4.3 KB  |  168 lines

  1. *  classface.asm - Intuition object/class method invocation
  2. *  converts "standard" C calling conventions to appropriate
  3. *  hook conventions.
  4. *
  5. * Code in here "freezes" these facts (and no others):
  6. *    - pointer to an object's class immediately precedes the object pointer
  7. *    - pointer to a class's superclass is (h_SIZEOF+4) into the class
  8.  
  9.     INCLUDE 'exec/types.i'
  10.     INCLUDE 'exec/nodes.i'
  11.  
  12.     INCLUDE 'utility/hooks.i'
  13.  
  14.     section    text,code
  15.  
  16. * varargs interfaces for invoking method functions
  17.     xdef    _DoMethod
  18.     xdef    _DoSuperMethod
  19.     xdef    _CoerceMethod
  20.     xdef    _SetSuperAttrs
  21.  
  22. * corresponding method invocations for a pre-packaged parameter
  23. * "message" packet
  24.     xdef    _DM
  25.     xdef    _DSM
  26.     xdef    _CM
  27.  
  28. * DoMethod( o, method_id, param1, param2, ... )
  29. * Invoke upon an object the method function defined by an object's class.
  30. * This function (with its "short form" DM() ) is the only one that
  31. * you should use unless you are implementing a class.
  32. *
  33. _DoMethod:
  34.     move.l    a2,-(a7)    ; rely on a6 being preserved
  35.     move.l    8(sp),a2    ; object
  36.     move.l    a2,d0        ; be safe
  37.     beq.s    cmnullreturn
  38.     lea    12(sp),a1    ; message
  39.     move.l    -4(a2),a0    ; object class ptr precedes object
  40.  
  41.     bra.s    cminvoke    ; will cleanup a2
  42.     ; ----- don't return here
  43.  
  44. * DoSuperMethod( cl, o, method_id, param1, param2, ... )
  45. * Invoke upon an object the method defined for the superclass
  46. * of the class specified.  In a class implementation, you
  47. * are passed a pointer to the class you are implementing, which
  48. * you pass to this function to send a message to the object
  49. * considered as a member of your superclass.
  50. *
  51. _DoSuperMethod:
  52.     move.l    a2,-(a7)    ; rely on a6 being preserved
  53.     movem.l    8(sp),a0/a2    ; class, object
  54.     move.l    a2,d0        ; be safe (object)
  55.     beq.s    cmnullreturn
  56.     move.l    a0,d0        ; be safe (class)
  57.     beq.s    cmnullreturn
  58.     lea    16(sp),a1    ; message
  59.     move.l    h_SIZEOF+4(a0),a0    ; substitute superclass
  60.  
  61.     bra.s    cminvoke    ; will cleanup a2
  62.     ; ----- don't return here
  63.  
  64. * CoerceMethod( cl, o, method_id, param1, param2, ... );
  65. * Invoke upon the given object a method function for whatever
  66. * specified class.  This is sort of the primitive basis behind
  67. * DoMethod and DoSuperMethod.
  68. *
  69. _CoerceMethod:
  70.     move.l    a2,-(a7)    ; rely on a6 being preserved
  71.     movem.l    8(sp),a0/a2    ; get hook and object
  72.     move.l    a2,d0        ; be safe (object)
  73.     beq.s    cmnullreturn
  74.     move.l    a0,d0        ; be safe (class)
  75.     beq.s    cmnullreturn
  76.     lea    16(sp),a1    ; varargs version
  77.     ; --- registers ready, now call hook
  78.     bra.s    cminvoke
  79.     ; ----- don't return here
  80.  
  81.  
  82. * CM( a0: cl, a2: o, a1: msg )
  83. * This is CoerceMethod for prepackaged "message" packets
  84. *
  85. _CM:
  86.     move.l    a2,-(a7)    ; rely on a6 being preserved
  87.     movem.l    8(sp),a0/a2    ; get class and object
  88.     move.l    a2,d0
  89.     beq.s    cmnullreturn
  90.     move.l    a0,d0
  91.     beq.s    cmnullreturn
  92.     move.l    16(sp),a1    ; get msg
  93.     ; --- registers ready, now call hook
  94.  
  95.     ; --- performs call to hook in A0 and restores a2
  96. cminvoke:
  97.     pea.l    cmreturn(pc)
  98.     move.l    h_Entry(a0),-(sp)
  99.     rts
  100. cmnullreturn:
  101.     moveq.l    #0,d0
  102. cmreturn:
  103.     move.l    (sp)+,a2
  104.     rts
  105.  
  106.  
  107. * DM( o, msg )
  108. * This is DoMethod for prepackaged "message" packets
  109. _DM:
  110.     move.l    a2,-(a7)    ; rely on a6 being preserved
  111.     move.l    8(sp),a2    ; object
  112.     move.l    a2,d0
  113.     beq.s    cmnullreturn
  114.     move.l    12(sp),a1    ; message
  115.     move.l    -4(a2),a0    ; object class precedes object
  116.  
  117.     bra.s    cminvoke    ; will cleanup a2
  118.     ; ----- don't return here
  119.  
  120.  
  121. * DSM( cl, o, msg )
  122. * This is DoSuperMethod for prepackaged "message" packets
  123. _DSM:
  124.     move.l    a2,-(a7)    ; rely on a6 being preserved
  125.     movem.l    8(sp),a0/a2    ; class, object
  126.     move.l    a2,d0
  127.     beq.s    cmnullreturn
  128.     move.l    a0,d0
  129.     beq.s    cmnullreturn
  130.     move.l    16(sp),a1    ; message
  131.     move.l    h_SIZEOF+4(a0),a0    ; substitute superclass
  132.  
  133.     bra.s    cminvoke    ; will cleanup a2
  134.     ; ----- don't return here
  135.  
  136.  
  137. * SetSuperAttrs( cl, o, tag1, data1, ..., TAG_END );
  138. * A useful varargs conversion to the proper OM_SET method.
  139. _SetSuperAttrs:
  140.     move.l    a2,-(a7)    ; save
  141.  
  142.     movem.l    8(sp),a0/a2    ; class, object
  143.     move.l    a2,d0        ; be safe (object)
  144.     beq.s    cmnullreturn
  145.     move.l    a0,d0        ; be safe (class)
  146.     beq.s    cmnullreturn
  147.  
  148.     move.l    h_SIZEOF+4(a0),a0    ; substitute superclass
  149.  
  150.     ; -----    build msg packet on the stack
  151.     move.l    #0,-(sp)    ; NULL GadgetInfo
  152.     pea.l    4+16(sp)    ; address of tags on deeper stack
  153.     move.l    #$103,-(sp)    ; MethodID OM_SET
  154.     lea.l    (sp),a1        ; put the address of the whole thing in a1
  155.  
  156.     pea.l    ssaret(pc)
  157.     move.l    h_Entry(a0),-(sp)
  158.     rts
  159.  
  160. ssaret:
  161.     ; -----    return here to clean up stack
  162.     lea.l    12(sp),sp    ; pop off three long parameters
  163.     move.l    (sp)+,a2    ; pop/restore original a2
  164.     rts
  165.  
  166.  
  167.     end
  168.