PS2SDK
PS2 Homebrew Libraries
Loading...
Searching...
No Matches
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
31extern "C"
32{
33#endif
34
35 // ---
36 // Packet2 management
37 // ---
38
51 packet2_t *packet2_create(u16 qwords, enum Packet2Type type, enum Packet2Mode mode, u8 tte);
52
67 packet2_t *packet2_create_from(qword_t *base, qword_t *next, u16 qwords, enum Packet2Type type, enum Packet2Mode mode, u8 tte);
68
73 void packet2_free(packet2_t *packet2);
74
83 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 void packet2_print(packet2_t *packet2, u32 qw_count);
189
194 void packet2_print_qw_count(packet2_t *packet2);
195
197 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
vif_code_t * vif_code_opened_at
dma_tag_t * tag_opened_at
qword_t * next
Packet2Mode
Packet2Type
static void packet2_pad128(packet2_t *packet2, const u32 val)
Definition packet2.h:173
void packet2_print(packet2_t *packet2, u32 qw_count)
Definition packet2.c:108
void packet2_free(packet2_t *packet2)
Definition packet2.c:81
void packet2_print_qw_count(packet2_t *packet2)
Definition packet2.c:127
void packet2_reset(packet2_t *packet2, u8 clear_mem)
Definition packet2.c:88
static void packet2_add_u32(packet2_t *packet2, const u32 val)
Definition packet2.h:134
static u8 packet2_doesnt_have_even_number_of_quads(packet2_t *packet2)
Definition packet2.h:203
static void packet2_add_s32(packet2_t *packet2, const s32 val)
Definition packet2.h:141
static void packet2_update(packet2_t *packet2, qword_t *qw)
Definition packet2.h:89
static u32 packet2_get_qw_count(packet2_t *packet2)
Definition packet2.h:200
static void packet2_add_u64(packet2_t *packet2, const u64 val)
Definition packet2.h:127
static void packet2_pad96(packet2_t *packet2, const u32 val)
Definition packet2.h:164
static u8 packet2_is_dma_tag_opened(packet2_t *packet2)
Definition packet2.h:206
static void packet2_add_float(packet2_t *packet2, const float val)
Definition packet2.h:148
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
static u8 packet2_is_vif_code_opened(packet2_t *packet2)
Definition packet2.h:209
void packet2_add(packet2_t *a, packet2_t *b)
Definition packet2.c:101
static void packet2_add_s64(packet2_t *packet2, const s64 val)
Definition packet2.h:108
packet2_t * packet2_create(u16 qwords, enum Packet2Type type, enum Packet2Mode mode, u8 tte)
Definition packet2.c:25
static void packet2_advance_next(packet2_t *packet2, u32 i)
Definition packet2.h:96