ps2sdk  1.1
A collection of Open Source libraries used for developing applications on Sony's PlayStation 2® (PS2).
packet.c
Go to the documentation of this file.
1 #include <string.h>
2 #include <stdlib.h>
3 #include <malloc.h>
4 #include <packet.h>
5 
6 #define SPR_BEGIN 0x70000000
7 
8 packet_t *packet_init(int qwords, int type)
9 {
10 
11  int byte_size = 0;
12  packet_t *packet = (packet_t*)calloc(1,sizeof(packet_t));
13 
14  if (packet == NULL)
15  {
16 
17  return NULL;
18 
19  }
20 
21  if (type == PACKET_SPR)
22  {
23 
25  packet->qwc = 0x1000;
26 
27  }
28  else
29  {
30  // Size of qwords in bytes.
31  byte_size = qwords << 4;
32 
33  // Allocate the data area in bytes aligned to cache line.
34  if ((packet->data = memalign(64, byte_size)) == NULL)
35  {
36  free(packet);
37  return NULL;
38 
39  }
40  }
41 
42  // Set the pointer attribute to ucab space.
43  if (type == PACKET_UCAB)
44  {
45 
46  packet->data = (qword_t *)((u32)packet->data | 0x30000000);
47 
48  }
49 
50  // Clear the packet area.
51  memset(packet->data, 0, byte_size);
52 
53  // Set the packet counts
54  packet->qwc = 0;
55  packet->qwords = qwords;
56  packet->type = type;
57 
58  // End function.
59  return packet;
60 
61 }
62 
64 {
65 
66  // Free the allocated data buffer.
67  if (packet->type == PACKET_SPR)
68  {
69 
70  packet->data = NULL;
71 
72  }
73  else
74  {
75  if (packet->type == PACKET_UCAB)
76  {
77 
78  packet->data = (qword_t *)((u32)packet->data ^ 0x30000000);
79 
80  }
81 
82  free(packet->data);
83  }
84 
85  free(packet);
86 
87 }
88 
90 {
91 
92  // Reset the quadword counter.
93  packet->qwc = 0;
94 
95  if (packet->type == PACKET_SPR)
96  {
97 
99  return;
100 
101  }
102 
103  // Zero out the data
104  memset(packet->data, 0, packet->qwords << 4);
105 
106 }
packet_t packet
Definition: font.c:24
packet_t * packet_init(int qwords, int type)
Definition: packet.c:8
#define SPR_BEGIN
Definition: packet.c:6
void packet_free(packet_t *packet)
Definition: packet.c:63
void packet_reset(packet_t *packet)
Definition: packet.c:89
#define PACKET_SPR
Definition: packet.h:16
#define PACKET_UCAB
Definition: packet.h:15
u16 type
Definition: packet.h:26
u16 qwc
Definition: packet.h:25
u32 qwords
Definition: packet.h:24
qword_t * data
Definition: packet.h:27
#define NULL
Definition: tamtypes.h:91
unsigned int u32
Definition: tamtypes.h:30