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 "CartBFSC.hxx"
21#include "PopUpWidget.hxx"
22#include "CartBFSCWidget.hxx"
23
24// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
25CartridgeBFSCWidget::CartridgeBFSCWidget(
26 GuiObject* boss, const GUI::Font& lfont, const GUI::Font& nfont,
27 int x, int y, int w, int h, CartridgeBFSC& cart)
28 : CartDebugWidget(boss, lfont, nfont, x, y, w, h),
29 myCart(cart)
30{
31 uInt32 size = 64 * 4096;
32
33 ostringstream info;
34 info << "256K BFSC + RAM, 64 4K banks\n"
35 << "128 bytes RAM @ $F000 - $F0FF\n"
36 << " $F080 - $F0FF (R), $F000 - $F07F (W)\n"
37 << "Startup bank = " << cart.startBank() << "\n";
38
39 // Eventually, we should query this from the debugger/disassembler
40 for(uInt32 i = 0, offset = 0xFFC, spot = 0xF80; i < 64; ++i, offset += 0x1000)
41 {
42 uInt16 start = (cart.myImage[offset+1] << 8) | cart.myImage[offset];
43 start -= start % 0x1000;
44 info << "Bank " << std::dec << i << " @ $" << Common::Base::HEX4 << (start + 0x100)
45 << " - " << "$" << (start + 0xFFF) << " (hotspot = $F" << (spot+i) << ")\n";
46 }
47
48 int xpos = 2,
49 ypos = addBaseInformation(size, "CPUWIZ", info.str()) + myLineHeight;
50
51 VariantList items;
52 VarList::push_back(items, " 0 ($FF80)");
53 VarList::push_back(items, " 1 ($FF81)");
54 VarList::push_back(items, " 2 ($FF82)");
55 VarList::push_back(items, " 3 ($FF83)");
56 VarList::push_back(items, " 4 ($FF84)");
57 VarList::push_back(items, " 5 ($FF85)");
58 VarList::push_back(items, " 6 ($FF86)");
59 VarList::push_back(items, " 7 ($FF87)");
60 VarList::push_back(items, " 8 ($FF88)");
61 VarList::push_back(items, " 9 ($FF89)");
62 VarList::push_back(items, "10 ($FF8A)");
63 VarList::push_back(items, "11 ($FF8B)");
64 VarList::push_back(items, "12 ($FF8C)");
65 VarList::push_back(items, "13 ($FF8D)");
66 VarList::push_back(items, "14 ($FF8E)");
67 VarList::push_back(items, "15 ($FF8F)");
68 VarList::push_back(items, "16 ($FF90)");
69 VarList::push_back(items, "17 ($FF91)");
70 VarList::push_back(items, "18 ($FF92)");
71 VarList::push_back(items, "19 ($FF93)");
72 VarList::push_back(items, "20 ($FF94)");
73 VarList::push_back(items, "21 ($FF95)");
74 VarList::push_back(items, "22 ($FF96)");
75 VarList::push_back(items, "23 ($FF97)");
76 VarList::push_back(items, "24 ($FF98)");
77 VarList::push_back(items, "25 ($FF99)");
78 VarList::push_back(items, "26 ($FF9A)");
79 VarList::push_back(items, "27 ($FF9B)");
80 VarList::push_back(items, "28 ($FF9C)");
81 VarList::push_back(items, "29 ($FF9D)");
82 VarList::push_back(items, "30 ($FF9E)");
83 VarList::push_back(items, "31 ($FF9F)");
84 VarList::push_back(items, "32 ($FFA0)");
85 VarList::push_back(items, "33 ($FFA1)");
86 VarList::push_back(items, "34 ($FFA2)");
87 VarList::push_back(items, "35 ($FFA3)");
88 VarList::push_back(items, "36 ($FFA4)");
89 VarList::push_back(items, "37 ($FFA5)");
90 VarList::push_back(items, "38 ($FFA6)");
91 VarList::push_back(items, "39 ($FFA7)");
92 VarList::push_back(items, "40 ($FFA8)");
93 VarList::push_back(items, "41 ($FFA9)");
94 VarList::push_back(items, "42 ($FFAA)");
95 VarList::push_back(items, "43 ($FFAB)");
96 VarList::push_back(items, "44 ($FFAC)");
97 VarList::push_back(items, "45 ($FFAD)");
98 VarList::push_back(items, "46 ($FFAE)");
99 VarList::push_back(items, "47 ($FFAF)");
100 VarList::push_back(items, "48 ($FFB0)");
101 VarList::push_back(items, "49 ($FFB1)");
102 VarList::push_back(items, "50 ($FFB2)");
103 VarList::push_back(items, "51 ($FFB3)");
104 VarList::push_back(items, "52 ($FFB4)");
105 VarList::push_back(items, "53 ($FFB5)");
106 VarList::push_back(items, "54 ($FFB6)");
107 VarList::push_back(items, "55 ($FFB7)");
108 VarList::push_back(items, "56 ($FFB8)");
109 VarList::push_back(items, "57 ($FFB9)");
110 VarList::push_back(items, "58 ($FFBA)");
111 VarList::push_back(items, "59 ($FFBB)");
112 VarList::push_back(items, "60 ($FFBC)");
113 VarList::push_back(items, "61 ($FFBD)");
114 VarList::push_back(items, "62 ($FFBE)");
115 VarList::push_back(items, "63 ($FFBF)");
116
117 myBank =
118 new PopUpWidget(boss, _font, xpos, ypos-2, _font.getStringWidth("63 ($FFBF)"),
119 myLineHeight, items, "Set bank ",
120 0, kBankChanged);
121 myBank->setTarget(this);
122 addFocusWidget(myBank);
123}
124
125// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
126void CartridgeBFSCWidget::saveOldState()
127{
128 myOldState.internalram.clear();
129
130 for(uInt32 i = 0; i < internalRamSize(); ++i)
131 myOldState.internalram.push_back(myCart.myRAM[i]);
132
133 myOldState.bank = myCart.getBank();
134}
135
136// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
137void CartridgeBFSCWidget::loadConfig()
138{
139 myBank->setSelectedIndex(myCart.getBank(), myCart.getBank() != myOldState.bank);
140
141 CartDebugWidget::loadConfig();
142}
143
144// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
145void CartridgeBFSCWidget::handleCommand(CommandSender* sender,
146 int cmd, int data, int id)
147{
148 if(cmd == kBankChanged)
149 {
150 myCart.unlockBank();
151 myCart.bank(myBank->getSelected());
152 myCart.lockBank();
153 invalidate();
154 }
155}
156
157// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
158string CartridgeBFSCWidget::bankState()
159{
160 ostringstream& buf = buffer();
161
162 static const char* const spot[] = {
163 "$FF80", "$FF81", "$FF82", "$FF83", "$FF84", "$FF85", "$FF86", "$FF87",
164 "$FF88", "$FF89", "$FF8A", "$FF8B", "$FF8C", "$FF8D", "$FF8E", "$FF8F",
165 "$FF90", "$FF91", "$FF92", "$FF93", "$FF94", "$FF95", "$FF96", "$FF97",
166 "$FF98", "$FF99", "$FF9A", "$FF9B", "$FF9C", "$FF9D", "$FF9E", "$FF9F",
167 "$FFA0", "$FFA1", "$FFA2", "$FFA3", "$FFA4", "$FFA5", "$FFA6", "$FFA7",
168 "$FFA8", "$FFA9", "$FFAA", "$FFAB", "$FFAC", "$FFAD", "$FFAE", "$FFAF",
169 "$FFB0", "$FFB1", "$FFB2", "$FFB3", "$FFB4", "$FFB5", "$FFB6", "$FFB7",
170 "$FFB8", "$FFB9", "$FFBA", "$FFBB", "$FFBC", "$FFBD", "$FFBE", "$FFBF"
171 };
172 buf << "Bank = " << std::dec << myCart.getBank()
173 << ", hotspot = " << spot[myCart.getBank()];
174
175 return buf.str();
176}
177
178// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
179uInt32 CartridgeBFSCWidget::internalRamSize()
180{
181 return 128;
182}
183
184// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
185uInt32 CartridgeBFSCWidget::internalRamRPort(int start)
186{
187 return 0xF080 + start;
188}
189
190// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
191string CartridgeBFSCWidget::internalRamDescription()
192{
193 ostringstream desc;
194 desc << "$F000 - $F07F used for Write Access\n"
195 << "$F080 - $F0FF used for Read Access";
196
197 return desc.str();
198}
199
200// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
201const ByteArray& CartridgeBFSCWidget::internalRamOld(int start, int count)
202{
203 myRamOld.clear();
204 for(int i = 0; i < count; i++)
205 myRamOld.push_back(myOldState.internalram[start + i]);
206 return myRamOld;
207}
208
209// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
210const ByteArray& CartridgeBFSCWidget::internalRamCurrent(int start, int count)
211{
212 myRamCurrent.clear();
213 for(int i = 0; i < count; i++)
214 myRamCurrent.push_back(myCart.myRAM[start + i]);
215 return myRamCurrent;
216}
217
218// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
219void CartridgeBFSCWidget::internalRamSetValue(int addr, uInt8 value)
220{
221 myCart.myRAM[addr] = value;
222}
223
224// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
225uInt8 CartridgeBFSCWidget::internalRamGetValue(int addr)
226{
227 return myCart.myRAM[addr];
228}
229
230// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
231string CartridgeBFSCWidget::internalRamLabel(int addr)
232{
233 CartDebug& dbg = instance().debugger().cartDebug();
234 return dbg.getLabel(addr + 0xF080, false);
235}
236