pico.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. /*
  2. * PicoDrive
  3. * (c) Copyright Dave, 2004
  4. * (C) notaz, 2006-2010
  5. *
  6. * This work is licensed under the terms of MAME license.
  7. * See COPYING file in the top-level directory.
  8. */
  9. #ifndef PICO_H
  10. #define PICO_H
  11. #include <stdlib.h> // size_t
  12. #ifdef __cplusplus
  13. extern "C" {
  14. #endif
  15. // message log
  16. extern void lprintf(const char *fmt, ...);
  17. // external funcs for Sega/Mega CD
  18. extern int mp3_get_bitrate(void *f, int size);
  19. extern void mp3_start_play(void *f, int pos);
  20. extern void mp3_update(int *buffer, int length, int stereo);
  21. // this function should write-back d-cache and invalidate i-cache
  22. // on a mem region [start_addr, end_addr)
  23. // used by dynarecs
  24. extern void cache_flush_d_inval_i(void *start_addr, void *end_addr);
  25. // attempt to alloc mem at specified address.
  26. // alloc anywhere else if that fails (callers should handle that)
  27. extern void *plat_mmap(unsigned long addr, size_t size, int need_exec, int is_fixed);
  28. extern void *plat_mremap(void *ptr, size_t oldsize, size_t newsize);
  29. extern void plat_munmap(void *ptr, size_t size);
  30. // memory for the dynarec; plat_mem_get_for_drc() can just return NULL
  31. extern void *plat_mem_get_for_drc(size_t size);
  32. extern int plat_mem_set_exec(void *ptr, size_t size);
  33. // this one should handle display mode changes
  34. extern void emu_video_mode_change(int start_line, int line_count, int is_32cols);
  35. // this must switch to 16bpp mode
  36. extern void emu_32x_startup(void);
  37. // optional 32X BIOS, should be left NULL if not used
  38. // must be 256, 2048, 1024 bytes
  39. extern void *p32x_bios_g, *p32x_bios_m, *p32x_bios_s;
  40. // Pico.c
  41. #define POPT_EN_FM (1<< 0) // 00 000x
  42. #define POPT_EN_PSG (1<< 1)
  43. #define POPT_EN_Z80 (1<< 2)
  44. #define POPT_EN_STEREO (1<< 3)
  45. #define POPT_ALT_RENDERER (1<< 4) // 00 00x0
  46. // unused (1<< 5)
  47. // unused (1<< 6)
  48. #define POPT_ACC_SPRITES (1<< 7)
  49. #define POPT_DIS_32C_BORDER (1<< 8) // 00 0x00
  50. #define POPT_EXT_FM (1<< 9)
  51. #define POPT_EN_MCD_PCM (1<<10)
  52. #define POPT_EN_MCD_CDDA (1<<11)
  53. #define POPT_EN_MCD_GFX (1<<12) // 00 x000
  54. // unused (1<<13)
  55. #define POPT_EN_SOFTSCALE (1<<14)
  56. #define POPT_EN_MCD_RAMCART (1<<15)
  57. #define POPT_DIS_VDP_FIFO (1<<16) // 0x 0000
  58. #define POPT_EN_DRC (1<<17)
  59. #define POPT_DIS_SPRITE_LIM (1<<18)
  60. #define POPT_DIS_IDLE_DET (1<<19)
  61. #define POPT_EN_32X (1<<20)
  62. #define POPT_EN_PWM (1<<21)
  63. #define POPT_PWM_IRQ_OPT (1<<22)
  64. #define PAHW_MCD (1<<0)
  65. #define PAHW_32X (1<<1)
  66. #define PAHW_SVP (1<<2)
  67. #define PAHW_PICO (1<<3)
  68. #define PAHW_SMS (1<<4)
  69. #define PQUIRK_FORCE_6BTN (1<<0)
  70. // the emulator is configured and some status is reported
  71. // through this global state (not saved in savestates)
  72. typedef struct
  73. {
  74. unsigned int opt; // POPT_* bitfield
  75. unsigned short pad[2]; // Joypads, format is MXYZ SACB RLDU
  76. unsigned short padInt[2]; // internal copy
  77. unsigned short AHW; // active addon hardware: PAHW_* bitfield
  78. unsigned short skipFrame; // skip rendering frame, but still do sound (if enabled) and emulation stuff
  79. unsigned short regionOverride; // override the region detection 0: auto, 1: Japan NTSC, 2: Japan PAL, 4: US, 8: Europe
  80. unsigned short autoRgnOrder; // packed priority list of regions, for example 0x148 means this detection order: EUR, USA, JAP
  81. unsigned short quirks; // game-specific quirks: PQUIRK_*
  82. unsigned short overclockM68k; // overclock the emulated 68k, in %
  83. int sndRate; // rate in Hz
  84. short *sndOut; // PCM output buffer
  85. void (*writeSound)(int len); // write .sndOut callback, called once per frame
  86. void (*osdMessage)(const char *msg); // output OSD message from emu, optional
  87. void (*mcdTrayOpen)(void);
  88. void (*mcdTrayClose)(void);
  89. } PicoInterface;
  90. extern PicoInterface PicoIn;
  91. void PicoInit(void);
  92. void PicoExit(void);
  93. void PicoPower(void);
  94. int PicoReset(void);
  95. void PicoLoopPrepare(void);
  96. void PicoFrame(void);
  97. void PicoFrameDrawOnly(void);
  98. typedef enum { PI_ROM, PI_ISPAL, PI_IS40_CELL, PI_IS240_LINES } pint_t;
  99. typedef union { int vint; void *vptr; } pint_ret_t;
  100. void PicoGetInternal(pint_t which, pint_ret_t *ret);
  101. struct PicoEState;
  102. // pico.c
  103. #define XPCM_BUFFER_SIZE (320+160)
  104. typedef struct
  105. {
  106. int pen_pos[2];
  107. int page;
  108. // internal
  109. int fifo_bytes; // bytes in FIFO
  110. int fifo_bytes_prev;
  111. int fifo_line_bytes; // float part, << 16
  112. int line_counter;
  113. unsigned short r1, r12;
  114. unsigned char xpcm_buffer[XPCM_BUFFER_SIZE+4];
  115. unsigned char *xpcm_ptr;
  116. } picohw_state;
  117. extern picohw_state PicoPicohw;
  118. // area.c
  119. int PicoState(const char *fname, int is_save);
  120. int PicoStateLoadGfx(const char *fname);
  121. void *PicoTmpStateSave(void);
  122. void PicoTmpStateRestore(void *data);
  123. extern void (*PicoStateProgressCB)(const char *str);
  124. // cd/cdd.c
  125. int cdd_load(const char *filename, int type);
  126. int cdd_unload(void);
  127. // Cart.c
  128. typedef enum
  129. {
  130. PMT_UNCOMPRESSED = 0,
  131. PMT_ZIP,
  132. PMT_CSO
  133. } pm_type;
  134. typedef struct
  135. {
  136. void *file; /* file handle */
  137. void *param; /* additional file related field */
  138. unsigned int size; /* size */
  139. pm_type type;
  140. char ext[4];
  141. } pm_file;
  142. pm_file *pm_open(const char *path);
  143. size_t pm_read(void *ptr, size_t bytes, pm_file *stream);
  144. int pm_seek(pm_file *stream, long offset, int whence);
  145. int pm_close(pm_file *fp);
  146. int PicoCartLoad(pm_file *f,unsigned char **prom,unsigned int *psize,int is_sms);
  147. int PicoCartInsert(unsigned char *rom, unsigned int romsize, const char *carthw_cfg);
  148. void PicoCartUnload(void);
  149. extern void (*PicoCartLoadProgressCB)(int percent);
  150. extern void (*PicoCDLoadProgressCB)(const char *fname, int percent);
  151. extern int PicoGameLoaded;
  152. // Draw.c
  153. // for line-based renderer, set conversion
  154. // from internal 8 bit representation in 'HighCol' to:
  155. typedef enum
  156. {
  157. PDF_NONE = 0, // no conversion
  158. PDF_RGB555, // RGB/BGR output, depends on compile options
  159. PDF_8BIT, // 8-bit out (handles shadow/hilight mode, sonic water)
  160. } pdso_t;
  161. void PicoDrawSetOutFormat(pdso_t which, int use_32x_line_mode);
  162. void PicoDrawSetOutBuf(void *dest, int increment);
  163. void PicoDrawSetCallbacks(int (*begin)(unsigned int num), int (*end)(unsigned int num));
  164. // utility
  165. #ifdef _ASM_DRAW_C
  166. void vidConvCpyRGB565(void *to, void *from, int pixels);
  167. #endif
  168. void PicoDoHighPal555(int sh, int line, struct PicoEState *est);
  169. // internals
  170. #define PDRAW_SPRITES_MOVED (1<<0) // (asm)
  171. #define PDRAW_WND_DIFF_PRIO (1<<1) // not all window tiles use same priority
  172. #define PDRAW_INTERLACE (1<<3)
  173. #define PDRAW_DIRTY_SPRITES (1<<4) // (asm)
  174. #define PDRAW_SONIC_MODE (1<<5) // mid-frame palette changes for 8bit renderer
  175. #define PDRAW_PLANE_HI_PRIO (1<<6) // have layer with all hi prio tiles (mk3)
  176. #define PDRAW_SHHI_DONE (1<<7) // layer sh/hi already processed
  177. #define PDRAW_32_COLS (1<<8) // 32 column mode
  178. extern int rendstatus_old;
  179. extern int rendlines;
  180. // draw.c
  181. void PicoDrawUpdateHighPal(void);
  182. void PicoDrawSetInternalBuf(void *dest, int line_increment);
  183. // draw2.c
  184. // stuff below is optional
  185. extern unsigned short *PicoCramHigh; // pointer to CRAM buff (0x40 shorts), converted to native device color (works only with 16bit for now)
  186. extern void (*PicoPrepareCram)(); // prepares PicoCramHigh for renderer to use
  187. // pico.c (32x)
  188. #ifndef NO_32X
  189. void Pico32xSetClocks(int msh2_hz, int ssh2_hz);
  190. #else
  191. #define Pico32xSetClocks(msh2_khz, ssh2_khz)
  192. #endif
  193. // normally 68k clock (7670442) * 3, in reality but much lower
  194. // because of high memory latencies
  195. #define PICO_MSH2_HZ ((int)(7670442.0 * 2.4))
  196. #define PICO_SSH2_HZ ((int)(7670442.0 * 2.4))
  197. // sound.c
  198. extern void (*PsndMix_32_to_16l)(short *dest, int *src, int count);
  199. void PsndRerate(int preserve_state);
  200. // media.c
  201. enum media_type_e {
  202. PM_BAD_DETECT = -1,
  203. PM_ERROR = -2,
  204. PM_BAD_CD = -3,
  205. PM_BAD_CD_NO_BIOS = -4,
  206. PM_MD_CART = 1, /* also 32x */
  207. PM_MARK3,
  208. PM_CD,
  209. };
  210. enum cd_img_type
  211. {
  212. CIT_NOT_CD = 0,
  213. CIT_ISO,
  214. CIT_BIN,
  215. CIT_CUE
  216. };
  217. enum media_type_e PicoLoadMedia(const char *filename,
  218. const char *carthw_cfg_fname,
  219. const char *(*get_bios_filename)(int *region, const char *cd_fname),
  220. void (*do_region_override)(const char *media_filename));
  221. int PicoCdCheck(const char *fname_in, int *pregion);
  222. extern unsigned char media_id_header[0x100];
  223. // memory.c
  224. enum input_device {
  225. PICO_INPUT_NOTHING,
  226. PICO_INPUT_PAD_3BTN,
  227. PICO_INPUT_PAD_6BTN,
  228. };
  229. void PicoSetInputDevice(int port, enum input_device device);
  230. #ifdef __cplusplus
  231. } // End of extern "C"
  232. #endif
  233. #endif // PICO_H