22. DWORD id; // MMD1-MMD3
23. DWORD modlen; // Size of file
24. DWORD song; // Position in file for this song
27. DWORD blockarr; // Position in file for blocks
29. DWORD smplarr; // Position in file for samples
31. DWORD expdata; // Absolute offset in file for ExpData (0 if not present)
39. BYTE extra_songs; // # of songs - 1
42. typedef struct tagMMD0SAMPLE
51. // MMD0/MMD1 song header
52. typedef struct tagMMD0SONGHEADER
54. MMD0SAMPLE sample[63];
55. WORD numblocks; // # of blocks
56. WORD songlen; // # of entries used in playseq
57. BYTE playseq[256]; // Play sequence
58. WORD deftempo; // BPM tempo
59. signed char playtransp; // Play transpose
60. BYTE flags; // 0x10: Hex Volumes | 0x20: ST/NT/PT Slides | 0x40: 8 Channels song
61. BYTE flags2; // [b4-b0]+1: Tempo LPB, 0x20: tempo mode, 0x80: mix_conv=on
62. BYTE tempo2; // tempo TPL
63. BYTE trkvol[16]; // track volumes
64. BYTE mastervol; // master volume
65. BYTE numsamples; // # of samples (max=63)
68. typedef struct tagMMD0EXP
70. DWORD nextmod; // File offset of next Hdr
71. DWORD exp_smp; // Pointer to extra instrument data
72. WORD s_ext_entries; // Number of extra instrument entries
73. WORD s_ext_entrsz; // Size of extra instrument data
76. DWORD iinfo; // Instrument names
81. BYTE channelsplit[4]; // Only used if 8ch_conv (extra channel for every nonzero entry)
83. DWORD songname; // Song name
89. DWORD trackinfo_ofs; // ptr to song->numtracks ptrs to tag lists
90. DWORD effectinfo_ofs; // ptr to group ptrs
96. // Byte swapping functions from the GNU C Library and libsdl
98. /* Swap bytes in 16 bit value. */
100. # define bswap_16(x)
102. ({ unsigned short int __bsx = (x);
103. ((((__bsx) >> 8) & 0xff) | (((__bsx) & 0xff) << 8)); }))
105. static __inline unsigned short int
106. bswap_16 (unsigned short int __bsx)
108. return ((((__bsx) >> 8) & 0xff) | (((__bsx) & 0xff) << 8));
112. /* Swap bytes in 32 bit value. */
114. # define bswap_32(x)
116. ({ unsigned int __bsx = (x);
117. ((((__bsx) & 0xff000000) >> 24) | (((__bsx) & 0x00ff0000) >> 8) |
118. (((__bsx) & 0x0000ff00) << 8) | (((__bsx) & 0x000000ff) << 24)); }))
120. static __inline unsigned int
121. bswap_32 (unsigned int __bsx)
123. return ((((__bsx) & 0xff000000) >> 24) | (((__bsx) & 0x00ff0000) >> 8) |
124. (((__bsx) & 0x0000ff00) << 8) | (((__bsx) & 0x000000ff) << 24));
128. #ifdef WORDS_BIGENDIAN
129. #define bswapLE16(X) bswap_16(X)
130. #define bswapLE32(X) bswap_32(X)
131. #define bswapBE16(X) (X)
132. #define bswapBE32(X) (X)
134. #define bswapLE16(X) (X)
135. #define bswapLE32(X) (X)
136. #define bswapBE16(X) bswap_16(X)
137. #define bswapBE32(X) bswap_32(X)
142. MEDMODULEHEADER mmh;
148. memset(&mmh, 0, sizeof (mmh));
149. memset(&msh, 0, sizeof (msh));
150. memset(&mex, 0, sizeof (mex));
154. mmh.id = 0x30444D4D; // version = '0'
156. p += sizeof (MEDMODULEHEADER);
157. mmh.song = bswapBE32(p);
159. p += sizeof (MMD0SONGHEADER);
160. mmh.expdata = bswapBE32(p);
162. p += sizeof (MMD0EXP);
163. mex.annolen = bswapBE32(-1);
164. mex.annotxt = bswapBE32(p);
166. file = fopen("test.s3m", "wb+");
169. printf("create file failed!
173. fwrite(&mmh, 1, sizeof (mmh), file);
174. fwrite(&msh, 1, sizeof (msh), file);
175. fwrite(&mex, 1, sizeof (mex), file);
177. while ( ftell(file) < 0x1000 )
179. fwrite("AAAAAAAAAAAAAAAAAAAA", 1, 16, file);