[Dialogs] Prevent viewers from causing a crash

Some of the viewers dialogs were not properly set up and were causing a
crash at runtime.
This commit is contained in:
Fabrice de Gans 2024-04-04 11:50:20 -07:00 committed by Fabrice de Gans
parent ecd16a21dc
commit 047ad27777
2 changed files with 48 additions and 20 deletions

View File

@ -1683,7 +1683,9 @@ public:
} }
protected: protected:
int charbase_, is256_, palette_; int charbase_ = 0;
int is256_ = 0;
int palette_ = 0;
wxControl *tileno_, *addr_; wxControl *tileno_, *addr_;
int selx_, sely_; int selx_, sely_;

View File

@ -4,6 +4,7 @@
#include <limits> #include <limits>
#include <wx/event.h>
#include <wx/ffile.h> #include <wx/ffile.h>
#include <wx/vlbox.h> #include <wx/vlbox.h>
@ -79,7 +80,7 @@ public:
Fit(); Fit();
SetMinSize(GetSize()); SetMinSize(GetSize());
dis->maxaddr = (uint32_t)~0; dis->maxaddr = (uint32_t)~0;
dismode = 0; disassembly_mode_ = DisassemblyMode::Automatic;
GotoPC(); GotoPC();
} }
void Update() void Update()
@ -106,9 +107,8 @@ public:
UpdateDis(); UpdateDis();
} }
// wx-2.8.4 or MacOSX compiler can't resolve overloads in evt table // wx-2.8.4 or MacOSX compiler can't resolve overloads in evt table
void GotoPCEv(wxCommandEvent& ev) void GotoPCEv(wxCommandEvent&)
{ {
(void)ev; // unused params
GotoPC(); GotoPC();
} }
void GotoPC() void GotoPC()
@ -161,13 +161,14 @@ public:
dis->strings.clear(); dis->strings.clear();
dis->addrs.clear(); dis->addrs.clear();
uint32_t addr = dis->topaddr; uint32_t addr = dis->topaddr;
bool arm = dismode == 1 || (armState && dismode != 2); const bool arm_mode = disassembly_mode_ == DisassemblyMode::Arm ||
dis->back_size = arm ? 4 : 2; (armState && disassembly_mode_ == DisassemblyMode::Automatic);
dis->back_size = arm_mode ? 4 : 2;
for (int i = 0; i < dis->nlines; i++) { for (int i = 0; i < dis->nlines; i++) {
dis->addrs.push_back(addr); dis->addrs.push_back(addr);
if (arm) if (arm_mode)
addr += disArm(addr, buf, 4096, DIS_VIEW_CODE | DIS_VIEW_ADDRESS); addr += disArm(addr, buf, 4096, DIS_VIEW_CODE | DIS_VIEW_ADDRESS);
else else
addr += disThumb(addr, buf, 4096, DIS_VIEW_CODE | DIS_VIEW_ADDRESS); addr += disThumb(addr, buf, 4096, DIS_VIEW_CODE | DIS_VIEW_ADDRESS);
@ -178,10 +179,32 @@ public:
dis->Refill(); dis->Refill();
} }
private:
enum class DisassemblyMode {
Automatic,
Arm,
Thumb,
};
void AutomaticMode(wxCommandEvent& ev) {
disassembly_mode_ = DisassemblyMode::Automatic;
RefillListEv(ev);
}
void ArmMode(wxCommandEvent& ev) {
disassembly_mode_ = DisassemblyMode::Arm;
RefillListEv(ev);
}
void ThumbMode(wxCommandEvent& ev) {
disassembly_mode_ = DisassemblyMode::Thumb;
RefillListEv(ev);
}
DisList* dis; DisList* dis;
wxTextCtrl* goto_addr; wxTextCtrl* goto_addr;
wxCheckBox *N, *Z, *C, *V, *I, *F, *T; wxCheckBox *N, *Z, *C, *V, *I, *F, *T;
int dismode; DisassemblyMode disassembly_mode_;
wxControl *regv[17], *Modev; wxControl *regv[17], *Modev;
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
}; };
@ -193,6 +216,9 @@ EVT_TEXT_ENTER(XRCID("GotoAddress"), DisassembleViewer::Goto)
EVT_BUTTON(XRCID("GotoPC"), DisassembleViewer::GotoPCEv) EVT_BUTTON(XRCID("GotoPC"), DisassembleViewer::GotoPCEv)
EVT_BUTTON(XRCID("Next"), DisassembleViewer::Next) EVT_BUTTON(XRCID("Next"), DisassembleViewer::Next)
EVT_BUTTON(XRCID("Refresh"), DisassembleViewer::RefreshCmd) EVT_BUTTON(XRCID("Refresh"), DisassembleViewer::RefreshCmd)
EVT_BUTTON(XRCID("InsAuto"), DisassembleViewer::AutomaticMode)
EVT_BUTTON(XRCID("InsARM"), DisassembleViewer::ArmMode)
EVT_BUTTON(XRCID("InsThumb"), DisassembleViewer::ThumbMode)
END_EVENT_TABLE() END_EVENT_TABLE()
class GBDisassembleViewer : public Viewer { class GBDisassembleViewer : public Viewer {
@ -386,7 +412,7 @@ public:
// and while at it, translate all the strings // and while at it, translate all the strings
if (!lline) { if (!lline) {
for (int j = 0; j < 16; j++) { for (int j = 0; j < 16; j++) {
if (ioregs[i].bits[j][0]) { if (!ioregs[i].bits[j].IsEmpty()) {
ioregs[i].bits[j] = wxGetTranslation(ioregs[i].bits[j]); ioregs[i].bits[j] = wxGetTranslation(ioregs[i].bits[j]);
int w, h; int w, h;
bitlab[0]->GetTextExtent(ioregs[i].bits[j], &w, &h); bitlab[0]->GetTextExtent(ioregs[i].bits[j], &w, &h);
@ -621,7 +647,7 @@ public:
} }
bs = XRCCTRL(*this, "BlockStart", wxChoice); bs = XRCCTRL(*this, "BlockStart", wxChoice);
if (bs) { if (!bs) {
baddialog(); baddialog();
} }