ps2sdk  1.1
A collection of Open Source libraries used for developing applications on Sony's PlayStation 2® (PS2).
packets.c File Reference
#include <errno.h>
#include <stdio.h>
#include <kernel.h>
#include <libgs.h>
#include "internal.h"
+ Include dependency graph for packets.c:

Go to the source code of this file.

Functions

QWORDGsGifPacketsAlloc (GS_PACKET_TABLE *table, u32 num_qwords)
 
void GsGifPacketsClear (GS_PACKET_TABLE *table)
 
int GsGifPacketsExecute (GS_PACKET_TABLE *table, u16 wait)
 

Variables

QWORD GsPrimWorkArea [64]
 

Function Documentation

◆ GsGifPacketsAlloc()

QWORD* GsGifPacketsAlloc ( GS_PACKET_TABLE table,
u32  num_qwords 
)

Definition at line 20 of file packets.c.

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 }
packet_t packet
Definition: font.c:24
#define UNCACHED_SEG(x)
Definition: kernel.h:35
#define GS_PACKET_DATA_QWORD_MAX
Definition: libgs.h:2279
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
u16 qwc
Definition: packet.h:25
#define NULL
Definition: tamtypes.h:91

References GS_GIF_PACKET::data, GS_PACKET_DATA_QWORD_MAX, NULL, packet, GS_PACKET_TABLE::packet_count, GS_PACKET_TABLE::packet_offset, GS_PACKET_TABLE::packets, packet_t::qwc, GS_PACKET_TABLE::qword_offset, and UNCACHED_SEG.

Referenced by DrawSprites(), and DrawTriangles().

◆ GsGifPacketsClear()

void GsGifPacketsClear ( GS_PACKET_TABLE table)

Definition at line 70 of file packets.c.

71 {
72  table->packet_offset=0;
73  table->qword_offset=0;
74 }

References GS_PACKET_TABLE::packet_offset, and GS_PACKET_TABLE::qword_offset.

Referenced by main().

◆ GsGifPacketsExecute()

int GsGifPacketsExecute ( GS_PACKET_TABLE table,
u16  wait 
)

Definition at line 76 of file packets.c.

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 }
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
GS_GIF_DMACHAIN_TAG tag
Definition: libgs.h:2283
unsigned int u32
Definition: tamtypes.h:30

References GsDmaSend_tag(), GsDmaWait(), NULL, packet, GS_PACKET_TABLE::packet_offset, GS_PACKET_TABLE::packets, packet_t::qwc, GS_PACKET_TABLE::qword_offset, GS_GIF_PACKET::tag, and UNCACHED_SEG.

Referenced by main().

Variable Documentation

◆ GsPrimWorkArea