-
Notifications
You must be signed in to change notification settings - Fork 0
/
CPU.h
100 lines (90 loc) · 1.41 KB
/
CPU.h
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
#pragma once
#include <iostream>
#include <string>
enum Opcode
{
null = 0, //CPU::_null()
R_read, //CPU::R_read()
write, //CPU::_write()
R_write, //CPU::R_write()
add, //CPU::_add()
R_add, //CPU::R_add()
subtract, //CPU::_sub()
jump, //CPU::_jump()
jumpgt, //CPU::_jumpgt()
jumplt, //CPU::_jumplt()
move, //CPU::_move()
out, //CPU::_out()
pause, //CPU::_pause()
halt //CPU::_halt()
};
struct Instruction
{
int opcode;
int size;
void (*funcPtr)();
};
struct ASM
{
Instruction null;
Instruction R_read;
Instruction write;
Instruction R_write;
Instruction add;
Instruction R_add;
Instruction subtract;
Instruction jump;
Instruction jumpgt;
Instruction jumplt;
Instruction move;
Instruction out;
Instruction pause;
Instruction halt;
};
struct Ram
{
int size = 255 * 255;
int memory[255 * 255]{ 0 };
};
struct Var
{
int loc[255]{ 0 };
int size = 255;
};
struct Registers
{
bool halt = false;
int pc = 0;
Var var;
};
class CPU
{
public:
CPU();
~CPU();
void run();
void step();
void print(int addr);
void write(int arg1, int arg2);
private:
Registers registers;
Ram ram;
ASM Assembly;
private:
void _decode();
void _null();
void R_read();
void _write();
void R_write();
void _add();
void R_add();
void _sub();
void _jump();
void _jumpgt();
void _jumplt();
void _move();
void _out();
void _pause();
void _halt();
void _dumpIns(int addr);
};