home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / at-inc-bin.lha / os-include / utility / pack.h < prev    next >
C/C++ Source or Header  |  1993-10-15  |  7KB  |  174 lines

  1. #ifndef UTILITY_PACK_H
  2. #define UTILITY_PACK_H
  3. /*
  4. **    $VER: pack.h 39.3 (10.2.93)
  5. **    Includes Release 40.15
  6. **
  7. **    Control attributes for Pack/UnpackStructureTags()
  8. **
  9. **    (C) Copyright 1992-1993 Commodore-Amiga Inc.
  10. **    All Rights Reserved
  11. */
  12.  
  13. /*****************************************************************************/
  14.  
  15.  
  16. #ifndef EXEC_TYPES_H
  17. #include <exec/types.h>
  18. #endif
  19.  
  20. #ifndef UTILITY_TAGITEM_H
  21. #include <utility/tagitem.h>
  22. #endif
  23.  
  24.  
  25. /*****************************************************************************/
  26.  
  27.  
  28. /* PackTable definition:
  29.  *
  30.  * The PackTable is a simple array of LONGWORDS that are evaluated by
  31.  * PackStructureTags() and UnpackStructureTags().
  32.  *
  33.  * The table contains compressed information such as the tag offset from
  34.  * the base tag. The tag offset has a limited range so the base tag is
  35.  * defined in the first longword.
  36.  *
  37.  * After the first longword, the fields look as follows:
  38.  *
  39.  *    +--------- 1 = signed, 0 = unsigned (for bits, 1=inverted boolean)
  40.  *    |
  41.  *    |  +------ 00 = Pack/Unpack, 10 = Pack, 01 = Unpack, 11 = special
  42.  *    | / \
  43.  *    | | |  +-- 00 = Byte, 01 = Word, 10 = Long, 11 = Bit
  44.  *    | | | / \
  45.  *    | | | | | /----- For bit operations: 1 = TAG_EXISTS is TRUE
  46.  *    | | | | | |
  47.  *    | | | | | | /-------------------- Tag offset from base tag value
  48.  *    | | | | | | |              \
  49.  *    m n n o o p q q q q q q q q q q r r r s s s s s s s s s s s s s
  50.  *                    \   | |              |
  51.  *    Bit offset (for bit operations) ----/ |              |
  52.  *                          \               |
  53.  *    Offset into data structure -----------------------------------/
  54.  *
  55.  * A -1 longword signifies that the next longword will be a new base tag
  56.  *
  57.  * A 0 longword signifies that it is the end of the pack table.
  58.  *
  59.  * What this implies is that there are only 13-bits of address offset
  60.  * and 10 bits for tag offsets from the base tag.  For most uses this
  61.  * should be enough, but when this is not, either multiple pack tables
  62.  * or a pack table with extra base tags would be able to do the trick.
  63.  * The goal here was to make the tables small and yet flexible enough to
  64.  * handle most cases.
  65.  */
  66.  
  67. #define    PSTB_SIGNED 31
  68. #define PSTB_UNPACK 30      /* Note that these are active low... */
  69. #define PSTB_PACK   29      /* Note that these are active low... */
  70. #define    PSTB_EXISTS 26      /* Tag exists bit true flag hack...  */
  71.  
  72. #define    PSTF_SIGNED (1L << PSTB_SIGNED)
  73. #define PSTF_UNPACK (1L << PSTB_UNPACK)
  74. #define PSTF_PACK   (1L << PSTB_PACK)
  75.  
  76. #define    PSTF_EXISTS (1L << PSTB_EXISTS)
  77.  
  78.  
  79. /*****************************************************************************/
  80.  
  81.  
  82. #define PKCTRL_PACKUNPACK 0x00000000
  83. #define PKCTRL_PACKONLY   0x40000000
  84. #define PKCTRL_UNPACKONLY 0x20000000
  85.  
  86. #define PKCTRL_BYTE      0x80000000
  87. #define PKCTRL_WORD      0x88000000
  88. #define PKCTRL_LONG      0x90000000
  89.  
  90. #define PKCTRL_UBYTE      0x00000000
  91. #define PKCTRL_UWORD      0x08000000
  92. #define PKCTRL_ULONG      0x10000000
  93.  
  94. #define PKCTRL_BIT      0x18000000
  95. #define PKCTRL_FLIPBIT      0x98000000
  96.  
  97.  
  98. /*****************************************************************************/
  99.  
  100.  
  101. /* Macros used by the next batch of macros below. Normally, you don't use
  102.  * this batch directly. Then again, some folks are wierd
  103.  */
  104.  
  105. #define PK_BITNUM1(flg) ((flg) == 0x01 ? 0 : (flg) == 0x02 ? 1 : (flg) == 0x04 ? 2 : (flg) == 0x08 ? 3 : (flg) == 0x10 ? 4 : (flg) == 0x20 ? 5 : (flg) == 0x40 ? 6 : 7)
  106. #define PK_BITNUM2(flg) ((flg < 0x100 ? PK_BITNUM1(flg) : 8+PK_BITNUM1(flg >> 8)))
  107. #define PK_BITNUM(flg) ((flg < 0x10000 ? PK_BITNUM2(flg) : 16+PK_BITNUM2(flg >> 16)))
  108. #define PK_WORDOFFSET(flg) ((flg) < 0x100 ? 1 : 0)
  109. #define PK_LONGOFFSET(flg) ((flg) < 0x100  ? 3 : (flg) < 0x10000 ? 2 : (flg) < 0x1000000 ? 1 : 0)
  110. #define PK_CALCOFFSET(type,field) ((ULONG)(&((struct type *)0)->field))
  111.  
  112.  
  113. /*****************************************************************************/
  114.  
  115.  
  116. /* Some handy dandy macros to easily create pack tables
  117.  *
  118.  * Use PACK_STARTTABLE() at the start of a pack table. You pass it the
  119.  * base tag value that will be handled in the following chunk of the pack
  120.  * table.
  121.  *
  122.  * PACK_ENDTABLE() is used to mark the end of a pack table.
  123.  *
  124.  * PACK_NEWOFFSET() lets you change the base tag value used for subsequent
  125.  * entries in the table
  126.  *
  127.  * PACK_ENTRY() lets you define an entry in the pack table. You pass it the
  128.  * base tag value, the tag of interest, the type of the structure to use,
  129.  * the field name in the structure to affect and control bits (combinations of
  130.  * the various PKCTRL_XXX bits)
  131.  *
  132.  * PACK_BYTEBIT() lets you define a bit-control entry in the pack table. You
  133.  * pass it the same data as PACK_ENTRY, plus the flag bit pattern this tag
  134.  * affects. This macro should be used when the field being affected is byte
  135.  * sized.
  136.  *
  137.  * PACK_WORDBIT() lets you define a bit-control entry in the pack table. You
  138.  * pass it the same data as PACK_ENTRY, plus the flag bit pattern this tag
  139.  * affects. This macro should be used when the field being affected is word
  140.  * sized.
  141.  *
  142.  * PACK_LONGBIT() lets you define a bit-control entry in the pack table. You
  143.  * pass it the same data as PACK_ENTRY, plus the flag bit pattern this tag
  144.  * affects. This macro should be used when the field being affected is longword
  145.  * sized.
  146.  *
  147.  * EXAMPLE:
  148.  *
  149.  *    ULONG packTable[] =
  150.  *    {
  151.  *       PACK_STARTTABLE(GA_Dummy),
  152.  *       PACK_ENTRY(GA_Dummy,GA_Left,Gadget,LeftEdge,PKCTRL_WORD|PKCTRL_PACKUNPACK),
  153.  *       PACK_ENTRY(GA_Dummy,GA_Top,Gadget,TopEdge,PKCTRL_WORD|PKCTRL_PACKUNPACK),
  154.  *       PACK_ENTRY(GA_Dummy,GA_Width,Gadget,Width,PKCTRL_UWORD|PKCTRL_PACKUNPACK),
  155.  *       PACK_ENTRY(GA_Dummy,GA_Height,Gadget,Height,PKCTRL_UWORD|PKCTRL_PACKUNPACK),
  156.  *       PACK_WORDBIT(GA_Dummy,GA_RelVerify,Gadget,Activation,PKCTRL_BIT|PKCTRL_PACKUNPACK,GACT_RELVERIFY)
  157.  *       PACK_ENDTABLE
  158.  *    };
  159.  */
  160.  
  161. #define PACK_STARTTABLE(tagbase)               (tagbase)
  162. #define PACK_NEWOFFSET(tagbase)               (-1L),(tagbase)
  163. #define PACK_ENDTABLE                       0
  164. #define PACK_ENTRY(tagbase,tag,type,field,control)       (control | ((tag-tagbase) << 16L) | PK_CALCOFFSET(type,field))
  165. #define PACK_BYTEBIT(tagbase,tag,type,field,control,flags) (control | ((tag-tagbase) << 16L) | PK_CALCOFFSET(type,field) | (PK_BITNUM(flags) << 13L))
  166. #define PACK_WORDBIT(tagbase,tag,type,field,control,flags) (control | ((tag-tagbase) << 16L) | (PK_CALCOFFSET(type,field)+PK_WORDOFFSET(flags)) | ((PK_BITNUM(flags)&7) << 13L))
  167. #define PACK_LONGBIT(tagbase,tag,type,field,control,flags) (control | ((tag-tagbase) << 16L) | (PK_CALCOFFSET(type,field)+PK_LONGOFFSET(flags)) | ((PK_BITNUM(flags)&7) << 13L))
  168.  
  169.  
  170. /*****************************************************************************/
  171.  
  172.  
  173. #endif /* UTILITY_PACK_H */
  174.