PS2SDK
PS2 Homebrew Libraries
Loading...
Searching...
No Matches
graph.c
1#include <kernel.h>
2#include <gs_privileged.h>
3
4#include <graph.h>
5
6int graph_initialize(int fbp, int width, int height, int psm, int x, int y)
7{
8
9 int mode = graph_get_region();
10
11 // Set a default interlaced video mode with flicker filter.
12 graph_set_mode(GRAPH_MODE_INTERLACED, mode, GRAPH_MODE_FIELD, GRAPH_ENABLE);
13
14 // Set the screen up
15 graph_set_screen(0,0,width,height);
16
17 // Set black background
18 graph_set_bgcolor(0,0,0);
19
20 graph_set_framebuffer_filtered(fbp,width,psm,x,y);
21
23
24 // End function.
25 return 0;
26
27}
28
29int graph_add_vsync_handler(int (*vsync_callback)())
30{
31
32 int callback_id;
33
34 DIntr();
35
36 callback_id = AddIntcHandler(INTC_VBLANK_S, vsync_callback, -1);
37
38 EnableIntc(INTC_VBLANK_S);
39
40 EIntr();
41
42 return callback_id;
43
44}
45
46void graph_remove_vsync_handler(int callback_id)
47{
48
49 DIntr();
50
51 DisableIntc(INTC_VBLANK_S);
52
53 RemoveIntcHandler(INTC_VBLANK_S, callback_id);
54
55 EIntr();
56
57}
58
59int graph_get_field(void)
60{
61
62 // Return the currently displayed field.
63 if (*GS_REG_CSR & (1 << 13))
64 {
65
66 return GRAPH_FIELD_ODD;
67
68 }
69
70 return GRAPH_FIELD_EVEN;
71
72}
73
75{
76
77 // Initiate hsync interrupt
78 *GS_REG_CSR |= *GS_REG_CSR & 4;
79
80 // Wait for hsync interrupt to be generated.
81 while (!(*GS_REG_CSR & 4));
82
83}
84
86{
87
88 return (*GS_REG_CSR & 8);
89
90}
91
93{
94
95 *GS_REG_CSR |= *GS_REG_CSR & 8;
96
97}
98
100{
101
102 // Initiate vsync interrupt.
103 *GS_REG_CSR |= *GS_REG_CSR & 8;
104
105 // Wait for vsync interrupt to be generated.
106 while (!(*GS_REG_CSR & 8));
107
108}
int graph_set_screen(int x, int y, int width, int height)
Definition graph_mode.c:186
void graph_set_bgcolor(unsigned char r, unsigned char g, unsigned char b)
Definition graph_mode.c:297
void graph_remove_vsync_handler(int callback_id)
Definition graph.c:46
int graph_initialize(int fbp, int width, int height, int psm, int x, int y)
Definition graph.c:6
int graph_add_vsync_handler(int(*vsync_callback)())
Definition graph.c:29
void graph_enable_output(void)
Definition graph_mode.c:315
void graph_wait_vsync(void)
Definition graph.c:99
void graph_set_framebuffer_filtered(int fbp, int width, int psm, int x, int y)
Definition graph_mode.c:268
int graph_get_region(void)
Definition graph_mode.c:114
int graph_check_vsync(void)
Definition graph.c:85
void graph_start_vsync(void)
Definition graph.c:92
void graph_wait_hsync(void)
Definition graph.c:74
int graph_set_mode(int interlace, int mode, int ffmd, int flicker_filter)
Definition graph_mode.c:130
#define GS_REG_CSR