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

/*
File: MSFManager.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.
*/


// MSFManager.h: interface for the CMSFManager class.
//


#pragma once

#include "MSF.h"
#include "Defines.h"
#include "FDDController.h"

#define MSF_STATE_ID 65536
#define MSF_VERSION_MINIMAL 15
#define MSF_VERSION_CURRENT 15


class CMSFManager
{
		CFile               m_fileMSF;
		bool                m_bOpenForLoad;
		MSF_FILE_HEADER     m_header;

		CArray<MSF_BLOCK_INFO, MSF_BLOCK_INFO &> m_blocks;

		bool                Seek(int nOffset, UINT nFrom);
		bool                ReleaseFile();

	public:
		CMSFManager();
		virtual ~CMSFManager();

		bool                CheckFile(const CString &strPath, bool bSilent = true);
		bool                OpenFile(const CString &strPath, bool bLoad);
		inline void         SetType(DWORD type)
		{
			m_header.type = type;
		}
		inline DWORD        GetType()
		{
			return m_header.type;
		}
		inline void         SetVersion(DWORD version)
		{
			m_header.version = version;
		}
		inline DWORD        GetVersion()
		{
			return m_header.version;
		}
		inline void         SetConfiguration(CONFIG_BKMODEL_NUMBER configuration)
		{
			m_header.configuration = configuration;
		}
		inline CONFIG_BKMODEL_NUMBER     GetConfiguration()
		{
			return static_cast<CONFIG_BKMODEL_NUMBER>(m_header.configuration);
		}
		inline bool         IsLoad()
		{
			return m_bOpenForLoad;
		}
		inline bool         IsSave()
		{
			return !m_bOpenForLoad;
		}

		bool                FindBlock(DWORD blockType, MSF_BLOCK_INFO *pBi);
		bool                SetBlockHeader(MSF_BLOCK_INFO *pBi);
		bool                GetBlockHeader(MSF_BLOCK_INFO *pBi);
		bool                SetBlockData(BYTE *pBuff, DWORD length);
		bool                GetBlockData(BYTE *pBuff, DWORD length);

		bool                SetBlockPreview(HBITMAP hScreenshot);
		bool                GetBlockPreview(HBITMAP *hScreenshot);
		bool                SetBlockBaseMemory(BYTE *pMemory);
		bool                GetBlockBaseMemory(BYTE *pMemory);
		bool                SetBlockBaseMemory11M(BYTE *pMemory);
		bool                GetBlockBaseMemory11M(BYTE *pMemory);
		bool                SetBlockMemorySMK512(BYTE *pMemory);
		bool                GetBlockMemorySMK512(BYTE *pMemory);
		bool                SetBlockCPURegisters(MSF_CPU_REGISTERS *pCPURegisters);
		bool                GetBlockCPURegisters(MSF_CPU_REGISTERS *pCPURegisters);
		bool                SetBlockPortRegs(MSF_PORT_REGS *pPortRegs);
		bool                GetBlockPortRegs(MSF_PORT_REGS *pPortRegs);

		bool                GetBlockMemMap(BKMEMBank_Type *MBType, ConfBKModel_Type *CBKMType);
		bool                SetBlockMemMap(BKMEMBank_Type *MBType, ConfBKModel_Type *CBKMType);

		bool                GetBlockConfig();
		bool                SetBlockConfig();

		bool                GetBlockFrameData(MSF_FRAMEDATA *FDBlock);
		bool                SetBlockFrameData(MSF_FRAMEDATA *FDBlock);

		bool                SetBlockExt32Memory(DWORD nPage, BYTE *pMemoryExt);
		bool                GetBlockExt32Memory(DWORD *pnPage, BYTE *pMemoryExt);
		bool                SetBlockExt16Memory(BYTE *pMemoryExt);
		bool                GetBlockExt16Memory(BYTE *pMemoryExt);
		bool                SetBlockTape(BYTE *pPackedWave, DWORD nBitsLength, DWORD nPackLength);
		bool                GetBlockTape(BYTE *pPackedWave, DWORD *pnBitsLength, DWORD *pnPackLength);
};

