PS2SDK
PS2 Homebrew Libraries
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
29 extern "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  extern 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
P2_VIF_STROW
@ P2_VIF_STROW
Definition: packet2_types.h:247
UnpackMode
UnpackMode
Definition: packet2_types.h:131
packet2_vif_mpg
static void packet2_vif_mpg(packet2_t *packet2, u32 num, u32 addr, u8 irq)
Definition: packet2_vif.h:167
packet2_vif_mscnt
static void packet2_vif_mscnt(packet2_t *packet2, u8 irq)
Definition: packet2_vif.h:244
packet2_add_u32
static void packet2_add_u32(packet2_t *packet2, const u32 val)
Definition: packet2.h:134
packet2_vif_stcycl
static void packet2_vif_stcycl(packet2_t *packet2, u32 wl, u32 cl, u8 irq)
Definition: packet2_vif.h:181
packet2_vif_mark
static void packet2_vif_mark(packet2_t *packet2, u32 value, u8 irq)
Definition: packet2_vif.h:296
packet2_vif_open_direct
static void packet2_vif_open_direct(packet2_t *packet2, u8 irq)
Definition: packet2_vif.h:95
packet2_vif_pad128
static void packet2_vif_pad128(packet2_t *packet2)
Definition: packet2_vif.h:153
P2_VIF_FLUSH
@ P2_VIF_FLUSH
Definition: packet2_types.h:211
P2_VIF_STCOL
@ P2_VIF_STCOL
Definition: packet2_types.h:253
packet2_vif_close_direct_manual
static void packet2_vif_close_direct_manual(packet2_t *packet2, u32 qwords)
Definition: packet2_vif.h:109
Mask
Definition: packet2_types.h:333
packet2_vif_nop
static void packet2_vif_nop(packet2_t *packet2, u8 irq)
Definition: packet2_vif.h:135
packet2_vif_open_unpack
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
P2_VIF_STCYCL
@ P2_VIF_STCYCL
Definition: packet2_types.h:161
P2_VIF_MSCAL
@ P2_VIF_MSCAL
Definition: packet2_types.h:223
P2_VIF_FLUSHE
@ P2_VIF_FLUSHE
Definition: packet2_types.h:204
packet2_vif_offset
static void packet2_vif_offset(packet2_t *packet2, u32 offset, u8 irq)
Definition: packet2_vif.h:194
packet2_pad96
static void packet2_pad96(packet2_t *packet2, const u32 val)
Definition: packet2.h:164
packet2_pad128
static void packet2_pad128(packet2_t *packet2, const u32 val)
Definition: packet2.h:173
packet2_vif_mscal
static void packet2_vif_mscal(packet2_t *packet2, u32 addr, u8 irq)
Definition: packet2_vif.h:232
vif_code_t::cmd
u32 cmd
Definition: packet2_types.h:293
P2_VIF_FLUSHA
@ P2_VIF_FLUSHA
Definition: packet2_types.h:217
packet2_t
Definition: packet2_types.h:300
vif_code_t::immediate
u32 immediate
Definition: packet2_types.h:281
vif_code_t
Definition: packet2_types.h:278
packet2_t::next
qword_t * next
Definition: packet2_types.h:319
packet2_vif_strow
static void packet2_vif_strow(packet2_t *packet2, const u32 *row_arr, u8 irq)
Definition: packet2_vif.h:360
P2_VIF_ITOP
@ P2_VIF_ITOP
Definition: packet2_types.h:180
packet2_vif_stmask
static void packet2_vif_stmask(packet2_t *packet2, Mask mask, u8 irq)
Definition: packet2_vif.h:346
packet2_vif_close_direct_auto
static void packet2_vif_close_direct_auto(packet2_t *packet2)
Definition: packet2_vif.h:123
P2_VIF_OFFSET
@ P2_VIF_OFFSET
Definition: packet2_types.h:168
packet2_vif_flush
static void packet2_vif_flush(packet2_t *packet2, u8 irq)
Definition: packet2_vif.h:219
P2_VIF_BASE
@ P2_VIF_BASE
Definition: packet2_types.h:174
P2_VIF_MPG
@ P2_VIF_MPG
Definition: packet2_types.h:259
packet2_vif_mscalf
static void packet2_vif_mscalf(packet2_t *packet2, u32 addr, u8 irq)
Definition: packet2_vif.h:333
vif_code_t::num
u32 num
Definition: packet2_types.h:288
packet2_vif_mskpath3
static void packet2_vif_mskpath3(packet2_t *packet2, u32 mask, u8 irq)
Definition: packet2_vif.h:283
P2_VIF_MSCALF
@ P2_VIF_MSCALF
Definition: packet2_types.h:235
packet2_vif_stmod
static void packet2_vif_stmod(packet2_t *packet2, u32 mode, u8 irq)
Definition: packet2_vif.h:270
packet2_vif_stcol
static void packet2_vif_stcol(packet2_t *packet2, const u32 *col_arr, u8 irq)
Definition: packet2_vif.h:377
packet2_t::vif_code_opened_at
vif_code_t * vif_code_opened_at
Definition: packet2_types.h:329
P2_VIF_STMOD
@ P2_VIF_STMOD
Definition: packet2_types.h:186
packet2_vif_add_micro_program
void packet2_vif_add_micro_program(packet2_t *packet2, u32 dest, u32 *start, u32 *end)
Definition: packet2_vif.c:14
packet2_vif_base
static void packet2_vif_base(packet2_t *packet2, u32 base, u8 irq)
Definition: packet2_vif.h:207
P2_VIF_DIRECT
@ P2_VIF_DIRECT
Definition: packet2_types.h:265
P2_VIF_STMASK
@ P2_VIF_STMASK
Definition: packet2_types.h:241
packet2_vif_close_unpack_auto
u32 packet2_vif_close_unpack_auto(packet2_t *packet2, u32 wl, u32 cl)
Definition: packet2_vif.c:34
packet2_vif_flusha
static void packet2_vif_flusha(packet2_t *packet2, u8 irq)
Definition: packet2_vif.h:320
P2_VIF_NOP
@ P2_VIF_NOP
Definition: packet2_types.h:156
P2_VIF_MSCNT
@ P2_VIF_MSCNT
Definition: packet2_types.h:229
P2_VIF_MARK
@ P2_VIF_MARK
Definition: packet2_types.h:199
packet2_vif_close_unpack_manual
static void packet2_vif_close_unpack_manual(packet2_t *packet2, u32 unpack_num)
Definition: packet2_vif.h:68
packet2_vif_pad96
static void packet2_vif_pad96(packet2_t *packet2)
Definition: packet2_vif.h:144
packet2_vif_itop
static void packet2_vif_itop(packet2_t *packet2, u32 itops, u8 irq)
Definition: packet2_vif.h:257
P2_VIF_MSKPATH3
@ P2_VIF_MSKPATH3
Definition: packet2_types.h:192
packet2_vif_flushe
static void packet2_vif_flushe(packet2_t *packet2, u8 irq)
Definition: packet2_vif.h:308