/*************************************************
*           BK Emulator v3.9 for Windows         *
*************************************************/

/*
File: Globals.h
Version: 1.0.0
Written by: Yuriy Kalmykov <kalmykov@stoik.com>
    Copyright (c) 2002-2004 Yuriy Kalmykov

    BK Emulator is a program emulated hardware environment for running
code for BK 0010(01) in different configurations.

    This code may be used in compiled form in any way you desire.
This file or it's parts can't be redistributed without the authors
written consent, but can be modified for your private needs.
    Providing that this notice and the authors name and all copyright
notices remains intact.

    Please, an email me to know how you are using it and where. You can
ask me for any information about this below code or any attendant
knowledge.

    This file is provided "as is" with no expressed or implied warranty.
The author accepts no liability for any damage or loss of business that
this product may cause.
*/


// Globals.h

#pragma once
#include "resource.h"
#include "Defines.h"
#include "Config.h"
#include "MSF.h"

extern CConfig g_Config;

//тут надо бы придумать более человеческий способ
//а то и енум CONFIG_BKMODEL_NUMBER и массив должны совпадать.

struct BK_MODEL_PARAMETERS
{
	CString strBKModelConfigName;
	CString strBKModelName;
	MSF_CONF nBKModel;
	BKFDD_MODEL nBKFDDModel;
};

extern const BK_MODEL_PARAMETERS g_mstrConfigBKModelParameters[];

CString     WordToOctString(WORD word);
CString     ByteToOctString(BYTE byte);
WORD        OctStringToWord(const CString &str);
CString     IntToString(int iInt, int radix = 10);
CString     IntToFileLengthString(int iInt);
CString     MsTimeToTimeString(int msTime);

CString     BKToUNICODE(BYTE *pBuff, int size);
TCHAR       BKToUNICODE_Byte(BYTE b);
void        UNICODEtoBK(CString &ustr, BYTE *pBuff, int bufSize, bool bFillBuf);
void        ANSIToBK(BYTE &ch);

#ifdef _DEBUG
void        GetLastErrorOut(LPTSTR lpszFunction);
#endif

inline int GetDigit(register WORD word, register int pos)
{
	return (pos ? (word >> ((pos << 1) + pos)) : word) & 7;
}

static CString getCompileDate(const LPCTSTR &p_format = _T("%Y-%m-%d"))
{
	COleDateTime tCompileDate;
	tCompileDate.ParseDateTime(_T(__DATE__), LOCALE_NOUSEROVERRIDE, 1033);
	return tCompileDate.Format(p_format).GetString();
}

static CString getCompileTime(const LPCTSTR &p_format = _T("%H-%M-%S"))
{
	COleDateTime tCompileDate;
	tCompileDate.ParseDateTime(_T(__TIME__), LOCALE_NOUSEROVERRIDE, 1033);
	return tCompileDate.Format(p_format).GetString();
}

extern const TCHAR koi8tbl[128];

extern const char bk_codes[];

//идентификатор. означает, что к данному приводу/в данный слот/прочее ничего не подключено.
static const CString g_strEmptyUnit = _T("<empty>");

static const CString g_mstrDrives[4] =
{
	_T("A:"), _T("B:"), _T("C:"), _T("D:")
};

static const int g_mnDrivesIndx[4] =
{
	IDS_INI_DRIVEA, IDS_INI_DRIVEB, IDS_INI_DRIVEC, IDS_INI_DRIVED
};
