⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 debug.cpp

📁 一个gba的模拟器源代码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
                pen->Color=clWhite;
            }
            else
            {
                brush->Color=clTeal;
                pen->Color=clWhite;
            }
        }
        else
        {
            if (bp)
            {
                brush->Color=clPurple;
                pen->Color=clWhite;
            }
            else
            {
                brush->Color=clNavy;
                pen->Color=clWhite;
            }
        }
    }
    else
    {
        if ((!txt)&&(Code->Items->Strings[Index].c_str()[4]=='-'))
        {
            if (bp)
            {
                brush->Color=clOlive;
                pen->Color=clWhite;
            }
            else
            {
                brush->Color=clGreen;
                pen->Color=clWhite;
            }
        }
        else
        {
            if (bp)
            {
                brush->Color=clMaroon;
                pen->Color=clWhite;
            }
            else
            {
                brush->Color=clWhite;
                pen->Color=clBlack;
            }
        }
    }
    Code->Canvas->Brush=brush;
    Code->Canvas->Pen=pen;
    Code->Canvas->FillRect(Rect);
    Code->Canvas->Font->Color=pen->Color;
    HFONT fnt;
    TFont *oldFont;
    if (txt)
    {
        fnt=CreateFont(-MulDiv(8,GetDeviceCaps(
            Code->Canvas->Handle, LOGPIXELSY),72),0,0,0,
            FW_BOLD,0,0,0,ANSI_CHARSET,OUT_DEFAULT_PRECIS,
            CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,
            FF_DONTCARE,"Courier New");
        oldFont=Code->Canvas->Font;
        Code->Canvas->Font->Handle=fnt;
        Code->Canvas->TextOut(Rect.Left,Rect.Top,&(Code->Items->
            Strings[Index].c_str()[1]));
        Code->Canvas->Font=oldFont;
        DeleteObject(fnt);
    }
    else
    {
        Code->Canvas->TextOut(Rect.Left,Rect.Top,Code->Items->
            Strings[Index]);
    }
    Code->Canvas->Brush=oldBrush;
    Code->Canvas->Pen=oldPen;
}
//---------------------------------------------------------------------------

void __fastcall TDebugWnd::GotoPC1Click(TObject *Sender)
{
    debugStartPC=regPC;//R.PC.D;
    Update();
}
//---------------------------------------------------------------------------

void __fastcall TDebugWnd::Clearallbreakpoints1Click(TObject *Sender)
{
//    PauseStart();
    debugCodeBreakCount=0;
    debugDataBreakCount=0;
    debugProgBreak=0;
    Code->Repaint();
//    PauseEnd();
}
//---------------------------------------------------------------------------
void __fastcall TDebugWnd::Setdatabreakpoint1Click(TObject *Sender)
{
    if (!romLoaded) return;
    #ifdef DEMO
    MessageBox(NULL,"This feature is disabled in the demo version.","VGBC",MB_OK|MB_TASKMODAL);
    return;
    #endif
//    PauseStart();
//    DataBreakDlg->UpdateList();
//    DataBreakDlg->ShowModal();
//    PauseEnd();
}
//---------------------------------------------------------------------------

void __fastcall TDebugWnd::Searchforvalue1Click(TObject *Sender)
{
    if (!romLoaded) return;
    #ifdef DEMO
    MessageBox(NULL,"This feature is disabled in the demo version.","VGBC",MB_OK|MB_TASKMODAL);
    return;
    #else
    SearchDlg->ActiveControl=SearchDlg->Value;
    if (SearchDlg->ShowModal()==1)
    {
        int v,addr;
        if (SearchDlg->Size->ItemIndex<3)
        {
            sscanf(SearchDlg->Value->Text.c_str(),"%x",&v);
            if (SearchDlg->Size->ItemIndex==0) v&=0xff;
            else if (SearchDlg->Size->ItemIndex==1) v&=0xffff;
            addr=(debugStartMem+2)&0xffffff;
            int size=SearchDlg->Size->ItemIndex;
            if (size!=0) addr&=~1;
            for (;addr<0x10000;addr+=(size==0)?1:2)
            {
                if (size==0)
                {
                    if ((getmem_direct(addr)&0xff)==v)
                    {
                        debugStartMem=addr;
                        UpdateMem();
                        break;
                    }
                }
                else if (size==1)
                {
                    if ((GETWORD(addr)&0xffff)==v)
                    {
                        debugStartMem=addr;
                        UpdateMem();
                        break;
                    }
                }
                else
                {
                    if (GETDWORD(addr)==v)
                    {
                        debugStartMem=addr;
                        UpdateMem();
                        break;
                    }
                }
            }
        }
        else
        {
            char str[256];
            int indx;

            addr=(debugStartMem+2)&0xffffff;
            strcpy(str,SearchDlg->Value->Text.c_str());
            for (indx=0;addr<0x10000;addr++)
            {
                if (!str[indx])
                {
                    addr-=strlen(str);
                    debugStartMem=addr;
                    UpdateMem();
                    break;
                }
                if ((getmem_direct(addr)&0xff)!=(str[indx]&0xff))
                    indx=0;
                else
                    indx++;
            }
        }
        if (addr>=0x10000)
            MessageBox(Handle,"No matches found","Search error",MB_OK|MB_TASKMODAL);
    }
    #endif
}
//---------------------------------------------------------------------------

void __fastcall TDebugWnd::Stepover1Click(TObject *Sender)
{
    if (!romLoaded) return;
    debugException=0;
    if (debugStepOver) return;
    #ifdef DEMO
    MessageBox(NULL,"This feature is disabled in the demo version.","VGBC",MB_OK|MB_TASKMODAL);
    return;
    #else
    unsigned short buf[16];
    char str[64];
    int addr,i;
//    PauseStart();
//    for (i=0;i<16;i++)
//        buf[i]=GETWORD(R.PC.D+(i<<1));
    for (i=0;i<16;i++)
        buf[i]=GETWORD(regPC+(i<<1));
//    addr=R.PC.D+DasmZ80(str,R.PC.D);
    addr=regPC+DasmZ80(str,regPC);
    debugStepOver=1; debugStepGoal=addr;
    debugBeginStepOver=1; debugEndStepOver=0;
    debugStepA7=regSP;//R.SP.D;
    run=1;
    OneInstruction();
//    PauseEnd();
    #endif
}
//---------------------------------------------------------------------------

void __fastcall TDebugWnd::AFClick(TObject *Sender)
{
    #ifdef DEMO
    MessageBox(NULL,"This feature is disabled in the demo version.","VGBC",MB_OK|MB_TASKMODAL);
    return;
    #else
    char str[4];
//    sprintf(str,"%4.4X",R.AF.D&0xffff);
    sprintf(str,"%4.4X",regAF&0xffff);
    NewValueDlg->Address->Text=str;
    NewValueDlg->Address->SelectAll();
    NewValueDlg->ActiveControl=NewValueDlg->Address;
    if (NewValueDlg->ShowModal()==1)
    {
//        sscanf(NewValueDlg->Address->Text.c_str(),"%x",&R.AF.D);
        sscanf(NewValueDlg->Address->Text.c_str(),"%x",&regAF);
        Update();
    }
    #endif
}
//---------------------------------------------------------------------------

void __fastcall TDebugWnd::BCClick(TObject *Sender)
{
    #ifdef DEMO
    MessageBox(NULL,"This feature is disabled in the demo version.","VGBC",MB_OK|MB_TASKMODAL);
    return;
    #else
    char str[4];
//    sprintf(str,"%4.4X",R.BC.D&0xffff);
    sprintf(str,"%4.4X",regBC&0xffff);
    NewValueDlg->Address->Text=str;
    NewValueDlg->Address->SelectAll();
    NewValueDlg->ActiveControl=NewValueDlg->Address;
    if (NewValueDlg->ShowModal()==1)
    {
//        sscanf(NewValueDlg->Address->Text.c_str(),"%x",&R.BC.D);
        sscanf(NewValueDlg->Address->Text.c_str(),"%x",&regBC);
        Update();
    }
    #endif
}
//---------------------------------------------------------------------------

void __fastcall TDebugWnd::DEClick(TObject *Sender)
{
    #ifdef DEMO
    MessageBox(NULL,"This feature is disabled in the demo version.","VGBC",MB_OK|MB_TASKMODAL);
    return;
    #else
    char str[4];
//    sprintf(str,"%4.4X",R.DE.D&0xffff);
    sprintf(str,"%4.4X",regDE&0xffff);
    NewValueDlg->Address->Text=str;
    NewValueDlg->Address->SelectAll();
    NewValueDlg->ActiveControl=NewValueDlg->Address;
    if (NewValueDlg->ShowModal()==1)
    {
//        sscanf(NewValueDlg->Address->Text.c_str(),"%x",&R.DE.D);
        sscanf(NewValueDlg->Address->Text.c_str(),"%x",&regDE);
        Update();
    }
    #endif
}
//---------------------------------------------------------------------------

void __fastcall TDebugWnd::HLClick(TObject *Sender)
{
    #ifdef DEMO
    MessageBox(NULL,"This feature is disabled in the demo version.","VGBC",MB_OK|MB_TASKMODAL);
    return;
    #else
    char str[4];
//    sprintf(str,"%4.4X",R.HL.D&0xffff);
    sprintf(str,"%4.4X",regHL&0xffff);
    NewValueDlg->Address->Text=str;
    NewValueDlg->Address->SelectAll();
    NewValueDlg->ActiveControl=NewValueDlg->Address;
    if (NewValueDlg->ShowModal()==1)
    {
//        sscanf(NewValueDlg->Address->Text.c_str(),"%x",&R.HL.D);
        sscanf(NewValueDlg->Address->Text.c_str(),"%x",&regHL);
        Update();
    }
    #endif
}
//---------------------------------------------------------------------------

void __fastcall TDebugWnd::SPClick(TObject *Sender)
{
    #ifdef DEMO
    MessageBox(NULL,"This feature is disabled in the demo version.","VGBC",MB_OK|MB_TASKMODAL);
    return;
    #else
    char str[4];
//    sprintf(str,"%4.4X",R.SP.D&0xffff);
    sprintf(str,"%4.4X",regSP&0xffff);
    NewValueDlg->Address->Text=str;
    NewValueDlg->Address->SelectAll();
    NewValueDlg->ActiveControl=NewValueDlg->Address;
    if (NewValueDlg->ShowModal()==1)
    {
//        sscanf(NewValueDlg->Address->Text.c_str(),"%x",&R.SP.D);
        sscanf(NewValueDlg->Address->Text.c_str(),"%x",&regSP);
        Update();
    }
    #endif
}

void __fastcall TDebugWnd::PCClick(TObject *Sender)
{
    #ifdef DEMO
    MessageBox(NULL,"This feature is disabled in the demo version.","VGBC",MB_OK|MB_TASKMODAL);
    return;
    #else
    char str[4];
//    sprintf(str,"%4.4X",R.PC.D&0xffff);
    sprintf(str,"%4.4X",regPC);
    NewValueDlg->Address->Text=str;
    NewValueDlg->Address->SelectAll();
    NewValueDlg->ActiveControl=NewValueDlg->Address;
    if (NewValueDlg->ShowModal()==1)
    {
//        sscanf(NewValueDlg->Address->Text.c_str(),"%x",&R.PC.D);
        sscanf(NewValueDlg->Address->Text.c_str(),"%x",&regPC);
        Update();
    }
    #endif
}

/*void __fastcall TDebugWnd::Viewlog1Click(TObject *Sender)
{
    PauseStart();
    LogDlg->ShowModal();
    Enablelogging1->Checked=debugLogEnable;
    if ((debugLogEnable&&debugLogCount)||debugDataBreakCount)
        UseDebugReadFuncs();
    else
        RestoreReadFuncs();
    PauseEnd();
}
//---------------------------------------------------------------------------

void __fastcall TDebugWnd::Editloggedaddresses1Click(TObject *Sender)
{
    PauseStart();
    EditLogDlg->UpdateList();
    EditLogDlg->ShowModal();
    Enablelogging1->Checked=debugLogEnable;
    if ((debugLogEnable&&debugLogCount)||debugDataBreakCount)
        UseDebugReadFuncs();
    else
        RestoreReadFuncs();
    PauseEnd();
}
//---------------------------------------------------------------------------

void __fastcall TDebugWnd::Enablelogging1Click(TObject *Sender)
{
    PauseStart();
    debugLogEnable=!debugLogEnable;
    Enablelogging1->Checked=debugLogEnable;
    if ((debugLogEnable&&debugLogCount)||debugDataBreakCount)
        UseDebugReadFuncs();
    else
        RestoreReadFuncs();
    PauseEnd();
}
//---------------------------------------------------------------------------

void __fastcall TDebugWnd::Clearall1Click(TObject *Sender)
{
    PauseStart();
    debugLogEnable=0;
    Enablelogging1->Checked=false;
    debugLogCount=0;
    if ((debugLogEnable&&debugLogCount)||debugDataBreakCount)
        UseDebugReadFuncs();
    else
        RestoreReadFuncs();
    PauseEnd();
}
//---------------------------------------------------------------------------

void __fastcall TDebugWnd::Loglinkportsend1Click(TObject *Sender)
{
    Loglinkportsend1->Checked=!Loglinkportsend1->Checked;
    debugLogLinkSend=Loglinkportsend1->Checked;
}
//---------------------------------------------------------------------------

void __fastcall TDebugWnd::Loglinkportreceive1Click(TObject *Sender)
{
    Loglinkportreceive1->Checked=!Loglinkportreceive1->Checked;
    debugLogLinkRecv=Loglinkportreceive1->Checked;
}*/
//---------------------------------------------------------------------------

int CheckAddr(int addr,int size,int type,int v)
{
    int i;
    for (i=0;i<debugDataBreakCount;i++)
    {
        if (!(debugDataBreakType[i]&type)) continue;
        if ((addr>(debugDataBreakLow[i]-size))&&
            (addr<=debugDataBreakHigh[i]))
            return 1;
    }
/*    int pc=R.PC.D;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -