-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathmain.c
More file actions
115 lines (87 loc) · 2.66 KB
/
main.c
File metadata and controls
115 lines (87 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include <pspuser.h>
#include <pspgu.h>
#include <pspdisplay.h>
PSP_MODULE_INFO("shape", 0, 1, 0);
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_VFPU | THREAD_ATTR_USER);
#define BUFFER_WIDTH 512
#define BUFFER_HEIGHT 272
#define SCREEN_WIDTH 480
#define SCREEN_HEIGHT BUFFER_HEIGHT
char list[0x20000] __attribute__((aligned(64)));
int running;
int exit_callback(int arg1, int arg2, void *common) {
running = 0;
return 0;
}
int callback_thread(SceSize args, void *argp) {
int cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
sceKernelRegisterExitCallback(cbid);
sceKernelSleepThreadCB();
return 0;
}
int setup_callbacks(void) {
int thid = sceKernelCreateThread("update_thread", callback_thread, 0x11, 0xFA0, 0, 0);
if(thid >= 0)
sceKernelStartThread(thid, 0, 0);
return thid;
}
void initGu(){
sceGuInit();
//Set up buffers
sceGuStart(GU_DIRECT, list);
sceGuDrawBuffer(GU_PSM_8888,(void*)0,BUFFER_WIDTH);
sceGuDispBuffer(SCREEN_WIDTH,SCREEN_HEIGHT,(void*)0x88000,BUFFER_WIDTH);
sceGuDepthBuffer((void*)0x110000,BUFFER_WIDTH);
//Set up viewport
sceGuOffset(2048 - (SCREEN_WIDTH / 2), 2048 - (SCREEN_HEIGHT / 2));
sceGuViewport(2048, 2048, SCREEN_WIDTH, SCREEN_HEIGHT);
sceGuEnable(GU_SCISSOR_TEST);
sceGuScissor(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
//Set some stuff
sceGuDepthRange(65535, 0); //Use the full buffer for depth testing - buffer is reversed order
sceGuDepthFunc(GU_GEQUAL); //Depth buffer is reversed, so GEQUAL instead of LEQUAL
sceGuEnable(GU_DEPTH_TEST); //Enable depth testing
sceGuFinish();
sceGuDisplay(GU_TRUE);
}
void endGu(){
sceGuDisplay(GU_FALSE);
sceGuTerm();
}
void startFrame(){
sceGuStart(GU_DIRECT, list);
sceGuClearColor(0xFFFFFFFF); // White background
sceGuClear(GU_COLOR_BUFFER_BIT);
}
void endFrame(){
sceGuFinish();
sceGuSync(0, 0);
sceDisplayWaitVblankStart();
sceGuSwapBuffers();
}
typedef struct {
unsigned short u, v;
short x, y, z;
} Vertex;
void drawRect(float x, float y, float w, float h) {
Vertex* vertices = (Vertex*)sceGuGetMemory(2 * sizeof(Vertex));
vertices[0].x = x;
vertices[0].y = y;
vertices[1].x = x + w;
vertices[1].y = y + h;
sceGuColor(0xFF0000FF); // Red, colors are ABGR
sceGuDrawArray(GU_SPRITES, GU_TEXTURE_16BIT | GU_VERTEX_16BIT | GU_TRANSFORM_2D, 2, 0, vertices);
}
int main() {
// Make exiting with the home button possible
setup_callbacks();
// Setup the library used for rendering
initGu();
running = 1;
while(running){
startFrame();
drawRect(216, 96, 34, 64);
endFrame();
}
return 0;
}