dex.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. dex.c - DexDrive support for uCON64
  3. Copyright (c) 2002 NoisyB
  4. Copyright (c) 2004 dbjh
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. */
  17. #ifdef HAVE_CONFIG_H
  18. #include "config.h"
  19. #endif
  20. #include <stdlib.h>
  21. #include "misc/archive.h"
  22. #include "misc/file.h"
  23. #include "misc/parallel.h"
  24. #include "ucon64.h"
  25. #include "ucon64_misc.h"
  26. #include "backup/dex.h"
  27. #include "backup/psxpblib.h"
  28. #ifdef USE_PARALLEL
  29. static st_ucon64_obj_t dex_obj[] =
  30. {
  31. {0, WF_DEFAULT | WF_STOP | WF_NO_ROM}
  32. };
  33. #endif
  34. const st_getopt2_t dex_usage[] =
  35. {
  36. {
  37. NULL, 0, 0, 0,
  38. NULL, "DexDrive"/*"19XX InterAct http://www.dexdrive.de"*/,
  39. NULL
  40. },
  41. #ifdef USE_PARALLEL
  42. {
  43. "xdex", 1, 0, UCON64_XDEX,
  44. "N", "send/receive Block N to/from DexDrive; " OPTION_LONG_S "port=PORT\n"
  45. "receives automatically when SRAM does not exist",
  46. &dex_obj[0]
  47. },
  48. #endif
  49. {NULL, 0, 0, 0, NULL, NULL, NULL}
  50. };
  51. #ifdef USE_PARALLEL
  52. #define CONPORT 1
  53. #define TAP 1
  54. #define DELAY 4
  55. #define FRAME_SIZE 128
  56. #define BLOCK_SIZE (64*FRAME_SIZE)
  57. static unsigned short print_data;
  58. static unsigned char *
  59. read_block (int block_num)
  60. {
  61. return psx_memcard_read_block (print_data, CONPORT, TAP, DELAY, block_num);
  62. }
  63. static int
  64. write_block (int block_num, unsigned char *data)
  65. {
  66. return psx_memcard_write_block (print_data, CONPORT, TAP, DELAY, block_num,
  67. data);
  68. }
  69. #if 0
  70. char *
  71. read_frame (int frame, char *data)
  72. {
  73. return psx_memcard_read_frame (print_data, CONPORT, TAP, DELAY, frame);
  74. }
  75. int
  76. write_frame (int frame, char *data)
  77. {
  78. return psx_memcard_write_frame (print_data, CONPORT, TAP, DELAY, frame,
  79. data);
  80. }
  81. #endif
  82. int
  83. dex_read_block (const char *filename, int block_num, unsigned short parport)
  84. {
  85. unsigned char *data;
  86. print_data = parport;
  87. parport_print_info ();
  88. if ((data = read_block (block_num)) == NULL)
  89. {
  90. fprintf (stderr, ucon64_msg[PARPORT_ERROR]);
  91. exit (1);
  92. }
  93. ucon64_fwrite (data, 0, BLOCK_SIZE, filename, "wb");
  94. return 0;
  95. }
  96. int
  97. dex_write_block (const char *filename, int block_num, unsigned short parport)
  98. {
  99. unsigned char data[BLOCK_SIZE];
  100. print_data = parport;
  101. parport_print_info ();
  102. ucon64_fread (data, 0, BLOCK_SIZE, filename);
  103. if (write_block (block_num, data) == -1)
  104. {
  105. fprintf (stderr, ucon64_msg[PARPORT_ERROR]);
  106. exit (1);
  107. }
  108. return 0;
  109. }
  110. #endif // USE_PARALLEL