home *** CD-ROM | disk | FTP | other *** search
/ Quark 3 / Quark3.iso / KATALOG / ARCHIV / TOOL / T001.ZIP / SOURCE.ZIP / DiskIO.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1999-05-03  |  3.4 KB  |  241 lines

  1. /*
  2. Copyright (C) Matthew 'pagan' Baranowski & Sander 'FireStorm' van Rossen
  3.  
  4. This program is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU General Public License
  6. as published by the Free Software Foundation; either version 2
  7. of the License, or (at your option) any later version.
  8.  
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. GNU General Public License for more details.
  13.  
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  17. */
  18.  
  19. #include "system.h"
  20. #include "diskio.h"
  21.  
  22. void putLittle16 ( INT16 num , FILE *f )
  23. {
  24.     union
  25.     {
  26.         struct
  27.         {
  28.             UINT8    b1, b2;
  29.         };
  30.         UINT16     i1;
  31.     } u;
  32.  
  33.     u.i1 = num;
  34.  
  35.     fputc( u.b1, f );
  36.     fputc( u.b2, f );
  37. }
  38.  
  39. INT16 getLittle16 (FILE *f)
  40. {
  41.     union
  42.     {
  43.         struct
  44.         {
  45.             UINT8    b1, b2;
  46.         };
  47.         UINT16     i1;
  48.     } u;
  49.  
  50.     u.b1 = fgetc(f);
  51.     u.b2 = fgetc(f);
  52.  
  53.     return u.i1;
  54. }
  55.  
  56. void putLittle32 ( INT32 num , FILE *f )
  57. {
  58.     union 
  59.     {
  60.         struct
  61.         {
  62.             UINT8    b1, b2, b3, b4;
  63.         };
  64.         UINT32     i1;
  65.     } u;
  66.  
  67.     u.i1 = num;
  68.  
  69.     fputc( u.b1, f );
  70.     fputc( u.b2, f );
  71.     fputc( u.b3, f );
  72.     fputc( u.b4, f );
  73. }
  74.  
  75. INT32 getLittle32 (FILE *f)
  76. {
  77.     union 
  78.     {
  79.         struct
  80.         {
  81.             UINT8    b1, b2, b3, b4;
  82.         };
  83.         UINT32     i1;
  84.     } u;
  85.  
  86.     u.b1 = fgetc(f);
  87.     u.b2 = fgetc(f);
  88.     u.b3 = fgetc(f);
  89.     u.b4 = fgetc(f);
  90.  
  91.     return u.i1;
  92. }
  93.  
  94. void putLittleFloat( float num  , FILE *f )//32bit floating point number
  95. {
  96.     union 
  97.     {
  98.         struct
  99.         {
  100.             UINT8    b1, b2, b3, b4;
  101.         };
  102.         float     f1;
  103.     } u;
  104.  
  105.     u.f1 = num;
  106.  
  107.     fputc( u.b1, f );
  108.     fputc( u.b2, f );
  109.     fputc( u.b3, f );
  110.     fputc( u.b4, f );
  111. }
  112.  
  113. float getLittleFloat (FILE *f) //32bit floating point number
  114. {
  115.     union 
  116.     {
  117.         struct
  118.         {
  119.             UINT8    b1, b2, b3, b4;
  120.         };
  121.         float     f1;
  122.     } u;
  123.  
  124.     u.b1 = fgetc(f);
  125.     u.b2 = fgetc(f);
  126.     u.b3 = fgetc(f);
  127.     u.b4 = fgetc(f);
  128.  
  129.     return u.f1;
  130. }
  131.  
  132. void putBig16 ( INT16 num , FILE *f )
  133. {
  134.     union 
  135.     {
  136.         struct
  137.         {
  138.             UINT8    b1, b2, b3, b4;
  139.         };
  140.         INT16     i1;
  141.     } u;
  142.  
  143.     u.i1 = num;
  144.  
  145.     fputc( u.b2, f );
  146.     fputc( u.b1, f );
  147. }
  148.  
  149. INT16 getBig16 (FILE *f)
  150. {
  151.     union 
  152.     {
  153.         struct
  154.         {
  155.             UINT8    b1, b2;
  156.         };
  157.         UINT16     i1;
  158.     } u;
  159.  
  160.     u.b2 = fgetc(f);
  161.     u.b1 = fgetc(f);
  162.  
  163.     return u.i1;
  164. }
  165.  
  166. void putBig32 ( INT32 num , FILE *f )
  167. {
  168.     union 
  169.     {
  170.         struct
  171.         {
  172.             UINT8    b1, b2, b3, b4;
  173.         };
  174.         INT32     i1;
  175.     } u;
  176.  
  177.     u.i1 = num;
  178.  
  179.     fputc( u.b4, f );
  180.     fputc( u.b3, f );
  181.     fputc( u.b2, f );
  182.     fputc( u.b1, f );
  183. }
  184.  
  185. INT32 getBig32 (FILE *f)
  186. {
  187.     union 
  188.     {
  189.         struct
  190.         {
  191.             UINT8    b1, b2, b3, b4;
  192.         };
  193.         UINT32     i1;
  194.     } u;
  195.  
  196.     u.b4 = fgetc(f);
  197.     u.b3 = fgetc(f);
  198.     u.b2 = fgetc(f);
  199.     u.b1 = fgetc(f);
  200.  
  201.     return u.i1;
  202. }
  203.  
  204. void putBigFloat ( float num , FILE *f ) //32bit floating point number
  205. {
  206.     union 
  207.     {
  208.         struct
  209.         {
  210.             UINT8    b1, b2, b3, b4;
  211.         };
  212.         float     f1;
  213.     } u;
  214.  
  215.     u.f1 = num;
  216.  
  217.     fputc( u.b4, f );
  218.     fputc( u.b3, f );
  219.     fputc( u.b2, f );
  220.     fputc( u.b1, f );
  221. }
  222.  
  223. float getBigFloat (FILE *f) //32bit floating point number
  224. {
  225.     union 
  226.     {
  227.         struct
  228.         {
  229.             UINT8    b1, b2, b3, b4;
  230.         };
  231.         float     f1;
  232.     } u;
  233.  
  234.     u.b4 = fgetc(f);
  235.     u.b3 = fgetc(f);
  236.     u.b2 = fgetc(f);
  237.     u.b1 = fgetc(f);
  238.  
  239.     return u.f1;
  240. }
  241.