/* Copyright (c) 2013 Fredrik Wikstrom. All rights reserved.
**
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions
** are met:
**
** 1. Redistributions of source code must retain the above copyright
**    notice, this list of conditions and the following disclaimer.
**
** 2. Redistributions in binary form must reproduce the above copyright
**    notice, this list of conditions and the following disclaimer in the
**    documentation and/or other materials provided with the distribution.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
** CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
** ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
** POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef FLITE_DEVICE_H
#define FLITE_DEVICE_H

#include <exec/exec.h>
#include <dos/dos.h>
#include <proto/exec.h>
#include <proto/dos.h>
#include <devices/flite.h>
#include <devices/newstyle.h>
#include <string.h>

#ifdef DEBUG
#define dbug(args) ((struct ExecIFace *)(*(struct ExecBase **)4)->MainInterface)->DebugPrintF args
#else
#define dbug(args)
#endif

struct FliteBase {
	struct Library fb_LibNode;
	BPTR fb_SegList;
	struct SignalSemaphore *fb_SigSem;
	struct MsgPort *fb_Port;
	struct FliteUnit *fb_Unit;
};

struct FliteMessage {
	struct Message fm_Msg;
	struct FliteUnit *fm_Unit;
};

struct FliteUnit {
	uint32 fu_OpenCnt;
	struct FliteBase *fu_LibBase;

	struct SignalSemaphore *fu_SigSem;
	struct MsgPort *fu_Port;
	struct FliteMessage *fu_FliteMsg;
	struct DeathMessage *fu_DeathMsg;

	void *fu_Voice;
	float fu_Duration;
	float fu_Pitch;
};

/* io.c */
LONG libAbortIO (struct DeviceManagerInterface *Self, struct IORequest *which_io);
void libBeginIO (struct DeviceManagerInterface *Self, struct IOStdReq *io);

/* unit.c */
int32 UnitProcEntry (char *argstr, int32 arglen, struct ExecBase *sysbase);

#endif
