(CTR/3DS) improve performance by using a DMA friendly vout_buf.
[picodrive.git] / pico / pico.h
CommitLineData
cff531af 1/*\r
2 * PicoDrive\r
3 * (c) Copyright Dave, 2004\r
4 * (C) notaz, 2006-2010\r
5 *\r
6 * This work is licensed under the terms of MAME license.\r
7 * See COPYING file in the top-level directory.\r
8 */\r
cc68a136 9\r
10#ifndef PICO_H\r
11#define PICO_H\r
12\r
21ebcfd3 13#include <stdlib.h> // size_t\r
eff55556 14\r
cc68a136 15#ifdef __cplusplus\r
16extern "C" {\r
17#endif\r
18\r
2446536b 19// message log\r
20extern void lprintf(const char *fmt, ...);\r
21\r
75736070 22// external funcs for Sega/Mega CD\r
7c18e34a 23extern int mp3_get_bitrate(void *f, int size);\r
24extern void mp3_start_play(void *f, int pos);\r
84100c0f 25extern void mp3_update(int *buffer, int length, int stereo);\r
26\r
27// this function should write-back d-cache and invalidate i-cache\r
28// on a mem region [start_addr, end_addr)\r
b081408f 29// used by dynarecs\r
2446536b 30extern void cache_flush_d_inval_i(void *start_addr, void *end_addr);\r
cb0316e4 31\r
b081408f 32// attempt to alloc mem at specified address.\r
33// alloc anywhere else if that fails (callers should handle that)\r
e743be20 34extern void *plat_mmap(unsigned long addr, size_t size, int need_exec, int is_fixed);\r
b4db550e 35extern void *plat_mremap(void *ptr, size_t oldsize, size_t newsize);\r
b081408f 36extern void plat_munmap(void *ptr, size_t size);\r
c25d78ee 37extern int plat_mem_set_exec(void *ptr, size_t size);\r
b081408f 38\r
19954be1 39// this one should handle display mode changes\r
40extern void emu_video_mode_change(int start_line, int line_count, int is_32cols);\r
41\r
ae87bffa 42// this must switch to 16bpp mode\r
974fdb5b 43extern void emu_32x_startup(void);\r
44\r
83ff19ec 45// optional 32X BIOS, should be left NULL if not used\r
46// must be 256, 2048, 1024 bytes\r
47extern void *p32x_bios_g, *p32x_bios_m, *p32x_bios_s;\r
48\r
cc68a136 49// Pico.c\r
602133e1 50#define POPT_EN_FM (1<< 0) // 00 000x\r
51#define POPT_EN_PSG (1<< 1)\r
52#define POPT_EN_Z80 (1<< 2)\r
53#define POPT_EN_STEREO (1<< 3)\r
54#define POPT_ALT_RENDERER (1<< 4) // 00 00x0\r
531a8f38 55// unused (1<< 5)\r
2aa27095 56// unused (1<< 6)\r
602133e1 57#define POPT_ACC_SPRITES (1<< 7)\r
58#define POPT_DIS_32C_BORDER (1<< 8) // 00 0x00\r
59#define POPT_EXT_FM (1<< 9)\r
60#define POPT_EN_MCD_PCM (1<<10)\r
61#define POPT_EN_MCD_CDDA (1<<11)\r
62#define POPT_EN_MCD_GFX (1<<12) // 00 x000\r
92dfd9af 63// unused (1<<13)\r
602133e1 64#define POPT_EN_SOFTSCALE (1<<14)\r
65#define POPT_EN_MCD_RAMCART (1<<15)\r
66#define POPT_DIS_VDP_FIFO (1<<16) // 0x 0000\r
92dfd9af 67#define POPT_EN_DRC (1<<17)\r
381eea9b 68#define POPT_DIS_SPRITE_LIM (1<<18)\r
053fd9b4 69#define POPT_DIS_IDLE_DET (1<<19)\r
db1d3564 70#define POPT_EN_32X (1<<20)\r
71#define POPT_EN_PWM (1<<21)\r
602133e1 72extern int PicoOpt; // bitfield\r
be2c4208 73\r
fa22af4c 74#define PAHW_MCD (1<<0)\r
75#define PAHW_32X (1<<1)\r
76#define PAHW_SVP (1<<2)\r
77#define PAHW_PICO (1<<3)\r
3e49ffd0 78#define PAHW_SMS (1<<4)\r
fa22af4c 79extern int PicoAHW; // Pico active hw\r
a76fad41 80\r
81#define PQUIRK_FORCE_6BTN (1<<0)\r
82extern int PicoQuirks;\r
83\r
fa22af4c 84extern int PicoSkipFrame; // skip rendering frame, but still do sound (if enabled) and emulation stuff\r
cc68a136 85extern int PicoRegionOverride; // override the region detection 0: auto, 1: Japan NTSC, 2: Japan PAL, 4: US, 8: Europe\r
fa22af4c 86extern int PicoAutoRgnOrder; // packed priority list of regions, for example 0x148 means this detection order: EUR, USA, JAP\r
0ffefdb8 87extern int PicoSVPCycles;\r
2aa27095 88void PicoInit(void);\r
cc68a136 89void PicoExit(void);\r
1cb1584b 90void PicoPower(void);\r
91int PicoReset(void);\r
5e128c6d 92void PicoLoopPrepare(void);\r
2aa27095 93void PicoFrame(void);\r
a12e0116 94void PicoFrameDrawOnly(void);\r
cc68a136 95extern int PicoPad[2]; // Joypads, format is MXYZ SACB RLDU\r
a4edca53 96extern void (*PicoWriteSound)(int bytes); // called once per frame at the best time to send sound buffer (PsndOut) to hardware\r
66fdc0f0 97extern void (*PicoMessage)(const char *msg); // callback to output text message from emu\r
4609d0cd 98typedef enum { PI_ROM, PI_ISPAL, PI_IS40_CELL, PI_IS240_LINES } pint_t;\r
99typedef union { int vint; void *vptr; } pint_ret_t;\r
100void PicoGetInternal(pint_t which, pint_ret_t *ret);\r
cc68a136 101\r
89dbbf2b 102// cd/mcd.c\r
721cd396 103extern void (*PicoMCDopenTray)(void);\r
d687ef50 104extern void (*PicoMCDcloseTray)(void);\r
0a051f55 105\r
f3a57b2d 106// pico.c\r
ed367a3f 107#define XPCM_BUFFER_SIZE (320+160)\r
d49b10c2 108typedef struct\r
109{\r
110 int pen_pos[2];\r
111 int page;\r
112 // internal\r
fa22af4c 113 int fifo_bytes; // bytes in FIFO\r
114 int fifo_bytes_prev;\r
ef4eb506 115 int fifo_line_bytes; // float part, << 16\r
d49b10c2 116 int line_counter;\r
ef4eb506 117 unsigned short r1, r12;\r
118 unsigned char xpcm_buffer[XPCM_BUFFER_SIZE+4];\r
119 unsigned char *xpcm_ptr;\r
d49b10c2 120} picohw_state;\r
121extern picohw_state PicoPicohw;\r
406c96c5 122\r
bcc9eda0 123// area.c\r
124int PicoState(const char *fname, int is_save);\r
b4db550e 125int PicoStateLoadGfx(const char *fname);\r
126void *PicoTmpStateSave(void);\r
127void PicoTmpStateRestore(void *data);\r
76276b0b 128extern void (*PicoStateProgressCB)(const char *str);\r
cc68a136 129\r
274fcc35 130// cd/cdd.c\r
131int cdd_load(const char *filename, int type);\r
132int cdd_unload(void);\r
eff55556 133\r
cc68a136 134// Cart.c\r
83bd0b76 135typedef enum\r
136{\r
137 PMT_UNCOMPRESSED = 0,\r
71de3cd9 138 PMT_ZIP,\r
139 PMT_CSO\r
83bd0b76 140} pm_type;\r
141typedef struct\r
142{\r
143 void *file; /* file handle */\r
144 void *param; /* additional file related field */\r
145 unsigned int size; /* size */\r
146 pm_type type;\r
87b0845f 147 char ext[4];\r
83bd0b76 148} pm_file;\r
149pm_file *pm_open(const char *path);\r
150size_t pm_read(void *ptr, size_t bytes, pm_file *stream);\r
151int pm_seek(pm_file *stream, long offset, int whence);\r
152int pm_close(pm_file *fp);\r
3e49ffd0 153int PicoCartLoad(pm_file *f,unsigned char **prom,unsigned int *psize,int is_sms);\r
ae87bffa 154int PicoCartInsert(unsigned char *rom, unsigned int romsize, const char *carthw_cfg);\r
2aa27095 155void PicoCartUnload(void);\r
a9b3ffd3 156extern void (*PicoCartLoadProgressCB)(int percent);\r
b2451ac6 157extern void (*PicoCDLoadProgressCB)(const char *fname, int percent);\r
4c2e3554 158extern int PicoGameLoaded;\r
cc68a136 159\r
160// Draw.c\r
5a681086 161// for line-based renderer, set conversion\r
162// from internal 8 bit representation in 'HighCol' to:\r
163typedef enum\r
164{\r
165 PDF_NONE = 0, // no conversion\r
166 PDF_RGB555, // RGB/BGR output, depends on compile options\r
167 PDF_8BIT, // 8-bit out (handles shadow/hilight mode, sonic water)\r
168} pdso_t;\r
41946d70 169void PicoDrawSetOutFormat(pdso_t which, int use_32x_line_mode);\r
5a681086 170void PicoDrawSetOutBuf(void *dest, int increment);\r
f4750ee0 171void PicoDrawSetCallbacks(int (*begin)(unsigned int num), int (*end)(unsigned int num));\r
cc68a136 172extern void *DrawLineDest;\r
ea8c405f 173extern unsigned char *HighCol;\r
cc68a136 174// utility\r
175#ifdef _ASM_DRAW_C\r
ea8c405f 176void vidConvCpyRGB565(void *to, void *from, int pixels);\r
cc68a136 177#endif\r
e55f0cbb 178void PicoDoHighPal555(int sh);\r
fbc65db7 179extern int PicoDrawMask;\r
180#define PDRAW_LAYERB_ON (1<<2)\r
181#define PDRAW_LAYERA_ON (1<<3)\r
182#define PDRAW_SPRITES_LOW_ON (1<<4)\r
183#define PDRAW_SPRITES_HI_ON (1<<7)\r
5e49c3a8 184#define PDRAW_32X_ON (1<<8)\r
602133e1 185// internals\r
947fb5f9 186#define PDRAW_SPRITES_MOVED (1<<0) // (asm)\r
602133e1 187#define PDRAW_WND_DIFF_PRIO (1<<1) // not all window tiles use same priority\r
f8af9634 188#define PDRAW_SPR_LO_ON_HI (1<<2) // seen sprites without layer pri bit ontop spr. with that bit\r
947fb5f9 189#define PDRAW_INTERLACE (1<<3)\r
190#define PDRAW_DIRTY_SPRITES (1<<4) // (asm)\r
602133e1 191#define PDRAW_SONIC_MODE (1<<5) // mid-frame palette changes for 8bit renderer\r
192#define PDRAW_PLANE_HI_PRIO (1<<6) // have layer with all hi prio tiles (mk3)\r
193#define PDRAW_SHHI_DONE (1<<7) // layer sh/hi already processed\r
ae87bffa 194#define PDRAW_32_COLS (1<<8) // 32 column mode\r
19954be1 195extern int rendstatus, rendstatus_old;\r
ae87bffa 196extern int rendlines;\r
602133e1 197extern unsigned short HighPal[0x100];\r
cc68a136 198\r
5a681086 199// draw.c\r
200void PicoDrawUpdateHighPal(void);\r
201void PicoDrawSetInternalBuf(void *dest, int line_increment);\r
202\r
203// draw2.c\r
cc68a136 204// stuff below is optional\r
8e5427a0 205extern unsigned char *PicoDraw2FB; // buffer for fast renderer in format (8+320)x(8+224+8) (eights for borders)\r
cc68a136 206extern unsigned short *PicoCramHigh; // pointer to CRAM buff (0x40 shorts), converted to native device color (works only with 16bit for now)\r
207extern void (*PicoPrepareCram)(); // prepares PicoCramHigh for renderer to use\r
208\r
f3a57b2d 209// pico.c (32x)\r
ed4402a7 210#ifndef NO_32X\r
211\r
212void Pico32xSetClocks(int msh2_hz, int ssh2_hz);\r
fcdefcf6 213\r
ed4402a7 214#else\r
215\r
216#define Pico32xSetClocks(msh2_khz, ssh2_khz)\r
217\r
218#endif\r
219\r
220// normally 68k clock (7670442) * 3, in reality but much lower\r
221// because of high memory latencies\r
222#define PICO_MSH2_HZ ((int)(7670442.0 * 2.4))\r
223#define PICO_SSH2_HZ ((int)(7670442.0 * 2.4))\r
224\r
cc68a136 225// sound.c\r
226extern int PsndRate,PsndLen;\r
227extern short *PsndOut;\r
4a32f01f 228extern void (*PsndMix_32_to_16l)(short *dest, int *src, int count);\r
9d917eea 229void PsndRerate(int preserve_state);\r
cc68a136 230\r
4c2e3554 231// media.c\r
232enum media_type_e {\r
233 PM_BAD_DETECT = -1,\r
234 PM_ERROR = -2,\r
235 PM_BAD_CD = -3,\r
236 PM_BAD_CD_NO_BIOS = -4,\r
237 PM_MD_CART = 1, /* also 32x */\r
238 PM_MARK3,\r
239 PM_CD,\r
240};\r
274fcc35 241\r
242enum cd_img_type\r
243{\r
244 CIT_NOT_CD = 0,\r
245 CIT_ISO,\r
246 CIT_BIN,\r
247 CIT_CUE\r
248};\r
249\r
4c2e3554 250enum media_type_e PicoLoadMedia(const char *filename,\r
251 const char *carthw_cfg_fname,\r
252 const char *(*get_bios_filename)(int *region, const char *cd_fname),\r
253 void (*do_region_override)(const char *media_filename));\r
254int PicoCdCheck(const char *fname_in, int *pregion);\r
255\r
256extern unsigned char media_id_header[0x100];\r
257\r
531a8f38 258// memory.c\r
259enum input_device {\r
260 PICO_INPUT_NOTHING,\r
261 PICO_INPUT_PAD_3BTN,\r
262 PICO_INPUT_PAD_6BTN,\r
263};\r
264void PicoSetInputDevice(int port, enum input_device device);\r
265\r
cc68a136 266#ifdef __cplusplus\r
267} // End of extern "C"\r
268#endif\r
269\r
270#endif // PICO_H\r