#pragma once

// DisasmCtrl.h : header file
//
#include <mutex>
#include "MultiEditListCtrl.h"
#include "DebuggerItemParam.h"

// массив номеров колонок списка
enum DISASM_LIST : int
{
	COL_MARK = 0,
	COL_ADDR,
	COL_INSTR,
	COL_COMMENT,
};


class CDebugger;

/////////////////////////////////////////////////////////////////////////////
// CDisasmCtrl window

class CDisasmCtrl : public CMultiEditListCtrl
{
		DECLARE_DYNAMIC(CDisasmCtrl)

		CDebugger          *m_pDebugger;
		int                 m_nSelection;
		std::mutex          m_lock;

		HICON               m_hBPIcon, m_hCurrIcon;
		HICON               m_hBPIconOff, m_hBPIconMem, m_hBPIconMemOff;

		std::vector<CDbgItemParam> m_vItemsParam;

// Construction
	public:
		CDisasmCtrl();
		virtual ~CDisasmCtrl() override;

// Operations
	public:
		void                AttachDebugger(CDebugger *pDebugger);
		void                OutContent();
		void                Init();
		void                ChangeInstructionSet();
		uint16_t            GetCursorAddr() const;
		uint16_t            GetBottomAddr() const;
		void				EditAsmInstr(const int nRow, const int nCol);

	protected:
		void                DisasmStepUp(const int nCount = 1) const;
		void                DisasmStepDn(const int nCount = 1) const;
		void                DrawColoredText(CDC *pDC, CRect &rect, CString &str);
		uint16_t            GetLineAddress(int nRow) const;
		uint16_t            StepBackward(const int nSteps = 1) const;
		uint16_t            StepForward(const int nSteps = 1) const;
		CString				GetDisasmParTxt(CDbgItemParam &p);
		CString				GetArgText(const CDbgItemParam &p, CDbgItemParam::ARGTYPE t);
		CString				GetAddrText(const CDbgItemParam &p, CDbgItemParam::ARGTYPE t);
		CString				GetFPUArgText(const CDbgItemParam &p, CDbgItemParam::ARGTYPE t);
		CString				GetFloatNum(const CDbgItemParam::argParam &ap,int size);

		virtual BOOL		PreTranslateMessage(MSG *pMsg) override;
	// Generated message map functions
	protected:
		afx_msg void OnSize(UINT nType, int cx, int cy);
		afx_msg void OnItemchanged(NMHDR *pNMHDR, LRESULT *pResult);
		afx_msg void OnLVNKeyDown(NMHDR *pNMHDR, LRESULT *pResult);
		afx_msg void OnCustomDraw(NMHDR *pNMHDR, LRESULT *pResult);
		afx_msg void OnNMDblclk(NMHDR *pNMHDR, LRESULT *pResult);
		afx_msg void OnSetFocus(CWnd *pOldWnd);
		afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt);
		DECLARE_MESSAGE_MAP()
};

