PS2SDK
PS2 Homebrew Libraries
dvrav.c
1 /*
2 # _____ ___ ____ ___ ____
3 # ____| | ____| | | |____|
4 # | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
5 #-----------------------------------------------------------------------
6 # Copyright 2021-2021, ps2dev - http://www.ps2dev.org
7 # Licenced under Academic Free License version 2.0
8 # Review ps2sdk README & LICENSE files for further details.
9 */
10 
11 #include <stdbool.h>
12 #include "iomanX.h"
13 #include "loadcore.h"
14 #include "pvrdrv.h"
15 #include "stdio.h"
16 #include "thbase.h"
17 #include "thsemap.h"
18 #include "speedregs.h"
19 #include "errno.h"
20 #define MODNAME "DVRAV"
21 
22 #ifdef DEBUG
23 #define DPRINTF(x...) printf(MODNAME ": " x)
24 #else
25 #define DPRINTF(x...)
26 #endif
27 
28 extern int module_start(int argc, char *argv[], void *startaddr, ModuleInfo_t *mi);
29 extern int module_stop(int argc, char *argv[], void *startaddr, ModuleInfo_t *mi);
30 extern int dvrav_df_init(iomanX_iop_device_t *dev);
31 extern int dvrav_df_exit(iomanX_iop_device_t *dev);
32 extern int dvrav_df_ioctl(iomanX_iop_file_t *f, int cmd, void *param);
33 extern int dvrav_df_devctl(iomanX_iop_file_t *a1, const char *name, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
34 extern int dvrav_df_ioctl2(iomanX_iop_file_t *f, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
35 extern int avioctl2_select_position(iomanX_iop_file_t *a1, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
36 extern int avioctl2_get_position(iomanX_iop_file_t *a1, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
37 extern int avioctl2_position_up(iomanX_iop_file_t *a1, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
38 extern int avioctl2_position_down(iomanX_iop_file_t *a1, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
39 extern int avioctl2_set_d_audio_sel(iomanX_iop_file_t *a1, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
40 extern int avioctl2_get_tun_offset(iomanX_iop_file_t *a1, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
41 extern int avioctl2_tun_offset_up(iomanX_iop_file_t *a1, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
42 extern int avioctl2_tun_offset_down(iomanX_iop_file_t *a1, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
43 extern int avioctl2_tun_scan_ch(iomanX_iop_file_t *a1, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
44 extern int avioctl2_get_bs_gain(iomanX_iop_file_t *a1, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
45 extern int avioctl2_set_preset_info(iomanX_iop_file_t *a1, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
46 extern int avioctl2_change_sound(iomanX_iop_file_t *a1, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
47 extern int avioctl2_set_d_video_sel(iomanX_iop_file_t *a1, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
48 extern int avioctl2_get_av_src(iomanX_iop_file_t *a1, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
49 extern int avioctl2_get_preset_info(iomanX_iop_file_t *a1, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
50 extern int avioctl2_set_position_info(iomanX_iop_file_t *a1, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
51 extern int avioctl2_get_position_info(iomanX_iop_file_t *a1, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
52 extern int avioctl2_tun_scan_mode(iomanX_iop_file_t *a1, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
53 extern int avioctl2_f_select_position(iomanX_iop_file_t *a1, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
54 extern int avioctl2_select_rec_src(iomanX_iop_file_t *a1, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
55 extern int avioctl2_get_rec_src(iomanX_iop_file_t *a1, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
56 extern int avioctl2_tun_scan_mode_euro(iomanX_iop_file_t *a1, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
57 extern int avioctl2_tun_scan_ch_euro(iomanX_iop_file_t *a1, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
58 extern int avioctl2_get_curfreq_info(iomanX_iop_file_t *a1, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
59 extern int avioctl2_get_teletext_ver_no(iomanX_iop_file_t *a1, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
60 extern int avioctl2_set_tv_guide_page(iomanX_iop_file_t *a1, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
61 extern int avioctl2_get_tv_guide_page(iomanX_iop_file_t *a1, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
62 extern int avioctl2_change_mode_tv_to_dvd(iomanX_iop_file_t *a1, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
63 extern int avioctl2_get_vps_data(iomanX_iop_file_t *a1, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
64 extern int avioctl2_get_pdc_data(iomanX_iop_file_t *a1, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
65 extern int avioctl2_get_format1_data(iomanX_iop_file_t *a1, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
66 extern int avioctl2_get_header_time_data(iomanX_iop_file_t *a1, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
67 extern int avioctl2_set_acs_position_euro(iomanX_iop_file_t *a1, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
68 
69 struct DevctlCmdTbl_t
70 {
71  u16 cmd;
72  int (*fn)(iomanX_iop_file_t *f, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
73 } DevctlCmdTbl[33] =
74  {
75  {0x5616, &avioctl2_select_position},
76  {0x5619, &avioctl2_get_position},
77  {0x5617, &avioctl2_position_up},
78  {0x5618, &avioctl2_position_down},
79  {0x5612, &avioctl2_set_d_audio_sel},
80  {0x560B, &avioctl2_get_tun_offset},
81  {0x560C, &avioctl2_tun_offset_up},
82  {0x560D, &avioctl2_tun_offset_down},
83  {0x560E, &avioctl2_tun_scan_ch},
84  {0x560F, &avioctl2_get_bs_gain},
85  {0x5610, &avioctl2_set_preset_info},
86  {0x5611, &avioctl2_change_sound},
87  {0x5613, &avioctl2_set_d_video_sel},
88  {0x5614, &avioctl2_get_av_src},
89  {0x5615, &avioctl2_get_preset_info},
90  {0x561A, &avioctl2_set_position_info},
91  {0x561B, &avioctl2_get_position_info},
92  {0x561C, &avioctl2_tun_scan_mode},
93  {0x561D, &avioctl2_f_select_position},
94  {0x561E, &avioctl2_select_rec_src},
95  {0x561F, &avioctl2_get_rec_src},
96  {0x5618, &avioctl2_tun_scan_mode_euro},
97  {0x5619, &avioctl2_tun_scan_ch_euro},
98  {0x561A, &avioctl2_get_curfreq_info},
99  {0x561B, &avioctl2_get_teletext_ver_no},
100  {0x561C, &avioctl2_set_tv_guide_page},
101  {0x561D, &avioctl2_get_tv_guide_page},
102  {0x561E, &avioctl2_change_mode_tv_to_dvd},
103  {0x561F, &avioctl2_get_vps_data},
104  {0x5620, &avioctl2_get_pdc_data},
105  {0x5621, &avioctl2_get_format1_data},
106  {0x5622, &avioctl2_get_header_time_data},
107  {0x5623, &avioctl2_set_acs_position_euro},
108 };
109 
110 IOMANX_RETURN_VALUE_IMPL(EUNSUP);
111 
112 static iomanX_iop_device_ops_t DvrFuncTbl =
113  {
114  &dvrav_df_init, // init
115  &dvrav_df_exit, // deinit
116  IOMANX_RETURN_VALUE(EUNSUP), // format
117  IOMANX_RETURN_VALUE(EUNSUP), // open
118  IOMANX_RETURN_VALUE(EUNSUP), // close
119  IOMANX_RETURN_VALUE(EUNSUP), // read
120  IOMANX_RETURN_VALUE(EUNSUP), // write
121  IOMANX_RETURN_VALUE(EUNSUP), // lseek
122  &dvrav_df_ioctl, // ioctl
123  IOMANX_RETURN_VALUE(EUNSUP), // remove
124  IOMANX_RETURN_VALUE(EUNSUP), // mkdir
125  IOMANX_RETURN_VALUE(EUNSUP), // rmdir
126  IOMANX_RETURN_VALUE(EUNSUP), // dopen
127  IOMANX_RETURN_VALUE(EUNSUP), // dclose
128  IOMANX_RETURN_VALUE(EUNSUP), // dread
129  IOMANX_RETURN_VALUE(EUNSUP), // getstat
130  IOMANX_RETURN_VALUE(EUNSUP), // chstat
131  IOMANX_RETURN_VALUE(EUNSUP), // rename
132  IOMANX_RETURN_VALUE(EUNSUP), // chdir
133  IOMANX_RETURN_VALUE(EUNSUP), // sync
134  IOMANX_RETURN_VALUE(EUNSUP), // mount
135  IOMANX_RETURN_VALUE(EUNSUP), // umount
136  IOMANX_RETURN_VALUE_S64(EUNSUP), // lseek64
137  &dvrav_df_devctl, // devctl
138  IOMANX_RETURN_VALUE(EUNSUP), // symlink
139  IOMANX_RETURN_VALUE(EUNSUP), // readlink
140  &dvrav_df_ioctl2, // ioctl2
141  };
142 static iomanX_iop_device_t DVRAV = {
143  .name = "dvr_av",
144  .desc = "Digital Video Recorder AV task",
145  .type = (IOP_DT_FS | IOP_DT_FSEXT),
146  .ops = &DvrFuncTbl,
147 };
148 s32 sema_id;
149 
150 // Based off of DESR / PSX DVR system software version 1.31.
151 // Added additional functions from DESR / PSX DVR system software version 2.11.
152 IRX_ID(MODNAME, 1, 1);
153 
154 int _start(int argc, char *argv[], void *startaddr, ModuleInfo_t *mi)
155 {
156  if (argc >= 0)
157  return module_start(argc, argv, startaddr, mi);
158  else
159  return module_stop(argc, argv, startaddr, mi);
160 }
161 
162 int module_start(int argc, char *argv[], void *startaddr, ModuleInfo_t *mi)
163 {
164  int i;
165 
166  (void)argc;
167  (void)argv;
168  (void)startaddr;
169 
170  for (i = 0; i < 30000; ++i) {
171  if (((*((vu32 *)0xB0004230)) & 8) != 0)
172  break;
173  DelayThread(1000);
174  }
175  if (i == 30000) {
176  DPRINTF("AV task of DVRP is not running...\n");
177  return MODULE_NO_RESIDENT_END;
178  } else {
179  if (iomanX_AddDrv(&DVRAV) != 0)
180  return MODULE_NO_RESIDENT_END;
181  }
182 #if 0
183  return MODULE_REMOVABLE_END;
184 #else
185  if (mi && ((mi->newflags & 2) != 0))
186  mi->newflags |= 0x10;
187  return MODULE_RESIDENT_END;
188 #endif
189 }
190 
191 int module_stop(int argc, char *argv[], void *startaddr, ModuleInfo_t *mi)
192 {
193  (void)argc;
194  (void)argv;
195  (void)startaddr;
196  (void)mi;
197 
198  if (iomanX_DelDrv(DVRAV.name) != 0)
199  return MODULE_REMOVABLE_END;
200  return MODULE_NO_RESIDENT_END;
201 }
202 
203 int dvrav_df_init(iomanX_iop_device_t *dev)
204 {
205  int v1;
206  iop_sema_t v3;
207 
208  (void)dev;
209 
210  v3.attr = 0;
211  v3.initial = 1;
212  v3.max = 1;
213  v3.option = 0;
214  v1 = CreateSema(&v3);
215  if (v1 < 0)
216  return -1;
217  sema_id = v1;
218  return 0;
219 }
220 
221 int dvrav_df_exit(iomanX_iop_device_t *dev)
222 {
223  (void)dev;
224 
225  if (DeleteSema(sema_id) != 0)
226  return -1;
227  return 0;
228 }
229 
230 int dvrav_df_ioctl(iomanX_iop_file_t *f, int cmd, void *param)
231 {
232  (void)f;
233  (void)cmd;
234  (void)param;
235 
236  WaitSema(sema_id);
237  SignalSema(sema_id);
238  return -EINVAL;
239 }
240 
241 int dvrav_df_devctl(
242  iomanX_iop_file_t *a1,
243  const char *name,
244  int cmd,
245  void *arg,
246  unsigned int arglen,
247  void *buf,
248  unsigned int buflen)
249 {
250  int v10;
251  unsigned int v11;
252  unsigned int v12;
253 
254  (void)name;
255 
256  v10 = 0;
257  v11 = 0;
258  WaitSema(sema_id);
259  v12 = 0;
260  while (DevctlCmdTbl[v12].cmd != cmd) {
261  v12 = ++v11;
262  if (v11 >= sizeof(DevctlCmdTbl) / sizeof(DevctlCmdTbl[0]))
263  goto LABEL_5;
264  }
265  v10 = DevctlCmdTbl[v12].fn(a1, cmd, arg, arglen, buf, buflen);
266 LABEL_5:
267  if (v11 == sizeof(DevctlCmdTbl) / sizeof(DevctlCmdTbl[0]))
268  v10 = -EINVAL;
269  SignalSema(sema_id);
270  return v10;
271 }
272 
273 int dvrav_df_ioctl2(iomanX_iop_file_t *f, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen)
274 {
275  (void)f;
276  (void)cmd;
277  (void)arg;
278  (void)arglen;
279  (void)buf;
280  (void)buflen;
281 
282  WaitSema(sema_id);
283  SignalSema(sema_id);
284  return -EINVAL;
285 }
286 
287 int avioctl2_get_tun_offset(
288  iomanX_iop_file_t *a1,
289  int cmd,
290  void *arg,
291  unsigned int arglen,
292  void *buf,
293  unsigned int buflen)
294 {
295  drvdrv_exec_cmd_ack cmdack;
296 
297  (void)a1;
298  (void)cmd;
299  (void)arg;
300  (void)arglen;
301  (void)buflen;
302 
303  cmdack.command = 0x3102;
304  cmdack.input_word_count = 0;
305  if (DvrdrvExecCmdAck(&cmdack)) {
306  DPRINTF("avioctl2_get_tun_offset -> Handshake error!\n");
307  return -EIO;
308  } else if (cmdack.ack_status_ack) {
309  DPRINTF("avioctl2_get_tun_offset -> Status error!\n");
310  return -EADV;
311  } else {
312  *(u16 *)buf = cmdack.output_word[0];
313  *((u16 *)buf + 1) = cmdack.output_word[1];
314  }
315  return 0;
316 }
317 
318 int avioctl2_tun_offset_up(
319  iomanX_iop_file_t *a1,
320  int cmd,
321  void *arg,
322  unsigned int arglen,
323  void *buf,
324  unsigned int buflen)
325 {
326  drvdrv_exec_cmd_ack cmdack;
327 
328  (void)a1;
329  (void)cmd;
330  (void)arg;
331  (void)arglen;
332  (void)buflen;
333 
334  cmdack.command = 0x3103;
335  cmdack.input_word_count = 0;
336  if (DvrdrvExecCmdAck(&cmdack)) {
337  DPRINTF("avioctl2_tun_offset_up -> Handshake error!\n");
338  return -EIO;
339  } else if (cmdack.ack_status_ack) {
340  DPRINTF("avioctl2_tun_offset_up -> Status error!\n");
341  return -EADV;
342  } else {
343  *(u16 *)buf = cmdack.output_word[0];
344  *((u16 *)buf + 1) = cmdack.output_word[1];
345  *((u16 *)buf + 2) = cmdack.output_word[2];
346  *((u16 *)buf + 3) = cmdack.output_word[3];
347  *((u16 *)buf + 4) = cmdack.output_word[4];
348  }
349  return 0;
350 }
351 
352 int avioctl2_tun_offset_down(
353  iomanX_iop_file_t *a1,
354  int cmd,
355  void *arg,
356  unsigned int arglen,
357  void *buf,
358  unsigned int buflen)
359 {
360  drvdrv_exec_cmd_ack cmdack;
361 
362  (void)a1;
363  (void)cmd;
364  (void)arg;
365  (void)arglen;
366  (void)buflen;
367 
368  cmdack.command = 0x3104;
369  cmdack.input_word_count = 0;
370  if (DvrdrvExecCmdAck(&cmdack)) {
371  DPRINTF("avioctl2_tun_offset_down -> Handshake error!\n");
372  return -EIO;
373  } else if (cmdack.ack_status_ack) {
374  DPRINTF("avioctl2_tun_offset_down -> Status error!\n");
375  return -EADV;
376  } else {
377  *(u16 *)buf = cmdack.output_word[0];
378  *((u16 *)buf + 1) = cmdack.output_word[1];
379  *((u16 *)buf + 2) = cmdack.output_word[2];
380  *((u16 *)buf + 3) = cmdack.output_word[3];
381  *((u16 *)buf + 4) = cmdack.output_word[4];
382  }
383  return 0;
384 }
385 
386 int avioctl2_tun_scan_ch(
387  iomanX_iop_file_t *a1,
388  int cmd,
389  void *arg,
390  unsigned int arglen,
391  void *buf,
392  unsigned int buflen)
393 {
394  drvdrv_exec_cmd_ack cmdack;
395 
396  (void)a1;
397  (void)cmd;
398  (void)arglen;
399  (void)buflen;
400 
401  cmdack.command = 0x3105;
402  cmdack.input_word[0] = *(u16 *)arg;
403  cmdack.input_word[1] = *((u16 *)arg + 1);
404  cmdack.input_word[2] = *((u16 *)arg + 2);
405  cmdack.input_word_count = 3;
406  cmdack.timeout = 35000000;
407  if (DvrdrvExecCmdAckComp(&cmdack)) {
408  DPRINTF("avioctl2_tun_scan_ch -> Handshake error!\n");
409  return -EIO;
410  } else if (cmdack.ack_status_ack || cmdack.comp_status) {
411  DPRINTF("avioctl2_tun_scan_ch -> Status error!\n");
412  return -EADV;
413  } else {
414  *(u16 *)buf = cmdack.return_result_word[0];
415  *((u16 *)buf + 1) = cmdack.return_result_word[1];
416  *((u16 *)buf + 2) = cmdack.return_result_word[2];
417  *((u16 *)buf + 3) = cmdack.return_result_word[3];
418  *((u16 *)buf + 4) = cmdack.return_result_word[4];
419  *((u16 *)buf + 5) = cmdack.return_result_word[5];
420  }
421  return 0;
422 }
423 
424 int avioctl2_get_bs_gain(
425  iomanX_iop_file_t *a1,
426  int cmd,
427  void *arg,
428  unsigned int arglen,
429  void *buf,
430  unsigned int buflen)
431 {
432  drvdrv_exec_cmd_ack cmdack;
433 
434  (void)a1;
435  (void)cmd;
436  (void)arg;
437  (void)arglen;
438  (void)buflen;
439 
440  cmdack.command = 0x3106;
441  cmdack.input_word_count = 0;
442  if (DvrdrvExecCmdAck(&cmdack)) {
443  DPRINTF("avioctl2_get_bs_gain -> Handshake error!\n");
444  return -EIO;
445  } else {
446  if (cmdack.ack_status_ack) {
447  DPRINTF("avioctl2_get_bs_gain -> Status error!\n");
448  return -EADV;
449  } else {
450  *(u16 *)buf = cmdack.output_word[0];
451  }
452  }
453  return 0;
454 }
455 
456 int avioctl2_set_preset_info(
457  iomanX_iop_file_t *a1,
458  int cmd,
459  void *arg,
460  unsigned int arglen,
461  void *buf,
462  unsigned int buflen)
463 {
464  drvdrv_exec_cmd_ack cmdack;
465 
466  (void)a1;
467  (void)cmd;
468  (void)arglen;
469  (void)buf;
470  (void)buflen;
471 
472  cmdack.command = 0x3107;
473  cmdack.input_word[0] = *(u16 *)arg;
474  cmdack.input_word[1] = *((u16 *)arg + 1);
475  cmdack.input_word_count = 2;
476  if (DvrdrvExecCmdAck(&cmdack)) {
477  DPRINTF("avioctl2_set_preset_info -> Handshake error!\n");
478  return -EIO;
479  } else {
480  if (cmdack.ack_status_ack) {
481  DPRINTF("avioctl2_set_preset_info -> Status error!\n");
482  return -EADV;
483  }
484  }
485  return 0;
486 }
487 
488 int avioctl2_change_sound(
489  iomanX_iop_file_t *a1,
490  int cmd,
491  void *arg,
492  unsigned int arglen,
493  void *buf,
494  unsigned int buflen)
495 {
496  drvdrv_exec_cmd_ack cmdack;
497 
498  (void)a1;
499  (void)cmd;
500  (void)arg;
501  (void)arglen;
502  (void)buflen;
503 
504  cmdack.command = 0x3108;
505  cmdack.input_word_count = 0;
506  if (DvrdrvExecCmdAck(&cmdack)) {
507  DPRINTF("avioctl2_change_sound -> Handshake error!\n");
508  return -EIO;
509  } else {
510  if (cmdack.ack_status_ack) {
511  DPRINTF("avioctl2_change_sound -> Status error!\n");
512  return -EADV;
513  } else {
514  *(u16 *)buf = cmdack.output_word[0];
515  }
516  }
517  return 0;
518 }
519 
520 int avioctl2_set_d_audio_sel(
521  iomanX_iop_file_t *a1,
522  int cmd,
523  void *arg,
524  unsigned int arglen,
525  void *buf,
526  unsigned int buflen)
527 {
528  drvdrv_exec_cmd_ack cmdack;
529 
530  (void)a1;
531  (void)cmd;
532  (void)arglen;
533  (void)buf;
534  (void)buflen;
535 
536  cmdack.command = 0x3109;
537  cmdack.input_word[0] = *(u16 *)arg;
538  cmdack.input_word[1] = *((u16 *)arg + 1);
539  cmdack.input_word[2] = *((u16 *)arg + 2);
540  cmdack.input_word[3] = *((u16 *)arg + 3);
541  cmdack.input_word_count = 4;
542  if (DvrdrvExecCmdAck(&cmdack)) {
543  DPRINTF("avioctl2_set_d_audio_sel -> Handshake error!\n");
544  return -EIO;
545  } else {
546  if (cmdack.ack_status_ack) {
547  DPRINTF("avioctl2_set_d_audio_sel -> Status error!\n");
548  return -EADV;
549  }
550  }
551  return 0;
552 }
553 
554 int avioctl2_set_d_video_sel(
555  iomanX_iop_file_t *a1,
556  int cmd,
557  void *arg,
558  unsigned int arglen,
559  void *buf,
560  unsigned int buflen)
561 {
562  drvdrv_exec_cmd_ack cmdack;
563 
564  (void)a1;
565  (void)cmd;
566  (void)arglen;
567  (void)buf;
568  (void)buflen;
569 
570  cmdack.command = 0x310A;
571  cmdack.input_word_count = 1;
572  cmdack.input_word[0] = *(u16 *)arg;
573  if (DvrdrvExecCmdAck(&cmdack)) {
574  DPRINTF("avioctl2_set_d_video_sel -> Handshake error!\n");
575  return -EIO;
576  } else {
577  if (cmdack.ack_status_ack) {
578  DPRINTF("avioctl2_set_d_video_sel -> Status error!\n");
579  return -EADV;
580  }
581  }
582  return 0;
583 }
584 
585 int avioctl2_get_av_src(
586  iomanX_iop_file_t *a1,
587  int cmd,
588  void *arg,
589  unsigned int arglen,
590  void *buf,
591  unsigned int buflen)
592 {
593  drvdrv_exec_cmd_ack cmdack;
594 
595  (void)a1;
596  (void)cmd;
597  (void)arg;
598  (void)arglen;
599  (void)buflen;
600 
601  cmdack.command = 0x310B;
602  cmdack.input_word_count = 0;
603  if (DvrdrvExecCmdAck(&cmdack)) {
604  DPRINTF("avioctl2_get_av_src -> Handshake error!\n");
605  return -EIO;
606  } else if (cmdack.ack_status_ack) {
607  DPRINTF("avioctl2_get_av_src -> Status error!\n");
608  return -EADV;
609  } else {
610  *(u16 *)buf = cmdack.output_word[0];
611  *((u16 *)buf + 1) = cmdack.output_word[1];
612  }
613  return 0;
614 }
615 
616 int avioctl2_get_preset_info(
617  iomanX_iop_file_t *a1,
618  int cmd,
619  void *arg,
620  unsigned int arglen,
621  void *buf,
622  unsigned int buflen)
623 {
624  drvdrv_exec_cmd_ack cmdack;
625 
626  (void)a1;
627  (void)cmd;
628  (void)arglen;
629  (void)buflen;
630 
631  cmdack.command = 0x310C;
632  cmdack.input_word_count = 1;
633  cmdack.input_word[0] = *(u16 *)arg;
634  if (DvrdrvExecCmdAck(&cmdack)) {
635  DPRINTF("avioctl2_get_preset_info -> Handshake error!\n");
636  return -EIO;
637  } else {
638  if (cmdack.ack_status_ack) {
639  DPRINTF("avioctl2_get_preset_info -> Status error!\n");
640  return -EADV;
641  } else {
642  *(u16 *)buf = cmdack.output_word[0];
643  }
644  }
645  return 0;
646 }
647 
648 int avioctl2_select_position(
649  iomanX_iop_file_t *a1,
650  int cmd,
651  void *arg,
652  unsigned int arglen,
653  void *buf,
654  unsigned int buflen)
655 {
656  drvdrv_exec_cmd_ack cmdack;
657 
658  (void)a1;
659  (void)cmd;
660  (void)arglen;
661  (void)buf;
662  (void)buflen;
663 
664  cmdack.command = 0x310E;
665  cmdack.input_word_count = 1;
666  cmdack.input_word[0] = *(u16 *)arg;
667  if (DvrdrvExecCmdAck(&cmdack)) {
668  DPRINTF("avioctl2_select_position -> Handshake error!\n");
669  return -EIO;
670  } else {
671  if (cmdack.ack_status_ack) {
672  DPRINTF("avioctl2_select_position -> Status error!\n");
673  return -EADV;
674  }
675  }
676  return 0;
677 }
678 
679 int avioctl2_position_up(
680  iomanX_iop_file_t *a1,
681  int cmd,
682  void *arg,
683  unsigned int arglen,
684  void *buf,
685  unsigned int buflen)
686 {
687  drvdrv_exec_cmd_ack cmdack;
688 
689  (void)a1;
690  (void)cmd;
691  (void)arg;
692  (void)arglen;
693  (void)buflen;
694 
695  cmdack.command = 0x310F;
696  cmdack.input_word_count = 0;
697  if (DvrdrvExecCmdAck(&cmdack)) {
698  DPRINTF("avioctl2_position_up -> Handshake error!\n");
699  return -EIO;
700  } else {
701  if (cmdack.ack_status_ack) {
702  DPRINTF("avioctl2_position_up -> Status error!\n");
703  return -EADV;
704  } else {
705  *(u16 *)buf = cmdack.output_word[0];
706  }
707  }
708  return 0;
709 }
710 
711 int avioctl2_position_down(
712  iomanX_iop_file_t *a1,
713  int cmd,
714  void *arg,
715  unsigned int arglen,
716  void *buf,
717  unsigned int buflen)
718 {
719  drvdrv_exec_cmd_ack cmdack;
720 
721  (void)a1;
722  (void)cmd;
723  (void)arg;
724  (void)arglen;
725  (void)buflen;
726 
727  cmdack.command = 0x3110;
728  cmdack.input_word_count = 0;
729  if (DvrdrvExecCmdAck(&cmdack)) {
730  DPRINTF("avioctl2_position_down -> Handshake error!\n");
731  return -EIO;
732  } else {
733  if (cmdack.ack_status_ack) {
734  DPRINTF("avioctl2_position_down -> Status error!\n");
735  return -EADV;
736  } else {
737  *(u16 *)buf = cmdack.output_word[0];
738  }
739  }
740  return 0;
741 }
742 
743 int avioctl2_get_position(
744  iomanX_iop_file_t *a1,
745  int cmd,
746  void *arg,
747  unsigned int arglen,
748  void *buf,
749  unsigned int buflen)
750 {
751  drvdrv_exec_cmd_ack cmdack;
752 
753  (void)a1;
754  (void)cmd;
755  (void)arg;
756  (void)arglen;
757  (void)buflen;
758 
759  cmdack.command = 0x3111;
760  cmdack.input_word_count = 0;
761  if (DvrdrvExecCmdAck(&cmdack)) {
762  DPRINTF("avioctl2_get_position -> Handshake error!\n");
763  return -EIO;
764  } else if (cmdack.ack_status_ack) {
765  DPRINTF("avioctl2_get_position -> Status error!\n");
766  return -EADV;
767  } else {
768  *(u16 *)buf = cmdack.output_word[0];
769  DPRINTF("Now position = %d\n", cmdack.output_word[0]);
770  return 0;
771  }
772 }
773 
774 int avioctl2_set_position_info(
775  iomanX_iop_file_t *a1,
776  int cmd,
777  void *arg,
778  unsigned int arglen,
779  void *buf,
780  unsigned int buflen)
781 {
782  drvdrv_exec_cmd_ack cmdack;
783 
784  (void)a1;
785  (void)cmd;
786  (void)arglen;
787  (void)buf;
788  (void)buflen;
789 
790  cmdack.command = 0x3112;
791  cmdack.input_word[0] = *(u16 *)arg;
792  cmdack.input_word[1] = *((u16 *)arg + 1);
793  cmdack.input_word[2] = *((u16 *)arg + 2);
794  cmdack.input_word[3] = *((u16 *)arg + 3);
795  cmdack.input_word[4] = *((u16 *)arg + 4);
796  cmdack.input_word_count = 5;
797  if (DvrdrvExecCmdAck(&cmdack)) {
798  DPRINTF("avioctl2_set_position_info -> Handshake error!\n");
799  return -EIO;
800  } else {
801  if (cmdack.ack_status_ack) {
802  DPRINTF("avioctl2_set_position_info -> Status error!\n");
803  return -EADV;
804  }
805  }
806  return 0;
807 }
808 
809 int avioctl2_get_position_info(
810  iomanX_iop_file_t *a1,
811  int cmd,
812  void *arg,
813  unsigned int arglen,
814  void *buf,
815  unsigned int buflen)
816 {
817  drvdrv_exec_cmd_ack cmdack;
818 
819  (void)a1;
820  (void)cmd;
821  (void)arglen;
822  (void)buflen;
823 
824  cmdack.command = 0x3113;
825  cmdack.input_word_count = 1;
826  cmdack.input_word[0] = *(u16 *)arg;
827  if (DvrdrvExecCmdAck(&cmdack)) {
828  DPRINTF("avioctl2_get_position_info -> Handshake error!\n");
829  return -EIO;
830  } else if (cmdack.ack_status_ack) {
831  DPRINTF("avioctl2_get_position_info -> Status error!\n");
832  return -EADV;
833  } else {
834  *(u16 *)buf = *(u16 *)arg;
835  *((u16 *)buf + 1) = cmdack.output_word[0];
836  *((u16 *)buf + 2) = cmdack.output_word[1];
837  *((u16 *)buf + 3) = cmdack.output_word[2];
838  *((u16 *)buf + 4) = cmdack.output_word[3];
839  }
840  return 0;
841 }
842 
843 int avioctl2_tun_scan_mode(
844  iomanX_iop_file_t *a1,
845  int cmd,
846  void *arg,
847  unsigned int arglen,
848  void *buf,
849  unsigned int buflen)
850 {
851  drvdrv_exec_cmd_ack cmdack;
852 
853  (void)a1;
854  (void)cmd;
855  (void)arglen;
856  (void)buf;
857  (void)buflen;
858 
859  cmdack.command = 0x3114;
860  cmdack.input_word_count = 1;
861  cmdack.input_word[0] = *(u16 *)arg;
862  if (DvrdrvExecCmdAck(&cmdack)) {
863  DPRINTF("avioctl2_tun_scan_mode -> Handshake error!\n");
864  return -EIO;
865  } else {
866  if (cmdack.ack_status_ack) {
867  DPRINTF("avioctl2_tun_scan_mode -> Status error!\n");
868  return -EADV;
869  }
870  }
871  return 0;
872 }
873 
874 int avioctl2_f_select_position(
875  iomanX_iop_file_t *a1,
876  int cmd,
877  void *arg,
878  unsigned int arglen,
879  void *buf,
880  unsigned int buflen)
881 {
882  drvdrv_exec_cmd_ack cmdack;
883 
884  (void)a1;
885  (void)cmd;
886  (void)arglen;
887  (void)buf;
888  (void)buflen;
889 
890  cmdack.command = 0x3115;
891  cmdack.input_word_count = 1;
892  cmdack.input_word[0] = *(u16 *)arg;
893  if (DvrdrvExecCmdAck(&cmdack)) {
894  DPRINTF("avioctl2_f_select_position -> Handshake error!\n");
895  return -EIO;
896  } else {
897  if (cmdack.ack_status_ack) {
898  DPRINTF("avioctl2_f_select_position -> Status error!\n");
899  return -EADV;
900  }
901  }
902  return 0;
903 }
904 
905 int avioctl2_select_rec_src(
906  iomanX_iop_file_t *a1,
907  int cmd,
908  void *arg,
909  unsigned int arglen,
910  void *buf,
911  unsigned int buflen)
912 {
913  drvdrv_exec_cmd_ack cmdack;
914 
915  (void)a1;
916  (void)cmd;
917  (void)arglen;
918  (void)buf;
919  (void)buflen;
920 
921  cmdack.command = 0x3116;
922  cmdack.input_word_count = 1;
923  cmdack.timeout = 10000000;
924  cmdack.input_word[0] = *(u16 *)arg;
925  if (DvrdrvExecCmdAckComp(&cmdack)) {
926  DPRINTF("avioctl2_select_rec_src -> Handshake error!\n");
927  return -EIO;
928  } else if (cmdack.ack_status_ack || cmdack.comp_status) {
929  DPRINTF("avioctl2_select_rec_src -> Status error!\n");
930  return -EADV;
931  }
932  return 0;
933 }
934 
935 int avioctl2_get_rec_src(
936  iomanX_iop_file_t *a1,
937  int cmd,
938  void *arg,
939  unsigned int arglen,
940  void *buf,
941  unsigned int buflen)
942 {
943  drvdrv_exec_cmd_ack cmdack;
944 
945  (void)a1;
946  (void)cmd;
947  (void)arg;
948  (void)arglen;
949  (void)buflen;
950 
951  cmdack.command = 0x3117;
952  cmdack.input_word_count = 0;
953  if (DvrdrvExecCmdAck(&cmdack)) {
954  DPRINTF("avioctl2_get_rec_src -> Handshake error!\n");
955  return -EIO;
956  } else {
957  if (cmdack.ack_status_ack) {
958  DPRINTF("avioctl2_get_rec_src -> Status error!\n");
959  return -EADV;
960  } else {
961  *(u16 *)buf = cmdack.output_word[0];
962  }
963  }
964  return 0;
965 }
966 
967 int avioctl2_cmd_ack(
968  const char *a1,
969  u32 a2,
970  iomanX_iop_file_t *a3,
971  u8 cmd,
972  void *arg,
973  unsigned int arglen,
974  void *buf)
975 {
976  drvdrv_exec_cmd_ack cmdack;
977 
978  (void)a2;
979  (void)a3;
980 
981  cmdack.command = cmd | 0x3100;
982  if (arglen >> 1) {
983  u16 *input_word_tmp;
984  unsigned int input_word_copied;
985  input_word_tmp = (u16 *)&cmdack.input_word[0];
986  input_word_copied = 0;
987  do {
988  *input_word_tmp = *(u16 *)arg;
989  arg = (char *)arg + 2;
990  input_word_copied += 1;
991  input_word_tmp += 1;
992  } while (input_word_copied < arglen >> 1);
993  }
994  cmdack.input_word_count = arglen >> 1;
995  if (DvrdrvExecCmdAck(&cmdack)) {
996  DPRINTF(" %s -> Handshake error!\n", a1);
997  return -EIO;
998  } else {
999  if (cmdack.ack_status_ack) {
1000  DPRINTF(" %s -> Status error!\n", a1);
1001  return -EADV;
1002  } else {
1003  u16 *input_word;
1004  char *buf_tmp;
1005  int out_count;
1006  input_word = cmdack.output_word;
1007  buf_tmp = (char *)buf;
1008  out_count = 1;
1009  do {
1010  *(u16 *)buf_tmp = *input_word;
1011  out_count += 1;
1012  input_word += 1;
1013  buf_tmp += 2;
1014  } while (out_count < 16);
1015  return 0;
1016  }
1017  }
1018 }
1019 
1020 int avioctl2_cmd_ack_comp(
1021  const char *a1,
1022  u32 a2,
1023  iomanX_iop_file_t *a3,
1024  u8 cmd,
1025  void *arg,
1026  unsigned int arglen,
1027  void *buf)
1028 {
1029  drvdrv_exec_cmd_ack cmdack;
1030 
1031  (void)a1;
1032  (void)a2;
1033  (void)a3;
1034 
1035  cmdack.command = cmd | 0x3100;
1036  if (arglen >> 1) {
1037  u16 *input_word_tmp;
1038  unsigned int input_word_copied;
1039  input_word_tmp = (u16 *)&cmdack.input_word[0];
1040  input_word_copied = 0;
1041  do {
1042  *input_word_tmp = *(u16 *)arg;
1043  input_word_tmp += 1;
1044  arg = (char *)arg + 2;
1045  input_word_copied += 1;
1046  } while (input_word_copied < arglen >> 1);
1047  }
1048  cmdack.input_word_count = arglen >> 1;
1049  cmdack.timeout = a2;
1050  if (DvrdrvExecCmdAckComp(&cmdack)) {
1051  DPRINTF(" %s -> Handshake error!\n", a1);
1052  return -EIO;
1053  } else if (cmdack.ack_status_ack || cmdack.comp_status) {
1054  DPRINTF(" %s -> Status error!\n", a1);
1055  return -EADV;
1056  } else {
1057  int out_count;
1058  u16 *input_word;
1059  u16 *buf_tmp;
1060  out_count = 1;
1061  input_word = cmdack.return_result_word;
1062  buf_tmp = (u16 *)buf;
1063  do {
1064  *buf_tmp = *input_word;
1065  out_count += 1;
1066  input_word += 1;
1067  buf_tmp += 1;
1068  } while (out_count < 16);
1069  return 0;
1070  }
1071 }
1072 
1073 int avioctl2_tun_scan_mode_euro(
1074  iomanX_iop_file_t *a1,
1075  int cmd,
1076  void *arg,
1077  unsigned int arglen,
1078  void *buf,
1079  unsigned int buflen)
1080 {
1081  (void)buflen;
1082 
1083  return avioctl2_cmd_ack("avioctl2_tun_scan_mode_euro", 0x8000, a1, cmd, arg, arglen, buf);
1084 }
1085 
1086 int avioctl2_tun_scan_ch_euro(
1087  iomanX_iop_file_t *a1,
1088  int cmd,
1089  void *arg,
1090  unsigned int arglen,
1091  void *buf,
1092  unsigned int buflen)
1093 {
1094  (void)buflen;
1095 
1096  return avioctl2_cmd_ack_comp("avioctl2_tun_scan_ch_euro", 0x8000, a1, cmd, arg, arglen, buf);
1097 }
1098 
1099 int avioctl2_get_curfreq_info(
1100  iomanX_iop_file_t *a1,
1101  int cmd,
1102  void *arg,
1103  unsigned int arglen,
1104  void *buf,
1105  unsigned int buflen)
1106 {
1107  (void)buflen;
1108 
1109  return avioctl2_cmd_ack("avioctl2_get_curfreq_info", 0x8000, a1, cmd, arg, arglen, buf);
1110 }
1111 
1112 int avioctl2_get_teletext_ver_no(
1113  iomanX_iop_file_t *a1,
1114  int cmd,
1115  void *arg,
1116  unsigned int arglen,
1117  void *buf,
1118  unsigned int buflen)
1119 {
1120  (void)buflen;
1121 
1122  return avioctl2_cmd_ack_comp("avioctl2_get_teletext_ver_no", 0x8000, a1, cmd, arg, arglen, buf);
1123 }
1124 
1125 int avioctl2_set_tv_guide_page(
1126  iomanX_iop_file_t *a1,
1127  int cmd,
1128  void *arg,
1129  unsigned int arglen,
1130  void *buf,
1131  unsigned int buflen)
1132 {
1133  (void)buflen;
1134 
1135  return avioctl2_cmd_ack("avioctl2_set_tv_guide_page", 0x8000, a1, cmd, arg, arglen, buf);
1136 }
1137 
1138 int avioctl2_get_tv_guide_page(
1139  iomanX_iop_file_t *a1,
1140  int cmd,
1141  void *arg,
1142  unsigned int arglen,
1143  void *buf,
1144  unsigned int buflen)
1145 {
1146  (void)buflen;
1147 
1148  return avioctl2_cmd_ack("avioctl2_get_tv_guide_page", 0x8000, a1, cmd, arg, arglen, buf);
1149 }
1150 
1151 int avioctl2_change_mode_tv_to_dvd(
1152  iomanX_iop_file_t *a1,
1153  int cmd,
1154  void *arg,
1155  unsigned int arglen,
1156  void *buf,
1157  unsigned int buflen)
1158 {
1159  (void)buflen;
1160 
1161  return avioctl2_cmd_ack("avioctl2_change_mode_tv_to_dvd", 0x8000, a1, cmd, arg, arglen, buf);
1162 }
1163 
1164 int avioctl2_get_vps_data(
1165  iomanX_iop_file_t *a1,
1166  int cmd,
1167  void *arg,
1168  unsigned int arglen,
1169  void *buf,
1170  unsigned int buflen)
1171 {
1172  (void)buflen;
1173 
1174  return avioctl2_cmd_ack_comp("avioctl2_get_vps_data", 0x6B6C0, a1, cmd, arg, arglen, buf);
1175 }
1176 
1177 int avioctl2_get_pdc_data(
1178  iomanX_iop_file_t *a1,
1179  int cmd,
1180  void *arg,
1181  unsigned int arglen,
1182  void *buf,
1183  unsigned int buflen)
1184 {
1185  (void)buflen;
1186 
1187  return avioctl2_cmd_ack_comp("avioctl2_get_pdc_data", 0x2DC6C0, a1, cmd, arg, arglen, buf);
1188 }
1189 
1190 int avioctl2_get_format1_data(
1191  iomanX_iop_file_t *a1,
1192  int cmd,
1193  void *arg,
1194  unsigned int arglen,
1195  void *buf,
1196  unsigned int buflen)
1197 {
1198  (void)buflen;
1199 
1200  return avioctl2_cmd_ack_comp("avioctl2_get_format1_data", 0x2DC6C0, a1, cmd, arg, arglen, buf);
1201 }
1202 
1203 int avioctl2_get_header_time_data(
1204  iomanX_iop_file_t *a1,
1205  int cmd,
1206  void *arg,
1207  unsigned int arglen,
1208  void *buf,
1209  unsigned int buflen)
1210 {
1211  (void)buflen;
1212 
1213  return avioctl2_cmd_ack_comp("avioctl2_get_header_time_data", 0x2DC6C0, a1, cmd, arg, arglen, buf);
1214 }
1215 
1216 int avioctl2_set_acs_position_euro(
1217  iomanX_iop_file_t *a1,
1218  int cmd,
1219  void *arg,
1220  unsigned int arglen,
1221  void *buf,
1222  unsigned int buflen)
1223 {
1224  (void)buflen;
1225 
1226  return avioctl2_cmd_ack("avioctl2_set_acs_position_euro", 0x8000, a1, cmd, arg, arglen, buf);
1227 }
iomanX.h
_ModuleInfo::newflags
u16 newflags
Definition: loadcore.h:36
speedregs.h
IOP_DT_FSEXT
#define IOP_DT_FSEXT
Definition: iomanX.h:66
EUNSUP
#define EUNSUP
Definition: errno.h:117
thbase.h
iop_sema_t
Definition: thsemap.h:38
_iomanX_iop_file
Definition: iomanX.h:70
EADV
#define EADV
Definition: errno.h:151
EIO
#define EIO
Definition: errno.h:29
loadcore.h
pvrdrv.h
_iomanX_iop_device_ops
Definition: iomanX.h:95
thsemap.h
_iomanX_iop_device
Definition: iomanX.h:81
stdio.h
EINVAL
#define EINVAL
Definition: errno.h:63
DevctlCmdTbl_t
Definition: xesdrv.c:198
_ModuleInfo
Definition: loadcore.h:31
errno.h