ps2sdk  1.1
A collection of Open Source libraries used for developing applications on Sony's PlayStation 2® (PS2).

Macros

#define VU_GS_PRIM(PRIM, IIP, TME, FGE, ABE, AA1, FST, CTXT, FIX)   (u128)(((FIX << 10) | (CTXT << 9) | (FST << 8) | (AA1 << 7) | (ABE << 6) | (FGE << 5) | (TME << 4) | (IIP << 3) | (PRIM)))
 
#define VU_GS_GIFTAG(NLOOP, EOP, PRE, PRIM, FLG, NREG)   (((u64)(NREG) << 60) | ((u64)(FLG) << 58) | ((u64)(PRIM) << 47) | ((u64)(PRE) << 46) | (EOP << 15) | (NLOOP << 0))
 

Functions

static void packet2_utils_vu_add_double_buffer (packet2_t *packet2, u16 base, u16 offset)
 
static void packet2_utils_vu_add_unpack_data (packet2_t *packet2, u32 t_dest_address, void *t_data, u32 t_size, u8 t_use_top)
 
static void packet2_utils_vu_open_unpack (packet2_t *packet2, u32 t_dest_address, u8 t_use_top)
 
static u32 packet2_utils_vu_close_unpack (packet2_t *packet2)
 
static void packet2_utils_vu_add_continue_program (packet2_t *packet2)
 
static void packet2_utils_vu_add_start_program (packet2_t *packet2, u32 addr)
 
static void packet2_utils_vu_add_end_tag (packet2_t *packet2)
 
static u32 packet2_utils_get_packet_size_for_program (u32 *start, u32 *end)
 
static void packet2_utils_gif_add_set (packet2_t *packet2, u32 loops_count)
 
static void packet2_utils_gs_add_lod (packet2_t *packet2, lod_t *lod)
 
static void packet2_utils_gs_add_texbuff_clut (packet2_t *packet2, texbuffer_t *texbuff, clutbuffer_t *clut)
 
static void packet2_utils_gs_add_draw_finish_giftag (packet2_t *packet2)
 
static void packet2_utils_gs_add_prim_giftag (packet2_t *packet2, prim_t *prim, u32 loops_count, u32 nreg, u8 nreg_count, u8 context)
 

Detailed Description

Useful functions and examples for libpacket2.

Macro Definition Documentation

◆ VU_GS_GIFTAG

#define VU_GS_GIFTAG (   NLOOP,
  EOP,
  PRE,
  PRIM,
  FLG,
  NREG 
)    (((u64)(NREG) << 60) | ((u64)(FLG) << 58) | ((u64)(PRIM) << 47) | ((u64)(PRE) << 46) | (EOP << 15) | (NLOOP << 0))

Definition at line 33 of file packet2_utils.h.

◆ VU_GS_PRIM

#define VU_GS_PRIM (   PRIM,
  IIP,
  TME,
  FGE,
  ABE,
  AA1,
  FST,
  CTXT,
  FIX 
)    (u128)(((FIX << 10) | (CTXT << 9) | (FST << 8) | (AA1 << 7) | (ABE << 6) | (FGE << 5) | (TME << 4) | (IIP << 3) | (PRIM)))

Definition at line 32 of file packet2_utils.h.

Function Documentation

◆ packet2_utils_get_packet_size_for_program()

static u32 packet2_utils_get_packet_size_for_program ( u32 start,
u32 end 
)
inlinestatic

Get program size in qws

Parameters
startStart address.
endEnd address.
Returns
Packet size in qws for specified program (instructions/256 + 1qw for tolerance).

Definition at line 138 of file packet2_utils.h.

139  {
140  // Count instructions
141  u32 count = (end - start) / 2;
142  if (count & 1)
143  count++;
144  return (count >> 8) + 1;
145  }
unsigned int u32
Definition: tamtypes.h:30

Referenced by vu1_upload_micro_program().

◆ packet2_utils_gif_add_set()

static void packet2_utils_gif_add_set ( packet2_t packet2,
u32  loops_count 
)
inlinestatic

Add set GIFTag which will be sent from VU1 via XGKICK instruction.

Parameters
packet2Pointer to packet2.
loops_countHow many GIF tags there will be?

Definition at line 157 of file packet2_utils.h.

158  {
159  packet2_add_2x_s64(packet2, GIF_SET_TAG(loops_count, 0, 0, 0, GIF_FLG_PACKED, 1), GIF_REG_AD);
160  }
#define GIF_SET_TAG(NLOOP, EOP, PRE, PRIM, FLG, NREG)
Definition: gif_tags.h:80
#define GIF_REG_AD
Definition: gif_tags.h:72
#define GIF_FLG_PACKED
Definition: gif_tags.h:35
static void packet2_add_2x_s64(packet2_t *packet2, const s64 v1, const s64 v2)
Definition: packet2.h:114

References GIF_FLG_PACKED, GIF_REG_AD, GIF_SET_TAG, and packet2_add_2x_s64().

Referenced by calculate_cube().

◆ packet2_utils_gs_add_draw_finish_giftag()

static void packet2_utils_gs_add_draw_finish_giftag ( packet2_t packet2)
inlinestatic

Add draw finish event GIFTag which will be sent from VU1 via XGKICK instruction. Used for synchronization via draw_wait_finish()

Parameters
packet2Pointer to packet2.

Definition at line 220 of file packet2_utils.h.

221  {
222  packet2_add_2x_s64(packet2, 1, GS_REG_FINISH);
223  }
#define GS_REG_FINISH
Definition: gs_gp.h:143

References GS_REG_FINISH, and packet2_add_2x_s64().

◆ packet2_utils_gs_add_lod()

static void packet2_utils_gs_add_lod ( packet2_t packet2,
lod_t lod 
)
inlinestatic

Add lod GIFTag which will be sent from VU1 via XGKICK instruction.

Parameters
packet2Pointer to packet2.
lodPointer to lod settings.

Definition at line 172 of file packet2_utils.h.

173  {
175  packet2,
176  GS_SET_TEX1(
177  lod->calculation,
178  lod->max_level,
179  lod->mag_filter,
180  lod->min_filter,
182  lod->l,
183  (int)(lod->k * 16.0F)),
184  GS_REG_TEX1);
185  }
lod_t lod
Definition: main.c:86
#define GS_REG_TEX1
Definition: gs_gp.h:43
#define GS_SET_TEX1(LCM, MXL, MMAG, MMIN, MTBA, L, K)
Definition: gs_gp.h:289
unsigned char mag_filter
Definition: draw_sampling.h:42
float k
Definition: draw_sampling.h:46
unsigned char l
Definition: draw_sampling.h:45
unsigned char calculation
Definition: draw_sampling.h:40
unsigned char mipmap_select
Definition: draw_sampling.h:44
unsigned char min_filter
Definition: draw_sampling.h:43
unsigned char max_level
Definition: draw_sampling.h:41

References lod_t::calculation, GS_REG_TEX1, GS_SET_TEX1, lod_t::k, lod_t::l, lod, lod_t::mag_filter, lod_t::max_level, lod_t::min_filter, lod_t::mipmap_select, and packet2_add_2x_s64().

Referenced by calculate_cube().

◆ packet2_utils_gs_add_prim_giftag()

static void packet2_utils_gs_add_prim_giftag ( packet2_t packet2,
prim_t prim,
u32  loops_count,
u32  nreg,
u8  nreg_count,
u8  context 
)
inlinestatic

Add drawing (prim) GIFTag which will be sent from VU1 via XGKICK instruction.

Parameters
packet2Pointer to packet2.
primPointer to prim settings.
loops_countGIF tag loops count.
nregWhat types of data we will use?
nreg_countHow many types there are in nreg?
contextDrawing context

Definition at line 235 of file packet2_utils.h.

236  {
238  packet2,
239  VU_GS_GIFTAG(
240  loops_count, // Information for GS. Amount of loops
241  1,
242  1,
243  VU_GS_PRIM(
244  prim->type,
245  prim->shading,
246  prim->mapping,
247  prim->fogging,
248  prim->blending,
251  context, // context
252  prim->colorfix),
253  0,
254  nreg_count),
255  nreg);
256  }
prim_t prim
Definition: main.c:74
u8 context
Definition: main.c:71
#define VU_GS_PRIM(PRIM, IIP, TME, FGE, ABE, AA1, FST, CTXT, FIX)
Definition: packet2_utils.h:32
#define VU_GS_GIFTAG(NLOOP, EOP, PRE, PRIM, FLG, NREG)
Definition: packet2_utils.h:33
unsigned char type
unsigned char blending
unsigned char antialiasing
unsigned char colorfix
unsigned char shading
unsigned char fogging
unsigned char mapping_type
unsigned char mapping

References prim_t::antialiasing, prim_t::blending, prim_t::colorfix, context, prim_t::fogging, prim_t::mapping, prim_t::mapping_type, packet2_add_2x_s64(), prim, prim_t::shading, prim_t::type, VU_GS_GIFTAG, and VU_GS_PRIM.

Referenced by calculate_cube().

◆ packet2_utils_gs_add_texbuff_clut()

static void packet2_utils_gs_add_texbuff_clut ( packet2_t packet2,
texbuffer_t texbuff,
clutbuffer_t clut 
)
inlinestatic

Add texture buffer / clut GIFTag which will be sent from VU1 via XGKICK instruction.

Parameters
packet2Pointer to packet2.
texbuffPointer to texture buffer.
clutPointer to clut buffer.

Definition at line 194 of file packet2_utils.h.

195  {
197  packet2,
198  GS_SET_TEX0(
199  texbuff->address >> 6,
200  texbuff->width >> 6,
201  texbuff->psm,
202  texbuff->info.width,
203  texbuff->info.height,
204  texbuff->info.components,
205  texbuff->info.function,
206  clut->address >> 6,
207  clut->psm,
209  clut->start,
210  clut->load_method),
211  GS_REG_TEX0);
212  }
clutbuffer_t clut
Definition: main.c:80
#define GS_SET_TEX0(TBA, TBW, PSM, TW, TH, TCC, TFNCT, CBA, CPSM, CSM, CSA, CLD)
Definition: gs_gp.h:281
#define GS_REG_TEX0
Definition: gs_gp.h:25
unsigned int load_method
Definition: draw_buffers.h:68
unsigned int start
Definition: draw_buffers.h:67
unsigned int storage_mode
Definition: draw_buffers.h:66
unsigned int psm
Definition: draw_buffers.h:65
unsigned int address
Definition: draw_buffers.h:64
unsigned int address
Definition: draw_buffers.h:57
unsigned int width
Definition: draw_buffers.h:58
unsigned int psm
Definition: draw_buffers.h:59
texinfo_t info
Definition: draw_buffers.h:60
unsigned char height
Definition: draw_buffers.h:35
unsigned char function
Definition: draw_buffers.h:37
unsigned char components
Definition: draw_buffers.h:36
unsigned char width
Definition: draw_buffers.h:34

References texbuffer_t::address, clutbuffer_t::address, clut, texinfo_t::components, texinfo_t::function, GS_REG_TEX0, GS_SET_TEX0, texinfo_t::height, texbuffer_t::info, clutbuffer_t::load_method, packet2_add_2x_s64(), texbuffer_t::psm, clutbuffer_t::psm, clutbuffer_t::start, clutbuffer_t::storage_mode, texinfo_t::width, and texbuffer_t::width.

Referenced by calculate_cube().

◆ packet2_utils_vu_add_continue_program()

static void packet2_utils_vu_add_continue_program ( packet2_t packet2)
inlinestatic

Continue VU micro program (from –cont line). Adds FLUSH and MSCNT VIF opcodes.

Definition at line 103 of file packet2_utils.h.

104  {
105  packet2_chain_open_cnt(packet2, 0, 0, 0);
106  packet2_vif_flush(packet2, 0);
107  packet2_vif_mscnt(packet2, 0);
108  packet2_chain_close_tag(packet2);
109  }
static void packet2_chain_close_tag(packet2_t *packet2)
static void packet2_chain_open_cnt(packet2_t *packet2, u8 irq, u32 pce, u8 spr)
static void packet2_vif_mscnt(packet2_t *packet2, u8 irq)
Definition: packet2_vif.h:244
static void packet2_vif_flush(packet2_t *packet2, u8 irq)
Definition: packet2_vif.h:219

References packet2_chain_close_tag(), packet2_chain_open_cnt(), packet2_vif_flush(), and packet2_vif_mscnt().

◆ packet2_utils_vu_add_double_buffer()

static void packet2_utils_vu_add_double_buffer ( packet2_t packet2,
u16  base,
u16  offset 
)
inlinestatic

Add VU buffers size settings.

Parameters
t_baseBase address (qw)
t_offsetOffset address (qw)

Definition at line 49 of file packet2_utils.h.

50  {
51  packet2_chain_open_cnt(packet2, 0, 0, 0);
52  packet2_vif_base(packet2, base, 0);
53  packet2_vif_offset(packet2, offset, 0);
54  packet2_chain_close_tag(packet2);
55  }
static void packet2_vif_base(packet2_t *packet2, u32 base, u8 irq)
Definition: packet2_vif.h:207
static void packet2_vif_offset(packet2_t *packet2, u32 offset, u8 irq)
Definition: packet2_vif.h:194

References packet2_chain_close_tag(), packet2_chain_open_cnt(), packet2_vif_base(), and packet2_vif_offset().

Referenced by vu1_set_double_buffer_settings().

◆ packet2_utils_vu_add_end_tag()

static void packet2_utils_vu_add_end_tag ( packet2_t packet2)
inlinestatic

Add aligned END tag (with nops).

Definition at line 124 of file packet2_utils.h.

125  {
126  packet2_chain_open_end(packet2, 0, 0);
127  packet2_vif_nop(packet2, 0);
128  packet2_vif_nop(packet2, 0);
129  packet2_chain_close_tag(packet2);
130  }
static void packet2_chain_open_end(packet2_t *packet2, u8 irq, u32 pce)
static void packet2_vif_nop(packet2_t *packet2, u8 irq)
Definition: packet2_vif.h:135

References packet2_chain_close_tag(), packet2_chain_open_end(), and packet2_vif_nop().

Referenced by draw_cube(), vu1_set_double_buffer_settings(), and vu1_upload_micro_program().

◆ packet2_utils_vu_add_start_program()

static void packet2_utils_vu_add_start_program ( packet2_t packet2,
u32  addr 
)
inlinestatic

Start VU micro program. Adds FLUSH and MSCAL VIF opcodes.

Definition at line 115 of file packet2_utils.h.

116  {
117  packet2_chain_open_cnt(packet2, 0, 0, 0);
118  packet2_vif_flush(packet2, 0);
119  packet2_vif_mscal(packet2, addr, 0);
120  packet2_chain_close_tag(packet2);
121  }
static void packet2_vif_mscal(packet2_t *packet2, u32 addr, u8 irq)
Definition: packet2_vif.h:232

References packet2_chain_close_tag(), packet2_chain_open_cnt(), packet2_vif_flush(), and packet2_vif_mscal().

Referenced by draw_cube().

◆ packet2_utils_vu_add_unpack_data()

static void packet2_utils_vu_add_unpack_data ( packet2_t packet2,
u32  t_dest_address,
void *  t_data,
u32  t_size,
u8  t_use_top 
)
inlinestatic

Add data via REF tag and UNPACK. Please be sure that data is aligned, and there is no any open UNPACK/DIRECT.

Parameters
packet2Pointer to packet2.
t_dest_addressDestination address.
t_dataData pointer.
t_sizeSize in quadwords.
t_use_topUnpack to current double buffer?

Definition at line 67 of file packet2_utils.h.

68  {
69  packet2_chain_ref(packet2, t_data, t_size, 0, 0, 0);
70  packet2_vif_stcycl(packet2, 0, 0x0101, 0);
71  packet2_vif_open_unpack(packet2, P2_UNPACK_V4_32, t_dest_address, t_use_top, 0, 1, 0);
72  packet2_vif_close_unpack_manual(packet2, t_size);
73  }
static void packet2_chain_ref(packet2_t *packet2, const void *ref_data, u32 qw_length, u8 irq, u8 spr, u32 pce)
@ P2_UNPACK_V4_32
static void packet2_vif_close_unpack_manual(packet2_t *packet2, u32 unpack_num)
Definition: packet2_vif.h:68
static void packet2_vif_open_unpack(packet2_t *packet2, enum UnpackMode mode, u32 vuAddr, u8 dblBuffered, u8 masked, u8 usigned, u8 irq)
Definition: packet2_vif.h:50
static void packet2_vif_stcycl(packet2_t *packet2, u32 wl, u32 cl, u8 irq)
Definition: packet2_vif.h:181

References P2_UNPACK_V4_32, packet2_chain_ref(), packet2_vif_close_unpack_manual(), packet2_vif_open_unpack(), and packet2_vif_stcycl().

Referenced by draw_cube().

◆ packet2_utils_vu_close_unpack()

static u32 packet2_utils_vu_close_unpack ( packet2_t packet2)
inlinestatic

Close CNT tag + VU unpack.

Returns
Unpacked qwords count

Definition at line 92 of file packet2_utils.h.

93  {
94  packet2_vif_pad128(packet2);
95  packet2_chain_close_tag(packet2);
96  return packet2_vif_close_unpack_auto(packet2, 0, 0x0101);
97  }
static void packet2_vif_pad128(packet2_t *packet2)
Definition: packet2_vif.h:153
u32 packet2_vif_close_unpack_auto(packet2_t *packet2, u32 wl, u32 cl)
Definition: packet2_vif.c:34

References packet2_chain_close_tag(), packet2_vif_close_unpack_auto(), and packet2_vif_pad128().

◆ packet2_utils_vu_open_unpack()

static void packet2_utils_vu_open_unpack ( packet2_t packet2,
u32  t_dest_address,
u8  t_use_top 
)
inlinestatic

Open CNT tag + VU unpack.

Parameters
packet2Pointer to packet2.
t_dest_addressDestination address.
t_use_topUnpack to current double buffer?

Definition at line 81 of file packet2_utils.h.

82  {
83  packet2_chain_open_cnt(packet2, 0, 0, 0);
84  packet2_vif_stcycl(packet2, 0, 0x0101, 0);
85  packet2_vif_open_unpack(packet2, P2_UNPACK_V4_32, t_dest_address, t_use_top, 0, 1, 0);
86  }

References P2_UNPACK_V4_32, packet2_chain_open_cnt(), packet2_vif_open_unpack(), and packet2_vif_stcycl().