home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 13 / AACD13.ISO / AACD / Games / WHDLoad / Src / gci / misc.c < prev    next >
C/C++ Source or Header  |  2000-06-04  |  3KB  |  121 lines

  1. /*****************************************************************************
  2. ;  :Module.    misc.c
  3. ;  :Author.    Bert Jahn
  4. ;  :EMail.    wepl@whdload.org
  5. ;  :Address.    Franz-Liszt-Straße 16, Rudolstadt, 07404, Germany
  6. ;  :Version.    $Id: misc.c 1.2 2000/05/23 17:12:51 jah Exp $
  7. ;  :History.    28.03.00 extracted from whdloadgci.c
  8. ;  :Copyright.    All Rights Reserved
  9. ;  :Language.    C
  10. ;  :Translator.    GCC
  11. ****************************************************************************/
  12.  
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15.  
  16. #include "WHDLoadGCI.h"
  17.  
  18. /****************************************************************************/
  19.  
  20. /*
  21.  *    create string containing right aligned hexadecimal representation of value
  22.  */
  23. STRPTR val2hexr(ULONG value) {
  24.     static char s[12];
  25.     sprintf(s,"\33r%s",val2hex(value));
  26.     return s;
  27. }
  28.  
  29. /*
  30.  *    create string containing right aligned hexadecimal representation of value
  31.  */
  32. STRPTR val2hex64r(ULONG value1, ULONG value2) {
  33.     static char s[20];
  34.     if (value1) {
  35.         sprintf(s,"\33r$%x%08x",value1,value2);
  36.         return s;
  37.     } else {
  38.         return val2hexr(value2);
  39.     }
  40. }
  41.  
  42. /*
  43.  *    return string containing hexadecimal representation of value
  44.  */
  45. STRPTR val2hex(ULONG value) {
  46.     static char s[10];
  47.     sprintf(s,value < 16 ? "%d" : "$%x",value);
  48.     return s;
  49. }
  50.  
  51. /*
  52.  *    create string for "String"
  53.  */
  54. STRPTR val2hex4(UWORD val) {
  55.     static char s[6];
  56.     if (val < 16) {
  57.         sprintf(s,"%d",val);
  58.     } else {
  59.         sprintf(s,"$%x",val);
  60.     }
  61.     return s;
  62. }
  63. STRPTR val2hex8(ULONG val) {
  64.     static char s[10];
  65.     if (val < 16) {
  66.         sprintf(s,"%ld",val);
  67.     } else {
  68.         sprintf(s,"$%lx",val);
  69.     }
  70.     return s;
  71. }
  72. /*
  73.  *    create string for "Text"
  74.  */
  75. STRPTR val2hex1t(UBYTE val) {
  76.     static char s[3];
  77.     sprintf(s,"\33r%ld",val);
  78.     return s;
  79. }
  80. STRPTR val2hex4t(UWORD val) {
  81.     static char s[6];
  82.     if (val < 16) {
  83.         sprintf(s,"\33r%d",val);
  84.     } else {
  85.         sprintf(s,"\33r$%x",val);
  86.     }
  87.     return s;
  88. }
  89. STRPTR val2hex8t(ULONG val) {
  90.     static char s[10];
  91.     if (val < 16) {
  92.         sprintf(s,"\33r%ld",val);
  93.     } else {
  94.         sprintf(s,"\33r$%lx",val);
  95.     }
  96.     return s;
  97. }
  98. /*
  99.  *    set contents of "String"
  100.  */
  101. void sethex4(APTR gad, UWORD val) {
  102.     set(gad,MUIA_String_Contents,val2hex4(val));
  103. }
  104. void sethex8(APTR gad, ULONG val) {
  105.     set(gad,MUIA_String_Contents,val2hex8(val));
  106.     set(gad,MUIA_Text_Contents,val2hex8(val));
  107. }
  108. /*
  109.  *    set contents of "Text"
  110.  */
  111. void sethex1t(APTR gad, UBYTE val) {
  112.     set(gad,MUIA_Text_Contents,val2hex1t(val));
  113. }
  114. void sethex4t(APTR gad, UWORD val) {
  115.     set(gad,MUIA_Text_Contents,val2hex4t(val));
  116. }
  117. void sethex8t(APTR gad, ULONG val) {
  118.     set(gad,MUIA_Text_Contents,val2hex8t(val));
  119. }
  120.  
  121.