diff --git a/src/PaletteView.ui b/src/PaletteView.ui
index 66f25583..f6b027f8 100644
--- a/src/PaletteView.ui
+++ b/src/PaletteView.ui
@@ -290,6 +290,9 @@
-
+
+ autosync to openMSX
+
Autosync
diff --git a/src/TileViewer.cpp b/src/TileViewer.cpp
index b2a57be5..b2df24a2 100644
--- a/src/TileViewer.cpp
+++ b/src/TileViewer.cpp
@@ -7,26 +7,6 @@
#include
-// static to feed to PaletteDialog and be used when VDP colors aren't selected
-uint8_t TileViewer::defaultPalette[32] = {
-// RB G
- 0x00, 0,
- 0x00, 0,
- 0x11, 6,
- 0x33, 7,
- 0x17, 1,
- 0x27, 3,
- 0x51, 1,
- 0x27, 6,
- 0x71, 1,
- 0x73, 3,
- 0x61, 6,
- 0x64, 6,
- 0x11, 4,
- 0x65, 2,
- 0x55, 5,
- 0x77, 7,
-};
TileViewer::TileViewer(QWidget* parent)
@@ -43,7 +23,6 @@ TileViewer::TileViewer(QWidget* parent)
connect(cb_color0, &QCheckBox::stateChanged, this, &TileViewer::on_cb_color0_stateChanged);
connect(useVDPRegisters, &QCheckBox::stateChanged, this, &TileViewer::on_useVDPRegisters_stateChanged);
- connect(editPaletteButton, &QPushButton::clicked, this, &TileViewer::on_editPaletteButton_clicked);
connect(useVDPPalette, &QCheckBox::stateChanged, this, &TileViewer::on_useVDPPalette_stateChanged);
connect(zoomLevel, qOverload(&QDoubleSpinBox::valueChanged), this, &TileViewer::on_zoomLevel_valueChanged);
@@ -83,7 +62,7 @@ TileViewer::TileViewer(QWidget* parent)
scrollArea->setWidget(imageWidget);
const auto* vram = VDPDataStore::instance().getVramPointer();
- const auto* palette = VDPDataStore::instance().getPalettePointer();
+ auto* palette = VDPDataStore::instance().getPalette(paletteVDP);
//imageWidget->setNameTableAddress(0);
//imageWidget->setPatternTableAddress(0);
//imageWidget->setColorTableAddress(0);
@@ -106,7 +85,7 @@ TileViewer::TileViewer(QWidget* parent)
void TileViewer::VDPDataStoreDataRefreshed()
{
if (useVDPPalette->isChecked()) {
- imageWidget->setPaletteSource(VDPDataStore::instance().getPalettePointer());
+ imageWidget->setPaletteSource(VDPDataStore::instance().getPalette(paletteVDP));
}
decodeVDPregs();
}
@@ -336,33 +315,14 @@ void TileViewer::on_useVDPRegisters_stateChanged(int state)
cb_color0->setEnabled(useManual);
}
-void TileViewer::on_editPaletteButton_clicked(bool /*checked*/)
-{
- auto* p = new PaletteDialog();
- p->setPalette(defaultPalette);
- p->setAutoSync(true);
- connect(p, &PaletteDialog::paletteSynced, imageWidget, &VramTiledView::refresh);
- connect(p, &PaletteDialog::paletteSynced, this, &TileViewer::update_label_characterimage);
- p->show();
- //useVDPPalette->setChecked(false);
- //QMessageBox::information(
- // this,
- // "Not yet implemented",
- // "Sorry, the palette editor is not yet implemented, "
- // "only disabling 'Use VDP palette registers' for now");
-}
-
void TileViewer::on_useVDPPalette_stateChanged(int state)
{
- const uint8_t* palette = VDPDataStore::instance().getPalettePointer();
if (state) {
- imageWidget->setPaletteSource(palette);
+ imageWidget->setPaletteSource(VDPDataStore::instance().getPalette(paletteVDP));
} else {
- if (palette) memcpy(defaultPalette, palette, 32);
- imageWidget->setPaletteSource(defaultPalette);
+ imageWidget->setPaletteSource(VDPDataStore::instance().getPalette(paletteTiles));
}
imageWidget->refresh();
- editPaletteButton->setEnabled(!state);
}
void TileViewer::on_zoomLevel_valueChanged(double d)
diff --git a/src/TileViewer.h b/src/TileViewer.h
index c5205306..de0ba474 100644
--- a/src/TileViewer.h
+++ b/src/TileViewer.h
@@ -28,7 +28,6 @@ class TileViewer : public QDialog, private Ui::TileViewer
void on_cb_color0_stateChanged(int state);
void on_useVDPRegisters_stateChanged(int state);
- void on_editPaletteButton_clicked(bool checked);
void on_useVDPPalette_stateChanged(int state);
void on_zoomLevel_valueChanged(double d);
@@ -53,7 +52,6 @@ class TileViewer : public QDialog, private Ui::TileViewer
int mouseOverY = 0;
int mouseOverChar = 0;
- static uint8_t defaultPalette[32];
};
#endif // TILEVIEWER_H
diff --git a/src/TileViewer.ui b/src/TileViewer.ui
index 840ecdd3..c6e41c9e 100644
--- a/src/TileViewer.ui
+++ b/src/TileViewer.ui
@@ -6,7 +6,7 @@
0
0
- 911
+ 1070
756
@@ -50,8 +50,8 @@
0
0
- 615
- 369
+ 695
+ 368
@@ -559,16 +559,6 @@ NT: $196E (base+$16E)
-
-
-
-
-
- false
-
-
- Edit palette..
-
-
-
-
diff --git a/src/VramTiledView.cpp b/src/VramTiledView.cpp
index 5ff959d3..d9c45319 100644
--- a/src/VramTiledView.cpp
+++ b/src/VramTiledView.cpp
@@ -1,5 +1,6 @@
#include "VramTiledView.h"
#include "VDPDataStore.h"
+#include "MSXPalette.h"
#include "Convert.h"
#include "ranges.h"
#include
@@ -10,7 +11,8 @@ VramTiledView::VramTiledView(QWidget* parent)
: QWidget(parent)
, image(512, 512, QImage::Format_RGB32)
{
- ranges::fill(msxPalette, qRgb(80, 80, 80));
+ palette = nullptr;
+ setPaletteSource(VDPDataStore::instance().getPalette(paletteVDP));
setZoom(1.0f);
// Mouse update events when mouse is moved over the image, Quibus likes this
@@ -80,21 +82,6 @@ void VramTiledView::decode()
update();
}
-void VramTiledView::decodePalette()
-{
- if (!palette) return;
- //printf("VramTiledView::decodePallet palletpointer %p \n", palette);
-
- for (int i = 0; i < 16; ++i) {
- int r = (palette[2 * i + 0] & 0xf0) >> 4;
- int b = (palette[2 * i + 0] & 0x0f);
- int g = (palette[2 * i + 1] & 0x0f);
-
- auto scale = [](int x) { return (x >> 1) | (x << 2) | (x << 5); };
- msxPalette[i] = qRgb(scale(r), scale(g), scale(b));
- //printf("VramTiledView::decodePallet color %d => r %d g %d b %d \n", i, r, g, b);
- }
-}
void VramTiledView::decodePatternTable()
{
@@ -211,12 +198,7 @@ void VramTiledView::setPixel2x2(int x, int y, QRgb c)
QRgb VramTiledView::getColor(int c)
{
// TODO do we need to look at the TP bit???
- return msxPalette[c ? c : (tpBit ? 0 : borderColor)];
-}
-
-const uint8_t *VramTiledView::getPaletteSource() const
-{
- return palette;
+ return palette->color(c ? c : (tpBit ? 0 : borderColor));
}
int VramTiledView::getScreenMode() const
@@ -434,8 +416,7 @@ void VramTiledView::paintEvent(QPaintEvent* /*event*/)
void VramTiledView::refresh()
{
- decodePalette();
- decode();
+ decode();
}
QString VramTiledView::byteAsPattern(uint8_t byte)
@@ -568,9 +549,13 @@ void VramTiledView::setColorTableAddress(int adr)
decode();
}
-void VramTiledView::setPaletteSource(const uint8_t* adr)
+void VramTiledView::setPaletteSource(MSXPalette *adr)
{
if (palette == adr) return;
+ if (palette) {
+ disconnect(palette, &MSXPalette::paletteChanged, this, &VramTiledView::decode);
+ }
palette = adr;
+ connect(palette, &MSXPalette::paletteChanged, this, &VramTiledView::decode);
refresh();
}
diff --git a/src/VramTiledView.h b/src/VramTiledView.h
index 05e3f9ae..7e5e235e 100644
--- a/src/VramTiledView.h
+++ b/src/VramTiledView.h
@@ -10,6 +10,8 @@
#include
#include
+class MSXPalette;
+
class VramTiledView : public QWidget
{
Q_OBJECT
@@ -23,7 +25,7 @@ class VramTiledView : public QWidget
void setNameTableAddress(int adr);
void setPatternTableAddress(int adr);
void setColorTableAddress(int adr);
- void setPaletteSource(const uint8_t *adr);
+ void setPaletteSource(MSXPalette *adr);
void setBorderColor(int value);
void setDrawGrid(bool value);
void setTpBit(bool value);
@@ -59,7 +61,6 @@ class VramTiledView : public QWidget
void paintEvent(QPaintEvent* e) override;
void decode();
- void decodePalette();
void decodePatternTable();
void decodeNameTable();
void overLayNameTable();
@@ -83,10 +84,9 @@ class VramTiledView : public QWidget
QString byteAsPattern(uint8_t byte);
private:
- QRgb msxPalette[16];
QImage image;
QPixmap pixImage;
- const uint8_t* palette = nullptr;
+ MSXPalette* palette = nullptr;
const uint8_t* vramBase = nullptr;
float zoomFactor;
bool drawGrid = true;