#include <stdio.h>
#include <mem.h>
#include <string.h>
#include "..\comp\lcd\clcd.h"
#include "..\comp\graph\scr_urne.h"
#include "..\comp\graph\video.h"

CLcd* CLcd::m_phInst = NULL;
CLcd::CLcd(void)
{
    //ctor
}

CLcd::~CLcd(void)
{
    //dtor
}

/** @brief (one liner)
  *
  * (documentation goes here)
  */
int CLcd::Initialise(void)
{
    int iResult = 0;
	memset(m_szBufLine1, 0, sizeof(m_szBufLine1));
	memset(m_szBufLine2, 0, sizeof(m_szBufLine2));

    return iResult;
}

/** @brief (one liner)
  *
  * (documentation goes here)
  */
#pragma argsused
void CLcd::Display(int Line, int row, char *Chaine)
{

}

#pragma argsused
void CLcd::DisplayScreen(int Line, int Col, char* pzBuf)
{
#ifndef DIAGNOSTICS_TYPE
	int iTag;
	char *pzTp;

	if(Line == 0)
	{
		iTag = OU;
		if(Col == 0)
		{
			strcpy(m_szBufLine1, pzBuf);
			memset(m_szBufLine2, 0, sizeof(m_szBufLine2));
		}
		else
		{
			if(Col < 60 )
			{
				int iCpt;
				int iLen = strlen(m_szBufLine1);
				if(iLen <= Col)
				{
					iCpt = iLen;
					for(; (iCpt <= Col) && (iCpt < 60); iCpt++)
					{
						m_szBufLine1[iCpt] = ' ';
					}
				}
				iCpt = Col;
				for(; iCpt < 60; iCpt++)
				{
					m_szBufLine1[iCpt] = 0;
				}
				if( (Col + strlen(pzBuf)) < 60)
					strcpy(Col + m_szBufLine1, pzBuf);
			}
		}
		pzTp = m_szBufLine1;
	}
	else
	{
		iTag = OV;

		if(Col == 0)
		{
			memset(m_szBufLine2, 0, sizeof(m_szBufLine2));
			strcpy(m_szBufLine2, pzBuf);
		}
		else
		{
			if(Col < 60 )
			{
				int iCpt;
				int iLen = strlen(m_szBufLine2);
				if(iLen <= Col)
				{
					iCpt = iLen;
					for(; (iCpt <= Col) && (iCpt < 60); iCpt++)
					{
						m_szBufLine2[iCpt] = ' ';
					}
				}
				iCpt = Col;
				for(; iCpt < 60; iCpt++)
				{
					m_szBufLine2[iCpt] = 0;
				}
				if( (Col + strlen(pzBuf)) < 60)
					strcpy(Col + m_szBufLine2, pzBuf);
			}
		}
		pzTp = m_szBufLine2;
	}
	switch(GetVideoScreen())
	{
	case SCR_START:
	case SCR_URNE:
		{
			char szTpo1[65];
			iTag = OB;
			strcpy(szTpo1, m_szBufLine1);
			strcat(szTpo1, "\n");
			strcat(szTpo1, m_szBufLine2);
			Video_Affiche(OB, szTpo1);
		}
		break;
	case SCR_PWD:
		if(Line == 0)
		{
			iTag = PWD;
		}
		else
		{
			iTag = PWD2;
		}
		Video_Affiche(iTag, pzTp);
		break;
	case SCR_GEN:
	case SCR_RECOMPT:
		Video_Affiche(iTag, pzTp);
		break;
	}
#endif
}

