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 "CartFA2.hxx"
21#include "PopUpWidget.hxx"
22#include "CartFA2Widget.hxx"
23
24// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
25CartridgeFA2Widget::CartridgeFA2Widget(
26 GuiObject* boss, const GUI::Font& lfont, const GUI::Font& nfont,
27 int x, int y, int w, int h, CartridgeFA2& cart)
28 : CartDebugWidget(boss, lfont, nfont, x, y, w, h),
29 myCart(cart)
30{
31 size_t size = cart.mySize;
32
33 ostringstream info;
34 info << "Modified FA RAM+, six or seven 4K banks\n"
35 << "256 bytes RAM @ $F000 - $F1FF\n"
36 << " $F100 - $F1FF (R), $F000 - $F0FF (W)\n"
37 << "RAM can be loaded/saved to Harmony flash by accessing $FFF4\n"
38 << "Startup bank = " << cart.startBank() << " or undetermined\n";
39
40 // Eventually, we should query this from the debugger/disassembler
41 for(uInt32 i = 0, offset = 0xFFC, spot = 0xFF5; i < cart.bankCount();
42 ++i, offset += 0x1000)
43 {
44 uInt16 start = (cart.myImage[offset+1] << 8) | cart.myImage[offset];
45 start -= start % 0x1000;
46 info << "Bank " << i << " @ $" << Common::Base::HEX4 << (start + 0x200) << " - "
47 << "$" << (start + 0xFFF) << " (hotspot = $F" << (spot+i) << ")\n";
48 }
49
50 int xpos = 2,
51 ypos = addBaseInformation(size, "Chris D. Walton (Star Castle 2600)",
52 info.str(), 15) + myLineHeight;
53
54 VariantList items;
55 VarList::push_back(items, "0 ($FFF5)");
56 VarList::push_back(items, "1 ($FFF6)");
57 VarList::push_back(items, "2 ($FFF7)");
58 VarList::push_back(items, "3 ($FFF8)");
59 VarList::push_back(items, "4 ($FFF9)");
60 VarList::push_back(items, "5 ($FFFA)");
61 if(cart.bankCount() == 7)
62 VarList::push_back(items, "6 ($FFFB)");
63
64 myBank =
65 new PopUpWidget(boss, _font, xpos, ypos-2, _font.getStringWidth("0 ($FFFx)"),
66 myLineHeight, items, "Set bank ",
67 0, kBankChanged);
68 myBank->setTarget(this);
69 addFocusWidget(myBank);
70 ypos += myLineHeight + 20;
71
72 const int bwidth = _font.getStringWidth("Erase") + 20;
73
74 StaticTextWidget* t = new StaticTextWidget(boss, _font, xpos, ypos,
75 _font.getStringWidth("Harmony Flash "),
76 myFontHeight, "Harmony Flash ", TextAlign::Left);
77
78 xpos += t->getWidth() + 4;
79 myFlashErase =
80 new ButtonWidget(boss, _font, xpos, ypos-4, bwidth, myButtonHeight,
81 "Erase", kFlashErase);
82 myFlashErase->setTarget(this);
83 addFocusWidget(myFlashErase);
84 xpos += myFlashErase->getWidth() + 8;
85
86 myFlashLoad =
87 new ButtonWidget(boss, _font, xpos, ypos-4, bwidth, myButtonHeight,
88 "Load", kFlashLoad);
89 myFlashLoad->setTarget(this);
90 addFocusWidget(myFlashLoad);
91 xpos += myFlashLoad->getWidth() + 8;
92
93 myFlashSave =
94 new ButtonWidget(boss, _font, xpos, ypos-4, bwidth, myButtonHeight,
95 "Save", kFlashSave);
96 myFlashSave->setTarget(this);
97 addFocusWidget(myFlashSave);
98}
99
100// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
101void CartridgeFA2Widget::saveOldState()
102{
103 myOldState.internalram.clear();
104
105 for(uInt32 i = 0; i < internalRamSize(); ++i)
106 myOldState.internalram.push_back(myCart.myRAM[i]);
107
108 myOldState.bank = myCart.getBank();
109}
110
111// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
112void CartridgeFA2Widget::loadConfig()
113{
114 myBank->setSelectedIndex(myCart.getBank(), myCart.getBank() != myOldState.bank);
115
116 CartDebugWidget::loadConfig();
117}
118
119// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
120void CartridgeFA2Widget::handleCommand(CommandSender* sender,
121 int cmd, int data, int id)
122{
123 switch(cmd)
124 {
125 case kBankChanged:
126 myCart.unlockBank();
127 myCart.bank(myBank->getSelected());
128 myCart.lockBank();
129 invalidate();
130 break;
131
132 case kFlashErase:
133 myCart.flash(0);
134 break;
135
136 case kFlashLoad:
137 myCart.flash(1);
138 break;
139
140 case kFlashSave:
141 myCart.flash(2);
142 break;
143 }
144}
145
146// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
147string CartridgeFA2Widget::bankState()
148{
149 ostringstream& buf = buffer();
150
151 static const char* const spot[] = {
152 "$FFF5", "$FFF6", "$FFF7", "$FFF8", "$FFF9", "$FFFA", "$FFFB"
153 };
154 buf << "Bank = " << std::dec << myCart.getBank()
155 << ", hotspot = " << spot[myCart.getBank()];
156
157 return buf.str();
158}
159
160// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
161uInt32 CartridgeFA2Widget::internalRamSize()
162{
163 return 256;
164}
165
166// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
167uInt32 CartridgeFA2Widget::internalRamRPort(int start)
168{
169 return 0xF100 + start;
170}
171
172// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
173string CartridgeFA2Widget::internalRamDescription()
174{
175 ostringstream desc;
176 desc << "$F000 - $F0FF used for Write Access\n"
177 << "$F100 - $F1FF used for Read Access";
178
179 return desc.str();
180}
181
182// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
183const ByteArray& CartridgeFA2Widget::internalRamOld(int start, int count)
184{
185 myRamOld.clear();
186 for(int i = 0; i < count; i++)
187 myRamOld.push_back(myOldState.internalram[start + i]);
188 return myRamOld;
189}
190
191// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
192const ByteArray& CartridgeFA2Widget::internalRamCurrent(int start, int count)
193{
194 myRamCurrent.clear();
195 for(int i = 0; i < count; i++)
196 myRamCurrent.push_back(myCart.myRAM[start + i]);
197 return myRamCurrent;
198}
199
200// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
201void CartridgeFA2Widget::internalRamSetValue(int addr, uInt8 value)
202{
203 myCart.myRAM[addr] = value;
204}
205
206// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
207uInt8 CartridgeFA2Widget::internalRamGetValue(int addr)
208{
209 return myCart.myRAM[addr];
210}
211
212// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
213string CartridgeFA2Widget::internalRamLabel(int addr)
214{
215 CartDebug& dbg = instance().debugger().cartDebug();
216 return dbg.getLabel(addr + 0xF100, false);
217}
218