ps2sdk  1.1
A collection of Open Source libraries used for developing applications on Sony's PlayStation 2® (PS2).
main.c File Reference
#include <kernel.h>
#include <malloc.h>
#include <tamtypes.h>
#include <gs_psm.h>
#include <dma.h>
#include <packet2.h>
#include <packet2_utils.h>
#include <graph.h>
#include <draw.h>
#include "zbyszek.c"
#include "mesh_data.c"
+ Include dependency graph for main.c:

Go to the source code of this file.

Functions

void calculate_cube (texbuffer_t *t_texbuff)
 
void draw_cube (VECTOR t_object_position, texbuffer_t *t_texbuff)
 
void init_gs (framebuffer_t *t_frame, zbuffer_t *t_z, texbuffer_t *t_texbuff)
 
void init_drawing_environment (framebuffer_t *t_frame, zbuffer_t *t_z)
 
void send_texture (texbuffer_t *texbuf)
 
void clear_screen (framebuffer_t *frame, zbuffer_t *z)
 
void set_lod_clut_prim_tex_buff (texbuffer_t *t_texbuff)
 
void render (framebuffer_t *t_frame, zbuffer_t *t_z, texbuffer_t *t_texbuff)
 
void vu1_set_double_buffer_settings ()
 
void vu1_upload_micro_program ()
 
int main (int argc, char **argv)
 

Variables

unsigned char zbyszek []
 
u32 VU1Draw3D_CodeStart
 
u32 VU1Draw3D_CodeEnd
 
VECTOR object_rotation = {0.00f, 0.00f, 0.00f, 1.00f}
 
VECTOR camera_position = {140.00f, 140.00f, 40.00f, 1.00f}
 
VECTOR camera_rotation = {0.00f, 0.00f, 0.00f, 1.00f}
 
MATRIX local_world
 
MATRIX world_view
 
MATRIX view_screen
 
MATRIX local_screen
 
packet2_tvif_packets [2]
 
packet2_tcurr_vif_packet
 
packet2_tzbyszek_packet
 
u8 context = 0
 
prim_t prim
 
clutbuffer_t clut
 
lod_t lod
 
VECTORc_verts
 
VECTORc_sts
 

Function Documentation

◆ calculate_cube()

void calculate_cube ( texbuffer_t t_texbuff)

Calculate packet for cube data

Definition at line 95 of file main.c.

96 {
97  packet2_add_float(zbyszek_packet, 2048.0F); // scale
98  packet2_add_float(zbyszek_packet, 2048.0F); // scale
99  packet2_add_float(zbyszek_packet, ((float)0xFFFFFF) / 32.0F); // scale
100  packet2_add_s32(zbyszek_packet, faces_count); // vertex count
105  u8 j = 0; // RGBA
106  for (j = 0; j < 4; j++)
108 }
#define DRAW_STQ2_REGLIST
Definition: draw3d.h:55
packet2_t * zbyszek_packet
Definition: main.c:69
lod_t lod
Definition: main.c:86
prim_t prim
Definition: main.c:74
clutbuffer_t clut
Definition: main.c:80
static void packet2_utils_gs_add_texbuff_clut(packet2_t *packet2, texbuffer_t *texbuff, clutbuffer_t *clut)
static void packet2_utils_gs_add_lod(packet2_t *packet2, lod_t *lod)
static void packet2_utils_gs_add_prim_giftag(packet2_t *packet2, prim_t *prim, u32 loops_count, u32 nreg, u8 nreg_count, u8 context)
static void packet2_utils_gif_add_set(packet2_t *packet2, u32 loops_count)
static void packet2_add_u32(packet2_t *packet2, const u32 val)
Definition: packet2.h:134
static void packet2_add_s32(packet2_t *packet2, const s32 val)
Definition: packet2.h:141
static void packet2_add_float(packet2_t *packet2, const float val)
Definition: packet2.h:148
unsigned char u8
Definition: tamtypes.h:23
int faces_count
Definition: mesh_data.c:12

References clut, DRAW_STQ2_REGLIST, faces_count, lod, packet2_add_float(), packet2_add_s32(), packet2_add_u32(), packet2_utils_gif_add_set(), packet2_utils_gs_add_lod(), packet2_utils_gs_add_prim_giftag(), packet2_utils_gs_add_texbuff_clut(), prim, and zbyszek_packet.

Referenced by render().

◆ clear_screen()

void clear_screen ( framebuffer_t frame,
zbuffer_t z 
)

Send packet which will clear our screen.

Definition at line 206 of file main.c.

207 {
209 
210  // Clear framebuffer but don't update zbuffer.
211  packet2_update(clear, draw_disable_tests(clear->next, 0, z));
212  packet2_update(clear, draw_clear(clear->next, 0, 2048.0f - 320.0f, 2048.0f - 256.0f, frame->width, frame->height, 0x40, 0x40, 0x40));
213  packet2_update(clear, draw_enable_tests(clear->next, 0, z));
214  packet2_update(clear, draw_finish(clear->next));
215 
216  // Now send our current dma chain.
217  dma_wait_fast();
219 
220  packet2_free(clear);
221 
222  // Wait for scene to finish drawing
224 }
void dma_wait_fast(void)
Definition: dma.c:115
#define DMA_CHANNEL_GIF
Definition: dma.h:24
void dma_channel_send_packet2(packet2_t *packet2, int channel, u8 flush_cache)
Definition: dma.c:157
void draw_wait_finish(void)
Definition: draw.c:200
qword_t * draw_finish(qword_t *q)
Definition: draw.c:188
qword_t * draw_clear(qword_t *q, int context, float x, float y, float width, float height, int r, int g, int b)
Definition: draw.c:148
qword_t * draw_disable_tests(qword_t *q, int context, zbuffer_t *z)
Definition: draw.c:120
qword_t * draw_enable_tests(qword_t *q, int context, zbuffer_t *z)
Definition: draw.c:134
@ P2_MODE_NORMAL
Definition: packet2_types.h:33
@ P2_TYPE_NORMAL
Definition: packet2_types.h:41
void packet2_free(packet2_t *packet2)
Definition: packet2.c:81
packet2_t * packet2_create(u16 qwords, enum Packet2Type type, enum Packet2Mode mode, u8 tte)
Definition: packet2.c:25
static void packet2_update(packet2_t *packet2, qword_t *qw)
Definition: packet2.h:89
unsigned int height
Definition: draw_buffers.h:43
unsigned int width
Definition: draw_buffers.h:42
qword_t * next

References DMA_CHANNEL_GIF, dma_channel_send_packet2(), dma_wait_fast(), draw_clear(), draw_disable_tests(), draw_enable_tests(), draw_finish(), draw_wait_finish(), framebuffer_t::height, packet2_t::next, P2_MODE_NORMAL, P2_TYPE_NORMAL, packet2_create(), packet2_free(), packet2_update(), and framebuffer_t::width.

Referenced by render().

◆ draw_cube()

void draw_cube ( VECTOR  t_object_position,
texbuffer_t t_texbuff 
)

Calculate cube position and add packet with cube data

Definition at line 111 of file main.c.

112 {
113  create_local_world(local_world, t_object_position, object_rotation);
118 
119  // Add matrix at the beggining of VU mem (skip TOP)
121 
122  u32 vif_added_bytes = 0; // zero because now we will use TOP register (double buffer)
123  // we don't wan't to unpack at 8 + beggining of buffer, but at
124  // the beggining of the buffer
125 
126  // Merge packets
128  vif_added_bytes += packet2_get_qw_count(zbyszek_packet);
129 
130  // Add vertices
132  vif_added_bytes += faces_count; // one VECTOR is size of qword
133 
134  // Add sts
136  vif_added_bytes += faces_count;
137 
142 
143  // Switch packet, so we can proceed during DMA transfer
144  context = !context;
145 }
int dma_channel_wait(int channel, int timeout)
Definition: dma.c:130
#define DMA_CHANNEL_VIF1
Definition: dma.h:23
packet2_t * vif_packets[2]
Definition: main.c:65
MATRIX world_view
Definition: main.c:57
packet2_t * curr_vif_packet
Definition: main.c:66
MATRIX local_screen
Definition: main.c:57
VECTOR camera_position
Definition: main.c:55
VECTOR * c_sts
Definition: main.c:92
VECTOR * c_verts
Definition: main.c:92
MATRIX local_world
Definition: main.c:57
VECTOR object_rotation
Definition: main.c:54
MATRIX view_screen
Definition: main.c:57
VECTOR camera_rotation
Definition: main.c:56
u8 context
Definition: main.c:71
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)
Definition: packet2_utils.h:67
static void packet2_utils_vu_add_start_program(packet2_t *packet2, u32 addr)
static void packet2_utils_vu_add_end_tag(packet2_t *packet2)
void packet2_reset(packet2_t *packet2, u8 clear_mem)
Definition: packet2.c:88
static u32 packet2_get_qw_count(packet2_t *packet2)
Definition: packet2.h:200
void create_local_screen(MATRIX local_screen, MATRIX local_world, MATRIX world_view, MATRIX view_screen)
Definition: math3d.c:434
void create_local_world(MATRIX local_world, VECTOR translation, VECTOR rotation)
Definition: math3d.c:377
void create_world_view(MATRIX world_view, VECTOR translation, VECTOR rotation)
Definition: math3d.c:394
qword_t * base
unsigned int u32
Definition: tamtypes.h:30

References packet2_t::base, c_sts, c_verts, camera_position, camera_rotation, context, create_local_screen(), create_local_world(), create_world_view(), curr_vif_packet, dma_channel_send_packet2(), DMA_CHANNEL_VIF1, dma_channel_wait(), faces_count, local_screen, local_world, object_rotation, packet2_get_qw_count(), packet2_reset(), packet2_utils_vu_add_end_tag(), packet2_utils_vu_add_start_program(), packet2_utils_vu_add_unpack_data(), view_screen, vif_packets, world_view, and zbyszek_packet.

Referenced by render().

◆ init_drawing_environment()

void init_drawing_environment ( framebuffer_t t_frame,
zbuffer_t t_z 
)

Some initialization of GS 2

Definition at line 174 of file main.c.

175 {
177 
178  // This will setup a default drawing environment.
179  packet2_update(packet2, draw_setup_environment(packet2->next, 0, t_frame, t_z));
180 
181  // Now reset the primitive origin to 2048-width/2,2048-height/2.
182  packet2_update(packet2, draw_primitive_xyoffset(packet2->next, 0, (2048 - 320), (2048 - 256)));
183 
184  // Finish setting up the environment.
185  packet2_update(packet2, draw_finish(packet2->next));
186 
187  // Now send the packet, no need to wait since it's the first.
189  dma_wait_fast();
190 
191  packet2_free(packet2);
192 }
qword_t * draw_setup_environment(qword_t *q, int context, framebuffer_t *frame, zbuffer_t *z)
Definition: draw.c:11
qword_t * draw_primitive_xyoffset(qword_t *q, int context, float x, float y)

References DMA_CHANNEL_GIF, dma_channel_send_packet2(), dma_wait_fast(), draw_finish(), draw_primitive_xyoffset(), draw_setup_environment(), packet2_t::next, P2_MODE_NORMAL, P2_TYPE_NORMAL, packet2_create(), packet2_free(), and packet2_update().

Referenced by main().

◆ init_gs()

void init_gs ( framebuffer_t t_frame,
zbuffer_t t_z,
texbuffer_t t_texbuff 
)

Some initialization of GS and VRAM allocation

Definition at line 148 of file main.c.

149 {
150  // Define a 32-bit 640x512 framebuffer.
151  t_frame->width = 640;
152  t_frame->height = 512;
153  t_frame->mask = 0;
154  t_frame->psm = GS_PSM_32;
155  t_frame->address = graph_vram_allocate(t_frame->width, t_frame->height, t_frame->psm, GRAPH_ALIGN_PAGE);
156 
157  // Enable the zbuffer.
158  t_z->enable = DRAW_ENABLE;
159  t_z->mask = 0;
161  t_z->zsm = GS_ZBUF_32;
162  t_z->address = graph_vram_allocate(t_frame->width, t_frame->height, t_z->zsm, GRAPH_ALIGN_PAGE);
163 
164  // Allocate some vram for the texture buffer
165  t_texbuff->width = 128;
166  t_texbuff->psm = GS_PSM_24;
167  t_texbuff->address = graph_vram_allocate(128, 128, GS_PSM_24, GRAPH_ALIGN_BLOCK);
168 
169  // Initialize the screen and tie the first framebuffer to the read circuits.
170  graph_initialize(t_frame->address, t_frame->width, t_frame->height, t_frame->psm, 0, 0);
171 }
#define DRAW_ENABLE
Definition: draw.h:25
#define ZTEST_METHOD_GREATER_EQUAL
Definition: draw_tests.h:34
int graph_initialize(int fbp, int width, int height, int psm, int x, int y)
Definition: graph.c:6
#define GRAPH_ALIGN_BLOCK
Definition: graph_vram.h:16
int graph_vram_allocate(int width, int height, int psm, int alignment)
Definition: graph_vram.c:7
#define GRAPH_ALIGN_PAGE
Definition: graph_vram.h:13
#define GS_ZBUF_32
Definition: gs_psm.h:42
#define GS_PSM_32
Definition: gs_psm.h:11
#define GS_PSM_24
Definition: gs_psm.h:13
unsigned int address
Definition: draw_buffers.h:41
unsigned int psm
Definition: draw_buffers.h:44
unsigned int mask
Definition: draw_buffers.h:45
unsigned int address
Definition: draw_buffers.h:57
unsigned int width
Definition: draw_buffers.h:58
unsigned int psm
Definition: draw_buffers.h:59
unsigned int mask
Definition: draw_buffers.h:53
unsigned int method
Definition: draw_buffers.h:50
unsigned int address
Definition: draw_buffers.h:51
unsigned int enable
Definition: draw_buffers.h:49
unsigned int zsm
Definition: draw_buffers.h:52

References framebuffer_t::address, zbuffer_t::address, texbuffer_t::address, DRAW_ENABLE, zbuffer_t::enable, GRAPH_ALIGN_BLOCK, GRAPH_ALIGN_PAGE, graph_initialize(), graph_vram_allocate(), GS_PSM_24, GS_PSM_32, GS_ZBUF_32, framebuffer_t::height, framebuffer_t::mask, zbuffer_t::mask, zbuffer_t::method, framebuffer_t::psm, texbuffer_t::psm, framebuffer_t::width, texbuffer_t::width, zbuffer_t::zsm, and ZTEST_METHOD_GREATER_EQUAL.

Referenced by main().

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 350 of file main.c.

351 {
352 
353  // Init DMA channels.
358 
359  // Initialize vif packets
363 
366 
367  // The buffers to be used.
368  framebuffer_t frame;
369  zbuffer_t z;
370  texbuffer_t texbuff;
371 
372  // Init the GS, framebuffer, zbuffer, and texture buffer.
373  init_gs(&frame, &z, &texbuff);
374 
375  // Init the drawing environment and framebuffer.
376  init_drawing_environment(&frame, &z);
377 
378  // Load the texture into vram.
379  send_texture(&texbuff);
380 
381  // Render textured cube
382  render(&frame, &z, &texbuff);
383 
387 
388  // Sleep
389  SleepThread();
390 
391  // End program.
392  return 0;
393 }
int dma_channel_initialize(int channel, void *handler, int flags)
Definition: dma.c:58
void dma_channel_fast_waits(int channel)
Definition: dma.c:108
void render(framebuffer_t *t_frame, zbuffer_t *t_z, texbuffer_t *t_texbuff)
Definition: main.c:257
void vu1_upload_micro_program()
Definition: main.c:338
void send_texture(texbuffer_t *texbuf)
Definition: main.c:195
void init_drawing_environment(framebuffer_t *t_frame, zbuffer_t *t_z)
Definition: main.c:174
void init_gs(framebuffer_t *t_frame, zbuffer_t *t_z, texbuffer_t *t_texbuff)
Definition: main.c:148
void vu1_set_double_buffer_settings()
Definition: main.c:328
@ P2_MODE_CHAIN
Definition: packet2_types.h:34
s32 SleepThread(void)
#define NULL
Definition: tamtypes.h:91

References dma_channel_fast_waits(), DMA_CHANNEL_GIF, dma_channel_initialize(), DMA_CHANNEL_VIF1, init_drawing_environment(), init_gs(), NULL, P2_MODE_CHAIN, P2_TYPE_NORMAL, packet2_create(), packet2_free(), render(), send_texture(), SleepThread(), vif_packets, vu1_set_double_buffer_settings(), vu1_upload_micro_program(), and zbyszek_packet.

◆ render()

void render ( framebuffer_t t_frame,
zbuffer_t t_z,
texbuffer_t t_texbuff 
)

Allocate some space for object position calculating. c_ prefix = calc_

Definition at line 257 of file main.c.

258 {
259  int i, j;
260 
261  set_lod_clut_prim_tex_buff(t_texbuff);
262 
267  c_verts = (VECTOR *)memalign(128, sizeof(VECTOR) * faces_count);
268  c_sts = (VECTOR *)memalign(128, sizeof(VECTOR) * faces_count);
269 
270  VECTOR c_zbyszek_position;
271 
272  for (i = 0; i < faces_count; i++)
273  {
274  c_verts[i][0] = vertices[faces[i]][0];
275  c_verts[i][1] = vertices[faces[i]][1];
276  c_verts[i][2] = vertices[faces[i]][2];
277  c_verts[i][3] = vertices[faces[i]][3];
278 
279  c_sts[i][0] = sts[faces[i]][0];
280  c_sts[i][1] = sts[faces[i]][1];
281  c_sts[i][2] = sts[faces[i]][2];
282  c_sts[i][3] = sts[faces[i]][3];
283  }
284 
285  // Create the view_screen matrix.
286  create_view_screen(view_screen, graph_aspect_ratio(), -3.00f, 3.00f, -3.00f, 3.00f, 1.00f, 2000.00f);
287  calculate_cube(t_texbuff);
288 
289  // The main loop...
290  for (;;)
291  {
292  // Spin the cube a bit.
293  object_rotation[0] += 0.008f;
294  while (object_rotation[0] > 3.14f)
295  {
296  object_rotation[0] -= 6.28f;
297  }
298  object_rotation[1] += 0.012f;
299  while (object_rotation[1] > 3.14f)
300  {
301  object_rotation[1] -= 6.28f;
302  }
303 
304  camera_position[2] += .5F;
305  camera_rotation[2] += 0.002f;
306  if (camera_position[2] >= 400.0F)
307  {
308  camera_position[2] = 40.0F;
309  camera_rotation[2] = 0.00f;
310  }
311 
312  clear_screen(t_frame, t_z);
313 
314  for (i = 0; i < 8; i++)
315  {
316  c_zbyszek_position[0] = i * 40.0F;
317  for (j = 0; j < 8; j++)
318  {
319  c_zbyszek_position[1] = j * 40.0F;
320  draw_cube(c_zbyszek_position, t_texbuff);
321  }
322  }
323 
325  }
326 }
VECTOR vertices[24]
Definition: mesh_data.c:31
void set_lod_clut_prim_tex_buff(texbuffer_t *t_texbuff)
Definition: main.c:226
void draw_cube(VECTOR t_object_position, texbuffer_t *t_texbuff)
Definition: main.c:111
void calculate_cube(texbuffer_t *t_texbuff)
Definition: main.c:95
void clear_screen(framebuffer_t *frame, zbuffer_t *z)
Definition: main.c:206
void graph_wait_vsync(void)
Definition: graph.c:99
float graph_aspect_ratio(void)
Definition: graph_mode.c:397
float VECTOR[4]
Definition: math3d.h:21
void create_view_screen(MATRIX view_screen, float aspect, float left, float right, float bottom, float top, float near, float far)
Definition: math3d.c:416
int faces[36]
Definition: mesh_data.c:18
VECTOR sts[24]
Definition: mesh_data.c:61

References c_sts, c_verts, calculate_cube(), camera_position, camera_rotation, clear_screen(), create_view_screen(), draw_cube(), faces, faces_count, graph_aspect_ratio(), graph_wait_vsync(), object_rotation, set_lod_clut_prim_tex_buff(), sts, vertices, and view_screen.

Referenced by main().

◆ send_texture()

void send_texture ( texbuffer_t texbuf)

Send texture data to GS.

Definition at line 195 of file main.c.

196 {
198  packet2_update(packet2, draw_texture_transfer(packet2->next, zbyszek, 128, 128, GS_PSM_24, texbuf->address, texbuf->width));
199  packet2_update(packet2, draw_texture_flush(packet2->next));
201  dma_wait_fast();
202  packet2_free(packet2);
203 }
unsigned char zbyszek[]
qword_t * draw_texture_transfer(qword_t *q, void *src, int width, int height, int psm, int dest, int dest_width)
Definition: draw.c:223
qword_t * draw_texture_flush(qword_t *q)
Definition: draw.c:208

References texbuffer_t::address, DMA_CHANNEL_GIF, dma_channel_send_packet2(), dma_wait_fast(), draw_texture_flush(), draw_texture_transfer(), GS_PSM_24, packet2_t::next, P2_MODE_CHAIN, P2_TYPE_NORMAL, packet2_create(), packet2_free(), packet2_update(), texbuffer_t::width, and zbyszek.

Referenced by main().

◆ set_lod_clut_prim_tex_buff()

void set_lod_clut_prim_tex_buff ( texbuffer_t t_texbuff)

Definition at line 226 of file main.c.

227 {
229  lod.max_level = 0;
232  lod.l = 0;
233  lod.k = 0;
234 
236  clut.start = 0;
237  clut.psm = 0;
239  clut.address = 0;
240 
241  // Define the triangle primitive we want to use.
250 
251  t_texbuff->info.width = draw_log2(128);
252  t_texbuff->info.height = draw_log2(128);
254  t_texbuff->info.function = TEXTURE_FUNCTION_DECAL;
255 }
#define DRAW_DISABLE
Definition: draw.h:24
unsigned char draw_log2(unsigned int x)
Definition: draw.c:348
#define CLUT_NO_LOAD
Definition: draw_buffers.h:26
#define TEXTURE_FUNCTION_DECAL
Definition: draw_buffers.h:17
#define TEXTURE_COMPONENTS_RGB
Definition: draw_buffers.h:12
#define CLUT_STORAGE_MODE1
Definition: draw_buffers.h:22
#define PRIM_SHADE_GOURAUD
#define PRIM_UNFIXED
#define PRIM_MAP_ST
#define PRIM_TRIANGLE
#define LOD_MIN_NEAREST
Definition: draw_sampling.h:18
#define LOD_USE_K
Definition: draw_sampling.h:13
#define LOD_MAG_NEAREST
Definition: draw_sampling.h:16
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 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 min_filter
Definition: draw_sampling.h:43
unsigned char max_level
Definition: draw_sampling.h:41
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
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 clutbuffer_t::address, prim_t::antialiasing, prim_t::blending, lod_t::calculation, clut, CLUT_NO_LOAD, CLUT_STORAGE_MODE1, prim_t::colorfix, texinfo_t::components, DRAW_DISABLE, DRAW_ENABLE, draw_log2(), prim_t::fogging, texinfo_t::function, texinfo_t::height, texbuffer_t::info, lod_t::k, lod_t::l, clutbuffer_t::load_method, lod, LOD_MAG_NEAREST, LOD_MIN_NEAREST, LOD_USE_K, lod_t::mag_filter, prim_t::mapping, prim_t::mapping_type, lod_t::max_level, lod_t::min_filter, prim, PRIM_MAP_ST, PRIM_SHADE_GOURAUD, PRIM_TRIANGLE, PRIM_UNFIXED, clutbuffer_t::psm, prim_t::shading, clutbuffer_t::start, clutbuffer_t::storage_mode, TEXTURE_COMPONENTS_RGB, TEXTURE_FUNCTION_DECAL, prim_t::type, and texinfo_t::width.

Referenced by render().

◆ vu1_set_double_buffer_settings()

void vu1_set_double_buffer_settings ( )

Definition at line 328 of file main.c.

329 {
331  packet2_utils_vu_add_double_buffer(packet2, 8, 496);
335  packet2_free(packet2);
336 }
static void packet2_utils_vu_add_double_buffer(packet2_t *packet2, u16 base, u16 offset)
Definition: packet2_utils.h:49

References dma_channel_send_packet2(), DMA_CHANNEL_VIF1, dma_channel_wait(), P2_MODE_CHAIN, P2_TYPE_NORMAL, packet2_create(), packet2_free(), packet2_utils_vu_add_double_buffer(), and packet2_utils_vu_add_end_tag().

Referenced by main().

◆ vu1_upload_micro_program()

void vu1_upload_micro_program ( )

Definition at line 338 of file main.c.

339 {
340  u32 packet_size =
342  packet2_t *packet2 = packet2_create(packet_size, P2_TYPE_NORMAL, P2_MODE_CHAIN, 1);
347  packet2_free(packet2);
348 }
u32 VU1Draw3D_CodeStart
u32 VU1Draw3D_CodeEnd
static u32 packet2_utils_get_packet_size_for_program(u32 *start, u32 *end)
void packet2_vif_add_micro_program(packet2_t *packet2, u32 dest, u32 *start, u32 *end)
Definition: packet2_vif.c:14

References dma_channel_send_packet2(), DMA_CHANNEL_VIF1, dma_channel_wait(), P2_MODE_CHAIN, P2_TYPE_NORMAL, packet2_create(), packet2_free(), packet2_utils_get_packet_size_for_program(), packet2_utils_vu_add_end_tag(), packet2_vif_add_micro_program(), VU1Draw3D_CodeEnd, and VU1Draw3D_CodeStart.

Referenced by main().

Variable Documentation

◆ c_sts

VECTOR * c_sts

Definition at line 92 of file main.c.

Referenced by draw_cube(), and render().

◆ c_verts

VECTOR* c_verts

Helper arrays. Needed for calculations.

Definition at line 92 of file main.c.

Referenced by draw_cube(), and render().

◆ camera_position

VECTOR camera_position = {140.00f, 140.00f, 40.00f, 1.00f}

Definition at line 55 of file main.c.

Referenced by draw_cube(), and render().

◆ camera_rotation

VECTOR camera_rotation = {0.00f, 0.00f, 0.00f, 1.00f}

Definition at line 56 of file main.c.

Referenced by draw_cube(), and render().

◆ clut

Color look up table. Needed for texture.

Definition at line 80 of file main.c.

Referenced by calculate_cube(), draw_clutbuffer(), draw_texturebuffer(), packet2_utils_gs_add_texbuff_clut(), run_demo(), set_lod_clut_prim_tex_buff(), and setup_texture().

◆ context

◆ curr_vif_packet

packet2_t* curr_vif_packet

Definition at line 66 of file main.c.

Referenced by draw_cube().

◆ local_screen

MATRIX local_screen

Definition at line 57 of file main.c.

Referenced by calculate_vertices(), create_local_screen(), draw_cube(), render(), and render_teapot().

◆ local_world

MATRIX local_world

Definition at line 57 of file main.c.

Referenced by create_local_screen(), create_local_world(), draw_cube(), render(), and render_teapot().

◆ lod

lod_t lod

Level of details. Needed for texture.

Definition at line 86 of file main.c.

Referenced by calculate_cube(), draw_texture_sampling(), packet2_utils_gs_add_lod(), run_demo(), set_lod_clut_prim_tex_buff(), and setup_texture().

◆ object_rotation

VECTOR object_rotation = {0.00f, 0.00f, 0.00f, 1.00f}

Definition at line 54 of file main.c.

Referenced by draw_cube(), and render().

◆ prim

◆ view_screen

MATRIX view_screen

Definition at line 57 of file main.c.

Referenced by create_local_screen(), create_view_screen(), draw_cube(), render(), and render_teapot().

◆ vif_packets

packet2_t* vif_packets[2]

Packets for sending VU data Each packet will have: a) View/Projection matrix (calculated every frame) b) Cube data (prim,lod,vertices,sts,...) added from zbyszek_packet.

Definition at line 65 of file main.c.

Referenced by draw_cube(), and main().

◆ VU1Draw3D_CodeEnd

u32 VU1Draw3D_CodeEnd
extern

◆ VU1Draw3D_CodeStart

u32 VU1Draw3D_CodeStart
extern

Data of VU1 micro program (draw_3D.vcl/vsm). How we can use it:

  1. Upload program to VU1.
  2. Send calculated local_screen matrix once per mesh (3D object)
  3. Set buffers size. (double-buffering described below)
  4. Send packet with: lod, clut, tex buffer, scale vector, rgba, verts and sts. What this program is doing?
  1. Load local_screen.
  2. Zero clipping flag.
  3. Set current buffer start address from TOP register (xtop command) To use pararelism, we set two buffers in the VU1. It means, that when VU1 is working with one verts packet, we can load second one into another buffer. xtop command is automatically switching buffers. I think that AAA games used quad buffers (TOP+TOPS) which can give best performance and no VIF_FLUSH should be needed.
  4. Load rest of data.
  5. Prepare GIF tag.
  6. For every vertex: transform, clip, scale, perspective divide.
  7. Send it to GS via XGKICK command.

Referenced by vu1_upload_micro_program().

◆ world_view

MATRIX world_view

Definition at line 57 of file main.c.

Referenced by create_local_screen(), create_world_view(), draw_cube(), render(), and render_teapot().

◆ zbyszek

unsigned char zbyszek[]
extern

Data of our texture (24bit, RGB8)

Referenced by send_texture().

◆ zbyszek_packet

packet2_t* zbyszek_packet

Cube data

Definition at line 69 of file main.c.

Referenced by calculate_cube(), draw_cube(), and main().