/*
See https://blog.jochumzen.com/ entry 21
Demonstration of RAM, Memory Address Register (MAR)and Memory Data Register (MDR)
Set DIP 1 to ON on the address DIP's (left)
Set DIP 1 to ON on the data DIP's (right)
This takes us into "programming mode" where the DIPs determine address and data
Set an address on DIP 5-8 on the address DIP's and data on DIP 5-8 on the data DIP's
Click Print
Observe:
The address mux and the data mux has selection S = 1 (DIPS) and they output address and data from DIPs
Address A and Data D on RAM are given by the DIPS.
Program some data, say 5 at address 0, 9 at address 1 and 6 at address 2:
Set address DIPs to 0000
Set data DIPS to 0101 (decimal 5)
Click RAM-L
Similarly for address 1 and 2
Click Print. Observe RAM and that correct data has been programmed.
Move the content of RAM at address 0 to the register
Set address DIPs to 0000
Click and hold RAM-W, REG-L (press 4 and 5 on keyboard)
Click Clock to latch. Register now contains 5.
Click Print. Observe Register and MDR and that Q = 5
Program RAM address 3 with content of Register
Set the Data select S to OFF (DIP 1). RAM D now takes input from MDR
Click and hold REG-W, MDR-L (press 2 and 6 on keyboard)
Click Clock to latch
Set address DIPs to 0011
Click RAM-L
Click Print to check that RAM address 3 now contains 5
*/
//Library with basic gates
#include <ACEL.h>
//Create an Arduino board
auto* ard = new ArduinoBoard();
//Define chips
auto* ram = new SixteenByFourRam((char*)("RAM"));
auto* mdr = new FourBitRegister((char*)("MDR"));
auto* mar = new FourBitRegister((char*)("MAR"));
auto* dataBus = new BusLineFour((char*)("Data Bus"));
auto* addressBus = new BusLineFour((char*)("Address Bus"));
auto* addressMux = new QuadFourToOneMux((char*)("Address Mux"));
auto* dataMux = new QuadFourToOneMux((char*)("Data Mux"));
auto* reg = new FourBitRegister((char*)("Register"));
//Add all chips to be emulated here
Chip* chips[] = {
ram, mdr, mar, dataBus, addressBus, addressMux, dataMux, reg
};
//Add all connections here
ConnectionBase* connections[] = {
//Address stuff
new ConnectionFour(addressBus->W, mar->D),
new ConnectionFour(mar->Q, addressMux->A),
new Connection(ard,2,addressMux->S),
new ConnectionFour(ard,3, addressMux->B,1),
new ConnectionFour(addressMux->Q, ram->A),
new ConnectionFour(mar->W, addressBus->X),
//Data stuff
new ConnectionFour(dataBus->W, mdr->D),
new ConnectionFour(mdr->Q, dataMux->A),
new Connection(ard,7,dataMux->S),
new ConnectionFour(ard,8, dataMux->B,1),
new ConnectionFour(dataMux->Q, ram->D),
new ConnectionFour(mdr->W, dataBus->X),
//RAM
new ConnectionFour(ram->W, addressBus->X),
new ConnectionFour(ram->W, dataBus->X),
//Register
new ConnectionFour(dataBus->W, reg->D),
new ConnectionFour(reg->W, dataBus->X),
//Buttons
new Connection(ard,22,mdr->Clock),
new Connection(ard,22,mar->Clock),
new Connection(ard,22,reg->Clock),
new Connection(ard,23,mdr->Load),
new Connection(ard,24,ram->Load),
new Connection(ard,25,ram->Write),
new Connection(ard,26,reg->Load),
new Connection(ard,27,reg->Write),
};
//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
S
Clock
Address
Data
RAM-L
RAM-W
S
REG-L
REG-W
MDR-L