annotate mmio/mmio.c @ 11:d5cb2cfc8eca

Initial revision
author darius
date Fri, 23 Jan 1998 16:05:11 +0000
parents 55420dceb8e0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
1 /*
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
2 --> The MMIO Portable Input/Output functions
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
3 -> Divine Entertainment GameDev Libraries
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
4
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
5 File: MMIO.C
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
6
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
7 Description:
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
8 Miscellaneous I/O routines.. used to solve some portability issues
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
9 (like big/little endian machines and word alignment in structures )
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
10 Also includes mikmod's ingenious error handling variable.
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
11
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
12 Portability:
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
13 All systems - all compilers
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
14
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
15
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
16 -----------------------------------
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
17 The way this module works - By Jake Stine [Air Richter]
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
18
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
19 - _mm_fopen and _mm_copyfile will call the errorhandler [see mmerror.c] in
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
20 addition to setting _mm_errno on exit.
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
21
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
22 - _mm_iobase is for internal use. It is used by ML_LoadFP() to ensure that it
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
23 works properly with wad files.
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
24
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
25 - _mm_read_I_UWORD and _mm_read_M_UWORD have distinct differences:
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
26 the first is for reading data written by a little endian (intel) machine,
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
27 and the second is for reading big endian (Mac, RISC, Alpha) machine data.
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
28
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
29 - _mm_write functions work the same as the _mm_read functions.
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
30
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
31 - _mm_read_string is for reading binary strings. It is basically the same
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
32 as an fread of bytes.
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
33 */
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
34
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
35 #include "mmio.h"
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
36 #include <string.h>
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
37
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
38 #define COPY_BUFSIZE 1024
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
39
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
40 static long _mm_iobase = 0,
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
41 temp_iobase = 0;
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
42
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
43 UBYTE _mm_cpybuf[COPY_BUFSIZE];
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
44
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
45
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
46 void StringWrite(CHAR *s, FILE *fp)
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
47 // Specialized file output procedure. Writes a UWORD length and then a
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
48 // string of the specified length (no NULL terminator) afterward.
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
49 {
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
50 int slen;
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
51
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
52 if(s==NULL)
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
53 { _mm_write_I_UWORD(0,fp);
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
54 } else
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
55 { _mm_write_I_UWORD(slen = strlen(s),fp);
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
56 _mm_write_UBYTES(s,slen,fp);
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
57 }
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
58 }
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
59
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
60 CHAR *StringRead(FILE *fp)
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
61 // Reads strings written out by StringWrite above: a UWORD length followed
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
62 // by length characters. A NULL is added to the string after loading.
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
63 {
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
64 CHAR *s;
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
65 UWORD len;
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
66
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
67 len = _mm_read_I_UWORD(fp);
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
68 if(len==0)
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
69 { s = _mm_calloc(16, sizeof(CHAR));
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
70 } else
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
71 { if((s = (CHAR *)_mm_malloc(len+1)) == NULL) return NULL;
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
72 _mm_read_UBYTES(s,len,fp);
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
73 s[len] = 0;
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
74 }
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
75
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
76 return s;
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
77 }
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
78
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
79
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
80 FILE *_mm_fopen(CHAR *fname, CHAR *attrib)
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
81 {
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
82 FILE *fp;
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
83
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
84 if((fp=fopen(fname,attrib)) == NULL)
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
85 { _mm_errno = _mm_errno = MMERR_OPENING_FILE;
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
86 if(_mm_errorhandler!=NULL) _mm_errorhandler();
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
87 }
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
88 return fp;
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
89 }
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
90
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
91
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
92 int _mm_fseek(FILE *stream, long offset, int whence)
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
93 {
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
94 return fseek(stream,(whence==SEEK_SET) ? offset+_mm_iobase : offset, whence);
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
95 }
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
96
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
97
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
98 long _mm_ftell(FILE *stream)
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
99 {
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
100 return ftell(stream)-_mm_iobase;
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
101 }
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
102
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
103
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
104 BOOL _mm_FileExists(CHAR *fname)
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
105 {
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
106 FILE *fp;
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
107
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
108 if((fp=fopen(fname,"r")) == NULL) return 0;
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
109 fclose(fp);
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
110
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
111 return 1;
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
112 }
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
113
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
114
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
115 long _mm_flength(FILE *stream)
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
116 {
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
117 long tmp,tmp2;
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
118
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
119 tmp = ftell(stream);
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
120 fseek(stream,0,SEEK_END);
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
121 tmp2 = ftell(stream);
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
122 fseek(stream,tmp,SEEK_SET);
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
123 return tmp2-tmp;
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
124 }
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
125
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
126
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
127 long _mm_iobase_get(void)
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
128 {
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
129 return _mm_iobase;
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
130 }
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
131
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
132
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
133 void _mm_iobase_set(long iobase)
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
134 {
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
135 temp_iobase = _mm_iobase; // store old value in case of revert
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
136 _mm_iobase = iobase;
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
137 }
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
138
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
139
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
140 // Sets the current file-position as the new _mm_iobase
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
141 void _mm_iobase_setcur(FILE *fp)
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
142 {
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
143 temp_iobase = _mm_iobase; // store old value in case of revert
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
144 _mm_iobase = ftell(fp);
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
145 }
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
146
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
147
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
148 // Reverts to the last known _mm_iobase value.
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
149 void _mm_iobase_revert(void)
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
150 {
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
151 _mm_iobase = temp_iobase;
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
152 }
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
153
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
154
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
155 // Procedure: _mm_copyfile
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
156 // Copies a given number of bytes from the source file to the destination
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
157 // file. Returns 1 on error, and calls the _mm_errnohandler, if registered.
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
158 BOOL _mm_copyfile(FILE *fpi, FILE *fpo, ULONG len)
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
159 {
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
160 ULONG todo;
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
161
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
162 while(len)
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
163 { todo = (len > COPY_BUFSIZE) ? COPY_BUFSIZE : len;
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
164 if(!fread(_mm_cpybuf, todo, 1, fpi))
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
165 { _mm_errno = _mm_errno = MMERR_END_OF_FILE;
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
166 if(_mm_errorhandler!=NULL) _mm_errorhandler();
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
167 return 1;
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
168 }
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
169 if(!fwrite(_mm_cpybuf, todo, 1, fpo))
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
170 { _mm_errno = _mm_errno = MMERR_DISK_FULL;
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
171 if(_mm_errorhandler!=NULL) _mm_errorhandler();
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
172 return 1;
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
173 }
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
174 len -= todo;
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
175 }
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
176
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
177 return 0;
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
178 }
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
179
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
180
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
181 void _mm_write_string(CHAR *data, FILE *fp)
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
182 {
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
183 if(data!=NULL)
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
184 _mm_write_UBYTES(data, strlen(data), fp);
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
185 }
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
186
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
187
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
188 void _mm_fputs(FILE *fp, CHAR *data)
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
189 {
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
190 if(data != NULL)
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
191 _mm_write_UBYTES(data, strlen(data), fp);
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
192
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
193 #ifndef __UNIX__
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
194 _mm_write_UBYTE(13,fp);
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
195 #endif
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
196 _mm_write_UBYTE(10,fp);
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
197 }
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
198
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
199
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
200
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
201 /*************
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
202 // These have accompanying #define's in mmio.h
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
203
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
204 void _mm_write_SBYTE(SBYTE data, FILE *fp)
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
205 {
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
206 fputc(data,fp);
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
207 }
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
208
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
209 void _mm_write_UBYTE(UBYTE data,FILE *fp)
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
210 {
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
211 fputc(data,fp);
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
212 }
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
213 */
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
214
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
215 #ifdef MM_BIG_ENDIAN
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
216
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
217 // --> Big Endian Write Functions
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
218
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
219 void _mm_write_M_UWORD(UWORD data,FILE *fp)
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
220 {
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
221 _mm_write_UBYTE(data&0xff,fp);
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
222 _mm_write_UBYTE(data>>8,fp);
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
223 }
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
224
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
225
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
226 void _mm_write_I_UWORD(UWORD data,FILE *fp)
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
227 {
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
228 _mm_write_UBYTE(data>>8,fp);
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
229 _mm_write_UBYTE(data&0xff,fp);
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
230 }
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
231
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
232
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
233 void _mm_write_M_ULONG(ULONG data,FILE *fp)
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
234 {
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
235 _mm_write_M_UWORD(data&0xffff,fp);
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
236 _mm_write_M_UWORD(data>>16,fp);
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
237 }
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
238
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
239
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
240 void _mm_write_I_ULONG(ULONG data,FILE *fp)
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
241 {
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
242 _mm_write_I_UWORD(data>>16,fp);
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
243 _mm_write_I_UWORD(data&0xffff,fp);
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
244 }
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
245
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
246 #else
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
247
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
248 // --> Little Endian Write Functions
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
249
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
250 void _mm_write_M_UWORD(UWORD data,FILE *fp)
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
251 {
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
252 _mm_write_UBYTE(data>>8,fp);
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
253 _mm_write_UBYTE(data&0xff,fp);
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
254 }
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
255
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
256
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
257 void _mm_write_I_UWORD(UWORD data,FILE *fp)
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
258 {
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
259 _mm_write_UBYTE(data&0xff,fp);
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
260 _mm_write_UBYTE(data>>8,fp);
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
261 }
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
262
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
263
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
264 void _mm_write_M_ULONG(ULONG data,FILE *fp)
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
265 {
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
266 _mm_write_M_UWORD(data>>16,fp);
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
267 _mm_write_M_UWORD(data&0xffff,fp);
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
268 }
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
269
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
270
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
271 void _mm_write_I_ULONG(ULONG data,FILE *fp)
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
272 {
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
273 _mm_write_I_UWORD(data&0xffff,fp);
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
274 _mm_write_I_UWORD(data>>16,fp);
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
275 }
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
276
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
277 #endif
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
278
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
279
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
280 void _mm_write_M_SWORD(SWORD data,FILE *fp)
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
281 {
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
282 _mm_write_M_UWORD((UWORD)data,fp);
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
283 }
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
284
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
285
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
286 void _mm_write_I_SWORD(SWORD data,FILE *fp)
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
287 {
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
288 _mm_write_I_UWORD((UWORD)data,fp);
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
289 }
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
290
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
291
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
292 void _mm_write_M_SLONG(SLONG data,FILE *fp)
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
293 {
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
294 _mm_write_M_ULONG((ULONG)data,fp);
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
295 }
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
296
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
297
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
298 void _mm_write_I_SLONG(SLONG data,FILE *fp)
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
299 {
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
300 _mm_write_I_ULONG((ULONG)data,fp);
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
301 }
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
302
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
303
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
304 #define DEFINE_MULTIPLE_WRITE_FUNCTION(type_name, type) \
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
305 void \
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
306 _mm_write_##type_name##S (type *buffer, int number, FILE *fp) \
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
307 { \
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
308 while(number>0) \
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
309 { _mm_write_##type_name(*(buffer++),fp); \
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
310 number--; \
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
311 } \
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
312 }
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
313
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
314 //DEFINE_MULTIPLE_WRITE_FUNCTION (SBYTE, SBYTE)
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
315 //DEFINE_MULTIPLE_WRITE_FUNCTION (UBYTE, UBYTE)
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
316
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
317 DEFINE_MULTIPLE_WRITE_FUNCTION (M_SWORD, SWORD)
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
318 DEFINE_MULTIPLE_WRITE_FUNCTION (M_UWORD, UWORD)
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
319 DEFINE_MULTIPLE_WRITE_FUNCTION (I_SWORD, SWORD)
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
320 DEFINE_MULTIPLE_WRITE_FUNCTION (I_UWORD, UWORD)
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
321
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
322 DEFINE_MULTIPLE_WRITE_FUNCTION (M_SLONG, SLONG)
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
323 DEFINE_MULTIPLE_WRITE_FUNCTION (M_ULONG, ULONG)
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
324 DEFINE_MULTIPLE_WRITE_FUNCTION (I_SLONG, SLONG)
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
325 DEFINE_MULTIPLE_WRITE_FUNCTION (I_ULONG, ULONG)
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
326
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
327
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
328 /**********
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
329 SBYTE _mm_read_SBYTE(FILE *fp)
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
330 {
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
331 return(fgetc(fp));
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
332 }
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
333
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
334 UBYTE _mm_read_UBYTE(FILE *fp)
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
335 {
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
336 return(fgetc(fp));
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
337 }
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
338 **********/
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
339
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
340
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
341 #ifdef MM_BIG_ENDIAN
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
342
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
343 UWORD _mm_read_I_UWORD(FILE *fp)
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
344 {
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
345 UWORD result=((UWORD)_mm_read_UBYTE(fp))<<8;
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
346 result|=_mm_read_UBYTE(fp);
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
347 return result;
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
348 }
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
349
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
350 UWORD _mm_read_M_UWORD(FILE *fp)
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
351 {
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
352 UWORD result=_mm_read_UBYTE(fp);
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
353 result|=((UWORD)_mm_read_UBYTE(fp))<<8;
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
354 return result;
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
355 }
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
356
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
357 ULONG _mm_read_I_ULONG(FILE *fp)
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
358 {
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
359 ULONG result=((ULONG)_mm_read_M_UWORD(fp))<<16;
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
360 result|=_mm_read_M_UWORD(fp);
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
361 return result;
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
362 }
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
363
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
364 ULONG _mm_read_M_ULONG(FILE *fp)
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
365 {
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
366 ULONG result=_mm_read_I_UWORD(fp);
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
367 result|=((ULONG)_mm_read_I_UWORD(fp))<<16;
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
368 return result;
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
369 }
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
370
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
371 #else
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
372
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
373 UWORD _mm_read_M_UWORD(FILE *fp)
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
374 {
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
375 UWORD result=((UWORD)_mm_read_UBYTE(fp))<<8;
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
376 result|=_mm_read_UBYTE(fp);
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
377 return result;
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
378 }
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
379
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
380 UWORD _mm_read_I_UWORD(FILE *fp)
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
381 {
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
382 UWORD result=_mm_read_UBYTE(fp);
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
383 result|=((UWORD)_mm_read_UBYTE(fp))<<8;
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
384 return result;
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
385 }
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
386
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
387 ULONG _mm_read_M_ULONG(FILE *fp)
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
388 {
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
389 ULONG result=((ULONG)_mm_read_M_UWORD(fp))<<16;
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
390 result|=_mm_read_M_UWORD(fp);
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
391 return result;
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
392 }
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
393
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
394 ULONG _mm_read_I_ULONG(FILE *fp)
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
395 {
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
396 ULONG result=_mm_read_I_UWORD(fp);
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
397 result|=((ULONG)_mm_read_I_UWORD(fp))<<16;
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
398 return result;
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
399 }
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
400
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
401 #endif
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
402
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
403 SWORD _mm_read_M_SWORD(FILE *fp)
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
404 {
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
405 return((SWORD)_mm_read_M_UWORD(fp));
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
406 }
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
407
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
408 SWORD _mm_read_I_SWORD(FILE *fp)
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
409 {
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
410 return((SWORD)_mm_read_I_UWORD(fp));
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
411 }
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
412
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
413 SLONG _mm_read_M_SLONG(FILE *fp)
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
414 {
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
415 return((SLONG)_mm_read_M_ULONG(fp));
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
416 }
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
417
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
418 SLONG _mm_read_I_SLONG(FILE *fp)
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
419 {
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
420 return((SLONG)_mm_read_I_ULONG(fp));
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
421 }
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
422
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
423
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
424 int _mm_read_string(CHAR *buffer, int number, FILE *fp)
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
425 {
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
426 fread(buffer,1,number,fp);
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
427 return !feof(fp);
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
428 }
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
429
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
430
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
431
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
432 #define DEFINE_MULTIPLE_READ_FUNCTION(type_name, type) \
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
433 int \
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
434 _mm_read_##type_name##S (type *buffer, int number, FILE *fp) \
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
435 { \
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
436 while(number>0) \
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
437 { *(buffer++)=_mm_read_##type_name(fp); \
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
438 number--; \
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
439 } \
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
440 return !feof(fp); \
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
441 }
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
442
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
443 //DEFINE_MULTIPLE_READ_FUNCTION (SBYTE, SBYTE)
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
444 //DEFINE_MULTIPLE_READ_FUNCTION (UBYTE, UBYTE)
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
445
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
446 DEFINE_MULTIPLE_READ_FUNCTION (M_SWORD, SWORD)
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
447 DEFINE_MULTIPLE_READ_FUNCTION (M_UWORD, UWORD)
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
448 DEFINE_MULTIPLE_READ_FUNCTION (I_SWORD, SWORD)
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
449 DEFINE_MULTIPLE_READ_FUNCTION (I_UWORD, UWORD)
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
450
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
451 DEFINE_MULTIPLE_READ_FUNCTION (M_SLONG, SLONG)
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
452 DEFINE_MULTIPLE_READ_FUNCTION (M_ULONG, ULONG)
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
453 DEFINE_MULTIPLE_READ_FUNCTION (I_SLONG, SLONG)
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
454 DEFINE_MULTIPLE_READ_FUNCTION (I_ULONG, ULONG)
55420dceb8e0 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
455