Skip to content

Instantly share code, notes, and snippets.

@iolo
Created September 11, 2024 16:45
Show Gist options
  • Save iolo/ccdab36b109a897fd1d6830c4eeb935d to your computer and use it in GitHub Desktop.
Save iolo/ccdab36b109a897fd1d6830c4eeb935d to your computer and use it in GitHub Desktop.
Ben Eater's 6502 bus inspector firmware for Arduino Mega https://eater.net/6502
const char ADDR[] = {22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52};
const char DATA[] = {39, 41, 43, 45, 47, 49, 51, 53};
#define CLOCK 2
#define READ_WRITE 3
void setup() {
for (int n = 0; n < 16; n += 1) {
pinMode(ADDR[n], INPUT);
}
for (int n = 0; n < 8; n += 1) {
pinMode(DATA[n], INPUT);
}
pinMode(CLOCK, INPUT);
pinMode(READ_WRITE, INPUT);
attachInterrupt(digitalPinToInterrupt(CLOCK), onClock, RISING);
Serial.begin(57600);
}
void onClock() {
char output[15];
unsigned int address = 0;
for (int n = 0; n < 16; n += 1) {
int bit = digitalRead(ADDR[n]) ? 1 : 0;
Serial.print(bit);
address = (address << 1) + bit;
}
Serial.print(" ");
unsigned int data = 0;
for (int n = 0; n < 8; n += 1) {
int bit = digitalRead(DATA[n]) ? 1 : 0;
Serial.print(bit);
data = (data << 1) + bit;
}
sprintf(output, " %04x %c %02x", address, digitalRead(READ_WRITE) ? 'r' : 'W', data);
Serial.println(output);
}
void loop() {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment