| 1 |
#ifndef OSDEPEND_H |
| 2 |
#define OSDEPEND_H |
| 3 |
|
| 4 |
#include "osd_cpu.h" |
| 5 |
#include "inptport.h" |
| 6 |
|
| 7 |
#ifdef __cplusplus |
| 8 |
extern "C" { |
| 9 |
#endif |
| 10 |
|
| 11 |
/* The Win32 port requires this constant for variable arg routines. */ |
| 12 |
#ifndef CLIB_DECL |
| 13 |
#define CLIB_DECL |
| 14 |
#endif |
| 15 |
|
| 16 |
#ifdef __LP64__ |
| 17 |
#define FPTR unsigned long /* 64bit: sizeof(void *) is sizeof(long) */ |
| 18 |
#else |
| 19 |
#define FPTR unsigned int |
| 20 |
#endif |
| 21 |
|
| 22 |
|
| 23 |
int osd_init(void); |
| 24 |
void osd_exit(void); |
| 25 |
|
| 26 |
|
| 27 |
/****************************************************************************** |
| 28 |
|
| 29 |
Display |
| 30 |
|
| 31 |
******************************************************************************/ |
| 32 |
|
| 33 |
/* mame_bitmap used to be declared here, but has moved to common.c */ |
| 34 |
/* sadly, the include order requires that at least this forward declaration is here */ |
| 35 |
struct mame_bitmap; |
| 36 |
|
| 37 |
/* |
| 38 |
Create a display screen, or window, of the given dimensions (or larger). It is |
| 39 |
acceptable to create a smaller display if necessary, in that case the user must |
| 40 |
have a way to move the visibility window around. |
| 41 |
Attributes are the ones defined in driver.h, they can be used to perform |
| 42 |
optimizations, e.g. dirty rectangle handling if the game supports it, or faster |
| 43 |
blitting routines with fixed palette if the game doesn't change the palette at |
| 44 |
run time. The VIDEO_PIXEL_ASPECT_RATIO flags should be honored to produce a |
| 45 |
display of correct proportions. |
| 46 |
Orientation is the screen orientation (as defined in driver.h) which will be done |
| 47 |
by the core. This can be used to select thinner screen modes for vertical games |
| 48 |
(ORIENTATION_SWAP_XY set), or even to ask the user to rotate the monitor if it's |
| 49 |
a pivot model. Note that the OS dependant code must NOT perform any rotation, |
| 50 |
this is done entirely in the core. |
| 51 |
Depth can be 8 or 16 for palettized modes, meaning that the core will store in the |
| 52 |
bitmaps logical pens which will have to be remapped through a palette at blit time, |
| 53 |
and 15 or 32 for direct mapped modes, meaning that the bitmaps will contain RGB |
| 54 |
triplets (555 or 888). For direct mapped modes, the VIDEO_RGB_DIRECT flag is set |
| 55 |
in the attributes field. |
| 56 |
|
| 57 |
Returns 0 on success. |
| 58 |
*/ |
| 59 |
int osd_create_display(int width,int height,int depth,int fps,int attributes,int orientation); |
| 60 |
void osd_close_display(void); |
| 61 |
|
| 62 |
|
| 63 |
/* |
| 64 |
Set the portion of the screen bitmap that has to be drawn on screen. The OS |
| 65 |
dependant code is allowed to display a smaller portion of the bitmap if |
| 66 |
necessary, in that case the user must have a way to move the visibility |
| 67 |
window around. |
| 68 |
Parts of the bitmap outside the specified rectangle must never be drawn |
| 69 |
because they might contain garbage. |
| 70 |
The function must call set_ui_visarea() to tell the core the portion of the |
| 71 |
bitmap actually visible (which might be smaller than requested), so the user |
| 72 |
interface can be drawn accordingly. If the visible area is smaller than |
| 73 |
requested, set_ui_visarea() must also be called whenever the user moves the |
| 74 |
visibility window, so the user interface will remain at a fixed position on |
| 75 |
screen while the game display moves around. |
| 76 |
*/ |
| 77 |
void osd_set_visible_area(int min_x,int max_x,int min_y,int max_y); |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
/* |
| 82 |
osd_allocate_colors() is called after osd_create_display(), to create and |
| 83 |
initialize the palette. |
| 84 |
|
| 85 |
palette is an array of 'totalcolors' R,G,B triplets. |
| 86 |
|
| 87 |
For direct mapped modes, the palette contains just three entries, a pure red, |
| 88 |
pure green and pure blue. Of course this is not the game palette, it is only |
| 89 |
used by the core to determine the layout (RGB, BGR etc.) so the OS code can |
| 90 |
do a straight copy of the bitmap without having to remap it. RGB 565 modes |
| 91 |
are NOT supported yet by the core, only 555. The function must return in |
| 92 |
*rgb_components the values corresponding to the requested colors. |
| 93 |
|
| 94 |
The function must also initialize Machine->uifont->colortable[] to get proper |
| 95 |
white-on-black and black-on-white text. |
| 96 |
|
| 97 |
The debug_* parameters are for the debugger display, and may be NULL if the |
| 98 |
debugger is not enabled. The debugger always uses DEBUGGER_TOTAL_COLORS |
| 99 |
colors and the palette doesn't change at run time. |
| 100 |
|
| 101 |
Return 0 for success. |
| 102 |
*/ |
| 103 |
int osd_allocate_colors(unsigned int totalcolors, |
| 104 |
const UINT8 *palette,UINT32 *rgb_components, |
| 105 |
const UINT8 *debug_palette,UINT32 *debug_pens); |
| 106 |
void osd_modify_pen(int pen,unsigned char red, unsigned char green, unsigned char blue); |
| 107 |
|
| 108 |
#ifdef MAME32JP |
| 109 |
#define osd_mark_dirty(xmin, ymin, xmax, ymax) |
| 110 |
#else |
| 111 |
void osd_mark_dirty(int xmin,int ymin,int xmax,int ymax); |
| 112 |
#endif |
| 113 |
|
| 114 |
/* |
| 115 |
osd_skip_this_frame() must return 0 if the current frame will be displayed. |
| 116 |
This can be used by drivers to skip cpu intensive processing for skipped |
| 117 |
frames, so the function must return a consistent result throughout the |
| 118 |
current frame. The function MUST NOT check timers and dynamically determine |
| 119 |
whether to display the frame: such calculations must be done in |
| 120 |
osd_update_video_and_audio(), and they must affect the FOLLOWING frames, not |
| 121 |
the current one. At the end of osd_update_video_and_audio(), the code must |
| 122 |
already know exactly whether the next frame will be skipped or not. |
| 123 |
*/ |
| 124 |
int osd_skip_this_frame(void); |
| 125 |
|
| 126 |
/* |
| 127 |
Update video and audio. game_bitmap contains the game display, while |
| 128 |
debug_bitmap an image of the debugger window (if the debugger is active; NULL |
| 129 |
otherwise). They can be shown one at a time, or in two separate windows, |
| 130 |
depending on the OS limitations. If only one is shown, the user must be able |
| 131 |
to toggle between the two by pressing IPT_UI_TOGGLE_DEBUG; moreover, |
| 132 |
osd_debugger_focus() will be used by the core to force the display of a |
| 133 |
specific bitmap, e.g. the debugger one when the debugger becomes active. |
| 134 |
|
| 135 |
leds_status is a bitmask of lit LEDs, usually player start lamps. They can be |
| 136 |
simulated using the keyboard LEDs, or in other ways e.g. by placing graphics |
| 137 |
on the window title bar. |
| 138 |
*/ |
| 139 |
#ifdef MAME32JP |
| 140 |
void osd_update_video_and_audio(struct mame_bitmap *game_bitmap, struct mame_bitmap *debug_bitmap); |
| 141 |
#else |
| 142 |
void osd_update_video_and_audio( |
| 143 |
struct mame_bitmap *game_bitmap,struct mame_bitmap *debug_bitmap,int leds_status); |
| 144 |
#endif |
| 145 |
|
| 146 |
#ifdef MAME32JP |
| 147 |
#define osd_debugger_focus(debugger_has_focus) |
| 148 |
#else |
| 149 |
void osd_debugger_focus(int debugger_has_focus); |
| 150 |
#endif |
| 151 |
|
| 152 |
void osd_set_gamma(float _gamma); |
| 153 |
float osd_get_gamma(void); |
| 154 |
void osd_set_brightness(int brightness); |
| 155 |
int osd_get_brightness(void); |
| 156 |
|
| 157 |
/* |
| 158 |
Save a screen shot of the game display. It is suggested to use the core |
| 159 |
function save_screen_snapshot() or save_screen_snapshot_as(), so the format |
| 160 |
of the screen shots will be consistent across ports. This hook is provided |
| 161 |
only to allow the display of a file requester to let the user choose the |
| 162 |
file name. This isn't scrictly necessary, so you can just call |
| 163 |
save_screen_snapshot() to let the core automatically pick a default name. |
| 164 |
*/ |
| 165 |
void osd_save_snapshot(struct mame_bitmap *bitmap); |
| 166 |
|
| 167 |
#ifdef MAME32JP |
| 168 |
void osd_refresh_display(void); |
| 169 |
#endif |
| 170 |
|
| 171 |
/****************************************************************************** |
| 172 |
|
| 173 |
Sound |
| 174 |
|
| 175 |
******************************************************************************/ |
| 176 |
|
| 177 |
/* |
| 178 |
osd_start_audio_stream() is called at the start of the emulation to initialize |
| 179 |
the output stream, then osd_update_audio_stream() is called every frame to |
| 180 |
feed new data. osd_stop_audio_stream() is called when the emulation is stopped. |
| 181 |
|
| 182 |
The sample rate is fixed at Machine->sample_rate. Samples are 16-bit, signed. |
| 183 |
When the stream is stereo, left and right samples are alternated in the |
| 184 |
stream. |
| 185 |
|
| 186 |
osd_start_audio_stream() and osd_update_audio_stream() must return the number |
| 187 |
of samples (or couples of samples, when using stereo) required for next frame. |
| 188 |
This will be around Machine->sample_rate / Machine->drv->frames_per_second, |
| 189 |
the code may adjust it by SMALL AMOUNTS to keep timing accurate and to |
| 190 |
maintain audio and video in sync when using vsync. Note that sound emulation, |
| 191 |
especially when DACs are involved, greatly depends on the number of samples |
| 192 |
per frame to be roughly constant, so the returned value must always stay close |
| 193 |
to the reference value of Machine->sample_rate / Machine->drv->frames_per_second. |
| 194 |
Of course that value is not necessarily an integer so at least a +/- 1 |
| 195 |
adjustment is necessary to avoid drifting over time. |
| 196 |
*/ |
| 197 |
int osd_start_audio_stream(int stereo); |
| 198 |
int osd_update_audio_stream(INT16 *buffer); |
| 199 |
void osd_stop_audio_stream(void); |
| 200 |
|
| 201 |
/* |
| 202 |
control master volume. attenuation is the attenuation in dB (a negative |
| 203 |
number). To convert from dB to a linear volume scale do the following: |
| 204 |
volume = MAX_VOLUME; |
| 205 |
while (attenuation++ < 0) |
| 206 |
volume /= 1.122018454; // = (10 ^ (1/20)) = 1dB |
| 207 |
*/ |
| 208 |
void osd_set_mastervolume(int attenuation); |
| 209 |
int osd_get_mastervolume(void); |
| 210 |
|
| 211 |
void osd_sound_enable(int enable); |
| 212 |
|
| 213 |
#ifdef MAME32JP |
| 214 |
void osd_start_log_wave(void); |
| 215 |
void osd_stop_log_wave(void); |
| 216 |
void osd_log_wave(void); |
| 217 |
#endif |
| 218 |
|
| 219 |
/****************************************************************************** |
| 220 |
|
| 221 |
Keyboard |
| 222 |
|
| 223 |
******************************************************************************/ |
| 224 |
|
| 225 |
/* |
| 226 |
return a list of all available keys (see input.h) |
| 227 |
*/ |
| 228 |
const struct KeyboardInfo *osd_get_key_list(void); |
| 229 |
|
| 230 |
/* |
| 231 |
tell whether the specified key is pressed or not. keycode is the OS dependant |
| 232 |
code specified in the list returned by osd_get_key_list(). |
| 233 |
*/ |
| 234 |
int osd_is_key_pressed(int keycode); |
| 235 |
|
| 236 |
/* |
| 237 |
Return the Unicode value of the most recently pressed key. This |
| 238 |
function is used only by text-entry routines in the user interface and should |
| 239 |
not be used by drivers. The value returned is in the range of the first 256 |
| 240 |
bytes of Unicode, e.g. ISO-8859-1. A return value of 0 indicates no key down. |
| 241 |
|
| 242 |
Set flush to 1 to clear the buffer before entering text. This will avoid |
| 243 |
having prior UI and game keys leak into the text entry. |
| 244 |
*/ |
| 245 |
int osd_readkey_unicode(int flush); |
| 246 |
|
| 247 |
|
| 248 |
/****************************************************************************** |
| 249 |
|
| 250 |
Joystick & Mouse/Trackball |
| 251 |
|
| 252 |
******************************************************************************/ |
| 253 |
|
| 254 |
/* |
| 255 |
return a list of all available joystick inputs (see input.h) |
| 256 |
*/ |
| 257 |
const struct JoystickInfo *osd_get_joy_list(void); |
| 258 |
|
| 259 |
/* |
| 260 |
tell whether the specified joystick direction/button is pressed or not. |
| 261 |
joycode is the OS dependant code specified in the list returned by |
| 262 |
osd_get_joy_list(). |
| 263 |
*/ |
| 264 |
int osd_is_joy_pressed(int joycode); |
| 265 |
|
| 266 |
|
| 267 |
/* We support 4 players for each analog control / trackball */ |
| 268 |
#define OSD_MAX_JOY_ANALOG 4 |
| 269 |
#define X_AXIS 1 |
| 270 |
#define Y_AXIS 2 |
| 271 |
|
| 272 |
#ifdef MAME32JP |
| 273 |
void osd_joystick_get_device_numbers(int *buf); |
| 274 |
void osd_joystick_set_device_numbers(int *buf); |
| 275 |
const char *osd_joystick_get_device_name(int number); |
| 276 |
#else |
| 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 |
#endif |
| 290 |
|
| 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_x, int *analog_y); |
| 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 dependant 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 |
File I/O |
| 312 |
|
| 313 |
******************************************************************************/ |
| 314 |
|
| 315 |
/* inp header */ |
| 316 |
typedef struct |
| 317 |
{ |
| 318 |
char name[9]; /* 8 bytes for game->name + NUL */ |
| 319 |
char version[3]; /* byte[0] = 0, byte[1] = version byte[2] = beta_version */ |
| 320 |
char reserved[20]; /* for future use, possible store game options? */ |
| 321 |
} INP_HEADER; |
| 322 |
|
| 323 |
|
| 324 |
/* file handling routines */ |
| 325 |
enum |
| 326 |
{ |
| 327 |
OSD_FILETYPE_ROM = 1, |
| 328 |
OSD_FILETYPE_ROM_NOCRC, |
| 329 |
OSD_FILETYPE_IMAGE_R, |
| 330 |
OSD_FILETYPE_IMAGE_RW, |
| 331 |
OSD_FILETYPE_IMAGE_DIFF, |
| 332 |
OSD_FILETYPE_SAMPLE, |
| 333 |
OSD_FILETYPE_ARTWORK, |
| 334 |
OSD_FILETYPE_NVRAM, |
| 335 |
OSD_FILETYPE_HIGHSCORE, |
| 336 |
OSD_FILETYPE_HIGHSCORE_DB, |
| 337 |
OSD_FILETYPE_CONFIG, |
| 338 |
OSD_FILETYPE_INPUTLOG, |
| 339 |
OSD_FILETYPE_STATE, |
| 340 |
OSD_FILETYPE_MEMCARD, |
| 341 |
OSD_FILETYPE_SCREENSHOT, |
| 342 |
OSD_FILETYPE_HISTORY, |
| 343 |
OSD_FILETYPE_CHEAT, |
| 344 |
OSD_FILETYPE_LANGUAGE, |
| 345 |
OSD_FILETYPE_CTRLR, |
| 346 |
#ifdef MAME32JP |
| 347 |
OSD_FILETYPE_WAVE, |
| 348 |
#endif |
| 349 |
OSD_FILETYPE_end /* dummy last entry */ |
| 350 |
}; |
| 351 |
|
| 352 |
/* gamename holds the driver name, filename is only used for ROMs and */ |
| 353 |
/* samples. If 'write' is not 0, the file is opened for write. Otherwise */ |
| 354 |
/* it is opened for read. */ |
| 355 |
|
| 356 |
int osd_faccess(const char *filename, int filetype); |
| 357 |
void *osd_fopen(const char *gamename,const char *filename,int filetype,int read_or_write); |
| 358 |
int osd_fread(void *file,void *buffer,int length); |
| 359 |
int osd_fwrite(void *file,const void *buffer,int length); |
| 360 |
int osd_fread_swap(void *file,void *buffer,int length); |
| 361 |
int osd_fwrite_swap(void *file,const void *buffer,int length); |
| 362 |
#ifdef LSB_FIRST |
| 363 |
#define osd_fread_msbfirst osd_fread_swap |
| 364 |
#define osd_fwrite_msbfirst osd_fwrite_swap |
| 365 |
#define osd_fread_lsbfirst osd_fread |
| 366 |
#define osd_fwrite_lsbfirst osd_fwrite |
| 367 |
#else |
| 368 |
#define osd_fread_msbfirst osd_fread |
| 369 |
#define osd_fwrite_msbfirst osd_fwrite |
| 370 |
#define osd_fread_lsbfirst osd_fread_swap |
| 371 |
#define osd_fwrite_lsbfirst osd_fwrite_swap |
| 372 |
#endif |
| 373 |
int osd_fseek(void *file,int offset,int whence); |
| 374 |
void osd_fclose(void *file); |
| 375 |
int osd_fchecksum(const char *gamename, const char *filename, unsigned int *length, unsigned int *sum); |
| 376 |
int osd_fsize(void *file); |
| 377 |
unsigned int osd_fcrc(void *file); |
| 378 |
/* LBO 040400 - start */ |
| 379 |
int osd_fgetc(void *file); |
| 380 |
int osd_ungetc(int c, void *file); |
| 381 |
char *osd_fgets(char *s, int n, void *file); |
| 382 |
int osd_feof(void *file); |
| 383 |
int osd_ftell(void *file); |
| 384 |
/* LBO 040400 - end */ |
| 385 |
/* strip directory part from a filename, does _not_ malloc */ |
| 386 |
char *osd_basename(char *filename); |
| 387 |
/* get directory part of a filename in malloced buffer */ |
| 388 |
char *osd_dirname(char *filename); |
| 389 |
/* strip extension from a filename, copy to malloced buffer */ |
| 390 |
char *osd_strip_extension(char *filename); |
| 391 |
|
| 392 |
/****************************************************************************** |
| 393 |
|
| 394 |
Miscellaneous |
| 395 |
|
| 396 |
******************************************************************************/ |
| 397 |
|
| 398 |
/* called while loading ROMs. It is called a last time with name == 0 to signal */ |
| 399 |
/* that the ROM loading process is finished. */ |
| 400 |
/* return non-zero to abort loading */ |
| 401 |
int osd_display_loading_rom_message(const char *name,int current,int total); |
| 402 |
|
| 403 |
/* called when the game is paused/unpaused, so the OS dependant code can do special */ |
| 404 |
/* things like changing the title bar or darkening the display. */ |
| 405 |
/* Note that the OS dependant code must NOT stop processing input, since the user */ |
| 406 |
/* interface is still active while the game is paused. */ |
| 407 |
void osd_pause(int paused); |
| 408 |
|
| 409 |
#ifdef MAME32JP |
| 410 |
int osd_quit_window(void); |
| 411 |
#endif |
| 412 |
|
| 413 |
|
| 414 |
#ifdef MAME_NET |
| 415 |
/* network */ |
| 416 |
int osd_net_init(void); |
| 417 |
int osd_net_send(int player, unsigned char buf[], int *size); |
| 418 |
int osd_net_recv(int player, unsigned char buf[], int *size); |
| 419 |
int osd_net_sync(void); |
| 420 |
int osd_net_input_sync(void); |
| 421 |
int osd_net_exit(void); |
| 422 |
int osd_net_add_player(void); |
| 423 |
int osd_net_remove_player(int player); |
| 424 |
int osd_net_game_init(void); |
| 425 |
int osd_net_game_exit(void); |
| 426 |
#endif /* MAME_NET */ |
| 427 |
|
| 428 |
#ifdef MESS |
| 429 |
/* this is here to follow the current mame file hierachi style */ |
| 430 |
#include "osd_dir.h" |
| 431 |
#endif |
| 432 |
|
| 433 |
void CLIB_DECL logerror(const char *text,...); |
| 434 |
|
| 435 |
#ifdef __cplusplus |
| 436 |
} |
| 437 |
#endif |
| 438 |
|
| 439 |
#endif |