dex.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. dex.c - DexDrive support for uCON64
  3. Copyright (c) 2002 NoisyB <noisyb@gmx.net>
  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 <stdio.h>
  21. #include <stdlib.h>
  22. #include "misc/misc.h"
  23. #include "misc/file.h"
  24. #ifdef USE_ZLIB
  25. #include "misc/archive.h"
  26. #endif
  27. #include "misc/getopt2.h" // st_getopt2_t
  28. #include "ucon64.h"
  29. #include "ucon64_misc.h"
  30. #include "dex.h"
  31. #include "psxpblib.h"
  32. #include "misc/parallel.h"
  33. const st_getopt2_t dex_usage[] =
  34. {
  35. {
  36. NULL, 0, 0, 0,
  37. NULL, "DexDrive"/*"19XX InterAct http://www.dexdrive.de"*/,
  38. NULL
  39. },
  40. {
  41. "xdex", 1, 0, UCON64_XDEX,
  42. "N", "send/receive Block N to/from DexDrive; " OPTION_LONG_S "port=PORT\n"
  43. "receives automatically when SRAM does not exist",
  44. &ucon64_wf[WF_OBJ_ALL_DEFAULT_STOP_NO_ROM]
  45. },
  46. {NULL, 0, 0, 0, NULL, NULL, NULL}
  47. };
  48. #ifdef USE_PARALLEL
  49. #define CONPORT 1
  50. #define TAP 1
  51. #define DELAY 4
  52. #define FRAME_SIZE 128
  53. #define BLOCK_SIZE (64*FRAME_SIZE)
  54. static int print_data;
  55. static unsigned char *
  56. read_block (int block_num)
  57. {
  58. return psx_memcard_read_block (print_data, CONPORT, TAP, DELAY, block_num);
  59. }
  60. static int
  61. write_block (int block_num, unsigned char *data)
  62. {
  63. return psx_memcard_write_block (print_data, CONPORT, TAP, DELAY, block_num,
  64. data);
  65. }
  66. #if 0
  67. char *
  68. read_frame (int frame, char *data)
  69. {
  70. return psx_memcard_read_frame (print_data, CONPORT, TAP, DELAY, frame);
  71. }
  72. int
  73. write_frame (int frame, char *data)
  74. {
  75. return psx_memcard_write_frame (print_data, CONPORT, TAP, DELAY, frame,
  76. data);
  77. }
  78. #endif
  79. int
  80. dex_read_block (const char *filename, int block_num, unsigned int parport)
  81. {
  82. unsigned char *data;
  83. print_data = parport;
  84. parport_print_info ();
  85. if ((data = read_block (block_num)) == NULL)
  86. {
  87. fprintf (stderr, ucon64_msg[PARPORT_ERROR]);
  88. exit (1);
  89. }
  90. ucon64_fwrite (data, 0, BLOCK_SIZE, filename, "wb");
  91. return 0;
  92. }
  93. int
  94. dex_write_block (const char *filename, int block_num, unsigned int parport)
  95. {
  96. unsigned char data[BLOCK_SIZE];
  97. print_data = parport;
  98. parport_print_info ();
  99. ucon64_fread (data, 0, BLOCK_SIZE, filename);
  100. if (write_block (block_num, data) == -1)
  101. {
  102. fprintf (stderr, ucon64_msg[PARPORT_ERROR]);
  103. exit (1);
  104. }
  105. return 0;
  106. }
  107. #endif // USE_PARALLEL