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 "CartMDM.hxx"
19#include "PopUpWidget.hxx"
20#include "Widget.hxx"
21#include "CartMDMWidget.hxx"
22
23// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
24CartridgeMDMWidget::CartridgeMDMWidget(
25 GuiObject* boss, const GUI::Font& lfont, const GUI::Font& nfont,
26 int x, int y, int w, int h, CartridgeMDM& cart)
27 : CartDebugWidget(boss, lfont, nfont, x, y, w, h),
28 myCart(cart)
29{
30 size_t size = myCart.mySize;
31
32 ostringstream info;
33 info << "Menu Driven Megacart, containing up to 128 4K banks\n"
34 << "Startup bank = " << cart.startBank() << "\n"
35 << "\nBanks are selected by reading from $800 - $BFF, where the lower "
36 "byte determines the 4K bank to use.";
37
38 int xpos = 2,
39 ypos = addBaseInformation(size, "Edwin Blink", info.str(), 15) + myLineHeight;
40
41 VariantList items;
42 for(uInt32 i = 0x800; i < (0x800u + myCart.bankCount()); ++i)
43 {
44 info.str("");
45 info << std::dec << (i & 0xFF) << " ($" << Common::Base::HEX4 << i << ")";
46 VarList::push_back(items, info.str());
47 }
48
49 myBank =
50 new PopUpWidget(boss, _font, xpos, ypos-2, _font.getStringWidth("xxx ($0FFF)"),
51 myLineHeight, items, "Set bank ",
52 0, kBankChanged);
53 myBank->setTarget(this);
54 addFocusWidget(myBank);
55
56 xpos += myBank->getWidth() + 30;
57 myBankDisabled = new CheckboxWidget(boss, _font, xpos, ypos,
58 "Bankswitching is locked/disabled",
59 kBankDisabled);
60 myBankDisabled->setTarget(this);
61 addFocusWidget(myBankDisabled);
62}
63
64// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
65void CartridgeMDMWidget::loadConfig()
66{
67 myBank->setSelectedIndex(myCart.getBank());
68 myBankDisabled->setState(myCart.myBankingDisabled);
69
70 CartDebugWidget::loadConfig();
71}
72
73// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
74void CartridgeMDMWidget::handleCommand(CommandSender* sender,
75 int cmd, int data, int id)
76{
77 if(cmd == kBankChanged)
78 {
79 myCart.unlockBank();
80 myCart.bank(myBank->getSelected());
81 myCart.lockBank();
82 invalidate();
83 }
84 else if(cmd == kBankDisabled)
85 {
86 myCart.myBankingDisabled = myBankDisabled->getState();
87 }
88}
89
90// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
91string CartridgeMDMWidget::bankState()
92{
93 ostringstream& buf = buffer();
94
95 buf << "Bank = " << std::dec << myCart.getBank()
96 << ", hotspot = " << "$" << Common::Base::HEX4
97 << (myCart.getBank()+0x800);
98
99 return buf.str();
100}
101