Skip to main content
net8.0

FlawlessChips is a collection of gate-level simulations of 8-bit chips.

Published
Nov 22, 2023
2y ago
Total Downloads
1.0K
1,006

Install

dotnet add package FlawlessChips --version 0.1.1
ProductVersions
.NET
net8.0

README

FlawlessChips Build Status NuGet

FlawlessChips is a C# library that provides gate-level simulation of various 8-bit chips.

FlawlessChips is (with a nod and wink to perfect6502's description):

  • Flawless - it is a simulation of the original transistors, not an emulation. (Of course, there might be bugs...)
  • Slow - like, really slow. This implementation is faster than the JavaScript implementations on which it's based, but it's still way slower than the original chips.

FlawlessChips's intended audience is emulator authors who want to run their emulations and compare e.g. output pins with this half-cycle exact simulation.

Simulated chips

  • 6502 - FlawlessChips.Flawless6502
  • 2A03 - FlawlessChips.Flawless2A03
  • 2C02 - FlawlessChips.Flawless2C02

Install

FlawlessChips is available as a NuGet Package.

Usage

This example shows the Flawless6502 chip simulator. Other chips are similar.

var chip = new Flawless6502();

// Assert reset pin, initialize other pins, deassert reset pin.
// Calling this method is optional; you can perform this setup
// in your own code.
chip.Startup();

// Loop a few times.
for (var i = 0; i < 100; i++)
{
    var newClk = !chip.IsHigh(clk0);

    // Pulse clock pin. Any transistors connected to this pin will be re-evaluated, recursively,
    // until the chip "settles" in its new state.
    chip.SetNode(clk0, newClk ? NodeValue.PulledHigh : NodeValue.PulledLow);

    // Memory accesses should only occur when the 6502's phi2 output pin is high.
    if (chip.IsHigh(clk2out))
    {
        // Does the 6502 want to read?
        if (chip.IsHigh(rw))
        {
            // You can access individual pin values via chip.IsHigh(ab0), chip.IsHigh(ab1), etc.
            // But for simplicity there's GetBus and SetBus to set the whole bus value at once.
            var address = chip.GetBus(ab);
            var data = memory[address];
            chip.SetBus(db, data);
        }
        else // Otherwise the 6502 wants to write.
        {
            var address = chip.GetBus(ab);
            var data = chip.GetBus(db);
            memory[address] = data;
        }
    }

    // Print out a few interesting bits of chip state. There are also hundreds of other node names
    // available in the FlawlessChips.Flawless6502.NodeIds class.
    Console.WriteLine(
        "Φ2 {0}   PC {1:X4}   X {2:X2}   Y {3:X2}   A {4:X2}   SP {5:X2}   AB {6:X4}   DB {7:X2}   RW {8}",
        chip.IsHigh(clk2out) ? '1' : '0',
        chip.GetPC(),
        chip.GetBus(x),
        chip.GetBus(y),
        chip.GetBus(a),
        chip.GetBus(s),
        chip.GetBus(ab),
        chip.GetBus(db),
        chip.IsHigh(rw) ? '1' : '0');
}

License

This software is released under the BSD-Clause 2 license.

Credits

This project is essentially a C# port of the following projects. The authors of these projects deserve huge credit for their efforts in photographing chips, analyzing circuits, and writing the simulators.

The logo is a modified version of the chips icon by pictranoosa, and the perfect icon by Paffi.

Author

Tim Jones

Changes from Previous Version

No structural changes between v0.1.0 and v0.1.1.

Adoption Assessment

Assess this package against its supported frameworks, license, maintenance signals and dependency graph before making it a project standard.

Compatibility metadata lists 1 target framework; confirm the exact target used by your application.

Related Guides & Workflows

Learn how to evaluate, integrate, or audit this package in your .NET project.