Skip to content

Commit f2b1155

Browse files
authored
Merge pull request #285 from fjtrujy/magic_numbers_gu
Some clean ups around `sceGu`
2 parents 7f1ca0a + 4743678 commit f2b1155

24 files changed

+194
-114
lines changed

src/display/pspdisplay.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,15 @@ enum PspDisplayPixelFormats {
3131
};
3232

3333
enum PspDisplaySetBufSync {
34-
/** Buffer change effective immediately */
35-
PSP_DISPLAY_SETBUF_IMMEDIATE = 0,
36-
/** Buffer change effective next frame */
37-
PSP_DISPLAY_SETBUF_NEXTFRAME = 1
34+
/** Buffer change effective next hsync */
35+
PSP_DISPLAY_SETBUF_NEXTHSYNC = 0,
36+
/** Buffer change effective next vsync */
37+
PSP_DISPLAY_SETBUF_NEXTVSYNC = 1
3838
};
3939

40+
/** Values for retro compatibility */
41+
#define PSP_DISPLAY_SETBUF_IMMEDIATE PSP_DISPLAY_SETBUF_NEXTHSYNC
42+
#define PSP_DISPLAY_SETBUF_NEXTFRAME PSP_DISPLAY_SETBUF_NEXTVSYNC
4043

4144
enum PspDisplayErrorCodes
4245
{

src/gu/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ libpspgu_a_SOURCES = \
5757
sceGuEnable.c \
5858
sceGuEndObject.c \
5959
sceGuFinish.c \
60+
sceGuFinishId.c \
6061
sceGuFog.c \
6162
sceGuFrontFace.c \
6263
sceGuGetAllStatus.c \

src/gu/guInternal.h

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ extern GuLightSettings light_settings[4];
116116

117117
void callbackSig(int id, void *arg);
118118
void callbackFin(int id, void *arg);
119-
void resetValues();
119+
void _sceGuResetGlobalVariables();
120120

121121
typedef enum GECommand
122122
{
@@ -645,12 +645,18 @@ static inline void sendCommandf(GECommand cmd, float argument)
645645
sendCommandi(cmd, t.i >> 8);
646646
}
647647

648-
static inline void sendCommandiStall(GECommand cmd, int argument)
649-
{
650-
sendCommandi(cmd, argument);
651-
652-
if (!gu_object_stack_depth && !gu_curr_context)
653-
sceGeListUpdateStallAddr(ge_list_executed[0], gu_list->current);
648+
static inline int _sceGuUpdateStallAddr(void) {
649+
if (gu_curr_context == GU_DIRECT) {
650+
// Just if there are no objects in the stack (no guBeginObject)
651+
if (!gu_object_stack_depth) {
652+
int res;
653+
res = sceGeListUpdateStallAddr(ge_list_executed[0], gu_list->current);
654+
if (res < 0) {
655+
return res;
656+
}
657+
}
658+
}
659+
return 0;
654660
}
655661

656662
#endif

src/gu/pspgu.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -433,8 +433,10 @@ void sceGuFog(float near, float far, unsigned int color);
433433
* Initalize the GU system
434434
*
435435
* This function MUST be called as the first function, otherwise state is undetermined.
436+
*
437+
* @return 0 for success, < 0 for failure
436438
**/
437-
void sceGuInit(void);
439+
int sceGuInit(void);
438440

439441
/**
440442
* Shutdown the GU system
@@ -475,6 +477,11 @@ void* sceGuSetCallback(int signal, void (*callback)(int));
475477

476478
/**
477479
* Trigger signal to call code from the command stream
480+
*
481+
* Available signals are:
482+
* - GU_SIGNAL_WAIT - Wait for callback to finish
483+
* - GU_SIGNAL_NOWAIT - Do not wait for callback to finish
484+
* - GU_SIGNAL_PAUSE - Pause execution until callback is finished
478485
*
479486
* Available behaviors are:
480487
* - GU_BEHAVIOR_SUSPEND - Stops display list execution until callback function finished
@@ -564,8 +571,9 @@ int sceGuFinishId(unsigned int id);
564571
* Call previously generated display-list
565572
*
566573
* @param list - Display list to call
574+
* @return 0 for success, < 0 for failure
567575
**/
568-
void sceGuCallList(const void* list);
576+
int sceGuCallList(const void* list);
569577

570578
/**
571579
* Set wether to use stack-based calls or signals to handle execution of called lists.
@@ -1525,8 +1533,8 @@ void sceGuDrawArrayN(int primitive_type, int vertex_type, int vcount, int primco
15251533
* Set how the display should be set
15261534
*
15271535
* Available behaviours are:
1528-
* - PSP_DISPLAY_SETBUF_IMMEDIATE - Display is swapped immediately
1529-
* - PSP_DISPLAY_SETBUF_NEXTFRAME - Display is swapped on the next frame
1536+
* - PSP_DISPLAY_SETBUF_NEXTHSYNC - Display is swapped on the next hsync
1537+
* - PSP_DISPLAY_SETBUF_NEXTVSYNC - Display is swapped on the next vsync
15301538
*
15311539
* Do remember that this swaps the pointers internally, regardless of setting, so be careful to wait until the next
15321540
* vertical blank or use another buffering algorithm (see guSwapBuffersCallback()).

src/gu/resetValues.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#include "guInternal.h"
1010

11-
void resetValues()
11+
void _sceGuResetGlobalVariables()
1212
{
1313
unsigned int i;
1414

@@ -18,7 +18,7 @@ void resetValues()
1818
gu_current_frame = 0;
1919
gu_object_stack_depth = 0;
2020

21-
gu_display_on = 0;
21+
gu_display_on = GU_FALSE;
2222
gu_call_mode = GU_CALL_NORMAL;
2323

2424
gu_draw_buffer.pixel_size = 1;

src/gu/sceGuCallList.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,25 @@
88

99
#include "guInternal.h"
1010

11-
void sceGuCallList(const void *list)
11+
int sceGuCallList(const void *list)
1212
{
13+
int res;
1314
unsigned int list_addr = (unsigned int)list;
1415

1516
if (gu_call_mode == GU_CALL_SIGNAL)
1617
{
1718
sendCommandi(SIGNAL, (list_addr >> 16) | 0x110000);
1819
sendCommandi(END, list_addr & 0xffff);
19-
sendCommandiStall(NOP, 0);
2020
}
2121
else
2222
{
2323
sendCommandi(BASE, (list_addr >> 8) & 0xf0000);
24-
sendCommandiStall(CALL, list_addr);
24+
sendCommandi(CALL, list_addr);
2525
}
26+
27+
res = _sceGuUpdateStallAddr();
28+
if (res < 0) {
29+
return res;
30+
}
31+
return 0;
2632
}

src/gu/sceGuColor.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010

1111
void sceGuColor(unsigned int color)
1212
{
13-
sceGuMaterial(7,color);
13+
sceGuMaterial(GU_AMBIENT | GU_DIFFUSE | GU_SPECULAR, color);
1414
}

src/gu/sceGuDisable.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,6 @@ void sceGuDisable(int state)
8989
break;
9090
}
9191

92-
if (state < 22)
92+
if (state < GU_MAX_STATUS)
9393
gu_states &= ~(1 << state);
9494
}

src/gu/sceGuDispBuffer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@ void sceGuDispBuffer(int width, int height, void *dispbp, int dispbw)
3030
sceDisplaySetMode(0, gu_draw_buffer.width, gu_draw_buffer.height);
3131

3232
if (gu_display_on)
33-
sceDisplaySetFrameBuf((void *)(((unsigned int)ge_edram_address) + ((unsigned int)gu_draw_buffer.disp_buffer)), dispbw, gu_draw_buffer.pixel_size, PSP_DISPLAY_SETBUF_NEXTFRAME);
33+
sceDisplaySetFrameBuf((void *)(((unsigned int)ge_edram_address) + ((unsigned int)gu_draw_buffer.disp_buffer)), dispbw, gu_draw_buffer.pixel_size, PSP_DISPLAY_SETBUF_NEXTVSYNC);
3434
}

src/gu/sceGuDisplay.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313

1414
int sceGuDisplay(int state)
1515
{
16-
if (state)
17-
sceDisplaySetFrameBuf((void*)((unsigned int)ge_edram_address+(unsigned int)gu_draw_buffer.disp_buffer),gu_draw_buffer.frame_width,gu_draw_buffer.pixel_size,PSP_DISPLAY_SETBUF_NEXTFRAME);
16+
if (state == GU_TRUE)
17+
sceDisplaySetFrameBuf((void *)((unsigned int)ge_edram_address + (unsigned int)gu_draw_buffer.disp_buffer), gu_draw_buffer.frame_width, gu_draw_buffer.pixel_size, PSP_DISPLAY_SETBUF_NEXTVSYNC);
1818
else
19-
sceDisplaySetFrameBuf(0,0,0,PSP_DISPLAY_SETBUF_NEXTFRAME);
19+
sceDisplaySetFrameBuf(NULL, 0, 0, PSP_DISPLAY_SETBUF_NEXTVSYNC);
2020

2121
gu_display_on = state;
2222
return state;

0 commit comments

Comments
 (0)