-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
151 lines (130 loc) · 6.36 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*
Authors:
- Henry Schuler
*/
// Include local header files
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
#include "..\4004\4004.h"
#elif __unix__
#include "../4004/4004.h"
#endif
// Include global header files
#include <iostream>
#include <iomanip>
// Declaring namespaces
using namespace std;
// Declaring functions
void functionIntel4004();
bool functionPrintProcessorState(Intel4004Base *processor);
// MAIN
int main() {
functionIntel4004();
return 0;
}
// Functions
void functionIntel4004() {
// Instantiate an Intel4004 processor
Intel4004Base *processor = { get4004Instance(0xFFFF, 0xFFFFFFFF) };
// Access RAM Module
Intel4002Base *RAM = processor->getPtrToRAM();
// Access ROM Module
Intel4001Base *ROM = processor->getPtrToROM();
// Access Stack Module
Intel4004StackBase *Stack = processor->getPtrToStack();
// Write to ROM
// Array containing Commands (FIM_0 0xFF, NOP)
uint8_t source[] = { 0x50, 0xFF, 0x00 };
processor->getPtrToROM()->writeFrom(source, sizeof(source));
// IntelHex file
/**
* processor->getPtrToROM()->writeFromIntelHexFile("hexFilePath");
*/
// Binary file
/**
* processor->getPtrToROM()->writeFromBinaryFile("binaryFilePath");
*/
// Get a copy of the current Stack
UBankedAddress *copyStack = new UBankedAddress[3]();
processor->getPtrToStack()->getCopyOfStack(copyStack);
// Here you can access the copyStack array -> check the Elements on the stack
delete copyStack;
// Perform next command operation
processor->nextCommand();
// View current state of processor
functionPrintProcessorState(processor);
delete processor;
}
bool functionPrintProcessorState(Intel4004Base *processor) {
/**
* This function was just created as an addition. There is no guarantee for correctness.
*/
cout << "---- Intel4004 Emulation ----" << endl << endl;
cout << "Intel4004 CPU:" << endl;
cout << setw(8) << "PC " << hex << setw(3) << setfill('0') << (int) processor->getPC().raw << dec << setfill(' ') << endl;
UBankedAddress stackCopy[3];
processor->getPtrToStack()->getCopyOfStack(stackCopy);
cout << setw(8) << "Level 1 " << hex << setw(3) << setfill('0') << (int) stackCopy[(processor->getPtrToStack()->getCurrentStackPosition() + 2) % 3].raw << dec << setfill(' ') << endl;
cout << setw(8) << "Level 2 " << hex << setw(3) << setfill('0') << (int) stackCopy[processor->getPtrToStack()->getCurrentStackPosition() % 3].raw << dec << setfill(' ') << endl;
cout << setw(8) << "Level 3 " << hex << setw(3) << setfill('0') << (int) stackCopy[(processor->getPtrToStack()->getCurrentStackPosition() + 1) % 3].raw << dec << setfill(' ') << endl;
cout << endl;
cout << "Registers:" << endl;
cout << "R0R1 " << hex << (int) processor->getRegister(R0) << " " << (int) processor->getRegister(R1) << dec << endl;
cout << "R2R3 " << hex << (int) processor->getRegister(R2) << " " << (int) processor->getRegister(R3) << dec << endl;
cout << "R4R5 " << hex << (int) processor->getRegister(R4) << " " << (int) processor->getRegister(R5) << dec << endl;
cout << "R6R7 " << hex << (int) processor->getRegister(R6) << " " << (int) processor->getRegister(R7) << dec << endl;
cout << "R8R9 " << hex << (int) processor->getRegister(R8) << " " << (int) processor->getRegister(R9) << dec << endl;
cout << "RARB " << hex << (int) processor->getRegister(R10) << " " << (int) processor->getRegister(R11) << dec << endl;
cout << "RCRD " << hex << (int) processor->getRegister(R12) << " " << (int) processor->getRegister(R13) << dec << endl;
cout << "RERF " << hex << (int) processor->getRegister(R14) << " " << (int) processor->getRegister(R15) << dec << endl;
cout << endl;
cout << "Accumulator: " << setw(1) << setfill('0') << hex << (int) processor->getAccumulator() << dec << setfill(' ') << endl;
cout << endl;
cout << "Carry: " << setw(1) << setfill('0') << hex << processor->getCarry() << " Test: " << setw(1) << setfill('0') << processor->getTestPin() << dec << setfill(' ') << endl;
cout << endl;
cout << endl;
cout << "Intel4002 RAM:" << endl;
cout << endl;
for (int l = 0; l < 8; l++) {
cout << "Bank " << l << endl;
for (int k = 0; k < 4; k++) {
cout << "Chip " << k << endl;
cout << endl;
cout << setw(10) << " " << "0 1 2 3 4 5 6 7 8 9 A B C D E F" << setw(4) << " " << "0 1 2 3" << endl;
for (int j = 0; j < 4; j++) {
cout << setw(8) << "Register" << j << " ";
for (int i = 0; i < 16; i++) {
cout << hex << (int) processor->getPtrToRAM()->readRAMNibble((ERAMBank) l, (ERAMChip) k, (ERAMRegister) j, i) << " " << dec;
}
cout << setw(3) << " ";
for (int i = 0; i < 4; i++) {
cout << hex << (int) processor->getPtrToRAM()->readStatusNibble((ERAMBank) l, (ERAMChip) k, (ERAMRegister) j, i) << " " << dec;
}
cout << endl;
}
cout << endl;
uint4_t ramPort = processor->getPtrToRAM()->readFromPortBuffer((ERAMBank) l, (ERAMChip) k);
cout << "Port " << (int) ((ramPort & 0b1000) >> 3) << " " << (int) ((ramPort & 0b0100) >> 2) << " " << (int) ((ramPort & 0b0010) >> 1) << " " << (int) ((ramPort & 0b0001) >> 0) << endl;
cout << endl;
}
}
cout << endl;
cout << "Intel4001 ROM:" << endl;
cout << endl;
for (int i = 0; i < 16; i++) {
cout << "Chip " << i << endl;
cout << endl;
cout << " 0 1 2 3 4 5 6 7 8 9 A B C D E F 0 1 2 3 4 5 6 7 8 9 A B C D E F " << endl;
for (int j = 0; j < 8; j++) {
for (int k = 0; k < 32; k++) {
cout << hex << setw(2) << setfill('0') << (int) processor->getPtrToROM()->read((UBankedAddress) ((i * 256) + (j * 32) + k)) << " " << setfill(' ') << dec;
}
cout << endl;
}
cout << endl;
uint4_t romPort = processor->getPtrToROM()->readFromPort((EROMChip) i);
cout << "Port " << (int) ((romPort & 0b1000) >> 3) << " " << (int) ((romPort & 0b0100) >> 2) << " " << (int) ((romPort & 0b0010) >> 1) << " " << (int) ((romPort & 0b0001) >> 0) << endl;
cout << endl;
}
cout << endl;
return true;
}