Skip to content

Commit

Permalink
Merge pull request #225 from fjtrujy/improve_gu
Browse files Browse the repository at this point in the history
Improving SCE GU readability
  • Loading branch information
sharkwouter authored Aug 9, 2024
2 parents ebae12f + 191880f commit 0b50f4c
Show file tree
Hide file tree
Showing 66 changed files with 1,310 additions and 480 deletions.
646 changes: 578 additions & 68 deletions src/gu/guInternal.h

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/gu/sceGuAlphaFunc.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
void sceGuAlphaFunc(int a0, int a1, int a2)
{
int arg = a0 | ((a1 & 0xff) << 8) | ((a2 & 0xff) << 16);
sendCommandi(219,arg);
sendCommandi(ALPHA_TEST, arg);
}
4 changes: 2 additions & 2 deletions src/gu/sceGuAmbient.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@

void sceGuAmbient(unsigned int color)
{
sendCommandi(92,(color & 0xffffff));
sendCommandi(93,(color >> 24));
sendCommandi(AMBIENT_LIGHT_COLOR,(color & 0xffffff));
sendCommandi(AMBIENT_LIGHT_ALPHA,(color >> 24));
}
4 changes: 2 additions & 2 deletions src/gu/sceGuAmbientColor.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@

void sceGuAmbientColor(unsigned int color)
{
sendCommandi(85,color & 0xffffff);
sendCommandi(88,color >> 24);
sendCommandi(AMBIENT_COLOR, color & 0xffffff);
sendCommandi(AMBIENT_ALPHA, color >> 24);
}
18 changes: 9 additions & 9 deletions src/gu/sceGuBeginObject.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,30 @@

#include "guInternal.h"

void sceGuBeginObject(int vertex_type, int a1, const void* indices, const void* vertices)
void sceGuBeginObject(int vertex_type, int a1, const void *indices, const void *vertices)
{
if (vertex_type)
sendCommandi(18,vertex_type);
sendCommandi(VERTEX_TYPE, vertex_type);

if (indices)
{
sendCommandi(16,(((unsigned int)indices) >> 8) & 0xf0000);
sendCommandi(2,((unsigned int)indices) & 0xffffff);
sendCommandi(BASE, (((unsigned int)indices) >> 8) & 0xf0000);
sendCommandi(IADDR, ((unsigned int)indices) & 0xffffff);
}

if (vertices)
{
sendCommandi(16,(((unsigned int)vertices) >> 8) & 0x0f0000);
sendCommandi(1,((unsigned int)vertices) & 0xffffff);
sendCommandi(BASE, (((unsigned int)vertices) >> 8) & 0x0f0000);
sendCommandi(VADDR, ((unsigned int)vertices) & 0xffffff);
}

sendCommandi(7,a1);
sendCommandi(BOUNDING_BOX, a1);

// store start to new object

gu_object_stack[gu_object_stack_depth++] = gu_list->current;

// dummy commands, overwritten in sceGuEndObject()
sendCommandi(16,0);
sendCommandi(9,0);
sendCommandi(BASE, 0);
sendCommandi(BJUMP, 0);
}
6 changes: 3 additions & 3 deletions src/gu/sceGuBlendFunc.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

void sceGuBlendFunc(int op, int src, int dest, unsigned int srcfix, unsigned int destfix)
{
sendCommandi(223,src | (dest << 4) | (op << 8));
sendCommandi(224,srcfix & 0xffffff);
sendCommandi(225,destfix & 0xffffff);
sendCommandi(BLEND_MODE, src | (dest << 4) | (op << 8));
sendCommandi(BLEND_FIXED_A, srcfix & 0xffffff);
sendCommandi(BLEND_FIXED_B, destfix & 0xffffff);
}
12 changes: 6 additions & 6 deletions src/gu/sceGuBoneMatrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@

#include "guInternal.h"

void sceGuBoneMatrix(unsigned int index, const ScePspFMatrix4* matrix)
void sceGuBoneMatrix(unsigned int index, const ScePspFMatrix4 *matrix)
{
unsigned int offset = ((index << 1)+index) << 2; // 3*4 matrix
unsigned int i,j;
const float* fmatrix = (const float*)matrix;
unsigned int offset = ((index << 1) + index) << 2; // 3*4 matrix
unsigned int i, j;
const float *fmatrix = (const float *)matrix;

sendCommandi(42,offset);
sendCommandi(BONE_MATRIX_NUMBER, offset);
for (i = 0; i < 4; ++i)
{
for (j = 0; j < 3; ++j)
{
sendCommandf(43,fmatrix[j+(i << 2)]);
sendCommandf(BONE_MATRIX_DATA, fmatrix[j + (i << 2)]);
}
}
}
12 changes: 6 additions & 6 deletions src/gu/sceGuCallList.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@

#include "guInternal.h"

void sceGuCallList(const void* list)
void sceGuCallList(const void *list)
{
unsigned int list_addr = (unsigned int)list;

if (gu_call_mode == 1)
{
sendCommandi(14,(list_addr >> 16) | 0x110000);
sendCommandi(12,list_addr & 0xffff);
sendCommandiStall(0,0);
sendCommandi(SIGNAL, (list_addr >> 16) | 0x110000);
sendCommandi(END, list_addr & 0xffff);
sendCommandiStall(NOP, 0);
}
else
{
sendCommandi(16,(list_addr >> 8) & 0xf0000);
sendCommandiStall(10,list_addr & 0xffffff);
sendCommandi(BASE, (list_addr >> 8) & 0xf0000);
sendCommandiStall(CALL, list_addr & 0xffffff);
}
}
44 changes: 27 additions & 17 deletions src/gu/sceGuClear.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,40 @@

void sceGuClear(int flags)
{
GuContext* context = &gu_contexts[gu_curr_context];
GuContext *context = &gu_contexts[gu_curr_context];
unsigned int filter;
struct Vertex
{
u32 color;
u16 x,y,z;
u16 x, y, z;
u16 pad;
};

switch (gu_draw_buffer.pixel_size)
{
case 0: filter = context->clear_color & 0xffffff; break;
case 1: filter = (context->clear_color & 0xffffff) | (context->clear_stencil << 31); break;
case 2: filter = (context->clear_color & 0xffffff) | (context->clear_stencil << 28); break;
case 3: filter = (context->clear_color & 0xffffff) | (context->clear_stencil << 24); break;
default: filter = 0; break;
case 0:
filter = context->clear_color & 0xffffff;
break;
case 1:
filter = (context->clear_color & 0xffffff) | (context->clear_stencil << 31);
break;
case 2:
filter = (context->clear_color & 0xffffff) | (context->clear_stencil << 28);
break;
case 3:
filter = (context->clear_color & 0xffffff) | (context->clear_stencil << 24);
break;
default:
filter = 0;
break;
}

struct Vertex* vertices;
struct Vertex *vertices;
int count;

if (!(flags & GU_FAST_CLEAR_BIT))
{
vertices = (struct Vertex*)sceGuGetMemory(2 * sizeof(struct Vertex));
vertices = (struct Vertex *)sceGuGetMemory(2 * sizeof(struct Vertex));
count = 2;

vertices[0].color = 0;
Expand All @@ -48,27 +58,27 @@ void sceGuClear(int flags)
}
else
{
struct Vertex* curr;
struct Vertex *curr;
unsigned int i;
count = ((gu_draw_buffer.width+63)/64)*2;
vertices = (struct Vertex*)sceGuGetMemory(count * sizeof(struct Vertex));
count = ((gu_draw_buffer.width + 63) / 64) * 2;
vertices = (struct Vertex *)sceGuGetMemory(count * sizeof(struct Vertex));
curr = vertices;

for (i = 0; i < count; ++i, ++curr)
{
unsigned int j,k;
unsigned int j, k;

j = i >> 1;
k = (i & 1);

curr->color = filter;
curr->x = (j+k) * 64;
curr->x = (j + k) * 64;
curr->y = k * gu_draw_buffer.height;
curr->z = context->clear_depth;
}
}

sendCommandi(211,((flags & (GU_COLOR_BUFFER_BIT|GU_STENCIL_BUFFER_BIT|GU_DEPTH_BUFFER_BIT)) << 8) | 0x01);
sceGuDrawArray(GU_SPRITES,GU_COLOR_8888|GU_VERTEX_16BIT|GU_TRANSFORM_2D,count,0,vertices);
sendCommandi(211,0);
sendCommandi(CLEAR_MODE, ((flags & (GU_COLOR_BUFFER_BIT | GU_STENCIL_BUFFER_BIT | GU_DEPTH_BUFFER_BIT)) << 8) | 0x01);
sceGuDrawArray(GU_SPRITES, GU_COLOR_8888 | GU_VERTEX_16BIT | GU_TRANSFORM_2D, count, 0, vertices);
sendCommandi(CLEAR_MODE, 0);
}
8 changes: 4 additions & 4 deletions src/gu/sceGuClutLoad.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

#include "guInternal.h"

void sceGuClutLoad(int num_blocks, const void* cbp)
void sceGuClutLoad(int num_blocks, const void *cbp)
{
sendCommandi(176,((unsigned int)cbp) & 0xffffff);
sendCommandi(177,(((unsigned int)cbp) >> 8) & 0xf0000);
sendCommandi(196,num_blocks);
sendCommandi(CLUT_ADDR, ((unsigned int)cbp) & 0xffffff);
sendCommandi(CLUT_ADDR_UPPER, (((unsigned int)cbp) >> 8) & 0xf0000);
sendCommandi(LOAD_CLUT, num_blocks);
}
2 changes: 1 addition & 1 deletion src/gu/sceGuClutMode.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
void sceGuClutMode(unsigned int cpsm, unsigned int shift, unsigned int mask, unsigned int a3)
{
unsigned int argument = (cpsm) | (shift << 2) | (mask << 8) | (a3 << 16);
sendCommandi(197,argument);
sendCommandi(CLUT_FORMAT, argument);
}
6 changes: 3 additions & 3 deletions src/gu/sceGuColorFunc.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

void sceGuColorFunc(int func, unsigned int color, unsigned int mask)
{
sendCommandi(216,func & 0x03);
sendCommandi(217,color & 0xffffff);
sendCommandi(218,mask);
sendCommandi(COLOR_TEST, func & 0x03);
sendCommandi(COLOR_REF, color & 0xffffff);
sendCommandi(COLOR_TESTMASK, mask);
}
2 changes: 1 addition & 1 deletion src/gu/sceGuColorMaterial.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@

void sceGuColorMaterial(int a0)
{
sendCommandi(83,a0);
sendCommandi(MATERIAL_COLOR, a0);
}
18 changes: 9 additions & 9 deletions src/gu/sceGuCopyImage.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@

#include "guInternal.h"

void sceGuCopyImage(int psm, int sx, int sy, int width, int height, int srcw, void* src, int dx, int dy, int destw, void* dest)
void sceGuCopyImage(int psm, int sx, int sy, int width, int height, int srcw, void *src, int dx, int dy, int destw, void *dest)
{
sendCommandi(178,((unsigned int)src) & 0xffffff);
sendCommandi(179,((((unsigned int)src) & 0xff000000) >> 8)|srcw);
sendCommandi(235,(sy << 10)|sx);
sendCommandi(180,((unsigned int)dest) & 0xffffff);
sendCommandi(181,((((unsigned int)dest) & 0xff000000) >> 8)|destw);
sendCommandi(236,(dy << 10)|dx);
sendCommandi(238,((height-1) << 10)|(width-1));
sendCommandi(234,(psm ^ 0x03) ? 0 : 1);
sendCommandi(TRANSFER_SRC, ((unsigned int)src) & 0xffffff);
sendCommandi(TRANSFER_SRC_W, ((((unsigned int)src) & 0xff000000) >> 8) | srcw);
sendCommandi(TRANSFER_SRC_OFFSET, (sy << 10) | sx);
sendCommandi(TRANSFER_DST, ((unsigned int)dest) & 0xffffff);
sendCommandi(TRANSFER_DST_W, ((((unsigned int)dest) & 0xff000000) >> 8) | destw);
sendCommandi(TRANSFER_DST_OFFSET, (dy << 10) | dx);
sendCommandi(TRANSFER_SIZE, ((height - 1) << 10) | (width - 1));
sendCommandi(TRANSFER_START, (psm ^ 0x03) ? 0 : 1);
}
6 changes: 3 additions & 3 deletions src/gu/sceGuDepthBuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@

#include "guInternal.h"

void sceGuDepthBuffer(void* zbp, int zbw)
void sceGuDepthBuffer(void *zbp, int zbw)
{
gu_draw_buffer.depth_buffer = zbp;

if (!gu_draw_buffer.depth_width || (gu_draw_buffer.depth_width != zbw))
gu_draw_buffer.depth_width = zbw;

sendCommandi(158,((unsigned int)zbp) & 0xffffff);
sendCommandi(159,((((unsigned int)zbp) & 0xff000000) >> 8)|zbw);
sendCommandi(Z_BUF_PTR, ((unsigned int)zbp) & 0xffffff);
sendCommandi(Z_BUF_WIDTH, ((((unsigned int)zbp) & 0xff000000) >> 8) | zbw);
}
2 changes: 1 addition & 1 deletion src/gu/sceGuDepthFunc.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@

void sceGuDepthFunc(int function)
{
sendCommandi(222,function);
sendCommandi(Z_TEST, function);
}
2 changes: 1 addition & 1 deletion src/gu/sceGuDepthMask.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@

void sceGuDepthMask(int mask)
{
sendCommandi(231,mask);
sendCommandi(Z_MASK, mask);
}
26 changes: 13 additions & 13 deletions src/gu/sceGuDepthRange.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,25 @@

void sceGuDepthRange(int near, int far)
{
GuContext* context = &gu_contexts[gu_curr_context];
GuContext *context = &gu_contexts[gu_curr_context];

unsigned int max = (unsigned int)near + (unsigned int)far;
int val = (int)((max >> 31) + max);
float z = (float)(val >> 1);
unsigned int max = (unsigned int)near + (unsigned int)far;
int val = (int)((max >> 31) + max);
float z = (float)(val >> 1);

context->near_plane = near;
context->near_plane = near;
context->far_plane = far;

sendCommandf(68,z - ((float)near));
sendCommandf(71,z + ((float)context->depth_offset));
sendCommandf(VIEWPORT_Z_SCALE, z - ((float)near));
sendCommandf(VIEWPORT_Z_CENTER, z + ((float)context->depth_offset));

if (near > far)
if (near > far)
{
int temp = near;
near = far;
far = temp;
int temp = near;
near = far;
far = temp;
}

sendCommandi(214,near);
sendCommandi(215,far);
sendCommandi(MIN_Z, near);
sendCommandi(MAX_Z, far);
}
Loading

0 comments on commit 0b50f4c

Please sign in to comment.