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 "CartF8.hxx"
19#include "PopUpWidget.hxx"
20#include "CartF8Widget.hxx"
21
22// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
23CartridgeF8Widget::CartridgeF8Widget(
24 GuiObject* boss, const GUI::Font& lfont, const GUI::Font& nfont,
25 int x, int y, int w, int h, CartridgeF8& cart)
26 : CartDebugWidget(boss, lfont, nfont, x, y, w, h),
27 myCart(cart)
28{
29 uInt16 size = 2 * 4096;
30
31 ostringstream info;
32 info << "Standard F8 cartridge, two 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 = 0xFF8; i < 2; ++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 ($FFF8)");
49 VarList::push_back(items, "1 ($FFF9)");
50 myBank =
51 new PopUpWidget(boss, _font, xpos, ypos-2, _font.getStringWidth("0 ($FFFx)"),
52 myLineHeight, items, "Set bank ",
53 0, kBankChanged);
54 myBank->setTarget(this);
55 addFocusWidget(myBank);
56}
57
58// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
59void CartridgeF8Widget::loadConfig()
60{
61 Debugger& dbg = instance().debugger();
62 CartDebug& cart = dbg.cartDebug();
63 const CartState& state = static_cast<const CartState&>(cart.getState());
64 const CartState& oldstate = static_cast<const CartState&>(cart.getOldState());
65
66 myBank->setSelectedIndex(myCart.getBank(), state.bank != oldstate.bank);
67
68 CartDebugWidget::loadConfig();
69}
70
71// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
72void CartridgeF8Widget::handleCommand(CommandSender* sender,
73 int cmd, int data, int id)
74{
75 if(cmd == kBankChanged)
76 {
77 myCart.unlockBank();
78 myCart.bank(myBank->getSelected());
79 myCart.lockBank();
80 invalidate();
81 }
82}
83
84// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
85string CartridgeF8Widget::bankState()
86{
87 ostringstream& buf = buffer();
88
89 static const char* const spot[] = { "$FFF8", "$FFF9" };
90 buf << "Bank = " << std::dec << myCart.getBank()
91 << ", hotspot = " << spot[myCart.getBank()];
92
93 return buf.str();
94}
95