home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 3 / PDCD_3.iso / utilities / utilss / sprtools / h / io < prev    next >
Text File  |  1994-07-18  |  4KB  |  143 lines

  1. /****************************************************************************
  2.  *                                                                          *
  3.  * io.h                                                                     *
  4.  * ====                                                                     *
  5.  *                                                                          *
  6.  * I/O routines for image conversion programs                               *
  7.  *                                                                          *
  8.  * Version 1.00 (13-Aug-1993)                                               *
  9.  *         1.10 (20-Aug-1993) read_struct & write_struct added              *
  10.  *         1.20 (22-Aug-1993) new endian routines added                     *
  11.  *         1.30 (23-Aug-1993) progess function added                        *
  12.  *         1.42 (12-Oct-1993) progess start & finish functions added        *
  13.  *                                                                          *
  14.  * (C) 1993 DEEJ Technology PLC                                             *
  15.  *                                                                          *
  16.  ****************************************************************************/
  17.  
  18. #ifndef __io_h
  19. #define __io_h
  20.  
  21. #define uchar  unsigned char
  22. #define ushort unsigned short
  23. #define uint   unsigned int
  24.  
  25. #ifndef BYTE
  26. #define BYTE  unsigned char
  27. #define WORD  unsigned short
  28. #define DWORD unsigned int
  29. #endif
  30.  
  31. /* endian type definititions */
  32.  
  33. #define LITTLE_ENDIAN   0
  34. #define BIG_ENDIAN      1
  35. #define LE              LITTLE_ENDIAN
  36. #define BE              BIG_ENDIAN
  37.  
  38. /**** machine configuration ****/
  39.  
  40. #ifdef RISCOS
  41. #define ENDIAN_TYPE     LITTLE_ENDIAN
  42. #define ALIGN_WORD      2
  43. #define ALIGN_DWORD     4
  44. #define ENDIAN_MACROS
  45. #endif
  46.  
  47. #ifdef M68K
  48. /* 68000 based */
  49. #define ENDIAN_TYPE     BIG_ENDIAN
  50. #define ALIGN_WORD      2
  51. #define ALIGN_DWORD     2
  52. #endif
  53.  
  54. #ifdef SPARC
  55. #define ENDIAN_TYPE     BIG_ENDIAN
  56. #define ALIGN_WORD      2
  57. #define ALIGN_DWORD     4
  58. #endif
  59.  
  60. #ifdef PA_RISC
  61. #define ENDIAN_TYPE     BIG_ENDIAN
  62. #define ALIGN_WORD      2
  63. #define ALIGN_DWORD     4
  64. #endif
  65.  
  66. /* add new machine definitions here */
  67.  
  68. #ifndef ENDIAN_TYPE
  69. /* comment follow line if compiler does not support it */
  70. #error "io.h: Not setup for this machine"
  71. #endif
  72.  
  73. #ifndef TRUE
  74. #define TRUE 1
  75. #define FALSE 0
  76. #endif
  77. #ifndef BOOL
  78. #define BOOL int
  79. #endif
  80.  
  81. /* macros */
  82.  
  83. #ifdef ENDIAN_MACROS
  84.  
  85. #define swap_endian(dword) ( ((dword & 0xff000000)>>24) | \
  86.                          ((dword & 0x00ff0000)>>8)  | \
  87.                          ((dword & 0x0000ff00)<<8)  | \
  88.                          ((dword & 0x000000ff)<<24) )
  89.  
  90. #define swap_endian_word(word) ( ((ushort)(word & 0xff00)>>8) | \
  91.                                  ((ushort)(word & 0x00ff)<<8) )
  92.  
  93. #define endian(type,dword)  ((type!=ENDIAN_TYPE) ? swap_endian(dword) : dword)
  94. #define endian_w(type,word) ((type!=ENDIAN_TYPE) ? swap_endian(word)  : word)
  95.  
  96. #define bit_swap(byte) ( ((byte & 0x80)>>7) | \
  97.                          ((byte & 0x40)>>5) | \
  98.                          ((byte & 0x20)>>3) | \
  99.                          ((byte & 0x10)>>1) | \
  100.                          ((byte & 0x08)<<1) | \
  101.                          ((byte & 0x04)<<3) | \
  102.                          ((byte & 0x02)<<5) | \
  103.                          ((byte & 0x01)<<7) )
  104.  
  105. #define bit2_swap(byte) ( ((byte & 0xC0)>>6) | \
  106.                           ((byte & 0x30)>>2) | \
  107.                           ((byte & 0x0C)<<2) | \
  108.                           ((byte & 0x03)<<6) )
  109.  
  110. #define bit4_swap(byte) ( ((byte & 0xF0)>>4) | \
  111.                           ((byte & 0x0F)<<4) )
  112.  
  113. #else
  114.  
  115. extern uint   bit_swap(uint);
  116. extern uint   bit2_swap(uint);
  117. extern uint   bit4_swap(uint);
  118. extern uint   swap_endian(uint);
  119. extern ushort swap_endian_word(ushort);
  120. extern uint   endian(int, uint);
  121. extern ushort endian_w(int, ushort);
  122.  
  123. #endif
  124.  
  125. /* function prototypes */
  126.  
  127. extern void   fputwLE(WORD, FILE*);
  128. extern ushort fgetwLE(FILE*);
  129. extern void   fputwBE(WORD, FILE*);
  130. extern ushort fgetwBE(FILE*);
  131. extern void   fputdLE(DWORD, FILE*);
  132. extern uint   fgetdLE(FILE*);
  133. extern void   fputdBE(DWORD, FILE*);
  134. extern uint   fgetdBE(FILE*);
  135. extern void   file_args(int, char**, FILE**, FILE**, FILE**);
  136. extern void   read_struct(int, BYTE*, int*, FILE*);
  137. extern void   write_struct(int, BYTE*, int*, FILE*);
  138. extern void   progress_start(char*);
  139. extern void   progress(int, int);
  140. extern void   progress_finish(void);
  141.  
  142. #endif
  143.