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 "CartF0.hxx"
19#include "PopUpWidget.hxx"
20#include "CartF0Widget.hxx"
21
22// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
23CartridgeF0Widget::CartridgeF0Widget(
24 GuiObject* boss, const GUI::Font& lfont, const GUI::Font& nfont,
25 int x, int y, int w, int h, CartridgeF0& cart)
26 : CartDebugWidget(boss, lfont, nfont, x, y, w, h),
27 myCart(cart)
28{
29 uInt32 size = 16 * 4096;
30
31 ostringstream info;
32 info << "64K Megaboy F0 cartridge, 16 4K banks\n"
33 << "Startup bank = #" << cart.startBank() << " or undetermined\n"
34 << "Bankswitch triggered by accessing $1FF0\n";
35
36 // Eventually, we should query this from the debugger/disassembler
37 for(uInt32 i = 0, offset = 0xFFC; i < 16; ++i, offset += 0x1000)
38 {
39 uInt16 start = (cart.myImage[offset+1] << 8) | cart.myImage[offset];
40 start -= start % 0x1000;
41 info << "Bank " << std::dec << i << " @ $" << Common::Base::HEX4 << start
42 << " - " << "$" << (start + 0xFFF) << "\n";
43 }
44
45 int xpos = 2,
46 ypos = addBaseInformation(size, "Dynacom Megaboy",
47 info.str()) + myLineHeight;
48
49 VariantList items;
50 VarList::push_back(items, " 0");
51 VarList::push_back(items, " 1");
52 VarList::push_back(items, " 2");
53 VarList::push_back(items, " 3");
54 VarList::push_back(items, " 4");
55 VarList::push_back(items, " 5");
56 VarList::push_back(items, " 6");
57 VarList::push_back(items, " 7");
58 VarList::push_back(items, " 8");
59 VarList::push_back(items, " 9");
60 VarList::push_back(items, " 10");
61 VarList::push_back(items, " 11");
62 VarList::push_back(items, " 12");
63 VarList::push_back(items, " 13");
64 VarList::push_back(items, " 14");
65 VarList::push_back(items, " 15");
66 myBank =
67 new PopUpWidget(boss, _font, xpos, ypos-2, _font.getStringWidth(" 15"),
68 myLineHeight, items, "Set bank #",
69 0, kBankChanged);
70 myBank->setTarget(this);
71 addFocusWidget(myBank);
72}
73
74// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
75void CartridgeF0Widget::loadConfig()
76{
77 Debugger& dbg = instance().debugger();
78 CartDebug& cart = dbg.cartDebug();
79 const CartState& state = static_cast<const CartState&>(cart.getState());
80 const CartState& oldstate = static_cast<const CartState&>(cart.getOldState());
81
82 myBank->setSelectedIndex(myCart.getBank(), state.bank != oldstate.bank);
83
84 CartDebugWidget::loadConfig();
85}
86
87// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
88void CartridgeF0Widget::handleCommand(CommandSender* sender,
89 int cmd, int data, int id)
90{
91 if(cmd == kBankChanged)
92 {
93 myCart.unlockBank();
94 myCart.bank(myBank->getSelected());
95 myCart.lockBank();
96 invalidate();
97 }
98}
99
100// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
101string CartridgeF0Widget::bankState()
102{
103 ostringstream& buf = buffer();
104
105 buf << "Bank = #" << std::dec << myCart.getBank() << ", hotspot = $FFF0";
106
107 return buf.str();
108}
109