/*************************************************************************

	formZ by auto*des*sys, Inc.
	Copyright c 2004 autodessys, Inc.  All rights reserved.
	
	
	File :	fzrt_platform.h
	
	By :	Keith Agee
	
	Description :	Defines the platform and compiler capability macros
					
***************************************************************************/
#ifndef __FZRT_PLATFORM_H
#define __FZRT_PLATFORM_H


/* @doc EXTERNAL FZRT */

/**************************************************************
	FZ_PRAGMA_STRUCT_PACKPUSH  - Compiler supports: #pragma pack(push, n)/pack(pop)
	FZ_PRAGMA_STRUCT_PACK      - Compiler supports: #pragma pack(n)
	FZ_PRAGMA_STRUCT_ALIGN     - Compiler supports: #pragma options align=mac68k/power/reset

	FZ_PRAGMA_ENUM_PACK        - Compiler supports: #pragma options(!pack_enums)
	FZ_PRAGMA_ENUM_ALWAYSINT   - Compiler supports: #pragma enumsalwaysint on/off/reset
	FZ_PRAGMA_ENUM_OPTIONS     - Compiler supports: #pragma options enum=int/small/reset

	FZ_FUNCTION_PASCAL         - Compiler supports "pascal void Foo()"
	FZ_FUNCTION_DECLSPEC       - Compiler supports "__declspec(xxx) void Foo()"
	FZ_FUNCTION_WIN32CC        - Compiler supports "void __cdecl Foo()" and "void __stdcall Foo()"
***************************************************************/        

/** valid values for __PLATFORM__ define */
#define MACINTOSH			0
#define WINDOWS				1
/******************************************************************************************************

	@def	
	
	@desc	Byte order is in big endian order.
			The byte order contains the most significant byte first.
			
	@avail	1.0

	@toc	fzrt

*******************************************************************************************************/
#define FZ_ENDIAN_BIG		0

/******************************************************************************************************

	@def	
	
	@desc	Byte order is in little endian order.
			The byte order contains the least significant byte first.
			
	@avail	1.0

	@toc	fzrt

*******************************************************************************************************/
#define FZ_ENDIAN_SMALL	1





#if defined(__MWERKS__)
 #if (__MWERKS__ < 0x0900) || macintosh
 	/* Metrowerks CodeWarrior for Mac */
		#define __PLATFORM__		MACINTOSH
		
/******************************************************************************************************

	@def	

	@desc	Byte order of the current platform.
			This defines the byte order of the current system. Macintosh is big endian. Windows is little endian.
		
	@avail	1.0

	@see	FZ_ENDIAN_SMALL, FZ_ENDIAN_SMALL

	@toc	fzrt

*******************************************************************************************************/
		#define	FZ_NATIVE_ENDIAN	FZ_ENDIAN_BIG
		#define FZRT_RT_CFM			1

		#define FZ_FUNCTION_PASCAL         		1
		#define FZ_FUNCTION_WIN32CC				0       
		#if (__MWERKS__ >= 0x2000)
			#define FZ_FUNCTION_DECLSPEC    	1
		#else
			#define FZ_FUNCTION_DECLSPEC    	0
		#endif
		#define FZ_PRAGMA_STRUCT_ALIGN			1
		#define FZ_PRAGMA_STRUCT_PACK			0
		#define FZ_PRAGMA_STRUCT_PACKPUSH 		0
		#define FZ_PRAGMA_ENUM_PACK 			0
		#define FZ_PRAGMA_ENUM_ALWAYSINT      	1
		#define FZ_PRAGMA_ENUM_OPTIONS         	0
	    #if defined(powerc) || defined(_powerc)				/* KDA 01/27/05 */
	    	#define FZ_CPU_PPC					1
	    	#define FZ_CPU_68K					0
	    	#define FZ_CPU_X86					0
			#define FZ_CPU_X64					0	/* JDE 07/12/06 : 64 bit changes */
		#else
	    	#define FZ_CPU_PPC					0
	    	#define FZ_CPU_68K					1
	    	#define FZ_CPU_X86					0
			#define FZ_CPU_X64					0	/* JDE 07/12/06 : 64 bit changes */
		#endif
        #define FZ_CPU_ARM						0
        #define FZ_CPU_ARM64					0


	#elif (__MWERKS__ >= 0x0900) && __INTEL__
	
   		/* Metrowerks for Windows */
   		
		#define __PLATFORM__		WINDOWS
		#define	FZ_NATIVE_ENDIAN	FZ_ENDIAN_SMALL
		#define FZRT_RT_WIN32		1
		
		#define FZ_FUNCTION_PASCAL				0
		#define FZ_FUNCTION_WIN32CC				1   
		#define FZ_FUNCTION_DECLSPEC			1      
		#define FZ_PRAGMA_STRUCT_ALIGN			0
		#define FZ_PRAGMA_STRUCT_PACK			1
		#define FZ_PRAGMA_STRUCT_PACKPUSH		1
		#define FZ_PRAGMA_ENUM_PACK				0
		#define FZ_PRAGMA_ENUM_ALWAYSINT		1
		#define FZ_PRAGMA_ENUM_OPTIONS			0
		
	    	#define FZ_CPU_PPC					0
	    	#define FZ_CPU_68K					0
	    	#define FZ_CPU_X86					1
			#define FZ_CPU_X64					0
			#define FZ_CPU_ARM					0
            #define FZ_CPU_ARM64				0

	#elif (__MWERKS__ >= 0x2110) && __MACH__
		/* Metrowerks for Mac OS X */
		#define __PLATFORM__		MACINTOSH
		#define	FZ_NATIVE_ENDIAN	FZ_ENDIAN_BIG
		#define FZRT_RT_MACHO		1
		
		#define FZ_FUNCTION_PASCAL           	1
		#define FZ_FUNCTION_DECLSPEC           	1
		#define FZ_FUNCTION_WIN32CC            	0           
		#define FZ_PRAGMA_STRUCT_ALIGN         	1
		#define FZ_PRAGMA_STRUCT_PACK          	1
		#define FZ_PRAGMA_STRUCT_PACKPUSH      	0
		#define FZ_PRAGMA_ENUM_PACK            	0
		#define FZ_PRAGMA_ENUM_ALWAYSINT       	1
		#define FZ_PRAGMA_ENUM_OPTIONS         	0
		
	    	#define FZ_CPU_PPC					1
	    	#define FZ_CPU_68K					0
	    	#define FZ_CPU_X86					0
			#define FZ_CPU_X64					0	/* JDE 07/12/06 : 64 bit changes */
			#define FZ_CPU_ARM					0
            #define FZ_CPU_ARM64				0

	#else
	#error "Unsupported Metrowerks version or build setting"
	#endif
#elif defined(__GNUC__) && (defined(__APPLE_CPP__) || defined(__APPLE_CC__) )
	/*  gcc based compilers  Mac OS X   */
 
 		/* JDE 03/28/06 : Changes for Intel builds */
		#include <TargetConditionals.h>
 
		#define __PLATFORM__					MACINTOSH
		#define FZRT_RT_MACHO					TARGET_RT_MAC_MACHO
		
//		#define FZ_PRAGMA_STRUCT_ALIGN			PRAGMA_STRUCT_ALIGN
//		#define FZ_PRAGMA_STRUCT_PACK			PRAGMA_STRUCT_PACK
//		#define FZ_PRAGMA_STRUCT_PACKPUSH		PRAGMA_STRUCT_PACKPUSH
//		#define FZ_PRAGMA_ENUM_PACK				PRAGMA_ENUM_PACK
//		#define FZ_PRAGMA_ENUM_ALWAYSINT		PRAGMA_ENUM_ALWAYSINT
//		#define FZ_PRAGMA_ENUM_OPTIONS			PRAGMA_ENUM_OPTIONS
//		#define FZ_FUNCTION_PASCAL				FUNCTION_PASCAL
//		#define FZ_FUNCTION_DECLSPEC			FUNCTION_DECLSPEC
//		#define FZ_FUNCTION_WIN32CC				FUNCTION_WIN32CC  

		#define FZ_PRAGMA_STRUCT_ALIGN         1 /*1*/	/* SPG 10/10/12 */
		#define FZ_PRAGMA_STRUCT_PACK          0
		#define FZ_PRAGMA_STRUCT_PACKPUSH      0
		#define FZ_PRAGMA_ENUM_PACK            0
		#define FZ_PRAGMA_ENUM_ALWAYSINT       0
		#define FZ_PRAGMA_ENUM_OPTIONS         0
		#define FZ_FUNCTION_PASCAL             0
		#define FZ_FUNCTION_DECLSPEC           0
		#define FZ_FUNCTION_WIN32CC            0  
		  
		#define FZ_CPU_PPC					TARGET_CPU_PPC
		#define FZ_CPU_68K					TARGET_CPU_68K
		#define FZ_CPU_X86					TARGET_CPU_X86
		#define FZ_CPU_X64					TARGET_CPU_X86_64		/* 	DEK 09/27/12 : OS X 64 */
        #define FZ_CPU_ARM					TARGET_CPU_ARM
        #define FZ_CPU_ARM64				TARGET_CPU_ARM64

		#if FZ_CPU_X64		
			#define	FZ_NATIVE_ENDIAN			FZ_ENDIAN_SMALL
		#elif FZ_CPU_X86
			#define	FZ_NATIVE_ENDIAN			FZ_ENDIAN_SMALL
        #elif FZ_CPU_ARM
            #define	FZ_NATIVE_ENDIAN			FZ_ENDIAN_SMALL
        #elif FZ_CPU_ARM64
            #define	FZ_NATIVE_ENDIAN			FZ_ENDIAN_SMALL
		#else
			#define	FZ_NATIVE_ENDIAN			FZ_ENDIAN_BIG
		#endif
	    	
#elif defined(_MSC_VER) && !defined(__MWERKS__) 
	/* Visual Studio C/C++ from Microsoft, Inc. */
	/* JDE 07/12/06 : 64 bit changes start */
	#if defined(_M_X64)
	
		#define __PLATFORM__		WINDOWS
		#define	FZ_NATIVE_ENDIAN	FZ_ENDIAN_SMALL
		#define FZRT_RT_WIN32		1
		
		#define FZ_PRAGMA_STRUCT_ALIGN         0
		#define FZ_PRAGMA_STRUCT_PACK          1
		#define FZ_PRAGMA_STRUCT_PACKPUSH      1
		#define FZ_PRAGMA_ENUM_PACK            0
		#define FZ_PRAGMA_ENUM_ALWAYSINT       0
		#define FZ_PRAGMA_ENUM_OPTIONS         0
		#define FZ_FUNCTION_PASCAL             0
		#define FZ_FUNCTION_DECLSPEC       		1
		#define FZ_FUNCTION_WIN32CC        		1
		   
	    	#define FZ_CPU_PPC					0
	    	#define FZ_CPU_68K					0
	    	#define FZ_CPU_X86					1
			#define FZ_CPU_X64					1
			#define FZ_CPU_ARM					0
            #define FZ_CPU_ARM64				0

			#define FZ_MENUNAME			GCLP_MENUNAME
			#define FZ_HBRBACKGROUND	GCLP_HBRBACKGROUND
			#define FZ_HCURSOR			GCLP_HCURSOR
			#define FZ_HICON			GCLP_HICON
			#define FZ_HMODULE			GCLP_HMODULE
			#define FZ_WNDPROC			GWLP_WNDPROC
			#define FZ_HICONSM			GCLP_HICONSM
			#define FZ_USERDATA			GWLP_USERDATA
			#define FZ_HWNDPARENT		GWLP_HWNDPARENT
			#define FZ_MSGRESULT		DWLP_MSGRESULT

			#define fzrt_get_window_long 	GetWindowLongPtr
			#define fzrt_set_window_long	SetWindowLongPtr
			#define fzrt_get_class_long		GetClassLongPtr

			#define	fzrt_windows_long_ptr	LONG_PTR
			#define	fzrt_windows_int_ptr	INT_PTR
			#define	fzrt_windows_uint_ptr	UINT_PTR
			#define	fzrt_windows_dword_ptr	DWORD_PTR

	#elif defined(_M_IX86) /* Visual Studio with Intel x86 target */
	/* JDE 07/12/06 : 64 bit changes end */
		
		#define __PLATFORM__		WINDOWS
		#define	FZ_NATIVE_ENDIAN	FZ_ENDIAN_SMALL
		#define FZRT_RT_WIN32		1
		
		#define FZ_PRAGMA_STRUCT_ALIGN         0
		#define FZ_PRAGMA_STRUCT_PACK          1
		#define FZ_PRAGMA_STRUCT_PACKPUSH      1
		#define FZ_PRAGMA_ENUM_PACK            0
		#define FZ_PRAGMA_ENUM_ALWAYSINT       0
		#define FZ_PRAGMA_ENUM_OPTIONS         0
		#define FZ_FUNCTION_PASCAL             0
		#define FZ_FUNCTION_DECLSPEC       		1
		#define FZ_FUNCTION_WIN32CC        		1
		   
	    	#define FZ_CPU_PPC					0
	    	#define FZ_CPU_68K					0
	    	#define FZ_CPU_X86					1
			#define FZ_CPU_X64					0				/* JDE 07/12/06 : 64 bit changes start*/
			#define FZ_CPU_ARM					0
            #define FZ_CPU_ARM64				0

			#define FZ_MENUNAME			GCL_MENUNAME
			#define FZ_HBRBACKGROUND	GCL_HBRBACKGROUND
			#define FZ_HCURSOR			GCL_HCURSOR
			#define FZ_HICON			GCL_HICON
			#define FZ_HMODULE			GCL_HMODULE
			#define FZ_WNDPROC			GWL_WNDPROC

			#define FZ_HICONSM			GCL_HICONSM
			#define FZ_USERDATA			GWL_USERDATA
			#define FZ_HWNDPARENT		GWL_HWNDPARENT
			#define FZ_MSGRESULT		DWL_MSGRESULT	/* JDE 07/12/06 : 64 bit changes end */

			#define fzrt_get_window_long 	GetWindowLong
			#define fzrt_set_window_long	SetWindowLong
			#define fzrt_get_class_long		GetClassLong

			
			#define	fzrt_windows_long_ptr	fzrt_int
			#define	fzrt_windows_int_ptr	int
			#define	fzrt_windows_uint_ptr	unsigned int
			#define	fzrt_windows_dword_ptr	fzrt_unsigned_int

	#else
	#error "Unsupported Visual Studio version or compiler"
	#endif

#endif /* compiler families */

#if !defined(__PLATFORM__) || ((__PLATFORM__ != WINDOWS) && (__PLATFORM__ != MACINTOSH))
	#error Unsupported compiler or platform
#endif	

#endif /* __FZRT_PLATFORM_H */