PS2SDK
PS2 Homebrew Libraries
graph_config.c
1 #include <stdio.h>
2 #include <errno.h>
3 #include <string.h>
4 
5 #include <graph.h>
6 #include <graph_config.h>
7 
8 int graph_make_config(int mode, int interlace, int ffmd, int x, int y, int flicker_filter, char *config)
9 {
10 
11  // Save the current mode value.
12  switch (mode)
13  {
14 
15  case GRAPH_MODE_NTSC: sprintf(config, "GRAPH_MODE_NTSC:"); break;
16  case GRAPH_MODE_PAL: sprintf(config, "GRAPH_MODE_PAL:"); break;
17  case GRAPH_MODE_HDTV_480P: sprintf(config, "GRAPH_MODE_HDTV_480P:"); break;
18  case GRAPH_MODE_HDTV_576P: sprintf(config, "GRAPH_MODE_HDTV_576P:"); break;
19  case GRAPH_MODE_HDTV_720P: sprintf(config, "GRAPH_MODE_HDTV_720P:"); break;
20  case GRAPH_MODE_HDTV_1080I: sprintf(config, "GRAPH_MODE_HDTV_1080I:"); break;
21  case GRAPH_MODE_VGA_640_60: sprintf(config, "GRAPH_MODE_VGA_640_60:"); break;
22  case GRAPH_MODE_VGA_640_72: sprintf(config, "GRAPH_MODE_VGA_640_72:"); break;
23  case GRAPH_MODE_VGA_640_75: sprintf(config, "GRAPH_MODE_VGA_640_75:"); break;
24  case GRAPH_MODE_VGA_640_85: sprintf(config, "GRAPH_MODE_VGA_640_85:"); break;
25  case GRAPH_MODE_VGA_800_56: sprintf(config, "GRAPH_MODE_VGA_800_56:"); break;
26  case GRAPH_MODE_VGA_800_60: sprintf(config, "GRAPH_MODE_VGA_800_60:"); break;
27  case GRAPH_MODE_VGA_800_72: sprintf(config, "GRAPH_MODE_VGA_800_72:"); break;
28  case GRAPH_MODE_VGA_800_75: sprintf(config, "GRAPH_MODE_VGA_800_75:"); break;
29  case GRAPH_MODE_VGA_800_85: sprintf(config, "GRAPH_MODE_VGA_800_85:"); break;
30  case GRAPH_MODE_VGA_1024_60: sprintf(config, "GRAPH_MODE_VGA_1024_60:"); break;
31  case GRAPH_MODE_VGA_1024_70: sprintf(config, "GRAPH_MODE_VGA_1024_70:"); break;
32  case GRAPH_MODE_VGA_1024_75: sprintf(config, "GRAPH_MODE_VGA_1024_75:"); break;
33  case GRAPH_MODE_VGA_1024_85: sprintf(config, "GRAPH_MODE_VGA_1024_85:"); break;
34  case GRAPH_MODE_VGA_1280_60: sprintf(config, "GRAPH_MODE_VGA_1280_60:"); break;
35  case GRAPH_MODE_VGA_1280_75: sprintf(config, "GRAPH_MODE_VGA_1280_75:"); break;
36  default: sprintf(config, "GRAPH_MODE_AUTO:"); break;
37 
38  }
39 
40  // Save the current interlacing mode.
41  switch (interlace)
42  {
43 
44  case GRAPH_MODE_NONINTERLACED: sprintf(config, "GRAPH_MODE_NONINTERLACED:"); break;
45  case GRAPH_MODE_INTERLACED: //Fall through
46  default: sprintf(config, "GRAPH_MODE_INTERLACED:"); break;
47 
48  }
49 
50  // Save the current field mode.
51  switch (ffmd)
52  {
53 
54  case GRAPH_MODE_FRAME: sprintf(config, "GRAPH_MODE_FRAME:"); break;
55  case GRAPH_MODE_FIELD: //Fall through
56  default: sprintf(config, "GRAPH_MODE_FIELD:"); break;
57 
58  }
59 
60  // Save status of flicker filter.
61  switch (flicker_filter)
62  {
63 
64  case GRAPH_ENABLE: sprintf(config, "GRAPH_ENABLE:"); break;
65  case GRAPH_DISABLE: //Fall through
66  default: sprintf(config, "GRAPH_DISABLE:"); break;
67 
68  }
69 
70  // Save the current screen offset.
71  sprintf(config, "%d:",x);
72  sprintf(config, "%d:",y);
73 
74  // End function.
75  return 0;
76 
77 }
78 
79 int graph_set_config(char *config)
80 {
81  char *temp0, *temp1;
82  int mode, interlace, ffmd;
83  //int x, y; //Not used
84  int flicker_filter;
85 
86  // Extract the mode config value.
87  temp0 = config; temp1 = strtok(temp0, ":"); temp0 += strlen(temp1) + 1;
88 
89  // Parse the mode config value.
90  if (strcmp(temp1, "GRAPH_MODE_AUTO" ) == 0) { mode = GRAPH_MODE_AUTO; } else
91  if (strcmp(temp1, "GRAPH_MODE_NTSC" ) == 0) { mode = GRAPH_MODE_NTSC; } else
92  if (strcmp(temp1, "GRAPH_MODE_PAL" ) == 0) { mode = GRAPH_MODE_PAL; } else
93  if (strcmp(temp1, "GRAPH_MODE_HDTV_480P" ) == 0) { mode = GRAPH_MODE_HDTV_480P; } else
94  if (strcmp(temp1, "GRAPH_MODE_HDTV_576P" ) == 0) { mode = GRAPH_MODE_HDTV_576P; } else
95  if (strcmp(temp1, "GRAPH_MODE_HDTV_720P" ) == 0) { mode = GRAPH_MODE_HDTV_720P; } else
96  if (strcmp(temp1, "GRAPH_MODE_HDTV_1080I" ) == 0) { mode = GRAPH_MODE_HDTV_1080I; } else
97  if (strcmp(temp1, "GRAPH_MODE_VGA_640_60" ) == 0) { mode = GRAPH_MODE_VGA_640_60; } else
98  if (strcmp(temp1, "GRAPH_MODE_VGA_640_72" ) == 0) { mode = GRAPH_MODE_VGA_640_72; } else
99  if (strcmp(temp1, "GRAPH_MODE_VGA_640_75" ) == 0) { mode = GRAPH_MODE_VGA_640_75; } else
100  if (strcmp(temp1, "GRAPH_MODE_VGA_640_85" ) == 0) { mode = GRAPH_MODE_VGA_640_85; } else
101  if (strcmp(temp1, "GRAPH_MODE_VGA_800_56" ) == 0) { mode = GRAPH_MODE_VGA_800_56; } else
102  if (strcmp(temp1, "GRAPH_MODE_VGA_800_60" ) == 0) { mode = GRAPH_MODE_VGA_800_60; } else
103  if (strcmp(temp1, "GRAPH_MODE_VGA_800_72" ) == 0) { mode = GRAPH_MODE_VGA_800_72; } else
104  if (strcmp(temp1, "GRAPH_MODE_VGA_800_75" ) == 0) { mode = GRAPH_MODE_VGA_800_75; } else
105  if (strcmp(temp1, "GRAPH_MODE_VGA_800_85" ) == 0) { mode = GRAPH_MODE_VGA_800_85; } else
106  if (strcmp(temp1, "GRAPH_MODE_VGA_1024_60" ) == 0) { mode = GRAPH_MODE_VGA_1024_60; } else
107  if (strcmp(temp1, "GRAPH_MODE_VGA_1024_70" ) == 0) { mode = GRAPH_MODE_VGA_1024_70; } else
108  if (strcmp(temp1, "GRAPH_MODE_VGA_1024_75" ) == 0) { mode = GRAPH_MODE_VGA_1024_75; } else
109  if (strcmp(temp1, "GRAPH_MODE_VGA_1024_85" ) == 0) { mode = GRAPH_MODE_VGA_1024_85; } else
110  if (strcmp(temp1, "GRAPH_MODE_VGA_1280_60" ) == 0) { mode = GRAPH_MODE_VGA_1280_60; } else
111  if (strcmp(temp1, "GRAPH_MODE_VGA_1280_75" ) == 0) { mode = GRAPH_MODE_VGA_1280_75; }
112  else
113  {
114 
115  mode = GRAPH_MODE_AUTO;
116 
117  }
118 
119  // Read the interlace config value.
120  temp1 = strtok(temp0, ":"); temp0 += strlen(temp1) + 1;
121 
122  // Parse the interlace config value.
123  if (strcmp(temp1, "GRAPH_MODE_NONINTERLACED" ) == 0) { interlace = GRAPH_MODE_NONINTERLACED; } else
124  if (strcmp(temp1, "GRAPH_MODE_INTERLACED" ) == 0) { interlace = GRAPH_MODE_INTERLACED; }
125  else
126  {
127 
128  interlace = GRAPH_MODE_INTERLACED;
129 
130  }
131 
132  // Read the field mode config value.
133  temp1 = strtok(temp0, ":"); temp0 += strlen(temp1) + 1;
134 
135  // Parse the field mode config value.
136  if (strcmp(temp1, "GRAPH_MODE_FRAME" ) == 0) { ffmd = GRAPH_MODE_FRAME; } else
137  if (strcmp(temp1, "GRAPH_MODE_FIELD" ) == 0) { ffmd = GRAPH_MODE_FIELD; }
138  else
139  {
140 
141  ffmd = GRAPH_MODE_FIELD;
142 
143  }
144 
145  // Read the flicker_filter config value.
146  temp1 = strtok(temp0, ":"); temp0 += strlen(temp1) + 1;
147 
148  // Parse the flicker_filter config value.
149  if (strcmp(temp1, "GRAPH_DISABLE" ) == 0) { flicker_filter = GRAPH_DISABLE; } else
150  if (strcmp(temp1, "GRAPH_ENABLE" ) == 0) { flicker_filter = GRAPH_ENABLE; }
151  else
152  {
153 
154  flicker_filter = GRAPH_ENABLE;
155 
156  }
157 
158  // Disable flicker filter if the mode is noninterlaced.
159  if (interlace == GRAPH_MODE_NONINTERLACED)
160  {
161 
162  flicker_filter = GRAPH_DISABLE;
163 
164  }
165 
166  // Read the x config value.
167  temp1 = strtok(temp0, ":"); temp0 += strlen(temp1) + 1;
168 
169  // Parse the x config value.
170  // x = (int)strtol(temp1,NULL,10); //Not used
171 
172  // Read the y config value.
173  temp1 = strtok(temp0, ":"); temp0 += strlen(temp1) + 1;
174 
175  // Parse the y config value.
176  // y = (int)strtol(temp1,NULL,10); //Not used
177 
178  graph_set_mode(interlace,mode,ffmd,flicker_filter);
179  // End function.
180  return 0;
181 
182 }
183 
184 int graph_load_config(char *filename)
185 {
186 
187  FILE *infile; char config[512];
188 
189  // Open the config file.
190  if ((infile = fopen(filename, "r")) == NULL)
191  {
192 
193  return -ENOENT;
194 
195  }
196 
197  // Read the config file contents.
198  if (fread(config, 1, sizeof(config), infile) != sizeof(config))
199  {
200 
201  fclose(infile);
202  return -EIO;
203 
204  }
205 
206  // Close the config file.
207  if (fclose(infile) != 0)
208  {
209 
210  return -1;
211 
212  }
213 
214  // Set the current mode config information.
215  return graph_set_config(config);
216 
217 }
218 
219 int graph_save_config(char *filename)
220 {
221 
222  FILE *outfile; char config[512];
223 
224  // Get the current mode config information.
225  graph_get_config(config);
226 
227  // Open the config file.
228  if ((outfile = fopen(filename, "w")) == NULL)
229  {
230 
231  return -ENOENT;
232 
233  }
234 
235  // Write the config file contents.
236  if (fwrite(config, 1, strnlen(config, sizeof(config)), outfile) == strnlen(config, sizeof(config)))
237  {
238 
239  fclose(outfile);
240  return -EIO;
241 
242  }
243 
244  // Close the config file.
245  if (fclose(outfile) != 0)
246  {
247 
248  return -1;
249 
250  }
251 
252  // End function.
253  return 0;
254 
255 }
graph_config.h
GRAPH_MODE_VGA_1024_85
#define GRAPH_MODE_VGA_1024_85
Definition: graph.h:51
GRAPH_MODE_VGA_640_60
#define GRAPH_MODE_VGA_640_60
Definition: graph.h:27
GRAPH_MODE_HDTV_720P
#define GRAPH_MODE_HDTV_720P
Definition: graph.h:23
GRAPH_MODE_HDTV_480P
#define GRAPH_MODE_HDTV_480P
Definition: graph.h:19
GRAPH_MODE_VGA_800_85
#define GRAPH_MODE_VGA_800_85
Definition: graph.h:43
GRAPH_MODE_VGA_1024_75
#define GRAPH_MODE_VGA_1024_75
Definition: graph.h:49
GRAPH_MODE_PAL
#define GRAPH_MODE_PAL
Definition: graph.h:17
GRAPH_MODE_VGA_640_75
#define GRAPH_MODE_VGA_640_75
Definition: graph.h:31
EIO
#define EIO
Definition: errno.h:29
GRAPH_MODE_AUTO
#define GRAPH_MODE_AUTO
Definition: graph.h:13
ENOENT
#define ENOENT
Definition: errno.h:23
GRAPH_MODE_VGA_1280_75
#define GRAPH_MODE_VGA_1280_75
Definition: graph.h:55
GRAPH_MODE_VGA_800_60
#define GRAPH_MODE_VGA_800_60
Definition: graph.h:37
GRAPH_MODE_HDTV_576P
#define GRAPH_MODE_HDTV_576P
Definition: graph.h:21
graph_save_config
int graph_save_config(char *filename)
Definition: graph_config.c:219
GRAPH_MODE_VGA_640_72
#define GRAPH_MODE_VGA_640_72
Definition: graph.h:29
GRAPH_MODE_NTSC
#define GRAPH_MODE_NTSC
Definition: graph.h:15
GRAPH_MODE_VGA_1024_60
#define GRAPH_MODE_VGA_1024_60
Definition: graph.h:45
GRAPH_MODE_VGA_640_85
#define GRAPH_MODE_VGA_640_85
Definition: graph.h:33
stdio.h
graph_load_config
int graph_load_config(char *filename)
Definition: graph_config.c:184
GRAPH_MODE_VGA_800_56
#define GRAPH_MODE_VGA_800_56
Definition: graph.h:35
GRAPH_MODE_VGA_1024_70
#define GRAPH_MODE_VGA_1024_70
Definition: graph.h:47
GRAPH_MODE_VGA_1280_60
#define GRAPH_MODE_VGA_1280_60
Definition: graph.h:53
graph.h
GRAPH_DISABLE
#define GRAPH_DISABLE
Definition: graph.h:67
GRAPH_MODE_VGA_800_72
#define GRAPH_MODE_VGA_800_72
Definition: graph.h:39
graph_get_config
int graph_get_config(char *config)
Definition: graph_mode.c:426
GRAPH_MODE_HDTV_1080I
#define GRAPH_MODE_HDTV_1080I
Definition: graph.h:25
graph_set_config
int graph_set_config(char *config)
Definition: graph_config.c:79
graph_make_config
int graph_make_config(int mode, int interlace, int ffmd, int x, int y, int flicker_filter, char *config)
Definition: graph_config.c:8
graph_set_mode
int graph_set_mode(int interlace, int mode, int ffmd, int flicker_filter)
Definition: graph_mode.c:130
errno.h
GRAPH_MODE_VGA_800_75
#define GRAPH_MODE_VGA_800_75
Definition: graph.h:41