cd64lib.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. #ifndef __CD64LIB_H__
  2. #define __CD64LIB_H__
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. #define CD64_BUFFER_SIZE 32768
  7. /* This is the only public header file for cd64lib. */
  8. #if defined __STDC_VERSION && __STDC_VERSION >= 19990L
  9. #include <stdint.h>
  10. #else
  11. #if !(defined __MSDOS__ || defined _MSC_VER)
  12. #include <inttypes.h>
  13. #else
  14. #ifndef OWN_INTTYPES
  15. #define OWN_INTTYPES /* signal that these are defined */
  16. typedef unsigned char uint8_t;
  17. typedef unsigned short int uint16_t;
  18. typedef unsigned int uint32_t;
  19. #ifndef _MSC_VER /* _WIN32 */
  20. typedef unsigned long long int uint64_t;
  21. #else
  22. typedef unsigned __int64 uint64_t;
  23. #endif
  24. typedef signed char int8_t;
  25. typedef signed short int int16_t;
  26. typedef signed int int32_t;
  27. #ifndef _MSC_VER /* _WIN32 */
  28. typedef signed long long int int64_t;
  29. #else
  30. typedef signed __int64 int64_t;
  31. #endif
  32. #endif /* OWN_INTTYPES */
  33. #endif /* __MSDOS__ || _MSC_VER */
  34. #endif /* STDC_VERSION */
  35. #include <stdio.h> /* FILE, FILENAME_MAX */
  36. #include <ultra64/rom.h>
  37. typedef enum {
  38. CD64BIOS = 0,
  39. GHEMOR = 1,
  40. ULTRALINK = 2
  41. } protocol_t;
  42. typedef enum {
  43. LIBIEEE1284 = 1,
  44. PPDEV = 2,
  45. PORTDEV = 3,
  46. RAWIO = 4
  47. } method_t;
  48. /* When using this structure, be sure to calloc it or otherwise set it to
  49. * zero before setting values or calling library functions. */
  50. struct cd64_t {
  51. int using_ppa;
  52. protocol_t protocol;
  53. struct parport *ppdev; /* libieee1284 */
  54. int ppdevfd; /* ppdev */
  55. int portdevfd; /* /dev/port */
  56. /* If using inb/outb or /dev/port, this is the I/O address
  57. * Otherwise it is the parport* number */
  58. int port;
  59. /* Directory with io.dll or dlportio.dll. Used by the Windows ports. */
  60. char io_driver_dir[FILENAME_MAX];
  61. /* A flag that can be set/read to determine whether
  62. * the current operation should be canceled. */
  63. int abort;
  64. int (*devopen)(struct cd64_t *cd64);
  65. int (*xfer)(struct cd64_t *cd64, uint8_t *write, uint8_t *read, int delayms);
  66. int (*devclose)(struct cd64_t *cd64);
  67. /* Progress callback is responsible for printing header info if the
  68. * user wants it */
  69. void (*progress_callback)(uint32_t curbyte, uint32_t totalbytes);
  70. int (*notice_callback)(const char *format, ...);
  71. int (*notice_callback2)(const char *format, ...);
  72. /* Callbacks for read, write and seek operations. By default they point to
  73. * callbacks in the library which just call fread(), fwrite(), ftell() and
  74. * fseek(). You can change them so that the library doesn't read from or
  75. * write to a FILE * (io_id). For example, a client can install its own
  76. * callback to make it possible to read from .zip files. */
  77. int (*read_callback)(void *io_id, void *buffer, uint32_t size);
  78. int (*write_callback)(void *io_id, void *buffer, uint32_t size);
  79. int32_t (*tell_callback)(void *io_id);
  80. int (*seek_callback)(void *io_id, int32_t offset, int whence);
  81. };
  82. /* This function must be called and return successful before any of the
  83. * other functions may be used. */
  84. int cd64_create(struct cd64_t *cd64, method_t method,
  85. uint16_t port, protocol_t protocol, int ppa);
  86. /* The following five functions are wrappers above the I/O abstraction.
  87. * Use them to write code that works regardless of the underlying
  88. * transport. */
  89. int cd64_send_byte(struct cd64_t *cd64, uint8_t what);
  90. int cd64_send_dword(struct cd64_t *cd64, uint32_t what);
  91. int cd64_grab_byte(struct cd64_t *cd64, uint8_t *val);
  92. int cd64_grab_dword(struct cd64_t *cd64, uint32_t *val);
  93. int cd64_trade_bytes(struct cd64_t *cd64, uint8_t give, uint8_t *recv);
  94. /* Generic protocol handlers */
  95. int cd64_bios_grab(struct cd64_t *cd64, void *io_id, uint32_t addr, uint32_t length,
  96. int *elapsed);
  97. int cd64_bios_send(struct cd64_t *cd64, void *io_id, uint32_t addr,
  98. uint32_t length, int *elapsed, int cmd);
  99. int cd64_ghemor_grab(struct cd64_t *cd64, void *io_id, uint8_t slow, int *elapsed);
  100. int cd64_ghemor_send(struct cd64_t *cd64, void *io_id, uint32_t length,
  101. int *elapsed);
  102. /* Functions for sending files to CD64 */
  103. int cd64_upload_dram(struct cd64_t *cd64, FILE *infile, uint32_t length,
  104. int *elapsed, int exec);
  105. int cd64_upload_ram(struct cd64_t *cd64, FILE *infile, uint32_t length,
  106. int *elapsed, uint32_t address);
  107. int cd64_upload_bootemu(struct cd64_t *cd64, FILE *infile, uint32_t length, int *elapsed);
  108. int cd64_upload_sram(struct cd64_t *cd64, FILE *infile);
  109. int cd64_upload_flashram(struct cd64_t *cd64, FILE *infile);
  110. int cd64_upload_eeprom(struct cd64_t *cd64, FILE *infile);
  111. int cd64_upload_mempak(struct cd64_t *cd64, FILE *infile, int8_t which);
  112. /* Functions for receiving files from CD64 */
  113. int cd64_download_cart(struct cd64_t *cd64, FILE *outfile, uint32_t length,
  114. int *elapsed);
  115. int cd64_download_dram(struct cd64_t *cd64, FILE *outfile, uint32_t start,
  116. uint32_t end, int *elapsed);
  117. int cd64_download_ram(struct cd64_t *cd64, FILE *outfile, uint32_t length,
  118. int *elapsed, uint32_t address);
  119. int cd64_download_sram(struct cd64_t *cd64, FILE *outfile);
  120. int cd64_download_flashram(struct cd64_t *cd64, FILE *outfile);
  121. int cd64_download_eeprom(struct cd64_t *cd64, FILE *outfile);
  122. int cd64_download_mempak(struct cd64_t *cd64, FILE *outfile, int8_t which);
  123. /* Remote control functions */
  124. int cd64_run_dram(struct cd64_t *cd64);
  125. int cd64_run_cart(struct cd64_t *cd64);
  126. /* This function simply gets the header from the cart and can be displayed
  127. * using ultra64_header_info() */
  128. int cd64_download_header(struct cd64_t *cd64, n64header_t *head, uint32_t location);
  129. #ifdef __cplusplus
  130. }
  131. #endif
  132. #define BIOS_TEMP_RAM 0xa0300000
  133. #define BIOS_DUMP_N64 'D'
  134. #define BIOS_TRANSFER_N64 'B'
  135. #define BIOS_DUMP_PI 'G'
  136. #define BIOS_TRANSFER_PI 'T'
  137. #define BIOS_EXECUTE_PI 'X'
  138. #define GHEMOR_RESTORE_MEMPAK 1
  139. #define GHEMOR_RESTORE_EEPROM 2
  140. #define GHEMOR_RESTORE_SRAM 3
  141. #define GHEMOR_RESTORE_FLASHRAM 4
  142. #define GHEMOR_EXECUTE_BOOTEMU 5
  143. #define GHEMOR_TRANSFER_PROGRAM 6
  144. #define GHEMOR_DUMP_CART 7
  145. #define GHEMOR_DUMP_MEMPAK 8
  146. #define GHEMOR_DUMP_EEPROM 9
  147. #define GHEMOR_DUMP_SRAM 10
  148. #define GHEMOR_DUMP_FLASH 11
  149. #define GHEMOR_RESET_DRAM 12
  150. #define GHEMOR_RESET_CART 13
  151. #endif