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 "CartF6.hxx"
19#include "PopUpWidget.hxx"
20#include "CartF6Widget.hxx"
21
22// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
23CartridgeF6Widget::CartridgeF6Widget(
24 GuiObject* boss, const GUI::Font& lfont, const GUI::Font& nfont,
25 int x, int y, int w, int h, CartridgeF6& cart)
26 : CartDebugWidget(boss, lfont, nfont, x, y, w, h),
27 myCart(cart)
28{
29 uInt16 size = 4 * 4096;
30
31 ostringstream info;
32 info << "Standard F6 cartridge, four 4K banks\n"
33 << "Startup bank = " << cart.startBank() << " or undetermined\n";
34
35 // Eventually, we should query this from the debugger/disassembler
36 for(uInt32 i = 0, offset = 0xFFC, spot = 0xFF6; i < 4; ++i, offset += 0x1000)
37 {
38 uInt16 start = (cart.myImage[offset+1] << 8) | cart.myImage[offset];
39 start -= start % 0x1000;
40 info << "Bank " << i << " @ $" << Common::Base::HEX4 << start << " - "
41 << "$" << (start + 0xFFF) << " (hotspot = $F" << (spot+i) << ")\n";
42 }
43
44 int xpos = 2,
45 ypos = addBaseInformation(size, "Atari", info.str()) + myLineHeight;
46
47 VariantList items;
48 VarList::push_back(items, "0 ($FFF6)");
49 VarList::push_back(items, "1 ($FFF7)");
50 VarList::push_back(items, "2 ($FFF8)");
51 VarList::push_back(items, "3 ($FFF9)");
52 myBank =
53 new PopUpWidget(boss, _font, xpos, ypos-2, _font.getStringWidth("0 ($FFFx) "),
54 myLineHeight, items, "Set bank ",
55 0, kBankChanged);
56 myBank->setTarget(this);
57 addFocusWidget(myBank);
58}
59
60// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
61void CartridgeF6Widget::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(), state.bank != oldstate.bank);
69
70 CartDebugWidget::loadConfig();
71}
72
73// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
74void CartridgeF6Widget::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 CartridgeF6Widget::bankState()
88{
89 ostringstream& buf = buffer();
90
91 static const char* const spot[] = { "$FFF6", "$FFF7", "$FFF8", "$FFF9" };
92 buf << "Bank = " << std::dec << myCart.getBank()
93 << ", hotspot = " << spot[myCart.getBank()];
94
95 return buf.str();
96}
97