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 "Debugger.hxx"
19#include "CartDebug.hxx"
20#include "CartF4SC.hxx"
21#include "PopUpWidget.hxx"
22#include "CartF4SCWidget.hxx"
23
24// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
25CartridgeF4SCWidget::CartridgeF4SCWidget(
26 GuiObject* boss, const GUI::Font& lfont, const GUI::Font& nfont,
27 int x, int y, int w, int h, CartridgeF4SC& cart)
28 : CartDebugWidget(boss, lfont, nfont, x, y, w, h),
29 myCart(cart)
30{
31 uInt16 size = 8 * 4096;
32
33 ostringstream info;
34 info << "Standard F4SC cartridge, eight 4K banks\n"
35 << "128 bytes RAM @ $F000 - $F0FF\n"
36 << " $F080 - $F0FF (R), $F000 - $F07F (W)\n"
37 << "Startup bank = " << cart.startBank() << " or undetermined\n";
38
39 // Eventually, we should query this from the debugger/disassembler
40 for(uInt32 i = 0, offset = 0xFFC, spot = 0xFF4; i < 8; ++i, offset += 0x1000)
41 {
42 uInt16 start = (cart.myImage[offset+1] << 8) | cart.myImage[offset];
43 start -= start % 0x1000;
44 info << "Bank " << i << " @ $" << Common::Base::HEX4 << (start + 0x100) << " - "
45 << "$" << (start + 0xFFF) << " (hotspot = $F" << (spot+i) << ")\n";
46 }
47
48 int xpos = 2,
49 ypos = addBaseInformation(size, "Atari", info.str(), 15) + myLineHeight;
50
51 VariantList items;
52 VarList::push_back(items, "0 ($FFF4)");
53 VarList::push_back(items, "1 ($FFF5)");
54 VarList::push_back(items, "2 ($FFF6)");
55 VarList::push_back(items, "3 ($FFF7)");
56 VarList::push_back(items, "4 ($FFF8)");
57 VarList::push_back(items, "5 ($FFF9)");
58 VarList::push_back(items, "6 ($FFFA)");
59 VarList::push_back(items, "7 ($FFFB)");
60 myBank =
61 new PopUpWidget(boss, _font, xpos, ypos-2, _font.getStringWidth("0 ($FFFx)"),
62 myLineHeight, items, "Set bank ",
63 0, kBankChanged);
64 myBank->setTarget(this);
65 addFocusWidget(myBank);
66}
67
68// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
69void CartridgeF4SCWidget::saveOldState()
70{
71 myOldState.internalram.clear();
72
73 for(uInt32 i = 0; i < internalRamSize(); ++i)
74 myOldState.internalram.push_back(myCart.myRAM[i]);
75
76 myOldState.bank = myCart.getBank();
77}
78
79// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
80void CartridgeF4SCWidget::loadConfig()
81{
82 myBank->setSelectedIndex(myCart.getBank(), myCart.getBank() != myOldState.bank);
83
84 CartDebugWidget::loadConfig();
85}
86
87// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
88void CartridgeF4SCWidget::handleCommand(CommandSender* sender,
89 int cmd, int data, int id)
90{
91 if(cmd == kBankChanged)
92 {
93 myCart.unlockBank();
94 myCart.bank(myBank->getSelected());
95 myCart.lockBank();
96 invalidate();
97 }
98}
99
100// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
101string CartridgeF4SCWidget::bankState()
102{
103 ostringstream& buf = buffer();
104
105 static const char* const spot[] = {
106 "$FFF4", "$FFF5", "$FFF6", "$FFF7", "$FFF8", "$FFF9", "$FFFA", "$FFFB"
107 };
108 buf << "Bank = " << std::dec << myCart.getBank()
109 << ", hotspot = " << spot[myCart.getBank()];
110
111 return buf.str();
112}
113
114// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
115uInt32 CartridgeF4SCWidget::internalRamSize()
116{
117 return 128;
118}
119
120// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
121uInt32 CartridgeF4SCWidget::internalRamRPort(int start)
122{
123 return 0xF080 + start;
124}
125
126// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
127string CartridgeF4SCWidget::internalRamDescription()
128{
129 ostringstream desc;
130 desc << "$F000 - $F07F used for Write Access\n"
131 << "$F080 - $F0FF used for Read Access";
132
133 return desc.str();
134}
135
136// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
137const ByteArray& CartridgeF4SCWidget::internalRamOld(int start, int count)
138{
139 myRamOld.clear();
140 for(int i = 0; i < count; i++)
141 myRamOld.push_back(myOldState.internalram[start + i]);
142 return myRamOld;
143}
144
145// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
146const ByteArray& CartridgeF4SCWidget::internalRamCurrent(int start, int count)
147{
148 myRamCurrent.clear();
149 for(int i = 0; i < count; i++)
150 myRamCurrent.push_back(myCart.myRAM[start + i]);
151 return myRamCurrent;
152}
153
154// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
155void CartridgeF4SCWidget::internalRamSetValue(int addr, uInt8 value)
156{
157 myCart.myRAM[addr] = value;
158}
159
160// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
161uInt8 CartridgeF4SCWidget::internalRamGetValue(int addr)
162{
163 return myCart.myRAM[addr];
164}
165
166// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
167string CartridgeF4SCWidget::internalRamLabel(int addr)
168{
169 CartDebug& dbg = instance().debugger().cartDebug();
170 return dbg.getLabel(addr + 0xF080, false);
171}
172