/*
See https://blog.jochumzen.com/ entry 28
Testing the Instruction register (IR).
RAM is programmed with:
0: LDA (1)
1: 8
2: MOV B,A (6)
3: LDA (1)
4: 9
5: ADD (2)
6: MOV OUT,A (7)
7: HLT (5)
8: 5
9: 3
We want to move the opcodes to the IR
1. Move the content of PC to MAR (address = 0 in RAM)
2. Move the content of RAM at address 0 (the number 1) to the IR. IR now holds 0001 or "LDA"
3. Increment PC twice
4. Move the content of PC to MAR (address = 2 in RAM)
5. Move the content of RAM at address 2 (the number 6) to the IR. IR now holds 0110 or "MOV B,A"
6. Increment PC
7. Move the content of PC to MAR (address = 3 in RAM)
8. Move the content of RAM at address 3 (the number 1) to the IR. IR now holds 0001 or "LDA"
9. Continue until IR holds 0101 or "HLT"
Click Print. Observe RAM and that correct data has been programmed.
Move the first instruction:
Click and hold PCW, MARL (press 3 and 5 on keyboard)
Click Clock to latch
Click and hold RAMW, IRL (press 7 and 8 on keyboard)
Click Clock to latch
Observe LEDs: 0001 means LDA
Move the second instruction:
Click and hold COUNT (4)
Click Clock to latch twice
Click and hold PCW, MARL (press 3 and 5 on keyboard)
Click Clock to latch
Click and hold RAMW, IRL (press 7 and 8 on keyboard)
Click Clock to latch
Observe LEDs: 0110 means MOV B,A
Move the remaining instructions to the IR. Increment count by 1 or 2 depending on the opcode
*/
//Library with basic gates
#include <ACEL.h>
byte data[16] = {1,8,6,1,9,2,7,5,5,3,0,0,0,0,0,0};
//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(data);
auto* ir = new FourBitRegister((char*)("Register OUT"));
auto* counter = new FourBitProgramCounter((char*)("Program counter"));
//Add all chips to be emulated here
Chip* chips[] = {
dataBus, addressBus, memorySys, ir, 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,ir->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,ir->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, ir->D),
//LED's
new ConnectionFour(ir->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
IRL
COUNT
PCW
IR
RAML
PCL