Previous 15994 Revisions Next

r3842 Tuesday 16th December, 2008 at 14:20:44 UTC by R. Belmont
[SDLMESS] Sync with SDLMAME u6.
[src/osd/sdl]drawogl.c drawsdl.c input.c osdsdl.h output.c sdl.mak sdlmain.c sdlsync.c sdlsync.h sdlwork.c texcopy.c window.c window.h

src/osd/sdl/drawogl.c
r3841r3842
2222#include "render.h"
2323#include "options.h"
2424#include "driver.h"
25#include "deprecat.h"
2625
2726// standard SDL headers
2827#include <SDL/SDL.h>
r3841r3842
245244   }
246245}
247246
248INLINE 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
290247//============================================================
291248//  PROTOTYPES
292249//============================================================
r3841r3842
374331//============================================================
375332
376333static void texture_set_data(texture_info *texture, const render_texinfo *texsource);
377static texture_info *texture_create(sdl_info *sdl, sdl_window_info *window, const render_texinfo *texsource, UINT32 flags);
334static texture_info *texture_create(sdl_window_info *window, const render_texinfo *texsource, UINT32 flags);
378335static texture_info *texture_find(sdl_info *sdl, const render_primitive *prim);
379static texture_info * texture_update(sdl_info *sdl, sdl_window_info *window, const render_primitive *prim, int shaderIdx);
336static texture_info * texture_update(sdl_window_info *window, const render_primitive *prim, int shaderIdx);
380337static void texture_all_disable(sdl_info *sdl);
381338static void texture_disable(sdl_info *sdl, texture_info * texture);
382339
r3841r3842
540497   
541498   sdl->gl_context_id = SDL_GL_CreateContext(window->window_id);
542499
500   SDL_GL_SetSwapInterval(options_get_bool(mame_options(), SDLOPTION_WAITVSYNC) ? 2 : 0);
501   
543502#else
544503   sdl->extra_flags = (window->fullscreen ?  SDL_FULLSCREEN : SDL_RESIZABLE);
545504   sdl->extra_flags |= SDL_OPENGL | SDL_DOUBLEBUF;
r3841r3842
13211280
13221281            set_blendmode(sdl, PRIMFLAG_GET_BLENDMODE(prim->flags));
13231282
1324            texture = texture_update(sdl, window, prim, 0);
1283            texture = texture_update(window, prim, 0);
13251284
13261285            if ( texture && texture->type==TEXTURE_TYPE_SHADER )
13271286            {
r3841r3842
13521311
13531312                  if(i>0) // first fetch already done
13541313                  {
1355                     texture = texture_update(sdl, window, prim, i);
1314                     texture = texture_update(window, prim, i);
13561315                  }
13571316                  glDrawArrays(GL_QUADS, 0, 4);
13581317               }
r3841r3842
18971856   return 0;
18981857}
18991858
1900static int texture_shader_create(sdl_info *sdl, sdl_window_info *window,
1859static int texture_shader_create(sdl_window_info *window,
19011860                                 const render_texinfo *texsource, texture_info *texture, UINT32 flags)
19021861{
1862   sdl_info *sdl = window->dxdata;
19031863   int uniform_location;
19041864   int lut_table_width_pow2=0;
19051865   int lut_table_height_pow2=0;
r3841r3842
22582218   return 0;
22592219}
22602220
2261static texture_info *texture_create(sdl_info *sdl, sdl_window_info *window, const render_texinfo *texsource, UINT32 flags)
2221static texture_info *texture_create(sdl_window_info *window, const render_texinfo *texsource, UINT32 flags)
22622222{
2223   sdl_info *sdl = window->dxdata;
22632224   texture_info *texture;
22642225   
22652226   // allocate a new texture
r3841r3842
23442305
23452306   if ( texture->type==TEXTURE_TYPE_SHADER )
23462307   {
2347      if ( texture_shader_create(sdl, window, texsource, texture, flags) )
2308      if ( texture_shader_create(window, texsource, texture, flags) )
23482309        {
23492310            free(texture);
23502311            return NULL;
r3841r3842
25772538//  texture_update
25782539//============================================================
25792540
2580static void texture_coord_update(sdl_info *sdl, sdl_window_info *window,
2541static void texture_coord_update(sdl_window_info *window,
25812542                                 texture_info *texture, const render_primitive *prim, int shaderIdx)
25822543{
2544   sdl_info *sdl = window->dxdata;
25832545   float ustart, ustop;         // beginning/ending U coordinates
25842546   float vstart, vstop;         // beginning/ending V coordinates
25852547   float du, dv;
r3841r3842
27292691   }
27302692}
27312693
2732static void texture_shader_update(sdl_info *sdl, sdl_window_info *window, texture_info *texture, int shaderIdx)
2694static void texture_shader_update(sdl_window_info *window, texture_info *texture, int shaderIdx)
27332695{
2696   sdl_info *sdl = window->dxdata;
27342697   if ( !texture->lut_texture )
27352698   {
27362699      int uniform_location, scrnum;
r3841r3842
27422705
27432706      scrnum = 0;
27442707      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))
27462709      {
27472710         if (scrnum == window->start_viewscreen)
27482711         {
r3841r3842
27802743   }
27812744}
27822745
2783static texture_info * texture_update(sdl_info *sdl, sdl_window_info *window, const render_primitive *prim, int shaderIdx)
2746static texture_info * texture_update(sdl_window_info *window, const render_primitive *prim, int shaderIdx)
27842747{
2748   sdl_info *sdl = window->dxdata;
27852749   texture_info *texture = texture_find(sdl, prim);
27862750   int texBound = 0;
27872751
27882752   // if we didn't find one, create a new texture
27892753   if (texture == NULL && prim->texture.base != NULL)
27902754    {
2791            texture = texture_create(sdl, window, &prim->texture, prim->flags);
2755            texture = texture_create(window, &prim->texture, prim->flags);
27922756
27932757    }
27942758   else if (texture != NULL)
r3841r3842
28132777   {
28142778      if ( texture->type == TEXTURE_TYPE_SHADER )
28152779      {
2816         texture_shader_update(sdl, window, texture, shaderIdx);
2780         texture_shader_update(window, texture, shaderIdx);
28172781         if ( sdl->glsl_program_num>1 )
28182782         {
28192783            texture_mpass_flip(sdl, texture, shaderIdx);
r3841r3842
28352799      if (!texBound) {
28362800         glBindTexture(texture->texTarget, texture->texture);
28372801      }
2838      texture_coord_update(sdl, window, texture, prim, shaderIdx);
2802      texture_coord_update(window, texture, prim, shaderIdx);
28392803
28402804      glEnableClientState(GL_TEXTURE_COORD_ARRAY);
28412805      if(sdl->usevbo)
src/osd/sdl/output.c
r3841r3842
1616// MAME headers
1717#include "osdepend.h"
1818#include "driver.h"
19#include "deprecat.h"
2019
2120// MAMEOS headers
2221#include "output.h"
src/osd/sdl/sdl.mak
r3841r3842
2121# for details
2222#-------------------------------------------------
2323
24
25# uncomment and edit next line to specify a distribution
26# supported debian-stable, ubuntu-intrepid
27
28# DISTRO = debian-stable
29# DISTRO = ubuntu-intrepid
30
2431# uncomment next line to build without OpenGL support
2532
2633# NO_OPENGL = 1
r3841r3842
4047USE_DISPATCH_GL = 1
4148
4249# uncomment and change the next line to compile and link to specific
43# SDL library. This is currently ony supported for unix!
50# SDL library. This is currently only supported for unix!
4451# There is no need to play with this option unless you are doing
4552# active development on sdlmame or SDL.
4653
47# SDL_INSTALL_ROOT = /usr/local/sdl13
54#SDL_INSTALL_ROOT = /usr/local/sdl13
55#SDL_INSTALL_ROOT = /usr/local/test
4856
4957###########################################################################
5058##################   END USER-CONFIGURABLE OPTIONS   ######################
r3841r3842
5462CFLAGS += $(OPT_FLAGS)
5563
5664#-------------------------------------------------
65# distribution may change things
66#-------------------------------------------------
67   
68ifeq ($(DISTRO),)
69DISTRO = generic
70else
71ifeq ($(DISTRO),debian-stable)
72DEFS += -DNO_AFFINITY_NP
73else
74ifeq ($(DISTRO),ubuntu-intrepid)
75# Force gcc-4.2 on ubuntu-intrepid
76CC = @gcc -V 4.2
77LD = @gcc -V 4.2
78else
79$(error DISTRO $(DISTRO) unknown)
80endif
81endif
82endif
83
84DEFS += -DDISTRO=$(DISTRO)
85
86#-------------------------------------------------
5787# sanity check the configuration
5888#-------------------------------------------------
5989
r3841r3842
6696# OS/2 can't have OpenGL (aww)
6797ifeq ($(TARGETOS),os2)
6898NO_OPENGL = 1
99DEFS += -DNO_THREAD_COOPERATIVE -DNO_DEBUGGER
69100endif
70101
71102# additional definitions when we are on Solaris
72103ifeq ($(TARGETOS),solaris)
73DEFS += -DSDLMAME_X11 -DSDLMAME_UNIX -DSDLMAME_SOLARIS
104DEFS += -DNO_AFFINITY_NP -DNO_DEBUGGER -DSDLMAME_X11 -DSDLMAME_UNIX -DSDLMAME_SOLARIS
74105endif
75106
76107#-------------------------------------------------
r3841r3842
95126
96127ifeq ($(TARGETOS),freebsd)
97128TARGETOS = unix
129DEFS += -DNO_THREAD_COOPERATIVE -DNO_DEBUGGER
98130endif
99131
100132ifeq ($(TARGETOS),unix)
r3841r3842
102134ifndef NO_X11
103135DEFS += -DSDLMAME_X11
104136else
105DEFS += -DSDLMAME_NO_X11
137DEFS += -DSDLMAME_NO_X11 -DNO_DEBUGGER
106138endif
107139endif
108140
109141ifeq ($(TARGETOS),macosx)
110DEFS += -DSDLMAME_UNIX -DSDLMAME_MACOSX
142DEFS += -DNO_THREAD_COOPERATIVE -DSDLMAME_UNIX -DSDLMAME_MACOSX
111143MAINLDFLAGS = -Xlinker -all_load
112144ifdef BIGENDIAN
113145PPC=1
r3841r3842
132164endif
133165
134166ifeq ($(TARGETOS),win32)
135DEFS += -DSDLMAME_WIN32
167DEFS += -DSDLMAME_WIN32 -DNO_DEBUGGER
136168endif
137169
138170ifeq ($(TARGETOS),os2)
src/osd/sdl/texcopy.c
r3841r3842
11
22#ifndef SDL_TEXFORMAT
33
4#if 0
5INLINE UINT32 ycc_to_rgb(unsigned y, unsigned cb, unsigned cr)
6{
7   /* original equations:
8
9        C = Y - 16
10        D = Cb - 128
11        E = Cr - 128
12
13        R = clip(( 298 * C           + 409 * E + 128) >> 8)
14        G = clip(( 298 * C - 100 * D - 208 * E + 128) >> 8)
15        B = clip(( 298 * C + 516 * D           + 128) >> 8)
16
17        R = clip(( 298 * (Y - 16)                    + 409 * (Cr - 128) + 128) >> 8)
18        G = clip(( 298 * (Y - 16) - 100 * (Cb - 128) - 208 * (Cr - 128) + 128) >> 8)
19        B = clip(( 298 * (Y - 16) + 516 * (Cb - 128)                    + 128) >> 8)
20
21        R = clip(( 298 * Y - 298 * 16                        + 409 * Cr - 409 * 128 + 128) >> 8)
22        G = clip(( 298 * Y - 298 * 16 - 100 * Cb + 100 * 128 - 208 * Cr + 208 * 128 + 128) >> 8)
23        B = clip(( 298 * Y - 298 * 16 + 516 * Cb - 516 * 128                        + 128) >> 8)
24
25        R = clip(( 298 * Y - 298 * 16                        + 409 * Cr - 409 * 128 + 128) >> 8)
26        G = clip(( 298 * Y - 298 * 16 - 100 * Cb + 100 * 128 - 208 * Cr + 208 * 128 + 128) >> 8)
27        B = clip(( 298 * Y - 298 * 16 + 516 * Cb - 516 * 128                        + 128) >> 8)
28    */
29   //int r, g, b, common;
30   unsigned int r, g, b, common;
31
32   common = 298 * y - 56992;
33   r = (common +            409 * cr);
34   g = (common - 100 * cb - 208 * cr + 91776);
35   b = (common + 516 * cb - 13696);
36
37   if ((int) r < 0) r = 0;
38   if ((int) g < 0) g = 0;
39   if ((int) b < 0) b = 0;
40
41   /* MAME_RGB does upper clamping */
42
43   return MAKE_RGB(r >> 8, g >> 8, b >> 8);
44}
45#else
46#define CLUL(x) ((int) x < 0 ? 0 : (x > 65535 ? 255 : x>>8))
47
48INLINE UINT32 ycc_to_rgb(unsigned y, unsigned cb, unsigned cr)
49{
50   unsigned int r, g, b, common;
51
52   common = 298 * y - 56992;
53   r = (common +            409 * cr);
54   g = (common - 100 * cb - 208 * cr + 91776);
55   b = (common + 516 * cb - 13696);
56
57   return 0xff000000 | (CLUL(r)<<16) | (CLUL(g)<<8) | (CLUL(b));
58}
59
60#endif
61
462#define SDL_TEXFORMAT SDL_TEXFORMAT_ARGB32
563#include "texcopy.c"
664
r3841r3842
83141   }
84142}
85143
86#define CLSH(x)      (((int) x < 0) ? 0 : x >> 8)
144#define CLSH(x)      (((int) (x) < 0) ? 0 : ( (x) > 65535 ? 255 : (x) >> 8))
87145
88146static void texcopy_yuv16_paletted(texture_info *texture, const render_texinfo *texsource)
89147{
r3841r3842
109167         UINT8 cb = srcpix0 & 0xff;
110168         UINT8 cr = srcpix1 & 0xff;
111169         
112#if 0   
170#if 0
113171         *dst++ = ycc_to_rgb(texsource->palette[0x000 + (srcpix0 >> 8)], cb, cr);
114172         *dst++ = ycc_to_rgb(texsource->palette[0x000 + (srcpix1 >> 8)], cb, cr);
115173#else
r3841r3842
122180         b1 = b2 =  + 516 * cb - 70688;
123181         r1 += y1; g1 += y1; b1 += y1;
124182         r2 += y2; g2 += y2; b2 += y2;
125         *dst++ = MAKE_RGB(CLSH(r1), CLSH(g1), CLSH(b1));
126         *dst++ = MAKE_RGB(CLSH(r2), CLSH(g2), CLSH(b2));
183         *dst++ = 0xff000000 | (CLSH(r1)<<16) | (CLSH(g1)<<8) | (CLSH(b1));
184         *dst++ = 0xff000000 | (CLSH(r2)<<16) | (CLSH(g2)<<8) | (CLSH(b2));
127185#endif
128186      }
129187     
src/osd/sdl/input.c
r3841r3842
4646   POVDIR_DOWN
4747};
4848
49// introduced in 1.3
50
51#ifndef SDLK_INDEX
52#define SDLK_INDEX(x)      (x)
53#endif
54
5549#define MAX_KEYS         256
5650#define MAX_AXES         8
5751#define MAX_BUTTONS         32
5852#define MAX_HATS         8
5953#define MAX_POV            4
60#define MAX_JOYSTICKS      16
54#define MAX_DEVMAP_ENTRIES   16
6155
6256//============================================================
6357//  MACROS
6458//============================================================
6559
60// introduced in 1.3
6661
62#ifndef SDLK_INDEX
63#define SDLK_INDEX(x)      (x)
64#endif
65
66
6767//============================================================
6868//  TYPEDEFS
6969//============================================================
r3841r3842
118118   };
119119};
120120
121
121122//============================================================
122123//  LOCAL VARIABLES
123124//============================================================
r3841r3842
151152static device_info *      joystick_list;
152153
153154// joystick mapper
154static struct
155
156typedef struct _device_map_t device_map_t;
157struct _device_map_t
155158{
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};
159166
160static int joy_logical[MAX_JOYSTICKS];
167static device_map_t joy_map;
168static device_map_t mouse_map;
169static device_map_t keyboard_map;
161170
162171static int sixaxis_mode;
163172
173
164174//============================================================
165175//  PROTOTYPES
166176//============================================================
r3841r3842
181191static INT32 generic_axis_get_state(void *device_internal, void *item_internal);
182192static device_info *generic_device_find_index(device_info *devlist_head, int index);
183193
194
184195//============================================================
185196//  KEYBOARD/JOYSTICK LIST
186197//============================================================
r3841r3842
200211
201212#define OSD_SDL_INDEX(x) (x)
202213#define OSD_SDL_INDEX_KEYSYM(keysym) ((keysym)->scancode)
214
203215#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)
204219
220
205221#define KTT_ENTRY0(MAME, SDL, VK, AS, UI) { ITEM_ID_ ## MAME, SDL_SCANCODE_ ## SDL, "ITEM_ID_" #MAME, (char *) UI }
206222#define KTT_ENTRY1(MAME, SDL) KTT_ENTRY0(MAME, SDL, MAME, MAME, #MAME)
207223// only for reference ...
r3841r3842
325341#define OSD_SDL_INDEX(x) (SDLK_INDEX(x)-SDLK_FIRST)
326342#define OSD_SDL_INDEX_KEYSYM(keysym) (OSD_SDL_INDEX((keysym)->sym))
327343#define GET_WINDOW(ev) sdl_window_list
344#define GET_FOCUS_WINDOW(ev) sdl_window_list
328345
329346#define KTT_ENTRY0(MAME, SDL, VK, AS, UI) { ITEM_ID_ ## MAME, SDLK_ ## SDL, "ITEM_ID_" #MAME, (char *) UI }
330347#define KTT_ENTRY1(MAME, SDL) KTT_ENTRY0(MAME, SDL, MAME, MAME, #MAME)
r3841r3842
446463};
447464#endif
448465
449
450466typedef struct _key_lookup_table key_lookup_table;
451
452467struct _key_lookup_table
453468{
454469   int code;
r3841r3842
526541};
527542#endif
528543
544
529545//============================================================
530546//  INLINE FUNCTIONS
531547//============================================================
532548
533static int joy_map_leastfree(void)
549static int devmap_leastfree(device_map_t *devmap)
534550{
535551   int i;
536   for (i=0;i<MAX_JOYSTICKS;i++)
552   for (i=0;i<MAX_DEVMAP_ENTRIES;i++)
537553   {
538      if (*joy_map[i].name == 0)
554      if (*devmap->map[i].name == 0)
539555         return i;
540556   }
541557   return -1;
r3841r3842
574590   return r;
575591}
576592
593static 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
577617//============================================================
578618//  init_joymap
579619//============================================================
580620
581static void init_joymap(void)
621static void devmap_init(device_map_t *devmap, const char *opt, int max_devices, const char *label)
582622{
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++)
586629   {
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;
590633   }
591     
592   if (options_get_bool(mame_options(), SDLOPTION_JOYMAP))
634   devmap->initialized = 0;
635   
636   for (dev = 0; dev < max_devices; dev++)
593637   {
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);
600640
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))
604643      {
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;
606647      }
607      else
648   }
649}
650
651static 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)
608661      {
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);
636665      }
666      return NULL;
637667   }
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;
638674}
639675
676
640677//============================================================
641678//  sdlinput_register_joysticks
642679//============================================================
r3841r3842
644681static void sdlinput_register_joysticks(running_machine *machine)
645682{
646683   device_info *devinfo;
647   int physical_stick, axis, button, hat, stick, i;
684   int physical_stick, axis, button, hat, stick;
648685   char tempname[512];
649686   SDL_Joystick *joy;
650687
651   init_joymap();
688   devmap_init(&joy_map, SDLOPTION_JOYINDEX, 8, "Joystick mapping");
652689
653690   mame_printf_verbose("Joystick: Start initialization\n");
654691   for (physical_stick = 0; physical_stick < SDL_NumJoysticks(); physical_stick++)
655692   {
656693      char *joy_name = remove_spaces(SDL_JoystickName(physical_stick));
657      int found = 0;
658694     
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);
675696   }
676697
677   for (stick = 0; stick < MAX_JOYSTICKS; stick++)
698   for (stick = 0; stick < MAX_DEVMAP_ENTRIES; stick++)
678699   {
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);
696701
697      physical_stick = joy_map[stick].physical;
698     
699      if (physical_stick < 0)
702      if (devinfo == NULL)
700703         continue;
701704     
702      // loop over all axes
705      physical_stick = joy_map.map[stick].physical;
706     
703707      joy = SDL_JoystickOpen(physical_stick);
704708
705709      devinfo->joystick.device = joy;
r3841r3842
765769}
766770
767771//============================================================
772//  sdlinput_register_joysticks
773//============================================================
774
775#if (SDL_VERSION_ATLEAST(1,3,0))
776static 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
823static 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//============================================================
768857//  lookup_sdl_code
769858//============================================================
770859
r3841r3842
781870   return -1;
782871}
783872
873
784874//============================================================
785875//  lookup_mame_code
786876//============================================================
r3841r3842
815905}
816906#endif
817907
908
818909//============================================================
819910//  sdlinput_read_keymap
820911//============================================================
821912
822static kt_table * sdlinput_read_keymap(char *keymap_filename)
913static kt_table * sdlinput_read_keymap(void)
823914{
915   char *keymap_filename;
824916   kt_table *key_trans_table;
825917   FILE *keymap_file;
826918   int line = 1;
r3841r3842
830922   char sks[21];
831923   char kns[21];
832924
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);
833929   mame_printf_verbose("Keymap: Start reading keymap_file %s\n", keymap_filename);
834930
835931   keymap_file = fopen(keymap_filename, "r");
r3841r3842
881977   return key_trans_table;
882978}
883979
980
884981//============================================================
885//  sdlinput_init
982//  sdlinput_register_keyboards
886983//============================================================
887984
888void sdlinput_init(running_machine *machine)
985#if (SDL_VERSION_ATLEAST(1,3,0))
986static void sdlinput_register_keyboards(running_machine *machine)
889987{
890   device_info *devinfo;
891   int keynum, button;
892   char defname[20];
988   int physical_keyboard;
989   int index;
893990   kt_table *key_trans_table;
894991
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();
901993
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");
904995
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   }
9081003
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++)
9101006   {
911      char *keymap_filename;
1007      device_info *devinfo;
1008      char defname[90];
1009      int keynum;
9121010
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);
9141012
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);
9161031   }
917   else
918   {
919      key_trans_table = sdl_key_trans_table;
920   }
1032   mame_printf_verbose("Keyboard: End initialization\n");
1033}
1034#else
1035static 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;
9211041
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();
9251043
1044   keyboard_map.logical[0] = 0;
1045   
1046   mame_printf_verbose("Keyboard: Start initialization\n");
1047
9261048   // SDL 1.2 only has 1 keyboard (1.3+ will have multiple, this must be revisited then)
9271049   // add it now
9281050   devinfo = generic_device_alloc(&keyboard_list, "System keyboard");
r3841r3842
9431065      input_device_item_add(devinfo->device, defname, &devinfo->keyboard.state[OSD_SDL_INDEX(key_trans_table[keynum].sdl_key)], itemid, generic_button_get_state);
9441066   }
9451067
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
9491072
950   mouse_enabled = options_get_bool(mame_options(), OPTION_MOUSE);
1073//============================================================
1074//  sdlinput_init
1075//============================================================
1076
1077void sdlinput_init(running_machine *machine)
1078{
1079   keyboard_list = NULL;
1080   joystick_list = NULL;
1081   mouse_list = NULL;
1082   lightgun_list = NULL;
9511083   
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
9521100#ifdef MAME_DEBUG
9531101   if (mouse_enabled)
9541102   {
r3841r3842
9561104      mouse_enabled = 0;
9571105   }
9581106#endif
1107   // get Sixaxis special mode info
1108   sixaxis_mode = options_get_bool(mame_options(), SDLOPTION_SIXAXIS);
9591109
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
9711110   // register the joysticks
9721111   sdlinput_register_joysticks(machine);
9731112
r3841r3842
10181157      return sdl_window_list;
10191158}
10201159
1160
10211161//============================================================
10221162//  sdlinput_poll
10231163//============================================================
r3841r3842
10291169   
10301170   for (w = sdl_window_list; w != NULL; w = w->next)
10311171   {
1172      //printf("w->window_id: %d\n", w->window_id);
10321173      if (w->window_id == windowID)
10331174      {
10341175         return w;
r3841r3842
10591200#endif
10601201}
10611202
1203
10621204void sdlinput_poll(running_machine *machine)
10631205{
10641206   device_info *devinfo;
10651207   SDL_Event event;
1208   int index;
10661209#if SDLMAME_EVENTS_IN_WORKER_THREAD
10671210   SDL_Event         loc_event_buf[MAX_BUF_EVENTS];
10681211   int               loc_event_buf_count;
10691212   int bufp;
10701213#endif
10711214
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   }
10751223
10761224#if SDLMAME_EVENTS_IN_WORKER_THREAD
10771225   osd_lock_acquire(input_lock);
r3841r3842
10941242      }
10951243      switch(event.type) {
10961244      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);
10981247         devinfo->keyboard.state[OSD_SDL_INDEX_KEYSYM(&event.key.keysym)] = 0x80;
10991248#if (!SDL_VERSION_ATLEAST(1,3,0))
11001249         ui_input_push_char_event(machine, sdl_window_list->target, (unicode_char) event.key.keysym.unicode);
11011250#endif
11021251         break;
11031252      case SDL_KEYUP:
1104         devinfo = keyboard_list;
1253         devinfo = generic_device_find_index( keyboard_list, keyboard_map.logical[event.key.which]);
11051254         devinfo->keyboard.state[OSD_SDL_INDEX_KEYSYM(&event.key.keysym)] = 0x00;
11061255         break;
11071256      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]);
11091258         if (devinfo)
11101259         {
11111260            if (sixaxis_mode)
r3841r3842
11281277         }
11291278         break;
11301279      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]);
11321281         if (devinfo)
11331282         {
11341283            if (event.jhat.value & SDL_HAT_UP)
r3841r3842
11671316         break;
11681317      case SDL_JOYBUTTONDOWN:
11691318      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]);
11711320         if (devinfo)
11721321         {
11731322            devinfo->joystick.buttons[event.jbutton.button] = (event.jbutton.state == SDL_PRESSED) ? 0x80 : 0;
11741323         }
11751324         break;
11761325      case SDL_MOUSEBUTTONDOWN:
1177         devinfo = mouse_list;
1326         devinfo = generic_device_find_index(mouse_list, mouse_map.logical[event.button.which]);
11781327         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);
11791329         if (event.button.button == 1)
11801330         {
11811331            // FIXME Move static declaration
r3841r3842
11841334            static int last_y = 0;
11851335            int cx, cy;
11861336            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);
11891338            if (window != NULL && window->xy_to_render_target(window, event.button.x,event.button.y, &cx, &cy) )
11901339            {
11911340               ui_input_push_mouse_down_event(machine, window->target, cx, cy);
r3841r3842
12071356         }
12081357         break;
12091358      case SDL_MOUSEBUTTONUP:
1210         devinfo = mouse_list;
1359         devinfo = generic_device_find_index(mouse_list, mouse_map.logical[event.button.which]);
12111360         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);
12121362
12131363         if (event.button.button == 1)
12141364         {
12151365            int cx, cy;
1216            sdl_window_info *window = GET_WINDOW(&event.button);
1366            sdl_window_info *window = GET_FOCUS_WINDOW(&event.button);
12171367           
12181368            if (window != NULL && window->xy_to_render_target(window, event.button.x,event.button.y, &cx, &cy) )
12191369            {
r3841r3842
12221372         }
12231373         break;
12241374      case SDL_MOUSEMOTION:
1225         devinfo = mouse_list;
1375         devinfo = generic_device_find_index(mouse_list, mouse_map.logical[event.motion.which]);
12261376#if (SDL_VERSION_ATLEAST(1,3,0))
12271377         // 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);
12281379         devinfo->mouse.lX += event.motion.xrel * INPUT_RELATIVE_PER_PIXEL;
12291380         devinfo->mouse.lY += event.motion.yrel * INPUT_RELATIVE_PER_PIXEL;
12301381#else
r3841r3842
12331384#endif
12341385         {
12351386            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
12381389            if (window != NULL && window->xy_to_render_target(window, event.motion.x, event.motion.y, &cx, &cy) )
12391390               ui_input_push_mouse_move_event(machine, window->target, cx, cy);
12401391         }
r3841r3842
12441395         app_has_mouse_focus = event.active.gain;
12451396         if (!event.active.gain)
12461397         {
1247            sdl_window_info *window = GET_WINDOW(&event.motion);
1398            sdl_window_info *window = GET_FOCUS_WINDOW(&event.motion);
12481399            ui_input_push_mouse_leave_event(machine, window->target);
12491400         }
12501401         break;
r3841r3842
12581409      case SDL_TEXTINPUT:
12591410         if (*event.text.text)
12601411         {
1261            sdl_window_info *window = GET_WINDOW(&event.text);
1412            sdl_window_info *window = GET_FOCUS_WINDOW(&event.text);
12621413            unicode_char result;
12631414            if (window != NULL )
12641415            {
r3841r3842
12841435            ui_input_push_mouse_leave_event(machine, window->target);
12851436            app_has_mouse_focus = 0;
12861437            break;
1287           
12881438         }
12891439         case SDL_WINDOWEVENT_RESIZED:
12901440            if (event.window.data1 != window->width || event.window.data2 != window->height)
r3841r3842
13081458   }
13091459}
13101460
1461   
13111462//============================================================
13121463//  sdlinput_release_keys
13131464//============================================================
13141465
1466
13151467void  sdlinput_release_keys(running_machine *machine)
13161468{
13171469   // FIXME: SDL >= 1.3 will nuke the window event buffer when
r3841r3842
13191471   // state when a window is destroyed and recreated.
13201472#if (SDL_VERSION_ATLEAST(1,3,0))
13211473   device_info *devinfo;
1474   int index;
13221475
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;
13251481      memset(&devinfo->keyboard.state, 0, sizeof(devinfo->keyboard.state));
1482   }
13261483#endif   
13271484}
13281485
1486
13291487//============================================================
13301488//  sdlinput_should_hide_mouse
13311489//============================================================
r3841r3842
15001658   }
15011659}
15021660
1661
15031662//============================================================
15041663//  device_list_reset_devices
15051664//============================================================
r3841r3842
15121671      generic_device_reset(curdev);
15131672}
15141673
1674
15151675//============================================================
15161676//  device_list_free_devices
15171677//============================================================
r3841r3842
15291689   *devlist_head = NULL;
15301690}
15311691
1692
15321693//============================================================
15331694//  generic_device_alloc
15341695//============================================================
r3841r3842
16031764   return -1;
16041765}
16051766
1767
16061768static device_info *generic_device_find_index(device_info *devlist_head, int index)
16071769{
16081770   device_info *orig_head = devlist_head;
src/osd/sdl/drawsdl.c
r3841r3842
410410         width, height, sdl->extra_flags);
411411   SDL_ShowWindow(window->window_id);
412412   
413   SDL_SetWindowFullscreen(window->window_id, window->fullscreen);
414   SDL_GetWindowSize(window->window_id, &window->width, &window->height);     
415   SDL_RaiseWindow(window->window_id);
416   
417   /* FIXME: Bug in SDL 1.3 */
418   if (window->fullscreen)
419      SDL_SetWindowGrab(window->window_id, 1);
420
413421   // create a texture
414   SDL_CreateRenderer(window->window_id, -1, SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTDISCARD);
422   
423   if (options_get_bool(mame_options(), SDLOPTION_WAITVSYNC))   
424      SDL_CreateRenderer(window->window_id, -1, SDL_RENDERER_PRESENTFLIP2 | SDL_RENDERER_PRESENTDISCARD | SDL_RENDERER_PRESENTVSYNC);
425   else
426      SDL_CreateRenderer(window->window_id, -1, SDL_RENDERER_PRESENTFLIP2 | SDL_RENDERER_PRESENTDISCARD);
427     
415428    SDL_SelectRenderer(window->window_id);
416429   
417430    {
r3841r3842
440453       }
441454    }
442455   
443   SDL_SetWindowFullscreen(window->window_id, window->fullscreen);
444   SDL_GetWindowSize(window->window_id, &window->width, &window->height);     
445   SDL_RaiseWindow(window->window_id);
446456   setup_texture(window, width, height);
447457#else
448458   sdl->extra_flags = (window->fullscreen ?  SDL_FULLSCREEN : SDL_RESIZABLE);
src/osd/sdl/window.c
r3841r3842
703703   {
704704      //FIXME: SDL1.3: really broken: the whole SDL code
705705      //       will only work correct with relative mouse movements ...
706      //SDL_SetRelativeMouseMode
706707      if (!window->fullscreen && !sdlinput_should_hide_mouse(machine))
707708      {
708709         SDL_ShowCursor(SDL_ENABLE);
r3841r3842
768769   window->depth = config->depth;
769770   window->refresh = config->refresh;
770771   window->monitor = monitor;
772   window->machine = machine;
771773   
772774   //FIXME: these should be per_window in config-> or even better a bit set
773775   window->fullscreen = !video_config.windowed;
src/osd/sdl/window.h
r3841r3842
8989   // Pointer to next window
9090   sdl_window_info *   next;
9191   
92   // Pointer to machine
93   running_machine *   machine;
94   
9295   // Draw Callbacks
9396   int (*create)(sdl_window_info *window, int width, int height);
9497   void (*resize)(sdl_window_info *window, int width, int height);
src/osd/sdl/sdlsync.c
r3841r3842
4444#define pthread_self    _gettid
4545#endif
4646
47#if THREAD_COOPERATIVE
47#ifndef NO_THREAD_COOPERATIVE
4848typedef struct _hidden_mutex_t hidden_mutex_t;
4949struct _hidden_mutex_t {
5050   pthread_mutex_t id;
r3841r3842
8787};
8888
8989
90#if THREAD_COOPERATIVE
90#ifndef NO_THREAD_COOPERATIVE
9191
9292//============================================================
9393//  osd_lock_alloc
r3841r3842
586586
587587int osd_thread_cpu_affinity(osd_thread *thread, UINT32 mask)
588588{
589#if THREAD_COOPERATIVE
589#if !defined(NO_THREAD_COOPERATIVE) && !defined(NO_AFFINITY_NP)
590590   cpu_set_t   cmask;
591591   pthread_t   lthread;
592592   int         bitnum;
r3841r3842
603603   
604604   if (pthread_setaffinity_np(lthread, sizeof(cmask), &cmask) <0)
605605   {
606      // Not available during link in all targets
606      /* Not available during link in all targets */
607607      fprintf(stderr, "error %d setting cpu affinity to mask %08x", errno, mask);
608608      return FALSE;
609609   }
r3841r3842
769769}
770770
771771#endif  /* SDLMAME_OS2 */
772#else   // SDLMAME_WIN32
772#else   /* SDLMAME_WIN32 */
773773#include "../windows/winsync.c"
774774#endif
775775
src/osd/sdl/sdlsync.h
r3841r3842
1414
1515#ifndef SDLMAME_WIN32
1616
17#if (defined SDLMAME_MACOSX) || (defined SDLMAME_FREEBSD) || (defined SDLMAME_SOLARIS) || (defined SDLMAME_OS2)
18#define THREAD_COOPERATIVE      (0)
19#else
20#define THREAD_COOPERATIVE      (1)
21#endif
22
2317/***************************************************************************
2418    SYNCHRONIZATION INTERFACES - Events
2519***************************************************************************/
r3841r3842
2822
2923typedef struct _osd_event osd_event;
3024
25
3126/*-----------------------------------------------------------------------------
3227    osd_lock_event_alloc: allocate a new event
3328
r3841r3842
4439-----------------------------------------------------------------------------*/
4540osd_event *osd_event_alloc(int manualreset, int initialstate);
4641
42
4743/*-----------------------------------------------------------------------------
4844    osd_event_wait: wait for an event to be signalled
4945
r3841r3842
6157-----------------------------------------------------------------------------*/
6258int osd_event_wait(osd_event *event, osd_ticks_t timeout);
6359
60
6461/*-----------------------------------------------------------------------------
6562    osd_event_reset: reset an event to non-signalled state
6663
r3841r3842
7471-----------------------------------------------------------------------------*/
7572void osd_event_reset(osd_event *event);
7673
74
7775/*-----------------------------------------------------------------------------
7876    osd_event_set: set an event to signalled state
7977
r3841r3842
113111/* osd_thread is an opaque type which represents a thread */
114112typedef struct _osd_thread osd_thread;
115113
114
116115/* osd_thread_callback is a callback function that will be called from the thread */
117116typedef void *(*osd_thread_callback)(void *param);
118117
r3841r3842
146145-----------------------------------------------------------------------------*/
147146int osd_thread_adjust_priority(osd_thread *thread, int adjust);
148147
148
149149/*-----------------------------------------------------------------------------
150150    osd_thread_cpu_affinity: change cpu affinity of a thread
151151
r3841r3842
162162-----------------------------------------------------------------------------*/
163163int osd_thread_cpu_affinity(osd_thread *thread, UINT32 mask);
164164
165
165166/*-----------------------------------------------------------------------------
166167    osd_thread_wait_free: wait for thread to finish and free resources
167168
src/osd/sdl/sdlwork.c
r3841r3842
4040#define SDLENV_CPUMASKS               "OSDCPUMASKS"
4141
4242#define INFINITE            (osd_ticks_per_second() *  (osd_ticks_t) 10000)
43#if THREAD_COOPERATIVE
43#ifndef NO_THREAD_COOPERATIVE
4444//FIXME: depends on <THREADS>/<PHYS PROCESSORS>
4545#define SPIN_LOOP_TIME         (osd_ticks_per_second() / 10000)
4646//#define SPIN_LOOP_TIME         ((osd_ticks_t) 0)
r3841r3842
7272typedef struct _scalable_lock scalable_lock;
7373struct _scalable_lock
7474{
75#if THREAD_COOPERATIVE
75#ifndef NO_THREAD_COOPERATIVE
7676   osd_lock         *lock;
7777#else
7878   struct
r3841r3842
146146//============================================================
147147
148148static int effective_num_processors(void);
149#if THREAD_COOPERATIVE
149#ifndef NO_THREAD_COOPERATIVE
150150static UINT32 effective_cpu_mask(int index);
151151#endif
152152static void * worker_thread_entry(void *param);
r3841r3842
186186
187187INLINE void scalable_lock_init(scalable_lock *lock)
188188{
189#if THREAD_COOPERATIVE
189#ifndef NO_THREAD_COOPERATIVE
190190   lock->lock = osd_lock_alloc();
191191#else
192192   memset(lock, 0, sizeof(*lock));
r3841r3842
197197
198198INLINE INT32 scalable_lock_acquire(scalable_lock *lock)
199199{
200#if THREAD_COOPERATIVE
200#ifndef NO_THREAD_COOPERATIVE
201201   osd_lock_acquire(lock->lock);
202202   return 0;
203203#else
r3841r3842
259259
260260INLINE void scalable_lock_release(scalable_lock *lock, INT32 myslot)
261261{
262#if THREAD_COOPERATIVE
262#ifndef NO_THREAD_COOPERATIVE
263263   osd_lock_release(lock->lock);
264264   return;
265265#else
r3841r3842
282282
283283INLINE void scalable_lock_free(scalable_lock *lock)
284284{
285#if THREAD_COOPERATIVE
285#ifndef NO_THREAD_COOPERATIVE
286286   osd_lock_free(lock->lock);
287287#endif
288288}
r3841r3842
360360      else
361361         osd_thread_adjust_priority(thread->handle, 0);   // TODO: specify appropriate priority
362362
363#if THREAD_COOPERATIVE
363#ifndef NO_THREAD_COOPERATIVE
364364      // Bind main thread to cpu 0
365365      osd_thread_cpu_affinity(NULL, effective_cpu_mask(0));
366366     
r3841r3842
724724//  effective_cpu_mask
725725//============================================================
726726
727#if THREAD_COOPERATIVE
727#ifndef NO_THREAD_COOPERATIVE
728728static UINT32 effective_cpu_mask(int index)
729729{
730730   char    *s;
src/osd/sdl/sdlmain.c
r3841r3842
202202
203203   // joystick mapping
204204   { 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" },
208214
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
209236   // SDL low level driver options
210237   { 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" },
212239#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" },
214241#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" },
216243#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" },
218245#endif
219246
220247   // End of list
r3841r3842
414441   mame_printf_verbose("Build version:      %s\n", build_version);
415442   mame_printf_verbose("Build architecure:  ");
416443   MACRO_VERBOSE(SDLMAME_ARCH);
444   MACRO_VERBOSE(DISTRO);
417445   mame_printf_verbose("\n");
418446   mame_printf_verbose("Build defines:      ");
419447   MACRO_VERBOSE(SDLMAME_UNIX);
r3841r3842
451479   MACRO_VERBOSE(__ppc__);
452480   MACRO_VERBOSE(__ppc64__);
453481   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");
454486}
455487
456488//============================================================
489//   osd_sdl_info
490//============================================================
491
492static 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//============================================================
457541//   osd_init
458542//============================================================
459543
r3841r3842
505589         ShowError("Could not initialize SDL", SDL_GetError());
506590         exit(-1);
507591      }
592      osd_sdl_info();
508593   }
509594   // must be before sdlvideo_init!
510595   add_exit_callback(machine, osd_exit);
src/osd/sdl/osdsdl.h
r3841r3842
99     * SDL1.3/X11: Some compound keys, e.g. "'" are not supported by SDL driver
1010     * SDL1.3/X11: No -switchres because SDL does not support it right now.
1111     * SDL1.3/directfb: -switchres broken for directfb >= 1.2.0/works with 1.0.
12     * Need to submit the directfb driver to the SDL team
1312     * SDL1.3: sdlvideofps does not take -numscreens>1 into account.
1413
14   - fixed yuv issues (firefox) / this was a bug I introduced
15   - removed deprecat.h from output.c
16   - Separated keyboard and mouse initialization into separate functions
17   - added _FORTIFY_SOURCE to verbose compiler define output.
18   - remove MAX_CPU from debugwin.c
19   - fixed vsync handling in SDL1.3 in soft/opengl drivers
20   - "waitvsync" also supported by "soft" driver in SDL1.3
21   - multiple mice and keyboards supported in SDL1.3
22   - support for DISTRO= make option
23   - got rid of "-joymap" and "-joymap_file"
24   - add -joy_idx[0-7] -keyb_idx[0-7] -mouse_idx[0-7] which
25     specify, which device is allocated to to e.g. Mouse 1, Mouse 2, ...
26   - moved define of THREAD_COOPERATIVE into sdl.mak and renamed to
27     NO_THREAD_COOPERATIVE. Changed references to #ifndef
28   - define NO_DEBUGGER in sdl.mak
29   - Solaris now uses -DNO_AFFINITY_NP
30   - added machine to window_info, removed deprecat.h from drawogl.c
31   
1532   - For DEBUG=1 builds, disable input grapping while windowed
1633   - Fixed WIN32 compile
1734     Wrote setenv function since mingw does not provide one.
r3841r3842
217234#define SDLOPTION_WAITVSYNC            "waitvsync"
218235#define SDLOPTION_KEYMAP            "keymap"
219236#define SDLOPTION_KEYMAP_FILE         "keymap_file"
220#define SDLOPTION_JOYMAP            "remapjoys"
221#define SDLOPTION_JOYMAP_FILE         "remapjoyfile"
222237#define SDLOPTION_UIMODEKEY            "uimodekey"
223#define SDLOPTION_SIXAXIS            "sixaxis"
224238#define SDLOPTION_OSLOG               "oslog"
225239
240#define SDLOPTION_SIXAXIS            "sixaxis"
241#define SDLOPTION_JOYINDEX            "joy_idx" 
242#define SDLOPTION_KEYBINDEX            "keyb_idx" 
243#define SDLOPTION_MOUSEINDEX         "mouse_index" 
244
226245#define SDLOPTION_SHADER_MAME(x)      "glsl_shader_mame" x
227246#define SDLOPTION_SHADER_SCREEN(x)      "glsl_shader_screen" x
228247#define SDLOPTION_GLSL_FILTER         "gl_glsl_filter"
r3841r3842
245264#define SDLOPTVAL_OPENGL16            "opengl16"
246265#define SDLOPTVAL_SOFT               "soft"
247266
248#if 0
249/* FIXME: Remove me */
250#define SDLOPTVAL_HWBLIT            "hwblit"
251#define SDLOPTVAL_HWBEST            "hwbest"
252#define SDLOPTVAL_YV12               "yv12"
253#define SDLOPTVAL_YV12x2            "yv12x2"
254#define SDLOPTVAL_YUY2               "yuy2"
255#define SDLOPTVAL_YUY2x2            "yuy2x2"
256#endif
267#define SDLMAME_LED(x)               "led" #x
257268
258#define SDLMAME_LED(x)                  "led" #x
259
260269// read by sdlmame
261270
262271#define SDLENV_DESKTOPDIM            "SDLMAME_DESKTOPDIM"
r3841r3842
271280#define SDLENV_AUDIODRIVER            "SDL_AUDIODRIVER"
272281#define SDLENV_RENDERDRIVER            "SDL_VIDEO_RENDERER"
273282
274#define SDLMAME_SOUND_LOG               "sound.log"
283#define SDLMAME_SOUND_LOG            "sound.log"
275284
276285#ifdef SDLMAME_MACOSX
277286/* Vas Crabb: Default GL-lib for MACOSX */

Previous 15994 Revisions Next


© 1998-2018 The MESS Team