ps2sdk  1.1
A collection of Open Source libraries used for developing applications on Sony's PlayStation 2® (PS2).
packets.c
Go to the documentation of this file.
1 /*
2 # _____ ___ ____ ___ ____
3 # ____| | ____| | | |____|
4 # | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
5 #-----------------------------------------------------------------------
6 # (c) 2009 Lion
7 # Licenced under Academic Free License version 2.0
8 # Review ps2sdk README & LICENSE files for further details.
9 */
10 
11 #include <errno.h>
12 #include <stdio.h>
13 #include <kernel.h>
14 #include <libgs.h>
15 
16 #include "internal.h"
17 
18 QWORD GsPrimWorkArea[64] __attribute__((aligned(64))); // Align to a 64-byte boundary.
19 
21 {
22  void *pointer;
24 
25  if(num_qwords <= (GS_PACKET_DATA_QWORD_MAX-table->qword_offset)) //check if we can alloc in current packet
26  {
27  pointer=&table->packets[table->packet_offset].data[table->qword_offset];
28  table->qword_offset += num_qwords;
29  }
30  else //couldnt fit so we going to have to try to jump to next packet
31  {
32  if(table->packet_offset+1 == table->packet_count) //no more packet available so we return error;
33  {
34  pointer=NULL;
35  }
36  else //there is another pocket available so we can jump to it
37  {
38  //before we jup to this packet then we got to end current packet and point it to the new one
40  packet->tag.qwc=table->qword_offset;
41  packet->tag.pad1=0;
42  packet->tag.pce=0;
43  packet->tag.id=0x02; //next = tag.addr
44  packet->tag.irq =0;
45  packet->tag.addr=(unsigned int)&((GS_GIF_PACKET*)UNCACHED_SEG(&table->packets[table->packet_offset + 1]))->tag;
46  packet->tag.spr =0;
47  packet->tag.pad2 =0;
48 
49  //now reset qwords offset in this packet & update packet offset
50  table->qword_offset= 0;
51  table->packet_offset++;
52 
53  //now we use the new packet
54  // but we still got to check if enough mem is available
55  if( num_qwords <= (GS_PACKET_DATA_QWORD_MAX-table->qword_offset) )
56  {
57  pointer=&table->packets[table->packet_offset].data[table->qword_offset];
58  table->qword_offset += num_qwords;
59  }
60  else //not enough
61  {
62  pointer=NULL;
63  }
64  }
65  }
66 
67  return pointer;
68 }
69 
71 {
72  table->packet_offset=0;
73  table->qword_offset=0;
74 }
75 
77 {
79 
80  if(table->packet_offset==0 && table->qword_offset==0)
81  return 0;
82 
83  if(table->packets == NULL)
84  return -1;
85 
86  //close the current pocket
88  packet->tag.qwc =table->qword_offset;
89  packet->tag.pad1 =0;
90  packet->tag.pce =0;
91  packet->tag.id =0x07; //end
92  packet->tag.irq =0;
93  packet->tag.addr =(u32)0;
94  packet->tag.spr =0;
95  packet->tag.pad2 =0;
96 
97  GsDmaSend_tag(0, 0, &table->packets[0].tag);
98  if(wait)
99  GsDmaWait();
100 
101  return 0;
102 }
packet_t packet
Definition: font.c:24
#define UNCACHED_SEG(x)
Definition: kernel.h:35
void GsDmaWait(void)
Definition: dma.c:148
void GsDmaSend_tag(const void *addr, u32 qwords, const GS_GIF_DMACHAIN_TAG *tag)
Definition: dma.c:118
#define GS_PACKET_DATA_QWORD_MAX
Definition: libgs.h:2279
QWORD * GsGifPacketsAlloc(GS_PACKET_TABLE *table, u32 num_qwords)
Definition: packets.c:20
int GsGifPacketsExecute(GS_PACKET_TABLE *table, u16 wait)
Definition: packets.c:76
QWORD GsPrimWorkArea[64]
Definition: packets.c:18
void GsGifPacketsClear(GS_PACKET_TABLE *table)
Definition: packets.c:70
GS_GIF_DMACHAIN_TAG tag
Definition: libgs.h:2283
QWORD data[GS_PACKET_DATA_QWORD_MAX]
Definition: libgs.h:2284
u32 packet_count
Definition: libgs.h:2289
GS_GIF_PACKET * packets
Definition: libgs.h:2292
u32 packet_offset
Definition: libgs.h:2290
u32 qword_offset
Definition: libgs.h:2291
Definition: libgs.h:333
u16 qwc
Definition: packet.h:25
#define NULL
Definition: tamtypes.h:91
unsigned int u32
Definition: tamtypes.h:30
unsigned short u16
Definition: tamtypes.h:24