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 "CartSB.hxx"
19#include "PopUpWidget.hxx"
20#include "CartSBWidget.hxx"
21
22// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
23CartridgeSBWidget::CartridgeSBWidget(
24 GuiObject* boss, const GUI::Font& lfont, const GUI::Font& nfont,
25 int x, int y, int w, int h, CartridgeSB& cart)
26 : CartDebugWidget(boss, lfont, nfont, x, y, w, h),
27 myCart(cart)
28{
29 size_t size = myCart.mySize;
30
31 VariantList items;
32 ostringstream info, bank;
33 info << "SB SUPERbanking, 32 or 64 4K banks\n"
34 << "Hotspots are from $800 to $"
35 << Common::Base::HEX2 << (0x800 + myCart.bankCount() - 1) << ", including\n"
36 << "mirrors ($900, $A00, $B00, ...)\n"
37 << "Startup bank = " << std::dec << cart.startBank() << "\n";
38
39 // Eventually, we should query this from the debugger/disassembler
40 for(uInt32 i = 0, offset = 0xFFC, spot = 0x800; i < myCart.bankCount();
41 ++i, offset += 0x1000, ++spot)
42 {
43 uInt16 start = (cart.myImage[offset+1] << 8) | cart.myImage[offset];
44 start -= start % 0x1000;
45 info << "Bank " << std::dec << i << " @ $" << Common::Base::HEX4 << start << " - "
46 << "$" << (start + 0xFFF) << " (hotspot = $" << spot << ")\n";
47
48 bank << std::dec << std::setw(2) << std::setfill(' ') << i << " ($"
49 << Common::Base::HEX2 << spot << ")";
50 VarList::push_back(items, bank.str());
51 bank.str("");
52 }
53
54 int xpos = 2,
55 ypos = addBaseInformation(size, "Fred X. Quimby", info.str()) + myLineHeight;
56
57 myBank =
58 new PopUpWidget(boss, _font, xpos, ypos-2, _font.getStringWidth("XX ($800)"),
59 myLineHeight, items, "Set bank ",
60 0, kBankChanged);
61 myBank->setTarget(this);
62 addFocusWidget(myBank);
63}
64
65// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
66void CartridgeSBWidget::loadConfig()
67{
68 Debugger& dbg = instance().debugger();
69 CartDebug& cart = dbg.cartDebug();
70 const CartState& state = static_cast<const CartState&>(cart.getState());
71 const CartState& oldstate = static_cast<const CartState&>(cart.getOldState());
72
73 myBank->setSelectedIndex(myCart.getBank(), state.bank != oldstate.bank);
74
75 CartDebugWidget::loadConfig();
76}
77
78// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
79void CartridgeSBWidget::handleCommand(CommandSender* sender,
80 int cmd, int data, int id)
81{
82 if(cmd == kBankChanged)
83 {
84 myCart.unlockBank();
85 myCart.bank(myBank->getSelected());
86 myCart.lockBank();
87 invalidate();
88 }
89}
90
91// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
92string CartridgeSBWidget::bankState()
93{
94 ostringstream& buf = buffer();
95
96 buf << "Bank = " << std::dec << myCart.getBank()
97 << ", hotspot = $" << Common::Base::HEX2 << (myCart.getBank() + 0x800);
98
99 return buf.str();
100}
101