/*
See https://blog.jochumzen.com/ entry 23
Testing the ALU
1. Use the DIP switches to program RAM. Put say 5 at address 0 and 3 at address 1.
2. Move the content of address 0 to Register A (the number 5)
3. Move the content of address 1 to Register B (the number 3)
4. The ALU will calculate the sum (the number 8)
5.Store the sum in RAM at address 2.
Step by step:
Set DIP 1 to ON on the adddress 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
Program: 5 at address 0, 3 at address 1:
Set address DIPs to 0000
Set data DIPS to 0101 (decimal 5)
Click RAM-L
Similarly for address 1
Click Print. Observe RAM and that correct data has been programmed.
Move the content of RAM at address 0 to register A
Set address DIPs to 0000
Click and hold RAMW, REGAL (press 4 and 5 on keyboard)
Click Clock to latch
Click Print. Observe Register A and that Q = 5
Move the content of RAM at address 1 to register B
Set address DIPs to 0001
Click and hold RAMW, REGBL (press 4 and 6 on keyboard)
Click Clock to latch
Click Print. Observe Register B has Q = 3. Observe A=5, B=3 and Q=A+B=8 in the ALU
Move the content of the ALU to RAM address 2
Move the content of the ALU to MDR:
Click and hold ALU-W, MDR-L (press 2 and 7 on keyboard)
Click Clock to latch
Set the Data select S to OFF (DIP 1). RAM D now takes input from MDR
Click Print and observe that RAM D=8 (content of MDR)
Set address DIPs to 0010 (2)
Click RAM-L
Click Print to check that the RAM now has 3 and 5 at address 0 and 1 and that it has the sum at address 2.
*/
//Library with basic gates
#include <ACEL.h>
//Create an Arduino board
auto* ard = new ArduinoBoard();
//Define chips
auto* dataBus = new BusLineFour((char*)("Data Bus"));
auto* memorySys = new SixteenByFourMemorySystem((char*)("Memory System"));
auto* register1 = new FourBitRegister((char*)("Register A"));
auto* register2 = new FourBitRegister((char*)("Register B"));
auto* alu = new FourBitAdderTriState((char*)("ALU"));
//Add all chips to be emulated here
Chip* chips[] = {
dataBus, memorySys, register1, register2, alu
};
//Add all connections here
ConnectionBase* connections[] = {
//DIP's and buttons
new Connection(ard,2,memorySys->SA),
new ConnectionFour(ard,3, memorySys->AB,1), //Address, mux B: DIP
new Connection(ard,7,memorySys->SD),
new ConnectionFour(ard,8, memorySys->DB,1), //Data, mux B: DIP
new Connection(ard,22,memorySys->Clock),
new Connection(ard,22,register1->Clock),
new Connection(ard,22,register2->Clock),
new Connection(ard,23,memorySys->MDRL),
new Connection(ard,24,memorySys->RAML),
new Connection(ard,25,memorySys->RAMW),
new Connection(ard,26,register1->Load),
new Connection(ard,27,register2->Load),
new Connection(ard,28,alu->Write),
//Internal connections
new ConnectionFour(dataBus->W, memorySys->DA),
new ConnectionFour(memorySys->WD, dataBus->X),
new ConnectionFour(dataBus->W, register1->D),
new ConnectionFour(register1->Q, alu->A),
new ConnectionFour(dataBus->W, register2->D),
new ConnectionFour(register2->Q, alu->B),
new ConnectionFour(alu->W, dataBus->X),
};
//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
AS
Clock
Address
Data
RAML
MDRL
RAMW
DS
REGAL
REGBL
ALU-W