Zlog — Arduino Uno simulation

An interactive Arduino Uno circuit simulation you can run free in your browser on Velxio, by jezebelguedes.

Components

Sketch code

const byte DATA_PINS[8] = {2, 3, 4, 5, 6, 7, 8, 9};

const byte IORQ_PIN  = 10;
const byte WR_PIN    = 11;
const byte HALT_PIN  = 12;
const byte RESET_PIN = 13;
const byte MREQ_PIN  = A0;

int lastHalt = HIGH;
int lastReset = HIGH;

bool writeDetected = false;
unsigned long writeCount = 0;

void setup() {
  Serial.begin(9600);

  for (byte i = 0; i < 8; i++) {
    pinMode(DATA_PINS[i], INPUT);
  }

  pinMode(IORQ_PIN, INPUT);
  pinMode(WR_PIN, INPUT);
  pinMode(HALT_PIN, INPUT);
  pinMode(RESET_PIN, INPUT);
  pinMode(MREQ_PIN, INPUT);

  Serial.println("=== MONITOR Z80 BYTEZILOG ===");
  Serial.println("Aguardando atividade...");
}

void loop() {
  int iorq = digitalRead(IORQ_PIN);
  int wr = digitalRead(WR_PIN);
  int mreq = digitalRead(MREQ_PIN);

  int halt = digitalRead(HALT_PIN);
  int reset = digitalRead(RESET_PIN);

  // Captura escrita de I/O
  if (iorq == LOW && wr == LOW && !writeDetected) {

    // Pequena espera para estabilizar a leitura
    delayMicroseconds(20);

    byte data = 0;

    for (byte i = 0; i < 8; i++) {
      if (digitalRead(DATA_PINS[i]) == HIGH) {
        bitSet(data, i);
      }
    }

    writeCount++;

    Serial.print("ESCRITA I/O #");
    Serial.print(writeCount);

    Serial.print(" | HEX: 0x");
    if (data < 16) Serial.print("0");
    Serial.print(data, HEX);

    Serial.print(" | BIN: ");
    for (int i = 7; i >= 0; i--) {
      Serial.print(bitRead(data, i));
    }

    Serial.print(" | ASCII: ");
    if (data >= 32 && data <= 126) {
      Serial.write(data);
    } else {
      Serial.print(".");
    }

    Serial.print(" | MREQ: ");
    Serial.println(mreq == LOW ? "LOW" : "HIGH");

    writeDetected = true;
  }

  if (iorq == HIGH || wr == HIGH) {
    writeDetected = false;
  }

  if (halt != lastHalt) {
    Serial.print("HALT: ");
    Serial.println(halt == LOW ? "ATIVO - CPU PARADA" : "INATIVO");
    lastHalt = halt;
  }

  if (reset != lastReset) {
    Serial.print("RESET: ");
    Serial.println(reset == LOW ? "ATIVO" : "LIBERADO");
    lastReset = reset;
  }
}