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