Skip to content

Commit b3f0fb5

Browse files
authored
Merge pull request #320 from fjtrujy/sceguDebug
Creating `libpspgud` library
2 parents 58c2b2a + b1bf44e commit b3f0fb5

File tree

89 files changed

+606
-11
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+606
-11
lines changed

src/gu/Makefile.am

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ CFLAGS = @PSPSDK_CFLAGS@
1212
libpspguincludedir = @PSPSDK_INCLUDEDIR@
1313
libpspguinclude_HEADERS = pspgu.h
1414

15-
lib_LIBRARIES = libpspgu.a
15+
lib_LIBRARIES = libpspgu.a libpspgud.a
1616

1717
noinst_HEADERS = guInternal.h
1818

19+
# Regular library (no debug assertions)
1920
libpspgu_a_SOURCES = \
2021
guInternal.c \
2122
sceGuAlphaFunc.c \
@@ -112,3 +113,7 @@ libpspgu_a_SOURCES = \
112113
sceGuViewport.c \
113114
vram.c
114115

116+
# Debug library (with debug assertions)
117+
libpspgud_a_SOURCES = $(libpspgu_a_SOURCES)
118+
libpspgud_a_CFLAGS = $(CFLAGS) -DGU_DEBUG
119+

src/gu/guInternal.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ int gu_display_on;
1919
int gu_call_mode;
2020
int gu_states;
2121
GuDrawBuffer gu_draw_buffer;
22-
unsigned int* gu_object_stack[32];
22+
unsigned int* gu_object_stack[GU_OBJECT_STACK_SIZE];
2323
int gu_object_stack_depth;

src/gu/guInternal.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@
1111

1212
#include "pspgu.h"
1313

14+
#ifdef GU_DEBUG
15+
#include <assert.h>
16+
#include <stdio.h>
17+
#endif
18+
19+
#define GU_OBJECT_STACK_SIZE 32
20+
1421
typedef void (*GuCallback)(int);
1522

1623
typedef struct

src/gu/sceGuAlphaFunc.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010

1111
void sceGuAlphaFunc(int func, int value, int mask)
1212
{
13+
#ifdef GU_DEBUG
14+
printf("sceGuAlphaFunc(%d, %d, %d);\n", func, value, mask);
15+
assert(gu_init && "GU not initialized");
16+
assert(func >= GU_NEVER && func <= GU_GEQUAL && "Invalid alpha function");
17+
#endif
18+
1319
int arg = func | ((value & 0xff) << 8) | ((mask & 0xff) << 16);
1420
sendCommandi(ALPHA_TEST, arg);
1521
}

src/gu/sceGuAmbient.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010

1111
void sceGuAmbient(unsigned int color)
1212
{
13+
#ifdef GU_DEBUG
14+
printf("sceGuAmbient(%08X);\n", color);
15+
assert(gu_init && "GU not initialized");
16+
#endif
17+
1318
sendCommandi(AMBIENT_LIGHT_COLOR,(color));
1419
sendCommandi(AMBIENT_LIGHT_ALPHA,(color >> 24));
1520
}

src/gu/sceGuAmbientColor.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010

1111
void sceGuAmbientColor(unsigned int color)
1212
{
13+
#ifdef GU_DEBUG
14+
printf("sceGuAmbientColor(0x%08X);\n", color);
15+
assert(gu_init && "GU not initialized");
16+
#endif
17+
1318
sendCommandi(AMBIENT_COLOR, color);
1419
sendCommandi(AMBIENT_ALPHA, color >> 24);
1520
}

src/gu/sceGuBeginObject.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@
1010

1111
void sceGuBeginObject(int vertex_type, int count, const void *indices, const void *vertices)
1212
{
13+
#ifdef GU_DEBUG
14+
printf("sceGuBeginObject(%d, %d, %p, %p);\n", vertex_type, count, indices, vertices);
15+
assert(gu_init && "GU not initialized");
16+
assert(count > 0 && count <= 255 && (count % 8) == 0 && "Invalid vertex count - must be positive, <= 65535, and multiple of 8");
17+
assert(gu_object_stack_depth < GU_OBJECT_STACK_SIZE && "Object stack overflow");
18+
#endif
19+
1320
if (vertex_type)
1421
sendCommandi(VERTEX_TYPE, vertex_type);
1522

src/gu/sceGuBlendFunc.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@
1010

1111
void sceGuBlendFunc(int op, int src, int dest, unsigned int srcfix, unsigned int destfix)
1212
{
13+
#ifdef GU_DEBUG
14+
printf("sceGuBlendFunc(%d, %d, %d, 0x%08X, 0x%08X);\n", op, src, dest, srcfix, destfix);
15+
assert(gu_init && "GU not initialized");
16+
assert(op >= GU_ADD && op <= GU_ABS && "Invalid blend operation");
17+
assert(src >= GU_OTHER_COLOR && src <= GU_FIX && "Invalid source blend factor");
18+
assert(dest >= GU_OTHER_COLOR && dest <= GU_FIX && "Invalid destination blend factor");
19+
#endif
20+
1321
sendCommandi(BLEND_MODE, src | (dest << 4) | (op << 8));
1422
sendCommandi(BLEND_FIXED_A, srcfix);
1523
sendCommandi(BLEND_FIXED_B, destfix);

src/gu/sceGuBoneMatrix.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010

1111
void sceGuBoneMatrix(unsigned int index, const ScePspFMatrix4 *matrix)
1212
{
13+
#ifdef GU_DEBUG
14+
printf("sceGuBoneMatrix(%d, %p);\n", index, matrix);
15+
assert(gu_init && "GU not initialized");
16+
assert(index < 8 && "Invalid bone matrix index");
17+
#endif
18+
1319
unsigned int offset = ((index << 1) + index) << 2; // 3*4 matrix
1420
unsigned int i, j;
1521
const float *fmatrix = (const float *)matrix;

src/gu/sceGuCallList.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010

1111
int sceGuCallList(const void *list)
1212
{
13+
#ifdef GU_DEBUG
14+
printf("sceGuCallList(%p);\n", list);
15+
assert(gu_init && "GU not initialized");
16+
#endif
17+
1318
int res;
1419
unsigned int list_addr = (unsigned int)list;
1520

0 commit comments

Comments
 (0)