home *** CD-ROM | disk | FTP | other *** search
/ Computer Select (Limited Edition) / Computer Select.iso / dobbs / v17n03 / oopasm.exe / OBJECTS.MAC < prev    next >
Encoding:
Text File  |  1990-12-13  |  10.7 KB  |  490 lines

  1. COMMENT    %
  2. ==============================================================================
  3. Defines an object.
  4.  
  5. Passed:    Obj - Object name
  6.     Objs - Ancestor list
  7.     Instances - Instance variable list
  8.     Messages - Message list
  9.  
  10. =============================================================================%
  11. defObj    MACRO    Obj,Objs,Instances,Messages
  12.     LOCAL    ObjTbl,MsgTbl,InstTbl
  13.  
  14.     ObjTbl        LABEL    WORD
  15.     objsDef        Obj,<Objs>
  16.  
  17.     MsgTbl        LABEL    WORD
  18.     msgsDef        Obj,<Messages>
  19.  
  20.     InstTbl        LABEL    WORD
  21.     instDef        <Instances>
  22.  
  23.     ALIGN    2
  24.     PUBLIC    Obj
  25.     Obj    _Object        <ObjTbl,MsgTbl,InstTbl>
  26.  
  27.     ENDM
  28.  
  29.  
  30.  
  31. COMMENT    %
  32. ==============================================================================
  33. Defines objects.
  34.  
  35. Passed:    Obj - Object name
  36.     Objs - Ancestor list
  37.  
  38. =============================================================================%
  39. objsDef    MACRO    Obj,Objs
  40.     DW        Obj
  41.     IRP        Obj,<Objs>
  42.     DW        Obj
  43.     ENDM
  44.     ENDM
  45.  
  46.  
  47.  
  48. COMMENT    %
  49. ==============================================================================
  50. Defines messages.
  51.  
  52. Passed:    Obj - Object name
  53.     Messages - Message list
  54.  
  55. =============================================================================%
  56. msgsDef    MACRO    Obj,Messages
  57.     IRP        Msg,<Messages>
  58.     DB        Msg            ;Msg# identifies msg
  59.     IFNDEF        Obj&&Msg
  60.     DW        Nil            ;Obj has no local methods
  61.     ELSE
  62.     DW        Obj&&Msg        ;Obj has local methods
  63.     ENDIF
  64.     ENDM
  65.     ENDM
  66.  
  67.  
  68.  
  69. COMMENT    %
  70. ==============================================================================
  71. Defines instances variables.
  72.  
  73. Passed:    Instances - Instance variable list
  74.  
  75. =============================================================================%
  76. instDef    MACRO    Instances
  77.     X    =    0
  78.     Y    =    0
  79.     IRP        Inst,<Instances>
  80.     defInst        Inst,%X,%Y
  81.     ENDM
  82.     ENDM
  83.  
  84.  
  85.  
  86. COMMENT    %
  87. ==============================================================================
  88. Defines an instance variable.
  89.  
  90. Passed:    Inst - Instance variable name
  91.     Cnt - Instance variable field number
  92.     Size - Size of instance variable
  93.  
  94. =============================================================================%
  95. defInst    MACRO    Inst,Cnt,Size
  96.     IFIDN        <Cnt>,<0>
  97.     X    =    X+1
  98.     ELSE
  99.     IFIDN        <Cnt>,<1>
  100.     X    =    X+1
  101.     Y    =    Inst
  102.     ELSE
  103.     X    =    0
  104.     defVar        Size,Inst
  105.     ENDIF
  106.     ENDIF
  107.     ENDM
  108.  
  109.  
  110.  
  111. COMMENT    %
  112. ==============================================================================
  113. Defines a data item.
  114.  
  115. Passed:    Size - Size of data in bytes
  116.     Value - Value of data item
  117.  
  118. =============================================================================%
  119. defVar    MACRO    Size,Value
  120.     IFIDN        <Size>,<1>
  121.     DB        Value
  122.     ELSE
  123.     IFIDN        <Size>,<2>
  124.     DW        Value
  125.     ELSE
  126.     IFIDN        <Size>,<4>
  127.     DD        Value
  128.     ELSE
  129.     IFIDN        <Size>,<8>
  130.     DQ        Value
  131.     ELSE
  132.     IFIDN        <Size>,<10>
  133.     DT        Value
  134.     ENDIF
  135.     ENDIF
  136.     ENDIF
  137.     ENDIF
  138.     ENDIF
  139.     ENDM
  140.  
  141.  
  142.  
  143.  
  144. COMMENT    %
  145. ==============================================================================
  146. Defines a message.
  147.  
  148. Passed:    Obj - Object name
  149.     Msg - Message name
  150.     Methods - Method list 
  151.  
  152. =============================================================================%
  153. defMsg    MACRO    Obj,Msg,Methods
  154.     ALIGN    2
  155.     Obj&Msg    _Message    <Methods>
  156.     ENDM    
  157.  
  158.  
  159.  
  160. COMMENT    %
  161. ==============================================================================
  162. Sets us SI to point to object, and calls initObject procedure.
  163.  
  164. =============================================================================%
  165. initObj    MACRO    Obj
  166.     lea        si,Obj            ;Pass object ptr
  167.     call        initObject        ;Find all ancestors
  168.     ENDM
  169.  
  170.  
  171.  
  172. COMMENT    %
  173. ==============================================================================
  174. Gets an object's instance variable.
  175.  
  176. Passed:    Dest- Destination register
  177.     Var - Instance variable name
  178.     Obj - Source object 
  179.  
  180. =============================================================================%
  181. getInst    MACRO    Dest,Var,Obj
  182.     IFNB        <Obj>
  183.     IFIDN        <Obj>,<Self>
  184.     mov        si,WORD PTR[Self]
  185.     mov        si,WORD PTR[si].Instances
  186.     ELSE
  187.     IFIDN        <si>,<Obj>
  188.     mov        si,WORD PTR[si].Instances
  189.     ELSE
  190.     mov        si,Obj&.Instances
  191.     ENDIF
  192.     ENDIF
  193.     ENDIF
  194.     mov        Dest,[si+Var]
  195.     ENDM
  196.  
  197.  
  198.  
  199. COMMENT    %
  200. ==============================================================================
  201. Gets an object's instance variable, but object is pointed to by one of 
  202. Self's instance variables.
  203.  
  204. Passed:    Dest- Destination register
  205.     Var - Instance variable name
  206.     Obj - Source object instance variable
  207.  
  208. =============================================================================%
  209. getInst$    MACRO    Dest,Var,Obj
  210.     mov        si,WORD PTR[Self]    
  211.     mov        si,WORD PTR[si].Instances
  212.     mov        si,[si+Obj]
  213.     mov        si,WORD PTR[si].Instances
  214.     mov        Dest,[si+Var]
  215.     ENDM
  216.  
  217.  
  218.  
  219. COMMENT    %
  220. ==============================================================================
  221. Sets an object's instance variable.
  222.  
  223. Passed:    Var - Instance variable name
  224.     Source - Source register
  225.     Obj - Source object
  226.     Size - Size of data
  227.  
  228. =============================================================================%
  229. setInst    MACRO    Var,Source,Obj,Size
  230.     IFNB        <Obj>
  231.     IFIDN        <Obj>,<Self>
  232.     mov        si,WORD PTR[Self]
  233.     mov        si,WORD PTR[si].Instances
  234.     ELSE
  235.     mov        si,Obj&.Instances
  236.     ENDIF
  237.     ENDIF
  238.     setInst_    Var,Source,Size
  239.     ENDM
  240.  
  241.  
  242.  
  243. COMMENT    %
  244. ==============================================================================
  245. Sets an object's instance variable, but object is pointed to by one of 
  246. Self's instance variables.
  247.  
  248. Passed:    Var - Instance variable name
  249.     Source - Source register
  250.     Obj - Source object instance variable
  251.     Size - Size of data
  252.  
  253.  
  254. =============================================================================%
  255. setInst$    MACRO    Var,Source,Obj,Size
  256.     mov        si,WORD PTR[Self]
  257.     mov        si,WORD PTR[si].Instances
  258.     mov        si,[si+Obj]
  259.     mov        si,WORD PTR[si].Instances
  260.     setInst_    Var,Source,Size
  261.     ENDM
  262.  
  263.  
  264.  
  265. COMMENT    %
  266. ==============================================================================
  267. Assembles move instruction based on source register.
  268.  
  269. =============================================================================%
  270. setInst_    MACRO    Var,Source,Size
  271.     IFIDN        <Source>,<al>
  272.     mov        BYTE PTR[si+Var],Source
  273.     ELSE
  274.     IFIDN        <Source>,<ah>
  275.     mov        BYTE PTR[si+Var],Source
  276.     ELSE
  277.     IFIDN        <Source>,<bl>
  278.     mov        BYTE PTR[si+Var],Source
  279.     ELSE
  280.     IFIDN        <Source>,<bh>
  281.     mov        BYTE PTR[si+Var],Source
  282.     ELSE
  283.     IFIDN        <Source>,<cl>
  284.     mov        BYTE PTR[si+Var],Source
  285.     ELSE
  286.     IFIDN        <Source>,<ch>
  287.     mov        BYTE PTR[si+Var],Source
  288.     ELSE
  289.     IFIDN        <Source>,<dl>
  290.     mov        BYTE PTR[si+Var],Source
  291.     ELSE
  292.     IFIDN        <Source>,<dh>
  293.     mov        BYTE PTR[si+Var],Source
  294.     ELSE
  295.     IFIDN        <Source>,<ax>
  296.     mov        WORD PTR[si+Var],Source
  297.     ELSE
  298.     IFIDN        <Source>,<bx>
  299.     mov        WORD PTR[si+Var],Source
  300.     ELSE
  301.     IFIDN        <Source>,<cx>
  302.     mov        WORD PTR[si+Var],Source
  303.     ELSE
  304.     IFIDN        <Source>,<dx>
  305.     mov        WORD PTR[si+Var],Source
  306.     ELSE
  307.     IFIDN        <Source>,<di>
  308.     mov        WORD PTR[si+Var],Source
  309.     ELSE
  310.     IFIDN        <Source>,<si>
  311.     mov        WORD PTR[si+Var],Source
  312.     ELSE
  313.     IFIDN        <Size>,<1>
  314.     mov        BYTE PTR[si+Var],Source
  315.     ELSE
  316.     IFIDN        <Size>,<2>
  317.     mov        WORD PTR[si+Var],Source
  318.     ENDIF
  319.     ENDIF
  320.     ENDIF
  321.     ENDIF
  322.     ENDIF
  323.     ENDIF
  324.     ENDIF
  325.     ENDIF
  326.     ENDIF
  327.     ENDIF
  328.     ENDIF
  329.     ENDIF
  330.     ENDIF
  331.     ENDIF
  332.     ENDIF
  333.     ENDIF
  334.     ENDM
  335.  
  336.  
  337.  
  338. COMMENT    %
  339. ==============================================================================
  340. Sends the specified message to the specified table of enslaved objects.
  341.  
  342. =============================================================================%
  343. sendSlaves    MACRO    Tbl,Msg,Args
  344.         LOCAL    sds1
  345.  
  346.     mov        cx,Wptr[Tbl]        ;Get object count
  347. sds1:    add        Tbl,2            ;Point to next object obj
  348.     mov        si,Wptr[Tbl]        ;Get object obj ptr
  349.     pushData    <Self,Tbl,cx>
  350.     send        si,Msg,Args        ;Send object the message
  351.     popData        <cx,Tbl,Self>
  352.     loop        sds1
  353.     ENDM
  354.  
  355.  
  356.  
  357. COMMENT    %
  358. ==============================================================================
  359. Executes the specified object/message pair sends.
  360.  
  361. =============================================================================%
  362. sendLoop    MACRO    Reg,CountOff,TblOff
  363.         LOCAL    sdlp1,sdlp2
  364.  
  365.     push        Self
  366.     xor        ch,ch            ;Zero hi-order of count reg
  367.     mov        cl,Bptr[Reg+CountOff]    ;Get count byte
  368.     mov        di,Wptr[Reg+TblOff]    ;Get beginning of tbl
  369. sdlp1:    pushData    <cx,di>
  370.     mov        si,Wptr[di]        ;Get obj ptr
  371.     neq        si,<OFFSET Self>,sdlp2  ;Jump if not sending to Self 
  372.     mov        si,Wptr[si]        ;Else get obj ptr 
  373. sdlp2:    mov        dx,Wptr[di+2]        ;Get msg number
  374.     call        sendMsg            ;Send message
  375.     popData        <di,cx>
  376.     add        di,4            ;Point to next msg
  377.     loop        sdlp1            ;Do it again
  378.     pop        Self
  379.     ENDM
  380.  
  381.  
  382.  
  383. COMMENT %
  384. ==========================================================================
  385. Sets up stack, SI with object pointer, DX with message number, and calls
  386. sendMsg procedure.
  387.  
  388. Passed:    Obj - Name of receiving object
  389.     Msg - Message number
  390.  
  391. =========================================================================%
  392. send    MACRO        Obj,Msg,ArgList
  393.     pushArgs    ArgList            ;Push arguments onto stack
  394.  
  395.     IFIDN        <Obj>,<Self>        ;If object is Self
  396.     mov        si,Wptr[Self]        ;Get object ptr from it
  397.     ELSE
  398.     IFDIF        <Obj>,<si>        ;If object ptr not in SI
  399.     lea        si,Obj            ;Load SI with ptr to object
  400.     ENDIF
  401.     ENDIF
  402.  
  403.     IFDIF        <Msg>,<dx>        ;If msg number not in DX
  404.     mov        dx,Msg            ;Put it in DX
  405.     ENDIF
  406.  
  407.     call        sendMsg            ;Send message
  408.  
  409.     IFNB        <ArgList>        ;If arguments
  410.     X    =    0            ;Init stack depth counter
  411.     IRP        Arg,<ArgList>        ;For every arg on stack
  412.     X    =    X+2            ;Increment depth counter
  413.     ENDM
  414.     add        sp,X            ;Reset stack pointer
  415.     ENDIF
  416.     ENDM
  417.  
  418.  
  419.  
  420. COMMENT %
  421. ==========================================================================
  422. Pushes up to ten arguments onto the stack.
  423.  
  424. =========================================================================%
  425. pushArgs    MACRO    A0,A1,A2,A3,A4,A5,A6,A7,A8,A9
  426.     IFB        <A0>            ;If no more arguments
  427.     EXITM                    ;Exit macro
  428.     ENDIF
  429.  
  430.     IFIDN        <A0>,<ax>        ;If arg in AX
  431.     push        ax            ;Push AX
  432.     ELSE
  433.     IFIDN        <A0>,<bx>        ;If arg in BX
  434.     push        bx            ;Push BX
  435.     ELSE
  436.     IFIDN        <A0>,<cx>        ;If arg in CX
  437.     push        cx            ;Push CX
  438.     ELSE
  439.     IFIDN        <A0>,<dx>        ;If arg in DX
  440.     push        dx            ;Push DX
  441.     ELSE
  442.     mov        bx,A0            ;Else move into BX
  443.     push        bx            ;Push BX
  444.     ENDIF
  445.     ENDIF
  446.     ENDIF
  447.     ENDIF
  448.  
  449.     pushArgs    A1,A2,A3,A4,A5,A6,A7,A8,A9
  450.     ENDM
  451.  
  452.  
  453.  
  454. COMMENT %
  455. ==========================================================================
  456. Finds the specified message for specified object.
  457.  
  458. Passed:    Msg - Message number
  459.     Obj - Addr ptr to object structure
  460.  
  461. Passes:    si - Pointer to combined method pointer
  462.  
  463. =========================================================================%
  464. findMsg    MACRO    Obj,Msg,Lbl
  465.     LOCAL    fdmg1,fdmg2
  466.  
  467.     IFDIF        <Obj>,<si>        ;If object ptr is not in SI
  468.     mov        si,Obj            ;Put it there
  469.     ENDIF
  470.  
  471.     mov        di,Wptr[si].Instances    
  472.                         ;Addr of msg tbl end
  473.     mov        si,Wptr[si].Messages
  474.                         ;Addr of msg tbl beginning 
  475.  
  476. fdmg1:    lodsb                    ;Fetch msg number
  477.     eq        al,Msg,fdmg2        ;Exit if message is found
  478.     add        si,2            ;Else point to next message
  479.     cmp        si,di            ;More messages?
  480.     jb        fdmg1            ;If so continue search
  481.  
  482.     IFNB        <Lbl>            ;If label provided
  483.     jmp        Lbl            ;Jump to it upon failure
  484.     ENDIF
  485. fdmg2:
  486.     ENDM
  487.  
  488.  
  489.  
  490.