Skip to content

Commit efdac4c

Browse files
committed
Add support for querying supported CHIP-8 variants across emulators for correct disassembly and enhance CLI with version flag
1 parent 293c982 commit efdac4c

File tree

14 files changed

+48
-7
lines changed

14 files changed

+48
-7
lines changed

CHANGELOG.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10-
## [1.1.9-1.1.11] (wip)
10+
## [1.1.9-1.9.90] (wip)
1111

1212
### Added
1313

@@ -36,7 +36,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3636
- [Desktop only] Library/Research screen and database integration allows for easier research on existing roms
3737
and interpreters, all information about programs, and even the binaries themselves are now kept
3838
in a local SQLite3 file in the configuration directory (<10MB for all known programs combined)
39-
- [Desktop only] Cadmium now remembers window position and scaling and starts like it was closed.
39+
- [Desktop only] Cadmium now remembers window position and scaling and starts like it was closed
40+
- Cadmium now has a `--version` command line option and shows the git commit hash in the about dialog
4041

4142
### Changed
4243

@@ -51,6 +52,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
5152

5253
### Fixed
5354

55+
- Disassembly sometimes only showed hex bytes instead of opcodes
5456
- The VIP-CHIP-8E interpreter had a typo leading to `BBnn` not working ([#12](https://github.com/gulrak/cadmium/issues/12))
5557
- Disassembling 0x7C, 0x7D or 0x7F generated single byte opcodes instead two byte ones ([#13](https://github.com/gulrak/cadmium/issues/12))
5658
- Octo-Assembler would hang on macro definitions without name or parameter

src/cadmium.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1811,7 +1811,7 @@ void main()
18111811
DrawTextureRec(_titleTexture, {34, 2, 60, 60}, {aboutScroll.x + 8.0f, aboutScroll.y + 31.0f}, WHITE);
18121812
auto styleColor = GetStyle(LABEL, TEXT_COLOR_NORMAL);
18131813
SetStyle(LABEL, TEXT_COLOR_NORMAL, ColorToInt(WHITE));
1814-
Label(" Cadmium v" CADMIUM_VERSION);
1814+
Label(" Cadmium v" CADMIUM_VERSION "-" CADMIUM_GIT_HASH);
18151815
SetStyle(LABEL, TEXT_COLOR_NORMAL, styleColor);
18161816
Space(4);
18171817
Label(" (c) 2022 by Steffen 'Gulrak' Schümann");
@@ -3550,6 +3550,7 @@ int main(int argc, char* argv[])
35503550
bool compareRun = false;
35513551
int64_t benchmark= 0;
35523552
bool showHelp = false;
3553+
bool showVersion = false;
35533554
bool opcodeTable = false;
35543555
bool opcodeJSON = false;
35553556
bool dumpLibNickel = false;
@@ -3568,6 +3569,7 @@ int main(int argc, char* argv[])
35683569
cli.category("General Options");
35693570
#ifndef PLATFORM_WEB
35703571
cli.optionEnable({"-h", "--help"}, showHelp, "Show this help text");
3572+
cli.optionEnable({"-v", "--version"}, showVersion, "Show version information");
35713573
cli.option({"-t", "--trace"}, traceLines, "Run headless and dump given number of trace lines");
35723574
cli.optionEnable({"-c", "--compare"}, compareRun, "Run and compare with reference engine, trace until diff");
35733575
cli.option({"-b", "--benchmark"}, benchmark, "Run given number of cycles as benchmark");
@@ -3698,6 +3700,11 @@ int main(int argc, char* argv[])
36983700
cli.usage();
36993701
exit(0);
37003702
}
3703+
if(showVersion) {
3704+
std::cout << "Cadmium v" << CADMIUM_VERSION << "-" << CADMIUM_GIT_HASH << std::endl;
3705+
std::cout << "(c) Copyright 2022 by Steffen 'Gulrak' Schümann" << std::endl;
3706+
exit(0);
3707+
}
37013708
#ifndef PLATFORM_WEB
37023709
if(convertRomList) {
37033710
convertKnownRomList();

src/emuhostex.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -384,10 +384,10 @@ bool EmuHostEx::loadBinary(std::string_view filename, ghc::span<const uint8_t> b
384384
auto startAddress = _properties->get<Property::Integer>("startAddress");
385385
auto loadAddress = startAddress ? startAddress->intValue : 0;
386386
emu::Chip8Decompiler decomp{_romImage, static_cast<uint32_t>(loadAddress)};
387-
decomp.setVariants(chip8::Variant::CHIP_8 /*_options.presetAsVariant()*/, true); // TODO: Fix this!!
388-
// TraceLog(LOG_INFO, "Setting variant.");
389-
// decomp.setVariant(Chip8Variant::CHIP_8, true);
390-
// TraceLog(LOG_INFO, "About to decompile...");
387+
auto chip8Emu = dynamic_cast<emu::IChip8Emulator*>(_chipEmu->executionUnit(0));
388+
TraceLog(LOG_INFO, "Setting variant.");
389+
decomp.setVariants(chip8Emu ? chip8Emu->supportedChip8Variants() : chip8::Variant::NONE, true);
390+
TraceLog(LOG_INFO, "About to decompile...");
391391
decomp.decompile(filename, loadAddress, &os, false, true);
392392
source = os.str();
393393
}

src/emulation/chip8generic.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,11 @@ Chip8GenericEmulator::~Chip8GenericEmulator()
783783
#endif
784784
}
785785

786+
chip8::VariantSet Chip8GenericEmulator::supportedChip8Variants() const
787+
{
788+
return _options.variant();
789+
}
790+
786791
int64_t Chip8GenericEmulator::executeFor(int64_t micros)
787792
{
788793
if (_execMode == ePAUSED || _cpuState == eERROR) {

src/emulation/chip8generic.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ class Chip8GenericEmulator : public Chip8GenericBase
114114
{
115115
return "Chip-8-MPT";
116116
}
117+
chip8::VariantSet supportedChip8Variants() const override;
117118
uint32_t cpuID() const override { return 0xC8; }
118119
bool updateProperties(Properties& props, Property& changed) override;
119120
int64_t machineCycles() const override { return 0; }

src/emulation/chip8strict.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ struct StrictFactoryInfo final : public CoreRegistry::FactoryInfo<Chip8StrictEmu
8585

8686
static bool registeredStrictC8 = CoreRegistry::registerFactory(PROP_CLASS, std::make_unique<StrictFactoryInfo>("First cycle exact HLE emulation of CHIP-8 on a COSMAC VIP"));
8787

88+
chip8::VariantSet Chip8StrictEmulator::supportedChip8Variants() const
89+
{
90+
return chip8::Variant::CHIP_8;
91+
}
92+
8893
bool Chip8StrictEmulator::updateProperties(Properties& props, Property& changed)
8994
{
9095
(void)registeredStrictC8;

src/emulation/chip8strict.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ class Chip8StrictEmulator : public Chip8GenericBase
7474
{
7575
return "Chip-8-Strict";
7676
}
77+
chip8::VariantSet supportedChip8Variants() const override;
7778
uint32_t cpuID() const override { return 0xC856; }
7879
uint8_t readMemoryByte(uint32_t addr) const override { return readByte(addr); }
7980
uint16_t getCurrentScreenWidth() const override { return 64; }

src/emulation/cosmacvip.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -872,6 +872,11 @@ std::string CosmacVIP::name() const
872872
return "Chip-8-RVIP";
873873
}
874874

875+
chip8::VariantSet CosmacVIP::supportedChip8Variants() const
876+
{
877+
return getVariantForInterpreter(_impl->_options.interpreter);
878+
}
879+
875880
unsigned CosmacVIP::stackSize() const
876881
{
877882
return 24;

src/emulation/cosmacvip.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class CosmacVIP : public Chip8RealCoreBase, public Cdp1802Bus
5555

5656
bool updateProperties(Properties& props, Property& changed) override;
5757
std::string name() const override;
58+
chip8::VariantSet supportedChip8Variants() const override;
5859

5960
// IEmulationCore
6061
size_t numberOfExecutionUnits() const override;

src/emulation/dream6800.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,11 @@ std::string Dream6800::name() const
395395
return "DREAM6800";
396396
}
397397

398+
chip8::VariantSet Dream6800::supportedChip8Variants() const
399+
{
400+
return _impl->_options.romName == "CHIPOS" ? chip8::Variant::CHIP_8_D6800 : chip8::Variant::CHIP_8_D6800_LOP;
401+
}
402+
398403
bool Dream6800::updateProperties(Properties& props, Property& changed)
399404
{
400405
if(fuzzyAnyOf(changed.getName(), {"TraceLog", "InstructionsPerFrame", "FrameRate"})) {

0 commit comments

Comments
 (0)