Fam4000 — Esp32 Devkit C V4 simulation

An interactive Esp32 Devkit C V4 circuit simulation you can run free in your browser on Velxio, by alireza-cs94.

Components

Sketch code

#include <Arduino.h>
#include "Assembler4004.hpp"

// -----------------------------------------------------------------------
// Test harness for Assembler4004.
//
// HOW TO USE:
//   1. Rename whichever .ino currently has setup()/loop() (e.g.
//      Main_testasm.ino or Main_asm.ino) to something ending in .inoORG
//      so it's excluded from the build - a sketch can only have ONE
//      setup()/loop() pair.
//   2. Rename this file from Main_asm_tests.ino-----------------------------------------------------------------------

Assembler4004 asm4;
int testsRun = 0;
int testsPassed = 0;

void runTest(const char* name, const String& source,
             const uint8_t* expected, int expectedLen,
             bool expectSuccess = true) {
  testsRun++;
  Serial.print("[TEST] ");
  Serial.print(name);
  Serial.print(" ... ");

  bool ok = asm4.assemble(source);

  if (ok != expectSuccess) {
    Serial.print("FAIL (assemble() returned ");
    Serial.print(ok ? "true" : "false");
    Serial.print(", expected ");
    Serial.print(expectSuccess ? "true" : "false");
    Serial.println(")");
    return;
  }

  if (!expectSuccess) {
    // We only care that it correctly failed; no byte comparison needed.
    Serial.println("PASS (correctly rejected)");
    testsPassed++;
    return;
  }

  bool bytesMatch = true;
  int mismatchIndex = -1;
  for (int i = 0; i < expectedLen; i++) {
    if (asm4.output[i] != expected[i]) {
      bytesMatch = false;
      mismatchIndex = i;
      break;
    }
  }

  if (bytesMatch) {
    Serial.println("PASS");
    testsPassed++;
  } else {
    Serial.print("FAIL (byte mismatch at index ");
    Serial.print(mismatchIndex);
    Serial.print(": got 0x");
    Serial.print(asm4.output[mismatchIndex], HEX);
    Serial.print(", expected 0x");
    Serial.print(expected[mismatchIndex], HEX);
    Serial.println(")");

    Serial.print("  got:      ");
    for (int i = 0; i < expectedLen; i++) {
      Serial.printf("%02X ", asm4.output[i]);
    }
    Serial.println();
    Serial.print("  expected: ");
    for (int i = 0; i < expectedLen; i++) {
      Serial.printf("%02X ", expected[i]);
    }
    Serial.println();
  }
}

void setup() {
  Serial.begin(115200);
  delay(1000);
  Serial.println("===== Assembler4004 test suite =====");
  Serial.println("BUILD CHECK: strictParseInt fix v2");

  // ---- Test 1: basic I/O + unconditional jump ----
  {
    const char* src =
      "start:\n"
      "  LDM 1\n"
      "  WRR\n"
      "  LDM 0\n"
      "  WRR\n"
      "  JUN start\n";
    uint8_t expected[] = { 0xD1, 0xE2, 0xD0, 0xE2, 0x40, 0x00 };
    runTest("basic I/O + JUN", String(src), expected, sizeof(expected));
  }

  // ---- Test 2: FIM / INC / ISZ delay loop ----
  {
    const char* src =
      "start:\n"
      "  LDM 1\n"
      "  WRR\n"
      "  FIM R0, 0x0F\n"
      "delay1:\n"
      "  INC R0\n"
      "  ISZ R0, delay1\n"
      "  JUN start\n";
    uint8_t expected[] = { 0xD1, 0xE2, 0x20, 0x0F, 0x60, 0x70, 0x04, 0x40, 0x00 };
    runTes

More projects by alireza-cs94