Skip to content

Commit 65d690a

Browse files
committed
Ensure palette consistency across emulators and improve breakpoint handling during resets.
1 parent 004c621 commit 65d690a

File tree

7 files changed

+28
-5
lines changed

7 files changed

+28
-5
lines changed

src/cadmium.cpp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2227,6 +2227,8 @@ void main()
22272227
SetNextWidth(60);
22282228
if (Button("Ok")) {
22292229
_defaultPalette = _colorPalette;
2230+
setPalette(_defaultPalette);
2231+
_chipEmu->setPalette(_defaultPalette);
22302232
_selectedColor = nullptr;
22312233
_colorSelectOpen = false;
22322234
}
@@ -2941,9 +2943,25 @@ void main()
29412943
reloadRom();
29422944
updateBehaviorSelects();
29432945
resetStats();
2946+
// ensure palette has enough colors, else fill up
29442947
if (_properties->palette().empty() || _properties->palette().size() != _chipEmu->getMaxColors()) {
2945-
_colorPalette = _defaultPalette;
2946-
_colorPalette.colors.resize(_chipEmu->getMaxColors());
2948+
_colorPalette = _properties->palette();
2949+
size_t currentSize = _colorPalette.colors.size();
2950+
size_t targetSize = _chipEmu->getMaxColors();
2951+
if (currentSize < targetSize) {
2952+
_colorPalette.colors.reserve(targetSize);
2953+
for (size_t i = currentSize; i < targetSize; ++i) {
2954+
if (i < _defaultPalette.colors.size()) {
2955+
_colorPalette.colors.push_back(_defaultPalette.colors[i]);
2956+
}
2957+
else {
2958+
_colorPalette.colors.push_back(emu::Palette::Color{0});
2959+
}
2960+
}
2961+
}
2962+
else if (currentSize > targetSize) {
2963+
_colorPalette.colors.resize(targetSize);
2964+
}
29472965
_properties->palette() = _colorPalette;
29482966
_chipEmu->setPalette(_colorPalette);
29492967
}

src/emuhostex.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,6 @@ void EmuHostEx::updateEmulatorOptions(const Properties& properties)
227227
_previousProperties = properties;
228228
_chipEmu = create(*_properties, _chipEmu.get());
229229
if (_chipEmu) {
230-
if (_chipEmu->getMaxColors() != _properties->palette().colors.size()) {
231-
_properties->palette().colors.clear();
232-
}
233230
if(_chipEmu->getScreen())
234231
(void)_chipEmu->getScreen();
235232
whenEmuChanged(*_chipEmu);

src/emulation/chip8generic.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,7 @@ bool Chip8GenericEmulator::updateProperties(Properties& props, Property& changed
528528
void Chip8GenericEmulator::setPalette(const Palette& palette)
529529
{
530530
_screen.setPalette(palette);
531+
_screenNeedsUpdate = true;
531532
}
532533

533534
int Chip8GenericEmulator::getMaxColors() const

src/emulation/chip8generic.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ class Chip8GenericEmulator : public Chip8GenericBase
321321
_screenNeedsUpdate = true;
322322
}
323323

324+
/*
324325
bool handleDisplayWait()
325326
{
326327
if (_cpuState == eWAIT) {
@@ -330,6 +331,7 @@ class Chip8GenericEmulator : public Chip8GenericBase
330331
//if(_options.optExtendedVBlank
331332
}
332333
}
334+
*/
333335

334336
template<uint16_t quirks>
335337
void opDxyn_displayWait(uint16_t opcode)

src/emulation/chip8strict.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ GenericCpu::StackContent Chip8StrictEmulator::stack() const
108108
void Chip8StrictEmulator::setPalette(const Palette& palette)
109109
{
110110
_screen.setPalette(palette);
111+
_screenNeedsUpdate = true;
111112
}
112113

113114
}

src/emulation/hardware/genericcpu.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ class GenericCpu
7676
virtual ~GenericCpu() = default;
7777
void reset(bool cold = true)
7878
{
79+
for(auto& [addr, bpi] : _breakpoints) {
80+
bpi.numHits = 0;
81+
}
7982
initExpressionist();
8083
handleReset(cold);
8184
}

src/knownfiles.ipp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ static KnownRomInfo g_knownRoms[] = {
123123
{"3450e0d92e0bbf8e9d3065fd088cd6dfa5f9441d"_sha1, "chip-8", "Octo Bird (Cody Hoover, 2016)",nullptr, nullptr},
124124
{"346f2760ca55bb6d45b1f255fe4960a7d244191e"_sha1, "vip-chip-8", "Bingo (Andrew Modla)",nullptr, nullptr},
125125
{"35158696bd94ea22ef34e899fff1f15f7154d4fd"_sha1, "chip-8", "Craps (Camerlo Cortez, 1978)",nullptr, nullptr},
126+
{"36363ecdd850dd1a099e272fae6d9b786c2a7d36"_sha1, "xo-chip", "Raycaster (A-KouZ1, 2018)",R"({"instructionsPerFrame":200000,"palette":{"border":"#000000","colors":["#000000","#555555","#aaaaaa","#ffffff"],"signal":"#888888"}})", nullptr},
126127
{"3643118e2e237deab98151b742f34caf9533dc05"_sha1, "chip-8", "Mandelbrot Program (A-KouZ1, 2018)",nullptr, nullptr},
127128
{"39970ccfd3a3f00180d53464d4fd7862193eaf0f"_sha1, "chip-8", "Octo: A Chip 8 Story (SystemLogoff, 2015-10-29)",R"({"instructionsPerFrame":7,"palette":{"border":"#222222","colors":["#111111","#eeeeee"],"signal":"#ffff00"}})", nullptr},
128129
{"3a840c33442ad9e912df1fa2aa61833bf571af34"_sha1, "chip-8", "Private Eye (TCNJ S.572.37)",nullptr, nullptr},

0 commit comments

Comments
 (0)