/*
See https://blog.jochumzen.com/ entry 23
Testing the Program counter with the memory system
1. Use the DIP switches to program RAM.
Put 8 at address 1 and 15 at address 8.
2. Increase the count in the program counter (PC) (making it equal to 1)
3. Move the content of PC to MAR so that address is 1 in RAM
4. Move the content of RAM at address 1 (the number 8) to the PC
5. Move the content of PC to MAR so that address is 8 in RAM
6. Move the content of RAM at address 8 (the number 15) to the OUT register
Step by step:
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
Program: 8 at address 1, 15 at address 8:
Set address DIPs to 0001
Set data DIPS to 1000 (decimal 8)
Click RAML
Similarly for address 8 (address: 1000, data: 1111)
Click Print. Observe RAM and that correct data has been programmed.
Return to "compute mode" by setting both DIP 1's to OFF
Increment PC
Click and hold COUNT (press 4 on keyboard)
Click Clock to latch
Click Print. Observe Q = 1 in program counter.
Move the content of PC to MAR
Click and hold PCW, MARL (press 3 and 5 on keyboard)
Click Clock to latch
Click Print. Observe MAR Q = 1, RAM Address = 1 and RAMQ = 8
Move the content of RAM at address 1 to the PC
Click and hold RAMW, PCW (press 2 and 7 on keyboard)
Click Clock to latch
Click Print. Observe PC Q = 8
Move the content of PC to MAR
Click and hold PCW, MARL (press 3 and 5 on keyboard)
Click Clock to latch
Click Print. Observe MAR Q = 8, RAM Address = 8 and RAMQ = 15
Move the content of RAM at address 8 to the output register
Click and hold RAMW, OUTL (press 7 and 8 on keyboard)
Click Clock to latch
Observe LED bar displays 1111 (15)
*/
//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* addressBus = new BusLineFour((char*)("Address Bus"));
auto* memorySys = new SixteenByFourMemorySystem((char*)("Memory System"));
auto* out = new FourBitRegister((char*)("Register OUT"));
auto* counter = new FourBitProgramCounter((char*)("Program counter"));
//Add all chips to be emulated here
Chip* chips[] = {
dataBus, addressBus, memorySys, out, counter
};
//Add all connections here
ConnectionBase* connections[] = {
//DIP's and buttons
new Connection(ard,2,memorySys->SA),
new ConnectionFour(ard,3, memorySys->DIPA,1),
new Connection(ard,7,memorySys->SD),
new ConnectionFour(ard,8, memorySys->DIPD,1),
new Connection(ard,22,memorySys->Clock),
new Connection(ard,22,out->Clock),
new Connection(ard,22,counter->Clock),
new Connection(ard,23,counter->Load),
new Connection(ard,24,counter->Write),
new Connection(ard,25,counter->Count),
new Connection(ard,26,memorySys->MARL),
new Connection(ard,27,memorySys->RAML),
new Connection(ard,28,memorySys->RAMW),
new Connection(ard,28,out->Load),
//Internal connections
new ConnectionFour(counter->W, addressBus->X),
new ConnectionFour(dataBus->W, counter->D),
new ConnectionFour(addressBus->W, memorySys->MARD),
new ConnectionFour(memorySys->WD, dataBus->X),
new ConnectionFour(dataBus->W, out->D),
//LED's
new ConnectionFour(out->Q, ard, 33,1)
};
//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
MARL
RAMW
DS
OUTL
COUNT
PCW
OUT
RAML
PCL