1 #ifndef MAME2003_H
2 #define MAME2003_H
3 
4 #include <stdio.h>
5 #include <libretro.h>
6 #include <file/file_path.h>
7 #include <compat/posix_string.h>
8 #include "osd_cpu.h"
9 #include "inptport.h"
10 
11 /*
12  * we can't #include <retro_miscellaneous.h> to bring in PATH_MAX_LENGTH due to namespace conflicts
13  * involing the DWORD define so we'll include only some useful bits for now
14  */
15 #include <retro_inline.h>
16 
17 #if defined(__CELLOS_LV2__)
18 #include <sys/fs_external.h>
19 #endif
20 
21 #include <limits.h>
22 
23 #ifndef PATH_MAX_LENGTH
24 #if defined(__CELLOS_LV2__)
25 #define PATH_MAX_LENGTH CELL_FS_MAX_FS_PATH_LENGTH
26 #elif defined(_XBOX1) || defined(_3DS) || defined(PSP) || defined(PS2) || defined(GEKKO) || defined(WIIU) || defined(ORBIS)
27 #define PATH_MAX_LENGTH 512
28 #else
29 #define PATH_MAX_LENGTH 4096
30 #endif
31 #endif
32 
33 /*
34  * end of retro_miscellaneous.h bits
35  */
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 
41 /* The Win32 port requires this constant for variable arg routines. */
42 #ifndef CLIB_DECL
43 #define CLIB_DECL
44 #endif
45 
46 #ifdef __LP64__
47 #define FPTR unsigned long   /* 64bit: sizeof(void *) is sizeof(long)  */
48 #else
49 #define FPTR unsigned int
50 #endif
51 
52 
53 extern void mame2003_video_get_geometry(struct retro_game_geometry *geom);
54 
55 
56 /******************************************************************************
57 
58 	Shared libretro log interface
59     set in mame2003.c
60 
61 ******************************************************************************/
62 extern retro_log_printf_t log_cb;
63 
64 
65 /******************************************************************************
66 
67 	frontend message interface
68     implemented in mame2003.c
69 
70 ******************************************************************************/
71 extern void frontend_message_cb(const char *message_string, unsigned frames_to_display);
72 
73 
74 struct retro_variable_default
75 {
76    const char *key;
77    const char *defaults_string;
78 };
79 
80 enum
81 {
82   IDX_CLASSIC = 0,
83   IDX_MODERN,
84   IDX_8BUTTON,
85   IDX_6BUTTON,
86   IDX_PAD_end,
87 };
88 
89 #define PLAYER_COUNT 6
90 
91 enum /*the "display numbers" for each player, as opposed to their array index */
92 {
93   DISP_PLAYER1 = 1,
94   DISP_PLAYER2,
95   DISP_PLAYER3,
96   DISP_PLAYER4,
97   DISP_PLAYER5,
98   DISP_PLAYER6
99 };
100 
101 
102 /******************************************************************************
103 
104 	Display
105 
106 ******************************************************************************/
107 
108 /* mame_bitmap used to be declared here, but has moved to common.c */
109 /* sadly, the include order requires that at least this forward declaration is here */
110 struct mame_bitmap;
111 struct mame_display;
112 struct performance_info;
113 struct rectangle;
114 struct rom_load_data;
115 
116 
117 /* these are the parameters passed into osd_create_display */
118 struct osd_create_params
119 {
120 	int width, height;			/* width and height */
121 	int aspect_x, aspect_y;		/* aspect ratio X:Y */
122 	int depth;					/* depth, either 16(palette), 15(RGB) or 32(RGB) */
123 	int colors;					/* colors in the palette (including UI) */
124 	float fps;					/* frame rate */
125 	int video_attributes;		/* video flags from driver */
126 	int orientation;			/* orientation requested by the user */
127 };
128 
129 
130 
131 /*
132   Create a display screen, or window, of the given dimensions (or larger). It is
133   acceptable to create a smaller display if necessary, in that case the user must
134   have a way to move the visibility window around.
135 
136   The params contains all the information the
137   Attributes are the ones defined in driver.h, they can be used to perform
138   optimizations, e.g. dirty rectangle handling if the game supports it, or faster
139   blitting routines with fixed palette if the game doesn't change the palette at
140   run time. The VIDEO_PIXEL_ASPECT_RATIO flags should be honored to produce a
141   display of correct proportions.
142   Orientation is the screen orientation (as defined in driver.h) which will be done
143   by the core. This can be used to select thinner screen modes for vertical games
144   (ORIENTATION_SWAP_XY set), or even to ask the user to rotate the monitor if it's
145   a pivot model. Note that the OS dependent code must NOT perform any rotation,
146   this is done entirely in the core.
147   Depth can be 8 or 16 for palettized modes, meaning that the core will store in the
148   bitmaps logical pens which will have to be remapped through a palette at blit time,
149   and 15 or 32 for direct mapped modes, meaning that the bitmaps will contain RGB
150   triplets (555 or 888). For direct mapped modes, the VIDEO_RGB_DIRECT flag is set
151   in the attributes field.
152 
153   Returns 0 on success.
154 */
155 int osd_create_display(const struct osd_create_params *params, UINT32 *rgb_components);
156 void osd_close_display(void);
157 
158 
159 /*
160   osd_skip_this_frame() must return 0 if the current frame will be displayed.
161   This can be used by drivers to skip cpu intensive processing for skipped
162   frames, so the function must return a consistent result throughout the
163   current frame. The function MUST NOT check timers and dynamically determine
164   whether to display the frame: such calculations must be done in
165   osd_update_video_and_audio(), and they must affect the FOLLOWING frames, not
166   the current one. At the end of osd_update_video_and_audio(), the code must
167   already know exactly whether the next frame will be skipped or not.
168 */
169 int osd_skip_this_frame(void);
170 
171 
172 /*
173   Update video and audio. game_bitmap contains the game display, while
174   debug_bitmap an image of the debugger window (if the debugger is active; NULL
175   otherwise). They can be shown one at a time, or in two separate windows,
176   depending on the OS limitations. If only one is shown, the user must be able
177   to toggle between the two by pressing IPT_UI_TOGGLE_DEBUG; moreover,
178   osd_debugger_focus() will be used by the core to force the display of a
179   specific bitmap, e.g. the debugger one when the debugger becomes active.
180 
181   leds_status is a bitmask of lit LEDs, usually player start lamps. They can be
182   simulated using the keyboard LEDs, or in other ways e.g. by placing graphics
183   on the window title bar.
184 */
185 void osd_update_video_and_audio(struct mame_display *display);
186 
187 
188 /******************************************************************************
189 
190 	Sound
191 
192 ******************************************************************************/
193 
194 /*
195   osd_start_audio_stream() is called at the start of the emulation to initialize
196   the output stream, then osd_update_audio_stream() is called every frame to
197   feed new data. osd_stop_audio_stream() is called when the emulation is stopped.
198 
199   The sample rate is fixed at Machine->sample_rate. Samples are 16-bit, signed.
200   When the stream is stereo, left and right samples are alternated in the
201   stream.
202 
203   osd_start_audio_stream() and osd_update_audio_stream() must return the number
204   of samples (or couples of samples, when using stereo) required for next frame.
205   This will be around Machine->sample_rate / Machine->drv->frames_per_second,
206   the code may adjust it by SMALL AMOUNTS to keep timing accurate and to
207   maintain audio and video in sync when using vsync. Note that sound emulation,
208   especially when DACs are involved, greatly depends on the number of samples
209   per frame to be roughly constant, so the returned value must always stay close
210   to the reference value of Machine->sample_rate / Machine->drv->frames_per_second.
211   Of course that value is not necessarily an integer so at least a +/- 1
212   adjustment is necessary to avoid drifting over time.
213 */
214 int osd_start_audio_stream(int stereo);
215 int osd_update_audio_stream(INT16 *buffer);
216 void osd_stop_audio_stream(void);
217 
218 
219 /******************************************************************************
220 
221 	Keyboard
222 
223 ******************************************************************************/
224 /*
225   return a list of all available keys (see input.h)
226 */
227 const struct KeyboardInfo *osd_get_key_list(void);
228 
229 /*
230   tell whether the specified key is pressed or not. keycode is the OS dependent
231   code specified in the list returned by osd_get_key_list().
232 */
233 int osd_is_key_pressed(int keycode);
234 
235 /*
236   Return the Unicode value of the most recently pressed key. This
237   function is used only by text-entry routines in the user interface and should
238   not be used by drivers. The value returned is in the range of the first 256
239   bytes of Unicode, e.g. ISO-8859-1. A return value of 0 indicates no key down.
240 
241   Set flush to 1 to clear the buffer before entering text. This will avoid
242   having prior UI and game keys leak into the text entry.
243 */
244 int osd_readkey_unicode(int flush);
245 
246 
247 /******************************************************************************
248 
249 	Joystick & Mouse/Trackball
250 
251 ******************************************************************************/
252 
253 /*
254   return a list of all available joystick inputs (see input.h)
255 */
256 const struct JoystickInfo *osd_get_joy_list(void);
257 
258 /*
259   tell whether the specified joystick direction/button is pressed or not.
260   joycode is the OS dependent code specified in the list returned by
261   osd_get_joy_list().
262 */
263 int osd_is_joy_pressed(int joycode);
264 
265 
266 /* We support 6 players for each analog control / trackball */
267 #define OSD_MAX_JOY_ANALOG	6
268 #define X_AXIS			0
269 #define Y_AXIS			1
270 #define Z_AXIS			2
271 #define PEDAL_AXIS		3
272 #define MAX_ANALOG_AXES	4
273 
274 /* added for building joystick seq for analog inputs */
275 int osd_is_joystick_axis_code(int joycode);
276 
277 /* Joystick calibration routines BW 19981216 */
278 /* Do we need to calibrate the joystick at all? */
279 int osd_joystick_needs_calibration(void);
280 /* Preprocessing for joystick calibration. Returns 0 on success */
281 void osd_joystick_start_calibration(void);
282 /* Prepare the next calibration step. Return a description of this step. */
283 /* (e.g. "move to upper left") */
284 const char *osd_joystick_calibrate_next(void);
285 /* Get the actual joystick calibration data for the current position */
286 void osd_joystick_calibrate(void);
287 /* Postprocessing (e.g. saving joystick data to config) */
288 void osd_joystick_end_calibration(void);
289 
290 void osd_lightgun_read(int player, int *deltax, int *deltay);
291 void osd_trak_read(int player, int *deltax, int *deltay);
292 
293 /* return values in the range -128 .. 128 (yes, 128, not 127) */
294 void osd_analogjoy_read(int player,int analog_axis[MAX_ANALOG_AXES], InputCode analogjoy_input[MAX_ANALOG_AXES]);
295 
296 
297 /*
298   inptport.c defines some general purpose defaults for key and joystick bindings.
299   They may be further adjusted by the OS dependent code to better match the
300   available keyboard, e.g. one could map pause to the Pause key instead of P, or
301   snapshot to PrtScr instead of F12. Of course the user can further change the
302   settings to anything he/she likes.
303   This function is called on startup, before reading the configuration from disk.
304   Scan the list, and change the keys/joysticks you want.
305 */
306 void osd_customize_inputport_defaults(struct ipd *defaults);
307 
308 
309 /******************************************************************************
310 
311 	Timing
312 
313 ******************************************************************************/
314 
315 typedef INT64 cycles_t;
316 
317 /* return the current number of cycles, or some other high-resolution timer */
318 cycles_t osd_cycles(void);
319 
320 /* return the number of cycles per second */
321 cycles_t osd_cycles_per_second(void);
322 
323 /* return the current number of cycles, or some other high-resolution timer.
324    This call must be the fastest possible because it is called by the profiler;
325    it isn't necessary to know the number of ticks per seconds. */
326 cycles_t osd_profiling_ticks(void);
327 
328 
329 #ifdef __cplusplus
330 }
331 #endif
332 
333 #endif /* MAME2003_H */
334