src/osd/sdl/drawogl.c
| r3841 | r3842 | |
| 22 | 22 | #include "render.h" |
| 23 | 23 | #include "options.h" |
| 24 | 24 | #include "driver.h" |
| 25 | | #include "deprecat.h" |
| 26 | 25 | |
| 27 | 26 | // standard SDL headers |
| 28 | 27 | #include <SDL/SDL.h> |
| r3841 | r3842 | |
| 245 | 244 | } |
| 246 | 245 | } |
| 247 | 246 | |
| 248 | | INLINE UINT32 ycc_to_rgb(UINT8 y, UINT8 cb, UINT8 cr) |
| 249 | | { |
| 250 | | /* original equations: |
| 251 | | |
| 252 | | C = Y - 16 |
| 253 | | D = Cb - 128 |
| 254 | | E = Cr - 128 |
| 255 | | |
| 256 | | R = clip(( 298 * C + 409 * E + 128) >> 8) |
| 257 | | G = clip(( 298 * C - 100 * D - 208 * E + 128) >> 8) |
| 258 | | B = clip(( 298 * C + 516 * D + 128) >> 8) |
| 259 | | |
| 260 | | R = clip(( 298 * (Y - 16) + 409 * (Cr - 128) + 128) >> 8) |
| 261 | | G = clip(( 298 * (Y - 16) - 100 * (Cb - 128) - 208 * (Cr - 128) + 128) >> 8) |
| 262 | | B = clip(( 298 * (Y - 16) + 516 * (Cb - 128) + 128) >> 8) |
| 263 | | |
| 264 | | R = clip(( 298 * Y - 298 * 16 + 409 * Cr - 409 * 128 + 128) >> 8) |
| 265 | | G = clip(( 298 * Y - 298 * 16 - 100 * Cb + 100 * 128 - 208 * Cr + 208 * 128 + 128) >> 8) |
| 266 | | B = clip(( 298 * Y - 298 * 16 + 516 * Cb - 516 * 128 + 128) >> 8) |
| 267 | | |
| 268 | | R = clip(( 298 * Y - 298 * 16 + 409 * Cr - 409 * 128 + 128) >> 8) |
| 269 | | G = clip(( 298 * Y - 298 * 16 - 100 * Cb + 100 * 128 - 208 * Cr + 208 * 128 + 128) >> 8) |
| 270 | | B = clip(( 298 * Y - 298 * 16 + 516 * Cb - 516 * 128 + 128) >> 8) |
| 271 | | */ |
| 272 | | //int r, g, b, common; |
| 273 | | unsigned int r, g, b, common; |
| 274 | | |
| 275 | | common = 298 * y - 56992; |
| 276 | | r = (common + 409 * cr); |
| 277 | | g = (common - 100 * cb - 208 * cr + 91776); |
| 278 | | b = (common + 516 * cb - 13696); |
| 279 | | |
| 280 | | if ((int) r < 0) r = 0; |
| 281 | | if ((int) g < 0) g = 0; |
| 282 | | if ((int) b < 0) b = 0; |
| 283 | | |
| 284 | | /* MAME_RGB does upper clamping */ |
| 285 | | |
| 286 | | return MAKE_RGB(r >> 8, g >> 8, b >> 8); |
| 287 | | } |
| 288 | | |
| 289 | | |
| 290 | 247 | //============================================================ |
| 291 | 248 | // PROTOTYPES |
| 292 | 249 | //============================================================ |
| r3841 | r3842 | |
| 374 | 331 | //============================================================ |
| 375 | 332 | |
| 376 | 333 | static void texture_set_data(texture_info *texture, const render_texinfo *texsource); |
| 377 | | static texture_info *texture_create(sdl_info *sdl, sdl_window_info *window, const render_texinfo *texsource, UINT32 flags); |
| 334 | static texture_info *texture_create(sdl_window_info *window, const render_texinfo *texsource, UINT32 flags); |
| 378 | 335 | static texture_info *texture_find(sdl_info *sdl, const render_primitive *prim); |
| 379 | | static texture_info * texture_update(sdl_info *sdl, sdl_window_info *window, const render_primitive *prim, int shaderIdx); |
| 336 | static texture_info * texture_update(sdl_window_info *window, const render_primitive *prim, int shaderIdx); |
| 380 | 337 | static void texture_all_disable(sdl_info *sdl); |
| 381 | 338 | static void texture_disable(sdl_info *sdl, texture_info * texture); |
| 382 | 339 | |
| r3841 | r3842 | |
| 540 | 497 | |
| 541 | 498 | sdl->gl_context_id = SDL_GL_CreateContext(window->window_id); |
| 542 | 499 | |
| 500 | SDL_GL_SetSwapInterval(options_get_bool(mame_options(), SDLOPTION_WAITVSYNC) ? 2 : 0); |
| 501 | |
| 543 | 502 | #else |
| 544 | 503 | sdl->extra_flags = (window->fullscreen ? SDL_FULLSCREEN : SDL_RESIZABLE); |
| 545 | 504 | sdl->extra_flags |= SDL_OPENGL | SDL_DOUBLEBUF; |
| r3841 | r3842 | |
| 1321 | 1280 | |
| 1322 | 1281 | set_blendmode(sdl, PRIMFLAG_GET_BLENDMODE(prim->flags)); |
| 1323 | 1282 | |
| 1324 | | texture = texture_update(sdl, window, prim, 0); |
| 1283 | texture = texture_update(window, prim, 0); |
| 1325 | 1284 | |
| 1326 | 1285 | if ( texture && texture->type==TEXTURE_TYPE_SHADER ) |
| 1327 | 1286 | { |
| r3841 | r3842 | |
| 1352 | 1311 | |
| 1353 | 1312 | if(i>0) // first fetch already done |
| 1354 | 1313 | { |
| 1355 | | texture = texture_update(sdl, window, prim, i); |
| 1314 | texture = texture_update(window, prim, i); |
| 1356 | 1315 | } |
| 1357 | 1316 | glDrawArrays(GL_QUADS, 0, 4); |
| 1358 | 1317 | } |
| r3841 | r3842 | |
| 1897 | 1856 | return 0; |
| 1898 | 1857 | } |
| 1899 | 1858 | |
| 1900 | | static int texture_shader_create(sdl_info *sdl, sdl_window_info *window, |
| 1859 | static int texture_shader_create(sdl_window_info *window, |
| 1901 | 1860 | const render_texinfo *texsource, texture_info *texture, UINT32 flags) |
| 1902 | 1861 | { |
| 1862 | sdl_info *sdl = window->dxdata; |
| 1903 | 1863 | int uniform_location; |
| 1904 | 1864 | int lut_table_width_pow2=0; |
| 1905 | 1865 | int lut_table_height_pow2=0; |
| r3841 | r3842 | |
| 2258 | 2218 | return 0; |
| 2259 | 2219 | } |
| 2260 | 2220 | |
| 2261 | | static texture_info *texture_create(sdl_info *sdl, sdl_window_info *window, const render_texinfo *texsource, UINT32 flags) |
| 2221 | static texture_info *texture_create(sdl_window_info *window, const render_texinfo *texsource, UINT32 flags) |
| 2262 | 2222 | { |
| 2223 | sdl_info *sdl = window->dxdata; |
| 2263 | 2224 | texture_info *texture; |
| 2264 | 2225 | |
| 2265 | 2226 | // allocate a new texture |
| r3841 | r3842 | |
| 2344 | 2305 | |
| 2345 | 2306 | if ( texture->type==TEXTURE_TYPE_SHADER ) |
| 2346 | 2307 | { |
| 2347 | | if ( texture_shader_create(sdl, window, texsource, texture, flags) ) |
| 2308 | if ( texture_shader_create(window, texsource, texture, flags) ) |
| 2348 | 2309 | { |
| 2349 | 2310 | free(texture); |
| 2350 | 2311 | return NULL; |
| r3841 | r3842 | |
| 2577 | 2538 | // texture_update |
| 2578 | 2539 | //============================================================ |
| 2579 | 2540 | |
| 2580 | | static void texture_coord_update(sdl_info *sdl, sdl_window_info *window, |
| 2541 | static void texture_coord_update(sdl_window_info *window, |
| 2581 | 2542 | texture_info *texture, const render_primitive *prim, int shaderIdx) |
| 2582 | 2543 | { |
| 2544 | sdl_info *sdl = window->dxdata; |
| 2583 | 2545 | float ustart, ustop; // beginning/ending U coordinates |
| 2584 | 2546 | float vstart, vstop; // beginning/ending V coordinates |
| 2585 | 2547 | float du, dv; |
| r3841 | r3842 | |
| 2729 | 2691 | } |
| 2730 | 2692 | } |
| 2731 | 2693 | |
| 2732 | | static void texture_shader_update(sdl_info *sdl, sdl_window_info *window, texture_info *texture, int shaderIdx) |
| 2694 | static void texture_shader_update(sdl_window_info *window, texture_info *texture, int shaderIdx) |
| 2733 | 2695 | { |
| 2696 | sdl_info *sdl = window->dxdata; |
| 2734 | 2697 | if ( !texture->lut_texture ) |
| 2735 | 2698 | { |
| 2736 | 2699 | int uniform_location, scrnum; |
| r3841 | r3842 | |
| 2742 | 2705 | |
| 2743 | 2706 | scrnum = 0; |
| 2744 | 2707 | container = (render_container *)NULL; |
| 2745 | | for (screen = video_screen_first(Machine->config); screen != NULL; screen = video_screen_next(screen)) |
| 2708 | for (screen = video_screen_first(window->machine->config); screen != NULL; screen = video_screen_next(screen)) |
| 2746 | 2709 | { |
| 2747 | 2710 | if (scrnum == window->start_viewscreen) |
| 2748 | 2711 | { |
| r3841 | r3842 | |
| 2780 | 2743 | } |
| 2781 | 2744 | } |
| 2782 | 2745 | |
| 2783 | | static texture_info * texture_update(sdl_info *sdl, sdl_window_info *window, const render_primitive *prim, int shaderIdx) |
| 2746 | static texture_info * texture_update(sdl_window_info *window, const render_primitive *prim, int shaderIdx) |
| 2784 | 2747 | { |
| 2748 | sdl_info *sdl = window->dxdata; |
| 2785 | 2749 | texture_info *texture = texture_find(sdl, prim); |
| 2786 | 2750 | int texBound = 0; |
| 2787 | 2751 | |
| 2788 | 2752 | // if we didn't find one, create a new texture |
| 2789 | 2753 | if (texture == NULL && prim->texture.base != NULL) |
| 2790 | 2754 | { |
| 2791 | | texture = texture_create(sdl, window, &prim->texture, prim->flags); |
| 2755 | texture = texture_create(window, &prim->texture, prim->flags); |
| 2792 | 2756 | |
| 2793 | 2757 | } |
| 2794 | 2758 | else if (texture != NULL) |
| r3841 | r3842 | |
| 2813 | 2777 | { |
| 2814 | 2778 | if ( texture->type == TEXTURE_TYPE_SHADER ) |
| 2815 | 2779 | { |
| 2816 | | texture_shader_update(sdl, window, texture, shaderIdx); |
| 2780 | texture_shader_update(window, texture, shaderIdx); |
| 2817 | 2781 | if ( sdl->glsl_program_num>1 ) |
| 2818 | 2782 | { |
| 2819 | 2783 | texture_mpass_flip(sdl, texture, shaderIdx); |
| r3841 | r3842 | |
| 2835 | 2799 | if (!texBound) { |
| 2836 | 2800 | glBindTexture(texture->texTarget, texture->texture); |
| 2837 | 2801 | } |
| 2838 | | texture_coord_update(sdl, window, texture, prim, shaderIdx); |
| 2802 | texture_coord_update(window, texture, prim, shaderIdx); |
| 2839 | 2803 | |
| 2840 | 2804 | glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
| 2841 | 2805 | if(sdl->usevbo) |
src/osd/sdl/input.c
| r3841 | r3842 | |
| 46 | 46 | POVDIR_DOWN |
| 47 | 47 | }; |
| 48 | 48 | |
| 49 | | // introduced in 1.3 |
| 50 | | |
| 51 | | #ifndef SDLK_INDEX |
| 52 | | #define SDLK_INDEX(x) (x) |
| 53 | | #endif |
| 54 | | |
| 55 | 49 | #define MAX_KEYS 256 |
| 56 | 50 | #define MAX_AXES 8 |
| 57 | 51 | #define MAX_BUTTONS 32 |
| 58 | 52 | #define MAX_HATS 8 |
| 59 | 53 | #define MAX_POV 4 |
| 60 | | #define MAX_JOYSTICKS 16 |
| 54 | #define MAX_DEVMAP_ENTRIES 16 |
| 61 | 55 | |
| 62 | 56 | //============================================================ |
| 63 | 57 | // MACROS |
| 64 | 58 | //============================================================ |
| 65 | 59 | |
| 60 | // introduced in 1.3 |
| 66 | 61 | |
| 62 | #ifndef SDLK_INDEX |
| 63 | #define SDLK_INDEX(x) (x) |
| 64 | #endif |
| 65 | |
| 66 | |
| 67 | 67 | //============================================================ |
| 68 | 68 | // TYPEDEFS |
| 69 | 69 | //============================================================ |
| r3841 | r3842 | |
| 118 | 118 | }; |
| 119 | 119 | }; |
| 120 | 120 | |
| 121 | |
| 121 | 122 | //============================================================ |
| 122 | 123 | // LOCAL VARIABLES |
| 123 | 124 | //============================================================ |
| r3841 | r3842 | |
| 151 | 152 | static device_info * joystick_list; |
| 152 | 153 | |
| 153 | 154 | // joystick mapper |
| 154 | | static struct |
| 155 | |
| 156 | typedef struct _device_map_t device_map_t; |
| 157 | struct _device_map_t |
| 155 | 158 | { |
| 156 | | char *name; |
| 157 | | int physical; |
| 158 | | } joy_map[MAX_JOYSTICKS]; |
| 159 | struct { |
| 160 | char *name; |
| 161 | int physical; |
| 162 | } map[MAX_DEVMAP_ENTRIES]; |
| 163 | int logical[MAX_DEVMAP_ENTRIES]; |
| 164 | int initialized; |
| 165 | }; |
| 159 | 166 | |
| 160 | | static int joy_logical[MAX_JOYSTICKS]; |
| 167 | static device_map_t joy_map; |
| 168 | static device_map_t mouse_map; |
| 169 | static device_map_t keyboard_map; |
| 161 | 170 | |
| 162 | 171 | static int sixaxis_mode; |
| 163 | 172 | |
| 173 | |
| 164 | 174 | //============================================================ |
| 165 | 175 | // PROTOTYPES |
| 166 | 176 | //============================================================ |
| r3841 | r3842 | |
| 181 | 191 | static INT32 generic_axis_get_state(void *device_internal, void *item_internal); |
| 182 | 192 | static device_info *generic_device_find_index(device_info *devlist_head, int index); |
| 183 | 193 | |
| 194 | |
| 184 | 195 | //============================================================ |
| 185 | 196 | // KEYBOARD/JOYSTICK LIST |
| 186 | 197 | //============================================================ |
| r3841 | r3842 | |
| 200 | 211 | |
| 201 | 212 | #define OSD_SDL_INDEX(x) (x) |
| 202 | 213 | #define OSD_SDL_INDEX_KEYSYM(keysym) ((keysym)->scancode) |
| 214 | |
| 203 | 215 | #define GET_WINDOW(ev) window_from_id((ev)->windowID) |
| 216 | // FIXME: sdl does not properly report the window for certain ops. |
| 217 | #define GET_FOCUS_WINDOW(ev) focus_window |
| 218 | //#define GET_FOCUS_WINDOW(ev) window_from_id((ev)->windowID) |
| 204 | 219 | |
| 220 | |
| 205 | 221 | #define KTT_ENTRY0(MAME, SDL, VK, AS, UI) { ITEM_ID_ ## MAME, SDL_SCANCODE_ ## SDL, "ITEM_ID_" #MAME, (char *) UI } |
| 206 | 222 | #define KTT_ENTRY1(MAME, SDL) KTT_ENTRY0(MAME, SDL, MAME, MAME, #MAME) |
| 207 | 223 | // only for reference ... |
| r3841 | r3842 | |
| 325 | 341 | #define OSD_SDL_INDEX(x) (SDLK_INDEX(x)-SDLK_FIRST) |
| 326 | 342 | #define OSD_SDL_INDEX_KEYSYM(keysym) (OSD_SDL_INDEX((keysym)->sym)) |
| 327 | 343 | #define GET_WINDOW(ev) sdl_window_list |
| 344 | #define GET_FOCUS_WINDOW(ev) sdl_window_list |
| 328 | 345 | |
| 329 | 346 | #define KTT_ENTRY0(MAME, SDL, VK, AS, UI) { ITEM_ID_ ## MAME, SDLK_ ## SDL, "ITEM_ID_" #MAME, (char *) UI } |
| 330 | 347 | #define KTT_ENTRY1(MAME, SDL) KTT_ENTRY0(MAME, SDL, MAME, MAME, #MAME) |
| r3841 | r3842 | |
| 446 | 463 | }; |
| 447 | 464 | #endif |
| 448 | 465 | |
| 449 | | |
| 450 | 466 | typedef struct _key_lookup_table key_lookup_table; |
| 451 | | |
| 452 | 467 | struct _key_lookup_table |
| 453 | 468 | { |
| 454 | 469 | int code; |
| r3841 | r3842 | |
| 526 | 541 | }; |
| 527 | 542 | #endif |
| 528 | 543 | |
| 544 | |
| 529 | 545 | //============================================================ |
| 530 | 546 | // INLINE FUNCTIONS |
| 531 | 547 | //============================================================ |
| 532 | 548 | |
| 533 | | static int joy_map_leastfree(void) |
| 549 | static int devmap_leastfree(device_map_t *devmap) |
| 534 | 550 | { |
| 535 | 551 | int i; |
| 536 | | for (i=0;i<MAX_JOYSTICKS;i++) |
| 552 | for (i=0;i<MAX_DEVMAP_ENTRIES;i++) |
| 537 | 553 | { |
| 538 | | if (*joy_map[i].name == 0) |
| 554 | if (*devmap->map[i].name == 0) |
| 539 | 555 | return i; |
| 540 | 556 | } |
| 541 | 557 | return -1; |
| r3841 | r3842 | |
| 574 | 590 | return r; |
| 575 | 591 | } |
| 576 | 592 | |
| 593 | static void devmap_register(device_map_t *devmap, int physical_idx, char *name) |
| 594 | { |
| 595 | int found = 0; |
| 596 | int stick, i; |
| 597 | |
| 598 | for (i=0;i<MAX_DEVMAP_ENTRIES;i++) |
| 599 | { |
| 600 | if (strcmp(name,devmap->map[i].name) == 0 && devmap->map[i].physical < 0) |
| 601 | { |
| 602 | devmap->map[i].physical = physical_idx; |
| 603 | found = 1; |
| 604 | devmap->logical[physical_idx] = i; |
| 605 | } |
| 606 | } |
| 607 | if (found == 0) |
| 608 | { |
| 609 | stick = devmap_leastfree(devmap); |
| 610 | devmap->map[stick].physical = physical_idx; |
| 611 | devmap->map[stick].name = name; |
| 612 | devmap->logical[physical_idx] = stick; |
| 613 | } |
| 614 | |
| 615 | } |
| 616 | |
| 577 | 617 | //============================================================ |
| 578 | 618 | // init_joymap |
| 579 | 619 | //============================================================ |
| 580 | 620 | |
| 581 | | static void init_joymap(void) |
| 621 | static void devmap_init(device_map_t *devmap, const char *opt, int max_devices, const char *label) |
| 582 | 622 | { |
| 583 | | int stick; |
| 584 | | |
| 585 | | for (stick=0; stick < MAX_JOYSTICKS; stick++) |
| 623 | int dev; |
| 624 | char defname[20]; |
| 625 | |
| 626 | assert(max_devices <= MAX_DEVMAP_ENTRIES); |
| 627 | |
| 628 | for (dev = 0; dev < MAX_DEVMAP_ENTRIES; dev++) |
| 586 | 629 | { |
| 587 | | joy_map[stick].name = (char *)""; |
| 588 | | joy_map[stick].physical = -1; |
| 589 | | joy_logical[stick] = -1; |
| 630 | devmap->map[dev].name = (char *)""; |
| 631 | devmap->map[dev].physical = -1; |
| 632 | devmap->logical[dev] = -1; |
| 590 | 633 | } |
| 591 | | |
| 592 | | if (options_get_bool(mame_options(), SDLOPTION_JOYMAP)) |
| 634 | devmap->initialized = 0; |
| 635 | |
| 636 | for (dev = 0; dev < max_devices; dev++) |
| 593 | 637 | { |
| 594 | | FILE *joymap_file; |
| 595 | | int line = 1; |
| 596 | | char *joymap_filename; |
| 597 | | |
| 598 | | joymap_filename = (char *)options_get_string(mame_options(), SDLOPTION_JOYMAP_FILE); |
| 599 | | mame_printf_verbose("Joymap: Start reading joymap_file %s\n", joymap_filename); |
| 638 | const char *dev_name; |
| 639 | sprintf(defname, "%s%d", opt, dev + 1); |
| 600 | 640 | |
| 601 | | joymap_file = fopen(joymap_filename, "r"); |
| 602 | | |
| 603 | | if (joymap_file == NULL) |
| 641 | dev_name = options_get_string(mame_options(), defname); |
| 642 | if (dev_name && *dev_name && strcmp(dev_name,SDLOPTVAL_AUTO)) |
| 604 | 643 | { |
| 605 | | mame_printf_warning( "Joymap: Unable to open joymap %s - using default mapping\n", joymap_filename); |
| 644 | devmap->map[dev].name = remove_spaces(dev_name); |
| 645 | mame_printf_verbose("%s: Logical id %d: %s\n", label, dev + 1, joy_map.map[dev].name); |
| 646 | devmap->initialized = 1; |
| 606 | 647 | } |
| 607 | | else |
| 648 | } |
| 649 | } |
| 650 | |
| 651 | static device_info *devmap_class_register(running_machine *machine, device_map_t *devmap, |
| 652 | int index, device_info **devlist, input_device_class devclass) |
| 653 | { |
| 654 | device_info *devinfo = NULL; |
| 655 | char tempname[20]; |
| 656 | |
| 657 | if (*devmap->map[index].name == 0) |
| 658 | { |
| 659 | /* only map place holders if there were mappings specified is enabled */ |
| 660 | if (devmap->initialized) |
| 608 | 661 | { |
| 609 | | int i, logical; |
| 610 | | char buf[256]; |
| 611 | | char name[65]; |
| 612 | | |
| 613 | | while (!feof(joymap_file) && fgets(buf, 255, joymap_file)) |
| 614 | | { |
| 615 | | if (*buf && buf[0] && buf[0] != '#') |
| 616 | | { |
| 617 | | buf[255]=0; |
| 618 | | i=strlen(buf); |
| 619 | | if (i && buf[i-1] == '\n') |
| 620 | | buf[i-1] = 0; |
| 621 | | memset(name, 0, 65); |
| 622 | | logical = -1; |
| 623 | | sscanf(buf, "%x %64c\n", &logical, name); |
| 624 | | if ((logical >=0 ) && (logical < MAX_JOYSTICKS)) |
| 625 | | { |
| 626 | | joy_map[logical].name = remove_spaces(name); |
| 627 | | mame_printf_verbose("Joymap: Logical id %d: %s\n", logical, joy_map[logical].name); |
| 628 | | } |
| 629 | | else |
| 630 | | mame_printf_warning("Joymap: Error reading map: Line %d: %s\n", line, buf); |
| 631 | | } |
| 632 | | line++; |
| 633 | | } |
| 634 | | fclose(joymap_file); |
| 635 | | mame_printf_verbose("Joymap: Processed %d lines\n", line); |
| 662 | sprintf(tempname, "NC%d", index); |
| 663 | devinfo = generic_device_alloc(devlist, tempname); |
| 664 | devinfo->device = input_device_add(machine, devclass, devinfo->name, devinfo); |
| 636 | 665 | } |
| 666 | return NULL; |
| 637 | 667 | } |
| 668 | else |
| 669 | { |
| 670 | devinfo = generic_device_alloc(devlist, devmap->map[index].name); |
| 671 | devinfo->device = input_device_add(machine, devclass, devinfo->name, devinfo); |
| 672 | } |
| 673 | return devinfo; |
| 638 | 674 | } |
| 639 | 675 | |
| 676 | |
| 640 | 677 | //============================================================ |
| 641 | 678 | // sdlinput_register_joysticks |
| 642 | 679 | //============================================================ |
| r3841 | r3842 | |
| 644 | 681 | static void sdlinput_register_joysticks(running_machine *machine) |
| 645 | 682 | { |
| 646 | 683 | device_info *devinfo; |
| 647 | | int physical_stick, axis, button, hat, stick, i; |
| 684 | int physical_stick, axis, button, hat, stick; |
| 648 | 685 | char tempname[512]; |
| 649 | 686 | SDL_Joystick *joy; |
| 650 | 687 | |
| 651 | | init_joymap(); |
| 688 | devmap_init(&joy_map, SDLOPTION_JOYINDEX, 8, "Joystick mapping"); |
| 652 | 689 | |
| 653 | 690 | mame_printf_verbose("Joystick: Start initialization\n"); |
| 654 | 691 | for (physical_stick = 0; physical_stick < SDL_NumJoysticks(); physical_stick++) |
| 655 | 692 | { |
| 656 | 693 | char *joy_name = remove_spaces(SDL_JoystickName(physical_stick)); |
| 657 | | int found = 0; |
| 658 | 694 | |
| 659 | | for (i=0;i<MAX_JOYSTICKS;i++) |
| 660 | | { |
| 661 | | if (strcmp(joy_name,joy_map[i].name) == 0 && joy_map[i].physical < 0) |
| 662 | | { |
| 663 | | joy_map[i].physical = physical_stick; |
| 664 | | found = 1; |
| 665 | | joy_logical[physical_stick] = i; |
| 666 | | } |
| 667 | | } |
| 668 | | if (found == 0) |
| 669 | | { |
| 670 | | stick = joy_map_leastfree(); |
| 671 | | joy_map[stick].physical = physical_stick; |
| 672 | | joy_map[stick].name = joy_name; |
| 673 | | joy_logical[physical_stick] = stick; |
| 674 | | } |
| 695 | devmap_register(&joy_map, physical_stick, joy_name); |
| 675 | 696 | } |
| 676 | 697 | |
| 677 | | for (stick = 0; stick < MAX_JOYSTICKS; stick++) |
| 698 | for (stick = 0; stick < MAX_DEVMAP_ENTRIES; stick++) |
| 678 | 699 | { |
| 679 | | if (*joy_map[stick].name == 0) |
| 680 | | { |
| 681 | | devinfo = NULL; |
| 682 | | /* only map place holders if remapjoys is enabled */ |
| 683 | | if (options_get_bool(mame_options(), SDLOPTION_JOYMAP)) |
| 684 | | { |
| 685 | | sprintf(tempname, "NC%d", stick); |
| 686 | | devinfo = generic_device_alloc(&joystick_list, tempname); |
| 687 | | devinfo->device = input_device_add(machine, DEVICE_CLASS_JOYSTICK, devinfo->name, devinfo); |
| 688 | | } |
| 689 | | } |
| 690 | | else |
| 691 | | { |
| 692 | | devinfo = generic_device_alloc(&joystick_list, joy_map[stick].name); |
| 693 | | devinfo->device = input_device_add(machine, DEVICE_CLASS_JOYSTICK, devinfo->name, devinfo); |
| 694 | | } |
| 695 | | |
| 700 | devinfo = devmap_class_register(machine, &joy_map, stick, &joystick_list, DEVICE_CLASS_JOYSTICK); |
| 696 | 701 | |
| 697 | | physical_stick = joy_map[stick].physical; |
| 698 | | |
| 699 | | if (physical_stick < 0) |
| 702 | if (devinfo == NULL) |
| 700 | 703 | continue; |
| 701 | 704 | |
| 702 | | // loop over all axes |
| 705 | physical_stick = joy_map.map[stick].physical; |
| 706 | |
| 703 | 707 | joy = SDL_JoystickOpen(physical_stick); |
| 704 | 708 | |
| 705 | 709 | devinfo->joystick.device = joy; |
| r3841 | r3842 | |
| 765 | 769 | } |
| 766 | 770 | |
| 767 | 771 | //============================================================ |
| 772 | // sdlinput_register_joysticks |
| 773 | //============================================================ |
| 774 | |
| 775 | #if (SDL_VERSION_ATLEAST(1,3,0)) |
| 776 | static void sdlinput_register_mice(running_machine *machine) |
| 777 | { |
| 778 | int index, physical_mouse; |
| 779 | |
| 780 | mouse_enabled = options_get_bool(mame_options(), OPTION_MOUSE); |
| 781 | |
| 782 | devmap_init(&mouse_map, SDLOPTION_MOUSEINDEX, 8, "Mouse mapping"); |
| 783 | |
| 784 | for (physical_mouse = 0; physical_mouse < SDL_GetNumMice(); physical_mouse++) |
| 785 | { |
| 786 | char *mouse_name = remove_spaces(SDL_GetMouseName(physical_mouse)); |
| 787 | |
| 788 | devmap_register(&mouse_map, physical_mouse, mouse_name); |
| 789 | } |
| 790 | |
| 791 | mame_printf_verbose("Mouse: Start initialization\n"); |
| 792 | for (index = 0; index < MAX_DEVMAP_ENTRIES; index++) |
| 793 | { |
| 794 | device_info *devinfo; |
| 795 | char defname[90]; |
| 796 | int button; |
| 797 | |
| 798 | devinfo = devmap_class_register(machine, &mouse_map, index, &mouse_list, DEVICE_CLASS_MOUSE); |
| 799 | |
| 800 | if (devinfo == NULL) |
| 801 | continue; |
| 802 | |
| 803 | // add the axes |
| 804 | sprintf(defname, "X %s", devinfo->name); |
| 805 | input_device_item_add(devinfo->device, defname, &devinfo->mouse.lX, ITEM_ID_XAXIS, generic_axis_get_state); |
| 806 | sprintf(defname, "Y %s", devinfo->name); |
| 807 | input_device_item_add(devinfo->device, defname, &devinfo->mouse.lY, ITEM_ID_YAXIS, generic_axis_get_state); |
| 808 | |
| 809 | for (button = 0; button < 4; button++) |
| 810 | { |
| 811 | sprintf(defname, "B%d", button + 1); |
| 812 | |
| 813 | input_device_item_add(devinfo->device, defname, &devinfo->mouse.buttons[button], ITEM_ID_BUTTON1+button, generic_button_get_state); |
| 814 | } |
| 815 | |
| 816 | if (0 && mouse_enabled) |
| 817 | SDL_SetRelativeMouseMode(index, 1); |
| 818 | mame_printf_verbose("Mouse: Registered %s\n", devinfo->name); |
| 819 | } |
| 820 | mame_printf_verbose("Mouse: End initialization\n"); |
| 821 | } |
| 822 | #else |
| 823 | static void sdlinput_register_mice(running_machine *machine) |
| 824 | { |
| 825 | device_info *devinfo; |
| 826 | char defname[20]; |
| 827 | int button; |
| 828 | |
| 829 | mame_printf_verbose("Mouse: Start initialization\n"); |
| 830 | |
| 831 | mouse_map.logical[0] = 0; |
| 832 | |
| 833 | // SDL 1.2 has only 1 mouse - 1.3+ will also change that, so revisit this then |
| 834 | devinfo = generic_device_alloc(&mouse_list, "System mouse"); |
| 835 | devinfo->device = input_device_add(machine, DEVICE_CLASS_MOUSE, devinfo->name, devinfo); |
| 836 | |
| 837 | mouse_enabled = options_get_bool(mame_options(), OPTION_MOUSE); |
| 838 | |
| 839 | // add the axes |
| 840 | input_device_item_add(devinfo->device, "X", &devinfo->mouse.lX, ITEM_ID_XAXIS, generic_axis_get_state); |
| 841 | input_device_item_add(devinfo->device, "Y", &devinfo->mouse.lY, ITEM_ID_YAXIS, generic_axis_get_state); |
| 842 | |
| 843 | for (button = 0; button < 4; button++) |
| 844 | { |
| 845 | sprintf(defname, "B%d", button + 1); |
| 846 | |
| 847 | input_device_item_add(devinfo->device, defname, &devinfo->mouse.buttons[button], ITEM_ID_BUTTON1+button, generic_button_get_state); |
| 848 | } |
| 849 | |
| 850 | mame_printf_verbose("Mouse: Registered %s\n", devinfo->name); |
| 851 | mame_printf_verbose("Mouse: End initialization\n"); |
| 852 | } |
| 853 | #endif |
| 854 | |
| 855 | |
| 856 | //============================================================ |
| 768 | 857 | // lookup_sdl_code |
| 769 | 858 | //============================================================ |
| 770 | 859 | |
| r3841 | r3842 | |
| 781 | 870 | return -1; |
| 782 | 871 | } |
| 783 | 872 | |
| 873 | |
| 784 | 874 | //============================================================ |
| 785 | 875 | // lookup_mame_code |
| 786 | 876 | //============================================================ |
| r3841 | r3842 | |
| 815 | 905 | } |
| 816 | 906 | #endif |
| 817 | 907 | |
| 908 | |
| 818 | 909 | //============================================================ |
| 819 | 910 | // sdlinput_read_keymap |
| 820 | 911 | //============================================================ |
| 821 | 912 | |
| 822 | | static kt_table * sdlinput_read_keymap(char *keymap_filename) |
| 913 | static kt_table * sdlinput_read_keymap(void) |
| 823 | 914 | { |
| 915 | char *keymap_filename; |
| 824 | 916 | kt_table *key_trans_table; |
| 825 | 917 | FILE *keymap_file; |
| 826 | 918 | int line = 1; |
| r3841 | r3842 | |
| 830 | 922 | char sks[21]; |
| 831 | 923 | char kns[21]; |
| 832 | 924 | |
| 925 | if (!options_get_bool(mame_options(), SDLOPTION_KEYMAP)) |
| 926 | return sdl_key_trans_table; |
| 927 | |
| 928 | keymap_filename = (char *)options_get_string(mame_options(), SDLOPTION_KEYMAP_FILE); |
| 833 | 929 | mame_printf_verbose("Keymap: Start reading keymap_file %s\n", keymap_filename); |
| 834 | 930 | |
| 835 | 931 | keymap_file = fopen(keymap_filename, "r"); |
| r3841 | r3842 | |
| 881 | 977 | return key_trans_table; |
| 882 | 978 | } |
| 883 | 979 | |
| 980 | |
| 884 | 981 | //============================================================ |
| 885 | | // sdlinput_init |
| 982 | // sdlinput_register_keyboards |
| 886 | 983 | //============================================================ |
| 887 | 984 | |
| 888 | | void sdlinput_init(running_machine *machine) |
| 985 | #if (SDL_VERSION_ATLEAST(1,3,0)) |
| 986 | static void sdlinput_register_keyboards(running_machine *machine) |
| 889 | 987 | { |
| 890 | | device_info *devinfo; |
| 891 | | int keynum, button; |
| 892 | | char defname[20]; |
| 988 | int physical_keyboard; |
| 989 | int index; |
| 893 | 990 | kt_table *key_trans_table; |
| 894 | 991 | |
| 895 | | keyboard_list = NULL; |
| 896 | | joystick_list = NULL; |
| 897 | | mouse_list = NULL; |
| 898 | | lightgun_list = NULL; |
| 899 | | |
| 900 | | app_has_mouse_focus = 1; |
| 992 | key_trans_table = sdlinput_read_keymap(); |
| 901 | 993 | |
| 902 | | // get Sixaxis special mode info |
| 903 | | sixaxis_mode = options_get_bool(mame_options(), SDLOPTION_SIXAXIS); |
| 994 | devmap_init(&keyboard_map, SDLOPTION_KEYBINDEX, 8, "Keyboard mapping"); |
| 904 | 995 | |
| 905 | | // we need pause and exit callbacks |
| 906 | | add_pause_callback(machine, sdlinput_pause); |
| 907 | | add_exit_callback(machine, sdlinput_exit); |
| 996 | for (physical_keyboard = 0; physical_keyboard < SDL_GetNumKeyboards(); physical_keyboard++) |
| 997 | { |
| 998 | char defname[90]; |
| 999 | snprintf(defname, sizeof(defname)-1, "Keyboard #%d", physical_keyboard + 1); |
| 1000 | |
| 1001 | devmap_register(&keyboard_map, physical_keyboard, defname); |
| 1002 | } |
| 908 | 1003 | |
| 909 | | if (options_get_bool(mame_options(), SDLOPTION_KEYMAP)) |
| 1004 | mame_printf_verbose("Keyboard: Start initialization\n"); |
| 1005 | for (index = 0; index < MAX_DEVMAP_ENTRIES; index++) |
| 910 | 1006 | { |
| 911 | | char *keymap_filename; |
| 1007 | device_info *devinfo; |
| 1008 | char defname[90]; |
| 1009 | int keynum; |
| 912 | 1010 | |
| 913 | | keymap_filename = (char *)options_get_string(mame_options(), SDLOPTION_KEYMAP_FILE); |
| 1011 | devinfo = devmap_class_register(machine, &keyboard_map, index, &keyboard_list, DEVICE_CLASS_KEYBOARD); |
| 914 | 1012 | |
| 915 | | key_trans_table = sdlinput_read_keymap(keymap_filename); |
| 1013 | if (devinfo == NULL) |
| 1014 | continue; |
| 1015 | |
| 1016 | // populate it |
| 1017 | for (keynum = 0; sdl_key_trans_table[keynum].mame_key >= 0; keynum++) |
| 1018 | { |
| 1019 | input_item_id itemid; |
| 1020 | |
| 1021 | itemid = key_trans_table[keynum].mame_key; |
| 1022 | |
| 1023 | // generate the default / modified name |
| 1024 | snprintf(defname, sizeof(defname)-1, "%s", key_trans_table[keynum].ui_name); |
| 1025 | |
| 1026 | // add the item to the device |
| 1027 | input_device_item_add(devinfo->device, defname, &devinfo->keyboard.state[OSD_SDL_INDEX(key_trans_table[keynum].sdl_key)], itemid, generic_button_get_state); |
| 1028 | } |
| 1029 | |
| 1030 | mame_printf_verbose("Keyboard: Registered %s\n", devinfo->name); |
| 916 | 1031 | } |
| 917 | | else |
| 918 | | { |
| 919 | | key_trans_table = sdl_key_trans_table; |
| 920 | | } |
| 1032 | mame_printf_verbose("Keyboard: End initialization\n"); |
| 1033 | } |
| 1034 | #else |
| 1035 | static void sdlinput_register_keyboards(running_machine *machine) |
| 1036 | { |
| 1037 | device_info *devinfo; |
| 1038 | char defname[20]; |
| 1039 | int keynum; |
| 1040 | kt_table *key_trans_table; |
| 921 | 1041 | |
| 922 | | // allocate a lock for input synchronizations |
| 923 | | input_lock = osd_lock_alloc(); |
| 924 | | assert_always(input_lock != NULL, "Failed to allocate input_lock"); |
| 1042 | key_trans_table = sdlinput_read_keymap(); |
| 925 | 1043 | |
| 1044 | keyboard_map.logical[0] = 0; |
| 1045 | |
| 1046 | mame_printf_verbose("Keyboard: Start initialization\n"); |
| 1047 | |
| 926 | 1048 | // SDL 1.2 only has 1 keyboard (1.3+ will have multiple, this must be revisited then) |
| 927 | 1049 | // add it now |
| 928 | 1050 | devinfo = generic_device_alloc(&keyboard_list, "System keyboard"); |
| r3841 | r3842 | |
| 943 | 1065 | input_device_item_add(devinfo->device, defname, &devinfo->keyboard.state[OSD_SDL_INDEX(key_trans_table[keynum].sdl_key)], itemid, generic_button_get_state); |
| 944 | 1066 | } |
| 945 | 1067 | |
| 946 | | // SDL 1.2 has only 1 mouse - 1.3+ will also change that, so revisit this then |
| 947 | | devinfo = generic_device_alloc(&mouse_list, "System mouse"); |
| 948 | | devinfo->device = input_device_add(machine, DEVICE_CLASS_MOUSE, devinfo->name, devinfo); |
| 1068 | mame_printf_verbose("Keyboard: Registered %s\n", devinfo->name); |
| 1069 | mame_printf_verbose("Keyboard: End initialization\n"); |
| 1070 | } |
| 1071 | #endif |
| 949 | 1072 | |
| 950 | | mouse_enabled = options_get_bool(mame_options(), OPTION_MOUSE); |
| 1073 | //============================================================ |
| 1074 | // sdlinput_init |
| 1075 | //============================================================ |
| 1076 | |
| 1077 | void sdlinput_init(running_machine *machine) |
| 1078 | { |
| 1079 | keyboard_list = NULL; |
| 1080 | joystick_list = NULL; |
| 1081 | mouse_list = NULL; |
| 1082 | lightgun_list = NULL; |
| 951 | 1083 | |
| 1084 | app_has_mouse_focus = 1; |
| 1085 | |
| 1086 | // we need pause and exit callbacks |
| 1087 | add_pause_callback(machine, sdlinput_pause); |
| 1088 | add_exit_callback(machine, sdlinput_exit); |
| 1089 | |
| 1090 | // allocate a lock for input synchronizations |
| 1091 | input_lock = osd_lock_alloc(); |
| 1092 | assert_always(input_lock != NULL, "Failed to allocate input_lock"); |
| 1093 | |
| 1094 | // register the keyboards |
| 1095 | sdlinput_register_keyboards(machine); |
| 1096 | |
| 1097 | // register the mice |
| 1098 | sdlinput_register_mice(machine); |
| 1099 | |
| 952 | 1100 | #ifdef MAME_DEBUG |
| 953 | 1101 | if (mouse_enabled) |
| 954 | 1102 | { |
| r3841 | r3842 | |
| 956 | 1104 | mouse_enabled = 0; |
| 957 | 1105 | } |
| 958 | 1106 | #endif |
| 1107 | // get Sixaxis special mode info |
| 1108 | sixaxis_mode = options_get_bool(mame_options(), SDLOPTION_SIXAXIS); |
| 959 | 1109 | |
| 960 | | // add the axes |
| 961 | | input_device_item_add(devinfo->device, "X", &devinfo->mouse.lX, ITEM_ID_XAXIS, generic_axis_get_state); |
| 962 | | input_device_item_add(devinfo->device, "Y", &devinfo->mouse.lY, ITEM_ID_YAXIS, generic_axis_get_state); |
| 963 | | |
| 964 | | for (button = 0; button < 4; button++) |
| 965 | | { |
| 966 | | sprintf(defname, "B%d", button + 1); |
| 967 | | |
| 968 | | input_device_item_add(devinfo->device, defname, &devinfo->mouse.buttons[button], ITEM_ID_BUTTON1+button, generic_button_get_state); |
| 969 | | } |
| 970 | | |
| 971 | 1110 | // register the joysticks |
| 972 | 1111 | sdlinput_register_joysticks(machine); |
| 973 | 1112 | |
| r3841 | r3842 | |
| 1018 | 1157 | return sdl_window_list; |
| 1019 | 1158 | } |
| 1020 | 1159 | |
| 1160 | |
| 1021 | 1161 | //============================================================ |
| 1022 | 1162 | // sdlinput_poll |
| 1023 | 1163 | //============================================================ |
| r3841 | r3842 | |
| 1029 | 1169 | |
| 1030 | 1170 | for (w = sdl_window_list; w != NULL; w = w->next) |
| 1031 | 1171 | { |
| 1172 | //printf("w->window_id: %d\n", w->window_id); |
| 1032 | 1173 | if (w->window_id == windowID) |
| 1033 | 1174 | { |
| 1034 | 1175 | return w; |
| r3841 | r3842 | |
| 1059 | 1200 | #endif |
| 1060 | 1201 | } |
| 1061 | 1202 | |
| 1203 | |
| 1062 | 1204 | void sdlinput_poll(running_machine *machine) |
| 1063 | 1205 | { |
| 1064 | 1206 | device_info *devinfo; |
| 1065 | 1207 | SDL_Event event; |
| 1208 | int index; |
| 1066 | 1209 | #if SDLMAME_EVENTS_IN_WORKER_THREAD |
| 1067 | 1210 | SDL_Event loc_event_buf[MAX_BUF_EVENTS]; |
| 1068 | 1211 | int loc_event_buf_count; |
| 1069 | 1212 | int bufp; |
| 1070 | 1213 | #endif |
| 1071 | 1214 | |
| 1072 | | devinfo = mouse_list; |
| 1073 | | devinfo->mouse.lX = 0; |
| 1074 | | devinfo->mouse.lY = 0; |
| 1215 | for (index=0; ;index++) |
| 1216 | { |
| 1217 | devinfo = generic_device_find_index( mouse_list, index); |
| 1218 | if (devinfo == NULL) |
| 1219 | break; |
| 1220 | devinfo->mouse.lX = 0; |
| 1221 | devinfo->mouse.lY = 0; |
| 1222 | } |
| 1075 | 1223 | |
| 1076 | 1224 | #if SDLMAME_EVENTS_IN_WORKER_THREAD |
| 1077 | 1225 | osd_lock_acquire(input_lock); |
| r3841 | r3842 | |
| 1094 | 1242 | } |
| 1095 | 1243 | switch(event.type) { |
| 1096 | 1244 | case SDL_KEYDOWN: |
| 1097 | | devinfo = keyboard_list; |
| 1245 | devinfo = generic_device_find_index( keyboard_list, keyboard_map.logical[event.key.which]); |
| 1246 | //printf("Key down %d %d %s\n", event.key.which, event.key.keysym.scancode, devinfo->name); |
| 1098 | 1247 | devinfo->keyboard.state[OSD_SDL_INDEX_KEYSYM(&event.key.keysym)] = 0x80; |
| 1099 | 1248 | #if (!SDL_VERSION_ATLEAST(1,3,0)) |
| 1100 | 1249 | ui_input_push_char_event(machine, sdl_window_list->target, (unicode_char) event.key.keysym.unicode); |
| 1101 | 1250 | #endif |
| 1102 | 1251 | break; |
| 1103 | 1252 | case SDL_KEYUP: |
| 1104 | | devinfo = keyboard_list; |
| 1253 | devinfo = generic_device_find_index( keyboard_list, keyboard_map.logical[event.key.which]); |
| 1105 | 1254 | devinfo->keyboard.state[OSD_SDL_INDEX_KEYSYM(&event.key.keysym)] = 0x00; |
| 1106 | 1255 | break; |
| 1107 | 1256 | case SDL_JOYAXISMOTION: |
| 1108 | | devinfo = generic_device_find_index(joystick_list, joy_logical[event.jaxis.which]); |
| 1257 | devinfo = generic_device_find_index(joystick_list, joy_map.logical[event.jaxis.which]); |
| 1109 | 1258 | if (devinfo) |
| 1110 | 1259 | { |
| 1111 | 1260 | if (sixaxis_mode) |
| r3841 | r3842 | |
| 1128 | 1277 | } |
| 1129 | 1278 | break; |
| 1130 | 1279 | case SDL_JOYHATMOTION: |
| 1131 | | devinfo = generic_device_find_index(joystick_list, joy_logical[event.jhat.which]); |
| 1280 | devinfo = generic_device_find_index(joystick_list, joy_map.logical[event.jhat.which]); |
| 1132 | 1281 | if (devinfo) |
| 1133 | 1282 | { |
| 1134 | 1283 | if (event.jhat.value & SDL_HAT_UP) |
| r3841 | r3842 | |
| 1167 | 1316 | break; |
| 1168 | 1317 | case SDL_JOYBUTTONDOWN: |
| 1169 | 1318 | case SDL_JOYBUTTONUP: |
| 1170 | | devinfo = generic_device_find_index(joystick_list, joy_logical[event.jbutton.which]); |
| 1319 | devinfo = generic_device_find_index(joystick_list, joy_map.logical[event.jbutton.which]); |
| 1171 | 1320 | if (devinfo) |
| 1172 | 1321 | { |
| 1173 | 1322 | devinfo->joystick.buttons[event.jbutton.button] = (event.jbutton.state == SDL_PRESSED) ? 0x80 : 0; |
| 1174 | 1323 | } |
| 1175 | 1324 | break; |
| 1176 | 1325 | case SDL_MOUSEBUTTONDOWN: |
| 1177 | | devinfo = mouse_list; |
| 1326 | devinfo = generic_device_find_index(mouse_list, mouse_map.logical[event.button.which]); |
| 1178 | 1327 | devinfo->mouse.buttons[event.button.button-1] = 0x80; |
| 1328 | //printf("But down %d %d %d %d %s\n", event.button.which, event.button.button, event.button.x, event.button.y, devinfo->name); |
| 1179 | 1329 | if (event.button.button == 1) |
| 1180 | 1330 | { |
| 1181 | 1331 | // FIXME Move static declaration |
| r3841 | r3842 | |
| 1184 | 1334 | static int last_y = 0; |
| 1185 | 1335 | int cx, cy; |
| 1186 | 1336 | osd_ticks_t click = osd_ticks() * 1000 / osd_ticks_per_second(); |
| 1187 | | sdl_window_info *window = GET_WINDOW(&event.button); |
| 1188 | | |
| 1337 | sdl_window_info *window = GET_FOCUS_WINDOW(&event.button); |
| 1189 | 1338 | if (window != NULL && window->xy_to_render_target(window, event.button.x,event.button.y, &cx, &cy) ) |
| 1190 | 1339 | { |
| 1191 | 1340 | ui_input_push_mouse_down_event(machine, window->target, cx, cy); |
| r3841 | r3842 | |
| 1207 | 1356 | } |
| 1208 | 1357 | break; |
| 1209 | 1358 | case SDL_MOUSEBUTTONUP: |
| 1210 | | devinfo = mouse_list; |
| 1359 | devinfo = generic_device_find_index(mouse_list, mouse_map.logical[event.button.which]); |
| 1211 | 1360 | devinfo->mouse.buttons[event.button.button-1] = 0; |
| 1361 | //printf("But up %d %d %d %d\n", event.button.which, event.button.button, event.button.x, event.button.y); |
| 1212 | 1362 | |
| 1213 | 1363 | if (event.button.button == 1) |
| 1214 | 1364 | { |
| 1215 | 1365 | int cx, cy; |
| 1216 | | sdl_window_info *window = GET_WINDOW(&event.button); |
| 1366 | sdl_window_info *window = GET_FOCUS_WINDOW(&event.button); |
| 1217 | 1367 | |
| 1218 | 1368 | if (window != NULL && window->xy_to_render_target(window, event.button.x,event.button.y, &cx, &cy) ) |
| 1219 | 1369 | { |
| r3841 | r3842 | |
| 1222 | 1372 | } |
| 1223 | 1373 | break; |
| 1224 | 1374 | case SDL_MOUSEMOTION: |
| 1225 | | devinfo = mouse_list; |
| 1375 | devinfo = generic_device_find_index(mouse_list, mouse_map.logical[event.motion.which]); |
| 1226 | 1376 | #if (SDL_VERSION_ATLEAST(1,3,0)) |
| 1227 | 1377 | // FIXME: may apply to 1.2 as well ... |
| 1378 | //printf("Motion %d %d %d %s\n", event.motion.which, event.motion.x, event.motion.y, devinfo->name); |
| 1228 | 1379 | devinfo->mouse.lX += event.motion.xrel * INPUT_RELATIVE_PER_PIXEL; |
| 1229 | 1380 | devinfo->mouse.lY += event.motion.yrel * INPUT_RELATIVE_PER_PIXEL; |
| 1230 | 1381 | #else |
| r3841 | r3842 | |
| 1233 | 1384 | #endif |
| 1234 | 1385 | { |
| 1235 | 1386 | int cx=-1, cy=-1; |
| 1236 | | sdl_window_info *window = GET_WINDOW(&event.motion); |
| 1237 | | |
| 1387 | sdl_window_info *window = GET_FOCUS_WINDOW(&event.motion); |
| 1388 | |
| 1238 | 1389 | if (window != NULL && window->xy_to_render_target(window, event.motion.x, event.motion.y, &cx, &cy) ) |
| 1239 | 1390 | ui_input_push_mouse_move_event(machine, window->target, cx, cy); |
| 1240 | 1391 | } |
| r3841 | r3842 | |
| 1244 | 1395 | app_has_mouse_focus = event.active.gain; |
| 1245 | 1396 | if (!event.active.gain) |
| 1246 | 1397 | { |
| 1247 | | sdl_window_info *window = GET_WINDOW(&event.motion); |
| 1398 | sdl_window_info *window = GET_FOCUS_WINDOW(&event.motion); |
| 1248 | 1399 | ui_input_push_mouse_leave_event(machine, window->target); |
| 1249 | 1400 | } |
| 1250 | 1401 | break; |
| r3841 | r3842 | |
| 1258 | 1409 | case SDL_TEXTINPUT: |
| 1259 | 1410 | if (*event.text.text) |
| 1260 | 1411 | { |
| 1261 | | sdl_window_info *window = GET_WINDOW(&event.text); |
| 1412 | sdl_window_info *window = GET_FOCUS_WINDOW(&event.text); |
| 1262 | 1413 | unicode_char result; |
| 1263 | 1414 | if (window != NULL ) |
| 1264 | 1415 | { |
| r3841 | r3842 | |
| 1284 | 1435 | ui_input_push_mouse_leave_event(machine, window->target); |
| 1285 | 1436 | app_has_mouse_focus = 0; |
| 1286 | 1437 | break; |
| 1287 | | |
| 1288 | 1438 | } |
| 1289 | 1439 | case SDL_WINDOWEVENT_RESIZED: |
| 1290 | 1440 | if (event.window.data1 != window->width || event.window.data2 != window->height) |
| r3841 | r3842 | |
| 1308 | 1458 | } |
| 1309 | 1459 | } |
| 1310 | 1460 | |
| 1461 | |
| 1311 | 1462 | //============================================================ |
| 1312 | 1463 | // sdlinput_release_keys |
| 1313 | 1464 | //============================================================ |
| 1314 | 1465 | |
| 1466 | |
| 1315 | 1467 | void sdlinput_release_keys(running_machine *machine) |
| 1316 | 1468 | { |
| 1317 | 1469 | // FIXME: SDL >= 1.3 will nuke the window event buffer when |
| r3841 | r3842 | |
| 1319 | 1471 | // state when a window is destroyed and recreated. |
| 1320 | 1472 | #if (SDL_VERSION_ATLEAST(1,3,0)) |
| 1321 | 1473 | device_info *devinfo; |
| 1474 | int index; |
| 1322 | 1475 | |
| 1323 | | devinfo = keyboard_list; |
| 1324 | | if (devinfo != NULL) |
| 1476 | for (index = 0; ;index++) |
| 1477 | { |
| 1478 | devinfo = generic_device_find_index( keyboard_list, index); |
| 1479 | if (devinfo == NULL) |
| 1480 | break; |
| 1325 | 1481 | memset(&devinfo->keyboard.state, 0, sizeof(devinfo->keyboard.state)); |
| 1482 | } |
| 1326 | 1483 | #endif |
| 1327 | 1484 | } |
| 1328 | 1485 | |
| 1486 | |
| 1329 | 1487 | //============================================================ |
| 1330 | 1488 | // sdlinput_should_hide_mouse |
| 1331 | 1489 | //============================================================ |
| r3841 | r3842 | |
| 1500 | 1658 | } |
| 1501 | 1659 | } |
| 1502 | 1660 | |
| 1661 | |
| 1503 | 1662 | //============================================================ |
| 1504 | 1663 | // device_list_reset_devices |
| 1505 | 1664 | //============================================================ |
| r3841 | r3842 | |
| 1512 | 1671 | generic_device_reset(curdev); |
| 1513 | 1672 | } |
| 1514 | 1673 | |
| 1674 | |
| 1515 | 1675 | //============================================================ |
| 1516 | 1676 | // device_list_free_devices |
| 1517 | 1677 | //============================================================ |
| r3841 | r3842 | |
| 1529 | 1689 | *devlist_head = NULL; |
| 1530 | 1690 | } |
| 1531 | 1691 | |
| 1692 | |
| 1532 | 1693 | //============================================================ |
| 1533 | 1694 | // generic_device_alloc |
| 1534 | 1695 | //============================================================ |
| r3841 | r3842 | |
| 1603 | 1764 | return -1; |
| 1604 | 1765 | } |
| 1605 | 1766 | |
| 1767 | |
| 1606 | 1768 | static device_info *generic_device_find_index(device_info *devlist_head, int index) |
| 1607 | 1769 | { |
| 1608 | 1770 | device_info *orig_head = devlist_head; |
src/osd/sdl/sdlmain.c
| r3841 | r3842 | |
| 202 | 202 | |
| 203 | 203 | // joystick mapping |
| 204 | 204 | { NULL, NULL, OPTION_HEADER, "SDL JOYSTICK MAPPING" }, |
| 205 | | { SDLOPTION_JOYMAP, "0", OPTION_BOOLEAN, "enable physical to logical joystick mapping" }, |
| 206 | | { SDLOPTION_JOYMAP_FILE, "joymap.dat", 0, "joymap filename" }, |
| 207 | | { SDLOPTION_SIXAXIS, "0", OPTION_BOOLEAN, "Use special handling for PS3 Sixaxis controllers" }, |
| 205 | { SDLOPTION_JOYINDEX "1", SDLOPTVAL_AUTO, 0, "name of joystick mapped to joystick #1" }, |
| 206 | { SDLOPTION_JOYINDEX "2", SDLOPTVAL_AUTO, 0, "name of joystick mapped to joystick #2" }, |
| 207 | { SDLOPTION_JOYINDEX "3", SDLOPTVAL_AUTO, 0, "name of joystick mapped to joystick #3" }, |
| 208 | { SDLOPTION_JOYINDEX "4", SDLOPTVAL_AUTO, 0, "name of joystick mapped to joystick #4" }, |
| 209 | { SDLOPTION_JOYINDEX "5", SDLOPTVAL_AUTO, 0, "name of joystick mapped to joystick #5" }, |
| 210 | { SDLOPTION_JOYINDEX "6", SDLOPTVAL_AUTO, 0, "name of joystick mapped to joystick #6" }, |
| 211 | { SDLOPTION_JOYINDEX "7", SDLOPTVAL_AUTO, 0, "name of joystick mapped to joystick #7" }, |
| 212 | { SDLOPTION_JOYINDEX "8", SDLOPTVAL_AUTO, 0, "name of joystick mapped to joystick #8" }, |
| 213 | { SDLOPTION_SIXAXIS, "0", OPTION_BOOLEAN, "Use special handling for PS3 Sixaxis controllers" }, |
| 208 | 214 | |
| 215 | #if (SDL_VERSION_ATLEAST(1,3,0)) |
| 216 | { NULL, NULL, OPTION_HEADER, "SDL MOUSE MAPPING" }, |
| 217 | { SDLOPTION_MOUSEINDEX "1", SDLOPTVAL_AUTO, 0, "name of mouse mapped to mouse #1" }, |
| 218 | { SDLOPTION_MOUSEINDEX "2", SDLOPTVAL_AUTO, 0, "name of mouse mapped to mouse #2" }, |
| 219 | { SDLOPTION_MOUSEINDEX "3", SDLOPTVAL_AUTO, 0, "name of mouse mapped to mouse #3" }, |
| 220 | { SDLOPTION_MOUSEINDEX "4", SDLOPTVAL_AUTO, 0, "name of mouse mapped to mouse #4" }, |
| 221 | { SDLOPTION_MOUSEINDEX "5", SDLOPTVAL_AUTO, 0, "name of mouse mapped to mouse #5" }, |
| 222 | { SDLOPTION_MOUSEINDEX "6", SDLOPTVAL_AUTO, 0, "name of mouse mapped to mouse #6" }, |
| 223 | { SDLOPTION_MOUSEINDEX "7", SDLOPTVAL_AUTO, 0, "name of mouse mapped to mouse #7" }, |
| 224 | { SDLOPTION_MOUSEINDEX "8", SDLOPTVAL_AUTO, 0, "name of mouse mapped to mouse #8" }, |
| 225 | |
| 226 | { NULL, NULL, OPTION_HEADER, "SDL KEYBOARD MAPPING" }, |
| 227 | { SDLOPTION_KEYBINDEX "1", SDLOPTVAL_AUTO, 0, "name of keyboard mapped to keyboard #1" }, |
| 228 | { SDLOPTION_KEYBINDEX "2", SDLOPTVAL_AUTO, 0, "name of keyboard mapped to keyboard #2" }, |
| 229 | { SDLOPTION_KEYBINDEX "3", SDLOPTVAL_AUTO, 0, "name of keyboard mapped to keyboard #3" }, |
| 230 | { SDLOPTION_KEYBINDEX "4", SDLOPTVAL_AUTO, 0, "name of keyboard mapped to keyboard #4" }, |
| 231 | { SDLOPTION_KEYBINDEX "5", SDLOPTVAL_AUTO, 0, "name of keyboard mapped to keyboard #5" }, |
| 232 | { SDLOPTION_KEYBINDEX "6", SDLOPTVAL_AUTO, 0, "name of keyboard mapped to keyboard #6" }, |
| 233 | { SDLOPTION_KEYBINDEX "7", SDLOPTVAL_AUTO, 0, "name of keyboard mapped to keyboard #7" }, |
| 234 | { SDLOPTION_KEYBINDEX "8", SDLOPTVAL_AUTO, 0, "name of keyboard mapped to keyboard #8" }, |
| 235 | #endif |
| 209 | 236 | // SDL low level driver options |
| 210 | 237 | { NULL, NULL, OPTION_HEADER, "SDL LOWLEVEL DRIVER OPTIONS" }, |
| 211 | | { SDLOPTION_VIDEODRIVER ";vd", SDLOPTVAL_AUTO, 0, "sdl video driver to use ('x11', 'directfb', ... or 'auto' for SDL default" }, |
| 238 | { SDLOPTION_VIDEODRIVER ";vd", SDLOPTVAL_AUTO, 0, "sdl video driver to use ('x11', 'directfb', ... or 'auto' for SDL default" }, |
| 212 | 239 | #if (SDL_VERSION_ATLEAST(1,3,0)) |
| 213 | | { SDLOPTION_RENDERDRIVER ";rd", SDLOPTVAL_AUTO, 0, "sdl render driver to use ('software', 'opengl', 'directfb' ... or 'auto' for SDL default" }, |
| 240 | { SDLOPTION_RENDERDRIVER ";rd", SDLOPTVAL_AUTO, 0, "sdl render driver to use ('software', 'opengl', 'directfb' ... or 'auto' for SDL default" }, |
| 214 | 241 | #endif |
| 215 | | { SDLOPTION_AUDIODRIVER ";ad", SDLOPTVAL_AUTO, 0, "sdl audio driver to use ('alsa', 'arts', ... or 'auto' for SDL default" }, |
| 242 | { SDLOPTION_AUDIODRIVER ";ad", SDLOPTVAL_AUTO, 0, "sdl audio driver to use ('alsa', 'arts', ... or 'auto' for SDL default" }, |
| 216 | 243 | #if USE_OPENGL |
| 217 | | { SDLOPTION_GL_LIB, SDLOPTVAL_GLLIB, 0, "alternative libGL.so to use; 'auto' for system default" }, |
| 244 | { SDLOPTION_GL_LIB, SDLOPTVAL_GLLIB, 0, "alternative libGL.so to use; 'auto' for system default" }, |
| 218 | 245 | #endif |
| 219 | 246 | |
| 220 | 247 | // End of list |
| r3841 | r3842 | |
| 414 | 441 | mame_printf_verbose("Build version: %s\n", build_version); |
| 415 | 442 | mame_printf_verbose("Build architecure: "); |
| 416 | 443 | MACRO_VERBOSE(SDLMAME_ARCH); |
| 444 | MACRO_VERBOSE(DISTRO); |
| 417 | 445 | mame_printf_verbose("\n"); |
| 418 | 446 | mame_printf_verbose("Build defines: "); |
| 419 | 447 | MACRO_VERBOSE(SDLMAME_UNIX); |
| r3841 | r3842 | |
| 451 | 479 | MACRO_VERBOSE(__ppc__); |
| 452 | 480 | MACRO_VERBOSE(__ppc64__); |
| 453 | 481 | mame_printf_verbose("\n"); |
| 482 | mame_printf_verbose("Compiler defines C: "); |
| 483 | MACRO_VERBOSE(_FORTIFY_SOURCE); |
| 484 | MACRO_VERBOSE(__USE_FORTIFY_LEVEL); |
| 485 | mame_printf_verbose("\n"); |
| 454 | 486 | } |
| 455 | 487 | |
| 456 | 488 | //============================================================ |
| 489 | // osd_sdl_info |
| 490 | //============================================================ |
| 491 | |
| 492 | static void osd_sdl_info(void) |
| 493 | { |
| 494 | #if SDL_VERSION_ATLEAST(1,3,0) |
| 495 | int i, cur, num = SDL_GetNumVideoDrivers(); |
| 496 | |
| 497 | mame_printf_verbose("Available videodrivers: "); |
| 498 | for (i=0;i<num;i++) |
| 499 | { |
| 500 | const char *name = SDL_GetVideoDriver(i); |
| 501 | mame_printf_verbose("%s ", name); |
| 502 | } |
| 503 | mame_printf_verbose("\n"); |
| 504 | mame_printf_verbose("Current Videodriver: %s\n", SDL_GetCurrentVideoDriver()); |
| 505 | num = SDL_GetNumVideoDisplays(); |
| 506 | cur = SDL_GetCurrentVideoDisplay(); |
| 507 | for (i=0;i<num;i++) |
| 508 | { |
| 509 | SDL_DisplayMode mode; |
| 510 | int j; |
| 511 | |
| 512 | SDL_SelectVideoDisplay(i); |
| 513 | mame_printf_verbose("\tDisplay #%d\n", i); |
| 514 | if (SDL_GetDesktopDisplayMode(&mode)); |
| 515 | mame_printf_verbose("\t\tDesktop Mode: %dx%d-%d@%d\n", mode.w, mode.h, SDL_BITSPERPIXEL(mode.format), mode.refresh_rate); |
| 516 | if (SDL_GetFullscreenDisplayMode(&mode)); |
| 517 | mame_printf_verbose("\t\tFullscreen Mode: %dx%d-%d@%d\n", mode.w, mode.h, SDL_BITSPERPIXEL(mode.format), mode.refresh_rate); |
| 518 | if (SDL_GetCurrentDisplayMode(&mode)); |
| 519 | mame_printf_verbose("\t\tCurrent Display Mode: %dx%d-%d@%d\n", mode.w, mode.h, SDL_BITSPERPIXEL(mode.format), mode.refresh_rate); |
| 520 | mame_printf_verbose("\t\tRenderdrivers:\n"); |
| 521 | for (j=0; j<SDL_GetNumRenderDrivers(); j++) |
| 522 | { |
| 523 | SDL_RendererInfo info; |
| 524 | SDL_GetRenderDriverInfo(j, &info); |
| 525 | mame_printf_verbose("\t\t\t%10s (%dx%d)\n", info.name, info.max_texture_width, info.max_texture_height); |
| 526 | } |
| 527 | } |
| 528 | SDL_SelectVideoDisplay(cur); |
| 529 | |
| 530 | mame_printf_verbose("Available audio drivers: \n"); |
| 531 | num = SDL_GetNumAudioDrivers(); |
| 532 | for (i=0;i<num;i++) |
| 533 | { |
| 534 | mame_printf_verbose("\t%-20s\n", SDL_GetAudioDriver(i)); |
| 535 | } |
| 536 | #endif |
| 537 | } |
| 538 | |
| 539 | |
| 540 | //============================================================ |
| 457 | 541 | // osd_init |
| 458 | 542 | //============================================================ |
| 459 | 543 | |
| r3841 | r3842 | |
| 505 | 589 | ShowError("Could not initialize SDL", SDL_GetError()); |
| 506 | 590 | exit(-1); |
| 507 | 591 | } |
| 592 | osd_sdl_info(); |
| 508 | 593 | } |
| 509 | 594 | // must be before sdlvideo_init! |
| 510 | 595 | add_exit_callback(machine, osd_exit); |