-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgfx.c
54 lines (44 loc) · 1.2 KB
/
gfx.c
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
#include "gfx.h"
#include <pspge.h>
#include <pspdisplay.h>
#include <psputils.h>
uint32_t* draw_buffer;
uint32_t* disp_buffer;
void GFX_init(){
draw_buffer = sceGeEdramGetAddr();
disp_buffer = (uint32_t*)sceGeEdramGetAddr() + (271 * 512 * sizeof(uint32_t));
sceDisplaySetMode(0, 480, 272);
sceDisplaySetFrameBuf(disp_buffer, 512, PSP_DISPLAY_PIXEL_FORMAT_8888, 1);
}
void GFX_clear(uint32_t color){
for(int i = 0; i < 512 * 272; i++){
draw_buffer[i] = color;
}
}
void GFX_swap_buffers(){
uint32_t* temp = disp_buffer;
disp_buffer = draw_buffer;
draw_buffer = temp;
sceKernelDcacheWritebackInvalidateAll();
sceDisplaySetFrameBuf(disp_buffer, 512, PSP_DISPLAY_PIXEL_FORMAT_8888, PSP_DISPLAY_SETBUF_NEXTFRAME);
}
void GFX_draw_rect(unsigned int x, unsigned int y, unsigned int w, unsigned int h, uint32_t color){
if (x > 480){
x = 480;
}
if (y > 272){
y = 272;
}
if (x + w > 480){
w = 480 - x;
}
if (y + h > 272){
h = 272 - y;
}
int off = x + (y * 512);
for (int y1 = 0; y1 < h; y1++){
for (int x1 = 0; x1 < w; x1++){
draw_buffer[x1 + off + y1 * 512] = color;
}
}
}