// *****
// * PROJECT:		ECCLib (ECC)
// * FILENAME: 		ECCLib.h
// * AUTHOR:		Feng ZHU
// *
// * 
// * DESCRIPTION:	ECC Shared library functionality interface definition
// *
// * HISTORY:
// * 10/28/02 Feng Zhu - Initial Version
// *
// * COPYRIGHT:		
// *
// *****
 
// *****
// * PROJECT:		MySharedLib (MSL)
// * FILENAME: 		MySharedLib.h
// * AUTHOR:		Jeff Ishaq 05/21/99
// * 
// * DESCRIPTION:	Shared library functionality interface definition
// *
// * COPYRIGHT:		As long as this 'copyright' is intact, this code is freely modifiable
// *				and distributable.
// *****
#pragma once

// Use this for SysLibFind calls.  This is what we 'name' our dispatch table, too:
#define ECC_LIB_NAME	"ECC Library"
#define ECC_LIB_CREATOR	'FZSL'		 						// Register this with Palm

// [swong] Dragonball microprocessor is big endian
// [swong] This library is still architecture independent but more efficient if the platform is big endian
#ifndef BIG_ENDIAN
#define BIG_ENDIAN
#endif

#include "ecc.h"

typedef struct tagECCGlobalsType
{
	Int16		iOpenCount;				// Our internal open-count of the lib
	
	/////
	// Your globals go here...
	/////

} ECCGlobalsType;

typedef ECCGlobalsType*	ECCGlobalsTypePtr;

// These are some utility functions.  We don't actually use these in our dispatch
// table, so we don't need to define traps for them nor extern them.
ECCGlobalsTypePtr	ECCAllocGlobals	( UInt16 uRefNum );
ECCGlobalsTypePtr	ECCLockGlobals	( UInt16 uRefNum );
Err 				ECCFreeGlobals	( UInt16 uRefNum );
Err					ECCUnlockGlobals( ECCGlobalsTypePtr gP );

// These are possible error types that ECC might return:
typedef enum tagECCErrEnum 
{
	ECCErrNone 			= 0,			
	ECCErrParam			= -1,
	ECCErrNoGlobals		= -2,

	/////
	// Your custom return codes go here...
	/////
	ECCErrNoSpec		= -3
	
} ECCErr;

// These are ECC's trap identifiers.  The PalmOS constant 'sysLibTrapCustom' is
// the first trap number we can use after open, close, sleep, and wake.

typedef enum tagECCTrapNumEnum
{
	/////
	// - Trap modification checklist -
	// 
	// If you add or remove or otherwise modify something here, be sure you've
	// also done all of the following steps!
	//
	// 0) All trap identifiers must always run sequentially; no gaps!
	// 1) Modify the ECCTrapNumEnum in MySharedLib.h
	// 2) Modify the DC.W to ECC_DispatchTable() in MySharedLibDispatch.c (no gaps!)
	// 3) Modify the JMP in ECC_DispatchTable() in MySharedLibDispatch.c (no gaps!)
	// 4) ** Update NUMBER_OF_FUNCTIONS in MySharedLibDispatch.c ** (0-based)
	// 5) Add or remove an "extern MyFunc(...) SYS_TRAP(ECCTrapMyFunc)" prototype somewhere
	//
	/////

	ECCTrapEccAdd = sysLibTrapCustom,		// libDispatchEntry(4)
	ECCTrapEccCopy,							// libDispatchEntry(5)
	ECCTrapEccDouble,						// libDispatchEntry(6)
	ECCTrapEccInit,							// libDispatchEntry(7)
	ECCTrapEccMul							// libDispatchEntry(8)
} ECCTrapNumEnum;

#ifdef __cplusplus
extern "C" { 
#endif

// These are the four required entry points:
extern ECCErr	ECCOpen	( UInt16 uRefNum )						SYS_TRAP ( sysLibTrapOpen);
extern ECCErr	ECCClose( UInt16 uRefNum, UInt32* dwRefCountP )	SYS_TRAP ( sysLibTrapClose);
extern Err		ECCSleep( UInt16 uRefNum )						SYS_TRAP ( sysLibTrapSleep);
extern Err		ECCWake	( UInt16 uRefNum )						SYS_TRAP ( sysLibTrapWake	);

// Here are the actual functions we want the library to extend to callers.
extern ECCErr ECCLIBeccAdd(Int16 refNum, eccPoint *R, const eccPoint *P, const eccPoint *Q, ECCBASE *eccBase)
				SYS_TRAP(ECCTrapEccAdd); // sets R = P + Q  
extern ECCErr ECCLIBeccCopy(Int16 refNum, eccPoint *R, const eccPoint *P)
				SYS_TRAP(ECCTrapEccCopy); // sets R = P
extern ECCErr ECCLIBeccDouble(Int16 refNum, eccPoint *R, const eccPoint *P, ECCBASE *eccBase)
				SYS_TRAP(ECCTrapEccDouble); // set R = 2P
extern ECCErr ECCLIBeccInit (Int16 refNum, ECCBASE *eccBase)
				SYS_TRAP(ECCTrapEccInit); // initialization
extern ECCErr ECCLIBeccMul(Int16 refNum, eccPoint *R, const eccPoint *P, const word *n, ECCBASE *eccBase)
				SYS_TRAP(ECCTrapEccMul); // set R= nP

#ifdef __cplusplus
}
#endif
