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 "EditTextWidget.hxx"
19#include "GuiObject.hxx"
20#include "OSystem.hxx"
21#include "CartDebug.hxx"
22#include "StringParser.hxx"
23#include "Widget.hxx"
24#include "Font.hxx"
25#include "StringListWidget.hxx"
26#include "ScrollBarWidget.hxx"
27#include "CartDebugWidget.hxx"
28#include "CartRamWidget.hxx"
29
30// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
31CartRamWidget::CartRamWidget(
32 GuiObject* boss, const GUI::Font& lfont, const GUI::Font& nfont,
33 int x, int y, int w, int h, CartDebugWidget& cartDebug)
34 : Widget(boss, lfont, x, y, w, h),
35 CommandSender(boss),
36 _nfont(nfont),
37 myFontWidth(lfont.getMaxCharWidth()),
38 myFontHeight(lfont.getFontHeight()),
39 myLineHeight(lfont.getLineHeight()),
40 myButtonHeight(myLineHeight + 4)
41{
42 int lwidth = lfont.getStringWidth("Description "),
43 fwidth = w - lwidth - 20;
44
45 EditTextWidget* etw = nullptr;
46 ostringstream buf;
47 int xpos = 2, ypos = 8;
48
49 // Add RAM size
50 new StaticTextWidget(_boss, _font, xpos, ypos + 1, "RAM Size ");
51
52 uInt32 ramsize = cartDebug.internalRamSize();
53 buf << ramsize << " bytes";
54 if(ramsize >= 1024)
55 buf << " / " << (ramsize/1024) << "KB";
56
57 etw = new EditTextWidget(boss, nfont, xpos+lwidth, ypos - 1,
58 fwidth, myLineHeight, buf.str());
59 etw->setEditable(false);
60 ypos += myLineHeight + 4;
61
62 // Add Description
63 const string& desc = cartDebug.internalRamDescription();
64 const uInt16 maxlines = 6;
65 StringParser bs(desc, (fwidth - kScrollBarWidth) / myFontWidth);
66 const StringList& sl = bs.stringList();
67 uInt32 lines = uInt32(sl.size());
68 if(lines < 3) lines = 3;
69 if(lines > maxlines) lines = maxlines;
70
71 new StaticTextWidget(_boss, _font, xpos, ypos + 1, "Description ");
72 myDesc = new StringListWidget(boss, nfont, xpos+lwidth, ypos - 1,
73 fwidth, lines * myLineHeight, false);
74 myDesc->setEditable(false);
75 myDesc->setList(sl);
76 addFocusWidget(myDesc);
77
78 ypos += myDesc->getHeight() + myFontHeight / 2;
79
80 // Add RAM widget
81 myRam = new InternalRamWidget(boss, lfont, nfont, 2, ypos, w, h-ypos, cartDebug);
82 addToFocusList(myRam->getFocusList());
83}
84
85// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
86void CartRamWidget::loadConfig()
87{
88 myRam->loadConfig();
89}
90
91// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
92void CartRamWidget::setOpsWidget(DataGridOpsWidget* w)
93{
94 myRam->setOpsWidget(w);
95}
96
97// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
98void CartRamWidget::handleCommand(CommandSender* sender, int cmd, int data, int id)
99{
100 myRam->handleCommand(sender, cmd, data, id);
101}
102
103///////////////////////////////////
104// Internal RAM implementation
105///////////////////////////////////
106
107// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
108CartRamWidget::InternalRamWidget::InternalRamWidget(GuiObject* boss,
109 const GUI::Font& lfont, const GUI::Font& nfont,
110 int x, int y, int w, int h,
111 CartDebugWidget& dbg)
112 : RamWidget(boss, lfont, nfont, x, y, w, h,
113 dbg.internalRamSize(), std::min(dbg.internalRamSize() / 16, 16u),
114 std::min(dbg.internalRamSize() / 16, 16u) * 16),
115 myCart(dbg)
116{
117}
118
119// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
120CartRamWidget::InternalRamWidget::~InternalRamWidget()
121{
122}
123
124// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
125uInt8 CartRamWidget::InternalRamWidget::getValue(int addr) const
126{
127 return myCart.internalRamGetValue(addr);
128}
129
130// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
131void CartRamWidget::InternalRamWidget::setValue(int addr, uInt8 value)
132{
133 myCart.internalRamSetValue(addr, value);
134}
135
136// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
137string CartRamWidget::InternalRamWidget::getLabel(int addr) const
138{
139 return myCart.internalRamLabel(addr);
140}
141
142// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
143void CartRamWidget::InternalRamWidget::fillList(uInt32 start, uInt32 size,
144 IntArray& alist, IntArray& vlist, BoolArray& changed) const
145{
146 const ByteArray& oldRam = myCart.internalRamOld(start, size);
147 const ByteArray& currRam = myCart.internalRamCurrent(start, size);
148
149 for(uInt32 i = 0; i < size; ++i)
150 {
151 alist.push_back(i+start);
152 vlist.push_back(currRam[i]);
153 changed.push_back(currRam[i] != oldRam[i]);
154 }
155}
156
157// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
158uInt32 CartRamWidget::InternalRamWidget::readPort(uInt32 start) const
159{
160 return myCart.internalRamRPort(start);
161}
162
163// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
164const ByteArray& CartRamWidget::InternalRamWidget::currentRam(uInt32 start) const
165{
166 return myCart.internalRamCurrent(start, myCart.internalRamSize());
167}
168