home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / Pascal / MAXONPASCAL2.DMS / in.adf / INCLUDE / Utility / pack_Functions.h < prev    next >
Encoding:
Text File  |  1994-07-25  |  4.7 KB  |  170 lines

  1. {$if not def UTILITY_PACK_MACROS_H} CONST UTILITY_PACK_MACROS_H=true;
  2.  
  3. { ****************************************************************
  4.   ** KickPascal-Include-Datei "utility/pack.h" zu Kickstart 3.0 **
  5.   ** Ergänzung der MACROS als Pascal FUNCTIONen           by JS **
  6.   **************************************************************** }
  7.  
  8. {$if not def UTILITY_PACK_H;incl "utility/pack.h";endif}
  9.  
  10. Function PK_BITNUM1(flg:Long):Long;
  11. begin
  12.  case flg of
  13.  $01: PK_BITNUM1:=0;
  14.  $02: PK_BITNUM1:=1;
  15.  $04: PK_BITNUM1:=2;
  16.  $08: PK_BITNUM1:=3;
  17.  $10: PK_BITNUM1:=4;
  18.  $20: PK_BITNUM1:=5;
  19.  $40: PK_BITNUM1:=6;
  20.  else
  21.   PK_BITNUM1:=7;
  22.  end;
  23. end;
  24. Function PK_BITNUM2(flg:Long):Long;
  25. begin
  26.  if flg<$100 then
  27.    PK_BITNUM2:=PK_BITNUM1(flg)
  28.   else
  29.    PK_BITNUM2:=8+PK_BITNUM1(flg shr 8); 
  30. end;
  31. Function PK_BITNUM(flg:Long):Long;
  32. begin
  33.  if flg<$10000 then
  34.    PK_BITNUM:=PK_BITNUM2(flg)
  35.   else
  36.    PK_BITNUM:=16+PK_BITNUM2(flg shr 16);
  37. end;
  38. Function PK_WORDOFFSET(flg:Long):Long;
  39. begin
  40.  if flg<$100 then 
  41.    PK_WORDOFFSET:=1
  42.   else
  43.    PK_WORDOFFSET:=0;
  44. end;
  45. Function PK_LONGOFFSET(flg:Long):Long;
  46. begin
  47.  if flg<$1000000 then
  48.  begin
  49.   if flg<$10000 then
  50.   begin
  51.    if flg<$100 then
  52.    begin
  53.     PK_LONGOFFSET:=1;
  54.    end
  55.    else
  56.    begin
  57.     PK_LONGOFFSET:=2;
  58.    end;
  59.   end
  60.   else 
  61.   begin
  62.    PK_LONGOFFSET:=3;
  63.   end;
  64.  end
  65.  else
  66.  begin
  67.   PK_LONGOFFSET:=0;
  68.  end;
  69. end;
  70. Function PK_CALCOFFSET(t,field:Ptr):Long;
  71. begin
  72.  PK_CALCOFFSET:=Long(field)-Long(t);
  73. end;
  74.  
  75.  
  76. (* Some handy dandy macros to easily create pack tables
  77.  *
  78.  * Use PACK_STARTTABLE() at the start of a pack table. You pass it the
  79.  * base tag value that will be handled in the following chunk of the pack
  80.  * table.
  81.  *
  82.  * PACK_ENDTABLE() is used to mark the end of a pack table.
  83.  *
  84.  * PACK_NEWOFFSET() lets you change the base tag value used for subsequent
  85.  * entries in the table
  86.  *
  87.  * PACK_ENTRY() lets you define an entry in the pack table. You pass it the
  88.  * base tag value, the tag of interest, the type of the structure to use,
  89.  * the field name in the structure to affect and control bits (combinations of
  90.  * the various PKCTRL_XXX bits)
  91.  *
  92.  * PACK_BYTEBIT() lets you define a bit-control entry in the pack table. You
  93.  * pass it the same data as PACK_ENTRY, plus the flag bit pattern this tag
  94.  * affects. This macro should be used when the field being affected is byte
  95.  * sized.
  96.  *
  97.  * PACK_WORDBIT() lets you define a bit-control entry in the pack table. You
  98.  * pass it the same data as PACK_ENTRY, plus the flag bit pattern this tag
  99.  * affects. This macro should be used when the field being affected is word
  100.  * sized.
  101.  *
  102.  * PACK_LONGBIT() lets you define a bit-control entry in the pack table. You
  103.  * pass it the same data as PACK_ENTRY, plus the flag bit pattern this tag
  104.  * affects. This macro should be used when the field being affected is longword
  105.  * sized.
  106.  *
  107.  * EXAMPLE:
  108.  *
  109.  *    ULONG packTable[] =
  110.  *    {
  111.  *    PACK_STARTTABLE(GA_Dummy),
  112.  *    PACK_ENTRY(GA_Dummy,GA_Left,Gadget,LeftEdge,PKCTRL_WORD|PKCTRL_PACKUNPACK),
  113.  *    PACK_ENTRY(GA_Dummy,GA_Top,Gadget,TopEdge,PKCTRL_WORD|PKCTRL_PACKUNPACK),
  114.  *    PACK_ENTRY(GA_Dummy,GA_Width,Gadget,Width,PKCTRL_UWORD|PKCTRL_PACKUNPACK),
  115.  *    PACK_ENTRY(GA_Dummy,GA_Height,Gadget,Height,PKCTRL_UWORD|PKCTRL_PACKUNPACK),
  116.  *    PACK_WORDBIT(GA_Dummy,GA_RelVerify,Gadget,Activation,PKCTRL_BIT|PKCTRL_PACKUNPACK,GACT_RELVERIFY)
  117.  *    PACK_ENDTABLE
  118.  *    };
  119.  *)
  120.  
  121. (* Änderungen gegenüber C-Original:
  122.    Type - Feld (t) und field - Feld sind Pointer auf einen RECORD und ein Feld daraus.
  123.  
  124.    entsprechende Änderung im Beispiel:
  125.  
  126.    PACK_ENTRY(GA_Dummy,GA_Left,^gg,^gg.LeftEdge,PKCTRL_WORD or PKCTRL_PACKUNPACK),
  127.  
  128.    wobei für gg gilt:
  129.    VAR gg:Gadget;
  130.  *)
  131.  
  132. Function PACK_STARTTABLE(tagbase:Long):Long;
  133. begin
  134.  PACK_STARTTABLE:=tagbase;
  135. end;
  136.  
  137. {Function PACK_NEWOFFSET(tagbase:Long):Long;
  138. begin
  139.  (* (-1),(tagbase)
  140.     mehrere Ergebnisse in KP nicht möglich! *)
  141. end;}
  142.  
  143. Function PACK_ENDTABLE:Long;
  144. begin
  145.  PACK_ENDTABLE:=0;
  146. end;
  147.  
  148. (* Function gegenüber C geändert *)
  149. Function PACK_ENTRY(tagbase,tag:Long;t,field:Ptr;control:Long):Long;
  150. begin
  151.  PACK_ENTRY:=(control or ((tag-tagbase) shl 16) or PK_CALCOFFSET(t,field));
  152. end;
  153.  
  154. Function PACK_BYTEBIT(tagbase,tag:Long;t,field:Ptr;control,flags:Long):Long;
  155. begin
  156.  PACK_BYTEBIT:=(control or ((tag-tagbase) shl 16) or PK_CALCOFFSET(t,field) or (PK_BITNUM(flags) shl 13));
  157. end;
  158.  
  159. Function PACK_WORDBIT(tagbase,tag:Long;t,field:Ptr;control,flags:Long):Long;
  160. begin
  161.  PACK_WORDBIT:=(control or ((tag-tagbase) shl 16) or (PK_CALCOFFSET(t,field)+PK_WORDOFFSET(flags)) or ((PK_BITNUM(flags)and 7) shl 13));
  162. end;
  163.  
  164. Function PACK_LONGBIT(tagbase,tag:Long;t,field:Ptr;control,flags:Long):Long;
  165. begin
  166.  PACK_LONGBIT:=(control or ((tag-tagbase) shl 16) or (PK_CALCOFFSET(t,field)+PK_LONGOFFSET(flags)) or ((PK_BITNUM(flags)and 7) shl 13));
  167. end;
  168.  
  169. {$endif}
  170.