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