Previous 15994 Revisions Next

r3030 Saturday 9th August, 2008 at 01:54:56 UTC by R. Belmont
[SDLMESS] Sync with SDLMAME 0.126u4.
[ROOT]makefile.sdl
[src/mess/osd/sdl]sdlmess.c
[src/osd/sdl]debugosx.c debugwin.c debugwin.h drawogl.c drawsdl.c input.c input.h keybled.c osdsdl.h sdl.mak sdlmain.c sdlmisc.c sdlsync.c sdlsync.h sdlwork.c sound.c video.c video.h window.c window.h

src/osd/sdl/sdlmisc.c
r3029r3030
1/* Miscelancelous utility functions
1//============================================================
2//
3//  sdlmisc.c - SDL utility functions
4//
5//  Copyright (c) 1996-2007, Nicola Salmoria and the MAME Team.
6//  Visit http://mamedev.org for licensing and usage restrictions.
7//
8//  SDLMAME by Olivier Galibert and R. Belmont
9//
10//  Note: previous versions of this file were from XMAME and marked as GPL.
11//        all of that code is now gone/rewritten so that attribution has been removed.
12//
13//============================================================
214
3   Copyright 2000 Hans de Goede
4
5   This file and the acompanying files in this directory are free software;
6   you can redistribute them and/or modify them under the terms of the GNU
7   Library General Public License as published by the Free Software Foundation;
8   either version 2 of the License, or (at your option) any later version.
9
10   These files are distributed in the hope that they will be useful,
11   but WITHOUT ANY WARRANTY; without even the implied warranty of
12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13   Library General Public License for more details.
14
15   You should have received a copy of the GNU Library General Public
16   License along with these files; see the file COPYING.LIB.  If not,
17   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18   Boston, MA 02111-1307, USA.
19*/
20/* Changelog
21Version 0.1, February 2000
22-initial release (Hans de Goede)
23Version 0.2, May 2000
24-moved time system headers from .h to .c to avoid header conflicts (Hans de Goede)
25-made uclock a function on systems without gettimeofday too (Hans de Goede)
26-UCLOCKS_PER_SECOND is now always 1000000, instead of making it depent on
27 the system headers. (Hans de Goede)
28*/
2915#include <stdio.h>
3016#include <stdlib.h>
3117#include <string.h>
r3029r3030
5339#include <os2.h>
5440#endif
5541
42//============================================================
43//  osd_alloc_executable
44//
45//  allocates "size" bytes of executable memory.  this must take
46//  things like NX support into account.
47//============================================================
48
5649void *osd_alloc_executable(size_t size)
5750{
5851#if defined(SDLMAME_DARWIN)
5952   return (void *)malloc(size);
53#elif defined(SDLMAME_FREEBSD)
54   return (void *)mmap(0, size, PROT_EXEC|PROT_READ|PROT_WRITE, MAP_ANON|MAP_SHARED, -1, 0);
6055#elif defined(SDLMAME_UNIX)
6156   return (void *)mmap(0, size, PROT_EXEC|PROT_READ|PROT_WRITE, MAP_ANON|MAP_SHARED, 0, 0);
6257#elif defined(SDLMAME_WIN32)
r3029r3030
7166#endif
7267}
7368
69//============================================================
70//  osd_free_executable
71//
72//  frees memory allocated with osd_alloc_executable
73//============================================================
74
7475void osd_free_executable(void *ptr, size_t size)
7576{
7677#ifdef SDLMAME_DARWIN
src/osd/sdl/drawogl.c
r3029r3030
749749   sdl_info *sdl = window->dxdata;
750750
751751#if (SDL_VERSION_ATLEAST(1,3,0))
752   //SDL_GL_MakeCurrent(window->window_id, sdl->gl_context_id);
752753   SDL_SetWindowSize(window->window_id, width, height);
753754   SDL_GetWindowSize(window->window_id, &window->width, &window->height);
754
755   //FIXME: no idea why, but this is necessary to avoid crashes with numscreen>1
756   SDL_GL_DeleteContext(sdl->gl_context_id);
757   sdl->gl_context_id = SDL_GL_CreateContext(window->window_id);
755   sdl->blittimer = 3;
758756#else
759757   SDL_FreeSurface(sdl->sdlsurf);
760758
r3029r3030
762760         SDL_SWSURFACE | SDL_ANYFORMAT | sdl->extra_flags);
763761   window->width = sdl->sdlsurf->w;
764762   window->height = sdl->sdlsurf->h;
765
766763#endif
767764   sdl->init_context = 1;
768765   
r3029r3030
15871584   if (sdl == NULL)
15881585      return;
15891586
1587   // free the memory in the window
1588
1589   drawogl_destroy_all_textures(window);
1590
15901591#if (SDL_VERSION_ATLEAST(1,3,0))
15911592   SDL_GL_DeleteContext(sdl->gl_context_id);
15921593   SDL_DestroyWindow(window->window_id);
r3029r3030
15981599   }
15991600#endif
16001601
1601   // free the memory in the window
1602
1603   drawogl_destroy_all_textures(window);
1604
16051602   free(sdl);
16061603   window->dxdata = NULL;
16071604}
r3029r3030
17611758      texture->borderpix = 0;   // don't border the screen right now, there's a bug
17621759   }
17631760
1764        texture_compute_type_subroutine(sdl, texsource, texture, flags);
1765         
1766        texture_compute_size_subroutine(window, texture, flags, texsource->width, texsource->height,
1767                                        &finalwidth, &finalheight, &finalwidth_create, &finalheight_create);
1761   texture_compute_type_subroutine(sdl, texsource, texture, flags);
1762   
1763   texture_compute_size_subroutine(window, texture, flags, texsource->width, texsource->height,
1764                                   &finalwidth, &finalheight, &finalwidth_create, &finalheight_create);
17681765
17691766   // if we added pixels for the border, and that just barely pushed us over, take it back
17701767   if (texture->borderpix &&
r3029r3030
17731770   {
17741771      texture->borderpix = FALSE;
17751772
1776                texture_compute_type_subroutine(sdl, texsource, texture, flags);
1777                 
1778                texture_compute_size_subroutine(window, texture, flags, texsource->width, texsource->height,
1779                                                &finalwidth, &finalheight, &finalwidth_create, &finalheight_create);
1773      texture_compute_type_subroutine(sdl, texsource, texture, flags);
1774       
1775      texture_compute_size_subroutine(window, texture, flags, texsource->width, texsource->height,
1776                                      &finalwidth, &finalheight, &finalwidth_create, &finalheight_create);
17801777   }
17811778
17821779   // if we're above the max width/height, do what?
1783        if (finalwidth_create > sdl->texture_max_width || finalheight_create > sdl->texture_max_height)
1784        {
1785            static int printed = FALSE;
1786            if (!printed)
1787               mame_printf_warning("Texture too big! (wanted: %dx%d, max is %dx%d)\n", finalwidth_create, finalheight_create, sdl->texture_max_width, sdl->texture_max_height);
1788            printed = TRUE;
1789        }
1780   if (finalwidth_create > sdl->texture_max_width || finalheight_create > sdl->texture_max_height)
1781   {
1782      static int printed = FALSE;
1783      if (!printed)
1784         mame_printf_warning("Texture too big! (wanted: %dx%d, max is %dx%d)\n", finalwidth_create, finalheight_create, sdl->texture_max_width, sdl->texture_max_height);
1785      printed = TRUE;
1786   }
17901787
1791        if(!texture->nocopy || texture->type==TEXTURE_TYPE_DYNAMIC || texture->type==TEXTURE_TYPE_SHADER ||
1792            // any of the mame core's device generated bitmap types:
1793            texture->format==SDL_TEXFORMAT_RGB32  ||
1794            texture->format==SDL_TEXFORMAT_RGB32_PALETTED  ||
1795            texture->format==SDL_TEXFORMAT_RGB15  ||
1796            texture->format==SDL_TEXFORMAT_RGB15_PALETTED  ||
1797            texture->format==SDL_TEXFORMAT_PALETTE16  ||
1798            texture->format==SDL_TEXFORMAT_PALETTE16A
1799            )
1800        {
1801        mame_printf_verbose("GL texture: copy %d, shader %d, dynamic %d, %dx%d %dx%d [%s, Equal: %d, Palette: %d,\n"
1802                       "            scale %dx%d (eff: %d), border %d, pitch %d,%d/%d], colors: %d, bytes/pix %d\n",
1803                !texture->nocopy, texture->type==TEXTURE_TYPE_SHADER, texture->type==TEXTURE_TYPE_DYNAMIC,
1804                finalwidth, finalheight, finalwidth_create, finalheight_create,
1805                texfmt_to_string[texture->format],
1806                (int)texture_copy_properties[texture->format][SDL_TEXFORMAT_SRC_EQUALS_DEST],
1807                (int)texture_copy_properties[texture->format][SDL_TEXFORMAT_SRC_HAS_PALETTE],
1808                texture->xprescale, texture->yprescale, texture->prescale_effect,
1809      texture->borderpix, texsource->rowpixels, finalwidth, sdl->texture_max_width,
1810      sdl->totalColors, (int)texture->texProperties[SDL_TEXFORMAT_PIXEL_SIZE]
1811         );
1812        }
1788   if(!texture->nocopy || texture->type==TEXTURE_TYPE_DYNAMIC || texture->type==TEXTURE_TYPE_SHADER ||
1789       // any of the mame core's device generated bitmap types:
1790       texture->format==SDL_TEXFORMAT_RGB32  ||
1791       texture->format==SDL_TEXFORMAT_RGB32_PALETTED  ||
1792       texture->format==SDL_TEXFORMAT_RGB15  ||
1793       texture->format==SDL_TEXFORMAT_RGB15_PALETTED  ||
1794       texture->format==SDL_TEXFORMAT_PALETTE16  ||
1795       texture->format==SDL_TEXFORMAT_PALETTE16A
1796       )
1797   {
1798      mame_printf_verbose("GL texture: copy %d, shader %d, dynamic %d, %dx%d %dx%d [%s, Equal: %d, Palette: %d,\n"
1799                   "            scale %dx%d (eff: %d), border %d, pitch %d,%d/%d], colors: %d, bytes/pix %d\n",
1800         !texture->nocopy, texture->type==TEXTURE_TYPE_SHADER, texture->type==TEXTURE_TYPE_DYNAMIC,
1801         finalwidth, finalheight, finalwidth_create, finalheight_create,
1802         texfmt_to_string[texture->format],
1803         (int)texture_copy_properties[texture->format][SDL_TEXFORMAT_SRC_EQUALS_DEST],
1804         (int)texture_copy_properties[texture->format][SDL_TEXFORMAT_SRC_HAS_PALETTE],
1805         texture->xprescale, texture->yprescale, texture->prescale_effect,
1806         texture->borderpix, texsource->rowpixels, finalwidth, sdl->texture_max_width,
1807         sdl->totalColors, (int)texture->texProperties[SDL_TEXFORMAT_PIXEL_SIZE]
1808         );
1809   }
18131810
18141811   // set the final values
18151812   texture->rawwidth = finalwidth;
r3029r3030
23092306         texture->format = SDL_TEXFORMAT_ARGB32;
23102307         break;
23112308      case TEXFORMAT_RGB32:
2312                        if (texsource->palette != NULL)
2313                                texture->format = SDL_TEXFORMAT_RGB32_PALETTED;
2314                        else
2315                                texture->format = SDL_TEXFORMAT_RGB32;
2309            if (texsource->palette != NULL)
2310                texture->format = SDL_TEXFORMAT_RGB32_PALETTED;
2311            else
2312                texture->format = SDL_TEXFORMAT_RGB32;
23162313         break;
23172314      case TEXFORMAT_PALETTE16:
23182315         texture->format = SDL_TEXFORMAT_PALETTE16;
23192316         break;
23202317      case TEXFORMAT_RGB15:
2321                        if (texsource->palette != NULL)
2322                                texture->format = SDL_TEXFORMAT_RGB15_PALETTED;
2323                        else
2324                                texture->format = SDL_TEXFORMAT_RGB15;
2325
2318            if (texsource->palette != NULL)
2319                texture->format = SDL_TEXFORMAT_RGB15_PALETTED;
2320            else
2321                texture->format = SDL_TEXFORMAT_RGB15;
23262322         break;
23272323      case TEXFORMAT_PALETTEA16:
23282324         texture->format = SDL_TEXFORMAT_PALETTE16A;
r3029r3030
23512347   if ( texture->type==TEXTURE_TYPE_SHADER )
23522348   {
23532349      if ( texture_shader_create(sdl, window, texsource, texture, flags) )
2354                {
2355                        free(texture);
2356         return NULL;
2357                }
2358        }
2350        {
2351            free(texture);
2352            return NULL;
2353        }
2354   }
23592355   else
23602356   {
23612357      // get a name for this texture
r3029r3030
23632359
23642360      glEnable(texture->texTarget);
23652361
2366                // make sure we're operating on *this* texture
2367                glBindTexture(texture->texTarget, texture->texture);
2362      // make sure we're operating on *this* texture
2363      glBindTexture(texture->texTarget, texture->texture);
2364     
2365      // this doesn't actually upload, it just sets up the PBO's parameters
2366      glTexImage2D(texture->texTarget, 0, texture->texProperties[SDL_TEXFORMAT_INTERNAL],
2367           texture->rawwidth_create, texture->rawheight_create,
2368           texture->borderpix ? 1 : 0,
2369           texture->texProperties[SDL_TEXFORMAT_FORMAT],
2370           texture->texProperties[SDL_TEXFORMAT_TYPE], NULL);
23682371
2369                // this doesn't actually upload, it just sets up the PBO's parameters
2370                glTexImage2D(texture->texTarget, 0, texture->texProperties[SDL_TEXFORMAT_INTERNAL],
2371                     texture->rawwidth_create, texture->rawheight_create,
2372                     texture->borderpix ? 1 : 0,
2373                     texture->texProperties[SDL_TEXFORMAT_FORMAT],
2374                     texture->texProperties[SDL_TEXFORMAT_TYPE], NULL);
2375
23762372      if ((PRIMFLAG_GET_SCREENTEX(flags)) && video_config.filter)
23772373      {
23782374         // screen textures get the user's choice of filtering
r3029r3030
24082404
24092405   if ( texture->type == TEXTURE_TYPE_DYNAMIC )
24102406   {
2411                assert(sdl->usepbo);
2407        assert(sdl->usepbo);
24122408
2413                // create the PBO
2414                pfn_glGenBuffers(1, (GLuint *)&texture->pbo);
2409        // create the PBO
2410        pfn_glGenBuffers(1, (GLuint *)&texture->pbo);
24152411
2416                pfn_glBindBuffer( GL_PIXEL_UNPACK_BUFFER_ARB, texture->pbo);
2412        pfn_glBindBuffer( GL_PIXEL_UNPACK_BUFFER_ARB, texture->pbo);
24172413
2418                // set up the PBO dimension, ..
2414        // set up the PBO dimension, ..
24192415      pfn_glBufferData(GL_PIXEL_UNPACK_BUFFER_ARB,
24202416                       texture->rawwidth * texture->rawheight * texture->texProperties[SDL_TEXFORMAT_PIXEL_SIZE],
24212417             NULL, GL_STREAM_DRAW);
2422        }
2418    }
24232419
2424        if ( !texture->nocopy && texture->type!=TEXTURE_TYPE_DYNAMIC )
2425        {
2426            texture->data = malloc(texture->rawwidth* texture->rawheight * texture->texProperties[SDL_TEXFORMAT_PIXEL_SIZE]);
2427            texture->data_own=TRUE;
2428        }
2420    if ( !texture->nocopy && texture->type!=TEXTURE_TYPE_DYNAMIC )
2421    {
2422        texture->data = malloc(texture->rawwidth* texture->rawheight * texture->texProperties[SDL_TEXFORMAT_PIXEL_SIZE]);
2423        texture->data_own=TRUE;
2424    }
24292425
24302426   if (texture->prescale_effect && !texture_copy_properties[texture->format][SDL_TEXFORMAT_SRC_EQUALS_DEST])
24312427      texture->effectbuf = malloc_or_die(texsource->width * 3 * texture->texProperties[SDL_TEXFORMAT_PIXEL_SIZE]);
r3029r3030
24422438      // Load The Data
24432439      pfn_glBufferData( GL_ARRAY_BUFFER_ARB, 4*2*sizeof(GLfloat), texture->texCoord, GL_STREAM_DRAW );
24442440      glTexCoordPointer( 2, GL_FLOAT, 0, (char *) NULL ); // we are using ARB VBO buffers
2445        } else {
2441   }
2442   else
2443   {
24462444      glTexCoordPointer(2, GL_FLOAT, 0, texture->texCoord);
24472445   }
24482446
r3029r3030
25162514         glTexSubImage2D(texture->texTarget, 0, 0, 0, texture->rawwidth, texture->rawheight,
25172515               texture->texProperties[SDL_TEXFORMAT_FORMAT],
25182516               texture->texProperties[SDL_TEXFORMAT_TYPE], texture->data);
2519      } else {
2517      }
2518      else
2519      {
25202520         glTexSubImage2D(texture->texTarget, 0, 0, 0, texture->rawwidth, texture->rawheight,
25212521               GL_ALPHA, GL_UNSIGNED_SHORT, texture->data);
25222522      }
2523   } else if ( texture->type == TEXTURE_TYPE_DYNAMIC )
2523   }
2524   else if ( texture->type == TEXTURE_TYPE_DYNAMIC )
25242525   {
25252526      glBindTexture(texture->texTarget, texture->texture);
25262527
r3029r3030
25332534      glTexSubImage2D(texture->texTarget, 0, 0, 0, texture->rawwidth, texture->rawheight,
25342535                 texture->texProperties[SDL_TEXFORMAT_FORMAT],
25352536            texture->texProperties[SDL_TEXFORMAT_TYPE], NULL);
2536   } else {
2537   }
2538   else
2539   {
25372540      glBindTexture(texture->texTarget, texture->texture);
25382541
25392542      // give the card a hint
r3029r3030
25422545      else
25432546         glPixelStorei(GL_UNPACK_ROW_LENGTH, texture->rawwidth);
25442547
2545                // and upload the image
2546                glTexSubImage2D(texture->texTarget, 0, 0, 0, texture->rawwidth, texture->rawheight,
2547                      texture->texProperties[SDL_TEXFORMAT_FORMAT],
2548            texture->texProperties[SDL_TEXFORMAT_TYPE], texture->data);
2548      // and upload the image
2549      glTexSubImage2D(texture->texTarget, 0, 0, 0, texture->rawwidth, texture->rawheight,
2550              texture->texProperties[SDL_TEXFORMAT_FORMAT],
2551      texture->texProperties[SDL_TEXFORMAT_TYPE], texture->data);
25492552   }
25502553}
25512554
r3029r3030
25852588
25862589   if ( texture->type != TEXTURE_TYPE_SHADER ||
25872590        ( texture->type == TEXTURE_TYPE_SHADER && shaderIdx<=sdl->glsl_program_mb2sc ) )
2588        {
2591   {
25892592      // compute the U/V scale factors
25902593      if (texture->borderpix)
25912594      {
r3029r3030
26032606         vstart = 0.0f;
26042607         vstop  = (float)(prim->texture.height*texture->yprescale) / (float)texture->rawheight_create;
26052608      }
2606   } else if ( texture->type == TEXTURE_TYPE_SHADER && shaderIdx>sdl->glsl_program_mb2sc )
2609   }
2610   else if ( texture->type == TEXTURE_TYPE_SHADER && shaderIdx>sdl->glsl_program_mb2sc )
26072611   {
26082612      int surf_w_pow2  = get_valid_pow2_value (window->width, texture->texpow2);
26092613      int surf_h_pow2  = get_valid_pow2_value (window->height, texture->texpow2);
r3029r3030
26122616      ustop  = (float)(window->width) / (float)surf_w_pow2;
26132617      vstart = 0.0f;
26142618      vstop  = (float)(window->height) / (float)surf_h_pow2;
2615   } else {
2619   }
2620   else
2621   {
26162622      assert(0); // ??
26172623   }
26182624
r3029r3030
26392645      texture->texCoord[5]=vstart + dv * 0.0f;
26402646      texture->texCoord[6]=ustart + du * 0.0f;
26412647      texture->texCoord[7]=vstart + dv * 0.0f;
2642   } else {
2648   }
2649   else
2650   {
26432651      // transformation: mamebm -> scrn
26442652      texture->texCoord[0]=ustart + du * prim->texcoords.tl.u;
26452653      texture->texCoord[1]=vstart + dv * prim->texcoords.tl.v;
r3029r3030
26702678   if ( shaderIdx<=sdl->glsl_program_mb2sc )
26712679   {
26722680      glBindTexture(texture->texTarget, texture->mpass_texture_mamebm[mpass_src_idx]);
2673   } else {
2681   }
2682   else
2683   {
26742684      glBindTexture(texture->texTarget, texture->mpass_texture_scrn[mpass_src_idx]);
26752685   }
26762686   pfn_glActiveTexture(texture->mpass_textureunit[texture->mpass_dest_idx]);
r3029r3030
26842694      {
26852695         glBindTexture(texture->texTarget, texture->mpass_texture_scrn[texture->mpass_dest_idx]);
26862696         pfn_glBindFramebuffer(GL_FRAMEBUFFER_EXT, texture->mpass_fbo_scrn[texture->mpass_dest_idx]);
2687      } else {
2697      }
2698      else
2699      {
26882700         glBindTexture(texture->texTarget, texture->mpass_texture_mamebm[texture->mpass_dest_idx]);
26892701         pfn_glBindFramebuffer(GL_FRAMEBUFFER_EXT, texture->mpass_fbo_mamebm[texture->mpass_dest_idx]);
26902702      }
r3029r3030
26942706         glPushAttrib(GL_VIEWPORT_BIT);
26952707         GL_CHECK_ERROR_NORMAL();
26962708         glViewport(0.0, 0.0, (GLsizei)texture->rawwidth, (GLsizei)texture->rawheight);
2697      } else if ( shaderIdx==sdl->glsl_program_mb2sc )
2709      }
2710      else if ( shaderIdx==sdl->glsl_program_mb2sc )
26982711      {
26992712         assert ( sdl->glsl_program_mb2sc < sdl->glsl_program_num-1 );
27002713         glPopAttrib(); // glViewport(0.0, 0.0, (GLsizei)window->width, (GLsizei)window->height)
27012714         GL_CHECK_ERROR_NORMAL();
27022715      }
27032716      glClear(GL_COLOR_BUFFER_BIT); // make sure the whole texture is redrawn ..
2704   } else {
2717   }
2718   else
2719   {
27052720      glBindTexture(texture->texTarget, 0);
27062721      pfn_glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0);
27072722
r3029r3030
27592774         if ( GL_CHECK_ERROR_QUIET() ) {
27602775            mame_printf_verbose("GLSL: could not set 'vid_attributes' for shader prog idx %d\n", shaderIdx);
27612776         }
2762      } else {
2777      }
2778      else
2779      {
27632780         mame_printf_verbose("GLSL: could not get render container for screen %d\n", window->start_viewscreen);
27642781      }
27652782   }
r3029r3030
27722789
27732790   // if we didn't find one, create a new texture
27742791   if (texture == NULL && prim->texture.base != NULL)
2775        {
2776                texture = texture_create(sdl, window, &prim->texture, prim->flags);
2792    {
2793            texture = texture_create(sdl, window, &prim->texture, prim->flags);
27772794
2778        } else if (texture != NULL)
2779        {
2795    }
2796   else if (texture != NULL)
2797    {
27802798      if ( texture->type == TEXTURE_TYPE_SHADER )
27812799      {
27822800         pfn_glUseProgramObjectARB(sdl->glsl_program[shaderIdx]); // back to our shader
2783                } else if ( texture->type == TEXTURE_TYPE_DYNAMIC )
2784                {
2785              assert ( sdl->usepbo ) ;
2786                        pfn_glBindBuffer( GL_PIXEL_UNPACK_BUFFER_ARB, texture->pbo);
2787                        glEnable(texture->texTarget);
2788      } else {
2789                        glEnable(texture->texTarget);
2790                }
27912801        }
2802      else if ( texture->type == TEXTURE_TYPE_DYNAMIC )
2803        {
2804           assert ( sdl->usepbo ) ;
2805            pfn_glBindBuffer( GL_PIXEL_UNPACK_BUFFER_ARB, texture->pbo);
2806            glEnable(texture->texTarget);
2807      }
2808      else
2809      {
2810            glEnable(texture->texTarget);
2811        }
2812    }
27922813
2793        if (texture != NULL)
2814    if (texture != NULL)
27942815   {
27952816      if ( texture->type == TEXTURE_TYPE_SHADER )
27962817      {
r3029r3030
28252846          // Load The Data
28262847          pfn_glBufferSubData( GL_ARRAY_BUFFER_ARB, 0, 4*2*sizeof(GLfloat), texture->texCoord );
28272848          glTexCoordPointer( 2, GL_FLOAT, 0, (char *) NULL ); // we are using ARB VBO buffers
2828      } else {
2849      }
2850      else
2851      {
28292852          glTexCoordPointer(2, GL_FLOAT, 0, texture->texCoord);
28302853      }
28312854   }
r3029r3030
28892912static void drawogl_destroy_all_textures(sdl_window_info *window)
28902913{
28912914   sdl_info *sdl = window->dxdata;
2892    int lock=FALSE;
2915   texture_info *next_texture=NULL, *texture = NULL;
2916   int lock=FALSE;
28932917
2894   if ( ! sdl->initialized )
2895   {
2918   if (sdl == NULL)
28962919      return;
2897   }
28982920
2899        if(window->primlist && window->primlist->lock) { lock=TRUE; osd_lock_acquire(window->primlist->lock); }
2900        {
2901                texture_info *next_texture=NULL, *texture = NULL;
2902                sdl_info *sdl = window->dxdata;
2921   if ( !sdl->initialized )
2922      return;
29032923
2904                if (sdl == NULL)
2905                        goto exit;
2924#if (SDL_VERSION_ATLEAST(1,3,0))
2925   SDL_GL_MakeCurrent(window->window_id, sdl->gl_context_id);
2926#endif
2927   
2928   if(window->primlist && window->primlist->lock)
2929   {
2930      lock=TRUE;
2931      osd_lock_acquire(window->primlist->lock);
2932   }
29062933
2907                texture = sdl->texlist;
2934   texture = sdl->texlist;
2935   glFinish();
29082936
2909                glFinish();
2937   texture_all_disable(sdl);
2938   glFinish();
2939   glDisableClientState(GL_VERTEX_ARRAY);
29102940
2911                texture_all_disable(sdl);
2941   while (texture)
2942   {
2943      next_texture = texture->next;
29122944
2913                glFinish();
2945      if(sdl->usevbo)
2946      {
2947         pfn_glDeleteBuffers( 1, &(texture->texCoordBufferName) );
2948         texture->texCoordBufferName=0;
2949       }
2950     
2951      if(sdl->usepbo && texture->pbo)
2952      {
2953         pfn_glDeleteBuffers( 1, (GLuint *)&(texture->pbo) );
2954         texture->pbo=0;
2955      }
2956     
2957      if( sdl->glsl_program_num > 1 )
2958      {
2959         assert(sdl->usefbo);
2960         pfn_glDeleteFramebuffers(2, (GLuint *)&texture->mpass_fbo_mamebm[0]);
2961         glDeleteTextures(2, (GLuint *)&texture->mpass_texture_mamebm[0]);
2962      }
2963     
2964      if ( sdl->glsl_program_mb2sc < sdl->glsl_program_num - 1 )
2965      {
2966         assert(sdl->usefbo);
2967         pfn_glDeleteFramebuffers(2, (GLuint *)&texture->mpass_fbo_scrn[0]);
2968         glDeleteTextures(2, (GLuint *)&texture->mpass_texture_scrn[0]);
2969      }
29142970
2915                glDisableClientState(GL_VERTEX_ARRAY);
2971      if(texture->lut_texture)
2972         glDeleteTextures(1, (GLuint *)&texture->lut_texture);
29162973
2917                while (texture)
2918                {
2919                        next_texture = texture->next;
2920
2921                        if(sdl->usevbo)
2922                        {
2923                            pfn_glDeleteBuffers( 1, &(texture->texCoordBufferName) );
2924                            texture->texCoordBufferName=0;
2925                        }
2926
2927                        if(sdl->usepbo && texture->pbo)
2928                        {
2929                            pfn_glDeleteBuffers( 1, (GLuint *)&(texture->pbo) );
2930                            texture->pbo=0;
2931                        }
2932
2933         if( sdl->glsl_program_num > 1 )
2934         {
2935            assert(sdl->usefbo);
2936            pfn_glDeleteFramebuffers(2, (GLuint *)&texture->mpass_fbo_mamebm[0]);
2937            glDeleteTextures(2, (GLuint *)&texture->mpass_texture_mamebm[0]);
2938         }
2939
2940         if ( sdl->glsl_program_mb2sc < sdl->glsl_program_num - 1 )
2941         {
2942            assert(sdl->usefbo);
2943            pfn_glDeleteFramebuffers(2, (GLuint *)&texture->mpass_fbo_scrn[0]);
2944            glDeleteTextures(2, (GLuint *)&texture->mpass_texture_scrn[0]);
2945         }
2946
2947         if(texture->lut_texture)
2948            glDeleteTextures(1, (GLuint *)&texture->lut_texture);
2949
2950                        glDeleteTextures(1, (GLuint *)&texture->texture);
2951                        if ( texture->data_own )
2952                        {
2953                                free(texture->data);
2954                                texture->data=NULL;
2955                                texture->data_own=FALSE;
2956                        }
2957                        if (texture->effectbuf)
2958                        {
2959                                free(texture->effectbuf);
2960                        }
2961                        free(texture);
2962                        texture = next_texture;
2963                }
2964                sdl->texlist = NULL;
2965
2966      if ( sdl->useglsl )
2974      glDeleteTextures(1, (GLuint *)&texture->texture);
2975      if ( texture->data_own )
29672976      {
2968         glsl_shader_free(sdl->glsl);
2969         sdl->glsl = NULL;
2977         free(texture->data);
2978         texture->data=NULL;
2979         texture->data_own=FALSE;
29702980      }
2981      if (texture->effectbuf)
2982      {
2983         free(texture->effectbuf);
2984      }
2985      free(texture);
2986      texture = next_texture;
2987   }
2988    sdl->texlist = NULL;
29712989
2972      sdl->initialized = 0;
2973        }
2974exit:
2975        if(lock) { osd_lock_release(window->primlist->lock); }
2990   if ( sdl->useglsl )
2991   {
2992      glsl_shader_free(sdl->glsl);
2993      sdl->glsl = NULL;
2994   }
2995   
2996   sdl->initialized = 0;
2997
2998   if (lock)
2999      osd_lock_release(window->primlist->lock);
29763000}
29773001
29783002//============================================================
src/osd/sdl/sdl.mak
r3029r3030
4444# There is no need to play with this option unless you are doing
4545# active development on sdlmame or SDL.
4646
47# SDL_INSTALL_ROOT = /usr/local/sdl13
47SDL_INSTALL_ROOT = /usr/local/sdl13
4848
4949###########################################################################
5050##################   END USER-CONFIGURABLE OPTIONS   ######################
r3029r3030
6868NO_OPENGL = 1
6969endif
7070
71# additional definitions when we are on Solaris
72ifeq ($(TARGETOS),solaris)
73DEFS += -DSDLMAME_X11 -DSDLMAME_UNIX -DSDLMAME_SOLARIS
74endif
75
7176#-------------------------------------------------
7277# compile and linking flags
7378#-------------------------------------------------
r3029r3030
237242endif
238243endif # Unix
239244
245# Solaris: add the necessary object
246ifeq ($(TARGETOS),solaris)
247OSDCOREOBJS += $(SDLOBJ)/debugwin.o
248
249# explicitly add some libs on Solaris
250LIBS += -lSDL -lX11 -lXinerama -lm
251endif # Solaris
252
240253# Win32: add the necessary libraries
241254ifeq ($(TARGETOS),win32)
242255OSDCOREOBJS += $(SDLOBJ)/main.o
src/osd/sdl/sound.c
r3029r3030
8989void sdlaudio_init(running_machine *machine)
9090{
9191   if (LOG_SOUND)
92      sound_log = fopen(SDL_SOUND_LOG, "w");
92      sound_log = fopen(SDLMAME_SOUND_LOG, "w");
9393
9494   // skip if sound disabled
9595   if (machine->sample_rate != 0)
src/osd/sdl/input.c
r3029r3030
169169
170170// deivce list management
171171static void device_list_reset_devices(device_info *devlist_head);
172static void device_list_free_devices(device_info *devlist_head);
172static void device_list_free_devices(device_info **devlist_head);
173173
174174// generic device management
175175static device_info *generic_device_alloc(device_info **devlist_head_ptr, const char *name);
r3029r3030
943943   // SDL 1.2 has only 1 mouse - 1.3+ will also change that, so revisit this then
944944   devinfo = generic_device_alloc(&mouse_list, "System mouse");
945945   devinfo->device = input_device_add(DEVICE_CLASS_MOUSE, devinfo->name, devinfo);
946   mouse_enabled = options_get_bool(mame_options(), OPTION_MOUSE);
946947
947948   // add the axes
948949   input_device_item_add(devinfo->device, "X", &devinfo->mouse.lX, ITEM_ID_XAXIS, generic_axis_get_state);
r3029r3030
987988   osd_lock_free(input_lock);
988989
989990   // free all devices
990   device_list_free_devices(keyboard_list);
991   device_list_free_devices(mouse_list);
992   device_list_free_devices(joystick_list);
991   device_list_free_devices(&keyboard_list);
992   device_list_free_devices(&mouse_list);
993   device_list_free_devices(&joystick_list);
993994}
994995
995996
r3029r3030
10311032   SDL_Event event;
10321033
10331034   osd_lock_acquire(input_lock);
1035#if (SDL_VERSION_ATLEAST(1,3,0))
1036   /* Make sure we get all pending events */
1037   SDL_PumpEvents();
1038#endif
10341039   while(SDL_PollEvent(&event))
10351040   {
10361041      if (event_buf_count < MAX_BUF_EVENTS)
r3029r3030
11141119         devinfo = generic_device_find_index(joystick_list, joy_logical[event.jhat.which]);
11151120         if (devinfo)
11161121         {
1122            // FIXME: change == to x & y != 0
11171123            if (event.jhat.value == SDL_HAT_UP)
11181124            {
11191125               devinfo->joystick.hatsU[event.jhat.hat] = 0x80;
r3029r3030
11951201         break;
11961202      case SDL_MOUSEMOTION:
11971203         devinfo = mouse_list;
1204#if (SDL_VERSION_ATLEAST(1,3,0))
1205         // FIXME: may apply to 1.2 as well ...
1206         devinfo->mouse.lX += event.motion.xrel * INPUT_RELATIVE_PER_PIXEL;
1207         devinfo->mouse.lY += event.motion.yrel * INPUT_RELATIVE_PER_PIXEL;
1208#else
11981209         devinfo->mouse.lX = event.motion.xrel * INPUT_RELATIVE_PER_PIXEL;
1199         devinfo->mouse.lY = event.motion.yrel * INPUT_RELATIVE_PER_PIXEL;
1210         devinfo->mouse.lY = event.motion.yrel * INPUT_RELATIVE_PER_PIXEL;
1211#endif
12001212         {
12011213            int cx=-1, cy=-1;
12021214            sdl_window_info *window = GET_WINDOW(&event.motion);
r3029r3030
12161228      case SDL_TEXTINPUT:
12171229         if (*event.text.text)
12181230         {
1219            sdl_window_info *w = GET_WINDOW(&event.text);
1231            sdl_window_info *window = GET_WINDOW(&event.text);
12201232            unicode_char result;
1221            osd_uchar_from_osdchar(&result, event.text.text, 1);
1222            ui_input_push_char_event(machine, w->target, result);
1233            if (window != NULL )
1234            {
1235               osd_uchar_from_osdchar(&result, event.text.text, 1);
1236               ui_input_push_char_event(machine, window->target, result);
1237            }
12231238         }
12241239         break;
12251240      case SDL_WINDOWEVENT:
r3029r3030
12411256           
12421257         }
12431258         case SDL_WINDOWEVENT_RESIZED:
1244            sdlwindow_resize(window, event.window.data1, event.window.data2);
1259            if (event.window.data1 != window->width || event.window.data2 != window->height)
1260               sdlwindow_resize(window, event.window.data1, event.window.data2);
12451261            /* fall through break; */
12461262         case SDL_WINDOWEVENT_FOCUS_GAINED:
12471263         case SDL_WINDOWEVENT_ENTER:
r3029r3030
12581274   }
12591275}
12601276
1277//============================================================
1278//  sdlinput_release_keys
1279//============================================================
12611280
1281void  sdlinput_release_keys(running_machine *machine)
1282{
1283   // FIXME: SDL >= 1.3 will nuke the window event buffer when
1284   // a window is closed. This will leave keys in a pressed
1285   // state when a window is destroyed and recreated.
1286#if (SDL_VERSION_ATLEAST(1,3,0))
1287   device_info *devinfo;
1288
1289   devinfo = keyboard_list;
1290   if (devinfo != NULL)
1291      memset(&devinfo->keyboard.state, 0, sizeof(devinfo->keyboard.state));
1292#endif   
1293}
1294
12621295//============================================================
12631296//  sdlinput_should_hide_mouse
12641297//============================================================
r3029r3030
13841417         
13851418         // LCTRL-F8 to decrease prescaling effect #
13861419         case IPT_OSD_8:
1387            if (sdl_use_unsupported()) {
1420            if (osd_use_unsupported()) {
13881421               typedesc->token = "DECREASE_EFFECT";
13891422               typedesc->name = "Decrease Effect";
13901423               input_seq_set_2(&typedesc->seq[SEQ_TYPE_STANDARD], KEYCODE_F8, KEYCODE_LCONTROL);
r3029r3030
13921425            break;
13931426         // add a Not lcrtl condition to frameskip decrease
13941427         case IPT_UI_FRAMESKIP_DEC:
1395            if (sdl_use_unsupported())
1428            if (osd_use_unsupported())
13961429               input_seq_set_3(&typedesc->seq[SEQ_TYPE_STANDARD], KEYCODE_F8, SEQCODE_NOT, KEYCODE_LCONTROL);
13971430            break;
13981431         
13991432         // LCTRL-F9 to increase prescaling effect #
14001433         case IPT_OSD_9:
1401            if (sdl_use_unsupported()) {
1434            if (osd_use_unsupported()) {
14021435               typedesc->token = "INCREASE_EFFECT";
14031436               typedesc->name = "Increase Effect";
14041437               input_seq_set_2(&typedesc->seq[SEQ_TYPE_STANDARD], KEYCODE_F9, KEYCODE_LCONTROL);
r3029r3030
14061439            break;
14071440         // add a Not lcrtl condition to frameskip increase
14081441         case IPT_UI_FRAMESKIP_INC:
1409            if (sdl_use_unsupported())
1442            if (osd_use_unsupported())
14101443               input_seq_set_3(&typedesc->seq[SEQ_TYPE_STANDARD], KEYCODE_F9, SEQCODE_NOT, KEYCODE_LCONTROL);
14111444            break;
14121445         
r3029r3030
14461479//  device_list_free_devices
14471480//============================================================
14481481
1449static void device_list_free_devices(device_info *devlist_head)
1482static void device_list_free_devices(device_info **devlist_head)
14501483{
14511484   device_info *curdev, *next;
14521485   
1453   for (curdev = devlist_head; curdev != NULL; )
1486   for (curdev = *devlist_head; curdev != NULL; )
14541487   {
14551488      next = curdev->next;
14561489      generic_device_free(curdev);
14571490      curdev = next;
14581491   }
1492   *devlist_head = NULL;
14591493}
14601494
14611495//============================================================
src/osd/sdl/drawsdl.c
r3029r3030
1818#include "render.h"
1919#include "options.h"
2020#include "driver.h"
21#include "ui.h"
2122
2223// standard SDL headers
2324#include <SDL/SDL.h>
r3029r3030
3839//  MACROS
3940//============================================================
4041
42//#define IS_YUV_MODE(_m)            ((_m) >= VIDEO_SCALE_MODE_YV12 && (_m) <= VIDEO_SCALE_MODE_YUY2X2)
4143
4244//============================================================
4345//  TYPES
4446//============================================================
4547
48typedef struct _sdl_scale_mode sdl_scale_mode;
49
4650/* sdl_info is the information about SDL for the current screen */
4751typedef struct _sdl_info sdl_info;
4852struct _sdl_info
r3029r3030
6973   int               hw_scale_height;
7074   int               last_hofs;
7175   int               last_vofs;
76   int               old_blitwidth;
77   int               old_blitheight;
78
79   // shortcut to scale mode info
80   
81   const sdl_scale_mode      *scale_mode;
7282};
7383
84struct _sdl_scale_mode
85{
86   const char *name;
87   int      is_scale;         /* Scale mode?           */
88   int      is_yuv;            /* Yuv mode?             */
89   int      mult_w;            /* Width multiplier      */
90   int      mult_h;            /* Height multiplier     */
91#if (!SDL_VERSION_ATLEAST(1,3,0))
92   int      extra_flags;      /* Texture/surface flags */
93#else
94   int      sdl_scale_mode;      /* sdl 1.3 scale mode    */
95#endif
96   int      pixel_format;      /* Pixel/Overlay format  */
97   void    (*yuv_blit)(UINT16 *bitmap, sdl_info *sdl, UINT8 *ptr, int pitch);
98};
99
74100//============================================================
75101//  INLINES
76102//============================================================
r3029r3030
113139
114140#if (!SDL_VERSION_ATLEAST(1,3,0))
115141static int shown_video_info = 0;
116static const char *scale_mode_names[] = { "none", "hwblit", "yv12", "yv12x2", "yuy2", "yuy2x2" };
142
143static const sdl_scale_mode scale_modes[] =
144{
145      { "none",    0, 0, 0, 0, SDL_DOUBLEBUF, 0, 0 },
146      { "async",   0, 0, 0, 0, SDL_DOUBLEBUF | SDL_ASYNCBLIT, 0, 0 },
147      { "yv12",    1, 1, 1, 1, 0,              SDL_YV12_OVERLAY, yuv_RGB_to_YV12 },
148      { "yv12x2",  1, 1, 2, 2, 0,              SDL_YV12_OVERLAY, yuv_RGB_to_YV12X2 },
149      { "yuy2",    1, 1, 1, 1, 0,              SDL_YUY2_OVERLAY, yuv_RGB_to_YUY2 },
150      { "yuy2x2",  1, 1, 2, 1, 0,              SDL_YUY2_OVERLAY, yuv_RGB_to_YUY2X2 },
151      { NULL }
152};
153#else
154static const sdl_scale_mode scale_modes[] =
155{
156      { "none",    0, 0, 0, 0, SDL_TEXTURESCALEMODE_NONE, 0, 0 },
157      { "hwblit",  1, 0, 1, 1, SDL_TEXTURESCALEMODE_FAST, 0, 0 },
158      { "hwbest",  1, 0, 1, 1, SDL_TEXTURESCALEMODE_BEST, 0, 0 },
159      { "yv12",    1, 1, 1, 1, SDL_TEXTURESCALEMODE_NONE, SDL_PIXELFORMAT_YV12, yuv_RGB_to_YV12 },
160      { "yv12x2",  1, 1, 2, 2, SDL_TEXTURESCALEMODE_NONE, SDL_PIXELFORMAT_YV12, yuv_RGB_to_YV12X2 },
161      { "yuy2",    1, 1, 1, 1, SDL_TEXTURESCALEMODE_NONE, SDL_PIXELFORMAT_YUY2, yuv_RGB_to_YUY2 },
162      { "yuy2x2",  1, 1, 2, 1, SDL_TEXTURESCALEMODE_NONE, SDL_PIXELFORMAT_YUY2, yuv_RGB_to_YUY2X2 },
163      { NULL }
164};
117165#endif
118166
119167//============================================================
168//  drawsdl_scale_mode
169//============================================================
170
171const char *drawsdl_scale_mode_str(int index)
172{
173   const sdl_scale_mode *sm = scale_modes;
174   
175   while (index>0)
176   {
177      if (sm->name == NULL)
178         return NULL;
179      index--;
180      sm++;
181   }
182   return sm->name;
183};
184
185int drawsdl_scale_mode(const char *s)
186{
187   const sdl_scale_mode *sm = scale_modes;
188   int index;
189   
190   index = 0;
191   while (sm->name != NULL)
192   {
193      if (strcmp(sm->name, s) == 0)
194         return index;
195      index++;
196      sm++;
197   }
198   return -1;
199}
200
201//============================================================
120202//  drawsdl_init
121203//============================================================
122204
r3029r3030
176258static void setup_texture(sdl_window_info *window, int tempwidth, int tempheight)
177259{
178260   sdl_info *   sdl = window->dxdata;
261   const sdl_scale_mode *sdl_sm = sdl->scale_mode;
179262   SDL_DisplayMode mode;
263   UINT32 fmt;
180264   
181265   // Determine preferred pixelformat and set up yuv if necessary
182266   SDL_GetCurrentDisplayMode(&mode);
r3029r3030
186270      free(sdl->yuv_bitmap);
187271      sdl->yuv_bitmap = NULL;   
188272   }
189   
190   switch (window->scale_mode)
273
274   if (sdl_sm->is_scale)
275      render_target_get_minimum_size(window->target, &sdl->hw_scale_width, &sdl->hw_scale_height);
276
277   if (sdl_sm->is_yuv)
278      sdl->yuv_bitmap = malloc_or_die(sdl->hw_scale_width * sdl->hw_scale_height * sizeof(UINT16));
279
280   fmt = (sdl_sm->pixel_format ? sdl_sm->pixel_format : mode.format);
281
282   if (sdl_sm->is_scale)
283      sdl->texture_id = SDL_CreateTexture(fmt, SDL_TEXTUREACCESS_STREAMING,
284            sdl->hw_scale_width * sdl_sm->mult_w, sdl->hw_scale_height * sdl_sm->mult_h);
285   else
191286   {
192      case VIDEO_SCALE_MODE_NONE:
193         sdl->texture_id = SDL_CreateTexture(mode.format, SDL_TEXTUREACCESS_STREAMING,
194               tempwidth, tempheight);
195         SDL_SetTextureScaleMode(sdl->texture_id, SDL_TEXTURESCALEMODE_NONE);
196         break;
197      case VIDEO_SCALE_MODE_HWBLIT:
198         render_target_get_minimum_size(window->target, &sdl->hw_scale_width, &sdl->hw_scale_height);
199         sdl->texture_id = SDL_CreateTexture(mode.format, SDL_TEXTUREACCESS_STREAMING,
200               sdl->hw_scale_width, sdl->hw_scale_height);
201         break;
202      case VIDEO_SCALE_MODE_YV12:
203         render_target_get_minimum_size(window->target, &sdl->hw_scale_width, &sdl->hw_scale_height);
204         sdl->yuv_bitmap = malloc_or_die(sdl->hw_scale_width * sdl->hw_scale_height * sizeof(UINT16));
205         sdl->texture_id = SDL_CreateTexture(SDL_PIXELFORMAT_YV12, SDL_TEXTUREACCESS_STREAMING,
206               sdl->hw_scale_width, sdl->hw_scale_height);
207         break;
208      case VIDEO_SCALE_MODE_YV12X2:
209         render_target_get_minimum_size(window->target, &sdl->hw_scale_width, &sdl->hw_scale_height);
210         sdl->yuv_bitmap = malloc_or_die(sdl->hw_scale_width * sdl->hw_scale_height * sizeof(UINT16));
211         sdl->texture_id = SDL_CreateTexture(SDL_PIXELFORMAT_YV12, SDL_TEXTUREACCESS_STREAMING,
212               sdl->hw_scale_width * 2, sdl->hw_scale_height * 2);
213         break;
214      case VIDEO_SCALE_MODE_YUY2:
215         render_target_get_minimum_size(window->target, &sdl->hw_scale_width, &sdl->hw_scale_height);
216         sdl->yuv_bitmap = malloc_or_die(sdl->hw_scale_width * sdl->hw_scale_height * sizeof(UINT16));
217         sdl->texture_id = SDL_CreateTexture(SDL_PIXELFORMAT_YUY2, SDL_TEXTUREACCESS_STREAMING,
218               sdl->hw_scale_width, sdl->hw_scale_height);
219         break;
220      case VIDEO_SCALE_MODE_YUY2X2:
221         render_target_get_minimum_size(window->target, &sdl->hw_scale_width, &sdl->hw_scale_height);
222         sdl->yuv_bitmap = malloc_or_die(sdl->hw_scale_width * sdl->hw_scale_height * sizeof(UINT16));
223         sdl->texture_id = SDL_CreateTexture(SDL_PIXELFORMAT_YUY2, SDL_TEXTUREACCESS_STREAMING,
224               sdl->hw_scale_width * 2, sdl->hw_scale_height);
225         break;
287      sdl->texture_id = SDL_CreateTexture(fmt, SDL_TEXTUREACCESS_STREAMING,
288            tempwidth, tempheight);
226289   }
290
291   SDL_SetTextureScaleMode(sdl->texture_id, sdl_sm->sdl_scale_mode);
292
227293}
228294#endif
229295
r3029r3030
235301static void yuv_overlay_init(sdl_window_info *window)
236302{
237303   sdl_info *sdl = window->dxdata;
304   const sdl_scale_mode *sdl_sm = sdl->scale_mode;
238305   int minimum_width, minimum_height;
239306
240307   render_target_get_minimum_size(window->target, &minimum_width, &minimum_height);
r3029r3030
248315   {
249316      free(sdl->yuv_bitmap);   
250317   }
318   
319   mame_printf_verbose("SDL: Creating %d x %d YUV-Overlay ...\n", minimum_width, minimum_height);
320
251321   sdl->yuv_bitmap = malloc_or_die(minimum_width*minimum_height*sizeof(UINT16));
252322
253   mame_printf_verbose("SDL: Creating %d x %d YUV-Overlay ...\n", minimum_width, minimum_height);
254   switch (window->scale_mode)
255   {
256      case VIDEO_SCALE_MODE_YV12:
257         sdl->yuvsurf = SDL_CreateYUVOverlay(minimum_width, minimum_height,
258                 SDL_YV12_OVERLAY, sdl->sdlsurf);
259         break;
260      case VIDEO_SCALE_MODE_YV12X2:
261         sdl->yuvsurf = SDL_CreateYUVOverlay(minimum_width*2, minimum_height*2,
262                  SDL_YV12_OVERLAY, sdl->sdlsurf);
263         break;
264      case VIDEO_SCALE_MODE_YUY2:
265         sdl->yuvsurf = SDL_CreateYUVOverlay(minimum_width, minimum_height,
266                  SDL_YUY2_OVERLAY, sdl->sdlsurf);
267         break;
268      case VIDEO_SCALE_MODE_YUY2X2:
269         sdl->yuvsurf = SDL_CreateYUVOverlay(minimum_width*2, minimum_height,
270                  SDL_YUY2_OVERLAY, sdl->sdlsurf);
271         break;
272   }
323   sdl->yuvsurf = SDL_CreateYUVOverlay(minimum_width * sdl_sm->mult_w, minimum_height * sdl_sm->mult_h,
324         sdl_sm->pixel_format, sdl->sdlsurf);
325
273326   if ( sdl->yuvsurf == NULL ) {
274327      mame_printf_error("SDL: Couldn't create SDL_yuv_overlay: %s\n", SDL_GetError());
275328      //return 1;
276329   }
330   
277331   sdl->hw_scale_width = minimum_width;
278332   sdl->hw_scale_height = minimum_height;
279333
280334   if (!shown_video_info)
281335   {
282      mame_printf_verbose("YUV Mode         : %s\n", scale_mode_names[window->scale_mode]);
336      mame_printf_verbose("YUV Mode         : %s\n", sdl_sm->name);
283337      mame_printf_verbose("YUV Overlay Size : %d x %d\n", minimum_width, minimum_height);
284338      mame_printf_verbose("YUV Acceleration : %s\n", sdl->yuvsurf->hw_overlay ? "Hardware" : "Software");
285339      shown_video_info = 1;
r3029r3030
288342#endif
289343
290344//============================================================
345//  drawsdl_show_info
346//============================================================
347
348#if (SDL_VERSION_ATLEAST(1,3,0))
349static void   drawsdl_show_info(sdl_window_info *window, struct SDL_RendererInfo *render_info)
350{
351#define RF_ENTRY(x) {x, #x }
352   static struct {
353      int flag;
354      const char *name;
355   } rflist[] =
356      {
357         RF_ENTRY(SDL_RENDERER_SINGLEBUFFER),
358         RF_ENTRY(SDL_RENDERER_PRESENTCOPY),
359         RF_ENTRY(SDL_RENDERER_PRESENTFLIP2),
360         RF_ENTRY(SDL_RENDERER_PRESENTFLIP3),
361         RF_ENTRY(SDL_RENDERER_PRESENTDISCARD),
362         RF_ENTRY(SDL_RENDERER_PRESENTVSYNC),
363         RF_ENTRY(SDL_RENDERER_ACCELERATED),
364         {-1, NULL}
365      };
366   int i;
367   
368   mame_printf_verbose("window: using renderer %s\n", render_info->name ? render_info->name : "<unknown>");
369   for (i = 0; rflist[i].name != NULL; i++)
370      if (render_info->flags & rflist[i].flag)
371         mame_printf_verbose("renderer: flag %s\n", rflist[i].name);
372}
373#endif
374
375//============================================================
291376//  drawsdl_window_create
292377//============================================================
293378
r3029r3030
301386
302387   window->dxdata = sdl;
303388   
389   sdl->scale_mode = &scale_modes[window->scale_mode];
390   
304391#if (SDL_VERSION_ATLEAST(1,3,0))
305392   sdl->extra_flags = (window->fullscreen ? 
306         SDL_WINDOW_BORDERLESS | SDL_WINDOW_INPUT_FOCUS : SDL_WINDOW_RESIZABLE);
393         SDL_WINDOW_BORDERLESS | SDL_WINDOW_INPUT_FOCUS | SDL_WINDOW_MOUSE_FOCUS
394         | SDL_WINDOW_INPUT_GRABBED : SDL_WINDOW_RESIZABLE);
307395
308396   SDL_SelectVideoDisplay(window->monitor->handle);
309397
r3029r3030
321409   window->window_id = SDL_CreateWindow(window->title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
322410         width, height, sdl->extra_flags);
323411   SDL_ShowWindow(window->window_id);
324   SDL_RaiseWindow(window->window_id);
325412   
326413   // create a texture
327414   SDL_CreateRenderer(window->window_id, -1, SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTDISCARD);
328415    SDL_SelectRenderer(window->window_id);
416   
417    {
418        struct SDL_RendererInfo render_info;
419       SDL_GetRendererInfo(&render_info);
420       
421       drawsdl_show_info(window, &render_info);
422
423       // Check scale mode
424       
425       if (sdl->scale_mode->pixel_format)
426       {
427          int i;
428          int found = 0;
429         
430          for (i=0; i < render_info.num_texture_formats; i++)
431             if (sdl->scale_mode->pixel_format == render_info.texture_formats[i])
432                found = 1;
433         
434          if (!found)
435          {
436             mame_printf_verbose("window: Scale mode %s not supported! Using default.\n", sdl->scale_mode->name);
437             ui_popup_time(3, "Scale mode %s not supported! Using default.", sdl->scale_mode->name);
438             sdl->scale_mode = &scale_modes[0];
439          }
440       }
441    }
442   
329443   SDL_SetWindowFullscreen(window->window_id, window->fullscreen);
330   SDL_GetWindowSize(window->window_id, &window->width, &window->height);
444   SDL_GetWindowSize(window->window_id, &window->width, &window->height);     
445   SDL_RaiseWindow(window->window_id);
331446   setup_texture(window, width, height);
332447#else
333448   sdl->extra_flags = (window->fullscreen ?  SDL_FULLSCREEN : SDL_RESIZABLE);
334   // create the SDL surface (which creates the window in windowed mode)
335   if (!IS_YUV_MODE(window->scale_mode))
336      sdl->extra_flags |= SDL_DOUBLEBUF;
337449
450   sdl->extra_flags |= sdl->scale_mode->extra_flags;
451
338452   sdl->sdlsurf = SDL_SetVideoMode(width, height,
339453               0, SDL_SWSURFACE | SDL_ANYFORMAT | sdl->extra_flags);
340454
r3029r3030
344458   window->width = sdl->sdlsurf->w;
345459   window->height = sdl->sdlsurf->h;
346460   
347   if (IS_YUV_MODE(window->scale_mode))
348   {
461   if (sdl->scale_mode->is_yuv)
349462      yuv_overlay_init(window);
350   }
351463
352464   // set the window title
353465   SDL_WM_SetCaption(window->title, "SDLMAME");
r3029r3030
365477
366478static void drawsdl_window_resize(sdl_window_info *window, int width, int height)
367479{
368   sdl_info *sdl = window->dxdata;
369480
370481#if (SDL_VERSION_ATLEAST(1,3,0))
371482   SDL_SetWindowSize(window->window_id, width, height);
372483   SDL_GetWindowSize(window->window_id, &window->width, &window->height);
373484
374   // create a texture
375   SDL_SelectRenderer(window->window_id);
376   SDL_DestroyTexture(sdl->texture_id);
485#else
486   sdl_info *sdl = window->dxdata;
377487
378   setup_texture(window, window->width, window->height);
379#else
380488   if (sdl->yuvsurf != NULL)
381489   {
382490      SDL_FreeYUVOverlay(sdl->yuvsurf);
r3029r3030
390498   window->width = sdl->sdlsurf->w;
391499   window->height = sdl->sdlsurf->h;
392500
393   if (IS_YUV_MODE(window->scale_mode))
501   if (sdl->scale_mode->is_yuv)
394502   {
395503      yuv_overlay_init(window);
396504   }
r3029r3030
470578      return 0;
471579   if (*yt<0 || *xt >= window->blitheight)
472580      return 0;
473   if (window->scale_mode == VIDEO_SCALE_MODE_NONE || (!SDL_VERSION_ATLEAST(1,3,0) && !IS_YUV_MODE(window->scale_mode)))
581   if (!sdl->scale_mode->is_scale)
474582   {
475583      return 1;
476584   }
r3029r3030
487595static const render_primitive_list *drawsdl_window_get_primitives(sdl_window_info *window)
488596{
489597   sdl_info *sdl = window->dxdata;
598   
490599   if ((!window->fullscreen) || (video_config.switchres))
491600   {
492601      sdlwindow_blit_surface_size(window, window->width, window->height);
r3029r3030
495604   {
496605      sdlwindow_blit_surface_size(window, window->monitor->center_width, window->monitor->center_height);
497606   }
498   if (window->scale_mode == VIDEO_SCALE_MODE_NONE || (!SDL_VERSION_ATLEAST(1,3,0) && !IS_YUV_MODE(window->scale_mode)))
607   if (!sdl->scale_mode->is_scale)
499608      render_target_set_bounds(window->target, window->blitwidth, window->blitheight, sdlvideo_monitor_get_aspect(window->monitor));
500609   else
501610      render_target_set_bounds(window->target, sdl->hw_scale_width, sdl->hw_scale_height, 0);
r3029r3030
534643   bmask = sdl->sdlsurf->format->Bmask;
535644   amask = sdl->sdlsurf->format->Amask;
536645   
646   if (window->blitwidth != sdl->old_blitwidth || window->blitheight != sdl->old_blitheight)
647   {
648      if (sdl->scale_mode->is_yuv)
649         yuv_overlay_init(window);
650      sdl->old_blitwidth = window->blitwidth;
651      sdl->old_blitheight = window->blitheight;
652      sdl->blittimer = 3;
653   }
654
537655   if (SDL_MUSTLOCK(sdl->sdlsurf)) SDL_LockSurface(sdl->sdlsurf);
538656   // Clear if necessary
539657
r3029r3030
544662   }
545663
546664   
547   if (IS_YUV_MODE(window->scale_mode))
665   if (sdl->scale_mode->is_yuv)
548666   {
549667      SDL_LockYUVOverlay(sdl->yuvsurf);
550668      surfptr = sdl->yuvsurf->pixels[0]; // (UINT8 *) sdl->yuv_bitmap;
r3029r3030
554672      surfptr = (UINT8 *)sdl->sdlsurf->pixels;
555673#else
556674   SDL_SelectRenderer(window->window_id);
675
676   if (window->blitwidth != sdl->old_blitwidth || window->blitheight != sdl->old_blitheight)
557677   {
678      SDL_DestroyTexture(sdl->texture_id);
679      setup_texture(window, window->blitwidth, window->blitheight);
680      sdl->old_blitwidth = window->blitwidth;
681      sdl->old_blitheight = window->blitheight;
682      sdl->blittimer = 3;
683   }
684   
685   {
558686        Uint32 format;
559687        int access, w, h;
560688     
r3029r3030
563691      bpp = bpp / 8; /* convert to bytes per pixels */
564692   }
565693
694   // Clear if necessary
695   if (sdl->blittimer > 0)
696   {
697      /* SDL Underlays need alpha = 0 ! */
698      SDL_RenderFill(0,0,0,0 /*255*/,NULL);
699      sdl->blittimer--;
700   }
701   
566702   SDL_LockTexture(sdl->texture_id, NULL, 1, (void **) &surfptr, &pitch);
567   // Clear if necessary
568   if (window->scale_mode == VIDEO_SCALE_MODE_NONE)
569      if (sdl->blittimer > 0)
570      {   
571         memset(surfptr, 0, window->height * pitch);
572         sdl->blittimer--;
573      }
574703
575704#endif
576705   // get ready to center the image
r3029r3030
617746   osd_lock_acquire(window->primlist->lock);
618747
619748   // render to it
620   if (!IS_YUV_MODE(window->scale_mode))
749   if (!sdl->scale_mode->is_yuv)
621750   {
622751      int mamewidth, mameheight;
623752     
624      if (window->scale_mode == VIDEO_SCALE_MODE_NONE || !SDL_VERSION_ATLEAST(1,3,0))
753      if (!sdl->scale_mode->is_scale)
625754      {
626755         mamewidth = blitwidth;
627756         mameheight = blitheight;
757#if !SDL_VERSION_ATLEAST(1,3,0)
628758         surfptr += ((vofs * pitch) + (hofs * bpp));
759#endif
629760      }
630761      else
631762      {
r3029r3030
660791      assert (sdl->yuv_bitmap != NULL);
661792      assert (surfptr != NULL);
662793      drawsdl_rgb555_draw_primitives(window->primlist->head, sdl->yuv_bitmap, sdl->hw_scale_width, sdl->hw_scale_height, sdl->hw_scale_width);
663      switch (window->scale_mode)
664      {
665         case VIDEO_SCALE_MODE_YV12:
666            yuv_RGB_to_YV12((UINT16 *)sdl->yuv_bitmap, sdl, surfptr, pitch);
667            break;
668         case VIDEO_SCALE_MODE_YV12X2:
669            yuv_RGB_to_YV12X2((UINT16 *)sdl->yuv_bitmap, sdl, surfptr, pitch);
670            break;
671         case VIDEO_SCALE_MODE_YUY2:
672            yuv_RGB_to_YUY2((UINT16 *)sdl->yuv_bitmap, sdl, surfptr, pitch);
673            break;
674         case VIDEO_SCALE_MODE_YUY2X2:
675            yuv_RGB_to_YUY2X2((UINT16 *)sdl->yuv_bitmap, sdl, surfptr, pitch);
676            break;
677      }
794      sdl->scale_mode->yuv_blit((UINT16 *)sdl->yuv_bitmap, sdl, surfptr, pitch);
678795   }
679796
680797   osd_lock_release(window->primlist->lock);
r3029r3030
682799   // unlock and flip
683800#if (!SDL_VERSION_ATLEAST(1,3,0))
684801   if (SDL_MUSTLOCK(sdl->sdlsurf)) SDL_UnlockSurface(sdl->sdlsurf);
685   if (!IS_YUV_MODE(window->scale_mode))
802   if (!sdl->scale_mode->is_yuv)
686803   {
687804      SDL_Flip(sdl->sdlsurf);
688805   }
r3029r3030
699816   }
700817#else
701818   SDL_UnlockTexture(sdl->texture_id);
702   if (window->scale_mode == VIDEO_SCALE_MODE_NONE)
703819   {
704      //SDL_UpdateTexture(sdl->sdltex, NULL, sdl->sdlsurf->pixels, pitch);
705      SDL_RenderCopy(sdl->texture_id, NULL, NULL);
706      SDL_RenderPresent();
707   }
708   else
709   {
710820      SDL_Rect r;
821
711822      r.x=hofs;
712823      r.y=vofs;
713824      r.w=blitwidth;
714825      r.h=blitheight;
826      //printf("blitwidth %d %d - %d %d\n", blitwidth, blitheight, window->width, window->height);
715827      //SDL_UpdateTexture(sdl->sdltex, NULL, sdl->sdlsurf->pixels, pitch);
716828      SDL_RenderCopy(sdl->texture_id, NULL, &r);
717829      SDL_RenderPresent();
src/osd/sdl/input.h
r3029r3030
2525sdl_window_info *sdlinput_get_focus_window(running_machine *machine);
2626
2727void  sdlinput_process_events_buf(running_machine *machine);
28void  sdlinput_release_keys(running_machine *machine);
2829
2930#endif /* __SDLINPUT_H__ */
src/osd/sdl/debugwin.c
r3029r3030
99//
1010//============================================================
1111
12#if !defined(SDLMAME_WIN32) && !defined(SDLMAME_NO_X11)
12#if !defined(SDLMAME_WIN32) && !defined(SDLMAME_NO_X11) && !defined(SDLMAME_SOLARIS)
1313
1414#include <gdk/gdkkeysyms.h>
1515#include <gtk/gtk.h>
r3029r3030
119119{
120120   memorycombo_item **tail = &memorycombo;
121121   UINT32 cpunum, spacenum;
122   const char *rgntag;
122123   int itemnum;
123   const char *rgnname;
124124
125125   // first add all the CPUs' address spaces
126126   for (cpunum = 0; cpunum < MAX_CPU; cpunum++)
r3029r3030
134134               memset(ci, 0, sizeof(*ci));
135135               ci->cpunum = cpunum;
136136               ci->spacenum = spacenum;
137               ci->prefsize = MIN(cpuinfo->space[spacenum].databytes, 4);
138               sprintf(ci->name, "CPU #%d (%s) %s memory", cpunum, cpunum_name(cpunum), address_space_names[spacenum]);
137               ci->prefsize = MIN(cpuinfo->space[spacenum].databytes, 8);
138
139               snprintf(ci->name, ARRAY_LENGTH(ci->name), "CPU #%d \"%s\" (%s) %s memory", cpunum, machine->config->cpu[cpunum].tag, cpunum_name(cpunum), address_space_names[spacenum]);
140
139141               *tail = ci;
140142               tail = &ci->next;
141143            }
142144   }
143145
144146   // then add all the memory regions
145   rgnname = memory_region_next(machine, NULL);
146   while (rgnname != NULL)
147   for (rgntag = memory_region_next(machine, NULL); rgntag != NULL; rgntag = memory_region_next(machine, rgntag))
147148   {
148      UINT8 *base = memory_region(machine, rgnname);
149149      memorycombo_item *ci = malloc_or_die(sizeof(*ci));
150      UINT32 flags = memory_region_flags(machine, rgnname);
151      UINT8 width = 0, little_endian;
150      UINT32 flags = memory_region_flags(machine, rgntag);
151      UINT8 little_endian = ((flags & ROMREGION_ENDIANMASK) == ROMREGION_LE);
152      UINT8 width = 1 << ((flags & ROMREGION_WIDTHMASK) >> 8);
152153
153154      memset(ci, 0, sizeof(*ci));
154      ci->base = base;
155      ci->length = memory_region_length(machine, rgnname);
156      little_endian = ((flags & ROMREGION_ENDIANMASK) == ROMREGION_LE);
157      switch (flags & ROMREGION_WIDTHMASK)
158      {
159         case ROMREGION_8BIT:
160            width = 8;
161            break;
162         case ROMREGION_16BIT:
163            width = 16;
164            break;
165         case ROMREGION_32BIT:
166            width = 32;
167            break;
168         case ROMREGION_64BIT:
169            width = 64;
170            break;
171      }
172      ci->prefsize = MIN(width, 4);
155      ci->base = memory_region(machine, rgntag);
156      ci->length = memory_region_length(machine, rgntag);
157      ci->prefsize = MIN(width, 8);
173158      ci->offset_xor = width - 1;
174159      ci->little_endian = little_endian;
175      strcpy(ci->name, rgnname);
160
161      snprintf(ci->name, ARRAY_LENGTH(ci->name), "Region \"%s\"", rgntag);
162
176163      *tail = ci;
177164      tail = &ci->next;
178
179      // and get the next region
180      rgnname = memory_region_next(machine, rgnname);
181165   }
182166
183167   // finally add all global array symbols
r3029r3030
199183         memset(ci, 0, sizeof(*ci));
200184         ci->base = base;
201185         ci->length = valcount * valsize;
202         ci->prefsize = MIN(valsize, 4);
186         ci->prefsize = MIN(valsize, 8);
203187         ci->little_endian = TRUE;
204188         strcpy(ci->name, strrchr(name, '/') + 1);
205189         *tail = ci;
r3029r3030
386370      debug_view_set_property_UINT32(dmain->registers, DVP_REGS_CPUNUM, cpunum);
387371
388372      // then update the caption
389      sprintf(title, "Debug: %s - CPU %d (%s)", machine->gamedrv->name, cpunum, cpunum_name(cpunum));
373      sprintf(title, "Debug: %s - CPU #%d \"%s\" (%s)", machine->gamedrv->name, cpunum, machine->config->cpu[cpunum].tag, cpunum_name(cpunum));
390374      gtk_window_set_title(GTK_WINDOW(dmain->win), title);
391375      debugmain_update_checks(dmain);
392376   }
r3029r3030
411395   gtk_main_iteration();
412396}
413397
414void debugwin_update_during_game(void)
398void debugwin_update_during_game(running_machine *machine)
415399{
416400   if(dmain)
417401      gtk_main_iteration_do(FALSE);
r3029r3030
594578
595579   disasmwin_update_checks(info);
596580
597   sprintf(title, "Disassembly: %s (%d)", cpunum_name(cpunum), cpunum);
581   sprintf(title, "Disassembly: CPU #%d \"%s\" (%s)", cpunum, Machine->config->cpu[cpunum].tag, cpunum_name(cpunum));
598582   gtk_window_set_title(GTK_WINDOW(info->win), title);
599583}
600584
r3029r3030
704688         if (cpuinfo->space[ADDRESS_SPACE_PROGRAM].databytes)
705689         {
706690            char name[100];
707            sprintf(name, "CPU #%d (%s)", cpunum, cpunum_name(cpunum));
691            sprintf(name, "CPU #%d \"%s\" (%s)", cpunum, Machine->config->cpu[cpunum].tag, cpunum_name(cpunum));
708692            gtk_combo_box_append_text(dis->cpu_w, name);
709693            if(cpunum == curcpu)
710694               citem = item;
r3029r3030
900884{
901885}
902886
903void debugwin_update_during_game(void)
887void debugwin_update_during_game(running_machine *machine)
904888{
905889}
906890
src/osd/sdl/video.c
r3029r3030
111111
112112   // extract data from the options
113113   extract_video_config(machine);
114   
114
115115   // ensure we get called on the way out
116116   add_exit_callback(machine, video_exit);
117117
r3029r3030
223223#endif
224224
225225
226
227226//============================================================
228227//  sdlvideo_monitor_refresh
229228//============================================================
r3029r3030
409408   check_osd_inputs(machine);
410409
411410   if (machine->debug_flags & DEBUG_FLAG_ENABLED)
412      debugwin_update_during_game();
411      debugwin_update_during_game(machine);
413412}
414413
415414
r3029r3030
824823         video_config.glsl_vid_attributes = 0;
825824      }
826825   
827      if (sdl_use_unsupported())
826      if (osd_use_unsupported())
828827         video_config.prescale_effect = options_get_int(mame_options(), SDLOPTION_PRESCALE_EFFECT);
829828      else
830829         video_config.prescale_effect = 0;
r3029r3030
847846#endif
848847   // yuv settings ...
849848   stemp = options_get_string(mame_options(), SDLOPTION_SCALEMODE);
850   if (strcmp(stemp, SDLOPTVAL_NONE) == 0)
851      video_config.scale_mode = VIDEO_SCALE_MODE_NONE;
852   else if (strcmp(stemp, SDLOPTVAL_HWBLIT) == 0)
853      video_config.scale_mode = VIDEO_SCALE_MODE_HWBLIT;
854   else if (strcmp(stemp, SDLOPTVAL_YV12) == 0)
855      video_config.scale_mode = VIDEO_SCALE_MODE_YV12;
856   else if (strcmp(stemp, SDLOPTVAL_YV12x2) == 0)
857      video_config.scale_mode = VIDEO_SCALE_MODE_YV12X2;
858   else if (strcmp(stemp, SDLOPTVAL_YUY2) == 0)
859      video_config.scale_mode = VIDEO_SCALE_MODE_YUY2;
860   else if (strcmp(stemp, SDLOPTVAL_YUY2x2) == 0)
861      video_config.scale_mode = VIDEO_SCALE_MODE_YUY2X2;
862   else
849   video_config.scale_mode = drawsdl_scale_mode(stemp);
850   if (video_config.scale_mode < 0)
863851   {
864852      mame_printf_warning("Invalid yuvmode value %s; reverting to none\n", stemp);
865853      video_config.scale_mode = VIDEO_SCALE_MODE_NONE;
r3029r3030
869857      mame_printf_warning("scalemode is only for -video soft, overriding\n");
870858      video_config.scale_mode = VIDEO_SCALE_MODE_NONE;
871859   }
872   if ( !SDL_VERSION_ATLEAST(1,3,0) && (video_config.mode == VIDEO_MODE_SOFT) && (video_config.scale_mode == VIDEO_SCALE_MODE_HWBLIT) )
873   {
874      mame_printf_warning("scalemode 'hwblit' treated like 'none' in SDL1.2\n");
875   }
876860}
877861
878862
src/osd/sdl/window.c
r3029r3030
9999static int main_threadid;
100100static int window_threadid;
101101
102static const char *scale_mode_names[] = { "none", "hwblit", "yv12", "yv12x2", "yuy2", "yuy2x2" };
103
104
105102// debugger
106103//static int in_background;
107104
r3029r3030
122119//============================================================
123120
124121static void sdlwindow_exit(running_machine *machine);
125static void sdlwindow_video_window_destroy(sdl_window_info *window);
122static void sdlwindow_video_window_destroy(running_machine *machine, sdl_window_info *window);
126123static OSDWORK_CALLBACK( draw_video_contents_wt );
127124static OSDWORK_CALLBACK( sdlwindow_video_window_destroy_wt );
128125static OSDWORK_CALLBACK( sdlwindow_resize_wt );
r3029r3030
262259
263260
264261//============================================================
265//  sdlwindow_exit
266//  (main thread)
262//  sdlwindow_sync
267263//============================================================
268264
269265static void sdlwindow_sync(void)
270266{
271267   if (multithreading_enabled)
272268   {
273      osd_work_queue_wait(work_queue, osd_ticks_per_second()*10);
269      // Fallback
270      while (!osd_work_queue_wait(work_queue, osd_ticks_per_second()*10))
271      {
272         mame_printf_warning("sdlwindow_sync: Sleeping...\n");
273         osd_sleep(100000);
274      }
274275   }
275276}
276277
r3029r3030
299300   {
300301      sdl_window_info *temp = sdl_window_list;
301302      sdl_window_list = temp->next;
302      sdlwindow_video_window_destroy(temp);
303      sdlwindow_video_window_destroy(machine, temp);
303304   }
304305   
305306   // if we're multithreaded, clean up the window thread
r3029r3030
400401      newheight = target_height;
401402   }
402403
404    //FIXME: really necessary to distinguish for yuv_modes ?
403405   if ((render_target_get_layer_config(window->target) & LAYER_CONFIG_ZOOM_TO_SCREEN)
404      && (window->scale_mode == VIDEO_SCALE_MODE_NONE || (!SDL_VERSION_ATLEAST(1,3,0) && !IS_YUV_MODE(window->scale_mode))))
406      && (window->scale_mode == VIDEO_SCALE_MODE_NONE ))
405407      newwidth = window_width;
406408
407409   if ((window->blitwidth != newwidth) || (window->blitheight != newheight))
r3029r3030
511513   }
512514
513515   window->destroy(window);
516   sdlinput_release_keys(wp->machine);
514517
515518   // toggle the window mode
516519   window->fullscreen = !window->fullscreen;   
r3029r3030
528531
529532   clear_worker_param(&wp);
530533   wp.window = window;
534   wp.machine = machine;
531535   
532   //FIMXE: Reset Key state ....
533536   execute_async_wait(&sdlwindow_toggle_full_screen_wt, &wp);
534537}
535538
536539static void sdlwindow_modify_yuv(running_machine *machine, sdl_window_info *window, int dir)
537540{
538541   int new_scale_mode = window->scale_mode;
539
540   if (dir > 0 && window->scale_mode < VIDEO_SCALE_MODE_MAX)
542   worker_param wp;
543   const char *stemp;
544   
545   if (dir > 0)
541546      new_scale_mode = window->scale_mode + 1;
542   if (dir < 0 && window->scale_mode > VIDEO_SCALE_MODE_MIN)
547   if (dir < 0)
543548      new_scale_mode = window->scale_mode - 1;
544549   
545   // FIXME: Changing to yv12 mode from video_mode none does not work
546   if (new_scale_mode != window->scale_mode)
547   {
548      worker_param wp;
550   stemp = drawsdl_scale_mode_str(new_scale_mode);
551   
552   if (stemp==NULL)
553      return;
554   
555   clear_worker_param(&wp);
556   wp.window = window;
557   wp.machine = machine;
558   sdlwindow_sync();
559   execute_async_wait(&sdlwindow_video_window_destroy_wt, &wp);
560     
561   window->scale_mode = new_scale_mode;
562   
563   ui_popup_time(1, "Scale mode %s", stemp);
564   mame_printf_verbose("Scale mode %s\n", stemp);
549565
550      clear_worker_param(&wp);
551      wp.window = window;
552      sdlwindow_sync();
553      execute_async_wait(&sdlwindow_video_window_destroy_wt, &wp);
554         
555      window->scale_mode = new_scale_mode;
556      execute_async_wait(&complete_create_wt, &wp);
557      sdlwindow_sync();
566   sdlwindow_sync();
567   execute_async_wait(&complete_create_wt, &wp);
568   sdlwindow_sync();
558569
559      ui_popup_time(1, "YUV mode %s", scale_mode_names[window->scale_mode]);
560      mame_printf_verbose("YUV mode %s\n", scale_mode_names[window->scale_mode]);
561   }
562570}
563571
564572static OSDWORK_CALLBACK( destroy_all_textures_wt )
r3029r3030
581589   clear_worker_param(&wp);
582590
583591   wp.window = window;
592   wp.machine = machine;
584593
585594   if (dir > 0 && window->prescale < 3)
586595      new_prescale = window->prescale + 1;
r3029r3030
642651void sdlwindow_toggle_draw(running_machine *machine, sdl_window_info *window)
643652{
644653#if USE_OPENGL
654   //FIXME: Not yet working in 1.3
655#if (!SDL_VERSION_ATLEAST(1,3,0))
645656   worker_param wp;
646657
647658   // If we are not fullscreen (windowed) remember our windowed size
r3029r3030
654665   clear_worker_param(&wp);
655666
656667   wp.window = window;
668   wp.machine = machine;
657669   execute_async_wait(&sdlwindow_video_window_destroy_wt, &wp);
658670
659671   window->scale_mode = VIDEO_SCALE_MODE_NONE;
r3029r3030
673685
674686   execute_async_wait(&complete_create_wt, &wp);
675687#endif
688#endif
676689}
677690
678691
r3029r3030
684697static void sdlwindow_update_cursor_state(running_machine *machine, sdl_window_info *window)
685698{
686699#if (SDL_VERSION_ATLEAST(1,3,0))
687   // FIXME: belongs into callback
688700   // do not do mouse capture if the debugger's enabled to avoid
689701   // the possibility of losing control
690702   if (!options_get_bool(mame_options(), OPTION_DEBUG))
691703   {
704      //FIXME: SDL1.3: really broken: the whole SDL code
705      //       will only work correct with relative mouse movements ...
692706      if (!window->fullscreen && !sdlinput_should_hide_mouse(machine))
693707      {
694708         SDL_ShowCursor(SDL_ENABLE);
r3029r3030
701715         if (!SDL_GetWindowGrab(window->window_id))
702716            SDL_SetWindowGrab(window->window_id, 1);
703717      }
718      SDL_SetCursor(NULL); // Force an update in case the underlying driver has changed visibility
704719   }
720
705721#else
706722   // do not do mouse capture if the debugger's enabled to avoid
707723   // the possibility of losing control
r3029r3030
727743#endif
728744}
729745
746
730747//============================================================
731748//  sdlwindow_video_window_create
732749//  (main thread)
r3029r3030
752769   window->refresh = config->refresh;
753770   window->monitor = monitor;
754771   
755   //FIXME: these should be per_window in config->
772   //FIXME: these should be per_window in config-> or even better a bit set
756773   window->fullscreen = !video_config.windowed;
757774   window->prescale = video_config.prescale;
758775   window->prescale_effect = video_config.prescale_effect;
r3029r3030
775792
776793   draw.attach(&draw, window);
777794   
778   // create a lock that we can use to skip blitting
779   window->render_lock = osd_lock_alloc();
795   // create an event that we can use to skip blitting
796   window->rendered_event = osd_event_alloc(FALSE, TRUE);
780797
781798   // load the layout
782799   window->target = render_target_alloc(NULL, FALSE);
r3029r3030
794811      sprintf(window->title, APPNAME ": %s [%s] - Screen %d", machine->gamedrv->description, machine->gamedrv->name, index);
795812
796813   wp->window = window;
814
797815   if (multithreading_enabled)
798816   {
799817      osd_work_item *wi;     
r3029r3030
813831   return 0;
814832
815833error:
816   sdlwindow_video_window_destroy(window);
834   sdlwindow_video_window_destroy(machine, window);
817835   return 1;
818836}
819837
838
820839//============================================================
821840//  sdlwindow_video_window_destroy
822841//  (main thread)
r3029r3030
832851   // free the textures etc
833852   window->destroy(window);
834853
854   // release all keys ...
855   sdlinput_release_keys(wp->machine);
856   
857
835858   free(wp);
836859   return NULL;
837860}
838861
839static void sdlwindow_video_window_destroy(sdl_window_info *window)
862static void sdlwindow_video_window_destroy(running_machine *machine, sdl_window_info *window)
840863{
841864   sdl_window_info **prevptr;
842865   worker_param wp;
r3029r3030
847870      sdlwindow_sync();
848871   }
849872
850   osd_lock_acquire(window->render_lock);
873   //osd_event_wait(window->rendered_event, osd_ticks_per_second()*10);
851874
852875   // remove us from the list
853876   for (prevptr = &sdl_window_list; *prevptr != NULL; prevptr = &(*prevptr)->next)
r3029r3030
860883   // free the textures etc
861884   clear_worker_param(&wp);
862885   wp.window = window;
886   wp.machine = machine;
863887   execute_async_wait(&sdlwindow_video_window_destroy_wt, &wp);
864888
865889   // free the render target, after the textures!
866890   if (window->target != NULL)
867891      render_target_free(window->target);
868892
869   // free the lock
870   osd_lock_free(window->render_lock);
893   // free the event
894   osd_event_free(window->rendered_event);
871895
872896   // free the window itself
873897   free(window);
r3029r3030
953977{
954978
955979   ASSERT_MAIN_THREAD();
956
980   
957981   // adjust the cursor state
958982   sdlwindow_update_cursor_state(machine, window);
959983
960984   // if we're visible and running and not in the middle of a resize, draw
961985   if (window->target != NULL)
962986   {
963      int got_lock = TRUE;
964987      int tempwidth, tempheight;
965988     
966989      // see if the games video mode has changed
r3029r3030
9801003            sdlwindow_resize(window, tempwidth, tempheight);
9811004         }
9821005      }
983     
984      got_lock = osd_lock_try(window->render_lock);
9851006
986      // only render if we were able to get the lock
987      if (got_lock)
1007      // only render if we have been signalled
1008      if (osd_event_wait(window->rendered_event, 0))
9881009      {
9891010         worker_param wp;
9901011         const render_primitive_list *primlist;
9911012
9921013         clear_worker_param(&wp);
9931014
994         // don't hold the lock; we just used it to see if rendering was still happening
995         osd_lock_release(window->render_lock);
996
9971015         // ensure the target bounds are up-to-date, and then get the primitives
9981016         primlist = window->get_primitives(window);
9991017
r3029r3030
10901108   if (window->create(window, tempwidth, tempheight))
10911109      return (void *) &result[1];
10921110
1111   // Make sure we have a consistent state
1112   SDL_ShowCursor(0);
1113   SDL_ShowCursor(1);
1114
10931115   return (void *) &result[0];
10941116}
10951117
r3029r3030
11711193   sdlinput_process_events_buf(wp->machine);
11721194
11731195   window->primlist = wp->list;
1174   osd_lock_acquire(window->render_lock);
11751196
11761197   // if no bitmap, just fill
11771198   if (window->primlist == NULL)
r3029r3030
11851206      else
11861207         window->draw(window, dc, update);
11871208   }
1188   osd_lock_release(window->render_lock);
1209
1210   /* all done, ready for next */
1211   osd_event_set(window->rendered_event);
11891212   free(wp);
11901213   
11911214   return NULL;
src/osd/sdl/debugwin.h
r3029r3030
1717//  PROTOTYPES
1818//============================================================
1919
20void debugwin_update_during_game(void);
20void debugwin_update_during_game(running_machine *machine);
2121
2222#endif
2323
src/osd/sdl/video.h
r3029r3030
2424#define VIDEO_MODE_OPENGL         (1)
2525
2626#define VIDEO_SCALE_MODE_NONE      (0)
27#define VIDEO_SCALE_MODE_HWBLIT      (1)
28#define VIDEO_SCALE_MODE_YV12      (2)
29#define VIDEO_SCALE_MODE_YV12X2      (3)
30#define VIDEO_SCALE_MODE_YUY2      (4)
31#define VIDEO_SCALE_MODE_YUY2X2      (5)
32#define VIDEO_SCALE_MODE_MAX      VIDEO_SCALE_MODE_YUY2X2
33#define VIDEO_SCALE_MODE_MIN      VIDEO_SCALE_MODE_NONE
3427
35#define IS_YUV_MODE(_m)            ((_m) >= VIDEO_SCALE_MODE_YV12 && (_m) <= VIDEO_SCALE_MODE_YUY2X2)
36
3728// texture formats
3829// This used to be an enum, but these are now defines so we can use them as
3930// preprocessor conditionals
src/osd/sdl/window.h
r3029r3030
1515#include <SDL/SDL.h>
1616#include "video.h"
1717#include "render.h"
18#include "sdlsync.h"
1819
1920#include "osd_opengl.h"
2021
r3029r3030
115116   int               startmaximized;
116117
117118   // rendering info
118   osd_lock *         render_lock;
119   osd_event *         rendered_event;
119120   render_target *      target;
120121   const render_primitive_list *primlist;
121122
r3029r3030
182183//============================================================
183184
184185int drawsdl_init(sdl_draw_info *callbacks);
186const char *drawsdl_scale_mode_str(int index);
187int drawsdl_scale_mode(const char *s);
188
189//============================================================
190// PROTOTYPES - drawsdl.c
191//============================================================
192
185193int drawogl_init(sdl_draw_info *callbacks);
186194
187195#endif /* __SDLWINDOW__ */
src/osd/sdl/keybled.c
r3029r3030
2020   if ( SDL_GetWMInfo(&info) && (info.subsystem == SDL_SYSWM_X11) )
2121   {
2222      /* GRR leds 1 and 2 are swapped in X */
23      output_set_notifier(SDL_LED(0), led_change_notify, (void *)2);
24      output_set_notifier(SDL_LED(1), led_change_notify, (void *)1);
25      output_set_notifier(SDL_LED(2), led_change_notify, (void *)3);
23      output_set_notifier(SDLMAME_LED(0), led_change_notify, (void *)2);
24      output_set_notifier(SDLMAME_LED(1), led_change_notify, (void *)1);
25      output_set_notifier(SDLMAME_LED(2), led_change_notify, (void *)3);
2626   }
2727   #endif
2828}
src/osd/sdl/sdlsync.c
r3029r3030
454454            {
455455               printf("Error %d while waiting for pthread_cond_timedwait:  %s\n", ret, strerror(ret));
456456            }
457               
457           
458458         } while (TRUE);
459459      }
460460   }
r3029r3030
471471/*
472472 * The following code has been added
473473 * for demonstration purposes only.
474 * It implements a events without the need
474 * It implements events without the need
475475 * for pthreads. However, it horribly fails, if
476476 * threads > num processors as is the case if you
477477 * enable "-mt"
src/osd/sdl/debugosx.c
r3029r3030
481481//  debugwin_update_during_game
482482//============================================================
483483
484void debugwin_update_during_game(void)
484void debugwin_update_during_game(running_machine *machine)
485485{
486486   osx_init_debugger();
487487
488488   // if we're running live, do some checks
489   if ( ! debug_cpu_is_stopped(Machine) )
489   if ( ! debug_cpu_is_stopped(machine) )
490490   {
491491      // see if the interrupt key is pressed and break if it is
492492      temporarily_fake_that_we_are_not_visible = TRUE;
493      if (ui_input_pressed(Machine, IPT_UI_DEBUG_BREAK))
493      if (ui_input_pressed(machine, IPT_UI_DEBUG_BREAK))
494494      {
495495         debugwin_info *info;
496496         HIViewRef   focuswnd;
r3029r3030
500500            focuswnd = NULL;
501501         }
502502         
503         debugger_break(Machine);
503         debugger_break(machine);
504504         debug_console_printf("User-initiated break\n");
505505
506506         // if we were focused on some window's edit box, reset it to default
r3029r3030
521521}
522522
523523
524#if 0
525524//============================================================
526//  debugwin_is_debugger_visible
527//============================================================
528
529int debugwin_is_debugger_visible(void)
530{
531   debugwin_info *info;
532
533   // a bit of hackiness to allow us to check key sequences even if we are visible
534   if (temporarily_fake_that_we_are_not_visible)
535      return 0;
536
537   // if any one of our windows is visible, return true
538   for (info = window_list; info; info = info->next)
539      if (IsWindowVisible(info->wnd))
540         return 1;
541   return 0;
542}
543#endif
544
545
546//============================================================
547525//  debug_window_create
548526//============================================================
549527
r3029r3030
19351913//  log_create_window
19361914//============================================================
19371915
1938static void log_create_window(void)
1916static void log_create_window(running_machine *machine)
19391917{
19401918   debugwin_info *info;
19411919   char title[256];
r3029r3030
19431921   Rect bounds;
19441922
19451923   // create the window
1946   snprintf(title, ARRAY_LENGTH(title), "Errorlog: %s [%s]", Machine->gamedrv->description, Machine->gamedrv->name);
1924   snprintf(title, ARRAY_LENGTH(title), "Errorlog: %s [%s]", machine->gamedrv->description, machine->gamedrv->name);
19471925   info = debug_window_create(title, NULL);
19481926   if (!info || !debug_view_create(info, 0, DVT_LOG))
19491927      return;
r3029r3030
19901968{
19911969   memorycombo_item **tail = &memorycombo;
19921970   UINT32 cpunum, spacenum;
1971   const char *rgntag;
19931972   int itemnum;
1994   const char *rgnname;
19951973
19961974   // first add all the CPUs' address spaces
19971975   for (cpunum = 0; cpunum < MAX_CPU; cpunum++)
r3029r3030
20051983               memset(ci, 0, sizeof(*ci));
20061984               ci->cpunum = cpunum;
20071985               ci->spacenum = spacenum;
2008               ci->prefsize = MIN(cpuinfo->space[spacenum].databytes, 4);
2009               sprintf(ci->name, "CPU #%d (%s) %s memory", cpunum, cpunum_name(cpunum), address_space_names[spacenum]);
1986               ci->prefsize = MIN(cpuinfo->space[spacenum].databytes, 8);
1987               snprintf(ci->name, ARRAY_LENGTH(ci->name), "CPU #%d \"%s\" (%s) %s memory", cpunum, machine->config->cpu[cpunum].tag, cpunum_name(cpunum), address_space_names[spacenum]);
20101988               *tail = ci;
20111989               tail = &ci->next;
20121990            }
20131991   }
20141992
20151993   // then add all the memory regions
2016   rgnname = memory_region_next(machine, NULL);
2017   while (rgnname != NULL)
1994   for (rgntag = memory_region_next(machine, NULL); rgntag != NULL; rgntag = memory_region_next(machine, rgntag))
20181995   {
2019      UINT8 *base = memory_region(machine, rgnname);
20201996      memorycombo_item *ci = malloc_or_die(sizeof(*ci));
2021      UINT32 flags = memory_region_flags(machine, rgnname);
2022      UINT8 width = 0, little_endian;
1997      UINT32 flags = memory_region_flags(machine, rgntag);
1998      UINT8 little_endian = ((flags & ROMREGION_ENDIANMASK) == ROMREGION_LE);
1999      UINT8 width = 1 << ((flags & ROMREGION_WIDTHMASK) >> 8);
20232000
20242001      memset(ci, 0, sizeof(*ci));
2025      ci->base = base;
2026      ci->length = memory_region_length(machine, rgnname);
2027      little_endian = ((flags & ROMREGION_ENDIANMASK) == ROMREGION_LE);
2028      switch (flags & ROMREGION_WIDTHMASK)
2029      {
2030         case ROMREGION_8BIT:
2031            width = 8;
2032            break;
2033         case ROMREGION_16BIT:
2034            width = 16;
2035            break;
2036         case ROMREGION_32BIT:
2037            width = 32;
2038            break;
2039         case ROMREGION_64BIT:
2040            width = 64;
2041            break;
2042      }
2043      ci->prefsize = MIN(width, 4);
2002      ci->base = memory_region(machine, rgntag);
2003      ci->length = memory_region_length(machine, rgntag);
2004      ci->prefsize = MIN(width, 8);
20442005      ci->offset_xor = width - 1;
20452006      ci->little_endian = little_endian;
2046      strcpy(ci->name, rgnname);
2007
2008      snprintf(ci->name, ARRAY_LENGTH(ci->name), "Regio \"%s\"", rgntag);
2009
20472010      *tail = ci;
20482011      tail = &ci->next;
2049
2050      // and get the next region
2051      rgnname = memory_region_next(machine, rgnname);
20522012   }
20532013
20542014   // finally add all global array symbols
r3029r3030
20702030         memset(ci, 0, sizeof(*ci));
20712031         ci->base = base;
20722032         ci->length = valcount * valsize;
2073         ci->prefsize = MIN(valsize, 4);
2033         ci->prefsize = MIN(valsize, 8);
20742034         ci->little_endian = TRUE;
20752035         strcpy(ci->name, strrchr(name, '/') + 1);
20762036         *tail = ci;
r3029r3030
27252685            char         name[100];
27262686            UInt16         item;
27272687
2728            snprintf(name, ARRAY_LENGTH(name), "CPU #%d (%s)", cpunum, cpunum_name(cpunum));
2688            snprintf(name, ARRAY_LENGTH(name), "CPU #%d \"%s\" (%s)", cpunum, Machine->config->cpu[cpunum].tag, cpunum_name(cpunum));
27292689           
27302690            cfName = CFStringCreateWithCString( NULL, name, CFStringGetSystemEncoding() );
27312691            AppendMenuItemTextWithCFString( popupmenu, cfName, 0, 0, &item );
r3029r3030
31343094   cpunum = debug_view_get_property_UINT32(info->view[0].view, DVP_DASM_CPUNUM);
31353095
31363096   // then update the caption
3137   snprintf(title, ARRAY_LENGTH(title), "Disassembly: %s (%d)", cpunum_name(cpunum), cpunum);
3097   snprintf(title, ARRAY_LENGTH(title), "Disassembly: CPU #%d \"%s\" (%s)", cpunum, Machine->config->cpu[cpunum].tag, cpunum_name(cpunum));
31383098
31393099   cftitle = CFStringCreateWithCString( NULL, title, CFStringGetSystemEncoding() );
31403100   
r3029r3030
34443404      debug_view_set_property_UINT32(main_console->view[1].view, DVP_REGS_CPUNUM, cpunum);
34453405
34463406   // then update the caption
3447   snprintf(title, ARRAY_LENGTH(title), "Debug: %s - CPU %d (%s)", machine->gamedrv->name, cpu_getactivecpu(), activecpu_name());
3407   snprintf(title, ARRAY_LENGTH(title), "Debug: %s - CPU #%d \"%s\" (%s)", machine->gamedrv->name, cpu_getactivecpu(), machine->config->cpu[cpu_getactivecpu()].tag, activecpu_name());
34483408   
34493409   cftitle = CFStringCreateWithCString( NULL, title, CFStringGetSystemEncoding() );
34503410   
r3029r3030
35303490         return 1;
35313491
35323492      case ID_NEW_LOG_WND:
3533         log_create_window();
3493         log_create_window(Machine);
35343494         return 1;
35353495
35363496      case ID_RUN_AND_HIDE:
r3029r3030
36643624           
36653625            case 'l':
36663626            case 'L':
3667               log_create_window();
3627               log_create_window(Machine);
36683628               return 1;
36693629         }
36703630      }
src/osd/sdl/sdlsync.h
r3029r3030
1616
1717#ifndef SDLMAME_OS2
1818
19#if (defined SDLMAME_MACOSX) || (defined SDLMAME_FREEBSD)
19#if (defined SDLMAME_MACOSX) || (defined SDLMAME_FREEBSD) || (defined SDLMAME_SOLARIS)
2020#define THREAD_COOPERATIVE      (0)
2121#else
2222#define THREAD_COOPERATIVE      (1)
src/osd/sdl/sdlwork.c
r3029r3030
504504               (UINT32) total);
505505      }
506506#endif
507   }
507508
508      // free the list
509   // free the list
510   if (queue->thread != NULL)
509511      free(queue->thread);
510   }
511512
512513   // free all the events
513514   if (queue->doneevent != NULL)
r3029r3030
552553
553554osd_work_item *osd_work_item_queue_multiple(osd_work_queue *queue, osd_work_callback callback, INT32 numitems, void *parambase, INT32 paramstep, UINT32 flags)
554555{
555   osd_work_item *itemlist = NULL;
556   osd_work_item *itemlist = NULL, *lastitem = NULL;
556557   osd_work_item **item_tailptr = &itemlist;
557558   INT32 lockslot;
558559   int itemnum;
r3029r3030
588589      item->done = FALSE;
589590
590591      // advance to the next
592      lastitem = item;
591593      *item_tailptr = item;
592594      item_tailptr = &item->next;
593595   }
r3029r3030
633635      begin_timing(queue->thread[0].waittime);
634636   }
635637   // only return the item if it won't get released automatically
636   return (flags & WORK_ITEM_FLAG_AUTO_RELEASE) ? NULL : itemlist;
638   return (flags & WORK_ITEM_FLAG_AUTO_RELEASE) ? NULL : lastitem;
639   //return (flags & WORK_ITEM_FLAG_AUTO_RELEASE) ? NULL : itemlist;
637640}
638641
639642
r3029r3030
654657       osd_event_reset(item->event);
655658
656659   // if we don't have an event, we need to spin (shouldn't ever really happen)
660   // FIXME: there is still a bug in winwork.c. The following is OK.
657661   if (item->event == NULL)
658662   {
659663      osd_ticks_t stopspin = osd_ticks() + timeout;
src/osd/sdl/sdlmain.c
r3029r3030
110110   #if (SDL_VERSION_ATLEAST(1,2,10))
111111   { SDLOPTION_WAITVSYNC,                    "0",        OPTION_BOOLEAN,    "enable waiting for the start of VBLANK before flipping screens; reduces tearing effects" },
112112   #endif
113   { SDLOPTION_SCALEMODE ";sm",         SDLOPTVAL_NONE,  0,                 "Scale mode: none, hwblit, yv12, yuy2, yv12x2, yuy2x2 (-video soft only)" },
113#if (SDL_VERSION_ATLEAST(1,3,0))
114   { SDLOPTION_SCALEMODE ";sm",         SDLOPTVAL_NONE,  0,                 "Scale mode: none, hwblit, hwbest, yv12, yuy2, yv12x2, yuy2x2 (-video soft only)" },
115#else
116   { SDLOPTION_SCALEMODE ";sm",         SDLOPTVAL_NONE,  0,                 "Scale mode: none, async, yv12, yuy2, yv12x2, yuy2x2 (-video soft only)" },
117#endif
114118#if USE_OPENGL
115119   // OpenGL specific options
116120   { NULL,                                   NULL,   OPTION_HEADER,  "OpenGL-SPECIFIC OPTIONS" },
r3029r3030
424428//============================================================
425429//   osd_init
426430//============================================================
431
427432void osd_init(running_machine *machine)
428433{
429434   const char *stemp;
r3029r3030
453458      }
454459   }
455460
461   /* Set the SDL environment variable for drivers wanting to load the
462    * lib at startup.
463    */
464   /* FIXME: move lib loading code from drawogl.c here */
465
466   stemp = options_get_string(mame_options(), SDLOPTION_GL_LIB);
467   if (stemp != NULL && strcmp(stemp, SDLOPTVAL_AUTO) != 0)
468   {
469      setenv("SDL_VIDEO_GL_DRIVER", stemp, 1);
470      mame_printf_verbose("Setting SDL_VIDEO_GL_DRIVER = '%s' ...\n", stemp);
471   }
472   
456473   if (!SDLMAME_INIT_IN_WORKER_THREAD)
457474   {
458475      if (SDL_Init(SDL_INIT_TIMER|SDL_INIT_AUDIO| SDL_INIT_VIDEO| SDL_INIT_JOYSTICK|SDL_INIT_NOPARACHUTE)) {
r3029r3030
482499      fflush(stdout);
483500      exit(-1);
484501   }
485   if (sdl_use_unsupported())
502   if (osd_use_unsupported())
486503      sdlled_init();
487504
488505   sdlinput_init(machine);
src/osd/sdl/osdsdl.h
r3029r3030
33
44/* Notes
55
6   - Known bugs:
7   
8     * SDL1.3/X11: Crash on switch to fullscreen. Bug fix submitted to SDL team.
9     * SDL1.3/X11: Some compound keys, e.g. "'" are not supported by SDL driver
10     * SDL1.3/X11: No -switchres because SDL does not support it right now.
11     * 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
13     * SDL1.3: sdlvideofps does not take -numscreens>1 into account.
14
15   - replaced window->render_lock with event window->rendered_event
16     for multiple windows and "-mt", the old code would allow filling up
17     the workqueue with 1000s of entries, since the lock would not block while
18     another window is rendered. The osd_event establishes a barrier which
19     is only freed if the last window blit operation has finished.
20   - Set SDL_VIDEO_GL_DRIVER if -gl_lib is given. The SDL directfb driver is picky about
21     this. Added reminder: FIXME: move lib loading code from drawogl.c here. This may be
22     used to disable opengl if no library was loaded.
23   - SDL1.3/video=opengl: Fixed windows not being updated after another window was resized
24   - for -verbose, output some information about renderer (-video soft)
25   - initialize mouse_enabled with option "-mouse". Affects both SDL1.2 and SDL1.3
26     This will hide the mouse if you specify "-mouse".
27   - SDL1.2: added blitmode "async" which sets SDL_ASYNCBLIT
28   - SDL1.2: removed blitmodes "hwbest" and "hwblit"
29   - added blitmode "hwbest" for antialiased and smoothed scaling now that the
30     directfb driver supports it. This is also supported by the 1.3 opengl
31     render backend
32   - added sdlinput_release_keys to cope with lost keyboard events in SDL1.3
33   - some identing in drawogl.c
34   - rename sdl_use_unsupported to osd_use_unsupported()
35   - rename SDL_* macros to SDLMAME_* (avoid name clashes)
36   - got rid of VIDEO_SCALE_MODE constants. Scale modes are now handled in drawsdl.c.
37     Starting mame with eg. -video soft -sm yuy2 on X11 no longer crashes.
38   - some more changes to input.c to avoid resize loops (issue for directfb)
39
640   - working ui mouse inputs for SDL1.2 and SDL1.3 incl. yuv modes
741   - added blitmode "hwblit" (SDL1.3) for rgb hardware scaling
842   - rename "-yuvmode" option to "-scalemode"
r3029r3030
161195#define SDLOPTION_CENTERH            "centerh"
162196#define SDLOPTION_CENTERV            "centerv"
163197#define SDLOPTION_PRESCALE            "prescale"
198
199/* FIXME: seems to be donge for a long time */
164200#define SDLOPTION_PRESCALE_EFFECT      "prescale_effect"
201
165202#define SDLOPTION_SCALEMODE            "scalemode"
166203#define SDLOPTION_MULTITHREADING      "multithreading"
167204#define SDLOPTION_WAITVSYNC            "waitvsync"
r3029r3030
195232#define SDLOPTVAL_OPENGL16            "opengl16"
196233#define SDLOPTVAL_SOFT               "soft"
197234
235#if 0
236/* FIXME: Remove me */
198237#define SDLOPTVAL_HWBLIT            "hwblit"
238#define SDLOPTVAL_HWBEST            "hwbest"
199239#define SDLOPTVAL_YV12               "yv12"
200240#define SDLOPTVAL_YV12x2            "yv12x2"
201241#define SDLOPTVAL_YUY2               "yuy2"
202242#define SDLOPTVAL_YUY2x2            "yuy2x2"
243#endif
203244
204#define SDL_LED(x)                  "led" #x
245#define SDLMAME_LED(x)                  "led" #x
205246
206247// read by sdlmame
207248
208249#define SDLENV_DESKTOPDIM            "SDLMAME_DESKTOPDIM"
209250#define SDLENV_VMWARE               "SDLMAME_VMWARE"
210251
211#define sdl_use_unsupported()         (getenv("SDLMAME_UNSUPPORTED") != NULL)
252#define osd_use_unsupported()         (getenv("SDLMAME_UNSUPPORTED") != NULL)
212253
213254// set by sdlmame
214255
r3029r3030
217258#define SDLENV_AUDIODRIVER            "SDL_AUDIODRIVER"
218259#define SDLENV_RENDERDRIVER            "SDL_VIDEO_RENDERER"
219260
220#define SDL_SOUND_LOG               "sound.log"
261#define SDLMAME_SOUND_LOG               "sound.log"
221262
222263#ifdef SDLMAME_MACOSX
223264/* Vas Crabb: Default GL-lib for MACOSX */
src/mess/osd/sdl/sdlmess.c
r3029r3030
2121#include <Carbon/Carbon.h>
2222#endif
2323
24#if defined(SDLMAME_UNIX) && !defined(SDLMAME_MACOSX)
25#include <SDL_timer.h>
26#include <X11/Xlib.h>
27#include <X11/Xatom.h>
28#include <SDL_syswm.h>
29#endif
30
3124//============================================================
3225//   osd_getcurdir
3326//============================================================
makefile.sdl
r3029r3030
11###########################################################################
22#
3#   makefile
3#   makefile.sdl
44#
5#   Core makefile for building MAME and derivatives
5#   Core makefile for building SDLMAME and derivatives
66#
77#   Copyright (c) Nicola Salmoria and the MAME Team.
88#   Visit http://mamedev.org for licensing and usage restrictions.
r3029r3030
366366LDFLAGS =
367367ifneq ($(TARGETOS),macosx)
368368ifneq ($(TARGETOS),os2)
369ifneq ($(TARGETOS),solaris)
369370LDFLAGS = -Wl,--warn-common
370371endif
371372endif
373endif
372374LDFLAGSEMULATOR =
373375
374376# add profiling information for the linker
r3029r3030
528530
529531ifndef EXECUTABLE_DEFINED
530532
533$(VERSIONOBJ): $(DRVLIBS) $(LIBOSD) $(LIBEMU) $(LIBCPU) $(LIBSOUND) $(LIBUTIL) $(EXPAT) $(ZLIB) $(LIBOCORE) $(RESFILE)
534
531535$(EMULATOR): $(VERSIONOBJ) $(DRVLIBS) $(LIBOSD) $(LIBEMU) $(LIBCPU) $(LIBSOUND) $(LIBUTIL) $(EXPAT) $(ZLIB) $(LIBOCORE) $(RESFILE)
532536# always recompile the version string
533537   $(CC) $(CDEFS) $(CFLAGS) -c $(SRC)/version.c -o $(VERSIONOBJ)

Previous 15994 Revisions Next


© 1998-2018 The MESS Team