-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.cpp
51 lines (46 loc) · 1.48 KB
/
index.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
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <fstream>
#include <memory>
#include "CPU.h"
int main(int argc, char** argv) {
CPU cpu;
cpu.mem = std::make_unique<Memory>();
std::string filename = argv[1];
std::ifstream infile(filename, std::ios::binary);
infile.seekg(0, std::ios::end);
size_t size = infile.tellg();
infile.seekg(0, std::ios::beg);
// memory.data = new BYTE[(int)std::pow(2,16)*sizeof(BYTE)];
// malloc enough memory for 64KB OF DATA.
cpu.mem->data = std::vector<BYTE>(std::pow(16,4));
// infile.read((char*)(memory.data+0x8000), size);
char* buffer = new char[size];
infile.read(buffer, size);
infile.close();
std::fill(cpu.mem->data.begin(), cpu.mem->data.end(), 0);
for(int i = 0; i < size; i++) {
cpu.mem->data[i+0x8000] = buffer[i];
}
cpu.Reset(cpu.mem);
// std::cout << cpu._BRK << std::endl;
// std::cout << "---------------------------------------" << std::endl;
// clear logs.txt file:
std::ofstream ofs;
ofs.open("logs.txt", std::ofstream::out | std::ofstream::trunc);
ofs.close();
cpu.Log();
while(cpu.BR == 0) {
cpu.Step(cpu.mem);
cpu.Log();
}
// dump memory into file memory.bin
std::ofstream outfile("memory.bin", std::ios::binary);
outfile.write((char*)cpu.mem->data.data(), (int)(65536 * sizeof(unsigned char)));
outfile.close();
// free(memory.data);
return 0;
}