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 "CartFC.hxx"
19#include "PopUpWidget.hxx"
20#include "CartFCWidget.hxx"
21
22// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
23CartridgeFCWidget::CartridgeFCWidget(
24 GuiObject* boss, const GUI::Font& lfont, const GUI::Font& nfont,
25 int x, int y, int w, int h, CartridgeFC& cart)
26 : CartDebugWidget(boss, lfont, nfont, x, y, w, h),
27 myCart(cart)
28{
29 uInt16 size = cart.bankCount() * 4096;
30
31 ostringstream info;
32 info << "FC cartridge, up to eight 4K banks\n"
33 << "Startup bank = " << cart.startBank() << " or undetermined\n";
34
35 // Eventually, we should query this from the debugger/disassembler
36 info << "Bank selected by hotspots\n"
37 << " $FFF8 (defines low 2 bits)\n"
38 << " $FFF9 (defines high bits)\n"
39 << " $FFFC (triggers bank switch)";
40
41 int xpos = 2,
42 ypos = addBaseInformation(size, "Amiga Corp.", info.str()) + myLineHeight;
43
44 VariantList items;
45 for (uInt16 i = 0; i < cart.bankCount(); ++i)
46 VarList::push_back(items, Variant(i).toString() +
47 " ($FFF8 = " + Variant(i & 0b11).toString() +
48 "/$FFF9 = " + Variant(i >> 2).toString() +")");
49
50
51 myBank =
52 new PopUpWidget(boss, _font, xpos, ypos - 2, _font.getStringWidth("7 ($FFF8 = 3/$FFF9 = 1)"),
53 myLineHeight, items, "Set bank ",
54 0, kBankChanged);
55 myBank->setTarget(this);
56 addFocusWidget(myBank);
57}
58
59// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
60void CartridgeFCWidget::loadConfig()
61{
62 Debugger& dbg = instance().debugger();
63 CartDebug& cart = dbg.cartDebug();
64 const CartState& state = static_cast<const CartState&>(cart.getState());
65 const CartState& oldstate = static_cast<const CartState&>(cart.getOldState());
66
67 myBank->setSelectedIndex(myCart.getBank(), state.bank != oldstate.bank);
68
69 CartDebugWidget::loadConfig();
70}
71
72// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
73void CartridgeFCWidget::handleCommand(CommandSender* sender,
74 int cmd, int data, int id)
75{
76 if (cmd == kBankChanged)
77 {
78 myCart.unlockBank();
79 myCart.bank(myBank->getSelected());
80 myCart.lockBank();
81 invalidate();
82 }
83}
84
85// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
86string CartridgeFCWidget::bankState()
87{
88 ostringstream& buf = buffer();
89 uInt16 bank = myCart.getBank();
90
91 buf << "Bank = #" << std::dec << bank
92 << ", hotspots $FFF8 = " << (bank & 0b11)
93 << "/$FF99 = " << (bank >> 2);
94
95 return buf.str();
96}
97