Debian Codegraph @

src/BitMapViewer.cpp

raw symbols SCIP
1 #include "BitMapViewer.h"
2 #include "PaletteDialog.h"
3 #include "VramBitMappedView.h"
4 #include "VDPDataStore.h"
5 #include "Convert.h"
6 #include <QMessageBox>
7
8
9 static uint8_t currentPalette[32] = { 0 };
10
11 BitMapViewer::BitMapViewer(QWidget* parent)
12 : QDialog(parent)
13 , pageSize(0) // avoid UMR
14 , screenMod(0)
15 {
16 setupUi(this);
17 //no connect slot byname anymore
18 connect(screenMode, qOverload<int>(&QComboBox::currentIndexChanged), this, &BitMapViewer::on_screenMode_currentIndexChanged);
19 connect(currentPage, qOverload<int>(&QComboBox:: currentIndexChanged), this, &BitMapViewer::on_currentPage_currentIndexChanged);
20 connect(linesVisible, qOverload<int>(&QComboBox:: currentIndexChanged), this, &BitMapViewer::on_linesVisible_currentIndexChanged);
21 connect(bgColor, qOverload<int>(&QSpinBox::valueChanged), this, &BitMapViewer::on_bgColor_valueChanged);
22
23 connect(useVDPRegisters, &QCheckBox::stateChanged,this, &BitMapViewer::on_useVDPRegisters_stateChanged);
24
25 connect(saveImageButton, &QPushButton::clicked, this, &BitMapViewer::on_saveImageButton_clicked);
26 connect(editPaletteButton, &QPushButton::clicked, this, &BitMapViewer::on_editPaletteButton_clicked);
27 connect(useVDPPalette, &QCheckBox::stateChanged, this, &BitMapViewer::on_useVDPPalette_stateChanged);
28 connect(zoomLevel, qOverload<double>(&QDoubleSpinBox::valueChanged), this, &BitMapViewer::on_zoomLevel_valueChanged);
29
30 // hand code entering the actual display widget in the scrollarea With
31 // the designer-qt4 there is an extra scrollAreaWidget between the
32 // imageWidget and the QScrollArea so the scrollbars are not correctly
33 // handled when the image is resized. (since the intermediate widget
34 // stays the same size). I did not try to have this intermediate widget
35 // resize and all, since it was superflous anyway.
36 imageWidget = new VramBitMappedView();
37 QSizePolicy sizePolicy1(QSizePolicy::Fixed, QSizePolicy::Fixed);
38 sizePolicy1.setHorizontalStretch(0);
39 sizePolicy1.setVerticalStretch(0);
40 sizePolicy1.setHeightForWidth(imageWidget->sizePolicy().hasHeightForWidth());
41 imageWidget->setSizePolicy(sizePolicy1);
42 imageWidget->setMinimumSize(QSize(256, 212));
43
44 scrollArea->setWidget(imageWidget);
45
46 useVDP = useVDPRegisters->isChecked();
47
48 const unsigned char* vram = VDPDataStore::instance().getVramPointer();
49 imageWidget->setVramSource(vram);
50 imageWidget->setVramAddress(0);
51 // Palette data not received from VDPDataStore yet causing black image, so
52 // we start by using fixed palette until VDPDataStoreDataRefreshed kicks in.
53 imageWidget->setPaletteSource(VDPDataStore::instance().getDefaultPalettePointer());
54
55 // now hook up some signals and slots
56 connect(&VDPDataStore::instance(), &VDPDataStore::dataRefreshed,
57 this, &BitMapViewer::VDPDataStoreDataRefreshed);
58 connect(&VDPDataStore::instance(), &VDPDataStore::dataRefreshed,
59 imageWidget, &VramBitMappedView::refresh);
60 connect(refreshButton, &QPushButton::clicked,
61 &VDPDataStore::instance(), &VDPDataStore::refresh);
62
63 connect(imageWidget, &VramBitMappedView::imageHovered,
64 this, &BitMapViewer::updateImagePosition);
65 connect(imageWidget, &VramBitMappedView::imageClicked,
66 this, &BitMapViewer::updateImagePosition);
67
68 // and now go fetch the initial data
69 VDPDataStore::instance().refresh();
70 }
71
72 void BitMapViewer::updateDisplayAsFrame()
73 {
74 screenMod = screenMode->itemText(screenMode->currentIndex()).toInt();
75 pageSize = screenMod >= 7 ? 65536 : 32768;
76 }
77
78 void BitMapViewer::decodeVDPregs()
79 {
80 const unsigned char* regs = VDPDataStore::instance().getRegsPointer();
81
82 // Get the number of lines
83 int v1 = (regs[9] & 128) ? 212 : 192;
84 printf("\nlines acording to the bits %i,: %i\n", (regs[9] & 128), v1);
85 linesLabel->setText(QString("%1").arg(v1, 0, 10));
86 if (useVDP) linesVisible->setCurrentIndex((regs[9] & 128) ? 1 : 0);
87
88 // Get the border color
89 int v2 = regs[7] & 15;
90 printf("\nborder acording to the regs %i,: %i\n", regs[7], v2);
91 if (regs[8] & 32) v2 = 0;
92 printf("\ncolor 0 is pallet regs %i,: %i\n", (regs[8] & 32), v2);
93 borderLabel->setText(QString("%1").arg(v2, 0, 10));
94 if (useVDP) bgColor->setValue(v2);
95
96 // Get current screenmode
97 static const int bits_modetxt[128] = {
98 1, 3, 0, 255, 2, 255, 255, 255,
99 4, 255, 80, 255, 5, 255, 255, 255,
100 6, 255, 255, 255, 7, 255, 255, 255,
101 255, 255, 255, 255, 8, 255, 255, 255,
102
103 255, 255, 255, 255,255, 255, 255, 255,
104 255, 255, 255, 255,255, 255, 255, 255,
105 255, 255, 255, 255,255, 255, 255, 255,
106 255, 255, 255, 255, 12, 255, 255, 255,
107
108 255, 255, 255, 255,255, 255, 255, 255,
109 255, 255, 255, 255,255, 255, 255, 255,
110 255, 255, 255, 255,255, 255, 255, 255,
111 255, 255, 255, 255,255, 255, 255, 255,
112
113 255, 255, 255, 255,255, 255, 255, 255,
114 255, 255, 255, 255,255, 255, 255, 255,
115 255, 255, 255, 255,255, 255, 255, 255,
116 255, 255, 255, 255, 11, 255, 255, 255,
117 };
118 static const int bits_mode[128] = {
119 0, 0, 0, 0, 0, 0, 0, 0,
120 0, 0, 0, 0, 0, 0, 0, 0,
121 1, 0, 0, 0, 2, 0, 0, 0,
122 0, 0, 0, 0, 3, 0, 0, 0,
123
124 0, 0, 0, 0, 0, 0, 0, 0,
125 0, 0, 0, 0, 0, 0, 0, 0,
126 0, 0, 0, 0, 0, 0, 0, 0,
127 0, 0, 0, 0, 6, 0, 0, 0,
128
129 0, 0, 0, 0, 0, 0, 0, 0,
130 0, 0, 0, 0, 0, 0, 0, 0,
131 0, 0, 0, 0, 0, 0, 0, 0,
132 0, 0, 0, 0, 0, 0, 0, 0,
133
134 0, 0, 0, 0, 0, 0, 0, 0,
135 0, 0, 0, 0, 0, 0, 0, 0,
136 0, 0, 0, 0, 0, 0, 0, 0,
137 0, 0, 0, 0, 5, 0, 0, 0,
138 };
139 int v3 = ((regs[0] & 0x0E) << 1) | ((regs[1] & 0x18) >> 3) | ((regs[25] & 0x18) << 2);
140 printf("screenMod according to the bits: %i\n", v3);
141 modeLabel->setText(QString("%1").arg(bits_modetxt[v3], 0, 10));
142
143 if (useVDP) {
144 screenMode->setCurrentIndex(bits_mode[v3]);
145 updateDisplayAsFrame();
146 }
147 if (useVDPPalette) {
148 imageWidget->setPaletteSource(VDPDataStore::instance().getPalettePointer());
149 }
150
151 // Get the current visible page
152 unsigned p = (regs[2] >> 5) & 3;
153 unsigned q = 1 << 15;
154 if (bits_modetxt[v3] > 6) {
155 p &= 1;
156 q <<= 1;
157 }
158 printf("visible page according to the bits: %i\n",p);
159
160 setPages();
161
162 addressLabel->setText(hexValue(p * q, 5));
163 if (useVDP) currentPage->setCurrentIndex(p);
164 }
165
166 void BitMapViewer::refresh()
167 {
168 // All of the code is in the VDPDataStore;
169 VDPDataStore::instance().refresh();
170 }
171
172 void BitMapViewer::on_screenMode_currentIndexChanged(int /*index*/)
173 {
174 updateDisplayAsFrame();
175
176 // change the number of visible pages when this changes
177 imageWidget->setVramAddress(0);
178
179 // make sure that we are decoding new mode from page 0, imagine viewing
180 // page 3 of screen5 and then switching to screen 8 without changing the
181 // starting vram address....
182 imageWidget->setScreenMode(screenMod);
183 setPages();
184 }
185
186 void BitMapViewer::setPages()
187 {
188 if (pageSize == 0) return;
189 static const QStringList pageNames = {"0", "1", "2", "3", "E0", "E1"};
190 int oldIndex = currentPage->currentIndex();
191
192 currentPage->clear();
193 int pageCount = VDPDataStore::instance().getVRAMSize() / pageSize;
194 int pages = std::min(pageCount, pageNames.count());
195
196 for (int p = 0; p < pages; ++p) {
197 currentPage->insertItem(p, pageNames[p]);
198 }
199
200 if (!useVDP && oldIndex < currentPage->count()) {
201 currentPage->setCurrentIndex(oldIndex);
202 }
203 }
204
205 void BitMapViewer::on_currentPage_currentIndexChanged(int index)
206 {
207 // if this is the consequence of a .clear() in the
208 // on_screenMode_currentIndexChanged we do nothing!
209 if (index == -1) return;
210
211 int vramAddress = pageSize * index;
212 imageWidget->setVramAddress(vramAddress);
213 addressLabel->setText(hexValue(vramAddress, 5));
214 }
215
216 void BitMapViewer::on_linesVisible_currentIndexChanged(int index)
217 {
218 static const int m[3] = { 192, 212, 256 };
219 int lines = m[index];
220 imageWidget->setLines(lines);
221 linesLabel->setText(QString("%1").arg(m[index]));
222 }
223
224 void BitMapViewer::on_bgColor_valueChanged(int value)
225 {
226 imageWidget->setBorderColor(value);
227 }
228
229 void BitMapViewer::on_useVDPRegisters_stateChanged(int state)
230 {
231 useVDP = state;
232
233 screenMode->setEnabled(!state);
234 linesVisible->setEnabled(!state);
235 currentPage->setEnabled(!state);
236 bgColor->setEnabled(!state);
237 decodeVDPregs();
238 imageWidget->refresh();
239 }
240
241 void BitMapViewer::on_zoomLevel_valueChanged(double d)
242 {
243 imageWidget->setZoom(float(d));
244 }
245
246 void BitMapViewer::on_saveImageButton_clicked(bool /*checked*/)
247 {
248 QMessageBox::information(
249 this,
250 "Not yet implemented",
251 "Sorry, the save image dialog is not yet implemented");
252 }
253
254 void BitMapViewer::on_editPaletteButton_clicked(bool /*checked*/)
255 {
256 auto* p = new PaletteDialog();
257 p->setPalette(currentPalette);
258 p->setAutoSync(true);
259 connect(p, &PaletteDialog::paletteSynced, imageWidget, &VramBitMappedView::refresh);
260 p->show();
261 }
262
263 void BitMapViewer::on_useVDPPalette_stateChanged(int state)
264 {
265 const uint8_t* palette = VDPDataStore::instance().getPalettePointer();
266 if (state) {
267 imageWidget->setPaletteSource(palette);
268 } else {
269 // Copy palette from VDP to allow changes.
270 if (palette) memcpy(currentPalette, palette, 32);
271 imageWidget->setPaletteSource(currentPalette);
272 }
273 imageWidget->refresh();
274 editPaletteButton->setEnabled(!state);
275 }
276
277 /*
278 void BitMapViewer::on_refreshButton_clicked(bool checked)
279 {
280 refresh();
281 decodeVDPregs();
282 imageWidget->refresh();
283 }
284 */
285
286 void BitMapViewer::VDPDataStoreDataRefreshed()
287 {
288 decodeVDPregs();
289 }
290
291 void BitMapViewer::updateImagePosition(
292 int x, int y, int color, unsigned addr, int byteValue)
293 {
294 labelX->setText(QString("%1").arg(x, 3, 10, QChar('0')));
295 labelY->setText(QString("%1").arg(y, 3, 10, QChar('0')));
296 labelColor->setText(QString("%1").arg(color, 3, 10, QChar('0')));
297 labelByte->setText(hexValue(byteValue, 2));
298 labelVramAddr->setText(hexValue(addr, 5));
299 }