home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 303.lha / AssemTools / Include / util.i < prev    next >
Text File  |  1980-12-03  |  3KB  |  178 lines

  1. ;METACOMCO needs:
  2. ;execlib.i, relative.i
  3.  
  4.  
  5.     ifnd    def
  6. def    macro
  7.     ifnd    \1
  8. \1    set    \2
  9.     endc
  10.     endm
  11.     endc
  12.  
  13.  
  14. ph    macro    oper
  15.     move.l    \1,-(sp)
  16.     endm
  17.  
  18. pl    macro    oper
  19.     move.l    (sp)+,\1
  20.     endm
  21.  
  22. * PH and PL are used to PusH and PulL an operand to/from stack.
  23. * They use MOVE and therefore are more effective than PUSH
  24. * and PULL that use MOVEM.
  25.  
  26. pk    macro    oper
  27.     move.l    (sp),\1
  28.     endm
  29.  
  30. * PK is used to peek a value from stack without changing the
  31. * valueo of stack pointer. This prevents the use of sequent
  32. * PH and PL macros with the same operand.
  33.  
  34.  
  35. sro    macro    value,oper
  36.     move.l    \2,-(sp)
  37.     move.l    \1,\2
  38.     endm
  39.  
  40. * SRO (Save and Replace Operand) is used to move a longword
  41. * value to an operand. Before doing this, the operand is pushed
  42. * onto the stack. The counterpart of this function is PL.
  43.  
  44.  
  45. * ALLOC and FREE are used to allocate and free memory.
  46.  
  47. alloc    macro    pointer,size[,[requi][,clean]]
  48.     move.l    \2,d0
  49.     addq.l    #4,d0
  50.     ifnc    '\3',''
  51.     move.l    \3,d1
  52.     endc
  53.     ifc    '\3',''
  54.     moveq    #0,d1
  55.     endc
  56.     lib    Exec,AllocMem
  57.     clr.l    \1
  58.     tst.l    d0
  59.     ifnc    '\4',''
  60.     beq    \4
  61.     endc
  62.     ifc    '\4',''
  63.     bne.s    .ui\@a
  64.     endc
  65.     move.l    d0,a0
  66.     move.l    \2,d0
  67.     addq.l    #4,d0
  68.     move.l    d0,(a0)+
  69.     move.l    a0,\1
  70. .ui\@a
  71.     endm
  72.  
  73. free    macro    pointer
  74.     move.l    \1,d0
  75.     beq.s    .ui\@a
  76.     move.l    d0,a1
  77.     move.l    -(a1),d0
  78.     lib    Exec,FreeMem
  79.     clr.l    \1
  80. .ui\@a
  81.     endm
  82.  
  83. .ui.form macro    <private>
  84.     move.l    \1,(a2)+
  85.     ifnc    '\2',''
  86.     .ui.form \2,\3,\4,\5,\6,\7,\8,\9
  87.     endc
  88.     endm
  89. formatp    macro    param-list
  90.     link    a3,#-4*NARG
  91.     move.l    sp,a2
  92.     .ui.form \1,\2,\3,\4,\5,\6,\7,\8,\9
  93.     move.l    sp,a2
  94.     endm
  95. format    macro    bufptr,format-str,param-list
  96.     ifnc    '\1','a1'
  97.     exg.l    \1,a1
  98.     endc
  99.     movem.l    a0/a2,-(sp)
  100.     link    a3,#-4*(NARG-2)
  101.     move.l    sp,a2
  102.     .ui.form \3,\4,\5,\6,\7,\8,\9
  103.     move.l    sp,a2
  104.     lea.l    .ui\@a(pc),a0
  105.     execlib    format
  106.     unlk    a3
  107.     movem.l    (sp)+,a0/a2
  108.     ifnc    '\1','a1'
  109.     exg.l    \1,a1
  110.     endc
  111.     bra.s    .ui\@b
  112. .ui\@a    dc.b    \2
  113.     dc.b    0
  114.     ds.w    0
  115. .ui\@b    ;;;
  116.     endm
  117.  
  118. ;  Sample usages:
  119. ;  *  format  a0,<' - Error code %ld',10>,d0
  120. ;  BUFPTR (a0) may be any address register.
  121. ;  FSTRING may be an ascii string.
  122. ;  parameters may be any locations or registers BUT NOT
  123. ;      A1, A2 or A3. Each one of them is used as LONG.
  124. ;  *  formatp fnam(a4),d0
  125. ;  Just reserves stack space for the parameters and
  126. ;  puts them there. a2 points to the beginning of the
  127. ;  data stream, a3 is the prev. stack pointer, so UNLK A3
  128. ;  frees the space from stack.
  129.  
  130.  
  131.     ; *** relative.i ONLY:
  132. .share    macro
  133. _share.cnt set    0
  134.     endm
  135.  
  136. dm    macro    name,size
  137.     dl    \1
  138. _DmS.\1    set    \2
  139. _share.cnt set    _share.cnt+(\2)
  140.     endm
  141.  
  142. share    macro    mem,type,clean
  143.     alloc    \1(a4),#_share.cnt,\2,\3
  144.     move.l    \1(a4),a0
  145.     endm
  146.  
  147. slice    macro    name[,name[,name...]]
  148.     move.l    a0,\1(a4)
  149.     lea    _DmS.\1(a0),a0
  150.     ifnc    '\2',''
  151.     slice    \2,\3,\4,\5,\6,\7,\8
  152.     endc
  153.     endm
  154.  
  155. ;see from a program how they work!
  156. ;(they allocate a bit of memory and share it)
  157. ;they work only with relative(.i) programs
  158.  
  159.  
  160. scribe    macro    rport,x,y,'text'
  161.     move.l    \1,a1
  162.     move.l    \2,d0
  163.     move.l    \3,d1
  164.     lib    Gfx,Move
  165.     move.l    \1,a1
  166.     lea    .s\@a(pc),a0
  167.     moveq    #.s\@b-.s\@a,d0
  168.     lib    Gfx,Text
  169.     bra    .s\@c
  170. .s\@a    dc.b    \4
  171. .s\@b
  172.     ds.l    0
  173. .s\@c
  174.     endm
  175.  
  176.  
  177.  
  178.