#pragma once
#include "afxcmn.h"
#include "resource.h"
#include "MultiEditListCtrl.h"
#include "GFResizeDialogHelper.h"

// RegDumpCPUDlg.h : header file
//

/////////////////////////////////////////////////////////////////////////////
// CRegDumpDlg dialog

class CDebugger;

constexpr auto NUMBER_CUSTOMVIEWS_REGS = 2;
enum CUSTOMVIEW_MODE : int
{
	CV_DEC_VIEW = 0,
	CV_HEX_VIEW
};

struct CUSTOMVIEW_MODE_PARAM
{
	CUSTOMVIEW_MODE mode;
	LPTSTR name;
};

class CRegDumpCPUDlg : public CDialogEx
{
		GFResizeDialogHelper m_Resizer;
		CDebugger           *m_pDebugger;
		CMultiEditListCtrl   m_listCPU;
		CMultiEditListCtrl   m_listSys;
		CMultiEditListCtrl   m_listAltPro;
		CFont                m_hFont;
		HACCEL               m_hAccelTable;
		CToolTipCtrl m_ToolTip;

		static const UINT m_pListCpuIDs[9];
		static const UINT m_pListSysIDs[2][9];
		static const UINT m_pListSysRegs[2][9];
		static const UINT m_pListAltProIDs[2];

		int                 m_nCurrentCVM; //индекс текущего режима
		static CUSTOMVIEW_MODE_PARAM m_cvArray[NUMBER_CUSTOMVIEWS_REGS]; //в этом массиве

		//номера колонок для listCPU
		enum : int
		{
			LISTCPU_NAME_COL = 0,
			LISTCPU_VALUE_COL,
			LISTCPU_CUSTOM_VALUE_COL
		};
		//номера строк для listCPU
		enum : int
		{
			R0_LINE = 0,
			R1_LINE,
			R2_LINE,
			R3_LINE,
			R4_LINE,
			R5_LINE,
			SP_LINE,
			PC_LINE,
			PSW_LINE
		};

		//номера колонок для listSys
		enum : int
		{
			LISTSYS_NAME1_COL = 0,
			LISTSYS_VALUE1_COL,
			LISTSYS_NAME2_COL,
			LISTSYS_VALUE2_COL
		};
		//номера строк для listSys, колонки 0,1
		enum : int
		{
			REG177660_LINE = 0,
			REG177662IN_LINE,
			REG177662OUT_LINE,
			REG177664_LINE,
			REG177714IN_LINE,
			REG177714OUT_LINE,
			REG177716IN_LINE,
			REG177716OUT_TAP_LINE,
			REG177716OUT_MEM_LINE
		};
		//номера строк для listSys, колонки 2,3
		enum : int
		{
			REG177700_LINE = 0,
			REG177702_LINE,
			REG177704_LINE,
			REG177706_LINE,
			REG177710_LINE,
			REG177712_LINE
		};

		//номера колонок для listAltPro
		enum : int
		{
			LISTALTPRO_NAME_COL = 0,
			LISTALTPRO_VALUE_COL
		};
		//номера строк для listAltPro
		enum : int
		{
			ALTPRO_MODE_LINE = 0,
			ALTPRO_CODE_LINE
		};


// Construction
	public:
		CRegDumpCPUDlg(CWnd *pParent = nullptr);   // standard constructor
		virtual ~CRegDumpCPUDlg() override;

		enum { IDD = IDD_REGDUMP_CPU_DLG };
		CSize               GetMinSize();
		void                AttachDebugger(CDebugger *pDbgr);
		void                DisplayFreqParam();
		void                UpdateFreq();
		void                SetPSW(uint16_t value);
		void                DisplayPortRegs();
		void                DisplayRegisters();
		void                DisplayAltProData();
		uint16_t            GetPSW(CString &strPSW);

	protected:
		int m_nCurrCPUFreq;
		CSpinButtonCtrl m_spinCPUFreq;
	protected:
		virtual void DoDataExchange(CDataExchange *pDX) override;    // DDX/DDV support
		virtual BOOL PreTranslateMessage(MSG *pMsg) override;

		CString             FormatPSW(uint16_t value);
		int                 ResizeList(CMultiEditListCtrl *list, int height);
		void				SlideObj(CWnd* pWnd, int nOffset);
		CString             WordToCustom(uint16_t value);
		uint16_t            CustomToWord(const CString &str);
		// Generated message map functions
		virtual BOOL OnInitDialog() override;
		virtual void OnOK() override;
		virtual void OnCancel() override;
		afx_msg void OnSize(UINT nType, int cx, int cy);
		afx_msg void OnLvnItemchangedMdCpuRegisters(NMHDR *pNMHDR, LRESULT *pResult);
		afx_msg void OnLvnItemchangedMdAltProData(NMHDR *pNMHDR, LRESULT *pResult);
		afx_msg void OnLvnItemchangedMdSysRegisters(NMHDR *pNMHDR, LRESULT *pResult);
		afx_msg void OnEnChangeEditDbg1Cpufreq();
		afx_msg void OnBnClickedButtonDbg1CpufreqDec();
		afx_msg void OnBnClickedButtonDbg1CpufreqInc();
		afx_msg void OnBnClickedButtonDbg1CpufreqBaseset();
		afx_msg void OnBnClickedRegdumpCvmode();
		DECLARE_MESSAGE_MAP()
};
