7 Miscellaneous I/O routines.. used to solve some portability issues
8 (like big/little endian machines and word alignment in structures )
9 Also includes mikmod's ingenious error handling variable + some much
13 All systems - all compilers
19 char *ERROR_ALLOC_STRUCT="Error allocating structure";
20 char *ERROR_LOADING_PATTERN="Error loading pattern";
21 char *ERROR_LOADING_TRACK="Error loading track";
22 char *ERROR_LOADING_HEADER="Error loading header";
23 char *ERROR_NOT_A_MODULE="Unknown module format";
24 char *ERROR_LOADING_SAMPLEINFO="Error loading sampleinfo";
25 char *ERROR_OUT_OF_HANDLES="Out of sample-handles";
26 char *ERROR_SAMPLE_TOO_BIG="Sample too big, out of memory";
30 static long _mm_iobase=0;
32 int _mm_fseek(FILE *stream, long offset, int whence)
35 (whence==SEEK_SET) ? offset+_mm_iobase : offset,
39 long _mm_ftell(FILE *stream)
41 return ftell(stream)-_mm_iobase;
44 void _mm_setiobase(long iobase)
49 void _mm_write_SBYTE(SBYTE data,FILE *fp)
54 void _mm_write_UBYTE(UBYTE data,FILE *fp)
59 void _mm_write_M_UWORD(UWORD data,FILE *fp)
61 _mm_write_UBYTE(data>>8,fp);
62 _mm_write_UBYTE(data&0xff,fp);
65 void _mm_write_I_UWORD(UWORD data,FILE *fp)
67 _mm_write_UBYTE(data&0xff,fp);
68 _mm_write_UBYTE(data>>8,fp);
71 void _mm_write_M_SWORD(SWORD data,FILE *fp)
73 _mm_write_M_UWORD((UWORD)data,fp);
76 void _mm_write_I_SWORD(SWORD data,FILE *fp)
78 _mm_write_I_UWORD((UWORD)data,fp);
81 void _mm_write_M_ULONG(ULONG data,FILE *fp)
83 _mm_write_M_UWORD(data>>16,fp);
84 _mm_write_M_UWORD(data&0xffff,fp);
87 void _mm_write_I_ULONG(ULONG data,FILE *fp)
89 _mm_write_I_UWORD(data&0xffff,fp);
90 _mm_write_I_UWORD(data>>16,fp);
93 void _mm_write_M_SLONG(SLONG data,FILE *fp)
95 _mm_write_M_ULONG((ULONG)data,fp);
98 void _mm_write_I_SLONG(SLONG data,FILE *fp)
100 _mm_write_I_ULONG((ULONG)data,fp);
104 #define DEFINE_MULTIPLE_WRITE_FUNCTION(type_name, type) \
106 _mm_write_##type_name##S (type *buffer, int number, FILE *fp) \
109 _mm_write_##type_name(*(buffer++),fp); \
114 DEFINE_MULTIPLE_WRITE_FUNCTION ( SBYTE, SBYTE)
115 DEFINE_MULTIPLE_WRITE_FUNCTION (UBYTE, UBYTE)
117 DEFINE_MULTIPLE_WRITE_FUNCTION (M_SWORD, SWORD)
118 DEFINE_MULTIPLE_WRITE_FUNCTION (M_UWORD, UWORD)
119 DEFINE_MULTIPLE_WRITE_FUNCTION (I_SWORD, SWORD)
120 DEFINE_MULTIPLE_WRITE_FUNCTION (I_UWORD, UWORD)
122 DEFINE_MULTIPLE_WRITE_FUNCTION (M_SLONG, SLONG)
123 DEFINE_MULTIPLE_WRITE_FUNCTION (M_ULONG, ULONG)
124 DEFINE_MULTIPLE_WRITE_FUNCTION (I_SLONG, SLONG)
125 DEFINE_MULTIPLE_WRITE_FUNCTION (I_ULONG, ULONG)
128 SBYTE _mm_read_SBYTE(FILE *fp)
133 UBYTE _mm_read_UBYTE(FILE *fp)
138 UWORD _mm_read_M_UWORD(FILE *fp)
140 UWORD result=((UWORD)_mm_read_UBYTE(fp))<<8;
141 result|=_mm_read_UBYTE(fp);
145 UWORD _mm_read_I_UWORD(FILE *fp)
147 UWORD result=_mm_read_UBYTE(fp);
148 result|=((UWORD)_mm_read_UBYTE(fp))<<8;
152 SWORD _mm_read_M_SWORD(FILE *fp)
154 return((SWORD)_mm_read_M_UWORD(fp));
157 SWORD _mm_read_I_SWORD(FILE *fp)
159 return((SWORD)_mm_read_I_UWORD(fp));
162 ULONG _mm_read_M_ULONG(FILE *fp)
164 ULONG result=((ULONG)_mm_read_M_UWORD(fp))<<16;
165 result|=_mm_read_M_UWORD(fp);
169 ULONG _mm_read_I_ULONG(FILE *fp)
171 ULONG result=_mm_read_I_UWORD(fp);
172 result|=((ULONG)_mm_read_I_UWORD(fp))<<16;
176 SLONG _mm_read_M_SLONG(FILE *fp)
178 return((SLONG)_mm_read_M_ULONG(fp));
181 SLONG _mm_read_I_SLONG(FILE *fp)
183 return((SLONG)_mm_read_I_ULONG(fp));
187 int _mm_read_str(char *buffer,int number,FILE *fp)
189 fread(buffer,1,number,fp);
194 #define DEFINE_MULTIPLE_READ_FUNCTION(type_name, type) \
196 _mm_read_##type_name##S (type *buffer, int number, FILE *fp) \
199 *(buffer++)=_mm_read_##type_name(fp); \
205 DEFINE_MULTIPLE_READ_FUNCTION ( SBYTE, SBYTE)
206 DEFINE_MULTIPLE_READ_FUNCTION (UBYTE, UBYTE)
208 DEFINE_MULTIPLE_READ_FUNCTION (M_SWORD, SWORD)
209 DEFINE_MULTIPLE_READ_FUNCTION (M_UWORD, UWORD)
210 DEFINE_MULTIPLE_READ_FUNCTION (I_SWORD, SWORD)
211 DEFINE_MULTIPLE_READ_FUNCTION (I_UWORD, UWORD)
213 DEFINE_MULTIPLE_READ_FUNCTION (M_SLONG, SLONG)
214 DEFINE_MULTIPLE_READ_FUNCTION (M_ULONG, ULONG)
215 DEFINE_MULTIPLE_READ_FUNCTION (I_SLONG, SLONG)
216 DEFINE_MULTIPLE_READ_FUNCTION (I_ULONG, ULONG)