Skip to content

Commit 2ecbb9d

Browse files
committed
Fixing remaining magic numbers
1 parent 7f1ca0a commit 2ecbb9d

19 files changed

+142
-97
lines changed

src/display/pspdisplay.h

+7-4
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

+1
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

+1-1
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
{

src/gu/pspgu.h

+5-3
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
@@ -1525,8 +1527,8 @@ void sceGuDrawArrayN(int primitive_type, int vertex_type, int vcount, int primco
15251527
* Set how the display should be set
15261528
*
15271529
* Available behaviours are:
1528-
* - PSP_DISPLAY_SETBUF_IMMEDIATE - Display is swapped immediately
1529-
* - PSP_DISPLAY_SETBUF_NEXTFRAME - Display is swapped on the next frame
1530+
* - PSP_DISPLAY_SETBUF_NEXTHSYNC - Display is swapped on the next hsync
1531+
* - PSP_DISPLAY_SETBUF_NEXTVSYNC - Display is swapped on the next vsync
15301532
*
15311533
* Do remember that this swaps the pointers internally, regardless of setting, so be careful to wait until the next
15321534
* vertical blank or use another buffering algorithm (see guSwapBuffersCallback()).

src/gu/resetValues.c

+2-2
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/sceGuColor.c

+1-1
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

+1-1
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

+1-1
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

+3-3
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;

src/gu/sceGuEnable.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,6 @@ void sceGuEnable(int state)
8989
break;
9090
}
9191

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

src/gu/sceGuFinish.c

-36
Original file line numberDiff line numberDiff line change
@@ -8,42 +8,6 @@
88

99
#include "guInternal.h"
1010

11-
int sceGuFinishId(unsigned int id)
12-
{
13-
switch (gu_curr_context)
14-
{
15-
case GU_DIRECT:
16-
case GU_SEND:
17-
{
18-
sendCommandi(FINISH, id & 0xffff);
19-
sendCommandiStall(END, 0);
20-
}
21-
break;
22-
23-
case GU_CALL:
24-
{
25-
if (gu_call_mode == GU_CALL_SIGNAL)
26-
{
27-
sendCommandi(SIGNAL, 0x120000);
28-
sendCommandi(END, 0);
29-
sendCommandiStall(NOP, 0);
30-
}
31-
else
32-
{
33-
sendCommandi(RET, 0);
34-
}
35-
}
36-
break;
37-
}
38-
39-
unsigned int size = ((unsigned int)gu_list->current) - ((unsigned int)gu_list->start);
40-
41-
// go to parent list
42-
gu_curr_context = gu_list->parent_context;
43-
gu_list = &gu_contexts[gu_curr_context].list;
44-
return size;
45-
}
46-
4711
int sceGuFinish(void)
4812
{
4913
return sceGuFinishId(0);

src/gu/sceGuFinishId.c

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* PSP Software Development Kit - https://github.com/pspdev
3+
* -----------------------------------------------------------------------
4+
* Licensed under the BSD license, see LICENSE in PSPSDK root for details.
5+
*
6+
* Copyright (c) 2005 Jesper Svennevid
7+
*/
8+
9+
#include "guInternal.h"
10+
11+
int sceGuFinishId(unsigned int id)
12+
{
13+
switch (gu_curr_context)
14+
{
15+
case GU_DIRECT:
16+
case GU_SEND:
17+
{
18+
sendCommandi(FINISH, id & 0xffff);
19+
sendCommandiStall(END, 0);
20+
}
21+
break;
22+
23+
case GU_CALL:
24+
{
25+
if (gu_call_mode == GU_CALL_SIGNAL)
26+
{
27+
sendCommandi(SIGNAL, 0x120000);
28+
sendCommandi(END, 0);
29+
sendCommandiStall(NOP, 0);
30+
}
31+
else
32+
{
33+
sendCommandi(RET, 0);
34+
}
35+
}
36+
break;
37+
}
38+
39+
unsigned int size = ((unsigned int)gu_list->current) - ((unsigned int)gu_list->start);
40+
41+
// go to parent list
42+
gu_curr_context = gu_list->parent_context;
43+
gu_list = &gu_contexts[gu_curr_context].list;
44+
return size;
45+
}

src/gu/sceGuInit.c

+42-18
Original file line numberDiff line numberDiff line change
@@ -235,46 +235,70 @@ static unsigned int __attribute__((aligned(16))) ge_init_list[] =
235235
ZV(END),
236236
};
237237

238-
void callbackFin(int id, void* arg)
238+
void callbackFin(int id, void *arg)
239239
{
240-
GuSettings* settings = (GuSettings*)arg;
240+
GuSettings *settings = (GuSettings *)arg;
241241
if (settings->fin)
242242
settings->fin(id & 0xffff);
243243
}
244244

245-
void callbackSig(int id, void* arg)
245+
void callbackSig(int id, void *arg)
246246
{
247-
GuSettings* settings = (GuSettings*)arg;
247+
GuSettings *settings = (GuSettings *)arg;
248248

249249
settings->signal_history[(settings->signal_offset++) & 15] = id & 0xffff;
250250

251251
if (settings->sig)
252252
settings->sig(id & 0xffff);
253253

254-
sceKernelSetEventFlag(settings->kernel_event_flag,1);
254+
sceKernelSetEventFlag(settings->kernel_event_flag, 1);
255255
}
256256

257-
void sceGuInit(void)
257+
int sceGuInit(void)
258258
{
259+
int res;
259260
PspGeCallbackData callback;
261+
262+
ge_edram_address = sceGeEdramGetAddr();
263+
_sceGuResetGlobalVariables();
264+
265+
res = sceKernelCreateEventFlag("SceGuSignal", PSP_EVENT_WAITMULTIPLE, 3, 0);
266+
if (res < 0)
267+
{
268+
return res;
269+
}
270+
gu_settings.kernel_event_flag = res;
271+
260272
callback.signal_func = callbackSig;
261273
callback.signal_arg = &gu_settings;
262274
callback.finish_func = callbackFin;
263275
callback.finish_arg = &gu_settings;
264-
gu_settings.ge_callback_id = sceGeSetCallback(&callback);
265-
266-
gu_settings.swapBuffersCallback = 0;
267-
gu_settings.swapBuffersBehaviour = PSP_DISPLAY_SETBUF_IMMEDIATE;
268-
269-
ge_edram_address = sceGeEdramGetAddr();
276+
res = sceGeSetCallback(&callback);
277+
if (res < 0)
278+
{
279+
sceKernelDeleteEventFlag(gu_settings.kernel_event_flag);
280+
gu_settings.kernel_event_flag = -1;
281+
return res;
282+
}
283+
gu_settings.ge_callback_id = res;
270284

271285
// initialize graphics hardware
272-
ge_list_executed[0] = sceGeListEnQueue((void *)((unsigned int)ge_init_list & 0x1fffffff), 0, gu_settings.ge_callback_id, 0);
273-
274-
resetValues();
275-
276-
gu_settings.kernel_event_flag = sceKernelCreateEventFlag("SceGuSignal", 512, 3, 0);
277-
286+
res = sceGeListEnQueue((void *)((unsigned int)ge_init_list & 0x1fffffff), 0, gu_settings.ge_callback_id, 0);
287+
if (res < 0)
288+
{
289+
sceKernelDeleteEventFlag(gu_settings.kernel_event_flag);
290+
sceGeUnsetCallback(gu_settings.ge_callback_id);
291+
gu_settings.ge_callback_id = -1;
292+
gu_settings.kernel_event_flag = -1;
293+
return res;
294+
}
295+
ge_list_executed[0] = res;
278296
// wait for init to complete
279297
sceGeListSync(ge_list_executed[0], 0);
298+
sceGeDrawSync(0);
299+
300+
gu_settings.swapBuffersCallback = NULL;
301+
gu_settings.swapBuffersBehaviour = PSP_DISPLAY_SETBUF_NEXTHSYNC;
302+
303+
return 0;
280304
}

src/gu/sceGuSendList.c

+9-6
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,18 @@
1313

1414
int sceGuSendList(int mode, const void *list, PspGeContext *context)
1515
{
16-
gu_settings.signal_offset = 0;
17-
18-
// TODO: figure out this structure
1916
PspGeListArgs args;
20-
args.size = 8; // Size of structure?
17+
int list_id;
18+
int callback;
19+
20+
args.size = sizeof(PspGeListArgs);
2121
args.context = context;
22+
args.numStacks = 0;
23+
args.stacks = NULL;
2224

23-
int list_id = 0;
24-
int callback = gu_settings.ge_callback_id;
25+
callback = gu_settings.ge_callback_id;
26+
gu_settings.signal_offset = 0;
27+
list_id = -1;
2528

2629
switch (mode)
2730
{

src/gu/sceGuSetCallback.c

+8-13
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,19 @@
88

99
#include "guInternal.h"
1010

11-
void* sceGuSetCallback(int signal, GuCallback callback)
11+
void *sceGuSetCallback(int signal, GuCallback callback)
1212
{
13-
GuCallback old_callback = 0;
13+
GuCallback old_callback = NULL;
1414

1515
switch (signal)
1616
{
17-
case GU_CALLBACK_SIGNAL:
18-
{
19-
old_callback = gu_settings.sig;
20-
gu_settings.sig = callback;
21-
}
17+
case GU_CALLBACK_SIGNAL:
18+
old_callback = gu_settings.sig;
19+
gu_settings.sig = callback;
2220
break;
23-
24-
case GU_CALLBACK_FINISH:
25-
{
26-
old_callback = gu_settings.fin;
27-
gu_settings.fin = callback;
28-
}
21+
case GU_CALLBACK_FINISH:
22+
old_callback = gu_settings.fin;
23+
gu_settings.fin = callback;
2924
break;
3025
}
3126

src/gu/sceGuShadeModel.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010

1111
void sceGuShadeModel(int mode)
1212
{
13-
sendCommandi(SHADE_MODE, mode ? 1 : 0);
13+
sendCommandi(SHADE_MODE, mode);
1414
}

src/gu/sceGuSync.c

+10-4
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,15 @@ int sceGuSync(int mode, int what)
1515
{
1616
switch (mode)
1717
{
18-
case GU_SYNC_FINISH: return sceGeDrawSync(what);
19-
case GU_SYNC_LIST: return sceGeListSync(ge_list_executed[0],what);
20-
case GU_SYNC_SEND: return sceGeListSync(ge_list_executed[1],what);
21-
default: case GU_SYNC_SIGNAL: case GU_SYNC_DONE: return 0;
18+
case GU_SYNC_FINISH:
19+
return sceGeDrawSync(what);
20+
case GU_SYNC_LIST:
21+
return sceGeListSync(ge_list_executed[0], what);
22+
case GU_SYNC_SEND:
23+
return sceGeListSync(ge_list_executed[1], what);
24+
default:
25+
case GU_SYNC_SIGNAL:
26+
case GU_SYNC_DONE:
27+
return 0;
2228
}
2329
}

src/samples/prx/image_display/main.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ int main_thread(SceSize args, void *argp){
129129

130130

131131
// get vram
132-
int ret = sceDisplayGetFrameBuf((void*)&vram32, &bufferwidth, &pixelformat, PSP_DISPLAY_SETBUF_IMMEDIATE);
133-
// works with both PSP_DISPLAY_SETBUF_NEXTFRAME and PSP_DISPLAY_SETBUF_IMMEDIATE
132+
int ret = sceDisplayGetFrameBuf((void*)&vram32, &bufferwidth, &pixelformat, PSP_DISPLAY_SETBUF_NEXTHSYNC);
133+
// works with both PSP_DISPLAY_SETBUF_NEXTVSYNC and PSP_DISPLAY_SETBUF_NEXTHSYNC
134134

135135
// check if return value from sceDisplayGetFrameBuf is valid
136136
// check if vram32 is not NULL

0 commit comments

Comments
 (0)