psxpblib.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. /*
  2. *
  3. * PSX Peripheral Bus Library v1.4 17/01/00 Richard Davies
  4. * <http://www.debaser.force9.co.uk/>
  5. * <mailto:richard@debaser.force9.co.uk>
  6. *
  7. * Revision History:
  8. * v1.4 - 17/01/00 Win32 / Win32 DLL support and bug fixes
  9. * v1.3 - 21/12/99 Linux support and bug fixes
  10. * v1.1 - 26/09/99 Minor Controller detection improvements.
  11. * v1.0 - 17/07/99 Initial release (based on PSXTest v1.1 by me).
  12. *
  13. * see psxpblib.txt for details.
  14. *
  15. */
  16. #ifdef HAVE_CONFIG_H
  17. #include "config.h"
  18. #endif
  19. #ifdef USE_PARALLEL
  20. /* outportb() and inportb() are only present in uCON64 if USE_PARALLEL is defined */
  21. #define psx_outportb(P, B) outportb ((unsigned short) (P), (unsigned char) (B))
  22. #define psx_inportb(P) inportb ((unsigned short) (P))
  23. #define LPT1_BASE 0x378
  24. #define LPT2_BASE 0x278
  25. #define LPT3_BASE 0x3bc
  26. #define LPT_D0 0x01 /* pin 2 */
  27. #define LPT_D1 0x02 /* pin 3 */
  28. #define LPT_D2 0x04 /* pin 4 */
  29. #define LPT_D3 0x08 /* pin 5 */
  30. #define LPT_D4 0x10 /* pin 6 */
  31. #define LPT_D5 0x20 /* pin 7 */
  32. #define LPT_D6 0x40 /* pin 8 */
  33. #define LPT_D7 0x80 /* pin 9 */
  34. #define LPT_AUT 0x08 /* pin 14 */
  35. #define LPT_SEL 0x10 /* pin 13 */
  36. #define LPT_PAP 0x20 /* pin 12 */
  37. #define LPT_ACK 0x40 /* pin 10 */
  38. #define LPT_ERR 0x02 /* pin 15 */
  39. #define LPT_INI 0x04 /* pin 16 */
  40. #define LPT_STR 0x08 /* pin 1 */
  41. #define PSX_MAX_CONPORTS 8
  42. #define PSX_MAX_TAPS 4
  43. #define PSX_MAX_DELAY 10
  44. #define PSX_MAX_DATA 30 /* maximum possible length of controller packet in bytes */
  45. /* JAP code EUR code Name */
  46. #define PSX_MOUSE 1 /* SCPH-1030 SCPH-???? Mouse */
  47. #define PSX_NEGCON 2 /* SLPH-0001 SLEH-0003 Namco neGcon
  48. SLPH-0007 Nasca Pachinco Handle (untested); Twist = Twist, TW = B
  49. SLPH-0015 ? Volume Controller (untested); Rotation = Twist, A = Start, B = A
  50. Puchi Carat paddle controller (not working!); Rotation = Twist, A = Start, B = A
  51. SLPH-???? SLEH-0005 MadKatz Steering Wheel (twitchy) */
  52. #define PSX_KONAMIGUN 3 /* SLPH-???? SLPH-???? Konami Lightgun (untested) */
  53. #define PSX_DIGITAL 4 /* SCPH-1010 SCPH 1080 E Controller
  54. SCPH-1110 SCPH-???? Analog Joystick - Digital Mode
  55. SCPH-???? SCPH-1180 E Analog Controller - Digital Mode
  56. SCPH-1150 SCPH-1200 E Dual Shock Analog Controller - Digital Mode
  57. SLPH-???? SLEH-0011 Ascii Resident Evil Pad
  58. SLPH-???? SLEH-0004 Namco Arcade Stick (untested)
  59. Twin Stick
  60. Blaze Pro-Shock Arcade Stick */
  61. #define PSX_ANALOG_GREEN 5 /* SCPH-1110 SCPH-???? Analog Joystick - Analog Mode (untested)
  62. SCPH-???? SCPH-1180 E Analog Controller - Analog Green Mode */
  63. #define PSX_GUNCON 6 /* SLPH-???? SLEH-0007 Namco G-con45 */
  64. #define PSX_ANALOG_RED 7 /* SCPH-1150 SCPH-1200 E Dual Shock Analog Controller - Analog Red Mode */
  65. /* SCPH-???? SCPH-1180 E Analog Controller - Analog Red Mode */
  66. #define PSX_JOGCON 14 /* SLPH-???? SLEH-0020 Namco Jogcon */
  67. /*#define PSX_MULTITAP 17 SCPH-1070 SCPH-1070 E Multi tap */
  68. #define PSX_MCB_STATE_OK 0x05
  69. #define PSX_MCB_STATE_DELETED 0x0a
  70. #define PSX_MCB_STATE_RESERVED 0x0f
  71. #define PSX_MCB_LTYPE_NONE 0x00
  72. #define PSX_MCB_LTYPE_FIRST 0x01
  73. #define PSX_MCB_LTYPE_MIDDLE 0x02
  74. #define PSX_MCB_LTYPE_LAST 0x03
  75. #define PSX_MCB_LTYPE_RESERVED 0x0f
  76. #define PSX_MCB_ICON_VALID 0x01
  77. typedef struct
  78. {
  79. unsigned char type;
  80. unsigned char length;
  81. unsigned char data[PSX_MAX_DATA];
  82. } PSX_CON_BUF;
  83. typedef struct
  84. {
  85. unsigned char read;
  86. char filename[9];
  87. char code[11];
  88. char territory; /* E, A or I */
  89. #ifdef _MSC_VER
  90. #pragma warning(push)
  91. #pragma warning(disable: 4820) /* 'bytes' bytes padding added after construct 'member_name' */
  92. #endif
  93. int bytes;
  94. #ifdef _MSC_VER
  95. #pragma warning(pop)
  96. #endif
  97. unsigned char state; /* PSX_MCB_STAT_* or unknown */
  98. unsigned char linktype; /* PSX_MCB_LTYPE_* or unknowm */
  99. unsigned char next; /* 0 to 14 */
  100. #ifdef _MSC_VER
  101. #pragma warning(push)
  102. #pragma warning(disable: 4820) /* 'bytes' bytes padding added after construct 'member_name' */
  103. #endif
  104. } PSX_MCB_INFO_DIR;
  105. #ifdef _MSC_VER
  106. #pragma warning(pop)
  107. #endif
  108. typedef struct
  109. {
  110. unsigned char read;
  111. char name[92];
  112. unsigned char blocks;
  113. unsigned char icon_valid;
  114. unsigned char icon_frames;
  115. } PSX_MCB_INFO_DAT;
  116. typedef struct
  117. {
  118. unsigned char scanned;
  119. unsigned char read;
  120. char name[92];
  121. char filename[9];
  122. char code[11];
  123. char territory;
  124. unsigned char state;
  125. unsigned char blocks;
  126. #ifdef _MSC_VER
  127. #pragma warning(push)
  128. #pragma warning(disable: 4820) /* 'bytes' bytes padding added after construct 'member_name' */
  129. #endif
  130. int bytes;
  131. #ifdef _MSC_VER
  132. #pragma warning(pop)
  133. #endif
  134. unsigned char linktype;
  135. unsigned char next;
  136. unsigned char icon_valid;
  137. unsigned char icon_frames;
  138. } PSX_MCB_INFO;
  139. /* sets clock for conport connected to parallel port base */
  140. void psx_clk (int base, int conport, int on);
  141. /* sets att for conport connected to parallel port base */
  142. void psx_att (int base, int conport, int on);
  143. /* sets command for conport connected to parallel port base */
  144. void psx_cmd (int base, int conport, int on);
  145. /* tests data for conport connected to parallel port base, returns 1 if high */
  146. int psx_dat (int base, int conport);
  147. /* tests ack for conport connected to parallel port base, returns 1 if high */
  148. int psx_ack (int base, int conport);
  149. /* wait for delay * (outportb() execution time) */
  150. void psx_delay (int base, int delay);
  151. /* send byte as a command to conport connected to parallel port base
  152. * assumes clock high and the attention of conport */
  153. unsigned char psx_sendbyte (int base, int conport, int delay,
  154. unsigned char byte, int wait);
  155. /* get io permissions under linux*/
  156. int psx_obtain_io_permission (int base);
  157. /* sets clock high and gets the attention of conport, use before psx_sendbyte() */
  158. void psx_sendinit (int base, int conport, int delay);
  159. /* use after psx_sendbyte() */
  160. void psx_sendclose (int base, int conport, int delay);
  161. /* send string as a series of commands to conport connected to parallel port base */
  162. void psx_sendstring (int base, int conport, int delay, int string[]);
  163. /* tests for the presence of a controller on conport:tap connected to base
  164. * returns the type if present, otherwise -1 */
  165. int psx_controller_detect (int base, int conport, int tap, int delay);
  166. /* reads a controller on conport:tap connected to base returns the data
  167. * if present, otherwise -1 */
  168. PSX_CON_BUF *psx_controller_read (int base, int conport, int tap, int delay);
  169. /* sends force feedback/shock init command sequence to conport:tap on port base
  170. * (also initialises crash protection for some controllers) */
  171. void psx_controller_vinit (int base, int conport, int tap, int delay);
  172. /* sends the dual shock command sequence to conport:tap on port base */
  173. void psx_controller_vshock (int base, int conport, int tap, int delay,
  174. int shock, int rumble);
  175. /* Reads a single frame (128 bytes) from Memory Card on conport base:tap */
  176. unsigned char *psx_memcard_read_frame (int base, int conport, int tap, int delay,
  177. int frame);
  178. /* Writes a single frame (128 bytes) to Memory Card on conport base:tap */
  179. int psx_memcard_write_frame (int base, int conport, int tap, int delay,
  180. int frame, unsigned char *data_f);
  181. /* Reads a single block (64 frames) from Memory Card on conport base:tap */
  182. unsigned char *psx_memcard_read_block (int base, int conport, int tap, int delay,
  183. int block);
  184. /* Writes a single block (64 frames) to Memory Card on conport base:tap */
  185. int psx_memcard_write_block (int base, int conport, int tap, int delay,
  186. int block, unsigned char *data_b);
  187. /* Reads the info associated with block from the directory */
  188. PSX_MCB_INFO_DIR *psx_mcb_read_dir (int base, int conport, int tap, int delay,
  189. int block);
  190. /* Prints the info associated with block from it's data */
  191. PSX_MCB_INFO_DAT *psx_mcb_read_dat (int base, int conport, int tap, int delay,
  192. int block);
  193. /* Merges the info associated with block from the directory and it's data */
  194. PSX_MCB_INFO *psx_mcb_info_merge (PSX_MCB_INFO_DIR mcb_info_dir,
  195. PSX_MCB_INFO_DAT mcb_info_dat,
  196. PSX_MCB_INFO * mcb_info);
  197. /* Reads the info associated with block from the directory and it's data */
  198. PSX_MCB_INFO *psx_mcb_read_info (int base, int conport, int tap, int delay,
  199. int block);
  200. #endif /* USE_PARALLEL */