Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/gu/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ CFLAGS = @PSPSDK_CFLAGS@
libpspguincludedir = @PSPSDK_INCLUDEDIR@
libpspguinclude_HEADERS = pspgu.h

lib_LIBRARIES = libpspgu.a
lib_LIBRARIES = libpspgu.a libpspgud.a

noinst_HEADERS = guInternal.h

# Regular library (no debug assertions)
libpspgu_a_SOURCES = \
guInternal.c \
sceGuAlphaFunc.c \
Expand Down Expand Up @@ -112,3 +113,7 @@ libpspgu_a_SOURCES = \
sceGuViewport.c \
vram.c

# Debug library (with debug assertions)
libpspgud_a_SOURCES = $(libpspgu_a_SOURCES)
libpspgud_a_CFLAGS = $(CFLAGS) -DGU_DEBUG

2 changes: 1 addition & 1 deletion src/gu/guInternal.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ int gu_display_on;
int gu_call_mode;
int gu_states;
GuDrawBuffer gu_draw_buffer;
unsigned int* gu_object_stack[32];
unsigned int* gu_object_stack[GU_OBJECT_STACK_SIZE];
int gu_object_stack_depth;
7 changes: 7 additions & 0 deletions src/gu/guInternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@

#include "pspgu.h"

#ifdef GU_DEBUG
#include <assert.h>
#include <stdio.h>
#endif

#define GU_OBJECT_STACK_SIZE 32

typedef void (*GuCallback)(int);

typedef struct
Expand Down
6 changes: 6 additions & 0 deletions src/gu/sceGuAlphaFunc.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@

void sceGuAlphaFunc(int func, int value, int mask)
{
#ifdef GU_DEBUG
printf("sceGuAlphaFunc(%d, %d, %d);\n", func, value, mask);
assert(gu_init && "GU not initialized");
assert(func >= GU_NEVER && func <= GU_GEQUAL && "Invalid alpha function");
#endif

int arg = func | ((value & 0xff) << 8) | ((mask & 0xff) << 16);
sendCommandi(ALPHA_TEST, arg);
}
5 changes: 5 additions & 0 deletions src/gu/sceGuAmbient.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@

void sceGuAmbient(unsigned int color)
{
#ifdef GU_DEBUG
printf("sceGuAmbient(%08X);\n", color);
assert(gu_init && "GU not initialized");
#endif

sendCommandi(AMBIENT_LIGHT_COLOR,(color));
sendCommandi(AMBIENT_LIGHT_ALPHA,(color >> 24));
}
5 changes: 5 additions & 0 deletions src/gu/sceGuAmbientColor.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@

void sceGuAmbientColor(unsigned int color)
{
#ifdef GU_DEBUG
printf("sceGuAmbientColor(0x%08X);\n", color);
assert(gu_init && "GU not initialized");
#endif

sendCommandi(AMBIENT_COLOR, color);
sendCommandi(AMBIENT_ALPHA, color >> 24);
}
7 changes: 7 additions & 0 deletions src/gu/sceGuBeginObject.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@

void sceGuBeginObject(int vertex_type, int count, const void *indices, const void *vertices)
{
#ifdef GU_DEBUG
printf("sceGuBeginObject(%d, %d, %p, %p);\n", vertex_type, count, indices, vertices);
assert(gu_init && "GU not initialized");
assert(count > 0 && count <= 255 && (count % 8) == 0 && "Invalid vertex count - must be positive, <= 65535, and multiple of 8");
assert(gu_object_stack_depth < GU_OBJECT_STACK_SIZE && "Object stack overflow");
#endif

if (vertex_type)
sendCommandi(VERTEX_TYPE, vertex_type);

Expand Down
8 changes: 8 additions & 0 deletions src/gu/sceGuBlendFunc.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@

void sceGuBlendFunc(int op, int src, int dest, unsigned int srcfix, unsigned int destfix)
{
#ifdef GU_DEBUG
printf("sceGuBlendFunc(%d, %d, %d, 0x%08X, 0x%08X);\n", op, src, dest, srcfix, destfix);
assert(gu_init && "GU not initialized");
assert(op >= GU_ADD && op <= GU_ABS && "Invalid blend operation");
assert(src >= GU_OTHER_COLOR && src <= GU_FIX && "Invalid source blend factor");
assert(dest >= GU_OTHER_COLOR && dest <= GU_FIX && "Invalid destination blend factor");
#endif

sendCommandi(BLEND_MODE, src | (dest << 4) | (op << 8));
sendCommandi(BLEND_FIXED_A, srcfix);
sendCommandi(BLEND_FIXED_B, destfix);
Expand Down
6 changes: 6 additions & 0 deletions src/gu/sceGuBoneMatrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@

void sceGuBoneMatrix(unsigned int index, const ScePspFMatrix4 *matrix)
{
#ifdef GU_DEBUG
printf("sceGuBoneMatrix(%d, %p);\n", index, matrix);
assert(gu_init && "GU not initialized");
assert(index < 8 && "Invalid bone matrix index");
#endif

unsigned int offset = ((index << 1) + index) << 2; // 3*4 matrix
unsigned int i, j;
const float *fmatrix = (const float *)matrix;
Expand Down
5 changes: 5 additions & 0 deletions src/gu/sceGuCallList.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@

int sceGuCallList(const void *list)
{
#ifdef GU_DEBUG
printf("sceGuCallList(%p);\n", list);
assert(gu_init && "GU not initialized");
#endif

int res;
unsigned int list_addr = (unsigned int)list;

Expand Down
6 changes: 6 additions & 0 deletions src/gu/sceGuCallMode.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,11 @@

void sceGuCallMode(int mode)
{
#ifdef GU_DEBUG
printf("sceGuCallMode(%d);\n", mode);
assert(gu_init && "GU not initialized");
assert(mode >= GU_CALL_NORMAL && mode <= GU_CALL_SIGNAL && "Invalid call mode");
#endif

gu_call_mode = mode;
}
7 changes: 7 additions & 0 deletions src/gu/sceGuClear.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@

void sceGuClear(int flags)
{
#ifdef GU_DEBUG
printf("sceGuClear(%d);\n", flags);
assert(gu_init && "GU not initialized");
assert(flags >= 0 && "Invalid clear flags");
assert((flags & ~(GU_COLOR_BUFFER_BIT | GU_STENCIL_BUFFER_BIT | GU_DEPTH_BUFFER_BIT | GU_FAST_CLEAR_BIT)) == 0 && "Invalid clear flags");
#endif

GuContext *context = &gu_contexts[gu_curr_context];
unsigned int filter;
struct Vertex
Expand Down
5 changes: 5 additions & 0 deletions src/gu/sceGuClearColor.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@

void sceGuClearColor(unsigned int color)
{
#ifdef GU_DEBUG
printf("sceGuClearColor(0x%08X);\n", color);
assert(gu_init && "GU not initialized");
#endif

GuContext* context = &gu_contexts[gu_curr_context];
context->clear_color = color;
}
6 changes: 6 additions & 0 deletions src/gu/sceGuClearDepth.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@

void sceGuClearDepth(unsigned int depth)
{
#ifdef GU_DEBUG
printf("sceGuClearDepth(%u);\n", depth);
assert(gu_init && "GU not initialized");
assert(depth <= 65535 && "Invalid depth value");
#endif

GuContext* context = &gu_contexts[gu_curr_context];
context->clear_depth = depth;
}
23 changes: 23 additions & 0 deletions src/gu/sceGuClearStencil.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,29 @@

void sceGuClearStencil(unsigned int stencil)
{
#ifdef GU_DEBUG
printf("sceGuClearStencil(%u);\n", stencil);
assert(gu_init && "GU not initialized");
switch (gu_draw_buffer.pixel_size)
{
case GU_PSM_8888:
assert(stencil <= 255 && "Invalid stencil value for GU_PSM_8888");
break;
case GU_PSM_4444:
assert(stencil <= 15 && "Invalid stencil value for GU_PSM_4444");
break;
case GU_PSM_5551:
assert(stencil <= 1 && "Invalid stencil value for GU_PSM_5551");
break;
case GU_PSM_5650:
assert(0 && "Stencil not supported for GU_PSM_5650");
break;
default:
assert(0 && "Invalid pixel format");
break;
}
#endif

GuContext* context = &gu_contexts[gu_curr_context];
context->clear_stencil = stencil;
}
6 changes: 6 additions & 0 deletions src/gu/sceGuClutLoad.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@

void sceGuClutLoad(int num_blocks, const void *cbp)
{
#ifdef GU_DEBUG
printf("sceGuClutLoad(%d, %p);\n", num_blocks, cbp);
assert(gu_init && "GU not initialized");
assert(num_blocks > 0 && num_blocks <= 65535 && "Invalid number of CLUT blocks");
#endif

sendCommandi(CLUT_BUF_PTR, ((unsigned int)cbp));
sendCommandi(CLUT_BUF_WIDTH, (((unsigned int)cbp) >> 8) & 0xf0000);
sendCommandi(CLUT_LOAD, num_blocks);
Expand Down
6 changes: 6 additions & 0 deletions src/gu/sceGuClutMode.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@

void sceGuClutMode(unsigned int cpsm, unsigned int shift, unsigned int mask, unsigned int csa)
{
#ifdef GU_DEBUG
printf("sceGuClutMode(%08X, %08X, %08X, %08X);\n", cpsm, shift, mask, csa);
assert(gu_init && "GU not initialized");
assert(cpsm >= GU_PSM_5650 && cpsm <= GU_PSM_8888 && "Invalid CLUT pixel format");
#endif

unsigned int argument = (cpsm) | (shift << 2) | (mask << 8) | (csa << 16);
sendCommandi(CLUT_FORMAT, argument);
}
4 changes: 4 additions & 0 deletions src/gu/sceGuColor.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,9 @@

void sceGuColor(unsigned int color)
{
#ifdef GU_DEBUG
assert(gu_init && "GU not initialized");
#endif

sceGuMaterial(GU_AMBIENT | GU_DIFFUSE | GU_SPECULAR, color);
}
6 changes: 6 additions & 0 deletions src/gu/sceGuColorFunc.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@

void sceGuColorFunc(int func, unsigned int color, unsigned int mask)
{
#ifdef GU_DEBUG
printf("sceGuColorFunc(%d, 0x%08X, 0x%08X);\n", func, color, mask);
assert(gu_init && "GU not initialized");
assert(func >= GU_NEVER && func <= GU_NOTEQUAL && "Invalid color function");
#endif

sendCommandi(COLOR_TEST, func & 0x03);
sendCommandi(COLOR_REF, color);
sendCommandi(COLOR_TESTMASK, mask);
Expand Down
6 changes: 6 additions & 0 deletions src/gu/sceGuColorMaterial.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,11 @@

void sceGuColorMaterial(int components)
{
#ifdef GU_DEBUG
printf("sceGuColorMaterial(%d);\n", components);
assert(gu_init && "GU not initialized");
assert((components >= 0) && ((components & ~(GU_AMBIENT | GU_DIFFUSE | GU_SPECULAR)) == 0) && "Invalid material components");
#endif

sendCommandi(MATERIAL_COLOR, components);
}
6 changes: 5 additions & 1 deletion src/gu/sceGuContinue.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@
* Copyright (c) 2005 Jesper Svennevid
*/

#include "pspge.h"
#include "guInternal.h"

int sceGuContinue(void)
{
#ifdef GU_DEBUG
printf("sceGuContinue();\n");
assert(gu_init && "GU not initialized");
#endif
return sceGeContinue();
}
14 changes: 14 additions & 0 deletions src/gu/sceGuCopyImage.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,20 @@

void sceGuCopyImage(int psm, int sx, int sy, int width, int height, int srcw, void *src, int dx, int dy, int destw, void *dest)
{
#ifdef GU_DEBUG
printf("sceGuCopyImage(%d, %d, %d, %d, %d, %d, %p, %d, %d, %d, %p);\n", psm, sx, sy, width, height, srcw, src, dx, dy, destw, dest);
assert(gu_init && "GU not initialized");
assert(psm >= GU_PSM_5650 && psm <= GU_PSM_8888 && "Invalid pixel format");
assert(width > 0 && width <= 1023 && "Invalid width");
assert(height > 0 && height <= 1023 && "Invalid height");
assert(srcw > 8 && srcw <= 1024 && (srcw & 0x7) == 0 && "Invalid source width, must be multiple of 8");
assert(destw > 8 && destw <= 1024 && (destw & 0x7) == 0 && "Invalid destination width, must be multiple of 8");
assert(sx >= 0 && sx < 1023 && "Invalid source X");
assert(sy >= 0 && sy < 1023 && "Invalid source Y");
assert(dx >= 0 && dx < 1023 && "Invalid destination X");
assert(dy >= 0 && dy < 1023 && "Invalid destination Y");
#endif

sendCommandi(TRANSFER_SRC, ((unsigned int)src));
sendCommandi(TRANSFER_SRC_W, ((((unsigned int)src) & 0xff000000) >> 8) | srcw);
sendCommandi(TRANSFER_SRC_OFFSET, (sy << 10) | sx);
Expand Down
7 changes: 7 additions & 0 deletions src/gu/sceGuDepthBuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@

void sceGuDepthBuffer(void *zbp, int zbw)
{
#ifdef GU_DEBUG
printf("sceGuDepthBuffer(%p, %d);\n", zbp, zbw);
assert(gu_init && "GU not initialized");
assert((zbw & 0x1FFF) == 0 && "Depth buffer pointer must be 8192-byte aligned");
assert(zbw > 64 && zbw <= 1024 && (zbw & 0x3F) == 0 && "Invalid depth buffer width, must be multiple of 64");
#endif

sendCommandi(Z_BUF_PTR, ((unsigned int)zbp));
sendCommandi(Z_BUF_WIDTH, ((((unsigned int)zbp) & 0xff000000) >> 8) | zbw);

Expand Down
6 changes: 6 additions & 0 deletions src/gu/sceGuDepthFunc.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,11 @@

void sceGuDepthFunc(int function)
{
#ifdef GU_DEBUG
printf("sceGuDepthFunc(%d);\n", function);
assert(gu_init && "GU not initialized");
assert(function >= GU_NEVER && function <= GU_GEQUAL && "Invalid depth function");
#endif

sendCommandi(Z_TEST, function);
}
6 changes: 6 additions & 0 deletions src/gu/sceGuDepthMask.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,11 @@

void sceGuDepthMask(int mask)
{
#ifdef GU_DEBUG
printf("sceGuDepthMask(%d);\n", mask);
assert(gu_init && "GU not initialized");
assert((mask == 0 || mask == 1) && "Invalid depth mask");
#endif

sendCommandi(Z_MASK, mask);
}
5 changes: 5 additions & 0 deletions src/gu/sceGuDepthOffset.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@

void sceGuDepthOffset(unsigned int offset)
{
#ifdef GU_DEBUG
printf("sceGuDepthOffset(%08X);\n", offset);
assert(gu_init && "GU not initialized");
#endif

GuContext* context = &gu_contexts[gu_curr_context];
context->depth_offset = offset;

Expand Down
7 changes: 7 additions & 0 deletions src/gu/sceGuDepthRange.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@

void sceGuDepthRange(int near, int far)
{
#ifdef GU_DEBUG
printf("sceGuDepthRange(%d, %d);\n", near, far);
assert(gu_init && "GU not initialized");
assert(near >= 0 && near <= 65535 && "Invalid near plane");
assert(far >= 0 && far <= 65535 && "Invalid far plane");
#endif

GuContext *context = &gu_contexts[gu_curr_context];

unsigned int max = (unsigned int)near + (unsigned int)far;
Expand Down
6 changes: 6 additions & 0 deletions src/gu/sceGuDisable.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@

void sceGuDisable(int state)
{
#ifdef GU_DEBUG
printf("sceGuDisable(%d);\n", state);
assert(gu_init && "GU not initialized");
assert(state >= 0 && state < GU_MAX_STATUS && "Invalid state");
#endif

switch (state)
{
case GU_ALPHA_TEST:
Expand Down
Loading