-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInstructionTypes.hpp
167 lines (149 loc) · 3.13 KB
/
InstructionTypes.hpp
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#pragma once
#include "InstructionEnums.hpp"
#include <string>
#include <sstream>
// using technically undefined behaviour but it's generally supported
union instruction_union
{
instruction_union()
{
raw = 0x0;
}
instruction_union(cpu_instructions op, unsigned int rs, unsigned int rt, unsigned int immediate)
{
immediate_instruction.op = static_cast<unsigned int>(op);
immediate_instruction.rs = rs;
immediate_instruction.rt = rt;
immediate_instruction.immediate = immediate;
}
instruction_union(cpu_instructions op, unsigned int target)
{
jump_instruction.op = static_cast<unsigned int>(op);
jump_instruction.target = target;
}
instruction_union(cpu_instructions op, unsigned int rs, unsigned int rt, unsigned int rd, unsigned int shamt, cpu_special_funcs funct)
{
register_instruction.op = static_cast<unsigned int>(op);
register_instruction.rs = rs;
register_instruction.rt = rt;
register_instruction.rd = rd;
register_instruction.shamt = shamt;
register_instruction.funct = static_cast<unsigned int>(funct);
}
instruction_union(unsigned int value)
{
raw = value;
}
unsigned int raw;
struct
{
unsigned int immediate : 16;
unsigned int rt : 5;
unsigned int rs : 5;
unsigned int op : 6;
} immediate_instruction;
struct
{
unsigned int target : 26;
unsigned int op : 6;
} jump_instruction;
struct
{
unsigned int funct : 6;
unsigned int shamt : 5;
unsigned int rd : 5;
unsigned int rt : 5;
unsigned int rs : 5;
unsigned int op : 6;
} register_instruction;
};
union gp_command
{
unsigned int raw;
struct
{
signed short x;
signed short y;
} vert;
struct
{
unsigned short data0;
unsigned short data1;
} pixel_data;
struct
{
unsigned int tex_x : 8;
unsigned int tex_y : 8;
unsigned int clut_x : 6;
unsigned int clut_y : 9;
unsigned int na : 1;
} tex_palette;
struct
{
unsigned int tex_x : 8;
unsigned int tex_y : 8;
unsigned int tex_page_base_x : 4;
unsigned int tex_page_base_y : 1;
unsigned int semi_transparency : 2;
unsigned int tex_page_colors : 2;
unsigned int na1 : 2;
unsigned int tex_disable : 1;
unsigned int na2 : 4;
} tex_page;
struct
{
unsigned int x_pos : 10;
unsigned int na0 : 6;
unsigned int y_pos : 9;
unsigned int na1 : 7;
} dest_coord;
struct
{
unsigned int x_coord : 10;
unsigned int y_coord : 9;
unsigned int na1 : 5;
// only on newer GPUs
unsigned int y_coord2 : 10;
unsigned int na2 : 4;
unsigned int op : 8;
} draw_area;
struct
{
unsigned int x_siz : 10;
unsigned int na0 : 6;
unsigned int y_siz : 9;
unsigned int na1 : 7;
} dims;
struct
{
unsigned char b;
unsigned char g;
unsigned char r;
unsigned char op;
} color;
struct
{
int x_offset : 11;
int y_offset : 11;
unsigned int na : 10;
} draw_offset;
struct
{
unsigned int horizontal_res : 2;
unsigned int vertical_res : 1;
unsigned int video_mode : 1;
unsigned int display_color_depth : 1;
unsigned int vertical_interlace : 1;
unsigned int horizontal_res_2 : 1;
unsigned int reverse_flag : 1;
unsigned int na : 24;
} display_mode;
gp_command(unsigned int val)
{
raw = val;
}
gp_command()
{
raw = 0x0;
}
};