// NVBIOS.h: interface for the CNVBIOS class.
//
// created by Unwinder
//////////////////////////////////////////////////////////////////////
#ifndef _NVBIOS_H_INCLUDED_
#define _NVBIOS_H_INCLUDED_
//////////////////////////////////////////////////////////////////////
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
//////////////////////////////////////////////////////////////////////
typedef void (__cdecl * LPNVBIOS_ENUM_THERMAL_TABLE_ENTRIES_PROC)(LPBYTE, LPVOID);
//////////////////////////////////////////////////////////////////////
class CNVBIOS  
{
public:
	//object initialization / uninitialization

	BOOL Init(DWORD dwGpu);	
		//initialize object
	void Uninit();
		//uninitialize object (called automatically in destructor)

	//misc helpers

	LPBYTE FindPattern(LPBYTE lpPattern, LPBYTE lpMask, DWORD dwSize, DWORD dwOffset);
		//find patter into VGA BIOS image

	//BIT related functions

	LPBYTE FindBIT();
		//find BIT structure into VGA BIOS image
	LPBYTE FindBITToken(DWORD dwToken);
		//find BIT token

	//thermal table related functions

	LPBYTE	FindThermalTable();
		//find thermal table into VGA BIOS image
	LPBYTE	EnumThermalTableEntries(DWORD dwEntry);
		//enumerate thermal table entries by indices
	void	EnumThermalTableEntries(LPNVBIOS_ENUM_THERMAL_TABLE_ENTRIES_PROC lpEnumProc, LPVOID lpContext);
		//enumerate thermal table entries using specified enumeration procedure

	void GetThermalTableTemperatureThreshold(DWORD dwChannelID, DWORD dwThresholdID, LONG *lpResult);
		//get thermal table temperature threshold by temperature channel and threshold ID
	void GetThermalTableTemperatureCompensation(LONG* lpResult);
		//get thermal table temperature compensation

	void GetThermalTableDiodeGainMul(LONG* lpResult);
		//get thermal table diode gain multiplier
	void GetThermalTableDiodeGainDiv(LONG* lpResult);
		//get thermal table diode gain divider

	void GetThermalTableDiodeOffsetMul(LONG* lpResult);
		//get thermal table diode offset multiplier
	void GetThermalTableDiodeOffsetDiv(LONG* lpResult);
		//get thermal table diode offset divider

	void GetThermalTableDiodeOffsetBinMul(LONG dwDiodeOffsetBin, LONG* lpResult);
		//get thermal table binary diode offset multiplier
	void GetThermalTableDiodeOffsetBinDiv(LONG dwDiodeOffsetBin, LONG* lpResult);
		//get thermal table binary diode offset divider
	
	//variable virtualization related functions

	LPBYTE FindVariableVirtualizationDefTable();
		//find variable virtualization definition table
	LPBYTE EnumVariableVirtualizationDefTableEntries(DWORD dwEntry);
		//enum variable virtualization definition table entires by indices

	LPBYTE FindVariableVirtualizationImpTable();
		//find variable virtualization implementation table
	LPBYTE EnumVariableVirtualizationImpTableEntries(DWORD dwEntry);
		//enum variable virtualization implementation table entires by indices

	void GetVirtualVariable(DWORD dwVarID, LONG* lpResult);
		//get virtual variable by variable ID

		//Note: only MMIO registers based virtual variables are supported

	CNVBIOS();
	virtual ~CNVBIOS();

private:

	//member variables

	LPBYTE	m_lpImage;
		//ptr to BIOS image
	DWORD	m_dwImageSize;
		//size of BIOS image
	DWORD	m_dwGpu;

	LPBYTE	m_lpBIT;
		//ptr to BIT structure

	//helper thermal table entries enumeration procedures

	static void EnumProcGetThermalTableTemperatureCompensation(LPBYTE lpEntry, LPVOID lpContext);
		//heleper enumeration procedure for GetThermalTableTemperatureCompensation
	static void EnumProcGetThermalTableDiodeGainMul(LPBYTE lpEntry, LPVOID lpContext);
		//heleper enumeration procedure for GetThermalTableDiodeGainMul
	static void EnumProcGetThermalTableDiodeGainDiv(LPBYTE lpEntry, LPVOID lpContext);
		//heleper enumeration procedure for GetThermalTableDiodeGainDiv
	static void EnumProcGetThermalTableDiodeOffsetMul(LPBYTE lpEntry, LPVOID lpContext);
		//heleper enumeration procedure for GetThermalTableDiodeOffsetMul
	static void EnumProcGetThermalTableDiodeOffsetDiv(LPBYTE lpEntry, LPVOID lpContext);
		//heleper enumeration procedure for GetThermalTableDiodeOffsetDiv
};
//////////////////////////////////////////////////////////////////////
#endif 
//////////////////////////////////////////////////////////////////////
