/*
 * $Id: global.h 4.13 1998/08/09 12:09:06 olsen Exp olsen $
 *
 * :ts=4
 *
 * Copyright © 1997-1998 Village Tronic Computer
 */

#ifndef _GLOBAL_H
#define _GLOBAL_H 1

/****************************************************************************/

#include <exec/execbase.h>
#include <exec/memory.h>
#include <exec/tasks.h>
#include <exec/resident.h>

#include <devices/timer.h>

#include <clib/exec_protos.h>
#include <clib/utility_protos.h>
#include <clib/timer_protos.h>
#include <clib/alib_protos.h>
#include <clib/dos_protos.h>

#include <pragmas/exec_sysbase_pragmas.h>
#include <pragmas/utility_pragmas.h>
#include <pragmas/timer_pragmas.h>
#include <pragmas/dos_pragmas.h>

#define USE_BUILTIN_MATH
#include <string.h>
#include <stdarg.h>
#include <dos.h>

/****************************************************************************/

#include <devices/ahi.h>
#include <libraries/ahi_sub.h>

#include <clib/ahi_sub_protos.h>
#include <pragmas/ahi_sub_pragmas.h>

/****************************************************************************/

#include "libraries/concierto.h"
#include "clib/concierto_protos.h"
#include "pragmas/concierto_pragmas.h"

/****************************************************************************/

#define REG(x)				register __ ## x
#define ASM					__asm
#define INTERRUPT			__interrupt

#define BIT_IS_SET(v,f)		(((v) & (1UL << (f))) != 0)
#define BIT_IS_UNSET(v,f)	(((v) & (1UL << (f))) == 0)

#define PORT_MASK(p)		(1UL << (p)->mp_SigBit)

#define FAILED				(0)

#define DONT				!
#define NO					!
#define NOT					!

/****************************************************************************/

#define DRIVERSTATUS_Idle	0
#define DRIVERSTATUS_Play	1
#define DRIVERSTATUS_Record	2

/****************************************************************************/

#define SIGB_Kill		SIGBREAKB_CTRL_C
#define SIGB_Reload		SIGBREAKB_CTRL_F

#define SIGF_Kill		(1UL<<SIGB_Kill)
#define SIGF_Reload		(1UL<<SIGB_Reload)

#define SIGF_Sync		SIGF_SINGLE

/****************************************************************************/

#define TASK_STACK_SIZE 8000

#define TASK_PRIORITY_UNSET 256

/****************************************************************************/

	/* The global library base. */

struct P4AHIBase
{
	struct Library				ab_Library;
	BPTR						ab_Segment;
	struct SignalSemaphore		ab_LibrarySemaphore;
	UWORD						ab_Pad0;	/* align to long-word boundary */

	struct ExecBase *			ab_SysBase;
	struct Library *			ab_UtilityBase;
	struct Library *			ab_ConciertoBase;
	struct Library *			ab_DOSBase;

	struct SignalSemaphore		ab_DriverSemaphore;
	BOOL						ab_DriverInUse;

	ULONG						ab_AudioFlags;
	struct AHIAudioCtrlDrv *	ab_AudioCtrl;

	struct Task					ab_Task;
	BOOL						ab_TaskRunning;
	WORD						ab_TaskPriority;
	UBYTE						ab_TaskStack[TASK_STACK_SIZE + 16];
	struct Task *				ab_Parent;
	ULONG						ab_RecordingSource;
	ULONG						ab_MonitorVolume;

	struct AudioContext *		ab_AudioContext;
	UBYTE *						ab_WorkBuffer[2];
	ULONG						ab_WorkBufferSize;
	LONG						ab_Bits;

	struct Hook					ab_ReloadHook;
	struct DSPQueryPacket		ab_Query;
};

/****************************************************************************/

#define SysBase			P4AHIBase->ab_SysBase
#define UtilityBase		P4AHIBase->ab_UtilityBase
#define DOSBase			P4AHIBase->ab_DOSBase
#define ConciertoBase	P4AHIBase->ab_ConciertoBase

/****************************************************************************/

#define RECORDBUFFER_SIZE 8000

/****************************************************************************/

#include "protos.h"

/****************************************************************************/

#endif	/* _GLOBAL_H */
