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 "Cart3F.hxx"
19#include "PopUpWidget.hxx"
20#include "Cart3FWidget.hxx"
21
22// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
23Cartridge3FWidget::Cartridge3FWidget(
24 GuiObject* boss, const GUI::Font& lfont, const GUI::Font& nfont,
25 int x, int y, int w, int h, Cartridge3F& cart)
26 : CartDebugWidget(boss, lfont, nfont, x, y, w, h),
27 myCart(cart)
28{
29 size_t size = cart.mySize;
30
31 ostringstream info;
32 info << "Tigervision 3F cartridge, 2-256 2K banks\n"
33 << "Startup bank = " << cart.startBank() << " or undetermined\n"
34 << "First 2K bank selected by writing to $3F\n"
35 << "Last 2K always points to last 2K of ROM\n";
36
37 // Eventually, we should query this from the debugger/disassembler
38 uInt16 start = (cart.myImage[size-3] << 8) | cart.myImage[size-4];
39 start -= start % 0x1000;
40 info << "Bank RORG" << " = $" << Common::Base::HEX4 << start << "\n";
41
42 int xpos = 2,
43 ypos = addBaseInformation(size, "TigerVision", info.str()) + myLineHeight;
44
45 VariantList items;
46 for(uInt16 i = 0; i < cart.bankCount(); ++i)
47 VarList::push_back(items, Variant(i).toString() + " ($3F)");
48
49 ostringstream label;
50 label << "Set bank ($" << Common::Base::HEX4 << start << " - $" <<
51 (start+0x7FF) << ") ";
52 myBank =
53 new PopUpWidget(boss, _font, xpos, ypos-2, _font.getStringWidth("0 ($3F) "),
54 myLineHeight, items, label.str(),
55 _font.getStringWidth(label.str()), kBankChanged);
56 myBank->setTarget(this);
57 addFocusWidget(myBank);
58}
59
60// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
61void Cartridge3FWidget::loadConfig()
62{
63 Debugger& dbg = instance().debugger();
64 CartDebug& cart = dbg.cartDebug();
65 const CartState& state = static_cast<const CartState&>(cart.getState());
66 const CartState& oldstate = static_cast<const CartState&>(cart.getOldState());
67
68 myBank->setSelectedIndex(myCart.getBank(0), state.bank != oldstate.bank);
69
70 CartDebugWidget::loadConfig();
71}
72
73// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
74void Cartridge3FWidget::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}
85
86// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
87string Cartridge3FWidget::bankState()
88{
89 ostringstream& buf = buffer();
90
91 buf << "Bank = #" << std::dec << myCart.myCurrentBank << ", hotspot = $3F";
92
93 return buf.str();
94}
95