#ifndef _POCKETDOS_API_H
#define _POCKETDOS_API_H

/*

	PocketDOS API v1.0 (c) 1997-2003 PocketDOS

	PocketDOS v1.07.3 and later support loading and calling a service 
	function from a BIOS extension library. This requires a specialised
	DLL to be developed which exports a PDOS_BIOS_Service function. This
	function can then be called from a program running under PocketDOS.
	All registers are passed to the DLL function, and pointers are provided
	to the start of the ES, CS, DS, SS segments. These pointers are pointers
	into the 1MB PC/XT address space, and so any modifications to this memory
	will modify the memory of the emulated PC/XT. It is important to modify
	only memory which is owned by the calling program, to avoid crashing the
	emulated PC/XT. Any changes made to registers in the PDOS_BIOS_Service 
	function will be reflected in the emulated x86 registers on return from the
	function, apart from the IP and segment registers. The DLL function is also
	provided with the CF flag and a copy of the flag register. Changes to the 
	CF flag will be reflected in the emulated x86 flag register, but changes to
	the copy of the flag register provided will be ignored. 

	To use a BIOS extension library from a DOS application, the library must be
	built using this header file and must export the following function:

	extern "C" void PDOS_BIOS_Service( tPDOS_x86Regs *pREG )

	The library can then be loaded and used from a DOS application with the 
	INT F8 software interrupt, which is detailed below:

	INT F8, 00 - Open PocketDOS BIOS extension library

		AH = 00h
		ES:BX = Null terminated ASCII string containing DLL name

		on return:
		AL = 00h if library missing or failed to load
		AL = FFh if no more extensions can be loaded
		AL = handle to library if library loaded OK

		- Supported on PocketDOS 1.07.3 and later

	INT F8, 01 - Close PocketDOS BIOS extension library

		AH = 01h
		AL = handle to library

		returns nothing

		- Supported on PocketDOS 1.07.3 and later

	INT F8, 02 - Call PocketDOS BIOS extension

		AH = 02h
		AL = handle to library

		returns nothing

		- Calls PDOS_BIOS_Service function in extension library
		- Supported on PocketDOS 1.07.3 and later

	An example DLL function:

	extern "C" __declspec(dllexport) void PDOS_BIOS_Service( tPDOS_x86Regs *pREG )
	{
	char *pFileName = (char *) &pREG->pES[pREG->nBX.word];

		...

		pREG->nAX.lo = 0;
		pREG->nCF = 1;
	}

*/

/* Name of entry point used for PocketDOS BIOS extensions */
#define PDOS_BIOS_SERVICEFN TEXT( "PDOS_BIOS_Service" )

/* Specify structure packing */
#pragma pack(4)   

/* PocketDOS x86 register definition. Currently, PocketDOS only uses 16 bit
   registers and so the upper word in "dword" is ignored */
typedef struct 
{
	union 
	{
		DWORD dword;
		struct 
		{
			union 
			{
				WORD word;
				struct 
				{
					BYTE lo;
					BYTE hi;
				};
			};
			WORD nReserved;
		};
	};
} tPDOS_x86Reg;

/* Registers passed to and from PocketDOS BIOS extension function. */ 
typedef struct
{
	/* 80x86 registers, IP is not updated on return from extension function */
	tPDOS_x86Reg 
		nAX,
		nCX,
		nDX,
		nBX,
		nSP,
		nBP,
		nSI,
		nDI,
		nIP;
	
	/* Pointers to start of x86 segments, not updated on return from extension */
	BYTE 
		*pES,
		*pCS,
		*pSS,
		*pDS;

	/* Condition flags, only CF is updated on return from extension function */
	WORD
		nCF,
		nFlags;
} tPDOS_x86Regs;

/* Revert to default structure packing */
#pragma pack()

/* Typedef for PocketDOS BIOS extension entry point function */
typedef void (*tPDOS_BiosExtFn)( tPDOS_x86Regs* );

#endif