home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / cbm / nduk-v37.lha / V37 / include / exec / lists.i < prev    next >
Text File  |  1991-11-27  |  4KB  |  176 lines

  1.     IFND    EXEC_LISTS_I
  2. EXEC_LISTS_I    SET    1
  3. **
  4. **    $Filename: exec/lists.i $
  5. **    $Release: 2.04 Includes, V37.4 $
  6. **    $Revision: 36.10 $
  7. **    $Date: 91/02/19 $
  8. **
  9. **    Definitions and macros for use with Exec lists.  Most of the
  10. **    macros require ownership or locking of the list before use.
  11. **
  12. **    (C) Copyright 1985-1991 Commodore-Amiga, Inc.
  13. **        All Rights Reserved
  14. **
  15.  
  16.     IFND EXEC_NODES_I
  17.     INCLUDE "exec/nodes.i"
  18.     ENDC    ; EXEC_NODES_I
  19.  
  20.  
  21. *---------------------------------------------------------------------
  22.  
  23. *
  24. * Full featured list header
  25. *
  26.    STRUCTURE    LH,0
  27.     APTR    LH_HEAD
  28.     APTR    LH_TAIL
  29.     APTR    LH_TAILPRED
  30.     UBYTE    LH_TYPE
  31.     UBYTE    LH_pad
  32.     LABEL    LH_SIZE ;word aligned
  33.  
  34. *
  35. * Minimal List Header - no type checking (best for most applications)
  36. *
  37.    STRUCTURE    MLH,0
  38.     APTR    MLH_HEAD
  39.     APTR    MLH_TAIL
  40.     APTR    MLH_TAILPRED
  41.     LABEL    MLH_SIZE ;longword aligned
  42.  
  43. *---------------------------------------------------------------------
  44.  
  45. ;Prepare a list header for use
  46. NEWLIST     MACRO   ; list
  47.         MOVE.L  \1,LH_TAILPRED(\1)
  48.         ADDQ.L  #4,\1    ;Get address of LH_TAIL
  49.         CLR.L   (\1)    ;Clear LH_TAIL
  50.         MOVE.L  \1,-(\1)    ;Address of LH_TAIL to LH_HEAD
  51.         ENDM
  52.  
  53. ;Test if list is empty (list address in register)
  54. ;This operation is safe at any time - no list arbitration needed.
  55. TSTLIST     MACRO   ; [list]
  56.         IFGT    NARG-1
  57.            FAIL    !!! TSTLIST - Too many arguments !!!
  58.         ENDC
  59.         IFC     '\1',''
  60.         CMP.L   LH_TAIL+LN_PRED(A0),A0
  61.         ENDC
  62.         IFNC    '\1',''
  63.         CMP.L   LH_TAIL+LN_PRED(\1),\1
  64.         ENDC
  65.         ENDM
  66.  
  67. ;Test if list is empty (from effective address of list)
  68. ;list arbitration required.
  69. TSTLST2     MACRO    ;EA of list,=node
  70.         MOVE.L   \1,\2
  71.         TST.L    (\2)
  72.         ENDM
  73.  
  74. ;Get next in list
  75. SUCC        MACRO   ; node,=succ
  76.         MOVE.L  (\1),\2
  77.         ENDM
  78.  
  79. ;Get previous in list
  80. PRED        MACRO   ; node,=pred
  81.         MOVE.L  LN_PRED(\1),\2
  82.         ENDM
  83.  
  84. ;If empty, branch
  85. IFEMPTY     MACRO   ; list,label
  86.         CMP.L   LH_TAIL+LN_PRED(\1),\1
  87.         BEQ     \2
  88.         ENDM
  89.  
  90. ;If not empty, branch
  91. IFNOTEMPTY  MACRO   ; list,label
  92.         CMP.L   LH_TAIL+LN_PRED(\1),\1
  93.         BNE     \2
  94.         ENDM
  95.  
  96. ;Get next node, test if at end
  97. TSTNODE     MACRO   ; node,=next
  98.         MOVE.L  (\1),\2
  99.         TST.L   (\2)
  100.         ENDM
  101.  
  102. ;Get next, go to exit label if at end
  103. NEXTNODE    MACRO   ; next=next,=current,exit_label ([.s],DX,AX,DISP16)
  104.         MOVE.L  \1,\2
  105.         MOVE.L  (\2),\1
  106.         IFC     '\0',''    ;Check extension
  107.         BEQ     \3
  108.         ENDC
  109.         IFNC    '\0',''
  110.         BEQ.S   \3
  111.         ENDC
  112.         ENDM
  113.  
  114. ;Add to head of list
  115. ADDHEAD     MACRO   ; A0-list(destroyed) A1-node D0-(destroyed)
  116.         MOVE.L  (A0),D0
  117.         MOVE.L  A1,(A0)
  118.         MOVEM.L D0/A0,(A1)
  119.         MOVE.L  D0,A0
  120.         MOVE.L  A1,LN_PRED(A0)
  121.         ENDM
  122.  
  123. ;Add to tail of list
  124. ADDTAIL     MACRO   ; A0-list(destroyed) A1-node D0-(destroyed)
  125.         ADDQ.L  #LH_TAIL,A0
  126.         MOVE.L  LN_PRED(A0),D0
  127.         MOVE.L  A1,LN_PRED(A0)
  128.         MOVE.L  A0,(A1)
  129.         MOVE.L  D0,LN_PRED(A1)
  130.         MOVE.L  D0,A0
  131.         MOVE.L  A1,(A0)
  132.         ENDM
  133.  
  134. ;Remove node from whatever list it is in
  135. REMOVE        MACRO   ; A0-(destroyed)  A1-node(destroyed)
  136.         MOVE.L  (A1),A0
  137.         MOVE.L  LN_PRED(A1),A1
  138.         MOVE.L  A0,(A1)
  139.         MOVE.L  A1,LN_PRED(A0)
  140.         ENDM
  141.  
  142. ;Remove node from head of list
  143. REMHEAD     MACRO   ; A0-list A1-(destroyed) D0=node
  144.         MOVE.L  (A0),A1
  145.         MOVE.L  (A1),D0
  146.         BEQ.S   REMHEAD\@
  147.         MOVE.L  D0,(A0)
  148.         EXG.L   D0,A1
  149.         MOVE.L  A0,LN_PRED(A1)
  150. REMHEAD\@
  151.         ENDM
  152.  
  153. ;Remove head quickly
  154. ;    Useful when a scratch register is available, and
  155. ;    list is known to contain at least one node.
  156. REMHEADQ    MACRO   ; list,=node,scratchReg-(destroyed)
  157.         MOVE.L  (\1),\2
  158.         MOVE.L  (\2),\3
  159.         MOVE.L  \3,(\1)
  160.         MOVE.L  \1,LN_PRED(\3)
  161.         ENDM
  162.  
  163. ;Remove node from tail of list
  164. REMTAIL     MACRO   ; A0-list A1-(destroyed) D0=node
  165.         MOVE.L  LH_TAIL+LN_PRED(A0),A1
  166.         MOVE.L  LN_PRED(A1),D0
  167.         BEQ.S   REMTAIL\@
  168.         MOVE.L  D0,LH_TAIL+LN_PRED(A0)
  169.         EXG.L   D0,A1
  170.         MOVE.L  A0,(A1)
  171.         ADDQ.L  #4,(A1)
  172. REMTAIL\@
  173.         ENDM
  174.  
  175.     ENDC    ; EXEC_LISTS_I
  176.