"Fossies" - the Fresh Open Source Software Archive

Member "stella-6.0.2/src/debugger/gui/RomWidget.cxx" (11 Oct 2019, 7551 Bytes) of package /linux/privat/stella-6.0.2-src.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "RomWidget.cxx" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 6.0.1_vs_6.0.2.

    1 //============================================================================
    2 //
    3 //   SSSS    tt          lll  lll
    4 //  SS  SS   tt           ll   ll
    5 //  SS     tttttt  eeee   ll   ll   aaaa
    6 //   SSSS    tt   ee  ee  ll   ll      aa
    7 //      SS   tt   eeeeee  ll   ll   aaaaa  --  "An Atari 2600 VCS Emulator"
    8 //  SS  SS   tt   ee      ll   ll  aa  aa
    9 //   SSSS     ttt  eeeee llll llll  aaaaa
   10 //
   11 // Copyright (c) 1995-2019 by Bradford W. Mott, Stephen Anthony
   12 // and the Stella Team
   13 //
   14 // See the file "License.txt" for information on usage and redistribution of
   15 // this file, and for a DISCLAIMER OF ALL WARRANTIES.
   16 //============================================================================
   17 
   18 #include "Settings.hxx"
   19 #include "Debugger.hxx"
   20 #include "CartDebug.hxx"
   21 #include "DiStella.hxx"
   22 #include "CpuDebug.hxx"
   23 #include "GuiObject.hxx"
   24 #include "Font.hxx"
   25 #include "DataGridWidget.hxx"
   26 #include "EditTextWidget.hxx"
   27 #include "PopUpWidget.hxx"
   28 #include "ContextMenu.hxx"
   29 #include "RomListWidget.hxx"
   30 #include "RomWidget.hxx"
   31 
   32 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   33 RomWidget::RomWidget(GuiObject* boss, const GUI::Font& lfont, const GUI::Font& nfont,
   34                      int x, int y, int w, int h)
   35   : Widget(boss, lfont, x, y, w, h),
   36     CommandSender(boss),
   37     myListIsDirty(true)
   38 {
   39   int xpos, ypos;
   40   StaticTextWidget* t;
   41   WidgetArray wid;
   42 
   43   // Show current bank state
   44   xpos = x;  ypos = y + 7;
   45   t = new StaticTextWidget(boss, lfont, xpos, ypos,
   46                            lfont.getStringWidth("Bank"),
   47                            lfont.getFontHeight(),
   48                            "Bank", TextAlign::Left);
   49 
   50   xpos += t->getWidth() + 5;
   51   myBank = new EditTextWidget(boss, nfont, xpos, ypos-2,
   52                               _w - 2 - xpos, nfont.getLineHeight());
   53   myBank->setEditable(false);
   54 
   55   // Create rom listing
   56   xpos = x;  ypos += myBank->getHeight() + 4;
   57 
   58   myRomList = new RomListWidget(boss, lfont, nfont, xpos, ypos, _w - 4, _h - ypos - 2);
   59   myRomList->setTarget(this);
   60   addFocusWidget(myRomList);
   61 }
   62 
   63 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   64 void RomWidget::loadConfig()
   65 {
   66   Debugger& dbg = instance().debugger();
   67   CartDebug& cart = dbg.cartDebug();
   68   const CartState& state = static_cast<const CartState&>(cart.getState());
   69   const CartState& oldstate = static_cast<const CartState&>(cart.getOldState());
   70 
   71   // Fill romlist the current bank of source or disassembly
   72   myListIsDirty |= cart.disassemble(myListIsDirty);
   73   if(myListIsDirty)
   74   {
   75     myRomList->setList(cart.disassembly(), dbg.breakPoints());
   76     myListIsDirty = false;
   77   }
   78 
   79   // Update romlist to point to current PC (if it has changed)
   80   int pcline = cart.addressToLine(dbg.cpuDebug().pc());
   81   if(pcline >= 0 && pcline != myRomList->getHighlighted())
   82     myRomList->setHighlighted(pcline);
   83 
   84   // Set current bank state
   85   myBank->setText(state.bank, state.bank != oldstate.bank);
   86 }
   87 
   88 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   89 void RomWidget::handleCommand(CommandSender* sender, int cmd, int data, int id)
   90 {
   91   switch(cmd)
   92   {
   93     case RomListWidget::kBPointChangedCmd:
   94       // 'data' is the line in the disassemblylist to be accessed
   95       // 'id' is the state of the breakpoint at 'data'
   96       setBreak(data, id);
   97       // Refresh the romlist, since the breakpoint may not have
   98       // actually changed
   99       myRomList->setDirty();
  100       myRomList->draw();
  101       break;
  102 
  103     case RomListWidget::kRomChangedCmd:
  104       // 'data' is the line in the disassemblylist to be accessed
  105       // 'id' is the base to use for the data to be changed
  106       patchROM(data, myRomList->getText(), Common::Base::Format(id));
  107       break;
  108 
  109     case RomListWidget::kSetPCCmd:
  110       // 'data' is the line in the disassemblylist to be accessed
  111       setPC(data);
  112       break;
  113 
  114     case RomListWidget::kRuntoPCCmd:
  115       // 'data' is the line in the disassemblylist to be accessed
  116       runtoPC(data);
  117       break;
  118 
  119     case RomListWidget::kDisassembleCmd:
  120       invalidate();
  121       break;
  122 
  123     case RomListWidget::kTentativeCodeCmd:
  124     {
  125       // 'data' is the boolean value
  126       DiStella::settings.resolveCode = data;
  127       instance().settings().setValue("dis.resolve",
  128           DiStella::settings.resolveCode);
  129       invalidate();
  130       break;
  131     }
  132 
  133     case RomListWidget::kPCAddressesCmd:
  134       // 'data' is the boolean value
  135       DiStella::settings.showAddresses = data;
  136       instance().settings().setValue("dis.showaddr",
  137           DiStella::settings.showAddresses);
  138       invalidate();
  139       break;
  140 
  141     case RomListWidget::kGfxAsBinaryCmd:
  142       // 'data' is the boolean value
  143       if(data)
  144       {
  145         DiStella::settings.gfxFormat = Common::Base::F_2;
  146         instance().settings().setValue("dis.gfxformat", "2");
  147       }
  148       else
  149       {
  150         DiStella::settings.gfxFormat = Common::Base::F_16;
  151         instance().settings().setValue("dis.gfxformat", "16");
  152       }
  153       invalidate();
  154       break;
  155 
  156     case RomListWidget::kAddrRelocationCmd:
  157       // 'data' is the boolean value
  158       DiStella::settings.rFlag = data;
  159       instance().settings().setValue("dis.relocate",
  160           DiStella::settings.rFlag);
  161       invalidate();
  162       break;
  163   }
  164 }
  165 
  166 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  167 void RomWidget::setBreak(int disasm_line, bool state)
  168 {
  169   const CartDebug::DisassemblyList& list =
  170       instance().debugger().cartDebug().disassembly().list;
  171   if(disasm_line >= int(list.size()))  return;
  172 
  173   if(list[disasm_line].address != 0 && list[disasm_line].bytes != "")
  174     instance().debugger().setBreakPoint(list[disasm_line].address, state);
  175 }
  176 
  177 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  178 void RomWidget::setPC(int disasm_line)
  179 {
  180   const CartDebug::DisassemblyList& list =
  181       instance().debugger().cartDebug().disassembly().list;
  182   if(disasm_line >= int(list.size()))  return;
  183 
  184   if(list[disasm_line].address != 0)
  185   {
  186     ostringstream command;
  187     command << "pc #" << list[disasm_line].address;
  188     instance().debugger().run(command.str());
  189   }
  190 }
  191 
  192 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  193 void RomWidget::runtoPC(int disasm_line)
  194 {
  195   const CartDebug::DisassemblyList& list =
  196       instance().debugger().cartDebug().disassembly().list;
  197   if(disasm_line >= int(list.size()))  return;
  198 
  199   if(list[disasm_line].address != 0)
  200   {
  201     ostringstream command;
  202     command << "runtopc #" << list[disasm_line].address;
  203     instance().debugger().run(command.str());
  204   }
  205 }
  206 
  207 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  208 void RomWidget::patchROM(int disasm_line, const string& bytes,
  209                          Common::Base::Format base)
  210 {
  211   const CartDebug::DisassemblyList& list =
  212       instance().debugger().cartDebug().disassembly().list;
  213   if(disasm_line >= int(list.size()))  return;
  214 
  215   if(list[disasm_line].address != 0)
  216   {
  217     ostringstream command;
  218 
  219     // Temporarily set to correct base, so we don't have to prefix each byte
  220     // with the type of data
  221     Common::Base::Format oldbase = Common::Base::format();
  222 
  223     Common::Base::setFormat(base);
  224     command << "rom #" << list[disasm_line].address << " " << bytes;
  225     instance().debugger().run(command.str());
  226 
  227     // Restore previous base
  228     Common::Base::setFormat(oldbase);
  229   }
  230 }
  231 
  232 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  233 void RomWidget::scrollTo(int line)
  234 {
  235   myRomList->setSelected(line);
  236 }