/* ============================================
     zmd2mid MIDファイル ヘッダブロック仮作成
   ============================================ */

#include <stdio.h>
#include <stdlib.h>
#include "etc.h"

#include "config.h"
UBYTE *makeMThd(UBYTE *MThd,int trks,int Z);

UBYTE *makeMThd(UBYTE *MThd,int trks,int Z)
{
	UBYTE *MThd_ = MThd;
#ifdef DEBUG
	FILE *fp;
#endif
	putDwordAlign(MThd,0x4D546864);		/* == 'MThd' */
	MThd += 4;
	putDwordAlign(MThd,6);				/* header size */
	MThd += 4;
	putWordAlign(MThd,1);				/* format type */
	MThd += 2;
	*MThd++ = 0;
	*MThd++ = trks;						/* トラック数 */
	Z &= 0xFFFF;
	*MThd++ = (UBYTE)(Z >> 8);
	*MThd   = (UBYTE)(Z & 0xFF);		/* 四分音符の分解能 */
#ifdef DEBUG
	fp = fopen("MThd","wb");			/* for debug */
	fwrite(MThd_,sizeof(unsigned char),14,fp);
	fclose(fp);
#endif
	return MThd_;
}
