pico.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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. extern int plat_mem_set_exec(void *ptr, size_t size);
  31. // this one should handle display mode changes
  32. extern void emu_video_mode_change(int start_line, int line_count, int is_32cols);
  33. // this must switch to 16bpp mode
  34. extern void emu_32x_startup(void);
  35. // optional 32X BIOS, should be left NULL if not used
  36. // must be 256, 2048, 1024 bytes
  37. extern void *p32x_bios_g, *p32x_bios_m, *p32x_bios_s;
  38. // Pico.c
  39. #define POPT_EN_FM (1<< 0) // 00 000x
  40. #define POPT_EN_PSG (1<< 1)
  41. #define POPT_EN_Z80 (1<< 2)
  42. #define POPT_EN_STEREO (1<< 3)
  43. #define POPT_ALT_RENDERER (1<< 4) // 00 00x0
  44. // unused (1<< 5)
  45. // unused (1<< 6)
  46. #define POPT_ACC_SPRITES (1<< 7)
  47. #define POPT_DIS_32C_BORDER (1<< 8) // 00 0x00
  48. #define POPT_EXT_FM (1<< 9)
  49. #define POPT_EN_MCD_PCM (1<<10)
  50. #define POPT_EN_MCD_CDDA (1<<11)
  51. #define POPT_EN_MCD_GFX (1<<12) // 00 x000
  52. // unused (1<<13)
  53. #define POPT_EN_SOFTSCALE (1<<14)
  54. #define POPT_EN_MCD_RAMCART (1<<15)
  55. #define POPT_DIS_VDP_FIFO (1<<16) // 0x 0000
  56. #define POPT_EN_DRC (1<<17)
  57. #define POPT_DIS_SPRITE_LIM (1<<18)
  58. #define POPT_DIS_IDLE_DET (1<<19)
  59. #define POPT_EN_32X (1<<20)
  60. #define POPT_EN_PWM (1<<21)
  61. extern int PicoOpt; // bitfield
  62. #define PAHW_MCD (1<<0)
  63. #define PAHW_32X (1<<1)
  64. #define PAHW_SVP (1<<2)
  65. #define PAHW_PICO (1<<3)
  66. #define PAHW_SMS (1<<4)
  67. extern int PicoAHW; // Pico active hw
  68. #define PQUIRK_FORCE_6BTN (1<<0)
  69. extern int PicoQuirks;
  70. extern int PicoSkipFrame; // skip rendering frame, but still do sound (if enabled) and emulation stuff
  71. extern int PicoRegionOverride; // override the region detection 0: auto, 1: Japan NTSC, 2: Japan PAL, 4: US, 8: Europe
  72. extern int PicoAutoRgnOrder; // packed priority list of regions, for example 0x148 means this detection order: EUR, USA, JAP
  73. extern int PicoSVPCycles;
  74. void PicoInit(void);
  75. void PicoExit(void);
  76. void PicoPower(void);
  77. int PicoReset(void);
  78. void PicoLoopPrepare(void);
  79. void PicoFrame(void);
  80. void PicoFrameDrawOnly(void);
  81. extern int PicoPad[2]; // Joypads, format is MXYZ SACB RLDU
  82. extern void (*PicoWriteSound)(int bytes); // called once per frame at the best time to send sound buffer (PsndOut) to hardware
  83. extern void (*PicoMessage)(const char *msg); // callback to output text message from emu
  84. typedef enum { PI_ROM, PI_ISPAL, PI_IS40_CELL, PI_IS240_LINES } pint_t;
  85. typedef union { int vint; void *vptr; } pint_ret_t;
  86. void PicoGetInternal(pint_t which, pint_ret_t *ret);
  87. struct PicoEState;
  88. // cd/mcd.c
  89. extern void (*PicoMCDopenTray)(void);
  90. extern void (*PicoMCDcloseTray)(void);
  91. // pico.c
  92. #define XPCM_BUFFER_SIZE (320+160)
  93. typedef struct
  94. {
  95. int pen_pos[2];
  96. int page;
  97. // internal
  98. int fifo_bytes; // bytes in FIFO
  99. int fifo_bytes_prev;
  100. int fifo_line_bytes; // float part, << 16
  101. int line_counter;
  102. unsigned short r1, r12;
  103. unsigned char xpcm_buffer[XPCM_BUFFER_SIZE+4];
  104. unsigned char *xpcm_ptr;
  105. } picohw_state;
  106. extern picohw_state PicoPicohw;
  107. // area.c
  108. int PicoState(const char *fname, int is_save);
  109. int PicoStateLoadGfx(const char *fname);
  110. void *PicoTmpStateSave(void);
  111. void PicoTmpStateRestore(void *data);
  112. extern void (*PicoStateProgressCB)(const char *str);
  113. // cd/cdd.c
  114. int cdd_load(const char *filename, int type);
  115. int cdd_unload(void);
  116. // Cart.c
  117. typedef enum
  118. {
  119. PMT_UNCOMPRESSED = 0,
  120. PMT_ZIP,
  121. PMT_CSO
  122. } pm_type;
  123. typedef struct
  124. {
  125. void *file; /* file handle */
  126. void *param; /* additional file related field */
  127. unsigned int size; /* size */
  128. pm_type type;
  129. char ext[4];
  130. } pm_file;
  131. pm_file *pm_open(const char *path);
  132. size_t pm_read(void *ptr, size_t bytes, pm_file *stream);
  133. int pm_seek(pm_file *stream, long offset, int whence);
  134. int pm_close(pm_file *fp);
  135. int PicoCartLoad(pm_file *f,unsigned char **prom,unsigned int *psize,int is_sms);
  136. int PicoCartInsert(unsigned char *rom, unsigned int romsize, const char *carthw_cfg);
  137. void PicoCartUnload(void);
  138. extern void (*PicoCartLoadProgressCB)(int percent);
  139. extern void (*PicoCDLoadProgressCB)(const char *fname, int percent);
  140. extern int PicoGameLoaded;
  141. // Draw.c
  142. // for line-based renderer, set conversion
  143. // from internal 8 bit representation in 'HighCol' to:
  144. typedef enum
  145. {
  146. PDF_NONE = 0, // no conversion
  147. PDF_RGB555, // RGB/BGR output, depends on compile options
  148. PDF_8BIT, // 8-bit out (handles shadow/hilight mode, sonic water)
  149. } pdso_t;
  150. void PicoDrawSetOutFormat(pdso_t which, int use_32x_line_mode);
  151. void PicoDrawSetOutBuf(void *dest, int increment);
  152. void PicoDrawSetCallbacks(int (*begin)(unsigned int num), int (*end)(unsigned int num));
  153. // utility
  154. #ifdef _ASM_DRAW_C
  155. void vidConvCpyRGB565(void *to, void *from, int pixels);
  156. #endif
  157. void PicoDoHighPal555(int sh, int line, struct PicoEState *est);
  158. // internals
  159. #define PDRAW_SPRITES_MOVED (1<<0) // (asm)
  160. #define PDRAW_WND_DIFF_PRIO (1<<1) // not all window tiles use same priority
  161. #define PDRAW_SPR_LO_ON_HI (1<<2) // seen sprites without layer pri bit ontop spr. with that bit
  162. #define PDRAW_INTERLACE (1<<3)
  163. #define PDRAW_DIRTY_SPRITES (1<<4) // (asm)
  164. #define PDRAW_SONIC_MODE (1<<5) // mid-frame palette changes for 8bit renderer
  165. #define PDRAW_PLANE_HI_PRIO (1<<6) // have layer with all hi prio tiles (mk3)
  166. #define PDRAW_SHHI_DONE (1<<7) // layer sh/hi already processed
  167. #define PDRAW_32_COLS (1<<8) // 32 column mode
  168. extern int rendstatus_old;
  169. extern int rendlines;
  170. // draw.c
  171. void PicoDrawUpdateHighPal(void);
  172. void PicoDrawSetInternalBuf(void *dest, int line_increment);
  173. // draw2.c
  174. // stuff below is optional
  175. extern unsigned short *PicoCramHigh; // pointer to CRAM buff (0x40 shorts), converted to native device color (works only with 16bit for now)
  176. extern void (*PicoPrepareCram)(); // prepares PicoCramHigh for renderer to use
  177. // pico.c (32x)
  178. #ifndef NO_32X
  179. void Pico32xSetClocks(int msh2_hz, int ssh2_hz);
  180. #else
  181. #define Pico32xSetClocks(msh2_khz, ssh2_khz)
  182. #endif
  183. // normally 68k clock (7670442) * 3, in reality but much lower
  184. // because of high memory latencies
  185. #define PICO_MSH2_HZ ((int)(7670442.0 * 2.4))
  186. #define PICO_SSH2_HZ ((int)(7670442.0 * 2.4))
  187. // sound.c
  188. extern int PsndRate,PsndLen;
  189. extern short *PsndOut;
  190. extern void (*PsndMix_32_to_16l)(short *dest, int *src, int count);
  191. void PsndRerate(int preserve_state);
  192. // media.c
  193. enum media_type_e {
  194. PM_BAD_DETECT = -1,
  195. PM_ERROR = -2,
  196. PM_BAD_CD = -3,
  197. PM_BAD_CD_NO_BIOS = -4,
  198. PM_MD_CART = 1, /* also 32x */
  199. PM_MARK3,
  200. PM_CD,
  201. };
  202. enum cd_img_type
  203. {
  204. CIT_NOT_CD = 0,
  205. CIT_ISO,
  206. CIT_BIN,
  207. CIT_CUE
  208. };
  209. enum media_type_e PicoLoadMedia(const char *filename,
  210. const char *carthw_cfg_fname,
  211. const char *(*get_bios_filename)(int *region, const char *cd_fname),
  212. void (*do_region_override)(const char *media_filename));
  213. int PicoCdCheck(const char *fname_in, int *pregion);
  214. extern unsigned char media_id_header[0x100];
  215. // memory.c
  216. enum input_device {
  217. PICO_INPUT_NOTHING,
  218. PICO_INPUT_PAD_3BTN,
  219. PICO_INPUT_PAD_6BTN,
  220. };
  221. void PicoSetInputDevice(int port, enum input_device device);
  222. #ifdef __cplusplus
  223. } // End of extern "C"
  224. #endif
  225. #endif // PICO_H