PS2SDK
PS2 Homebrew Libraries
packet2.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 
25 #ifndef __PACKET2_H__
26 #define __PACKET2_H__
27 
28 #include <packet2_types.h>
29 
30 #ifdef __cplusplus
31 extern "C"
32 {
33 #endif
34 
35  // ---
36  // Packet2 management
37  // ---
38 
51  extern packet2_t *packet2_create(u16 qwords, enum Packet2Type type, enum Packet2Mode mode, u8 tte);
52 
67  extern packet2_t *packet2_create_from(qword_t *base, qword_t *next, u16 qwords, enum Packet2Type type, enum Packet2Mode mode, u8 tte);
68 
73  extern void packet2_free(packet2_t *packet2);
74 
83  extern void packet2_reset(packet2_t *packet2, u8 clear_mem);
84 
89  static inline void packet2_update(packet2_t *packet2, qword_t *qw) { packet2->next = qw; }
90 
91  // ---
92  // Basic add
93  // ---
94 
96  static inline void packet2_advance_next(packet2_t *packet2, u32 i)
97  {
98  packet2->next = (qword_t *)((u8 *)packet2->next + i);
99  }
100 
101  static inline void packet2_add_u128(packet2_t *packet2, const u128 val)
102  {
103  *((u128 *)packet2->next) = val;
104  packet2_advance_next(packet2, sizeof(u128));
105  }
106 
108  static inline void packet2_add_s64(packet2_t *packet2, const s64 val)
109  {
110  *((s64 *)packet2->next) = val;
111  packet2_advance_next(packet2, sizeof(s64));
112  }
113 
114  static inline void packet2_add_2x_s64(packet2_t *packet2, const s64 v1, const s64 v2)
115  {
116  packet2_add_s64(packet2, v1);
117  packet2_add_s64(packet2, v2);
118  }
119 
120  static inline void packet2_add_s128(packet2_t *packet2, const s128 val)
121  {
122  *((s128 *)packet2->next) = val;
123  packet2_advance_next(packet2, sizeof(s128));
124  }
125 
127  static inline void packet2_add_u64(packet2_t *packet2, const u64 val)
128  {
129  *((u64 *)packet2->next) = val;
130  packet2_advance_next(packet2, sizeof(u64));
131  }
132 
134  static inline void packet2_add_u32(packet2_t *packet2, const u32 val)
135  {
136  *((u32 *)packet2->next) = val;
137  packet2_advance_next(packet2, sizeof(u32));
138  }
139 
141  static inline void packet2_add_s32(packet2_t *packet2, const s32 val)
142  {
143  *((s32 *)packet2->next) = val;
144  packet2_advance_next(packet2, sizeof(s32));
145  }
146 
148  static inline void packet2_add_float(packet2_t *packet2, const float val)
149  {
150  *((float *)packet2->next) = val;
151  packet2_advance_next(packet2, sizeof(float));
152  }
153 
154  static inline void packet2_add_data(packet2_t *packet2, void *t_data, u32 t_size)
155  {
156  u32 i;
157  for (i = 0; i < t_size; i++)
158  packet2_add_u128(packet2, ((u128 *)t_data)[i]);
159  }
160 
164  static inline void packet2_pad96(packet2_t *packet2, const u32 val)
165  {
166  while ((((u32)packet2->next + 4) & 0xf) != 0)
167  packet2_add_u32(packet2, val);
168  }
169 
173  static inline void packet2_pad128(packet2_t *packet2, const u32 val)
174  {
175  while (((u32)packet2->next & 0xf) != 0)
176  packet2_add_u32(packet2, val);
177  }
178 
179  // ---
180  // Other
181  // ---
182 
188  extern void packet2_print(packet2_t *packet2, u32 qw_count);
189 
194  extern void packet2_print_qw_count(packet2_t *packet2);
195 
197  extern void packet2_add(packet2_t *a, packet2_t *b);
198 
200  static inline u32 packet2_get_qw_count(packet2_t *packet2) { return ((u32)packet2->next - (u32)packet2->base) >> 4; }
201 
203  static inline u8 packet2_doesnt_have_even_number_of_quads(packet2_t *packet2) { return ((u32)packet2->next & 0xF) != 0; }
204 
206  static inline u8 packet2_is_dma_tag_opened(packet2_t *packet2) { return packet2->tag_opened_at != NULL; }
207 
209  static inline u8 packet2_is_vif_code_opened(packet2_t *packet2) { return packet2->vif_code_opened_at != NULL; }
210 
211 #ifdef __cplusplus
212 }
213 #endif
214 
215 #endif /* __PACKET2_H__ */
216  // end of packet2 group
packet2_add_u32
static void packet2_add_u32(packet2_t *packet2, const u32 val)
Definition: packet2.h:134
packet2_print
void packet2_print(packet2_t *packet2, u32 qw_count)
Definition: packet2.c:108
packet2_is_vif_code_opened
static u8 packet2_is_vif_code_opened(packet2_t *packet2)
Definition: packet2.h:209
packet2_add_float
static void packet2_add_float(packet2_t *packet2, const float val)
Definition: packet2.h:148
packet2_is_dma_tag_opened
static u8 packet2_is_dma_tag_opened(packet2_t *packet2)
Definition: packet2.h:206
Packet2Mode
Packet2Mode
Definition: packet2_types.h:31
packet2_create
packet2_t * packet2_create(u16 qwords, enum Packet2Type type, enum Packet2Mode mode, u8 tte)
Definition: packet2.c:25
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_add_s64
static void packet2_add_s64(packet2_t *packet2, const s64 val)
Definition: packet2.h:108
packet2_t
Definition: packet2_types.h:300
packet2_t::next
qword_t * next
Definition: packet2_types.h:319
packet2_create_from
packet2_t * packet2_create_from(qword_t *base, qword_t *next, u16 qwords, enum Packet2Type type, enum Packet2Mode mode, u8 tte)
Definition: packet2.c:60
packet2_get_qw_count
static u32 packet2_get_qw_count(packet2_t *packet2)
Definition: packet2.h:200
packet2_t::tag_opened_at
dma_tag_t * tag_opened_at
Definition: packet2_types.h:324
packet2_add_u64
static void packet2_add_u64(packet2_t *packet2, const u64 val)
Definition: packet2.h:127
packet2_free
void packet2_free(packet2_t *packet2)
Definition: packet2.c:81
packet2_reset
void packet2_reset(packet2_t *packet2, u8 clear_mem)
Definition: packet2.c:88
packet2_t::vif_code_opened_at
vif_code_t * vif_code_opened_at
Definition: packet2_types.h:329
packet2_update
static void packet2_update(packet2_t *packet2, qword_t *qw)
Definition: packet2.h:89
packet2_doesnt_have_even_number_of_quads
static u8 packet2_doesnt_have_even_number_of_quads(packet2_t *packet2)
Definition: packet2.h:203
packet2_add
void packet2_add(packet2_t *a, packet2_t *b)
Definition: packet2.c:101
packet2_print_qw_count
void packet2_print_qw_count(packet2_t *packet2)
Definition: packet2.c:127
Packet2Type
Packet2Type
Definition: packet2_types.h:38
packet2_add_s32
static void packet2_add_s32(packet2_t *packet2, const s32 val)
Definition: packet2.h:141
packet2_advance_next
static void packet2_advance_next(packet2_t *packet2, u32 i)
Definition: packet2.h:96