ps2sdk  1.1
A collection of Open Source libraries used for developing applications on Sony's PlayStation 2® (PS2).
packet.c File Reference
#include <string.h>
#include <stdlib.h>
#include <malloc.h>
#include <packet.h>
+ Include dependency graph for packet.c:

Go to the source code of this file.

Macros

#define SPR_BEGIN   0x70000000
 

Functions

packet_tpacket_init (int qwords, int type)
 
void packet_free (packet_t *packet)
 
void packet_reset (packet_t *packet)
 

Macro Definition Documentation

◆ SPR_BEGIN

#define SPR_BEGIN   0x70000000

Definition at line 6 of file packet.c.

Function Documentation

◆ packet_free()

void packet_free ( packet_t packet)

Free the space allocated by packet.

Definition at line 63 of file packet.c.

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 }
packet_t packet
Definition: font.c:24
#define PACKET_SPR
Definition: packet.h:16
#define PACKET_UCAB
Definition: packet.h:15
u16 type
Definition: packet.h:26
qword_t * data
Definition: packet.h:27
#define NULL
Definition: tamtypes.h:91
unsigned int u32
Definition: tamtypes.h:30

References packet_t::data, NULL, packet, PACKET_SPR, PACKET_UCAB, and packet_t::type.

Referenced by draw_init_env(), init_drawing_environment(), init_texture(), load_texture(), main(), render(), and setup_texture().

◆ packet_init()

packet_t* packet_init ( int  qwords,
int  type 
)

Allocate a new packet for use, size in quadwords.

Definition at line 8 of file packet.c.

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 }
#define SPR_BEGIN
Definition: packet.c:6
u16 qwc
Definition: packet.h:25
u32 qwords
Definition: packet.h:24

References packet_t::data, NULL, packet, PACKET_SPR, PACKET_UCAB, packet_t::qwc, packet_t::qwords, SPR_BEGIN, and packet_t::type.

Referenced by draw_init_env(), init_drawing_environment(), init_texture(), InitCB(), load_texture(), main(), render(), run_demo(), and setup_texture().

◆ packet_reset()

void packet_reset ( packet_t packet)

Reset the packet quadword counter and zero out data.

Definition at line 89 of file packet.c.

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 }

References packet_t::data, packet, PACKET_SPR, packet_t::qwc, packet_t::qwords, SPR_BEGIN, and packet_t::type.