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

