-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemulator_execute.c
77 lines (73 loc) · 1.55 KB
/
emulator_execute.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
#include "emulator.h"
#include <stdlib.h>
void emulator_execute(Emulator *emu, uint16_t instr) {
/*types of instructions
op N N N
op X N N
op X Y N
*/
uint16_t NNN;
uint8_t op, X, Y, N, NN;
op = (uint8_t) (instr >> 12 & 0xF);
X = (uint8_t) (instr >> 8 & 0xF);
Y = (uint8_t) (instr >> 4 & 0xF);
N = (uint8_t) (instr & 0xF);
NN = (uint8_t) (instr & 0x00FF);
NNN = (instr & 0x0FFF);
switch (op) {
case 0x0:
if (N == 0x0) {
// TO DO clear screen
} else {
emu->program_counter = emu->stack[emu->stack_pointer];
emu->stack_pointer = emu->stack_pointer - 1;
}
break;
case 0x1:
emu->program_counter = NNN;
break;
case 0x2:
emu->stack_pointer = emu->stack_pointer + 1;
emu->stack[emu->stack_pointer] = emu->program_counter;
emu->program_counter = NNN;
break;
case 0x3:
if (emu->registers[X] == NN)
emu->program_counter += 2;
break;
case 0x4:
if (emu->registers[X] != NN)
emu->program_counter += 2;
break;
case 0x5:
if (emu->registers[X] == emu->registers[Y])
emu->program_counter += 2;
break;
case 0x6:
emu->registers[X] = NN;
break;
case 0x7:
emu->registers[X] += NN;
break;
case 0x9:
if (emu->registers[X] != emu->registers[Y])
emu->program_counter += 2;
break;
case 0xA:
emu->address_register = NNN;
break;
case 0xB:
emu->program_counter = NNN + emu->registers[0];
break;
case 0xC:
emu->registers[X] = (uint8_t) (rand() & NN);
break;
case 0xD:
// TO DO display
case 0xE:
// TO DO keypress
case 0xF:
case 0x8:
break;
}
}