//---------------------------------------------------------------------------

#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ComCtrls.hpp>
#include <Dialogs.hpp>

#include <stdio.h>
#include <stdarg.h>


#include "ProcessThread.h"
#include "inifile.h"
#include <ExtCtrls.hpp>
#include <Grids.hpp>
#include <Menus.hpp>
#include <ToolWin.hpp>

/* Status bar fields index. */
#define SB_TRANSFER_INDEX 0
#define SB_DEBUGGER_INDEX 1
#define SB_LOG_INDEX      2
#define SB_SPEED_INDEX    3
#define SB_VERSION_INDEX  4
/*
 * Status bar activity field.
 *  0~SB_ACTIVITY_MAXCOUNT-1 : transfering ...
 */
#define SB_ACTIVITY_MAXCOUNT 4
/*
 * Prompt display rate
 */
#define SB_PROMPT_DISP_RATE 6

//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published:	// IDE-managed Components
        TGroupBox *GroupBox1;
        TMemo *mLog;
        TOpenDialog *odFile;
        TSaveDialog *sdFile;
        TStatusBar *StatusBar;
        TPageControl *psSettings;
        TTabSheet *tsReadWrite;
        TGroupBox *GroupBox6;
        TLabel *Label9;
        TEdit *edtDownFile;
        TButton *btnDownSelect;
        TButton *btnDownload;
        TGroupBox *GroupBox7;
        TLabel *Label10;
        TEdit *edtUpFile;
        TButton *btnUpSelect;
        TButton *btnUpload;
        TGroupBox *GroupBox8;
        TLabel *Label6;
        TLabel *Label7;
        TLabel *Label8;
        TEdit *edtStartAddress;
        TEdit *edtLength;
        TCheckBox *cbLengthKB;
        TButton *btnTemplateSet;
        TCheckBox *cbExecFlag;
        TComboBox *cbTemplate;
        TLabel *Label3;
        TTabSheet *tsDebugger;
        TMemo *mDbgText;
        TGroupBox *GroupBox3;
        TButton *btnOpen;
        TLabel *Label5;
        TTabSheet *tsMemView;
        TLabel *Label1;
        TButton *btnParamSet;
        TLabel *Label2;
        TButton *btnIniOpen;
        TEdit *edtIniPath;
        TProgressBar *pbTransfer;
        TCheckBox *cbDbgUse;
        TTimer *tmStatusBarRefresh;
        TLabel *Label4;
        TLabel *Label11;
        TEdit *edtMemViewAddress;
        TButton *btnMemView;
        TCheckBox *cbMemViewAuto;
        TButton *btnMemViewWrite;
        TButton *btnAdrDown;
        TButton *btnAdrUp;
        TComboBox *cbParamText;
        TComboBox *cbParamValue;
        TButton *btnLogClear;
        TButton *btnFastExec2;
        TButton *btnClose;
        TStringGrid *sgDbgText;
        TEdit *edtDbgPrompt;
        TLabel *Label18;
        TButton *btnPromptSend;
        TGroupBox *GroupBox2;
        TLabel *Label14;
        TEdit *edtDbgFile;
        TEdit *edtDbgStartAddress;
        TButton *btnFastExec;
        TButton *btnSetDbgFolder;
        TEdit *edtDbgFolder;
        TLabel *Label16;
        TLabel *Label12;
        TLabel *Label15;
        TGroupBox *GroupBox4;
        TLabel *Label13;
        TMemo *mMemoryValues;
        TTimer *tmMemviewRefresh;
        TStringGrid *sgMemConvert;
        TGroupBox *GroupBox9;
        TComboBox *cbMemoryConvert;
        TComboBox *cbMemSize;
        TLabel *Label21;
        TButton *btnTest2;
        TButton *btnTest3;
        TGroupBox *GroupBox10;
        TLabel *Label22;
        TComboBox *cbLogType;
        TLabel *Label23;
        TComboBox *cbLogOutput;
        TButton *btnLogLevelSet;
        TComboBox *cbLogLevel;
        TLabel *Label24;
        TEdit *edtLogPath;
        TEdit *edtMainLogPath;
        TLabel *Label19;
        TEdit *edtLogSettings;
        TButton *btnLogLdSettings;
        TLabel *Label17;
        TEdit *edtDebugSleep;
        TButton *btnLogSave;
        TButton *btnMainLogSave;
        TTabSheet *tsDataLinkDBG;
        TLabel *Label20;
        TLabel *Label25;
        TEdit *edtUDLPort;
        TEdit *edtUDLColor;
        TLabel *Label26;
        TEdit *edtUDLAddress;
        TButton *btnUDLGo;
        TLabel *Label27;
        TEdit *edtUDLLen;
        TEdit *edtUDLCount;
        TLabel *Label28;
        TButton *btnTest1;
        TTabSheet *tsExtra1;
        TGroupBox *GroupBox5;
        TButton *btnTargetInfo;
        TGroupBox *GroupBox11;
        TButton *btnVDP1View;
        TPanel *pnVDP1;
        TImage *imgVDP1;
        TButton *btnVDP2CRAM;
        TCheckBox *cbSilentDbg;
        TButton *btnMainLogClear;
        TButton *btnLogSilent;
        TButton *btnLogOn;
        TGroupBox *gbLogLevels;
        TButton *btnLogLevelsGet;
        TMemo *mLogLevels;
        TMainMenu *MainMenu1;
        TMenuItem *mniDevice;
        TMenuItem *mniSend;
        TMenuItem *mniReceive;
        TMenuItem *mniReceiveBackupMemory;
        TMenuItem *mniReceiveBIOS;
        TMenuItem *mniReceiveARPFirmWare;
        TMenuItem *mniSendBackupMemory;
        TLabel *lblDbgInfos1;
        TLabel *lblDbgInfos2;
        TLabel *lblDbgInfos3;
        TMenuItem *mniSetUSBDataLinkParameters;
        TMenuItem *mniOpenUSBDataLink;
        TMenuItem *mniExecProgram;
        void __fastcall FormCreate(TObject *Sender);
        void __fastcall FormClose(TObject *Sender, TCloseAction &Action);
        void __fastcall btnClick(TObject *Sender);
        void __fastcall btnDownSelectClick(TObject *Sender);
        void __fastcall btnUpSelectClick(TObject *Sender);
        void __fastcall btnIniOpenClick(TObject *Sender);
        void __fastcall btnTemplateSetClick(TObject *Sender);
        void __fastcall tmStatusBarRefreshTimer(TObject *Sender);
        void __fastcall edtDbgPromptKeyPress(TObject *Sender, char &Key);
        void __fastcall sgMemorySelectCell(TObject *Sender, int ACol,
          int ARow, bool &CanSelect);
        void __fastcall cbMemoryConvertChange(TObject *Sender);
        void __fastcall tmMemviewRefreshTimer(TObject *Sender);
        void __fastcall btnTest2Click(TObject *Sender);
        void __fastcall btnTest3Click(TObject *Sender);
        void __fastcall btnUDLGoClick(TObject *Sender);
        void __fastcall sgMemConvertDrawCell(TObject *Sender, int ACol,
          int ARow, TRect &Rect, TGridDrawState State);
        void __fastcall btnVDP2CRAMClick(TObject *Sender);
        void __fastcall btnLogLevelsGetClick(TObject *Sender);
        void __fastcall mniClick(TObject *Sender);
        void __fastcall mniSetUSBDataLinkParametersClick(TObject *Sender);
private:	// User declarations
        unsigned long ulCloseCount;
        void __fastcall ProcessThreadEnd(TObject *Sender);
public:		// User declarations
        __fastcall TForm1(TComponent* Owner);

        /*--- Command line related ---*/
        char cl_buffer[8192];
        char inifilebuffer[INIFILE_MAXSIZE];
        int argc;
        char* argv[MAXARGS];

        ProcessThread *thProcessThread;

        /*--- Logging related. ---*/
        void /*__fastcall*/ LogOut(const char *string, ...);
        /*--- Settings related. ---*/
        AnsiString __fastcall MakeSettingsFilePath(void);
        void __fastcall LoadSettingsFile(void);
        void __fastcall SaveSettingsFile(void);
        /*--- GUI related. ---*/
        char app_path[MAX_PATH];
        char app_name[MAX_PATH];
        UserData udGUI;
        int iDebugUse;
        void __fastcall InitFormItems(void);
        void __fastcall SaveFormItems(void);
        void __fastcall SaveToUserData(void);
        void __fastcall LoadFromUserData(void);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
