#ifndef XMODULE_PRIV_H
#define XMODULE_PRIV_H
/*
**	XModulePriv.h
**
**	Copyright (C) 1993,94,95,96,97 Bernardo Innocenti
**
**	Use 4 chars wide TABs to read this source
**
**	Private definitions for internal XModule use
*/

#ifndef	EXEC_NODES_H
#include <exec/nodes.h>
#endif /* !EXEC_NODES_H */

#ifndef	EXEC_LIBRARIES_H
#include <exec/libraries.h>
#endif /* !EXEC_LIBRARIES_H */

#ifndef	DOS_DOS_H
#include <dos/dos.h>
#endif /* !DOS_DOS_H */

#ifndef	DOS_DOS_H
#include <dos/dos.h>
#endif /* !DOS_DOS_H */

#ifndef	LIBRARIES_IFFPARSE_H
#include "libraries/iffparse.h"
#endif /* LIBRARIES_IFFPARSE_H */

#ifndef LIBRARIES_XMODULE_H
#include <libraries/xmodule.h>
#endif /* !LIBRARIES_XMODULE_H */

#ifndef LIBRARIES_SONGCLASS_H
#include <libraries/songclass.h>
#endif /* !LIBRARIES_SONGCLASS_H */

#include "XModule_rev.h"
#include "LocaleStrings.h"
#include "ListMacros.h"
#include "CompilerSpecific.h"
#include "Debug.h"			/* Debug support */

/* Single object compilation requires different attributes for global symbols */
#ifdef SINGLE_OBJECT
	#undef XREF
	#undef XDEF
	#undef GLOBALCALL
	#define XREF		extern
	#define XDEF		static
	#define GLOBALCALL	static
	#ifdef __SASC
//		#pragma msg 72 ignore
		#pragma msg 181 ignore
	#endif
#endif


/* Version information: updated auto-magically on every compilation ;-) */

#define XMODULEVER	VERS
#define XMODULEDATE	"(" DATE ")"
#define XMODULECOPY	"Copyright © 1993,94,95,96,97 by Bernardo Innocenti"

#ifdef OS30_ONLY
	#ifdef _M68020
		#define BUILDMODE "[M68020 OS3.0]"
	#else
		#define BUILDMODE "[M68000 OS3.0]"
	#endif
#else
	#ifdef _M68020
		#define BUILDMODE "[M68020 OS2.0]"
	#else
		#define BUILDMODE "[M68000 OS2.0]"
	#endif
#endif



/*************************/
/* Constants Definitions */
/*************************/

/* Maximum values */
#define MAXTABLEEFFECTS	 20			/* Number of entries in effect conversion table	*/
#define PATHNAME_MAX	108			/* Maximum length of an AmigaDOS path name		*/


/* Specific error codes */
#define ERROR_NOTMODULE	ERROR_OBJECT_WRONG_TYPE	/* File format not recognized		*/
#define ERROR_IOERR		RETURN_FAIL				/* A DOS call (e.g.: Read()) failed.
												 * check IoErr() for specific error.
												 */

/* Default directory for external hooks */
#define DEF_HOOKSDIR "PROGDIR:Hooks/"


/***********************/
/* Function Prototypes */
/***********************/

/* From "Audio.c" */
GLOBALCALL void		HandleAudio				(void);
GLOBALCALL void		PlaySample				(BYTE *samp, ULONG len, UWORD vol, UWORD per);
GLOBALCALL ULONG	SetupAudio				(void);
GLOBALCALL void		CleanupAudio			(void);

/* From "Misc.c" */
GLOBALCALL struct Library *MyOpenLibrary	(CONST_STRPTR name, ULONG ver);
GLOBALCALL void		CantOpenLib				(CONST_STRPTR name, LONG vers);
GLOBALCALL void		KillMsgPort				(struct MsgPort *mp);
GLOBALCALL struct TextAttr *CopyTextAttrPooled	(void *pool, const struct TextAttr *source, struct TextAttr *dest);
GLOBALCALL UWORD	CmpTextAttr				(const struct TextAttr *ta1, const struct TextAttr *ta2);
GLOBALCALL STRPTR	DupStringPooled			(void *pool, CONST_STRPTR source, STRPTR *dest);
GLOBALCALL void		FilterName				(STRPTR name);
GLOBALCALL struct DiskObject *GetProgramIcon (void);
GLOBALCALL LONG		PutIcon					(CONST_STRPTR source, CONST_STRPTR dest);
GLOBALCALL LONG		BackupFile				(CONST_STRPTR src, CONST_STRPTR template, ULONG versions);

/* From "Gui.c" (More functions prototyped in "Gui.h") */
GLOBALCALL LONG		HandleGui				(void);

/* From "Rexx.c" */
GLOBALCALL void		HandleRexxMsg			(void);
GLOBALCALL LONG		CreateRexxPort			(void);
GLOBALCALL void		DeleteRexxPort			(void);

/* From "ToolBoxWin.c" */
GLOBALCALL void		ToolBoxOpenModule		(CONST_STRPTR file, ULONG num, ULONG count);

/* From "Help.c" */
GLOBALCALL void		HandleHelp				(struct IntuiMessage *msg);
GLOBALCALL void		HandleAmigaGuide		(void);
GLOBALCALL void		CleanupHelp				(void);

/* From "Cx.c" */
GLOBALCALL LONG		SetupCx					(void);
GLOBALCALL void		HandleCx				(void);
GLOBALCALL void		CleanupCx				(void);

/* From "ProgressWin.c" */
GLOBALCALL void		DisplayAction			(ULONG msg);
GLOBALCALL void		DisplayActionStr		(CONST_STRPTR str);
GLOBALCALL LONG		DisplayProgress			(LONG Num, LONG Max);
GLOBALCALL void		ShowMessage				(ULONG msg, ...);
GLOBALCALL void		ShowString				(CONST_STRPTR s, LONG *args);

/* From "PlayWin.c" */
GLOBALCALL LONG		SetupPlayer				(void);
GLOBALCALL void		CleanupPlayer			(void);

/* From "Compress.c" */
GLOBALCALL BPTR		DecompressFile			(CONST_STRPTR name, UWORD type);
GLOBALCALL void		DecompressFileDone		(void);
GLOBALCALL LONG		CruncherType			(BPTR file);

/* From "Song.c" */
GLOBALCALL Class *	InitSongClass			(void);
GLOBALCALL void		FreeSongClass			(Class *cl);
GLOBALCALL void		FixSong					(struct SongInfo *si);
GLOBALCALL ULONG	CalcInstSize			(struct SongInfo *si);
GLOBALCALL ULONG	CalcSongSize			(struct SongInfo *si);
GLOBALCALL ULONG	CalcSongTime			(struct SongInfo *si);

/* From "Instr.c" */
GLOBALCALL LONG		LoadInstrument			(struct SongInfo *si, ULONG num, CONST_STRPTR filename);
GLOBALCALL LONG		SaveInstrument			(struct Instrument *inst, CONST_STRPTR filename);
GLOBALCALL LONG		Load8SVXInstrument		(struct SongInfo *si, ULONG num, struct IFFHandle *iff, CONST_STRPTR filename);
GLOBALCALL LONG		Save8SVXInstrument		(struct Instrument *inst, ULONG num, struct IFFHandle *iff);
GLOBALCALL void		OptimizeInstruments		(struct SongInfo *si);
GLOBALCALL void		RemDupInstruments		(struct SongInfo *si);
GLOBALCALL void		RemUnusedInstruments	(struct SongInfo *si);
GLOBALCALL void		RemapInstruments		(struct SongInfo *si);
GLOBALCALL void		SampChangeSign8			(UBYTE *samp, ULONG len);

/* From "Operators.c" */
GLOBALCALL ULONG	InsertPattern			(struct SongInfo *si, struct Pattern *patt, UWORD patnum);
GLOBALCALL struct SongInfo *MergeSongs		(struct SongInfo *songa, struct SongInfo *songb);
GLOBALCALL struct SongInfo *JoinSongs		(struct SongInfo *songa, struct SongInfo *songb);
GLOBALCALL void		RemDupPatterns 			(struct SongInfo *si);
GLOBALCALL void		DiscardPatterns			(struct SongInfo *si);
GLOBALCALL void		CutPatterns				(struct SongInfo *si);
GLOBALCALL LONG		ResizePatterns			(struct SongInfo *si, ULONG min, ULONG max);
GLOBALCALL struct Pattern	*CopyPattern	(struct SongInfo *si, struct Pattern *src, ULONG destNum);

/* From "Prefs.c" */
GLOBALCALL LONG		LoadPrefs				(CONST_STRPTR filename);
GLOBALCALL LONG		SavePrefs				(CONST_STRPTR filename);

/* From "Library.c" */
GLOBALCALL ULONG	MakeXModuleLibrary		(void);
GLOBALCALL void		DisposeXModuleLibrary	(void);

/* From "Locale.c" */
GLOBALCALL void		SetupLocale				(void);
GLOBALCALL void		CleanupLocale			(void);

/* From "XModuleHook.c" */
GLOBALCALL void		AddXModuleHooks			(void);
GLOBALCALL LONG		LoadSong				(struct IFFHandle *iff, struct SongInfo *si);
GLOBALCALL struct Pattern *LoadPattern		(struct SongInfo *si, ULONG num, struct IFFHandle *iff);
GLOBALCALL LONG		SaveSong				(struct IFFHandle *iff, struct SongInfo *si);
GLOBALCALL LONG		SaveSequence			(struct IFFHandle *iff, struct SongInfo *si);
GLOBALCALL LONG		SavePatterns			(struct IFFHandle *iff, struct SongInfo *si);
GLOBALCALL LONG		SaveInstruments			(struct IFFHandle *iff, struct SongInfo *si);
GLOBALCALL LONG		SavePattern				(struct IFFHandle *iff, struct Pattern *patt);
GLOBALCALL LONG		WriteStringChunk		(struct IFFHandle *iff, CONST_STRPTR name, ULONG id);

/* From "TrackerHook.c" */
GLOBALCALL void	AddTrackerHooks	(void);

/* From "Startup.asm" */
extern void			_XCEXIT		(LONG err);
extern void			SPrintf		(UBYTE *buf, CONST_STRPTR formatstr, ...);
extern void STDARGS	VSPrintf	(UBYTE *buf, CONST_STRPTR formatstr, void *argv);
extern struct WBStartup	*WBenchMsg;
extern struct Process	*ThisTask;


#ifndef OS30_ONLY

/* Memory pools support for pre-V39 OS */

#define CreatePool(f,p,t)	LibCreatePool((f),(p),(t))
#define DeletePool(p)		LibDeletePool(p)
#define AllocPooled(p,s)	AsmAllocPooled((p), (s), SysBase)
#define FreePooled(p,m,s)	AsmFreePooled((p), (m), (s), SysBase)

extern ASMCALL void *AsmAllocPooled		(REG(a0, void *pool), REG(d0, ULONG size), REG(a6, struct ExecBase *SysBase));
extern ASMCALL void *AsmFreePooled		(REG(a0, void *pool), REG(a1, void *drop), REG(d0, ULONG size), REG(a6, struct ExecBase *SysBase));

#endif /* !OS30_ONLY */


/* More memory pools support */

#ifdef PORTABLE
	GLOBALCALL void *CAllocPooled	(void *pool, ULONG size);
	GLOBALCALL void *AllocVecPooled	(void *pool, ULONG size);
	GLOBALCALL void FreeVecPooled	(void *pool, void *drop);
#else
	#define AllocVecPooled(p,s)	AsmAllocVecPooled((p), (s), SysBase)
	#define FreeVecPooled(p,m)	AsmFreeVecPooled((p), (m), SysBase)
	#define CAllocPooled(p,s)	AsmCAllocPooled((p), (s), SysBase)

	extern ASMCALL void *AsmCAllocPooled	(REG(a0, void *pool), REG(d0, ULONG size), REG(a6, struct ExecBase *SysBase));
	extern ASMCALL void *AsmAllocVecPooled	(REG(a0, void *pool), REG(d0, ULONG size), REG(a6, struct ExecBase *SysBase));
	extern ASMCALL void AsmFreeVecPooled	(REG(a0, void *pool), REG(a1, void *drop), REG(a6, struct ExecBase *SysBase));
#endif


/* Use these macros when the corresponding functions are not available.
 * GLOBALCALL void	InstallGfxFunctions		(void);
 * GLOBALCALL ULONG (*ReadAPen)(struct RastPort *RPort);
 * GLOBALCALL ULONG (*ReadBPen)(struct RastPort *RPort);
 * GLOBALCALL ULONG (*ReadDrMd)(struct RastPort *RPort);
 */



/********************/
/* Global variables */
/********************/

XREF struct Catalog	*Catalog;
XREF void			*Pool;
XREF STRPTR			 AppStrings[];
XREF BOOL			 Verbose;
XREF BPTR			 StdOut;
XREF LONG			 LastErr;
XREF UBYTE			 PubPortName[];

XREF BYTE			 CxPri;
XREF UBYTE			 CxPopKey[32];
XREF BOOL			 CxPopup;

XREF LONG			 IconX;
XREF LONG			 IconY;
XREF UBYTE			 IconName[16];

XREF const UBYTE	 Version[];
XREF const UBYTE	 BaseName[];	/* All caps		*/
XREF const UBYTE	 PrgName[];		/* Mixed case	*/

#endif /* !XMODULE_PRIV_H */

