-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcpu.h
82 lines (71 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
//
// cpu.h
// dcpu-deibit
//
// Created by david on 26/7/16.
//
//
#pragma once
#include <cstdlib>
#include <map>
#include <string>
#include <iostream>
#include <vector>
using word = std::uint16_t;
class Memory;
class Hardware;
enum : word {
A = 0x00,
B = 0x01,
C = 0x02,
X = 0x03,
Y = 0x04,
Z = 0x05,
I = 0x06,
J = 0x07,
SP = 0x1b,
PC = 0x1c,
EX = 0x1d,
IA = 0xd // There is not hardcode value for IA in the specs
};
struct Instruction {
word a;
word b;
word o;
};
struct Context {
void reset();
word& operator[](word);
word registers[12] = {};
};
class CPU {
public:
CPU();
virtual ~CPU();
void boot(const std::string filename);
void run();
void reset();
void dump();
Context& context();
private:
unsigned cycles;
bool halt; // and
bool catch_fire;
Context* ctx;
Memory* memory;
bool queuing;
std::vector<int> iq;
std::vector<Hardware*> devices;
static const word mask_5 = 0x1f; // 0b11111
static const word mask_6 = 0x3f; // 0b111111
unsigned step();
unsigned special(const Instruction&, word&);
word fetch();
void skip();
const Instruction decode(word);
//TODO Probably we can use here a std::pair<word,word&>
// or similar and have just one function
word& decode_value(word);
word decode_hardcoded(word);
void interrupt(word);
};