// ###########################################################################
// #
// # OSCAPS2Devices - Definition of OSCA PS2 Device Emulation (Mouse/KB)
// # Copyright (C) 2009-2011 Tony Friery [DialTone]
// #
// # ALL RIGHTS RESERVED
// #
// ###########################################################################

#ifndef OSCAPS2DevicesH
#define OSCAPS2DevicesH

#include "z80.h"
#include <System.hpp>

///////////////////////////////////////////////////////////////////////
//
//		Definition of PS2 Device Types and Constants
//
///////////////////////////////////////////////////////////////////////

typedef enum
{
	DEVICE_IDLE,		// Idle State
	HOST_RTS,			// Host is Ready to send (PS2 in recv mode)
	DEVICE_RTS			// Device is Ready to send
} PS2DeviceState;

///////////////////////////////////////////////////////////////////////
//
//		Definition of PS2 Device Handler Class
//
///////////////////////////////////////////////////////////////////////

class TOSCAPS2Device
{
	private:
		bool								fClockIn;
		bool								fDataIn;
		bool								fClockOut;
		bool								fDataOut;
		int								fClockPrescaler;
		byte								fBitCount;
		byte								fRecvData;
		bool								fRecvParity;
		bool								fParityCount;

		virtual void __fastcall		GotByte(byte Value) = 0;

	protected:
		bool								fIRQState;
		PS2DeviceState					fCurrentState;
		byte								fDeviceBuffer[32];
		byte								fReadPointer;
		byte								fWritePointer;

	public:
		void __fastcall				PushByte(byte Value);
		void __fastcall				WriteToDevice(bool Clock, bool Data);
		bool __fastcall				GetIRQState(void);
		void __fastcall				ClearIRQ(void);
		virtual void __fastcall		Reset(void);
		bool __fastcall				GetClock(void);
		bool __fastcall				GetData(void);
		byte __fastcall				GetDataByte(void);
		bool __fastcall				Tick(unsigned int cycles);

		__fastcall 						TOSCAPS2Device();
};

//---------------------------------------------------------------------------

#endif

