ps2sdk  1.1
A collection of Open Source libraries used for developing applications on Sony's PlayStation 2® (PS2).
graph.c
Go to the documentation of this file.
1 #include <kernel.h>
2 #include <gs_privileged.h>
3 
4 #include <graph.h>
5 
6 int 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.
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 
29 int 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 
39 
40  EIntr();
41 
42  return callback_id;
43 
44 }
45 
46 void graph_remove_vsync_handler(int callback_id)
47 {
48 
49  DIntr();
50 
52 
53  RemoveIntcHandler(INTC_VBLANK_S, callback_id);
54 
55  EIntr();
56 
57 }
58 
59 int 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 
74 void graph_wait_hsync(void)
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 
99 void graph_wait_vsync(void)
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:183
void graph_set_bgcolor(unsigned char r, unsigned char g, unsigned char b)
Definition: graph_mode.c:294
#define GRAPH_ENABLE
Definition: graph.h:68
void graph_enable_output(void)
Definition: graph_mode.c:312
#define GRAPH_FIELD_EVEN
Definition: graph.h:63
void graph_set_framebuffer_filtered(int fbp, int width, int psm, int x, int y)
Definition: graph_mode.c:265
int graph_get_region(void)
Definition: graph_mode.c:111
#define GRAPH_FIELD_ODD
Definition: graph.h:64
#define GRAPH_MODE_INTERLACED
Definition: graph.h:58
int graph_set_mode(int interlace, int mode, int ffmd, int flicker_filter)
Definition: graph_mode.c:127
#define GRAPH_MODE_FIELD
Definition: graph.h:60
#define GS_REG_CSR
Definition: gs_privileged.h:45
int EnableIntc(int intc)
int DisableIntc(int intc)
s32 RemoveIntcHandler(s32 cause, s32 handler_id)
s32 AddIntcHandler(s32 cause, s32(*handler_func)(s32 cause), s32 next)
@ INTC_VBLANK_S
Definition: kernel.h:85
int DIntr(void)
int EIntr(void)
s32 x
Definition: libmouse.c:34
s32 y
Definition: libmouse.c:34
s32 mode
Definition: rpc_client.c:15
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_get_field(void)
Definition: graph.c:59
int graph_add_vsync_handler(int(*vsync_callback)())
Definition: graph.c:29
void graph_wait_vsync(void)
Definition: graph.c:99
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