/*
See https://blog.jochumzen.com/ entry 15
Demonstration: Moving data from one register to another using the data bus
Set DIP 5-8 to something, say 0011
Click and hold E (1) to enable the buffers, 0011 is put onto the bus
Click and hold L (3) of register A to "open its gate"
Click Clock C (2) to latch 0011 into register A
Relase all buttons
Click and hold W (4) of register B to write its value onto the bus
Click and hold L (5) of register B to "open its gate"
Click Clock C (2) to latch 0011 into register B
We have moved data Register A to Register B
*/
//Library with basic gates
#include <ACELBC.h>
//Create an Arduino board
auto* ard = new ArduinoBoard();
//Define chips
auto* registerA = new FourBitRegister((char*)("Register A"));
auto* registerB = new FourBitRegister((char*)("Register B"));
auto* buffers = new QuadThreeStateSwitches((char*)("Buffers"));
auto* bus = new BusLineFour((char*)("Bus"));
//Add all chips to be emulated here
Chip* chips[] = {
buffers, bus, registerA, registerB
};
//Add all connections here
ConnectionBase* connections[] = {
//Connect DIP switches to pins 2-5
new ConnectionFour(ard, 2, buffers->D, 1),
new ConnectionFour(buffers->W, bus->X),
new Connection(ard, 6, buffers->Enable),
//Register A
new Connection(ard, 7, registerA->Clock),
new Connection(ard, 8, registerA->Load),
new Connection(ard, 9, registerA->Write),
new ConnectionFour(registerA->W, bus->X),
new ConnectionFour(bus->W, registerA->D),
//Register B
new Connection(ard, 7, registerB->Clock),
new Connection(ard, 10, registerB->Load),
new Connection(ard, 11, registerB->Write),
new ConnectionFour(registerB->W, bus->X),
new ConnectionFour(bus->W, registerB->D),
};
//Setting up the emulation. No need to change
Emulation emulation = Emulation(ard, chips, sizeof(chips)/2,
connections, sizeof(connections)/2);
void setup() {
Serial.begin(9600); Serial.println(); Serial.println("START");
Serial.println();
emulation.makePrintPin(13, 1);
emulation.printOnArdEvent(1);
}
void loop() {
emulation.emulate();
}
Print
C
E
L
W
L
W
REGISTER A
REGISTER B