This repository has been archived by the owner on Feb 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvif.h
181 lines (162 loc) · 3.18 KB
/
vif.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
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#pragma once
#include <int128.h>
#include <gs/queue.h>
#include <array>
class Bus;
union VIFSTAT
{
uint32_t value = 0;
struct
{
uint32_t vif_status : 2;
uint32_t e_wait : 1;
uint32_t waiting_for_gif : 1;
uint32_t : 2;
uint32_t mark : 1;
uint32_t double_buffer_flag : 1;
uint32_t stalled_after_stop : 1;
uint32_t stalled_on_intr : 1;
uint32_t intr_detected : 1;
uint32_t dmatag_mismatch : 1;
uint32_t invalid_cmd : 1;
uint32_t : 9;
uint32_t fifo_detection : 1;
uint32_t fifo_count : 5;
};
};
union VIFFBRST
{
uint8_t value = 0;
struct
{
uint8_t reset : 1;
uint8_t force_break : 1;
uint8_t stop_vif : 1;
uint8_t stall_cancel : 1;
};
};
union VIFCYCLE
{
uint16_t value;
struct
{
uint16_t cycle_length : 8;
uint16_t write_cycle_length;
};
};
union VIFCommand
{
uint32_t value;
struct
{
union
{
uint16_t immediate;
struct
{
uint16_t address : 10;
uint16_t : 4;
uint16_t sign_extend : 1;
uint16_t flg : 1;
};
};
uint8_t num;
union
{
uint8_t command;
struct
{
uint8_t vl : 2;
uint8_t vn : 2;
uint8_t mask : 1;
};
};
};
};
enum VIFCommands
{
VNOP = 0x0,
STCYCL = 0x1,
OFFSET = 0x2,
BASE = 0x3,
ITOP = 0x4,
STMOD = 0x5,
MSKPATH3 = 0x6,
MARK = 0x7,
FLUSHE = 0x10,
FLUSH = 0x11,
FLUSHA = 0x13,
MSCAL = 0x14,
MSCALF = 0x15,
MSCNT = 0x17,
STMASK = 0x20,
STROW = 0x30,
STCOL = 0x31,
MPG = 0x4A,
DIRECT = 0x50,
DIRECTHL = 0x51,
UNPACKSTART = 0x60,
UNPACKEND = 0x7F
};
enum VIFUFormat
{
S_32 = 0,
S_16 = 1,
S_8 = 2,
V2_32 = 4,
V2_16 = 5,
V2_8 = 6,
V3_32 = 8,
V3_16 = 9,
V3_8 = 10,
V4_32 = 12,
V4_16 = 13,
V4_8 = 14,
V4_5 = 15
};
enum WriteMode : bool
{
Skipping = 0,
Filling = 1
};
class VIF
{
public:
VIF(Bus* parent, int n);
~VIF() = default;
void tick(uint32_t cycles);
void reset();
template<typename T>
bool write_fifo(uint32_t, T data);
uint32_t read(uint32_t address);
void write(uint32_t address, uint32_t data);
private:
void process_command();
void process_unpack();
void execute_command();
void unpack_packet();
private:
Bus* bus;
int id;
VIFSTAT status = {};
VIFFBRST fbrst = {};
uint32_t err = 0, mark = 0;
VIFCYCLE cycle;
uint32_t mode = 0, num = 0;
uint32_t mask = 0, code = 0, itops = 0;
// VIF1 only
uint32_t base = 0, ofst = 0;
uint32_t tops = 0, itop = 0, top = 0;
std::array<uint32_t, 4> rn = {}, cn = {};
// End VIF1 only
util::Queue<uint32_t, 64> fifo;
WriteMode write_mode = WriteMode::Skipping;
VIFCommand command = {};
uint32_t subpacket_count = 0, address = 0;
uint32_t qwords_written = 0, word_cycles = 0;
};
template<typename T>
inline bool VIF::write_fifo(uint32_t, T data)
{
return fifo.push<T>(data);
}