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 "CartEFSC.hxx"
21#include "PopUpWidget.hxx"
22#include "CartEFSCWidget.hxx"
23
24// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
25CartridgeEFSCWidget::CartridgeEFSCWidget(
26 GuiObject* boss, const GUI::Font& lfont, const GUI::Font& nfont,
27 int x, int y, int w, int h, CartridgeEFSC& cart)
28 : CartDebugWidget(boss, lfont, nfont, x, y, w, h),
29 myCart(cart)
30{
31 uInt32 size = 16 * 4096;
32
33 ostringstream info;
34 info << "64K H. Runner EFSC + RAM, 16 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 = 0xFE0; i < 16; ++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, "Paul Slocum / Homestar Runner",
50 info.str()) + myLineHeight;
51
52 VariantList items;
53 VarList::push_back(items, " 0 ($FFE0)");
54 VarList::push_back(items, " 1 ($FFE1)");
55 VarList::push_back(items, " 2 ($FFE2)");
56 VarList::push_back(items, " 3 ($FFE3)");
57 VarList::push_back(items, " 4 ($FFE4)");
58 VarList::push_back(items, " 5 ($FFE5)");
59 VarList::push_back(items, " 6 ($FFE6)");
60 VarList::push_back(items, " 7 ($FFE7)");
61 VarList::push_back(items, " 8 ($FFE8)");
62 VarList::push_back(items, " 9 ($FFE9)");
63 VarList::push_back(items, "10 ($FFEA)");
64 VarList::push_back(items, "11 ($FFEB)");
65 VarList::push_back(items, "12 ($FFEC)");
66 VarList::push_back(items, "13 ($FFED)");
67 VarList::push_back(items, "14 ($FFEE)");
68 VarList::push_back(items, "15 ($FFEF)");
69 myBank =
70 new PopUpWidget(boss, _font, xpos, ypos-2, _font.getStringWidth("15 ($FFE0)"),
71 myLineHeight, items, "Set bank ",
72 0, kBankChanged);
73 myBank->setTarget(this);
74 addFocusWidget(myBank);
75}
76
77// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
78void CartridgeEFSCWidget::saveOldState()
79{
80 myOldState.internalram.clear();
81
82 for(uInt32 i = 0; i < internalRamSize(); ++i)
83 myOldState.internalram.push_back(myCart.myRAM[i]);
84
85 myOldState.bank = myCart.getBank();
86}
87
88// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
89void CartridgeEFSCWidget::loadConfig()
90{
91 myBank->setSelectedIndex(myCart.getBank(), myCart.getBank() != myOldState.bank);
92
93 CartDebugWidget::loadConfig();
94}
95
96// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
97void CartridgeEFSCWidget::handleCommand(CommandSender* sender,
98 int cmd, int data, int id)
99{
100 if(cmd == kBankChanged)
101 {
102 myCart.unlockBank();
103 myCart.bank(myBank->getSelected());
104 myCart.lockBank();
105 invalidate();
106 }
107}
108
109// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
110string CartridgeEFSCWidget::bankState()
111{
112 ostringstream& buf = buffer();
113
114 static const char* const spot[] = {
115 "$FFE0", "$FFE1", "$FFE2", "$FFE3", "$FFE4", "$FFE5", "$FFE6", "$FFE7",
116 "$FFE8", "$FFE9", "$FFEA", "$FFEB", "$FFEC", "$FFED", "$FFEE", "$FFEF"
117 };
118 buf << "Bank = " << std::dec << myCart.getBank()
119 << ", hotspot = " << spot[myCart.getBank()];
120
121 return buf.str();
122}
123
124// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
125uInt32 CartridgeEFSCWidget::internalRamSize()
126{
127 return 128;
128}
129
130// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
131uInt32 CartridgeEFSCWidget::internalRamRPort(int start)
132{
133 return 0xF080 + start;
134}
135
136// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
137string CartridgeEFSCWidget::internalRamDescription()
138{
139 ostringstream desc;
140 desc << "$F000 - $F07F used for Write Access\n"
141 << "$F080 - $F0FF used for Read Access";
142
143 return desc.str();
144}
145
146// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
147const ByteArray& CartridgeEFSCWidget::internalRamOld(int start, int count)
148{
149 myRamOld.clear();
150 for(int i = 0; i < count; i++)
151 myRamOld.push_back(myOldState.internalram[start + i]);
152 return myRamOld;
153}
154
155// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
156const ByteArray& CartridgeEFSCWidget::internalRamCurrent(int start, int count)
157{
158 myRamCurrent.clear();
159 for(int i = 0; i < count; i++)
160 myRamCurrent.push_back(myCart.myRAM[start + i]);
161 return myRamCurrent;
162}
163
164// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
165void CartridgeEFSCWidget::internalRamSetValue(int addr, uInt8 value)
166{
167 myCart.myRAM[addr] = value;
168}
169
170// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
171uInt8 CartridgeEFSCWidget::internalRamGetValue(int addr)
172{
173 return myCart.myRAM[addr];
174}
175
176// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
177string CartridgeEFSCWidget::internalRamLabel(int addr)
178{
179 CartDebug& dbg = instance().debugger().cartDebug();
180 return dbg.getLabel(addr + 0xF080, false);
181}
182