4 ** Copyright (C) 1995 Bernardo Innocenti
6 ** Load a FastTracker ][ module with any number of tracks.
9 #include <exec/memory.h>
10 #include <libraries/XModule.h>
12 #include <clib/exec_protos.h>
13 #include <clib/dos_protos.h>
14 #include <clib/xmodule_protos.h>
16 #include <pragmas/exec_sysbase_pragmas.h>
17 #include <pragmas/dos_pragmas.h>
18 #include <pragmas/xmodule_pragmas.h>
21 #include "FastTracker2.h"
24 /* Convert an Intel style WORD to Motorola format */
25 #define I2M(x) ( (UWORD) ( (((UWORD)(x)) >> 8) | (((UWORD)(x)) << 8) ) )
27 /* Convert an Intel style LONG to Motorola format */
28 #define I2ML(x) ( I2M((x)>>16) | (I2M((x))<<16) )
32 LONG GetFT2 (struct SongInfo *si, BPTR fh)
34 ULONG i, j; /* Loop counters */
35 struct FT2Header ft2hd;
38 /* Read module header */
39 if (Read (fh, &ft2hd, sizeof (ft2hd)) != sizeof (ft2hd))
42 /* Convert from Intel's shitty endian */
43 ft2hd.HeaderSize = I2ML(ft2hd.HeaderSize);
44 ft2hd.Length = I2M(ft2hd.Length);
45 ft2hd.Restart = I2M(ft2hd.Restart);
46 ft2hd.Channels = I2M(ft2hd.Channels);
47 ft2hd.NumPatt = I2M(ft2hd.NumPatt);
48 ft2hd.NumInstr = I2M(ft2hd.NumInstr);
49 ft2hd.Flags = I2M(ft2hd.Flags);
50 ft2hd.DefTempo = I2M(ft2hd.DefTempo);
51 ft2hd.DefBPM = I2M(ft2hd.DefBPM);
53 if (!xmSetSongLen (si, ft2hd.Length))
54 return ERROR_NO_FREE_STORE;
56 if (Read (fh, si->Sequence, si->Length * sizeof (UWORD)) !=
57 si->Length * sizeof (UWORD))
60 for (i = 0; i < si->Length; i++)
61 si->Sequence[i] = I2M(si->Sequence[i]);
63 si->Restart = ft2hd.Restart;
64 si->GlobalSpeed = ft2hd.DefTempo;
65 si->GlobalTempo = ft2hd.DefBPM;