psxpblib.h 8.6 KB

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