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