📄 uifltk-bkpt.cpp
字号:
/*************************************************************************** DSemu - The Next Generation ** Fltk user interface: Breakpoint dialog handler [uifltk-bkpt.cpp] ** Copyright Imran Nazar, 2005; released under the BSD public licence. ** Fltk used under the terms of the LGPL. ***************************************************************************/#include <FL/Fl.h>#include <map>#include "uifltk.h"#include "log.h"#include "datadefs.h"Fl_Window *UIFltk::UI::BkptWindow::mainWnd;Fl_Button *UIFltk::UI::BkptWindow::del, *UIFltk::UI::BkptWindow::add, *UIFltk::UI::BkptWindow::ok;Fl_Hold_Browser *UIFltk::UI::BkptWindow::browsemain, *UIFltk::UI::BkptWindow::browsesub;Fl_Group *UIFltk::UI::BkptWindow::grpmain, *UIFltk::UI::BkptWindow::grpsub;Fl_Tabs *UIFltk::UI::BkptWindow::tabs;int UIFltk::UI::BkptWindow::which = 0;// Initialise windowUIFltk::UI::BkptWindow::BkptWindow(int w, int h, void *t) : Fl_Window(w,h,"Breakpoints"){ mainWnd = (Fl_Window*)t; begin(); add = new Fl_Button(5,160, 80,30, "Add..."); add->callback(cbAdd, this); add->labelsize(11); del = new Fl_Button(90,160, 80,30, "Remove"); del->callback(cbDel, this); del->labelsize(11); ok = new Fl_Button(175,160, 80,30, "OK"); ok->callback(cbOK, this); ok->labelsize(11); // Add controls to the window if(DSmode) { tabs = new Fl_Tabs(5,5, 250,150); tabs->color(FL_GRAY, FL_GRAY); tabs->box(FL_EMBOSSED_BOX); tabs->labelsize(11); tabs->callback(cbTabs, this); grpmain = new Fl_Group(10,25, 240,125, "Main CPU"); grpmain->box(FL_NO_BOX); grpmain->labelsize(11); browsemain = new Fl_Hold_Browser(10,30, 240,120); browsemain->when(FL_WHEN_NEVER); grpmain->add(browsemain); grpsub = new Fl_Group(10,25, 240,125, "Sub CPU"); grpsub->box(FL_NO_BOX); grpsub->labelsize(11); browsesub = new Fl_Hold_Browser(10,30, 240,120); browsesub->when(FL_WHEN_NEVER); grpsub->add(browsesub); tabs->add(grpmain); tabs->add(grpsub); end(); cbTabs(tabs,this); resizable(tabs); } else { browsemain = new Fl_Hold_Browser(5,5, 250,150); browsemain->when(FL_WHEN_NEVER); end(); resizable(browsemain); } // Read the CPU's breakpoint map, and add entries to the browser std::map<u32, int> bkptmap = cpu->dbgBkptGet(); char str[10]; for(std::map<u32, int>::iterator i=bkptmap.begin(); i!=bkptmap.end(); ++i) { sprintf(str, "%08X", (*i).first); browsemain->add(str, (void*)(*i).first); } if(DSmode) { bkptmap = cpuSub->dbgBkptGet(); for(std::map<u32, int>::iterator i=bkptmap.begin(); i!=bkptmap.end(); ++i) { sprintf(str, "%08X", (*i).first); browsesub->add(str, (void*)(*i).first); } } which=0; // Put the window onscreen. show();}// Shut down window: Just hide it awayUIFltk::UI::BkptWindow::~BkptWindow(){ hide();}// Window event handler// NOTE: In this case, there's only one we want to catch: if the window// gets hidden, tell the main UI.int UIFltk::UI::BkptWindow::handle(int e){ int ret = Fl_Window::handle(e); switch(e) { case FL_HIDE: Fl::handle(0xBEEF0003, mainWnd); break; } return ret;}// Handler for the Add button (with static accessor function)void UIFltk::UI::BkptWindow::cbAdd(Fl_Widget *w, void *in) { ((UIFltk::UI::BkptWindow*)in)->cbAddI(); }inline void UIFltk::UI::BkptWindow::cbAddI(){ const char *in; char out[10]; u32 val; // Read a value from the user in = fl_input("Please enter an 8-digit hexadecimal address:"); if(!in) return; // Convert it to hexadecimal (automatically validates input) val = strtol(in, NULL, 16); sprintf(out, "%08X", val); // Add that entry to the breakpoint map. If it's already there, it // doesn't need adding. std::map<u32, int> bkptmap; switch(which) { case 0: bkptmap = cpu->dbgBkptGet(); if(bkptmap.find(val) != bkptmap.end()) return; browsemain->add(out, (void*)val); cpu->dbgBkptToggle(val); break; case 1: bkptmap = cpuSub->dbgBkptGet(); if(bkptmap.find(val) != bkptmap.end()) return; browsesub->add(out, (void*)val); cpuSub->dbgBkptToggle(val); break; }}// Handler for the Remove button (with static accessor)void UIFltk::UI::BkptWindow::cbDel(Fl_Widget *w, void *in) { ((UIFltk::UI::BkptWindow*)in)->cbDelI(); }inline void UIFltk::UI::BkptWindow::cbDelI(){ u32 addr; switch(which) { case 0: // Special case for only one value: Clear the browser if(browsemain->size()==1) { addr=(u32)browsemain->data(1); browsemain->clear(); cpu->dbgBkptToggle(addr); } else { // Run through the browser, removing all the selected items for(int i=0; i<browsemain->size(); ++i) { if(browsemain->selected(i+1)) { addr=(u32)browsemain->data(i+1); browsemain->remove(i+1); cpu->dbgBkptToggle(addr); } } } break; case 1: // Special case for only one value: Clear the browser if(browsesub->size()==1) { addr=(u32)browsesub->data(1); browsesub->clear(); cpuSub->dbgBkptToggle(addr); } else { // Run through the browser, removing all the selected items for(int i=0; i<browsesub->size(); ++i) { if(browsesub->selected(i+1)) { addr=(u32)browsesub->data(i+1); browsesub->remove(i+1); cpuSub->dbgBkptToggle(addr); } } } break; }}void UIFltk::UI::BkptWindow::cbTabs(Fl_Widget *w, void *in){ Fl::visible_focus(0); Fl_Tabs* t = (Fl_Tabs*)w; int n = t->children(); Fl_Group* g = (Fl_Group*) (t->value()); g->labelfont(FL_HELVETICA_BOLD); Fl_Group** kids = (Fl_Group**) (t->array()); for(int i = 0; i < n; ++i) { if(kids[i] != g) kids[i]->labelfont(FL_HELVETICA); else which = i; }}// Handler for OK (hide the window)void UIFltk::UI::BkptWindow::cbOK(Fl_Widget *w, void *in) { ((UIFltk::UI::BkptWindow*)in)->cbOKI(); }inline void UIFltk::UI::BkptWindow::cbOKI(){ hide();}/*** EOF: uifltk-bkpt.cpp ************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -