Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

NeevorPL

6
Posts
1
Topics
1
Following
A member registered 17 days ago

Recent community posts

(1 edit)

Hi everyone,

I just wanted to express my deepest gratitude for the absolute flood of responses and the overwhelming support I received on my last question. Your collective silence was truly deafening and incredibly inspiring—so much so that it motivated me to just take matters into my own hands.

With no other options, I ended up writing my own transpiler in Python. The script does exactly what I originally asked about: it directly parses the project’s JSON file, safely maps the old NAND-based sub-circuits to my new native C# components, and most importantly, it leaves the original GUIDs completely untouched while correctly recalculating the pin indices. All the wiring remains perfectly intact, and the simulation is finally back to a playable speed.

I’m dropping my code below. Take it and use it, so nobody else has to reinvent the wheel (or wait around for help that’s never coming).

import json
import os
import shutil
import glob

# List of gates to migrate to native Unity C# implementations
NATIVE_GATES = [
    "NOT", "AND", "OR", "XOR", "NOR", "XNOR",
    "AND3", "AND4", "AND8", "OR3", "OR4", "OR5", "OR6", "OR8"
]

CHIPS_DIR = "./Chips"
DELETED_DIR = "./Deleted Chips"


def main():
    if not os.path.exists(DELETED_DIR):
        os.makedirs(DELETED_DIR)
        print(f"Created directory: {DELETED_DIR}")

    gate_mappings = {}

    print("--- STEP 1: BUILDING ID MAP & MOVING OLD FILES ---")
    for gate in NATIVE_GATES:
        filename = f"{gate}.json"
        src_path = os.path.join(CHIPS_DIR, filename)
        dest_path = os.path.join(DELETED_DIR, filename)

        if not os.path.exists(src_path):
            print(f"[Skipped] Not found in {CHIPS_DIR}: {filename}")
            continue

        # Read the old gate JSON to map its complex IDs to sequential 0, 1, 2...
        with open(src_path, 'r', encoding='utf-8') as f:
            data = json.load(f)

        gate_mappings[gate] = {}
        current_new_id = 0

        if 'InputPins' in data:
            for pin in data['InputPins']:
                gate_mappings[gate][pin['ID']] = current_new_id
                current_new_id += 1

        if 'OutputPins' in data:
            for pin in data['OutputPins']:
                gate_mappings[gate][pin['ID']] = current_new_id
                current_new_id += 1

        # Move the old gate file out of the active directory
        try:
            if os.path.exists(dest_path):
                os.remove(dest_path)
            shutil.move(src_path, dest_path)
            print(f"[Mapped & Moved] {filename}")
        except Exception as e:
            print(f"[Error] Could not move {filename}: {e}")

    print("\n--- STEP 2: UPDATING WIRES IN REMAINING CHIPS ---")
    for filepath in glob.glob(os.path.join(CHIPS_DIR, '*.json')):
        filename = os.path.basename(filepath)
        chip_name = filename.replace('.json', '')

        with open(filepath, 'r', encoding='utf-8') as f:
            try:
                data = json.load(f)
            except json.JSONDecodeError:
                print(f"[Error] Failed to parse JSON in {filename}")
                continue

        modified = False
        subchips_to_update = {}

        # Check if the chip uses any of the migrated gates
        if 'SubChips' in data and data['SubChips']:
            for subchip in data['SubChips']:
                if subchip['Name'] in gate_mappings:
                    subchips_to_update[subchip['ID']] = subchip['Name']

        if not subchips_to_update:
            continue

        # Update the wiring to use the new sequential IDs (0, 1, 2...)
        if 'Wires' in data and data['Wires']:
            for wire in data['Wires']:
                # Update Source Pin
                src_owner = wire['SourcePinAddress']['PinOwnerID']
                if src_owner in subchips_to_update:
                    gate_name = subchips_to_update[src_owner]
                    old_pin = wire['SourcePinAddress']['PinID']
                    if old_pin in gate_mappings[gate_name]:
                        wire['SourcePinAddress']['PinID'] = gate_mappings[gate_name][old_pin]
                        modified = True

                # Update Target Pin
                tgt_owner = wire['TargetPinAddress']['PinOwnerID']
                if tgt_owner in subchips_to_update:
                    gate_name = subchips_to_update[tgt_owner]
                    old_pin = wire['TargetPinAddress']['PinID']
                    if old_pin in gate_mappings[gate_name]:
                        wire['TargetPinAddress']['PinID'] = gate_mappings[gate_name][old_pin]
                        modified = True

        # Save the updated chip JSON
        if modified:
            with open(filepath, 'w', encoding='utf-8') as f:
                json.dump(data, f, indent=2)
            print(f"[Updated Wires] -> {filename}")

    print("\n[SUCCESS] ALL DONE! The DLS library is fully migrated to native gates.")


if __name__ == '__main__':
    main()

Hope someone out there finds this useful. On a brighter note, the Commodore PLUS 4 replica is slowly taking shape!

Best regards, Pietrek

Hi everyone,

I’m currently deep into building a Commodore PLUS 4 replica. To keep the simulation speed at a playable level, I’ve moved away from building basic gates (OR, NOT, XOR, etc.) out of NAND sub-circuits. Instead, I’ve implemented them as native C# components within the DLS source code.

I have a large existing project folder where all the logic is already wired using sub-circuits (the standard .json format where a “Gate” is a collection of NANDs). My new native C# gates, while functionally identical, are seen as different entities by the simulator.

I’m looking for a way to “transpile” or convert my existing project JSON so that:

  • References to the old NAND-based sub-circuits are replaced with my new native C# components.

  • All existing wiring (connections) remains intact.

The way DLS saves sub-circuits vs. native components seems to differ in terms of componentName and how pins are indexed.

Doing replacement manually in the editor for a real CPU-scale project is impossible.

Has anyone developed a script or a tool to Batch-Replace components in DLS project files? Or perhaps someone has found a way to “alias” a sub-circuit so the engine treats it as a native script during the simulation update loop?

I’m currently considering writing a Python script to parse and edit the JSON directly, but I’m worried about breaking the internal GUIDs or pin mapping. Any insights or similar experiences would be greatly appreciated!

Best regards, Pietrek

I made it for you.

Find block diagram of any processor. Let’s try Zilog’s Z80 one. Here is the manual: https://www.zilog.com/docs/z80/um0080.pdf Recreate all the block - registers, instruction decoder, alu, etc Wire it all together, and voila, you have a Z80 replica ;P

Shift + D?

What you mean “duplicate something”?

MOS 8501 Replica