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 "CartF8SC.hxx"
21#include "PopUpWidget.hxx"
22#include "CartF8SCWidget.hxx"
23
24// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
25CartridgeF8SCWidget::CartridgeF8SCWidget(
26 GuiObject* boss, const GUI::Font& lfont, const GUI::Font& nfont,
27 int x, int y, int w, int h, CartridgeF8SC& cart)
28 : CartDebugWidget(boss, lfont, nfont, x, y, w, h),
29 myCart(cart)
30{
31 uInt16 size = 8192;
32
33 ostringstream info;
34 info << "Standard F8SC cartridge, two 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 = 0xFF8; i < 2; ++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()) + myLineHeight;
50
51 VariantList items;
52 VarList::push_back(items, "0 ($FFF8)");
53 VarList::push_back(items, "1 ($FFF9)");
54 myBank =
55 new PopUpWidget(boss, _font, xpos, ypos-2, _font.getStringWidth("0 ($FFFx)"),
56 myLineHeight, items, "Set bank ",
57 0, kBankChanged);
58 myBank->setTarget(this);
59 addFocusWidget(myBank);
60}
61
62// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
63void CartridgeF8SCWidget::saveOldState()
64{
65 myOldState.internalram.clear();
66
67 for(uInt32 i = 0; i < internalRamSize(); ++i)
68 myOldState.internalram.push_back(myCart.myRAM[i]);
69
70 myOldState.bank = myCart.getBank();
71}
72
73// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
74void CartridgeF8SCWidget::loadConfig()
75{
76 myBank->setSelectedIndex(myCart.getBank(), myCart.getBank() != myOldState.bank);
77
78 CartDebugWidget::loadConfig();
79}
80
81// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
82void CartridgeF8SCWidget::handleCommand(CommandSender* sender,
83 int cmd, int data, int id)
84{
85 if(cmd == kBankChanged)
86 {
87 myCart.unlockBank();
88 myCart.bank(myBank->getSelected());
89 myCart.lockBank();
90 invalidate();
91 }
92}
93
94// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
95string CartridgeF8SCWidget::bankState()
96{
97 ostringstream& buf = buffer();
98
99 static const char* const spot[] = { "$FFF8", "$FFF9" };
100 buf << "Bank = " << std::dec << myCart.getBank()
101 << ", hotspot = " << spot[myCart.getBank()];
102
103 return buf.str();
104}
105
106// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
107uInt32 CartridgeF8SCWidget::internalRamSize()
108{
109 return 128;
110}
111
112// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
113uInt32 CartridgeF8SCWidget::internalRamRPort(int start)
114{
115 return 0xF080 + start;
116}
117
118// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
119string CartridgeF8SCWidget::internalRamDescription()
120{
121 ostringstream desc;
122 desc << "$F000 - $F07F used for Write Access\n"
123 << "$F080 - $F0FF used for Read Access";
124
125 return desc.str();
126}
127
128// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
129const ByteArray& CartridgeF8SCWidget::internalRamOld(int start, int count)
130{
131 myRamOld.clear();
132 for(int i = 0; i < count; i++)
133 myRamOld.push_back(myOldState.internalram[start + i]);
134 return myRamOld;
135}
136
137// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
138const ByteArray& CartridgeF8SCWidget::internalRamCurrent(int start, int count)
139{
140 myRamCurrent.clear();
141 for(int i = 0; i < count; i++)
142 myRamCurrent.push_back(myCart.myRAM[start + i]);
143 return myRamCurrent;
144}
145
146// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
147void CartridgeF8SCWidget::internalRamSetValue(int addr, uInt8 value)
148{
149 myCart.myRAM[addr] = value;
150}
151
152// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
153uInt8 CartridgeF8SCWidget::internalRamGetValue(int addr)
154{
155 return myCart.myRAM[addr];
156}
157
158// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
159string CartridgeF8SCWidget::internalRamLabel(int addr)
160{
161 CartDebug& dbg = instance().debugger().cartDebug();
162 return dbg.getLabel(addr + 0xF080, false);
163}
164