PS2SDK
PS2 Homebrew Libraries
Loading...
Searching...
No Matches
packet2_vif.h
1/*
2# _____ ___ ____ ___ ____
3# ____| | ____| | | |____|
4# | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
5#-----------------------------------------------------------------------
6# (c) 2020 h4570 Sandro Sobczyński <sandro.sobczynski@gmail.com>
7# Licenced under Academic Free License version 2.0
8# Review ps2sdk README & LICENSE files for further details.
9*/
10
19#ifndef __PACKET2_VIF_H__
20#define __PACKET2_VIF_H__
21
22#include <packet2.h>
23#include <packet2_types.h>
24#include <assert.h>
25
26#define MAKE_VIF_CODE(_immediate, _num, _cmd, _irq) ((u32)(_immediate) | ((u32)(_num) << 16) | ((u32)(_cmd) << 24) | ((u32)(_irq) << 31))
27
28#ifdef __cplusplus
29extern "C"
30{
31#endif
32
50 static inline void packet2_vif_open_unpack(packet2_t *packet2, enum UnpackMode mode, u32 vuAddr, u8 dblBuffered, u8 masked, u8 usigned, u8 irq)
51 {
52 assert(packet2->vif_code_opened_at == NULL); // All previous UNPACK/DIRECT are closed.
53 packet2->vif_code_opened_at = (vif_code_t *)packet2->next;
54 packet2_add_u32(packet2,
55 MAKE_VIF_CODE(vuAddr | ((u32)usigned << 14) | ((u32)dblBuffered << 15),
56 0,
57 mode | ((u32)masked << 4) | 0x60, irq));
58 }
59
68 static inline void packet2_vif_close_unpack_manual(packet2_t *packet2, u32 unpack_num)
69 {
70 assert(packet2->vif_code_opened_at != NULL); // There is open UNPACK/DIRECT.
71 assert(((u32)packet2->next & 0x3) == 0); // Make sure we're u32 aligned
72 assert((packet2->vif_code_opened_at->cmd & 0x60) == 0x60); // It was UNPACK
73 assert(unpack_num <= 256);
74 packet2->vif_code_opened_at->num = (unpack_num == 256) ? 0 : unpack_num;
75 packet2->vif_code_opened_at = (vif_code_t *)NULL;
76 }
77
87 u32 packet2_vif_close_unpack_auto(packet2_t *packet2, u32 wl, u32 cl);
88
95 static inline void packet2_vif_open_direct(packet2_t *packet2, u8 irq)
96 {
97 assert(packet2->vif_code_opened_at == NULL); // All previous UNPACK/DIRECT are closed.
98 packet2->vif_code_opened_at = (vif_code_t *)packet2->next;
99 packet2_add_u32(packet2, MAKE_VIF_CODE(0, 0, P2_VIF_DIRECT, irq));
100 }
101
109 static inline void packet2_vif_close_direct_manual(packet2_t *packet2, u32 qwords)
110 {
111 assert(packet2->vif_code_opened_at != NULL); // There is open UNPACK/DIRECT.
112 assert((((u32)packet2->next - ((u32)packet2->vif_code_opened_at + 4)) & 0xF) == 0);
113 packet2->vif_code_opened_at->immediate = qwords;
114 packet2->vif_code_opened_at = (vif_code_t *)NULL;
115 }
116
123 static inline void packet2_vif_close_direct_auto(packet2_t *packet2)
124 {
125 return packet2_vif_close_direct_manual(packet2, ((u32)packet2->next - ((u32)packet2->vif_code_opened_at + 4)) >> 4);
126 }
127
135 static inline void packet2_vif_nop(packet2_t *packet2, u8 irq)
136 {
137 packet2_add_u32(packet2, MAKE_VIF_CODE(0, 0, P2_VIF_NOP, irq));
138 }
139
144 static inline void packet2_vif_pad96(packet2_t *packet2)
145 {
146 packet2_pad96(packet2, MAKE_VIF_CODE(0, 0, P2_VIF_NOP, 0));
147 }
148
153 static inline void packet2_vif_pad128(packet2_t *packet2)
154 {
155 packet2_pad128(packet2, MAKE_VIF_CODE(0, 0, P2_VIF_NOP, 0));
156 }
157
167 static inline void packet2_vif_mpg(packet2_t *packet2, u32 num, u32 addr, u8 irq)
168 {
169 packet2_add_u32(packet2, MAKE_VIF_CODE(addr, num, P2_VIF_MPG, irq));
170 }
171
181 static inline void packet2_vif_stcycl(packet2_t *packet2, u32 wl, u32 cl, u8 irq)
182 {
183 packet2_add_u32(packet2, MAKE_VIF_CODE(cl | (wl << 8), 0, P2_VIF_STCYCL, irq));
184 }
185
194 static inline void packet2_vif_offset(packet2_t *packet2, u32 offset, u8 irq)
195 {
196 packet2_add_u32(packet2, MAKE_VIF_CODE(offset, 0, P2_VIF_OFFSET, irq));
197 }
198
207 static inline void packet2_vif_base(packet2_t *packet2, u32 base, u8 irq)
208 {
209 packet2_add_u32(packet2, MAKE_VIF_CODE(base, 0, P2_VIF_BASE, irq));
210 }
211
219 static inline void packet2_vif_flush(packet2_t *packet2, u8 irq)
220 {
221 packet2_add_u32(packet2, MAKE_VIF_CODE(0, 0, P2_VIF_FLUSH, irq));
222 }
223
232 static inline void packet2_vif_mscal(packet2_t *packet2, u32 addr, u8 irq)
233 {
234 packet2_add_u32(packet2, MAKE_VIF_CODE(addr, 0, P2_VIF_MSCAL, irq));
235 }
236
244 static inline void packet2_vif_mscnt(packet2_t *packet2, u8 irq)
245 {
246 packet2_add_u32(packet2, MAKE_VIF_CODE(0, 0, P2_VIF_MSCNT, irq));
247 }
248
257 static inline void packet2_vif_itop(packet2_t *packet2, u32 itops, u8 irq)
258 {
259 packet2_add_u32(packet2, MAKE_VIF_CODE(itops, 0, P2_VIF_ITOP, irq));
260 }
261
270 static inline void packet2_vif_stmod(packet2_t *packet2, u32 mode, u8 irq)
271 {
272 packet2_add_u32(packet2, MAKE_VIF_CODE(mode, 0, P2_VIF_STMOD, irq));
273 }
274
283 static inline void packet2_vif_mskpath3(packet2_t *packet2, u32 mask, u8 irq)
284 {
285 packet2_add_u32(packet2, MAKE_VIF_CODE(mask, 0, P2_VIF_MSKPATH3, irq));
286 }
287
296 static inline void packet2_vif_mark(packet2_t *packet2, u32 value, u8 irq)
297 {
298 packet2_add_u32(packet2, MAKE_VIF_CODE(value, 0, P2_VIF_MARK, irq));
299 }
300
308 static inline void packet2_vif_flushe(packet2_t *packet2, u8 irq)
309 {
310 packet2_add_u32(packet2, MAKE_VIF_CODE(0, 0, P2_VIF_FLUSHE, irq));
311 }
312
320 static inline void packet2_vif_flusha(packet2_t *packet2, u8 irq)
321 {
322 packet2_add_u32(packet2, MAKE_VIF_CODE(0, 0, P2_VIF_FLUSHA, irq));
323 }
324
333 static inline void packet2_vif_mscalf(packet2_t *packet2, u32 addr, u8 irq)
334 {
335 packet2_add_u32(packet2, MAKE_VIF_CODE(addr, 0, P2_VIF_MSCALF, irq));
336 }
337
346 static inline void packet2_vif_stmask(packet2_t *packet2, Mask mask, u8 irq)
347 {
348 packet2_add_u32(packet2, MAKE_VIF_CODE(0, 0, P2_VIF_STMASK, irq));
349 packet2_add_u32(packet2, mask.m);
350 }
351
360 static inline void packet2_vif_strow(packet2_t *packet2, const u32 *row_arr, u8 irq)
361 {
362 packet2_add_u32(packet2, MAKE_VIF_CODE(0, 0, P2_VIF_STROW, irq));
363 packet2_add_u32(packet2, row_arr[0]);
364 packet2_add_u32(packet2, row_arr[1]);
365 packet2_add_u32(packet2, row_arr[2]);
366 packet2_add_u32(packet2, row_arr[3]);
367 }
368
377 static inline void packet2_vif_stcol(packet2_t *packet2, const u32 *col_arr, u8 irq)
378 {
379 packet2_add_u32(packet2, MAKE_VIF_CODE(0, 0, P2_VIF_STCOL, irq));
380 packet2_add_u32(packet2, col_arr[0]);
381 packet2_add_u32(packet2, col_arr[1]);
382 packet2_add_u32(packet2, col_arr[2]);
383 packet2_add_u32(packet2, col_arr[3]);
384 }
385
393 void packet2_vif_add_micro_program(packet2_t *packet2, u32 dest, u32 *start, u32 *end);
394
395#ifdef __cplusplus
396}
397#endif
398
399#endif /* __PACKET2_VIF_H__ */
400
// end of packet2_vif subgroup
vif_code_t * vif_code_opened_at
qword_t * next
UnpackMode
@ P2_VIF_MSKPATH3
@ P2_VIF_STROW
@ P2_VIF_MPG
@ P2_VIF_STMASK
@ P2_VIF_MSCAL
@ P2_VIF_STCOL
@ P2_VIF_OFFSET
@ P2_VIF_MSCALF
@ P2_VIF_FLUSHE
@ P2_VIF_FLUSH
@ P2_VIF_NOP
@ P2_VIF_STCYCL
@ P2_VIF_STMOD
@ P2_VIF_ITOP
@ P2_VIF_MSCNT
@ P2_VIF_DIRECT
@ P2_VIF_BASE
@ P2_VIF_FLUSHA
@ P2_VIF_MARK
static void packet2_vif_strow(packet2_t *packet2, const u32 *row_arr, u8 irq)
static void packet2_vif_mscal(packet2_t *packet2, u32 addr, u8 irq)
static void packet2_vif_close_unpack_manual(packet2_t *packet2, u32 unpack_num)
Definition packet2_vif.h:68
static void packet2_vif_base(packet2_t *packet2, u32 base, u8 irq)
static void packet2_vif_flusha(packet2_t *packet2, u8 irq)
static void packet2_vif_flushe(packet2_t *packet2, u8 irq)
static void packet2_vif_stcol(packet2_t *packet2, const u32 *col_arr, u8 irq)
static void packet2_vif_pad128(packet2_t *packet2)
static void packet2_vif_pad96(packet2_t *packet2)
static void packet2_vif_mark(packet2_t *packet2, u32 value, u8 irq)
void packet2_vif_add_micro_program(packet2_t *packet2, u32 dest, u32 *start, u32 *end)
Definition packet2_vif.c:14
static void packet2_vif_close_direct_auto(packet2_t *packet2)
static void packet2_vif_open_unpack(packet2_t *packet2, enum UnpackMode mode, u32 vuAddr, u8 dblBuffered, u8 masked, u8 usigned, u8 irq)
Definition packet2_vif.h:50
static void packet2_vif_nop(packet2_t *packet2, u8 irq)
static void packet2_vif_stmod(packet2_t *packet2, u32 mode, u8 irq)
static void packet2_vif_mskpath3(packet2_t *packet2, u32 mask, u8 irq)
static void packet2_vif_mscalf(packet2_t *packet2, u32 addr, u8 irq)
static void packet2_vif_stcycl(packet2_t *packet2, u32 wl, u32 cl, u8 irq)
static void packet2_vif_mscnt(packet2_t *packet2, u8 irq)
static void packet2_vif_mpg(packet2_t *packet2, u32 num, u32 addr, u8 irq)
static void packet2_vif_stmask(packet2_t *packet2, Mask mask, u8 irq)
static void packet2_vif_flush(packet2_t *packet2, u8 irq)
static void packet2_vif_open_direct(packet2_t *packet2, u8 irq)
Definition packet2_vif.h:95
static void packet2_vif_offset(packet2_t *packet2, u32 offset, u8 irq)
u32 packet2_vif_close_unpack_auto(packet2_t *packet2, u32 wl, u32 cl)
Definition packet2_vif.c:34
static void packet2_vif_close_direct_manual(packet2_t *packet2, u32 qwords)
static void packet2_vif_itop(packet2_t *packet2, u32 itops, u8 irq)
static void packet2_pad128(packet2_t *packet2, const u32 val)
Definition packet2.h:173
static void packet2_add_u32(packet2_t *packet2, const u32 val)
Definition packet2.h:134
static void packet2_pad96(packet2_t *packet2, const u32 val)
Definition packet2.h:164