/* MED.h V 2.10 by Teijo Kinnunen 1989, 1990 */
/* MED.h V 1.1  9.7.1989 -- uusi kappale */
/* MED.h V 1.11 4.8.1989 -- ukkeli + värit */
/* MED.h V 1.12 28.9.1989 -- CLohko */
/* MED.h V 1.20 5.10.1989 -- Softwareinteruptdata */
/* MED.h V 1.201 15.10.1989 -- osiot */
/* MED.h V 1.202 18.10.1989 -- okdefinet */
/* MED.h V 1.203 21.11.1989 -- lisää okdefineitä */
/* MED.h V 1.210 28.12.1989 -- MIDI-kamat */
/* MED.h V 1.220 29.12.1989 -- savel_period -> savel_num */
/* MED.h V 1.221 30.12.1989 -- Kappale -> Kappale + Kappale111 */
/* MED.h V 1.230 08.01.1990 -- Uusi Lohko */
/* MED.h V 1.240 23.01.1990 -- Soitin-structure */
/* MED.h V 1.250 20.02.1990 -- ST 2.4 module */
/* MED.h V 1.251 26.02.1990 -- MIDIIEVENTS ja okdefinet pois */
/* MED.h V 1.260 03.06.1990 -- ObjSong, osiot pois */
/* MED.h V 2.000 10.03.1990 -- vähän turhia pois, UUSI VERSIONUMERO */
/* MED.h V 2.100 13.04.1990 -- pathrakenteet */
/* MED.h V 2.110 25.04.1990 -- uusi Kappale */
/* MED.h V 2.120 21.05.1990 -- lohkon pituus säädeltävä */
/* MED.h V 2.130 07.06.1990 -- MMD0 & MMD0song */
/* MED.h V 2.131 12.06.1990 -- voim. hex/dec */
/* MED.h V 2.132 19.06.1990 -- MMD0sample */
/* MED.h V 2.140 14.07.1990 -- Kappale200 tuhottu */

struct Lohko { /* ** UUTTA 8.1.1990 ** */
	UBYTE	numtracks;
	UBYTE	lines; /* 0 = 1 line, 255 = 256 lines */
	UBYTE	pad[2];
	ULONG	hlmask[8]; /* 256 bits */
	UBYTE	music[1]; /* size varies */
}; /* note: bits in hlmasks are in reverse order (bit #0 is line 0) */
#define BLKHDRSZ 36

struct MMD0Block {
	UBYTE numtracks,lines;
};	/* a bit shorter version is used in modules to save memory */
#define MMDBLKHDRSZ 2
#define ALATEEMITAAN 0 /* Soittokäskyt */
#define SOITALOHKO 1
#define SOITAKAPPALE 2
#define OHJELMANLOPPU 3
#define SEIS 4
#define SOITANUOTTI 5

#define ALASOITA 0 /* soittotila */
#define SOITALOHKOA 1
#define SOITAKAPPALETTA 2

#define	FLAG_FILTERON	0x1 /* liput */
#define	FLAG_JUMPINGON	0x2
#define	FLAG_JUMP8TH	0x4
#define	FLAG_INSTRSATT	0x8 /* instruments are attached (this is a module) */
#define	FLAG_VOLHEX	0x10
#define  FLAG_STSLIDE	0x20 /* SoundTracker mode for slides */

struct Kappale111 { /* 1.11 */
	ULONG id; /* sisältää "MED\x02" versiolle 1.11 */
	char soitin[32][40];
	UBYTE soittimenvoimakkuus[32];
	UWORD stoisto[32];
	UWORD stoistonpit[32];
	UWORD lohkoja; /* montako lohkoa kappaleessa on */
	UBYTE soittojarjestys[100]; /* lohkojen soittoj... */
	UWORD kappaleen_pituus; /* montako soittojärjestystä */
	UWORD tempo; /* kappaleen tempo, jos ei ilmoitettu komennolla xFxx */
	UWORD liput;
	UWORD vaihtoja; /* 5 tai 6 */
	ULONG hyppysoitin; /* jokainen bitti on 1 soitin */
	UWORD rgb[8]; /* vain 4 nyt käytössä */
};

struct SongSample {
	char sname[40];		/* offs: 0 */
	UWORD rep,replen;		/* offs: 40, 42 */
	UBYTE midich,midipreset;	/* offs: 44, 45 */
	UBYTE svol;			/* offs: 46 */
	BYTE  strans;			/* offs: 47 */
}; /* 48 bytes */

struct Kappale {
	ULONG	id; /* MED\x04 for v2.10 */	/* offs: 0 */
	struct SongSample sample[63]; /* 48 * 63 = 3024 */
	UWORD	numblocks;		/* offs: 3028 */
	UWORD	songlen;		/* offs: 3030 */
	UBYTE	playseq[256];		/* offs: 3032 */
	UWORD	deftempo;		/* offs: 3288 */
	BYTE	playtransp;		/* offs: 3290 */
	UBYTE	flags;			/* offs: 3291 */
	UWORD	sliding;		/* offs: 3292 */
	ULONG	jumpmask;		/* offs: 3294 */
	UWORD	rgb[8];			/* offs: 3298 */
	UBYTE	trkvol[16];		/* offs: 3314 */
	UBYTE	mastervol;		/* offs: 3330 */
	UBYTE	pad;
};	/* length = 3332 bytes */

struct MMD0 {
/* 0 */	ULONG id;
/* 4 */	ULONG modlen; /* 0 if this module is not one continuous block */
/* 8 */	struct MMD0song *song;
/* 12 */	ULONG songlen; /* 0 if this module is a continuous block */
/* 16 */	struct MMD0block **blockarr; /* ptr to table of block pointers */
/* 20 */	ULONG blockarrlen; /* length of the table of block ptrs (bytes) */
/* 24 */	struct Soitin **smplarr; /* ptr to table of sample ptrs */
/* 28 */	ULONG smplarrlen; /* length of the table */
/* 32 */	CPTR expdata;	/* future expansion...should be 0 now */
/* 36 */	ULONG expsize; /* 0, please */
/* 40 */	UWORD pstate;	 /* some data for player routine */
/* 42 */	UWORD pblock;
/* 44 */	UWORD pline;
/* 46 */	UWORD pseqnum;
/* 48 */	WORD actplayline; /* these variables allow flexible switching */
/* 50 */	UBYTE counter; /* of songs */
/* 51 */	UBYTE pad;
}; /* length = 52 bytes */

struct MMD0sample {
	UWORD rep,replen;	/* offs: 0(s), 2(s) */
	UBYTE midich;		/* offs: 4(s) */
	UBYTE midipreset;	/* offs: 5(s) */
	UBYTE svol;		/* offs: 6(s) */
	BYTE strans;		/* offs: 7(s) */
};
struct MMD0song {
	struct MMD0sample sample[63]; /* 63 * 8 bytes = 504 bytes */
	UWORD	numblocks;		/* offs: 504 */
	UWORD	songlen;		/* offs: 506 */
	UBYTE	playseq[256];		/* offs: 508 */
	UWORD	deftempo;		/* offs: 764 */
	BYTE	playtransp;		/* offs: 766 */
	UBYTE	flags;			/* offs: 767 */
	UWORD	sliding;		/* offs: 768 */
	UBYTE	trkvol[16];		/* offs: 770 */
	UBYTE	mastervol;		/* offs: 786 */
	UBYTE	numsamples;		/* offs: 787 */
}; /* length = 788 bytes */

struct SoundTrackerIns { /* instrumenttidata */
	char sti_nimi[22];
	UWORD sti_pit; /* soittimen pituus (jostakin syystä jaettuna 2:lla) */
	UWORD sti_vol; /*  -  " -   voimakkuus */
	UWORD sti_repeat; /* mikä lie */
	UWORD sti_replen; /*   -"-    */
};

struct SoundTrackerKappale { /* suunnilleen, ei niin tarkasti */
	char st_nimi[20];
	struct SoundTrackerIns st_ins[15];
	UBYTE st_kappaleen_pit; /* soitettavien lohkojen määrä */
	UBYTE st_kummajainen; /* 0x78 ?? */
	UBYTE st_lohkojarj[128];
 /* tästä alkaa lohkot.... */
};

struct PlayNotedata {
	UBYTE playnote; /* 0 = no note to play, 1 = play this */
	UBYTE notenum;
	UBYTE instrnum;
	UBYTE tracknum;
};

struct Soitin {
	ULONG	length;
	UWORD	type;
	/* Followed by digitized data */
};

#define	IFF5OCT	1
#define	IFF3OCT	2

struct ST24Mod {
	char songname[20];
	struct {
		char name[22];
		UWORD length;
		UWORD volume;
		UWORD repeat;
		UWORD replen;
	} sample[31];
	UBYTE songlen;
	UBYTE I_dont_know_what_this_byte_is;
	UBYTE playseq[128];
	ULONG mk; /* contains M.K. ??? */
};

struct PSName {
	struct PSName *prev,*next;
	UBYTE namelen;	/* length of the name only */
	UBYTE firstletter; /* the first letter of the name in upper case */
/*	char name[]; the name, maybe followed by ::1234/5678 */
};

struct PSDir {
	struct PSDir *prev,*next;
	struct PSName *first,*last;
	UWORD entries;
	UBYTE namelen;
	UBYTE diravail;
/*	char name[] */
};

struct FData { struct FData *prev,*next; char fname[108]; LONG type; };

struct PrgNote {
	unsigned notenum:6,
		  xnn:1,
		  x0th:1,
		  x1st:1,
		  x2nd:1,
		  x3rd:1,
		  x4th:1,
		  num0:1,
		  num1:5,
		  num2:4,
		  num3:4,
		  num4:4;
};

#define DISKERR ((char *)-1)
#define NOERR ((char *)0)
extern char *nomem,*fileex,*notsaved;
