//---------------------------------------------------------------------------
#ifndef DriverH
#define DriverH
//---------------------------------------------------------------------------
#include <windows.h>


#define FILE_DEVICE_MAPMEM  0x00008000


#define IOCTL_KTAPI_DRV_MEMMAP                  0x82007000

#define IOCTL_KTAPI_DRV_UNMEMMAP                0x82007100

#define IOCTL_KTAPI_DRV_IO_BLOCK			       0x82007200


#define PORTTALK_TYPE 40000 // 32768-65535 are reserved for customers

// The IOCTL function codes from 0x800 to 0xFFF are for customer use.

#define IOCTL_IOPM_RESTRICT_ALL_ACCESS \
    CTL_CODE(PORTTALK_TYPE, 0x900, METHOD_BUFFERED, FILE_ANY_ACCESS)

#define IOCTL_IOPM_ALLOW_EXCUSIVE_ACCESS \
    CTL_CODE(PORTTALK_TYPE, 0x901, METHOD_BUFFERED, FILE_ANY_ACCESS)

#define IOCTL_SET_IOPM \
    CTL_CODE(PORTTALK_TYPE, 0x902, METHOD_BUFFERED, FILE_ANY_ACCESS)

#define IOCTL_ENABLE_IOPM_ON_PROCESSID \
    CTL_CODE(PORTTALK_TYPE, 0x903, METHOD_BUFFERED, FILE_ANY_ACCESS)

#define IOCTL_READ_PORT_UCHAR \
    CTL_CODE(PORTTALK_TYPE, 0x904, METHOD_BUFFERED, FILE_ANY_ACCESS)

#define IOCTL_WRITE_PORT_UCHAR \
    CTL_CODE(PORTTALK_TYPE, 0x905, METHOD_BUFFERED, FILE_ANY_ACCESS)


typedef struct
{
        ULONG   INDEX;
        ULONG   DATA;
} IOCELL;

typedef struct
    {
        ULONG  InterfaceType; // Isa, Eisa, etc....
        ULONG            BusNumber;     // Bus number
        LARGE_INTEGER    BusAddress;    // Bus-relative address
        ULONG            AddressSpace;  // 0 is memory, 1 is I/O
        ULONG            Length;        // Length of section to map
    } PHYSICAL_MEMORY_INFO, *PPHYSICAL_MEMORY_INFO;


	/*
    // 32 Bit IO
    VOID outpd(DWORD port,DWORD data);
    DWORD inpd(DWORD port);

    // 16 Bit IO
    VOID outpw(USHORT port,USHORT data);
    USHORT inpw(USHORT port);

    // 8 Bit IO
    VOID outp(USHORT port,UCHAR data);
    UCHAR inp(USHORT port);
*/

    PUCHAR MapMem(DWORD offset,DWORD nbytes);
    //USHORT Delay_1ms (VOID);

    DWORD InitializeDriver(VOID);
    DWORD UninitializeDriver(VOID);

    UCHAR TalkToDriver(DWORD IOCTL_CODE,PVOID IOBUF,DWORD DATA_SIZE);
    DWORD GetOSVersion(VOID);

	VOID UnMapMem(void * PartyMem);

    BOOL IsDriverOnDisk(PCHAR DRV_NAME);
    BOOL CreateDriver(PCHAR DRV_NAME);
    VOID EnableRealTime(BOOL REALTIME);

    BOOL InstallDriver(SC_HANDLE SchSCManager, LPCTSTR DriverName, LPCTSTR ServiceExe);

    BOOL RemoveDriver(SC_HANDLE SchSCManager, LPCTSTR DriverName);

    BOOL StartDriver(IN SC_HANDLE  SchSCManager, LPCTSTR DriverName);

    BOOL StopDriver(SC_HANDLE SchSCManager, LPCTSTR DriverName);

#endif
