/** SGX

The   sss    gggg x   x   
     s      g      x x    Engine
      sss   g  gg   x
         s  g   g  x x          Copyright 1995-2009.
     ssss    gggg x   x         Steven Goodwin. All Rights Reserved.
    
This version has been released under the GNU Public License v2.0.

Please see the license files for details.

File: sgx/src/sgx/core/platform/hwplatform.cpp

*/

#include "sgx/core/core.hpp"

CHardwarePlatform *CHardwarePlatform::ms_pSingleton = NULL;
sgxHashMap<tUINT32, const CHardwarePlatform *> CHardwarePlatform::m_PlatformList;
	
CHardwarePlatform::CHardwarePlatform() {}

CHardwarePlatform *CHardwarePlatform::get()
{
	if (!ms_pSingleton) {
		sgxError("You can not use hardware-specific information, until you've specified a h/w platform with CHardwarePlatformWinTel32::create() for example");
	}
    return ms_pSingleton;
}

void CHardwarePlatform::registerPlatform(const CHardwarePlatform *pPlatform) {
	m_PlatformList[sgxGetCRC32(pPlatform->getPlatformID())] = pPlatform;
}

const CHardwarePlatform *
CHardwarePlatform::getPlatform(const char *pName) {
	tUINT32 hash = sgxGetCRC32(pName);
	if (m_PlatformList.find(hash) != m_PlatformList.end()) {
		return m_PlatformList[hash];
	}
	return NULL;
}

void CHardwarePlatform::dumpStats(void) const 
{
    sgxTrace("SGX Engine - %s (%s)", getPlatformName(), getPlatformID());
    sgxTrace(" Local docs : %s", getDocsURL());
    sgxTrace(" Remote site : %s", getDevelopmentURL());

    sgxTrace("Disc Response:"); 
    sgxTrace(" seek time (in ms) : %.2f", SGX_KILOBYTES*getDiscAccessSpeed());
    sgxTrace(" read time (in Mps) : %2.2f", getDiscReadSpeed()/SGX_MEGABYTES);

    sgxTrace("CPUs:"); 
    sgxTrace(" Number : %d", getNumCPUs());
    tUINT32 i;
    for(i=0; i<getNumCPUs(); ++i) {
        sgxTrace("  CPU %d speed : %d", i+1, getCPUSpeed(i));
    }

    sgxTrace("Memory banks:"); 
    sgxTrace(" Number : %d", getNumMemoryBanks());
    for(i=0; i<getNumMemoryBanks(); ++i) {
        sgxTrace("  Bank %d size : %d", i+1, getMemorySize(i));
    }
}

CHardwarePlatform::tScreenFormat	
CHardwarePlatform::getVideoDefaultFormat()  const {
	return eUnused;
}

CHardwarePlatform::tOrientation	
CHardwarePlatform::getVideoOrientation(const CHardwarePlatform::tScreenFormat fmt)  const {
	sgxRect2i rc;
	getVideoResolution(rc, fmt);
	if (rc.right > rc.bottom) {
		return eLandscape;
	}
	return ePortrait;
} 

void
CHardwarePlatform::getVideoStandard(sgxRect2i &rc, const CHardwarePlatform::tVideoStandard std) {
	rc.left = rc.top = 0;
	switch(std) {
		case eVGA:	// aka VGA43
			rc.right = 640;
			rc.bottom = 480;
			break;
		case eVGA169:
			rc.right = 848;
			rc.bottom = 480;
			break;
		case eXGA:
			rc.right = 1024;
			rc.bottom = 768;
			break;
		case e720P:
			rc.right = 1280;
			rc.bottom = 720;
			break;
		case eWXGA:
			rc.right = 1280;
			rc.bottom = 768;
			break;
		case eSXGA:
			rc.right = 1280;
			rc.bottom = 1024;
			break;
		case eWXGA169:
			rc.right = 1360;
			rc.bottom = 768;
			break;
		default:
			rc.right = rc.bottom = 0;
			sgxTrace("Error in getVideoStandard resolution.");
	}
}


void CHardwarePlatform::getCRLF(tBYTE *pDest) const 
{
	*(pDest+0) = '\r';
	*(pDest+1) = '\n';
	*(pDest+2) = '\0';
}

