-
Notifications
You must be signed in to change notification settings - Fork 0
/
cop0.c
44 lines (36 loc) · 1.24 KB
/
cop0.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
#include <stdio.h>
#include "cop0.h"
void write_cop0_instruction(const unsigned char* instruction, FILE* file) {
unsigned char opcode = get_cop0_opcode(instruction);
switch (opcode) {
case 0b00000:
fputs("mfc0 ", file);
write_cop0_instruction_rest(instruction, file);
break;
case 0b00100:
fputs("mtc0 ", file);
write_cop0_instruction_rest(instruction, file);
break;
default:
printf("Unsupported cop0 opcode: %x\n", opcode);
break;
}
}
void write_cop0_instruction_rest(const unsigned char* instruction, FILE* file) {
fprintf(file, "%d, ", get_cop0_rt(instruction));
fprintf(file, "%d", get_cop0_rd(instruction));
}
unsigned char get_cop0_opcode(const unsigned char* instruction) {
unsigned char opcode0 = instruction[0] & 0b00000011;
unsigned char opcode1 = instruction[1] & 0b11100000;
opcode0 = opcode0 << 3;
opcode1 = opcode1 >> 5;
return opcode0 | opcode1;
}
unsigned char get_cop0_rt(const unsigned char* instruction) {
return instruction[1] & 0b00011111;
}
unsigned char get_cop0_rd(const unsigned char* instruction) {
unsigned char rd = instruction[2] & 0b11111000;
return rd >> 3;
}