emulator/emulatorbsp/inc/variant.h
changeset 0 cec860690d41
equal deleted inserted replaced
-1:000000000000 0:cec860690d41
       
     1 // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // wins\inc\variant.h
       
    15 // Wins Variant Header
       
    16 // 
       
    17 //
       
    18 
       
    19 #ifndef __VA_STD_H__
       
    20 #define __VA_STD_H__
       
    21 
       
    22 #include <assp.h>
       
    23 #include "vwins.h"
       
    24 #include "nk_priv.h"
       
    25 #pragma warning(disable : 4201) // nonstandard extension used : nameless struct/union
       
    26 #include <mmsystem.h>
       
    27 #pragma warning(default : 4201)
       
    28 #include <kernel/kpower.h>
       
    29 
       
    30 #ifdef _DEBUG
       
    31 const TInt KDefaultDebugMask = 1<<KPANIC; //KPANIC, override this with "DebugMask 0" in EPOC.INI
       
    32 #else
       
    33 const TInt KDefaultDebugMask = 0;
       
    34 #endif
       
    35 
       
    36 typedef void (*TMediaChangeCallBack)(TAny*);
       
    37 
       
    38 class WinsTimer
       
    39 	{
       
    40 public:
       
    41 	enum
       
    42 		{
       
    43 		EDefaultPeriod = 5,		// milliseconds
       
    44 		EMaxLag = 100,			// milliseconds
       
    45 		};
       
    46 public:
       
    47 	WinsTimer();
       
    48 	void Init(TUint aPeriod);
       
    49 	void Enable();
       
    50 	inline TUint Period() const
       
    51 		{return iPeriod;}
       
    52 	inline void SetIdleThread()
       
    53 		{if (!iIdleThread) iIdleThread = NKern::CurrentThread();}
       
    54 	inline void Nobble(TUint aNobbleFactor)
       
    55 		{iNobbleNanos = aNobbleFactor * iPeriod;}
       
    56 	TInt SystemTime() const;
       
    57 	void SetSystemTime(TInt aTime);
       
    58 	void Standby();
       
    59 	void Wakeup();
       
    60 private:
       
    61 	void EventThread(NTimerQ& aTimerQ);
       
    62 	static DWORD WINAPI Thread(LPVOID);
       
    63 	static void CALLBACK Tick(UINT, UINT, DWORD, DWORD, DWORD);
       
    64 private:
       
    65 	TUint iPeriod;
       
    66 	TUint iNobbleNanos;
       
    67 	TInt iMaxLagTicks;
       
    68 	HANDLE iSemaphore;
       
    69 	UINT iTimer;
       
    70 	TInt iSuspend;
       
    71 	Int64 iTime;
       
    72 	NThread* iIdleThread;
       
    73 	TBool iStandby;
       
    74 	};
       
    75 
       
    76 class Properties
       
    77 	{
       
    78 	struct SEntry
       
    79 		{
       
    80 		char* iProperty;
       
    81 		char* iValue;
       
    82 		};
       
    83 public:
       
    84 	Properties();
       
    85 	const char* Append(const char* aProperty, const char* aValue);
       
    86 	const char* Replace(const char* aProperty, const char* aValue);
       
    87 	TInt GetString(const char* aProperty, const char*& aValue) const;
       
    88 	TInt GetInt(const char* aProperty, TInt& aValue) const;
       
    89 	TInt GetBool(const char* aProperty, TBool& aValue, TBool aDefaultValue=EFalse) const;
       
    90 	//
       
    91 	void Dump() const;
       
    92 private:
       
    93 	TInt Find(const char* aProperty) const;
       
    94 	const char* Insert(TInt aIndex, const char* aProperty, const char* aValue);
       
    95 private:
       
    96 	SEntry* iEntries;
       
    97 	TInt iCount;
       
    98 	TInt iSize;
       
    99 	};
       
   100 
       
   101 class Wins : public Asic
       
   102 	{
       
   103 public:
       
   104 	Wins();
       
   105 	//
       
   106 	TInt Init(TBool aRunExe);
       
   107 	inline void InstallUi(DWinsUiBase& aUi);
       
   108 	TInt EmulatorHal(TInt aFunction, TAny* a1, TAny* a2);
       
   109 private:
       
   110 	// initialisation
       
   111 	void Init1();
       
   112 	void Init3();
       
   113 	void AddressInfo(SAddressInfo& anInfo);
       
   114 
       
   115 	// power management
       
   116 	void Idle();
       
   117 
       
   118 	// timing
       
   119 	TInt MsTickPeriod();
       
   120 	TInt SystemTimeInSecondsFrom2000(TInt& aTime);
       
   121 	TInt SetSystemTimeInSecondsFrom2000(TInt aTime);
       
   122 
       
   123 	// HAL
       
   124 	TInt VariantHal(TInt aFunction, TAny* a1, TAny* a2);
       
   125 
       
   126 	// Machine configuration
       
   127 	TPtr8 MachineConfiguration();
       
   128 	const char* EmulatorMediaPath();
       
   129 
       
   130 	// Debug trace
       
   131 	void DebugPrint(const TDesC8& aDes);
       
   132 	TBool ErrorDialog(TError aType, const TDesC8& aPanic, TInt aVal);
       
   133 	void EarlyLogging(const char* aMessage1,const char* aMessage2);
       
   134 private:
       
   135 	TInt InitProperties(TBool aRunExe);
       
   136 	TInt DebugMask();
       
   137 	TUint32 KernelConfigFlags();
       
   138 	TInt ParseCapabilitiesArg(SCapabilitySet& aCapabilities, const char *aText);
       
   139 	void DisabledCapabilities(SCapabilitySet& aCapabilities);
       
   140 	void CalibrateCpuSpeed();
       
   141 	TInt SetCpuSpeed(TUint aSpeed);
       
   142 	TInt AddProperty(char* aProperty, const char* aEol);
       
   143 	TInt ProcessCommandLine(TBool aRunExe, char* aCDrive);
       
   144 	TInt LoadProperties();
       
   145 	TInt ReadProperties(char* aData);
       
   146 	TInt ReadIniFile(const char* aFileName, char*& aContents);
       
   147 	TInt SetupPaths();
       
   148 	TInt SetupMediaPath();
       
   149 	TInt SetupDrive(int aDrive, const char* aPath);
       
   150 	TInt MapFilename(const TDesC& aFilename, TDes& aBuffer) const;
       
   151 	TInt MapDrive(int aDrive, TDes& aBuffer) const;
       
   152 	HANDLE DebugOutput();
       
   153 	void PurgeImages();
       
   154 	TBool ConfigSpecificProperty(const char * aProperty);
       
   155 	TInt LoadConfigSpecificProperties(const char * pFile);
       
   156 	TBool ScreenSpecificProperty(const char * aProperty);
       
   157 
       
   158 private:
       
   159 	friend class DWinsPowerController;
       
   160 	DWinsUiBase* iUi;
       
   161 	WinsTimer iTimer;
       
   162 	Properties iProperties;
       
   163 	TUint iRealCpuSpeed;
       
   164 	TUint iCpuSpeed;
       
   165 	HANDLE iDebugOutput;
       
   166 	TBool iLogTimeStamp;
       
   167 	TBool iPurgedImages;
       
   168 	TBool iLogToDebugger;
       
   169 	TBool iLogToFile;
       
   170 	TBool iConfigPropertySet;
       
   171 	TInt iConfigId;
       
   172 
       
   173 	class DWinsPowerController* iPowerController;
       
   174 	// For MMC emulation
       
   175 	static TBool MediaDoorOpen;
       
   176 	static TInt CurrentPBusDevice;
       
   177 	static TAny* MediaChangeCallbackParam;
       
   178 	static TMediaChangeCallBack MediaChangeCallBackPtr;
       
   179 public:
       
   180 	static Wins* Self()
       
   181 		{ return (Wins*) Arch::TheAsic();}
       
   182 	IMPORT_C void AssertWakeupSignal();
       
   183 	IMPORT_C void WakeupEvent();
       
   184 	IMPORT_C static TBool* MediaDoorOpenPtr();
       
   185 	IMPORT_C static TInt* CurrentPBusDevicePtr();
       
   186 	IMPORT_C static void SetMediaChangeCallBackPtr(TMediaChangeCallBack aPtr, TAny* aParam);
       
   187 	IMPORT_C static void MediaChangeCallBack();
       
   188 	};
       
   189 
       
   190 GLREF_D Wins TheVariant;
       
   191 
       
   192 #endif