-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathemulator.c
93 lines (85 loc) · 2.69 KB
/
emulator.c
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
#include <stdio.h>
#include <stdlib.h>
// checks if a valid register is accessed (by testing if op < 8)
// exits if op >= 8 as it makes the instruction illegal
void check_index(unsigned char op)
{
if(op < 8) {
return;
}
else {
printf("Illegal instruction\n");
exit(-1);
}
}
unsigned char memory[256] = {
0x00,0x00,0x80,0x00,0x01,0x00,0x00,0x02,0x1C,0x03,0x00,0x01,0x08,0x03,0x00,0x02,
0x03,0x07,0x05,0x03,0x00,0x04,0x00,0x01,0x01,0x01,0x01,0x02,0x02,0x01,0x06,0x02,
0x09,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x6d,0x73,0x68,0x6e,0x82,0x7a,0x37,0x66,0x7a,0x3a,0x6a,0x79,0x3a,0x7b,0x66,0x80,
0x3a,0x7b,0x66,0x7a,0x37,0x66,0x6d,0x79,0x3a,0x3a,0x84,0x11,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
unsigned char registers[8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
int main ()
{
int instruction_pointer = 0;
while(1) {
unsigned char op0 = memory[instruction_pointer+0];
unsigned char op1 = memory[instruction_pointer+1];
unsigned char op2 = memory[instruction_pointer+2];
instruction_pointer += 3;
switch(op0) {
case 0x00:
check_index(op1);
// UNIMPLEMENTED
case 0x01:
check_index(op1);
// UNIMPLEMENTED
case 0x02:
check_index(op1);
// UNIMPLEMENTED
case 0x03:
check_index(op1);
check_index(op2);
// UNIMPLEMENTED
case 0x04:
check_index(op1);
check_index(op2);
// UNIMPLEMENTED
case 0x05:
check_index(op1);
// UNIMPLEMENTED
case 0x06:
check_index(op1);
// UNIMPLEMENTED
case 0x07:
check_index(op1);
// UNIMPLEMENTED
case 0x08:
check_index(op1);
check_index(op2);
// UNIMPLEMENTED
case 0x09:
check_index(op1);
check_index(op2);
// UNIMPLEMENTED
case 0xff:
// UNIMPLEMENTED
default:
printf("Illegal instruction\n");
return -1;
}
}
return 0;
}