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