diff options
Diffstat (limited to 'src/osd/modules')
32 files changed, 1909 insertions, 1922 deletions
diff --git a/src/osd/modules/debugger/debug_module.h b/src/osd/modules/debugger/debug_module.h index 789e511e596..78b15aa41ef 100644 --- a/src/osd/modules/debugger/debug_module.h +++ b/src/osd/modules/debugger/debug_module.h @@ -20,11 +20,11 @@ class debug_module { public: - virtual ~debug_module() { } + virtual ~debug_module() { } - virtual void init_debugger(running_machine &machine) = 0; - virtual void wait_for_debugger(device_t &device, bool firststop) = 0; - virtual void debugger_update() = 0; + virtual void init_debugger(running_machine &machine) = 0; + virtual void wait_for_debugger(device_t &device, bool firststop) = 0; + virtual void debugger_update() = 0; }; diff --git a/src/osd/modules/debugger/debugint.c b/src/osd/modules/debugger/debugint.c index dcf9e80b3e7..3230e032bb8 100644 --- a/src/osd/modules/debugger/debugint.c +++ b/src/osd/modules/debugger/debugint.c @@ -27,23 +27,23 @@ class debug_internal : public osd_module, public debug_module { public: - debug_internal() - : osd_module(OSD_DEBUG_PROVIDER, "internal"), debug_module(), - m_machine(NULL) - { - } + debug_internal() + : osd_module(OSD_DEBUG_PROVIDER, "internal"), debug_module(), + m_machine(NULL) + { + } - virtual ~debug_internal() { } + virtual ~debug_internal() { } - virtual int init() { return 0;} - virtual void exit(); + virtual int init() { return 0;} + virtual void exit(); - virtual void init_debugger(running_machine &machine); - virtual void wait_for_debugger(device_t &device, bool firststop); - virtual void debugger_update(); + virtual void init_debugger(running_machine &machine); + virtual void wait_for_debugger(device_t &device, bool firststop); + virtual void debugger_update(); private: - running_machine *m_machine; + running_machine *m_machine; }; diff --git a/src/osd/modules/debugger/debugqt.c b/src/osd/modules/debugger/debugqt.c index bd1914e1d71..ce675a0180d 100644 --- a/src/osd/modules/debugger/debugqt.c +++ b/src/osd/modules/debugger/debugqt.c @@ -37,23 +37,23 @@ class debug_qt : public osd_module, public debug_module { public: - debug_qt() - : osd_module(OSD_DEBUG_PROVIDER, "qt"), debug_module(), - m_machine(NULL) - { - } + debug_qt() + : osd_module(OSD_DEBUG_PROVIDER, "qt"), debug_module(), + m_machine(NULL) + { + } - virtual ~debug_qt() { } + virtual ~debug_qt() { } - virtual int init() { return 0;} - virtual void exit() { } + virtual int init() { return 0;} + virtual void exit() { } - virtual void init_debugger(running_machine &machine); - virtual void wait_for_debugger(device_t &device, bool firststop); - virtual void debugger_update(); + virtual void init_debugger(running_machine &machine); + virtual void wait_for_debugger(device_t &device, bool firststop); + virtual void debugger_update(); private: - running_machine *m_machine; + running_machine *m_machine; }; //============================================================ @@ -357,7 +357,7 @@ void debug_qt::debugger_update() } #else /* SDLMAME_UNIX */ - MODULE_NOT_SUPPORTED(debug_qt, OSD_DEBUG_PROVIDER, "qt") + MODULE_NOT_SUPPORTED(debug_qt, OSD_DEBUG_PROVIDER, "qt") #endif MODULE_DEFINITION(DEBUG_QT, debug_qt) diff --git a/src/osd/modules/debugger/debugwin.c b/src/osd/modules/debugger/debugwin.c index 5d31bf3cbdc..658731bc09c 100644 --- a/src/osd/modules/debugger/debugwin.c +++ b/src/osd/modules/debugger/debugwin.c @@ -44,23 +44,23 @@ class debugger_windows : public osd_module, public debug_module { public: - debugger_windows() - : osd_module(OSD_DEBUG_PROVIDER, "windows"), debug_module(), - m_machine(NULL) - { - } + debugger_windows() + : osd_module(OSD_DEBUG_PROVIDER, "windows"), debug_module(), + m_machine(NULL) + { + } - virtual ~debugger_windows() { } + virtual ~debugger_windows() { } - virtual int init() { return 0;} - virtual void exit(); + virtual int init() { return 0;} + virtual void exit(); - virtual void init_debugger(running_machine &machine); - virtual void wait_for_debugger(device_t &device, bool firststop); - virtual void debugger_update(); + virtual void init_debugger(running_machine &machine); + virtual void wait_for_debugger(device_t &device, bool firststop); + virtual void debugger_update(); private: - running_machine *m_machine; + running_machine *m_machine; }; //============================================================ // PARAMETERS @@ -3094,7 +3094,7 @@ static void smart_show_all(BOOL show) smart_show_window(info->wnd, show); } #else /* not windows */ - MODULE_NOT_SUPPORTED(debugger_windows, OSD_DEBUG_PROVIDER, "windows") + MODULE_NOT_SUPPORTED(debugger_windows, OSD_DEBUG_PROVIDER, "windows") #endif MODULE_DEFINITION(DEBUG_WINDOWS, debugger_windows) diff --git a/src/osd/modules/debugger/none.c b/src/osd/modules/debugger/none.c index 41e51174f05..7fc671880fd 100644 --- a/src/osd/modules/debugger/none.c +++ b/src/osd/modules/debugger/none.c @@ -12,28 +12,28 @@ class debug_none : public osd_module, public debug_module { public: - debug_none() - : osd_module(OSD_DEBUG_PROVIDER, "none"), debug_module(), - m_machine(NULL) - { - } + debug_none() + : osd_module(OSD_DEBUG_PROVIDER, "none"), debug_module(), + m_machine(NULL) + { + } - virtual ~debug_none() { } + virtual ~debug_none() { } - virtual int init() { return 0;} - virtual void exit() { } + virtual int init() { return 0;} + virtual void exit() { } - virtual void init_debugger(running_machine &machine); - virtual void wait_for_debugger(device_t &device, bool firststop); - virtual void debugger_update(); + virtual void init_debugger(running_machine &machine); + virtual void wait_for_debugger(device_t &device, bool firststop); + virtual void debugger_update(); private: - running_machine *m_machine; + running_machine *m_machine; }; void debug_none::init_debugger(running_machine &machine) { - m_machine = &machine; + m_machine = &machine; } void debug_none::wait_for_debugger(device_t &device, bool firststop) diff --git a/src/osd/modules/font/font_module.h b/src/osd/modules/font/font_module.h index e5e5499a2f5..816b6fc839b 100644 --- a/src/osd/modules/font/font_module.h +++ b/src/osd/modules/font/font_module.h @@ -18,8 +18,8 @@ class font_module { public: - virtual ~font_module() { } - virtual osd_font *font_alloc() = 0; + virtual ~font_module() { } + virtual osd_font *font_alloc() = 0; }; diff --git a/src/osd/modules/font/font_none.c b/src/osd/modules/font/font_none.c index 4d6cdbe48c9..8f19e448be1 100644 --- a/src/osd/modules/font/font_none.c +++ b/src/osd/modules/font/font_none.c @@ -14,17 +14,17 @@ class osd_font_none : public osd_font { public: - virtual ~osd_font_none() {}; + virtual ~osd_font_none() {}; - virtual bool open(const char *font_path, const char *name, int &height); - virtual void close(); - virtual bool get_bitmap(unicode_char chnum, bitmap_argb32 &bitmap, INT32 &width, INT32 &xoffs, INT32 &yoffs); + virtual bool open(const char *font_path, const char *name, int &height); + virtual void close(); + virtual bool get_bitmap(unicode_char chnum, bitmap_argb32 &bitmap, INT32 &width, INT32 &xoffs, INT32 &yoffs); private: }; bool osd_font_none::open(const char *font_path, const char *_name, int &height) { - return false; + return false; } //------------------------------------------------- @@ -46,22 +46,21 @@ void osd_font_none::close() bool osd_font_none::get_bitmap(unicode_char chnum, bitmap_argb32 &bitmap, INT32 &width, INT32 &xoffs, INT32 &yoffs) { - return false; + return false; } class font_none : public osd_module, public font_module { public: - font_none() - : osd_module(OSD_FONT_PROVIDER, "none"), font_module() - { - } + font_none() + : osd_module(OSD_FONT_PROVIDER, "none"), font_module() + { + } - osd_font *font_alloc() - { - return global_alloc(osd_font_none); - } + osd_font *font_alloc() + { + return global_alloc(osd_font_none); + } }; MODULE_DEFINITION(FONT_NONE, font_none) - diff --git a/src/osd/modules/font/font_osx.c b/src/osd/modules/font/font_osx.c index 6e7e62acedf..e7e58b35ad9 100644 --- a/src/osd/modules/font/font_osx.c +++ b/src/osd/modules/font/font_osx.c @@ -26,71 +26,71 @@ class osd_font_osx : public osd_font { public: - virtual ~osd_font_osx() {}; + virtual ~osd_font_osx() {}; - virtual bool open(const char *font_path, const char *name, int &height); - virtual void close(); - virtual bool get_bitmap(unicode_char chnum, bitmap_argb32 &bitmap, INT32 &width, INT32 &xoffs, INT32 &yoffs); + virtual bool open(const char *font_path, const char *name, int &height); + virtual void close(); + virtual bool get_bitmap(unicode_char chnum, bitmap_argb32 &bitmap, INT32 &width, INT32 &xoffs, INT32 &yoffs); private: - CTFontRef m_font; + CTFontRef m_font; }; bool osd_font_osx::open(const char *font_path, const char *_name, int &height) { - CFStringRef font_name = NULL; - CTFontRef ct_font = NULL; - CTFontDescriptorRef font_descriptor; - CGAffineTransform affine_transform = CGAffineTransformIdentity; - - m_font = NULL; - astring name(_name); - printf("FONT NAME %s\n", _name); + CFStringRef font_name = NULL; + CTFontRef ct_font = NULL; + CTFontDescriptorRef font_descriptor; + CGAffineTransform affine_transform = CGAffineTransformIdentity; + + m_font = NULL; + astring name(_name); + printf("FONT NAME %s\n", _name); #if 0 - if (name == "default") - { - name = "LucidaGrande"; - } + if (name == "default") + { + name = "LucidaGrande"; + } #endif - /* handle bdf fonts in the core */ - if (name.len() > 4) - if (name.makeupper().substr(name.len()-4,4) == ".BDF" ) - return false; - - font_name = CFStringCreateWithCString( NULL, name.cstr(), kCFStringEncodingUTF8 ); - if( font_name != NULL ) - { - font_descriptor = CTFontDescriptorCreateWithNameAndSize( font_name, 0.0); //POINT_SIZE ); - - if( font_descriptor != NULL ) - { - ct_font = CTFontCreateWithFontDescriptor( font_descriptor, POINT_SIZE, &affine_transform ); - - CFRelease( font_descriptor ); - } - } - - CFRelease( font_name ); - - if (!ct_font) - { - osd_printf_verbose("Couldn't find/open font %s, using MAME default\n", name.cstr()); - return false; - } - - CFStringRef real_name = CTFontCopyPostScriptName( ct_font ); - char real_name_c_string[255]; - CFStringGetCString ( real_name, real_name_c_string, 255, kCFStringEncodingUTF8 ); - osd_printf_verbose("Matching font: %s\n", real_name_c_string); - CFRelease( real_name ); - - CGFloat line_height = 0.0; - line_height += CTFontGetAscent(ct_font); - line_height += CTFontGetDescent(ct_font); - line_height += CTFontGetLeading(ct_font); - height = ceilf(line_height * EXTRA_HEIGHT); - - m_font = ct_font; - return true; + /* handle bdf fonts in the core */ + if (name.len() > 4) + if (name.makeupper().substr(name.len()-4,4) == ".BDF" ) + return false; + + font_name = CFStringCreateWithCString( NULL, name.cstr(), kCFStringEncodingUTF8 ); + if( font_name != NULL ) + { + font_descriptor = CTFontDescriptorCreateWithNameAndSize( font_name, 0.0); //POINT_SIZE ); + + if( font_descriptor != NULL ) + { + ct_font = CTFontCreateWithFontDescriptor( font_descriptor, POINT_SIZE, &affine_transform ); + + CFRelease( font_descriptor ); + } + } + + CFRelease( font_name ); + + if (!ct_font) + { + osd_printf_verbose("Couldn't find/open font %s, using MAME default\n", name.cstr()); + return false; + } + + CFStringRef real_name = CTFontCopyPostScriptName( ct_font ); + char real_name_c_string[255]; + CFStringGetCString ( real_name, real_name_c_string, 255, kCFStringEncodingUTF8 ); + osd_printf_verbose("Matching font: %s\n", real_name_c_string); + CFRelease( real_name ); + + CGFloat line_height = 0.0; + line_height += CTFontGetAscent(ct_font); + line_height += CTFontGetDescent(ct_font); + line_height += CTFontGetLeading(ct_font); + height = ceilf(line_height * EXTRA_HEIGHT); + + m_font = ct_font; + return true; } //------------------------------------------------- @@ -100,10 +100,10 @@ bool osd_font_osx::open(const char *font_path, const char *_name, int &height) void osd_font_osx::close() { - if( m_font != NULL ) - { - CFRelease( m_font ); - } + if( m_font != NULL ) + { + CFRelease( m_font ); + } } //------------------------------------------------- @@ -116,88 +116,88 @@ void osd_font_osx::close() bool osd_font_osx::get_bitmap(unicode_char chnum, bitmap_argb32 &bitmap, INT32 &width, INT32 &xoffs, INT32 &yoffs) { - UniChar uni_char; - CGGlyph glyph; - CTFontRef ct_font = m_font; - const CFIndex count = 1; - CGRect bounding_rect, success_rect; - CGContextRef context_ref; - - if( chnum == ' ' ) - { - uni_char = 'n'; - CTFontGetGlyphsForCharacters( ct_font, &uni_char, &glyph, count ); - success_rect = CTFontGetBoundingRectsForGlyphs( ct_font, kCTFontDefaultOrientation, &glyph, &bounding_rect, count ); - uni_char = chnum; - CTFontGetGlyphsForCharacters( ct_font, &uni_char, &glyph, count ); - } - else - { - uni_char = chnum; - CTFontGetGlyphsForCharacters( ct_font, &uni_char, &glyph, count ); - success_rect = CTFontGetBoundingRectsForGlyphs( ct_font, kCTFontDefaultOrientation, &glyph, &bounding_rect, count ); - } - - if( CGRectEqualToRect( success_rect, CGRectNull ) == false ) - { - size_t bitmap_width; - size_t bitmap_height; - - bitmap_width = ceilf(bounding_rect.size.width * EXTRA_WIDTH); - bitmap_width = bitmap_width == 0 ? 1 : bitmap_width; - - bitmap_height = ceilf( (CTFontGetAscent(ct_font) + CTFontGetDescent(ct_font) + CTFontGetLeading(ct_font)) * EXTRA_HEIGHT); - - xoffs = yoffs = 0; - width = bitmap_width; - - size_t bits_per_component; - CGColorSpaceRef color_space; - CGBitmapInfo bitmap_info = kCGBitmapByteOrder32Host | kCGImageAlphaPremultipliedFirst; - - color_space = CGColorSpaceCreateDeviceRGB(); - bits_per_component = 8; - - bitmap.allocate(bitmap_width, bitmap_height); - - context_ref = CGBitmapContextCreate( bitmap.raw_pixptr(0), bitmap_width, bitmap_height, bits_per_component, bitmap.rowpixels()*4, color_space, bitmap_info ); - - if( context_ref != NULL ) - { - CGFontRef font_ref; - font_ref = CTFontCopyGraphicsFont( ct_font, NULL ); - CGContextSetTextPosition(context_ref, -bounding_rect.origin.x*EXTRA_WIDTH, CTFontGetDescent(ct_font)+CTFontGetLeading(ct_font) ); - CGContextSetRGBFillColor(context_ref, 1.0, 1.0, 1.0, 1.0); - CGContextSetFont( context_ref, font_ref ); - CGContextSetFontSize( context_ref, POINT_SIZE ); - CGContextShowGlyphs( context_ref, &glyph, count ); - CGFontRelease( font_ref ); - CGContextRelease( context_ref ); - } - - CGColorSpaceRelease( color_space ); - } - - return bitmap.valid(); + UniChar uni_char; + CGGlyph glyph; + CTFontRef ct_font = m_font; + const CFIndex count = 1; + CGRect bounding_rect, success_rect; + CGContextRef context_ref; + + if( chnum == ' ' ) + { + uni_char = 'n'; + CTFontGetGlyphsForCharacters( ct_font, &uni_char, &glyph, count ); + success_rect = CTFontGetBoundingRectsForGlyphs( ct_font, kCTFontDefaultOrientation, &glyph, &bounding_rect, count ); + uni_char = chnum; + CTFontGetGlyphsForCharacters( ct_font, &uni_char, &glyph, count ); + } + else + { + uni_char = chnum; + CTFontGetGlyphsForCharacters( ct_font, &uni_char, &glyph, count ); + success_rect = CTFontGetBoundingRectsForGlyphs( ct_font, kCTFontDefaultOrientation, &glyph, &bounding_rect, count ); + } + + if( CGRectEqualToRect( success_rect, CGRectNull ) == false ) + { + size_t bitmap_width; + size_t bitmap_height; + + bitmap_width = ceilf(bounding_rect.size.width * EXTRA_WIDTH); + bitmap_width = bitmap_width == 0 ? 1 : bitmap_width; + + bitmap_height = ceilf( (CTFontGetAscent(ct_font) + CTFontGetDescent(ct_font) + CTFontGetLeading(ct_font)) * EXTRA_HEIGHT); + + xoffs = yoffs = 0; + width = bitmap_width; + + size_t bits_per_component; + CGColorSpaceRef color_space; + CGBitmapInfo bitmap_info = kCGBitmapByteOrder32Host | kCGImageAlphaPremultipliedFirst; + + color_space = CGColorSpaceCreateDeviceRGB(); + bits_per_component = 8; + + bitmap.allocate(bitmap_width, bitmap_height); + + context_ref = CGBitmapContextCreate( bitmap.raw_pixptr(0), bitmap_width, bitmap_height, bits_per_component, bitmap.rowpixels()*4, color_space, bitmap_info ); + + if( context_ref != NULL ) + { + CGFontRef font_ref; + font_ref = CTFontCopyGraphicsFont( ct_font, NULL ); + CGContextSetTextPosition(context_ref, -bounding_rect.origin.x*EXTRA_WIDTH, CTFontGetDescent(ct_font)+CTFontGetLeading(ct_font) ); + CGContextSetRGBFillColor(context_ref, 1.0, 1.0, 1.0, 1.0); + CGContextSetFont( context_ref, font_ref ); + CGContextSetFontSize( context_ref, POINT_SIZE ); + CGContextShowGlyphs( context_ref, &glyph, count ); + CGFontRelease( font_ref ); + CGContextRelease( context_ref ); + } + + CGColorSpaceRelease( color_space ); + } + + return bitmap.valid(); } class font_osx : public osd_module, public font_module { public: - font_osx() - : osd_module(OSD_FONT_PROVIDER, "osx"), font_module() - { - } + font_osx() + : osd_module(OSD_FONT_PROVIDER, "osx"), font_module() + { + } - osd_font *font_alloc() - { - return global_alloc(osd_font_osx); - } + osd_font *font_alloc() + { + return global_alloc(osd_font_osx); + } }; #else /* SDLMAME_UNIX */ - MODULE_NOT_SUPPORTED(font_osx, OSD_FONT_PROVIDER, "osx") + MODULE_NOT_SUPPORTED(font_osx, OSD_FONT_PROVIDER, "osx") #endif MODULE_DEFINITION(FONT_OSX, font_osx) diff --git a/src/osd/modules/font/font_sdl.c b/src/osd/modules/font/font_sdl.c index 6ae72ca4fb3..d10f7209ab1 100644 --- a/src/osd/modules/font/font_sdl.c +++ b/src/osd/modules/font/font_sdl.c @@ -32,95 +32,95 @@ class osd_font_sdl : public osd_font { public: - virtual ~osd_font_sdl() {}; + virtual ~osd_font_sdl() {}; - virtual bool open(const char *font_path, const char *name, int &height); - virtual void close(); - virtual bool get_bitmap(unicode_char chnum, bitmap_argb32 &bitmap, INT32 &width, INT32 &xoffs, INT32 &yoffs); + virtual bool open(const char *font_path, const char *name, int &height); + virtual void close(); + virtual bool get_bitmap(unicode_char chnum, bitmap_argb32 &bitmap, INT32 &width, INT32 &xoffs, INT32 &yoffs); private: #ifndef SDLMAME_HAIKU - TTF_Font *search_font_config(astring name, bool bold, bool italic, bool underline, bool &bakedstyles); + TTF_Font *search_font_config(astring name, bool bold, bool italic, bool underline, bool &bakedstyles); #endif - bool BDF_Check_Magic(astring name); - TTF_Font * TTF_OpenFont_Magic(astring name, int fsize); - TTF_Font *m_font; + bool BDF_Check_Magic(astring name); + TTF_Font * TTF_OpenFont_Magic(astring name, int fsize); + TTF_Font *m_font; }; bool osd_font_sdl::open(const char *font_path, const char *_name, int &height) { - TTF_Font *font = (TTF_Font *)NULL; - bool bakedstyles = false; - int style = 0; - - // accept qualifiers from the name - astring name(_name); - - if (name == "default") - { - name = "Liberation Sans"; - } - - bool bold = (name.replace(0, "[B]", "") + name.replace(0, "[b]", "") > 0); - bool italic = (name.replace(0, "[I]", "") + name.replace(0, "[i]", "") > 0); - bool underline = (name.replace(0, "[U]", "") + name.replace(0, "[u]", "") > 0); - bool strike = (name.replace(0, "[S]", "") + name.replace(0, "[s]", "") > 0); - - // first up, try it as a filename - font = TTF_OpenFont_Magic(name, POINT_SIZE); - - // if no success, try the font path - - if (!font) - { - osd_printf_verbose("Searching font %s in -%s\n", name.cstr(), OPTION_FONTPATH); - //emu_file file(options().font_path(), OPEN_FLAG_READ); - emu_file file(font_path, OPEN_FLAG_READ); - if (file.open(name) == FILERR_NONE) - { - astring full_name = file.fullpath(); - font = TTF_OpenFont_Magic(full_name, POINT_SIZE); - if (font) - osd_printf_verbose("Found font %s\n", full_name.cstr()); - } - } - - // if that didn't work, crank up the FontConfig database + TTF_Font *font = (TTF_Font *)NULL; + bool bakedstyles = false; + int style = 0; + + // accept qualifiers from the name + astring name(_name); + + if (name == "default") + { + name = "Liberation Sans"; + } + + bool bold = (name.replace(0, "[B]", "") + name.replace(0, "[b]", "") > 0); + bool italic = (name.replace(0, "[I]", "") + name.replace(0, "[i]", "") > 0); + bool underline = (name.replace(0, "[U]", "") + name.replace(0, "[u]", "") > 0); + bool strike = (name.replace(0, "[S]", "") + name.replace(0, "[s]", "") > 0); + + // first up, try it as a filename + font = TTF_OpenFont_Magic(name, POINT_SIZE); + + // if no success, try the font path + + if (!font) + { + osd_printf_verbose("Searching font %s in -%s\n", name.cstr(), OPTION_FONTPATH); + //emu_file file(options().font_path(), OPEN_FLAG_READ); + emu_file file(font_path, OPEN_FLAG_READ); + if (file.open(name) == FILERR_NONE) + { + astring full_name = file.fullpath(); + font = TTF_OpenFont_Magic(full_name, POINT_SIZE); + if (font) + osd_printf_verbose("Found font %s\n", full_name.cstr()); + } + } + + // if that didn't work, crank up the FontConfig database #ifndef SDLMAME_HAIKU - if (!font) - { - font = search_font_config(name, bold, italic, underline, bakedstyles); - } + if (!font) + { + font = search_font_config(name, bold, italic, underline, bakedstyles); + } #endif - if (!font) - { - if (!BDF_Check_Magic(name)) - { - osd_printf_verbose("font %s is not TrueType or BDF, using MAME default\n", name.cstr()); - } - return NULL; - } - - // apply styles - if (!bakedstyles) - { - style |= bold ? TTF_STYLE_BOLD : 0; - style |= italic ? TTF_STYLE_ITALIC : 0; - } - style |= underline ? TTF_STYLE_UNDERLINE : 0; - // SDL_ttf 2.0.9 and earlier does not define TTF_STYLE_STRIKETHROUGH + if (!font) + { + if (!BDF_Check_Magic(name)) + { + osd_printf_verbose("font %s is not TrueType or BDF, using MAME default\n", name.cstr()); + } + return NULL; + } + + // apply styles + if (!bakedstyles) + { + style |= bold ? TTF_STYLE_BOLD : 0; + style |= italic ? TTF_STYLE_ITALIC : 0; + } + style |= underline ? TTF_STYLE_UNDERLINE : 0; + // SDL_ttf 2.0.9 and earlier does not define TTF_STYLE_STRIKETHROUGH #if SDL_VERSIONNUM(TTF_MAJOR_VERSION, TTF_MINOR_VERSION, TTF_PATCHLEVEL) > SDL_VERSIONNUM(2,0,9) - style |= strike ? TTF_STYLE_STRIKETHROUGH : 0; + style |= strike ? TTF_STYLE_STRIKETHROUGH : 0; #else - if (strike) - osd_printf_warning("Ignoring strikethrough for SDL_TTF older than 2.0.10\n"); + if (strike) + osd_printf_warning("Ignoring strikethrough for SDL_TTF older than 2.0.10\n"); #endif // PATCHLEVEL - TTF_SetFontStyle(font, style); + TTF_SetFontStyle(font, style); - height = TTF_FontLineSkip(font); + height = TTF_FontLineSkip(font); - m_font = font; - return true; + m_font = font; + return true; } //------------------------------------------------- @@ -130,7 +130,7 @@ bool osd_font_sdl::open(const char *font_path, const char *_name, int &height) void osd_font_sdl::close() { - TTF_CloseFont(this->m_font); + TTF_CloseFont(this->m_font); } //------------------------------------------------- @@ -143,184 +143,184 @@ void osd_font_sdl::close() bool osd_font_sdl::get_bitmap(unicode_char chnum, bitmap_argb32 &bitmap, INT32 &width, INT32 &xoffs, INT32 &yoffs) { - TTF_Font *ttffont; - SDL_Surface *drawsurf; - SDL_Color fcol = { 0xff, 0xff, 0xff }; - UINT16 ustr[16]; + TTF_Font *ttffont; + SDL_Surface *drawsurf; + SDL_Color fcol = { 0xff, 0xff, 0xff }; + UINT16 ustr[16]; - ttffont = m_font; + ttffont = m_font; - memset(ustr,0,sizeof(ustr)); - ustr[0] = (UINT16)chnum; - drawsurf = TTF_RenderUNICODE_Solid(ttffont, ustr, fcol); + memset(ustr,0,sizeof(ustr)); + ustr[0] = (UINT16)chnum; + drawsurf = TTF_RenderUNICODE_Solid(ttffont, ustr, fcol); - // was nothing returned? - if (drawsurf) - { - // allocate a MAME destination bitmap - bitmap.allocate(drawsurf->w, drawsurf->h); + // was nothing returned? + if (drawsurf) + { + // allocate a MAME destination bitmap + bitmap.allocate(drawsurf->w, drawsurf->h); - // copy the rendered character image into it - for (int y = 0; y < bitmap.height(); y++) - { - UINT32 *dstrow = &bitmap.pix32(y); - UINT8 *srcrow = (UINT8 *)drawsurf->pixels; + // copy the rendered character image into it + for (int y = 0; y < bitmap.height(); y++) + { + UINT32 *dstrow = &bitmap.pix32(y); + UINT8 *srcrow = (UINT8 *)drawsurf->pixels; - srcrow += (y * drawsurf->pitch); + srcrow += (y * drawsurf->pitch); - for (int x = 0; x < drawsurf->w; x++) - { - dstrow[x] = srcrow[x] ? rgb_t(0xff,0xff,0xff,0xff) : rgb_t(0x00,0xff,0xff,0xff); - } - } + for (int x = 0; x < drawsurf->w; x++) + { + dstrow[x] = srcrow[x] ? rgb_t(0xff,0xff,0xff,0xff) : rgb_t(0x00,0xff,0xff,0xff); + } + } - // what are these? - xoffs = yoffs = 0; - width = drawsurf->w; + // what are these? + xoffs = yoffs = 0; + width = drawsurf->w; - SDL_FreeSurface(drawsurf); - } + SDL_FreeSurface(drawsurf); + } - return bitmap.valid(); + return bitmap.valid(); } TTF_Font * osd_font_sdl::TTF_OpenFont_Magic(astring name, int fsize) { - emu_file file(OPEN_FLAG_READ); - if (file.open(name) == FILERR_NONE) - { - unsigned char buffer[5] = { 0xff, 0xff, 0xff, 0xff, 0xff }; - unsigned char magic[5] = { 0x00, 0x01, 0x00, 0x00, 0x00 }; - file.read(buffer,5); - if (memcmp(buffer, magic, 5)) - return NULL; - } - return TTF_OpenFont(name.cstr(), POINT_SIZE); + emu_file file(OPEN_FLAG_READ); + if (file.open(name) == FILERR_NONE) + { + unsigned char buffer[5] = { 0xff, 0xff, 0xff, 0xff, 0xff }; + unsigned char magic[5] = { 0x00, 0x01, 0x00, 0x00, 0x00 }; + file.read(buffer,5); + if (memcmp(buffer, magic, 5)) + return NULL; + } + return TTF_OpenFont(name.cstr(), POINT_SIZE); } bool osd_font_sdl::BDF_Check_Magic(astring name) { - emu_file file(OPEN_FLAG_READ); - if (file.open(name) == FILERR_NONE) - { - unsigned char buffer[9]; - unsigned char magic[9] = { 'S', 'T', 'A', 'R', 'T', 'F', 'O', 'N', 'T' }; - file.read(buffer, 9); - file.close(); - if (!memcmp(buffer, magic, 9)) - return true; - } - - return false; + emu_file file(OPEN_FLAG_READ); + if (file.open(name) == FILERR_NONE) + { + unsigned char buffer[9]; + unsigned char magic[9] = { 'S', 'T', 'A', 'R', 'T', 'F', 'O', 'N', 'T' }; + file.read(buffer, 9); + file.close(); + if (!memcmp(buffer, magic, 9)) + return true; + } + + return false; } #ifndef SDLMAME_HAIKU TTF_Font *osd_font_sdl::search_font_config(astring name, bool bold, bool italic, bool underline, bool &bakedstyles) { - TTF_Font *font = (TTF_Font *)NULL; - FcConfig *config; - FcPattern *pat; - FcObjectSet *os; - FcFontSet *fontset; - FcValue val; - - config = FcConfigGetCurrent(); - pat = FcPatternCreate(); - os = FcObjectSetCreate(); - FcPatternAddString(pat, FC_FAMILY, (const FcChar8 *)name.cstr()); - - // try and get a font with the requested styles baked-in - if (bold) - { - if (italic) - { - FcPatternAddString(pat, FC_STYLE, (const FcChar8 *)"Bold Italic"); - } - else - { - FcPatternAddString(pat, FC_STYLE, (const FcChar8 *)"Bold"); - } - } - else if (italic) - { - FcPatternAddString(pat, FC_STYLE, (const FcChar8 *)"Italic"); - } - else - { - FcPatternAddString(pat, FC_STYLE, (const FcChar8 *)"Regular"); - } - - FcPatternAddString(pat, FC_FONTFORMAT, (const FcChar8 *)"TrueType"); - - FcObjectSetAdd(os, FC_FILE); - fontset = FcFontList(config, pat, os); - - for (int i = 0; i < fontset->nfont; i++) - { - if (FcPatternGet(fontset->fonts[i], FC_FILE, 0, &val) != FcResultMatch) - { - continue; - } - - if (val.type != FcTypeString) - { - continue; - } - - osd_printf_verbose("Matching font: %s\n", val.u.s); - { - astring match_name((const char*)val.u.s); - font = TTF_OpenFont_Magic(match_name, POINT_SIZE); - } - - if (font) - { - bakedstyles = true; - break; - } - } - - // didn't get a font above? try again with no baked-in styles - if (!font) - { - FcPatternDestroy(pat); - FcFontSetDestroy(fontset); - - pat = FcPatternCreate(); - FcPatternAddString(pat, FC_FAMILY, (const FcChar8 *)name.cstr()); - FcPatternAddString(pat, FC_STYLE, (const FcChar8 *)"Regular"); - FcPatternAddString(pat, FC_FONTFORMAT, (const FcChar8 *)"TrueType"); - fontset = FcFontList(config, pat, os); - - for (int i = 0; i < fontset->nfont; i++) - { - if (FcPatternGet(fontset->fonts[i], FC_FILE, 0, &val) != FcResultMatch) - { - continue; - } - - if (val.type != FcTypeString) - { - continue; - } - - osd_printf_verbose("Matching unstyled font: %s\n", val.u.s); - { - astring match_name((const char*)val.u.s); - font = TTF_OpenFont_Magic(match_name, POINT_SIZE); - } - - if (font) - { - break; - } - } - } - - FcPatternDestroy(pat); - FcObjectSetDestroy(os); - FcFontSetDestroy(fontset); - return font; + TTF_Font *font = (TTF_Font *)NULL; + FcConfig *config; + FcPattern *pat; + FcObjectSet *os; + FcFontSet *fontset; + FcValue val; + + config = FcConfigGetCurrent(); + pat = FcPatternCreate(); + os = FcObjectSetCreate(); + FcPatternAddString(pat, FC_FAMILY, (const FcChar8 *)name.cstr()); + + // try and get a font with the requested styles baked-in + if (bold) + { + if (italic) + { + FcPatternAddString(pat, FC_STYLE, (const FcChar8 *)"Bold Italic"); + } + else + { + FcPatternAddString(pat, FC_STYLE, (const FcChar8 *)"Bold"); + } + } + else if (italic) + { + FcPatternAddString(pat, FC_STYLE, (const FcChar8 *)"Italic"); + } + else + { + FcPatternAddString(pat, FC_STYLE, (const FcChar8 *)"Regular"); + } + + FcPatternAddString(pat, FC_FONTFORMAT, (const FcChar8 *)"TrueType"); + + FcObjectSetAdd(os, FC_FILE); + fontset = FcFontList(config, pat, os); + + for (int i = 0; i < fontset->nfont; i++) + { + if (FcPatternGet(fontset->fonts[i], FC_FILE, 0, &val) != FcResultMatch) + { + continue; + } + + if (val.type != FcTypeString) + { + continue; + } + + osd_printf_verbose("Matching font: %s\n", val.u.s); + { + astring match_name((const char*)val.u.s); + font = TTF_OpenFont_Magic(match_name, POINT_SIZE); + } + + if (font) + { + bakedstyles = true; + break; + } + } + + // didn't get a font above? try again with no baked-in styles + if (!font) + { + FcPatternDestroy(pat); + FcFontSetDestroy(fontset); + + pat = FcPatternCreate(); + FcPatternAddString(pat, FC_FAMILY, (const FcChar8 *)name.cstr()); + FcPatternAddString(pat, FC_STYLE, (const FcChar8 *)"Regular"); + FcPatternAddString(pat, FC_FONTFORMAT, (const FcChar8 *)"TrueType"); + fontset = FcFontList(config, pat, os); + + for (int i = 0; i < fontset->nfont; i++) + { + if (FcPatternGet(fontset->fonts[i], FC_FILE, 0, &val) != FcResultMatch) + { + continue; + } + + if (val.type != FcTypeString) + { + continue; + } + + osd_printf_verbose("Matching unstyled font: %s\n", val.u.s); + { + astring match_name((const char*)val.u.s); + font = TTF_OpenFont_Magic(match_name, POINT_SIZE); + } + + if (font) + { + break; + } + } + } + + FcPatternDestroy(pat); + FcObjectSetDestroy(os); + FcFontSetDestroy(fontset); + return font; } #endif @@ -328,35 +328,33 @@ TTF_Font *osd_font_sdl::search_font_config(astring name, bool bold, bool italic, class font_sdl : public osd_module, public font_module { public: - font_sdl() - : osd_module(OSD_FONT_PROVIDER, "sdl"), font_module() - { - } - - osd_font *font_alloc() - { - return global_alloc(osd_font_sdl); - } - - int init() - { - if (TTF_Init() == -1) - { - osd_printf_error("SDL_ttf failed: %s\n", TTF_GetError()); - return -1; - } - return 0; - } - - virtual void exit() - { - TTF_Quit(); - } + font_sdl() + : osd_module(OSD_FONT_PROVIDER, "sdl"), font_module() + { + } + + osd_font *font_alloc() + { + return global_alloc(osd_font_sdl); + } + + int init() + { + if (TTF_Init() == -1) + { + osd_printf_error("SDL_ttf failed: %s\n", TTF_GetError()); + return -1; + } + return 0; + } + + virtual void exit() + { + TTF_Quit(); + } }; #else /* SDLMAME_UNIX */ - MODULE_NOT_SUPPORTED(font_sdl, OSD_FONT_PROVIDER, "sdl") + MODULE_NOT_SUPPORTED(font_sdl, OSD_FONT_PROVIDER, "sdl") #endif MODULE_DEFINITION(FONT_SDL, font_sdl) - - diff --git a/src/osd/modules/font/font_windows.c b/src/osd/modules/font/font_windows.c index 054ef077148..458534f3a74 100644 --- a/src/osd/modules/font/font_windows.c +++ b/src/osd/modules/font/font_windows.c @@ -34,72 +34,72 @@ class osd_font_windows : public osd_font { public: - virtual ~osd_font_windows() {}; + virtual ~osd_font_windows() {}; - virtual bool open(const char *font_path, const char *name, int &height); - virtual void close(); - virtual bool get_bitmap(unicode_char chnum, bitmap_argb32 &bitmap, INT32 &width, INT32 &xoffs, INT32 &yoffs); + virtual bool open(const char *font_path, const char *name, int &height); + virtual void close(); + virtual bool get_bitmap(unicode_char chnum, bitmap_argb32 &bitmap, INT32 &width, INT32 &xoffs, INT32 &yoffs); private: - HGDIOBJ m_font; + HGDIOBJ m_font; }; bool osd_font_windows::open(const char *font_path, const char *_name, int &height) { - // accept qualifiers from the name - astring name(_name); - if (name == "default") name = "Tahoma"; - bool bold = (name.replace(0, "[B]", "") + name.replace(0, "[b]", "") > 0); - bool italic = (name.replace(0, "[I]", "") + name.replace(0, "[i]", "") > 0); - - // build a basic LOGFONT description of what we want - LOGFONT logfont; - logfont.lfHeight = DEFAULT_FONT_HEIGHT; - logfont.lfWidth = 0; - logfont.lfEscapement = 0; - logfont.lfOrientation = 0; - logfont.lfWeight = bold ? FW_BOLD : FW_MEDIUM; - logfont.lfItalic = italic; - logfont.lfUnderline = FALSE; - logfont.lfStrikeOut = FALSE; - logfont.lfCharSet = ANSI_CHARSET; - logfont.lfOutPrecision = OUT_DEFAULT_PRECIS; - logfont.lfClipPrecision = CLIP_DEFAULT_PRECIS; - logfont.lfQuality = NONANTIALIASED_QUALITY; - logfont.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE; - - // copy in the face name - TCHAR *face = tstring_from_utf8(name); - _tcsncpy(logfont.lfFaceName, face, sizeof(logfont.lfFaceName) / sizeof(TCHAR)); - logfont.lfFaceName[sizeof(logfont.lfFaceName) / sizeof(TCHAR)-1] = 0; - osd_free(face); - - // create the font - height = logfont.lfHeight; - m_font = CreateFontIndirect(&logfont); - if (m_font == NULL) - return false; - - // select it into a temp DC and get the real font name - HDC dummyDC = CreateCompatibleDC(NULL); - HGDIOBJ oldfont = SelectObject(dummyDC, m_font); - TCHAR realname[100]; - GetTextFace(dummyDC, ARRAY_LENGTH(realname), realname); - SelectObject(dummyDC, oldfont); - DeleteDC(dummyDC); - - // if it doesn't match our request, fail - char *utf = utf8_from_tstring(realname); - int result = core_stricmp(utf, name); - osd_free(utf); - - // if we didn't match, nuke our font and fall back - if (result != 0) - { - DeleteObject(m_font); - m_font = NULL; - return false; - } - return true; + // accept qualifiers from the name + astring name(_name); + if (name == "default") name = "Tahoma"; + bool bold = (name.replace(0, "[B]", "") + name.replace(0, "[b]", "") > 0); + bool italic = (name.replace(0, "[I]", "") + name.replace(0, "[i]", "") > 0); + + // build a basic LOGFONT description of what we want + LOGFONT logfont; + logfont.lfHeight = DEFAULT_FONT_HEIGHT; + logfont.lfWidth = 0; + logfont.lfEscapement = 0; + logfont.lfOrientation = 0; + logfont.lfWeight = bold ? FW_BOLD : FW_MEDIUM; + logfont.lfItalic = italic; + logfont.lfUnderline = FALSE; + logfont.lfStrikeOut = FALSE; + logfont.lfCharSet = ANSI_CHARSET; + logfont.lfOutPrecision = OUT_DEFAULT_PRECIS; + logfont.lfClipPrecision = CLIP_DEFAULT_PRECIS; + logfont.lfQuality = NONANTIALIASED_QUALITY; + logfont.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE; + + // copy in the face name + TCHAR *face = tstring_from_utf8(name); + _tcsncpy(logfont.lfFaceName, face, sizeof(logfont.lfFaceName) / sizeof(TCHAR)); + logfont.lfFaceName[sizeof(logfont.lfFaceName) / sizeof(TCHAR)-1] = 0; + osd_free(face); + + // create the font + height = logfont.lfHeight; + m_font = CreateFontIndirect(&logfont); + if (m_font == NULL) + return false; + + // select it into a temp DC and get the real font name + HDC dummyDC = CreateCompatibleDC(NULL); + HGDIOBJ oldfont = SelectObject(dummyDC, m_font); + TCHAR realname[100]; + GetTextFace(dummyDC, ARRAY_LENGTH(realname), realname); + SelectObject(dummyDC, oldfont); + DeleteDC(dummyDC); + + // if it doesn't match our request, fail + char *utf = utf8_from_tstring(realname); + int result = core_stricmp(utf, name); + osd_free(utf); + + // if we didn't match, nuke our font and fall back + if (result != 0) + { + DeleteObject(m_font); + m_font = NULL; + return false; + } + return true; } //------------------------------------------------- @@ -109,9 +109,9 @@ bool osd_font_windows::open(const char *font_path, const char *_name, int &heigh void osd_font_windows::close() { - // delete the font ojbect - if (m_font != NULL) - DeleteObject(m_font); + // delete the font ojbect + if (m_font != NULL) + DeleteObject(m_font); } @@ -125,155 +125,155 @@ void osd_font_windows::close() bool osd_font_windows::get_bitmap(unicode_char chnum, bitmap_argb32 &bitmap, INT32 &width, INT32 &xoffs, INT32 &yoffs) { - // create a dummy DC to work with - HDC dummyDC = CreateCompatibleDC(NULL); - HGDIOBJ oldfont = SelectObject(dummyDC, m_font); - - // get the text metrics - TEXTMETRIC metrics = { 0 }; - GetTextMetrics(dummyDC, &metrics); - - // get the width of this character - ABC abc; - if (!GetCharABCWidths(dummyDC, chnum, chnum, &abc)) - { - abc.abcA = 0; - abc.abcC = 0; - GetCharWidth32(dummyDC, chnum, chnum, reinterpret_cast<LPINT>(&abc.abcB)); - } - width = abc.abcA + abc.abcB + abc.abcC; - - // determine desired bitmap size - int bmwidth = (50 + abc.abcA + abc.abcB + abc.abcC + 50 + 31) & ~31; - int bmheight = 50 + metrics.tmHeight + 50; - - // describe the bitmap we want - BYTE bitmapinfodata[sizeof(BITMAPINFOHEADER)+2 * sizeof(RGBQUAD)] = { 0 }; - BITMAPINFO &info = *reinterpret_cast<BITMAPINFO *>(bitmapinfodata); - info.bmiHeader.biSize = sizeof(info.bmiHeader); - info.bmiHeader.biWidth = bmwidth; - info.bmiHeader.biHeight = -bmheight; - info.bmiHeader.biPlanes = 1; - info.bmiHeader.biBitCount = 1; - info.bmiHeader.biCompression = BI_RGB; - info.bmiHeader.biSizeImage = 0; - info.bmiHeader.biXPelsPerMeter = GetDeviceCaps(dummyDC, HORZRES) / GetDeviceCaps(dummyDC, HORZSIZE); - info.bmiHeader.biYPelsPerMeter = GetDeviceCaps(dummyDC, VERTRES) / GetDeviceCaps(dummyDC, VERTSIZE); - info.bmiHeader.biClrUsed = 0; - info.bmiHeader.biClrImportant = 0; - RGBQUAD col1 = info.bmiColors[0]; - RGBQUAD col2 = info.bmiColors[1]; - col1.rgbBlue = col1.rgbGreen = col1.rgbRed = 0x00; - col2.rgbBlue = col2.rgbGreen = col2.rgbRed = 0xff; - - // create a DIB to render to - BYTE *bits; - HBITMAP dib = CreateDIBSection(dummyDC, &info, DIB_RGB_COLORS, reinterpret_cast<VOID **>(&bits), NULL, 0); - HGDIOBJ oldbitmap = SelectObject(dummyDC, dib); - - // clear the bitmap - int rowbytes = bmwidth / 8; - memset(bits, 0, rowbytes * bmheight); - - // now draw the character - WCHAR tempchar = chnum; - SetTextColor(dummyDC, RGB(0xff, 0xff, 0xff)); - SetBkColor(dummyDC, RGB(0x00, 0x00, 0x00)); - ExtTextOutW(dummyDC, 50 + abc.abcA, 50, ETO_OPAQUE, NULL, &tempchar, 1, NULL); - - // characters are expected to be full-height - rectangle actbounds; - actbounds.min_y = 50; - actbounds.max_y = 50 + metrics.tmHeight - 1; - - // determine the actual left of the character - for (actbounds.min_x = 0; actbounds.min_x < rowbytes; actbounds.min_x++) - { - BYTE *offs = bits + actbounds.min_x; - UINT8 summary = 0; - for (int y = 0; y < bmheight; y++) - summary |= offs[y * rowbytes]; - if (summary != 0) - { - actbounds.min_x *= 8; - if (!(summary & 0x80)) actbounds.min_x++; - if (!(summary & 0xc0)) actbounds.min_x++; - if (!(summary & 0xe0)) actbounds.min_x++; - if (!(summary & 0xf0)) actbounds.min_x++; - if (!(summary & 0xf8)) actbounds.min_x++; - if (!(summary & 0xfc)) actbounds.min_x++; - if (!(summary & 0xfe)) actbounds.min_x++; - break; - } - } - - // determine the actual right of the character - for (actbounds.max_x = rowbytes - 1; actbounds.max_x >= 0; actbounds.max_x--) - { - BYTE *offs = bits + actbounds.max_x; - UINT8 summary = 0; - for (int y = 0; y < bmheight; y++) - summary |= offs[y * rowbytes]; - if (summary != 0) - { - actbounds.max_x *= 8; - if (summary & 0x7f) actbounds.max_x++; - if (summary & 0x3f) actbounds.max_x++; - if (summary & 0x1f) actbounds.max_x++; - if (summary & 0x0f) actbounds.max_x++; - if (summary & 0x07) actbounds.max_x++; - if (summary & 0x03) actbounds.max_x++; - if (summary & 0x01) actbounds.max_x++; - break; - } - } - - // allocate a new bitmap - if (actbounds.max_x >= actbounds.min_x && actbounds.max_y >= actbounds.min_y) - { - bitmap.allocate(actbounds.max_x + 1 - actbounds.min_x, actbounds.max_y + 1 - actbounds.min_y); - - // copy the bits into it - for (int y = 0; y < bitmap.height(); y++) - { - UINT32 *dstrow = &bitmap.pix32(y); - UINT8 *srcrow = &bits[(y + actbounds.min_y) * rowbytes]; - for (int x = 0; x < bitmap.width(); x++) - { - int effx = x + actbounds.min_x; - dstrow[x] = ((srcrow[effx / 8] << (effx % 8)) & 0x80) ? rgb_t(0xff, 0xff, 0xff, 0xff) : rgb_t(0x00, 0xff, 0xff, 0xff); - } - } - - // set the final offset values - xoffs = actbounds.min_x - (50 + abc.abcA); - yoffs = actbounds.max_y - (50 + metrics.tmAscent); - } - - // de-select the font and release the DC - SelectObject(dummyDC, oldbitmap); - DeleteObject(dib); - SelectObject(dummyDC, oldfont); - DeleteDC(dummyDC); - return bitmap.valid(); + // create a dummy DC to work with + HDC dummyDC = CreateCompatibleDC(NULL); + HGDIOBJ oldfont = SelectObject(dummyDC, m_font); + + // get the text metrics + TEXTMETRIC metrics = { 0 }; + GetTextMetrics(dummyDC, &metrics); + + // get the width of this character + ABC abc; + if (!GetCharABCWidths(dummyDC, chnum, chnum, &abc)) + { + abc.abcA = 0; + abc.abcC = 0; + GetCharWidth32(dummyDC, chnum, chnum, reinterpret_cast<LPINT>(&abc.abcB)); + } + width = abc.abcA + abc.abcB + abc.abcC; + + // determine desired bitmap size + int bmwidth = (50 + abc.abcA + abc.abcB + abc.abcC + 50 + 31) & ~31; + int bmheight = 50 + metrics.tmHeight + 50; + + // describe the bitmap we want + BYTE bitmapinfodata[sizeof(BITMAPINFOHEADER)+2 * sizeof(RGBQUAD)] = { 0 }; + BITMAPINFO &info = *reinterpret_cast<BITMAPINFO *>(bitmapinfodata); + info.bmiHeader.biSize = sizeof(info.bmiHeader); + info.bmiHeader.biWidth = bmwidth; + info.bmiHeader.biHeight = -bmheight; + info.bmiHeader.biPlanes = 1; + info.bmiHeader.biBitCount = 1; + info.bmiHeader.biCompression = BI_RGB; + info.bmiHeader.biSizeImage = 0; + info.bmiHeader.biXPelsPerMeter = GetDeviceCaps(dummyDC, HORZRES) / GetDeviceCaps(dummyDC, HORZSIZE); + info.bmiHeader.biYPelsPerMeter = GetDeviceCaps(dummyDC, VERTRES) / GetDeviceCaps(dummyDC, VERTSIZE); + info.bmiHeader.biClrUsed = 0; + info.bmiHeader.biClrImportant = 0; + RGBQUAD col1 = info.bmiColors[0]; + RGBQUAD col2 = info.bmiColors[1]; + col1.rgbBlue = col1.rgbGreen = col1.rgbRed = 0x00; + col2.rgbBlue = col2.rgbGreen = col2.rgbRed = 0xff; + + // create a DIB to render to + BYTE *bits; + HBITMAP dib = CreateDIBSection(dummyDC, &info, DIB_RGB_COLORS, reinterpret_cast<VOID **>(&bits), NULL, 0); + HGDIOBJ oldbitmap = SelectObject(dummyDC, dib); + + // clear the bitmap + int rowbytes = bmwidth / 8; + memset(bits, 0, rowbytes * bmheight); + + // now draw the character + WCHAR tempchar = chnum; + SetTextColor(dummyDC, RGB(0xff, 0xff, 0xff)); + SetBkColor(dummyDC, RGB(0x00, 0x00, 0x00)); + ExtTextOutW(dummyDC, 50 + abc.abcA, 50, ETO_OPAQUE, NULL, &tempchar, 1, NULL); + + // characters are expected to be full-height + rectangle actbounds; + actbounds.min_y = 50; + actbounds.max_y = 50 + metrics.tmHeight - 1; + + // determine the actual left of the character + for (actbounds.min_x = 0; actbounds.min_x < rowbytes; actbounds.min_x++) + { + BYTE *offs = bits + actbounds.min_x; + UINT8 summary = 0; + for (int y = 0; y < bmheight; y++) + summary |= offs[y * rowbytes]; + if (summary != 0) + { + actbounds.min_x *= 8; + if (!(summary & 0x80)) actbounds.min_x++; + if (!(summary & 0xc0)) actbounds.min_x++; + if (!(summary & 0xe0)) actbounds.min_x++; + if (!(summary & 0xf0)) actbounds.min_x++; + if (!(summary & 0xf8)) actbounds.min_x++; + if (!(summary & 0xfc)) actbounds.min_x++; + if (!(summary & 0xfe)) actbounds.min_x++; + break; + } + } + + // determine the actual right of the character + for (actbounds.max_x = rowbytes - 1; actbounds.max_x >= 0; actbounds.max_x--) + { + BYTE *offs = bits + actbounds.max_x; + UINT8 summary = 0; + for (int y = 0; y < bmheight; y++) + summary |= offs[y * rowbytes]; + if (summary != 0) + { + actbounds.max_x *= 8; + if (summary & 0x7f) actbounds.max_x++; + if (summary & 0x3f) actbounds.max_x++; + if (summary & 0x1f) actbounds.max_x++; + if (summary & 0x0f) actbounds.max_x++; + if (summary & 0x07) actbounds.max_x++; + if (summary & 0x03) actbounds.max_x++; + if (summary & 0x01) actbounds.max_x++; + break; + } + } + + // allocate a new bitmap + if (actbounds.max_x >= actbounds.min_x && actbounds.max_y >= actbounds.min_y) + { + bitmap.allocate(actbounds.max_x + 1 - actbounds.min_x, actbounds.max_y + 1 - actbounds.min_y); + + // copy the bits into it + for (int y = 0; y < bitmap.height(); y++) + { + UINT32 *dstrow = &bitmap.pix32(y); + UINT8 *srcrow = &bits[(y + actbounds.min_y) * rowbytes]; + for (int x = 0; x < bitmap.width(); x++) + { + int effx = x + actbounds.min_x; + dstrow[x] = ((srcrow[effx / 8] << (effx % 8)) & 0x80) ? rgb_t(0xff, 0xff, 0xff, 0xff) : rgb_t(0x00, 0xff, 0xff, 0xff); + } + } + + // set the final offset values + xoffs = actbounds.min_x - (50 + abc.abcA); + yoffs = actbounds.max_y - (50 + metrics.tmAscent); + } + + // de-select the font and release the DC + SelectObject(dummyDC, oldbitmap); + DeleteObject(dib); + SelectObject(dummyDC, oldfont); + DeleteDC(dummyDC); + return bitmap.valid(); } class font_win : public osd_module, public font_module { public: - font_win() - : osd_module(OSD_FONT_PROVIDER, "win"), font_module() - { - } + font_win() + : osd_module(OSD_FONT_PROVIDER, "win"), font_module() + { + } - osd_font *font_alloc() - { - return global_alloc(osd_font_windows); - } + osd_font *font_alloc() + { + return global_alloc(osd_font_windows); + } }; #else /* SDLMAME_UNIX */ - MODULE_NOT_SUPPORTED(font_win, OSD_FONT_PROVIDER, "win") + MODULE_NOT_SUPPORTED(font_win, OSD_FONT_PROVIDER, "win") #endif MODULE_DEFINITION(FONT_WINDOWS, font_win) diff --git a/src/osd/modules/lib/osdlib_macosx.c b/src/osd/modules/lib/osdlib_macosx.c index 5d6233bce25..088cbd969df 100644 --- a/src/osd/modules/lib/osdlib_macosx.c +++ b/src/osd/modules/lib/osdlib_macosx.c @@ -34,7 +34,7 @@ const char *osd_getenv(const char *name) { - return getenv(name); + return getenv(name); } //============================================================ @@ -43,7 +43,7 @@ const char *osd_getenv(const char *name) int osd_setenv(const char *name, const char *value, int overwrite) { - return setenv(name, value, overwrite); + return setenv(name, value, overwrite); } //============================================================ @@ -52,7 +52,7 @@ int osd_setenv(const char *name, const char *value, int overwrite) void osd_process_kill(void) { - kill(getpid(), SIGKILL); + kill(getpid(), SIGKILL); } //============================================================ @@ -61,22 +61,22 @@ void osd_process_kill(void) int osd_get_num_processors(void) { - int processors = 1; - - struct host_basic_info host_basic_info; - unsigned int count; - kern_return_t r; - mach_port_t my_mach_host_self; - - count = HOST_BASIC_INFO_COUNT; - my_mach_host_self = mach_host_self(); - if ( ( r = host_info(my_mach_host_self, HOST_BASIC_INFO, (host_info_t)(&host_basic_info), &count)) == KERN_SUCCESS ) - { - processors = host_basic_info.avail_cpus; - } - mach_port_deallocate(mach_task_self(), my_mach_host_self); - - return processors; + int processors = 1; + + struct host_basic_info host_basic_info; + unsigned int count; + kern_return_t r; + mach_port_t my_mach_host_self; + + count = HOST_BASIC_INFO_COUNT; + my_mach_host_self = mach_host_self(); + if ( ( r = host_info(my_mach_host_self, HOST_BASIC_INFO, (host_info_t)(&host_basic_info), &count)) == KERN_SUCCESS ) + { + processors = host_basic_info.avail_cpus; + } + mach_port_deallocate(mach_task_self(), my_mach_host_self); + + return processors; } //============================================================ @@ -86,7 +86,7 @@ int osd_get_num_processors(void) void *osd_malloc(size_t size) { #ifndef MALLOC_DEBUG - return malloc(size); + return malloc(size); #else #error "MALLOC_DEBUG not yet supported" #endif @@ -100,7 +100,7 @@ void *osd_malloc(size_t size) void *osd_malloc_array(size_t size) { #ifndef MALLOC_DEBUG - return malloc(size); + return malloc(size); #else #error "MALLOC_DEBUG not yet supported" #endif @@ -114,7 +114,7 @@ void *osd_malloc_array(size_t size) void osd_free(void *ptr) { #ifndef MALLOC_DEBUG - free(ptr); + free(ptr); #else #error "MALLOC_DEBUG not yet supported" #endif @@ -131,9 +131,9 @@ void osd_free(void *ptr) void *osd_alloc_executable(size_t size) { #if defined(SDLMAME_BSD) || defined(SDLMAME_MACOSX) - return (void *)mmap(0, size, PROT_EXEC|PROT_READ|PROT_WRITE, MAP_ANON|MAP_SHARED, -1, 0); + return (void *)mmap(0, size, PROT_EXEC|PROT_READ|PROT_WRITE, MAP_ANON|MAP_SHARED, -1, 0); #elif defined(SDLMAME_UNIX) - return (void *)mmap(0, size, PROT_EXEC|PROT_READ|PROT_WRITE, MAP_ANON|MAP_SHARED, 0, 0); + return (void *)mmap(0, size, PROT_EXEC|PROT_READ|PROT_WRITE, MAP_ANON|MAP_SHARED, 0, 0); #endif } @@ -146,9 +146,9 @@ void *osd_alloc_executable(size_t size) void osd_free_executable(void *ptr, size_t size) { #ifdef SDLMAME_SOLARIS - munmap((char *)ptr, size); + munmap((char *)ptr, size); #else - munmap(ptr, size); + munmap(ptr, size); #endif } @@ -158,13 +158,13 @@ void osd_free_executable(void *ptr, size_t size) void osd_break_into_debugger(const char *message) { - #ifdef MAME_DEBUG - printf("MAME exception: %s\n", message); - printf("Attempting to fall into debugger\n"); - kill(getpid(), SIGTRAP); - #else - printf("Ignoring MAME exception: %s\n", message); - #endif + #ifdef MAME_DEBUG + printf("MAME exception: %s\n", message); + printf("Attempting to fall into debugger\n"); + kill(getpid(), SIGTRAP); + #else + printf("Ignoring MAME exception: %s\n", message); + #endif } @@ -191,36 +191,36 @@ static osd_ticks_t ticks_per_second; static osd_ticks_t init_cycle_counter(void) { - osd_ticks_t start, end; - osd_ticks_t a, b; + osd_ticks_t start, end; + osd_ticks_t a, b; - cycle_counter = mach_cycle_counter; - ticks_counter = mach_cycle_counter; + cycle_counter = mach_cycle_counter; + ticks_counter = mach_cycle_counter; - // wait for an edge on the timeGetTime call - a = SDL_GetTicks(); - do - { - b = SDL_GetTicks(); - } while (a == b); + // wait for an edge on the timeGetTime call + a = SDL_GetTicks(); + do + { + b = SDL_GetTicks(); + } while (a == b); - // get the starting cycle count - start = (*cycle_counter)(); + // get the starting cycle count + start = (*cycle_counter)(); - // now wait for 1/4 second total - do - { - a = SDL_GetTicks(); - } while (a - b < 250); + // now wait for 1/4 second total + do + { + a = SDL_GetTicks(); + } while (a - b < 250); - // get the ending cycle count - end = (*cycle_counter)(); + // get the ending cycle count + end = (*cycle_counter)(); - // compute ticks_per_sec - ticks_per_second = (end - start) * 4; + // compute ticks_per_sec + ticks_per_second = (end - start) * 4; - // return the current cycle count - return (*cycle_counter)(); + // return the current cycle count + return (*cycle_counter)(); } //============================================================ @@ -232,7 +232,7 @@ static osd_ticks_t init_cycle_counter(void) //============================================================ static osd_ticks_t mach_cycle_counter(void) { - return mach_absolute_time(); + return mach_absolute_time(); } //============================================================ @@ -241,7 +241,7 @@ static osd_ticks_t mach_cycle_counter(void) osd_ticks_t osd_ticks(void) { - return (*cycle_counter)(); + return (*cycle_counter)(); } @@ -251,12 +251,12 @@ osd_ticks_t osd_ticks(void) osd_ticks_t osd_ticks_per_second(void) { - if (ticks_per_second == 0) - { - // if we haven't computed the value yet, there's no time like the present - init_cycle_counter(); - } - return ticks_per_second; + if (ticks_per_second == 0) + { + // if we haven't computed the value yet, there's no time like the present + init_cycle_counter(); + } + return ticks_per_second; } @@ -267,20 +267,20 @@ osd_ticks_t osd_ticks_per_second(void) void osd_sleep(osd_ticks_t duration) { - UINT32 msec; - - // make sure we've computed ticks_per_second - if (ticks_per_second == 0) - (void)osd_ticks(); - - // convert to milliseconds, rounding down - msec = (UINT32)(duration * 1000 / ticks_per_second); - - // only sleep if at least 2 full milliseconds - if (msec >= 2) - { - // take a couple of msecs off the top for good measure - msec -= 2; - usleep(msec*1000); - } + UINT32 msec; + + // make sure we've computed ticks_per_second + if (ticks_per_second == 0) + (void)osd_ticks(); + + // convert to milliseconds, rounding down + msec = (UINT32)(duration * 1000 / ticks_per_second); + + // only sleep if at least 2 full milliseconds + if (msec >= 2) + { + // take a couple of msecs off the top for good measure + msec -= 2; + usleep(msec*1000); + } } diff --git a/src/osd/modules/lib/osdlib_os2.c b/src/osd/modules/lib/osdlib_os2.c index d852ea5ce93..9e1ab8fd52d 100644 --- a/src/osd/modules/lib/osdlib_os2.c +++ b/src/osd/modules/lib/osdlib_os2.c @@ -31,7 +31,7 @@ const char *osd_getenv(const char *name) { - return getenv(name); + return getenv(name); } //============================================================ @@ -40,7 +40,7 @@ const char *osd_getenv(const char *name) int osd_setenv(const char *name, const char *value, int overwrite) { - return setenv(name, value, overwrite); + return setenv(name, value, overwrite); } //============================================================ @@ -49,7 +49,7 @@ int osd_setenv(const char *name, const char *value, int overwrite) void osd_process_kill(void) { - fprintf(stderr,"osd_process_kill missing in OS/2 build\n"); + fprintf(stderr,"osd_process_kill missing in OS/2 build\n"); } //============================================================ @@ -58,11 +58,11 @@ void osd_process_kill(void) int osd_get_num_processors(void) { - ULONG numprocs = 1; + ULONG numprocs = 1; - DosQuerySysInfo(QSV_NUMPROCESSORS, QSV_NUMPROCESSORS, &numprocs, sizeof(numprocs)); + DosQuerySysInfo(QSV_NUMPROCESSORS, QSV_NUMPROCESSORS, &numprocs, sizeof(numprocs)); - return numprocs; + return numprocs; } //============================================================ @@ -72,7 +72,7 @@ int osd_get_num_processors(void) void *osd_malloc(size_t size) { #ifndef MALLOC_DEBUG - return malloc(size); + return malloc(size); #else #error "MALLOC_DEBUG not yet supported" #endif @@ -86,7 +86,7 @@ void *osd_malloc(size_t size) void *osd_malloc_array(size_t size) { #ifndef MALLOC_DEBUG - return malloc(size); + return malloc(size); #else #error "MALLOC_DEBUG not yet supported" #endif @@ -100,7 +100,7 @@ void *osd_malloc_array(size_t size) void osd_free(void *ptr) { #ifndef MALLOC_DEBUG - free(ptr); + free(ptr); #else #error "MALLOC_DEBUG not yet supported" #endif @@ -116,10 +116,10 @@ void osd_free(void *ptr) void *osd_alloc_executable(size_t size) { - void *p; + void *p; - DosAllocMem( &p, size, fALLOC ); - return p; + DosAllocMem( &p, size, fALLOC ); + return p; } //============================================================ @@ -130,7 +130,7 @@ void *osd_alloc_executable(size_t size) void osd_free_executable(void *ptr, size_t size) { - DosFreeMem( ptr ); + DosFreeMem( ptr ); } //============================================================ @@ -139,7 +139,7 @@ void osd_free_executable(void *ptr, size_t size) void osd_break_into_debugger(const char *message) { - printf("Ignoring MAME exception: %s\n", message); + printf("Ignoring MAME exception: %s\n", message); } //============================================================ @@ -167,65 +167,65 @@ static osd_ticks_t ticks_per_second; static osd_ticks_t init_cycle_counter(void) { - osd_ticks_t start, end; - osd_ticks_t a, b; - - ULONG frequency; - PTIB ptib; - ULONG ulClass; - ULONG ulDelta; - - DosGetInfoBlocks( &ptib, NULL ); - ulClass = HIBYTE( ptib->tib_ptib2->tib2_ulpri ); - ulDelta = LOBYTE( ptib->tib_ptib2->tib2_ulpri ); - - if ( DosTmrQueryFreq( &frequency ) == 0 ) - { - // use performance counter if available as it is constant - cycle_counter = performance_cycle_counter; - ticks_counter = performance_cycle_counter; - - ticks_per_second = frequency; - - // return the current cycle count - return (*cycle_counter)(); - } - else - { - fprintf(stderr, "No Timer available!\n"); - exit(-1); - } - - // temporarily set our priority higher - DosSetPriority( PRTYS_THREAD, PRTYC_TIMECRITICAL, PRTYD_MAXIMUM, 0 ); - - // wait for an edge on the timeGetTime call - a = SDL_GetTicks(); - do - { - b = SDL_GetTicks(); - } while (a == b); - - // get the starting cycle count - start = (*cycle_counter)(); - - // now wait for 1/4 second total - do - { - a = SDL_GetTicks(); - } while (a - b < 250); - - // get the ending cycle count - end = (*cycle_counter)(); - - // compute ticks_per_sec - ticks_per_second = (end - start) * 4; - - // restore our priority - DosSetPriority( PRTYS_THREAD, ulClass, ulDelta, 0 ); - - // return the current cycle count - return (*cycle_counter)(); + osd_ticks_t start, end; + osd_ticks_t a, b; + + ULONG frequency; + PTIB ptib; + ULONG ulClass; + ULONG ulDelta; + + DosGetInfoBlocks( &ptib, NULL ); + ulClass = HIBYTE( ptib->tib_ptib2->tib2_ulpri ); + ulDelta = LOBYTE( ptib->tib_ptib2->tib2_ulpri ); + + if ( DosTmrQueryFreq( &frequency ) == 0 ) + { + // use performance counter if available as it is constant + cycle_counter = performance_cycle_counter; + ticks_counter = performance_cycle_counter; + + ticks_per_second = frequency; + + // return the current cycle count + return (*cycle_counter)(); + } + else + { + fprintf(stderr, "No Timer available!\n"); + exit(-1); + } + + // temporarily set our priority higher + DosSetPriority( PRTYS_THREAD, PRTYC_TIMECRITICAL, PRTYD_MAXIMUM, 0 ); + + // wait for an edge on the timeGetTime call + a = SDL_GetTicks(); + do + { + b = SDL_GetTicks(); + } while (a == b); + + // get the starting cycle count + start = (*cycle_counter)(); + + // now wait for 1/4 second total + do + { + a = SDL_GetTicks(); + } while (a - b < 250); + + // get the ending cycle count + end = (*cycle_counter)(); + + // compute ticks_per_sec + ticks_per_second = (end - start) * 4; + + // restore our priority + DosSetPriority( PRTYS_THREAD, ulClass, ulDelta, 0 ); + + // return the current cycle count + return (*cycle_counter)(); } //============================================================ @@ -234,10 +234,10 @@ static osd_ticks_t init_cycle_counter(void) static osd_ticks_t performance_cycle_counter(void) { - QWORD qwTime; + QWORD qwTime; - DosTmrQueryTime( &qwTime ); - return (osd_ticks_t)qwTime.ulLo; + DosTmrQueryTime( &qwTime ); + return (osd_ticks_t)qwTime.ulLo; } //============================================================ @@ -246,7 +246,7 @@ static osd_ticks_t performance_cycle_counter(void) osd_ticks_t osd_ticks(void) { - return (*cycle_counter)(); + return (*cycle_counter)(); } @@ -256,12 +256,12 @@ osd_ticks_t osd_ticks(void) osd_ticks_t osd_ticks_per_second(void) { - if (ticks_per_second == 0) - { - // if we haven't computed the value yet, there's no time like the present - init_cycle_counter(); - } - return ticks_per_second; + if (ticks_per_second == 0) + { + // if we haven't computed the value yet, there's no time like the present + init_cycle_counter(); + } + return ticks_per_second; } @@ -271,21 +271,20 @@ osd_ticks_t osd_ticks_per_second(void) void osd_sleep(osd_ticks_t duration) { - UINT32 msec; - - // make sure we've computed ticks_per_second - if (ticks_per_second == 0) - (void)osd_ticks(); - - // convert to milliseconds, rounding down - msec = (UINT32)(duration * 1000 / ticks_per_second); - - // only sleep if at least 2 full milliseconds - if (msec >= 2) - { - // take a couple of msecs off the top for good measure - msec -= 2; - usleep(msec*1000); - } + UINT32 msec; + + // make sure we've computed ticks_per_second + if (ticks_per_second == 0) + (void)osd_ticks(); + + // convert to milliseconds, rounding down + msec = (UINT32)(duration * 1000 / ticks_per_second); + + // only sleep if at least 2 full milliseconds + if (msec >= 2) + { + // take a couple of msecs off the top for good measure + msec -= 2; + usleep(msec*1000); + } } - diff --git a/src/osd/modules/lib/osdlib_unix.c b/src/osd/modules/lib/osdlib_unix.c index 39eed83b918..7fe3c37988d 100644 --- a/src/osd/modules/lib/osdlib_unix.c +++ b/src/osd/modules/lib/osdlib_unix.c @@ -30,7 +30,7 @@ const char *osd_getenv(const char *name) { - return getenv(name); + return getenv(name); } //============================================================ @@ -39,7 +39,7 @@ const char *osd_getenv(const char *name) int osd_setenv(const char *name, const char *value, int overwrite) { - return setenv(name, value, overwrite); + return setenv(name, value, overwrite); } //============================================================ @@ -48,7 +48,7 @@ int osd_setenv(const char *name, const char *value, int overwrite) void osd_process_kill(void) { - kill(getpid(), SIGKILL); + kill(getpid(), SIGKILL); } //============================================================ @@ -57,12 +57,12 @@ void osd_process_kill(void) int osd_get_num_processors(void) { - int processors = 1; + int processors = 1; #if defined(_SC_NPROCESSORS_ONLN) - processors = sysconf(_SC_NPROCESSORS_ONLN); + processors = sysconf(_SC_NPROCESSORS_ONLN); #endif - return processors; + return processors; } //============================================================ @@ -72,7 +72,7 @@ int osd_get_num_processors(void) void *osd_malloc(size_t size) { #ifndef MALLOC_DEBUG - return malloc(size); + return malloc(size); #else #error "MALLOC_DEBUG not yet supported" #endif @@ -86,7 +86,7 @@ void *osd_malloc(size_t size) void *osd_malloc_array(size_t size) { #ifndef MALLOC_DEBUG - return malloc(size); + return malloc(size); #else #error "MALLOC_DEBUG not yet supported" #endif @@ -100,7 +100,7 @@ void *osd_malloc_array(size_t size) void osd_free(void *ptr) { #ifndef MALLOC_DEBUG - free(ptr); + free(ptr); #else #error "MALLOC_DEBUG not yet supported" #endif @@ -116,9 +116,9 @@ void osd_free(void *ptr) void *osd_alloc_executable(size_t size) { #if defined(SDLMAME_BSD) || defined(SDLMAME_MACOSX) - return (void *)mmap(0, size, PROT_EXEC|PROT_READ|PROT_WRITE, MAP_ANON|MAP_SHARED, -1, 0); + return (void *)mmap(0, size, PROT_EXEC|PROT_READ|PROT_WRITE, MAP_ANON|MAP_SHARED, -1, 0); #elif defined(SDLMAME_UNIX) - return (void *)mmap(0, size, PROT_EXEC|PROT_READ|PROT_WRITE, MAP_ANON|MAP_SHARED, 0, 0); + return (void *)mmap(0, size, PROT_EXEC|PROT_READ|PROT_WRITE, MAP_ANON|MAP_SHARED, 0, 0); #endif } @@ -131,9 +131,9 @@ void *osd_alloc_executable(size_t size) void osd_free_executable(void *ptr, size_t size) { #ifdef SDLMAME_SOLARIS - munmap((char *)ptr, size); + munmap((char *)ptr, size); #else - munmap(ptr, size); + munmap(ptr, size); #endif } @@ -143,13 +143,13 @@ void osd_free_executable(void *ptr, size_t size) void osd_break_into_debugger(const char *message) { - #ifdef MAME_DEBUG - printf("MAME exception: %s\n", message); - printf("Attempting to fall into debugger\n"); - kill(getpid(), SIGTRAP); - #else - printf("Ignoring MAME exception: %s\n", message); - #endif + #ifdef MAME_DEBUG + printf("MAME exception: %s\n", message); + printf("Attempting to fall into debugger\n"); + kill(getpid(), SIGTRAP); + #else + printf("Ignoring MAME exception: %s\n", message); + #endif } @@ -160,15 +160,15 @@ void osd_break_into_debugger(const char *message) osd_ticks_t osd_ticks(void) { #ifdef SDLMAME_EMSCRIPTEN - return (osd_ticks_t)(emscripten_get_now() * 1000.0); + return (osd_ticks_t)(emscripten_get_now() * 1000.0); #else - struct timeval tp; - static osd_ticks_t start_sec = 0; + struct timeval tp; + static osd_ticks_t start_sec = 0; - gettimeofday(&tp, NULL); - if (start_sec==0) - start_sec = tp.tv_sec; - return (tp.tv_sec - start_sec) * (osd_ticks_t) 1000000 + tp.tv_usec; + gettimeofday(&tp, NULL); + if (start_sec==0) + start_sec = tp.tv_sec; + return (tp.tv_sec - start_sec) * (osd_ticks_t) 1000000 + tp.tv_usec; #endif } @@ -179,7 +179,7 @@ osd_ticks_t osd_ticks(void) osd_ticks_t osd_ticks_per_second(void) { - return (osd_ticks_t) 1000000; + return (osd_ticks_t) 1000000; } //============================================================ @@ -188,16 +188,16 @@ osd_ticks_t osd_ticks_per_second(void) void osd_sleep(osd_ticks_t duration) { - UINT32 msec; - - // convert to milliseconds, rounding down - msec = (UINT32)(duration * 1000 / osd_ticks_per_second()); - - // only sleep if at least 2 full milliseconds - if (msec >= 2) - { - // take a couple of msecs off the top for good measure - msec -= 2; - usleep(msec*1000); - } + UINT32 msec; + + // convert to milliseconds, rounding down + msec = (UINT32)(duration * 1000 / osd_ticks_per_second()); + + // only sleep if at least 2 full milliseconds + if (msec >= 2) + { + // take a couple of msecs off the top for good measure + msec -= 2; + usleep(msec*1000); + } } diff --git a/src/osd/modules/lib/osdlib_win32.c b/src/osd/modules/lib/osdlib_win32.c index 4d78820f7d6..3150cdafc97 100644 --- a/src/osd/modules/lib/osdlib_win32.c +++ b/src/osd/modules/lib/osdlib_win32.c @@ -53,7 +53,7 @@ void (*s_debugger_stack_crawler)() = NULL; const char *osd_getenv(const char *name) { - return getenv(name); + return getenv(name); } @@ -63,23 +63,23 @@ const char *osd_getenv(const char *name) int osd_setenv(const char *name, const char *value, int overwrite) { - char *buf; - int result; - - if (!overwrite) - { - if (osd_getenv(name) != NULL) - return 0; - } - buf = (char *) osd_malloc_array(strlen(name)+strlen(value)+2); - sprintf(buf, "%s=%s", name, value); - result = putenv(buf); - - /* will be referenced by environment - * Therefore it is not freed here - */ - - return result; + char *buf; + int result; + + if (!overwrite) + { + if (osd_getenv(name) != NULL) + return 0; + } + buf = (char *) osd_malloc_array(strlen(name)+strlen(value)+2); + sprintf(buf, "%s=%s", name, value); + result = putenv(buf); + + /* will be referenced by environment + * Therefore it is not freed here + */ + + return result; } //============================================================ @@ -88,7 +88,7 @@ int osd_setenv(const char *name, const char *value, int overwrite) void osd_process_kill(void) { - TerminateProcess(GetCurrentProcess(), -1); + TerminateProcess(GetCurrentProcess(), -1); } //============================================================ @@ -97,13 +97,13 @@ void osd_process_kill(void) int osd_get_num_processors(void) { - SYSTEM_INFO info; + SYSTEM_INFO info; - // otherwise, fetch the info from the system - GetSystemInfo(&info); + // otherwise, fetch the info from the system + GetSystemInfo(&info); - // max out at 4 for now since scaling above that seems to do poorly - return MIN(info.dwNumberOfProcessors, 4); + // max out at 4 for now since scaling above that seems to do poorly + return MIN(info.dwNumberOfProcessors, 4); } //============================================================ @@ -113,17 +113,17 @@ int osd_get_num_processors(void) void *osd_malloc(size_t size) { #ifndef MALLOC_DEBUG - return HeapAlloc(GetProcessHeap(), 0, size); + return HeapAlloc(GetProcessHeap(), 0, size); #else - // add in space for the size - size += sizeof(size_t); + // add in space for the size + size += sizeof(size_t); - // basic objects just come from the heap - void *result = HeapAlloc(GetProcessHeap(), 0, size); + // basic objects just come from the heap + void *result = HeapAlloc(GetProcessHeap(), 0, size); - // store the size and return and pointer to the data afterward - *reinterpret_cast<size_t *>(result) = size; - return reinterpret_cast<UINT8 *>(result) + sizeof(size_t); + // store the size and return and pointer to the data afterward + *reinterpret_cast<size_t *>(result) = size; + return reinterpret_cast<UINT8 *>(result) + sizeof(size_t); #endif } @@ -135,30 +135,30 @@ void *osd_malloc(size_t size) void *osd_malloc_array(size_t size) { #ifndef MALLOC_DEBUG - return HeapAlloc(GetProcessHeap(), 0, size); + return HeapAlloc(GetProcessHeap(), 0, size); #else - // add in space for the size - size += sizeof(size_t); + // add in space for the size + size += sizeof(size_t); - // round the size up to a page boundary - size_t rounded_size = ((size + sizeof(void *) + PAGE_SIZE - 1) / PAGE_SIZE) * PAGE_SIZE; + // round the size up to a page boundary + size_t rounded_size = ((size + sizeof(void *) + PAGE_SIZE - 1) / PAGE_SIZE) * PAGE_SIZE; - // reserve that much memory, plus two guard pages - void *page_base = VirtualAlloc(NULL, rounded_size + 2 * PAGE_SIZE, MEM_RESERVE, PAGE_NOACCESS); - if (page_base == NULL) - return NULL; + // reserve that much memory, plus two guard pages + void *page_base = VirtualAlloc(NULL, rounded_size + 2 * PAGE_SIZE, MEM_RESERVE, PAGE_NOACCESS); + if (page_base == NULL) + return NULL; - // now allow access to everything but the first and last pages - page_base = VirtualAlloc(reinterpret_cast<UINT8 *>(page_base) + PAGE_SIZE, rounded_size, MEM_COMMIT, PAGE_READWRITE); - if (page_base == NULL) - return NULL; + // now allow access to everything but the first and last pages + page_base = VirtualAlloc(reinterpret_cast<UINT8 *>(page_base) + PAGE_SIZE, rounded_size, MEM_COMMIT, PAGE_READWRITE); + if (page_base == NULL) + return NULL; - // work backwards from the page base to get to the block base - void *result = GUARD_ALIGN_START ? page_base : (reinterpret_cast<UINT8 *>(page_base) + rounded_size - size); + // work backwards from the page base to get to the block base + void *result = GUARD_ALIGN_START ? page_base : (reinterpret_cast<UINT8 *>(page_base) + rounded_size - size); - // store the size at the start with a flag indicating it has a guard page - *reinterpret_cast<size_t *>(result) = size | 0x80000000; - return reinterpret_cast<UINT8 *>(result) + sizeof(size_t); + // store the size at the start with a flag indicating it has a guard page + *reinterpret_cast<size_t *>(result) = size | 0x80000000; + return reinterpret_cast<UINT8 *>(result) + sizeof(size_t); #endif } @@ -170,20 +170,20 @@ void *osd_malloc_array(size_t size) void osd_free(void *ptr) { #ifndef MALLOC_DEBUG - HeapFree(GetProcessHeap(), 0, ptr); + HeapFree(GetProcessHeap(), 0, ptr); #else - size_t size = reinterpret_cast<size_t *>(ptr)[-1]; - - // if no guard page, just free the pointer - if ((size & 0x80000000) == 0) - HeapFree(GetProcessHeap(), 0, reinterpret_cast<UINT8 *>(ptr) - sizeof(size_t)); - - // large items need more care - else - { - ULONG_PTR page_base = (reinterpret_cast<ULONG_PTR>(ptr) - sizeof(size_t)) & ~(PAGE_SIZE - 1); - VirtualFree(reinterpret_cast<void *>(page_base - PAGE_SIZE), 0, MEM_RELEASE); - } + size_t size = reinterpret_cast<size_t *>(ptr)[-1]; + + // if no guard page, just free the pointer + if ((size & 0x80000000) == 0) + HeapFree(GetProcessHeap(), 0, reinterpret_cast<UINT8 *>(ptr) - sizeof(size_t)); + + // large items need more care + else + { + ULONG_PTR page_base = (reinterpret_cast<ULONG_PTR>(ptr) - sizeof(size_t)) & ~(PAGE_SIZE - 1); + VirtualFree(reinterpret_cast<void *>(page_base - PAGE_SIZE), 0, MEM_RELEASE); + } #endif } @@ -197,7 +197,7 @@ void osd_free(void *ptr) void *osd_alloc_executable(size_t size) { - return VirtualAlloc(NULL, size, MEM_COMMIT, PAGE_EXECUTE_READWRITE); + return VirtualAlloc(NULL, size, MEM_COMMIT, PAGE_EXECUTE_READWRITE); } @@ -209,7 +209,7 @@ void *osd_alloc_executable(size_t size) void osd_free_executable(void *ptr, size_t size) { - VirtualFree(ptr, 0, MEM_RELEASE); + VirtualFree(ptr, 0, MEM_RELEASE); } @@ -220,19 +220,19 @@ void osd_free_executable(void *ptr, size_t size) void osd_break_into_debugger(const char *message) { #ifdef OSD_WINDOWS - if (IsDebuggerPresent()) - { - win_output_debug_string_utf8(message); - DebugBreak(); - } - else if (s_debugger_stack_crawler != NULL) - (*s_debugger_stack_crawler)(); + if (IsDebuggerPresent()) + { + win_output_debug_string_utf8(message); + DebugBreak(); + } + else if (s_debugger_stack_crawler != NULL) + (*s_debugger_stack_crawler)(); #else - if (IsDebuggerPresent()) - { - OutputDebugStringA(message); - DebugBreak(); - } + if (IsDebuggerPresent()) + { + OutputDebugStringA(message); + DebugBreak(); + } #endif } @@ -252,36 +252,36 @@ static BOOL using_qpc = TRUE; osd_ticks_t osd_ticks(void) { - LARGE_INTEGER performance_count; - - // if we're suspended, just return that - if (suspend_ticks != 0) - return suspend_ticks; - - // if we have a per second count, just go for it - if (ticks_per_second != 0) - { - // QueryPerformanceCounter if we can - if (using_qpc) - { - QueryPerformanceCounter(&performance_count); - return (osd_ticks_t)performance_count.QuadPart - suspend_ticks; - } - - // otherwise, fall back to timeGetTime - else - return (osd_ticks_t)timeGetTime() - suspend_ticks; - } - - // if not, we have to determine it - using_qpc = QueryPerformanceFrequency(&performance_count) && (performance_count.QuadPart != 0); - if (using_qpc) - ticks_per_second = (osd_ticks_t)performance_count.QuadPart; - else - ticks_per_second = 1000; - - // call ourselves to get the first value - return osd_ticks(); + LARGE_INTEGER performance_count; + + // if we're suspended, just return that + if (suspend_ticks != 0) + return suspend_ticks; + + // if we have a per second count, just go for it + if (ticks_per_second != 0) + { + // QueryPerformanceCounter if we can + if (using_qpc) + { + QueryPerformanceCounter(&performance_count); + return (osd_ticks_t)performance_count.QuadPart - suspend_ticks; + } + + // otherwise, fall back to timeGetTime + else + return (osd_ticks_t)timeGetTime() - suspend_ticks; + } + + // if not, we have to determine it + using_qpc = QueryPerformanceFrequency(&performance_count) && (performance_count.QuadPart != 0); + if (using_qpc) + ticks_per_second = (osd_ticks_t)performance_count.QuadPart; + else + ticks_per_second = 1000; + + // call ourselves to get the first value + return osd_ticks(); } @@ -291,9 +291,9 @@ osd_ticks_t osd_ticks(void) osd_ticks_t osd_ticks_per_second(void) { - if (ticks_per_second == 0) - osd_ticks(); - return ticks_per_second; + if (ticks_per_second == 0) + osd_ticks(); + return ticks_per_second; } //============================================================ @@ -302,28 +302,28 @@ osd_ticks_t osd_ticks_per_second(void) void osd_sleep(osd_ticks_t duration) { - DWORD msec; - - // make sure we've computed ticks_per_second - if (ticks_per_second == 0) - (void)osd_ticks(); - - // convert to milliseconds, rounding down - msec = (DWORD)(duration * 1000 / ticks_per_second); - - // only sleep if at least 2 full milliseconds - if (msec >= 2) - { - HANDLE current_thread = GetCurrentThread(); - int old_priority = GetThreadPriority(current_thread); - - // take a couple of msecs off the top for good measure - msec -= 2; - - // bump our thread priority super high so that we get - // priority when we need it - SetThreadPriority(current_thread, THREAD_PRIORITY_TIME_CRITICAL); - Sleep(msec); - SetThreadPriority(current_thread, old_priority); - } + DWORD msec; + + // make sure we've computed ticks_per_second + if (ticks_per_second == 0) + (void)osd_ticks(); + + // convert to milliseconds, rounding down + msec = (DWORD)(duration * 1000 / ticks_per_second); + + // only sleep if at least 2 full milliseconds + if (msec >= 2) + { + HANDLE current_thread = GetCurrentThread(); + int old_priority = GetThreadPriority(current_thread); + + // take a couple of msecs off the top for good measure + msec -= 2; + + // bump our thread priority super high so that we get + // priority when we need it + SetThreadPriority(current_thread, THREAD_PRIORITY_TIME_CRITICAL); + Sleep(msec); + SetThreadPriority(current_thread, old_priority); + } } diff --git a/src/osd/modules/lib/osdobj_common.c b/src/osd/modules/lib/osdobj_common.c index 73580dba2fd..57731edc591 100644 --- a/src/osd/modules/lib/osdobj_common.c +++ b/src/osd/modules/lib/osdobj_common.c @@ -17,79 +17,79 @@ extern bool g_print_verbose; const options_entry osd_options::s_option_entries[] = { - { NULL, NULL, OPTION_HEADER, "OSD FONT OPTIONS" }, - { OSD_FONT_PROVIDER, "auto", OPTION_STRING, "provider for ui font: " }, - - { NULL, NULL, OPTION_HEADER, "OSD CLI OPTIONS" }, - { OSDCOMMAND_LIST_MIDI_DEVICES ";mlist", "0", OPTION_COMMAND, "list available MIDI I/O devices" }, - { OSDCOMMAND_LIST_NETWORK_ADAPTERS ";nlist", "0", OPTION_COMMAND, "list available network adapters" }, - - // debugging options - { NULL, NULL, OPTION_HEADER, "OSD DEBUGGING OPTIONS" }, - { OSDOPTION_DEBUGGER, OSDOPTVAL_AUTO, OPTION_STRING, "debugger used : " }, - { OSDOPTION_WATCHDOG ";wdog", "0", OPTION_INTEGER, "force the program to terminate if no updates within specified number of seconds" }, - - // performance options - { NULL, NULL, OPTION_HEADER, "OSD PERFORMANCE OPTIONS" }, - { OSDOPTION_MULTITHREADING ";mt", "0", OPTION_BOOLEAN, "enable multithreading; this enables rendering and blitting on a separate thread" }, - { OSDOPTION_NUMPROCESSORS ";np", OSDOPTVAL_AUTO, OPTION_STRING, "number of processors; this overrides the number the system reports" }, - { OSDOPTION_BENCH, "0", OPTION_INTEGER, "benchmark for the given number of emulated seconds; implies -video none -sound none -nothrottle" }, - // video options - { NULL, NULL, OPTION_HEADER, "OSD VIDEO OPTIONS" }, + { NULL, NULL, OPTION_HEADER, "OSD FONT OPTIONS" }, + { OSD_FONT_PROVIDER, "auto", OPTION_STRING, "provider for ui font: " }, + + { NULL, NULL, OPTION_HEADER, "OSD CLI OPTIONS" }, + { OSDCOMMAND_LIST_MIDI_DEVICES ";mlist", "0", OPTION_COMMAND, "list available MIDI I/O devices" }, + { OSDCOMMAND_LIST_NETWORK_ADAPTERS ";nlist", "0", OPTION_COMMAND, "list available network adapters" }, + + // debugging options + { NULL, NULL, OPTION_HEADER, "OSD DEBUGGING OPTIONS" }, + { OSDOPTION_DEBUGGER, OSDOPTVAL_AUTO, OPTION_STRING, "debugger used : " }, + { OSDOPTION_WATCHDOG ";wdog", "0", OPTION_INTEGER, "force the program to terminate if no updates within specified number of seconds" }, + + // performance options + { NULL, NULL, OPTION_HEADER, "OSD PERFORMANCE OPTIONS" }, + { OSDOPTION_MULTITHREADING ";mt", "0", OPTION_BOOLEAN, "enable multithreading; this enables rendering and blitting on a separate thread" }, + { OSDOPTION_NUMPROCESSORS ";np", OSDOPTVAL_AUTO, OPTION_STRING, "number of processors; this overrides the number the system reports" }, + { OSDOPTION_BENCH, "0", OPTION_INTEGER, "benchmark for the given number of emulated seconds; implies -video none -sound none -nothrottle" }, + // video options + { NULL, NULL, OPTION_HEADER, "OSD VIDEO OPTIONS" }, // OS X can be trusted to have working hardware OpenGL, so default to it on for the best user experience - { OSDOPTION_VIDEO, OSDOPTVAL_AUTO, OPTION_STRING, "video output method: " }, - { OSDOPTION_NUMSCREENS "(1-4)", "1", OPTION_INTEGER, "number of screens to create; usually, you want just one" }, - { OSDOPTION_WINDOW ";w", "0", OPTION_BOOLEAN, "enable window mode; otherwise, full screen mode is assumed" }, - { OSDOPTION_MAXIMIZE ";max", "1", OPTION_BOOLEAN, "default to maximized windows; otherwise, windows will be minimized" }, - { OSDOPTION_KEEPASPECT ";ka", "1", OPTION_BOOLEAN, "constrain to the proper aspect ratio" }, - { OSDOPTION_UNEVENSTRETCH ";ues", "1", OPTION_BOOLEAN, "allow non-integer stretch factors" }, - { OSDOPTION_WAITVSYNC ";vs", "0", OPTION_BOOLEAN, "enable waiting for the start of VBLANK before flipping screens; reduces tearing effects" }, - { OSDOPTION_SYNCREFRESH ";srf", "0", OPTION_BOOLEAN, "enable using the start of VBLANK for throttling instead of the game time" }, - - // per-window options - { NULL, NULL, OPTION_HEADER, "OSD PER-WINDOW VIDEO OPTIONS" }, - { OSDOPTION_SCREEN, OSDOPTVAL_AUTO, OPTION_STRING, "explicit name of the first screen; 'auto' here will try to make a best guess" }, - { OSDOPTION_ASPECT ";screen_aspect", OSDOPTVAL_AUTO, OPTION_STRING, "aspect ratio for all screens; 'auto' here will try to make a best guess" }, - { OSDOPTION_RESOLUTION ";r", OSDOPTVAL_AUTO, OPTION_STRING, "preferred resolution for all screens; format is <width>x<height>[@<refreshrate>] or 'auto'" }, - { OSDOPTION_VIEW, OSDOPTVAL_AUTO, OPTION_STRING, "preferred view for all screens" }, - - { OSDOPTION_SCREEN "0", OSDOPTVAL_AUTO, OPTION_STRING, "explicit name of the first screen; 'auto' here will try to make a best guess" }, - { OSDOPTION_ASPECT "0", OSDOPTVAL_AUTO, OPTION_STRING, "aspect ratio of the first screen; 'auto' here will try to make a best guess" }, - { OSDOPTION_RESOLUTION "0;r0", OSDOPTVAL_AUTO, OPTION_STRING, "preferred resolution of the first screen; format is <width>x<height>[@<refreshrate>] or 'auto'" }, - { OSDOPTION_VIEW "0", OSDOPTVAL_AUTO, OPTION_STRING, "preferred view for the first screen" }, - - { OSDOPTION_SCREEN "1", OSDOPTVAL_AUTO, OPTION_STRING, "explicit name of the second screen; 'auto' here will try to make a best guess" }, - { OSDOPTION_ASPECT "1", OSDOPTVAL_AUTO, OPTION_STRING, "aspect ratio of the second screen; 'auto' here will try to make a best guess" }, - { OSDOPTION_RESOLUTION "1;r1", OSDOPTVAL_AUTO, OPTION_STRING, "preferred resolution of the second screen; format is <width>x<height>[@<refreshrate>] or 'auto'" }, - { OSDOPTION_VIEW "1", OSDOPTVAL_AUTO, OPTION_STRING, "preferred view for the second screen" }, - - { OSDOPTION_SCREEN "2", OSDOPTVAL_AUTO, OPTION_STRING, "explicit name of the third screen; 'auto' here will try to make a best guess" }, - { OSDOPTION_ASPECT "2", OSDOPTVAL_AUTO, OPTION_STRING, "aspect ratio of the third screen; 'auto' here will try to make a best guess" }, - { OSDOPTION_RESOLUTION "2;r2", OSDOPTVAL_AUTO, OPTION_STRING, "preferred resolution of the third screen; format is <width>x<height>[@<refreshrate>] or 'auto'" }, - { OSDOPTION_VIEW "2", OSDOPTVAL_AUTO, OPTION_STRING, "preferred view for the third screen" }, - - { OSDOPTION_SCREEN "3", OSDOPTVAL_AUTO, OPTION_STRING, "explicit name of the fourth screen; 'auto' here will try to make a best guess" }, - { OSDOPTION_ASPECT "3", OSDOPTVAL_AUTO, OPTION_STRING, "aspect ratio of the fourth screen; 'auto' here will try to make a best guess" }, - { OSDOPTION_RESOLUTION "3;r3", OSDOPTVAL_AUTO, OPTION_STRING, "preferred resolution of the fourth screen; format is <width>x<height>[@<refreshrate>] or 'auto'" }, - { OSDOPTION_VIEW "3", OSDOPTVAL_AUTO, OPTION_STRING, "preferred view for the fourth screen" }, - - // full screen options - { NULL, NULL, OPTION_HEADER, "OSD FULL SCREEN OPTIONS" }, - { OSDOPTION_SWITCHRES, "0", OPTION_BOOLEAN, "enable resolution switching" }, - - // sound options - { NULL, NULL, OPTION_HEADER, "OSD SOUND OPTIONS" }, - { OSDOPTION_SOUND, OSDOPTVAL_AUTO, OPTION_STRING, "sound output method: " }, - { OSDOPTION_AUDIO_LATENCY "(1-5)", "2", OPTION_INTEGER, "set audio latency (increase to reduce glitches, decrease for responsiveness)" }, - - // End of list - { NULL } + { OSDOPTION_VIDEO, OSDOPTVAL_AUTO, OPTION_STRING, "video output method: " }, + { OSDOPTION_NUMSCREENS "(1-4)", "1", OPTION_INTEGER, "number of screens to create; usually, you want just one" }, + { OSDOPTION_WINDOW ";w", "0", OPTION_BOOLEAN, "enable window mode; otherwise, full screen mode is assumed" }, + { OSDOPTION_MAXIMIZE ";max", "1", OPTION_BOOLEAN, "default to maximized windows; otherwise, windows will be minimized" }, + { OSDOPTION_KEEPASPECT ";ka", "1", OPTION_BOOLEAN, "constrain to the proper aspect ratio" }, + { OSDOPTION_UNEVENSTRETCH ";ues", "1", OPTION_BOOLEAN, "allow non-integer stretch factors" }, + { OSDOPTION_WAITVSYNC ";vs", "0", OPTION_BOOLEAN, "enable waiting for the start of VBLANK before flipping screens; reduces tearing effects" }, + { OSDOPTION_SYNCREFRESH ";srf", "0", OPTION_BOOLEAN, "enable using the start of VBLANK for throttling instead of the game time" }, + + // per-window options + { NULL, NULL, OPTION_HEADER, "OSD PER-WINDOW VIDEO OPTIONS" }, + { OSDOPTION_SCREEN, OSDOPTVAL_AUTO, OPTION_STRING, "explicit name of the first screen; 'auto' here will try to make a best guess" }, + { OSDOPTION_ASPECT ";screen_aspect", OSDOPTVAL_AUTO, OPTION_STRING, "aspect ratio for all screens; 'auto' here will try to make a best guess" }, + { OSDOPTION_RESOLUTION ";r", OSDOPTVAL_AUTO, OPTION_STRING, "preferred resolution for all screens; format is <width>x<height>[@<refreshrate>] or 'auto'" }, + { OSDOPTION_VIEW, OSDOPTVAL_AUTO, OPTION_STRING, "preferred view for all screens" }, + + { OSDOPTION_SCREEN "0", OSDOPTVAL_AUTO, OPTION_STRING, "explicit name of the first screen; 'auto' here will try to make a best guess" }, + { OSDOPTION_ASPECT "0", OSDOPTVAL_AUTO, OPTION_STRING, "aspect ratio of the first screen; 'auto' here will try to make a best guess" }, + { OSDOPTION_RESOLUTION "0;r0", OSDOPTVAL_AUTO, OPTION_STRING, "preferred resolution of the first screen; format is <width>x<height>[@<refreshrate>] or 'auto'" }, + { OSDOPTION_VIEW "0", OSDOPTVAL_AUTO, OPTION_STRING, "preferred view for the first screen" }, + + { OSDOPTION_SCREEN "1", OSDOPTVAL_AUTO, OPTION_STRING, "explicit name of the second screen; 'auto' here will try to make a best guess" }, + { OSDOPTION_ASPECT "1", OSDOPTVAL_AUTO, OPTION_STRING, "aspect ratio of the second screen; 'auto' here will try to make a best guess" }, + { OSDOPTION_RESOLUTION "1;r1", OSDOPTVAL_AUTO, OPTION_STRING, "preferred resolution of the second screen; format is <width>x<height>[@<refreshrate>] or 'auto'" }, + { OSDOPTION_VIEW "1", OSDOPTVAL_AUTO, OPTION_STRING, "preferred view for the second screen" }, + + { OSDOPTION_SCREEN "2", OSDOPTVAL_AUTO, OPTION_STRING, "explicit name of the third screen; 'auto' here will try to make a best guess" }, + { OSDOPTION_ASPECT "2", OSDOPTVAL_AUTO, OPTION_STRING, "aspect ratio of the third screen; 'auto' here will try to make a best guess" }, + { OSDOPTION_RESOLUTION "2;r2", OSDOPTVAL_AUTO, OPTION_STRING, "preferred resolution of the third screen; format is <width>x<height>[@<refreshrate>] or 'auto'" }, + { OSDOPTION_VIEW "2", OSDOPTVAL_AUTO, OPTION_STRING, "preferred view for the third screen" }, + + { OSDOPTION_SCREEN "3", OSDOPTVAL_AUTO, OPTION_STRING, "explicit name of the fourth screen; 'auto' here will try to make a best guess" }, + { OSDOPTION_ASPECT "3", OSDOPTVAL_AUTO, OPTION_STRING, "aspect ratio of the fourth screen; 'auto' here will try to make a best guess" }, + { OSDOPTION_RESOLUTION "3;r3", OSDOPTVAL_AUTO, OPTION_STRING, "preferred resolution of the fourth screen; format is <width>x<height>[@<refreshrate>] or 'auto'" }, + { OSDOPTION_VIEW "3", OSDOPTVAL_AUTO, OPTION_STRING, "preferred view for the fourth screen" }, + + // full screen options + { NULL, NULL, OPTION_HEADER, "OSD FULL SCREEN OPTIONS" }, + { OSDOPTION_SWITCHRES, "0", OPTION_BOOLEAN, "enable resolution switching" }, + + // sound options + { NULL, NULL, OPTION_HEADER, "OSD SOUND OPTIONS" }, + { OSDOPTION_SOUND, OSDOPTVAL_AUTO, OPTION_STRING, "sound output method: " }, + { OSDOPTION_AUDIO_LATENCY "(1-5)", "2", OPTION_INTEGER, "set audio latency (increase to reduce glitches, decrease for responsiveness)" }, + + // End of list + { NULL } }; osd_options::osd_options() : cli_options() { - add_entries(osd_options::s_option_entries); + add_entries(osd_options::s_option_entries); }; @@ -99,9 +99,9 @@ osd_options::osd_options() osd_common_t::osd_common_t(osd_options &options) : m_machine(NULL), - m_options(options), - m_sound(NULL), - m_debugger(NULL) + m_options(options), + m_sound(NULL), + m_debugger(NULL) { } @@ -110,52 +110,51 @@ osd_common_t::osd_common_t(osd_options &options) void osd_common_t::register_options() { + REGISTER_MODULE(m_mod_man, FONT_OSX); + REGISTER_MODULE(m_mod_man, FONT_WINDOWS); + REGISTER_MODULE(m_mod_man, FONT_SDL); + REGISTER_MODULE(m_mod_man, FONT_NONE); - REGISTER_MODULE(m_mod_man, FONT_OSX); - REGISTER_MODULE(m_mod_man, FONT_WINDOWS); - REGISTER_MODULE(m_mod_man, FONT_SDL); - REGISTER_MODULE(m_mod_man, FONT_NONE); - - REGISTER_MODULE(m_mod_man, SOUND_DSOUND); - REGISTER_MODULE(m_mod_man, SOUND_JS); - REGISTER_MODULE(m_mod_man, SOUND_SDL); - REGISTER_MODULE(m_mod_man, SOUND_NONE); + REGISTER_MODULE(m_mod_man, SOUND_DSOUND); + REGISTER_MODULE(m_mod_man, SOUND_JS); + REGISTER_MODULE(m_mod_man, SOUND_SDL); + REGISTER_MODULE(m_mod_man, SOUND_NONE); #ifdef SDLMAME_MACOSX - REGISTER_MODULE(m_mod_man, DEBUG_OSX); + REGISTER_MODULE(m_mod_man, DEBUG_OSX); #endif - REGISTER_MODULE(m_mod_man, DEBUG_WINDOWS); - REGISTER_MODULE(m_mod_man, DEBUG_QT); - REGISTER_MODULE(m_mod_man, DEBUG_INTERNAL); - REGISTER_MODULE(m_mod_man, DEBUG_NONE); - - // after initialization we know which modules are supported - - const char *names[20]; - int num; - m_mod_man.get_module_names(OSD_FONT_PROVIDER, 20, &num, names); - dynamic_array<const char *> dnames; - for (int i = 0; i < num; i++) - dnames.append(names[i]); - update_option(OSD_FONT_PROVIDER, dnames); - - m_mod_man.get_module_names(OSD_SOUND_PROVIDER, 20, &num, names); - dnames.reset(); - for (int i = 0; i < num; i++) - dnames.append(names[i]); - update_option(OSD_SOUND_PROVIDER, dnames); - - // Register debugger options and update options - m_mod_man.get_module_names(OSD_DEBUG_PROVIDER, 20, &num, names); - dnames.reset(); - for (int i = 0; i < num; i++) - dnames.append(names[i]); - update_option(OSD_DEBUG_PROVIDER, dnames); - - // Register video options and update options - video_options_add("none", NULL); - video_register(); - update_option(OSDOPTION_VIDEO, m_video_names); + REGISTER_MODULE(m_mod_man, DEBUG_WINDOWS); + REGISTER_MODULE(m_mod_man, DEBUG_QT); + REGISTER_MODULE(m_mod_man, DEBUG_INTERNAL); + REGISTER_MODULE(m_mod_man, DEBUG_NONE); + + // after initialization we know which modules are supported + + const char *names[20]; + int num; + m_mod_man.get_module_names(OSD_FONT_PROVIDER, 20, &num, names); + dynamic_array<const char *> dnames; + for (int i = 0; i < num; i++) + dnames.append(names[i]); + update_option(OSD_FONT_PROVIDER, dnames); + + m_mod_man.get_module_names(OSD_SOUND_PROVIDER, 20, &num, names); + dnames.reset(); + for (int i = 0; i < num; i++) + dnames.append(names[i]); + update_option(OSD_SOUND_PROVIDER, dnames); + + // Register debugger options and update options + m_mod_man.get_module_names(OSD_DEBUG_PROVIDER, 20, &num, names); + dnames.reset(); + for (int i = 0; i < num; i++) + dnames.append(names[i]); + update_option(OSD_DEBUG_PROVIDER, dnames); + + // Register video options and update options + video_options_add("none", NULL); + video_register(); + update_option(OSDOPTION_VIDEO, m_video_names); } void osd_common_t::update_option(const char * key, dynamic_array<const char *> &values) @@ -305,7 +304,7 @@ void osd_common_t::update_audio_stream(const INT16 *buffer, int samples_this_fra // It provides an array of stereo samples in L-R order which should be // output at the configured sample_rate. // - m_sound->update_audio_stream(m_machine->video().throttled(), buffer,samples_this_frame); + m_sound->update_audio_stream(m_machine->video().throttled(), buffer,samples_this_frame); } @@ -322,8 +321,8 @@ void osd_common_t::set_mastervolume(int attenuation) // while (attenuation++ < 0) // volume /= 1.122018454; // = (10 ^ (1/20)) = 1dB // - if (m_sound != NULL) - m_sound->set_mastervolume(attenuation); + if (m_sound != NULL) + m_sound->set_mastervolume(attenuation); } @@ -398,20 +397,20 @@ void *osd_common_t::get_slider_list() bool osd_common_t::execute_command(const char *command) { - if (strcmp(command, OSDCOMMAND_LIST_NETWORK_ADAPTERS) == 0) - { - network_init(); - osd_list_network_adapters(); - network_exit(); - return true; - } - else if (strcmp(command, OSDCOMMAND_LIST_MIDI_DEVICES) == 0) - { - osd_list_midi_devices(); - return true; - } + if (strcmp(command, OSDCOMMAND_LIST_NETWORK_ADAPTERS) == 0) + { + network_init(); + osd_list_network_adapters(); + network_exit(); + return true; + } + else if (strcmp(command, OSDCOMMAND_LIST_MIDI_DEVICES) == 0) + { + osd_list_midi_devices(); + return true; + } - return false; + return false; } @@ -437,15 +436,15 @@ void osd_common_t::init_subsystems() #endif midi_init(); - m_font_module = select_module_options<font_module *>(options(), OSD_FONT_PROVIDER); + m_font_module = select_module_options<font_module *>(options(), OSD_FONT_PROVIDER); - m_sound = select_module_options<sound_module *>(options(), OSD_SOUND_PROVIDER); - m_sound->m_sample_rate = options().sample_rate(); - m_sound->m_audio_latency = options().audio_latency(); + m_sound = select_module_options<sound_module *>(options(), OSD_SOUND_PROVIDER); + m_sound->m_sample_rate = options().sample_rate(); + m_sound->m_audio_latency = options().audio_latency(); - m_debugger = select_module_options<debug_module *>(options(), OSD_DEBUG_PROVIDER); + m_debugger = select_module_options<debug_module *>(options(), OSD_DEBUG_PROVIDER); - m_mod_man.init(); + m_mod_man.init(); } @@ -524,9 +523,9 @@ void osd_common_t::network_exit() void osd_common_t::osd_exit() { - m_mod_man.exit(); + m_mod_man.exit(); - exit_subsystems(); + exit_subsystems(); } void osd_common_t::video_options_add(const char *name, void *type) @@ -537,13 +536,11 @@ void osd_common_t::video_options_add(const char *name, void *type) bool osd_common_t::midi_init() { - // this should be done on the OS_level - return osd_midi_init(); + // this should be done on the OS_level + return osd_midi_init(); } void osd_common_t::midi_exit() { - osd_midi_exit(); + osd_midi_exit(); } - - diff --git a/src/osd/modules/lib/osdobj_common.h b/src/osd/modules/lib/osdobj_common.h index 3ea631a4495..322bcadf682 100644 --- a/src/osd/modules/lib/osdobj_common.h +++ b/src/osd/modules/lib/osdobj_common.h @@ -62,47 +62,47 @@ class osd_options : public cli_options { public: - // construction/destruction - osd_options(); - - // debugging options - const char *debugger() const { return value(OSDOPTION_DEBUGGER); } - int watchdog() const { return int_value(OSDOPTION_WATCHDOG); } - - // performance options - bool multithreading() const { return bool_value(OSDOPTION_MULTITHREADING); } - const char *numprocessors() const { return value(OSDOPTION_NUMPROCESSORS); } - int bench() const { return int_value(OSDOPTION_BENCH); } - - // video options - const char *video() const { return value(OSDOPTION_VIDEO); } - int numscreens() const { return int_value(OSDOPTION_NUMSCREENS); } - bool window() const { return bool_value(OSDOPTION_WINDOW); } - bool maximize() const { return bool_value(OSDOPTION_MAXIMIZE); } - bool keep_aspect() const { return bool_value(OSDOPTION_KEEPASPECT); } - bool uneven_stretch() const { return bool_value(OSDOPTION_UNEVENSTRETCH); } - bool wait_vsync() const { return bool_value(OSDOPTION_WAITVSYNC); } - bool sync_refresh() const { return bool_value(OSDOPTION_SYNCREFRESH); } - - // per-window options - const char *screen() const { return value(OSDOPTION_SCREEN); } - const char *aspect() const { return value(OSDOPTION_ASPECT); } - const char *resolution() const { return value(OSDOPTION_RESOLUTION); } - const char *view() const { return value(OSDOPTION_VIEW); } - const char *screen(int index) const { astring temp; return value(temp.format("%s%d", OSDOPTION_SCREEN, index)); } - const char *aspect(int index) const { astring temp; return value(temp.format("%s%d", OSDOPTION_ASPECT, index)); } - const char *resolution(int index) const { astring temp; return value(temp.format("%s%d", OSDOPTION_RESOLUTION, index)); } - const char *view(int index) const { astring temp; return value(temp.format("%s%d", OSDOPTION_VIEW, index)); } - - // full screen options - bool switch_res() const { return bool_value(OSDOPTION_SWITCHRES); } - - // sound options - const char *sound() const { return value(OSDOPTION_SOUND); } - int audio_latency() const { return int_value(OSDOPTION_AUDIO_LATENCY); } + // construction/destruction + osd_options(); + + // debugging options + const char *debugger() const { return value(OSDOPTION_DEBUGGER); } + int watchdog() const { return int_value(OSDOPTION_WATCHDOG); } + + // performance options + bool multithreading() const { return bool_value(OSDOPTION_MULTITHREADING); } + const char *numprocessors() const { return value(OSDOPTION_NUMPROCESSORS); } + int bench() const { return int_value(OSDOPTION_BENCH); } + + // video options + const char *video() const { return value(OSDOPTION_VIDEO); } + int numscreens() const { return int_value(OSDOPTION_NUMSCREENS); } + bool window() const { return bool_value(OSDOPTION_WINDOW); } + bool maximize() const { return bool_value(OSDOPTION_MAXIMIZE); } + bool keep_aspect() const { return bool_value(OSDOPTION_KEEPASPECT); } + bool uneven_stretch() const { return bool_value(OSDOPTION_UNEVENSTRETCH); } + bool wait_vsync() const { return bool_value(OSDOPTION_WAITVSYNC); } + bool sync_refresh() const { return bool_value(OSDOPTION_SYNCREFRESH); } + + // per-window options + const char *screen() const { return value(OSDOPTION_SCREEN); } + const char *aspect() const { return value(OSDOPTION_ASPECT); } + const char *resolution() const { return value(OSDOPTION_RESOLUTION); } + const char *view() const { return value(OSDOPTION_VIEW); } + const char *screen(int index) const { astring temp; return value(temp.format("%s%d", OSDOPTION_SCREEN, index)); } + const char *aspect(int index) const { astring temp; return value(temp.format("%s%d", OSDOPTION_ASPECT, index)); } + const char *resolution(int index) const { astring temp; return value(temp.format("%s%d", OSDOPTION_RESOLUTION, index)); } + const char *view(int index) const { astring temp; return value(temp.format("%s%d", OSDOPTION_VIEW, index)); } + + // full screen options + bool switch_res() const { return bool_value(OSDOPTION_SWITCHRES); } + + // sound options + const char *sound() const { return value(OSDOPTION_SOUND); } + int audio_latency() const { return int_value(OSDOPTION_AUDIO_LATENCY); } private: - static const options_entry s_option_entries[]; + static const options_entry s_option_entries[]; }; // ======================> osd_interface @@ -142,77 +142,77 @@ public: // video overridables virtual void *get_slider_list(); - // command option overrides - virtual bool execute_command(const char *command); + // command option overrides + virtual bool execute_command(const char *command); - osd_font *font_alloc() { return m_font_module->font_alloc(); } + osd_font *font_alloc() { return m_font_module->font_alloc(); } // FIXME: everything below seems to be osd specific and not part of // this INTERFACE but part of the osd IMPLEMENTATION - // getters - running_machine &machine() { assert(m_machine != NULL); return *m_machine; } + // getters + running_machine &machine() { assert(m_machine != NULL); return *m_machine; } - virtual void debugger_update(); + virtual void debugger_update(); - virtual void init_subsystems(); + virtual void init_subsystems(); - virtual bool video_init(); - virtual void video_register(); - virtual bool window_init(); + virtual bool video_init(); + virtual void video_register(); + virtual bool window_init(); - virtual void input_resume(); - virtual bool output_init(); - virtual bool network_init(); - virtual bool midi_init(); + virtual void input_resume(); + virtual bool output_init(); + virtual bool network_init(); + virtual bool midi_init(); - virtual void exit_subsystems(); - virtual void video_exit(); - virtual void window_exit(); - virtual void input_exit(); - virtual void output_exit(); - virtual void network_exit(); - virtual void midi_exit(); + virtual void exit_subsystems(); + virtual void video_exit(); + virtual void window_exit(); + virtual void input_exit(); + virtual void output_exit(); + virtual void network_exit(); + virtual void midi_exit(); - virtual void osd_exit(); + virtual void osd_exit(); - virtual void video_options_add(const char *name, void *type); + virtual void video_options_add(const char *name, void *type); - osd_options &options() { return m_options; } + osd_options &options() { return m_options; } protected: - virtual bool input_init(); - virtual void input_pause(); + virtual bool input_init(); + virtual void input_pause(); private: // internal state running_machine * m_machine; osd_options& m_options; - osd_module_manager m_mod_man; - font_module *m_font_module; + osd_module_manager m_mod_man; + font_module *m_font_module; void update_option(const char * key, dynamic_array<const char *> &values); - // FIXME: should be elsewhere - osd_module *select_module_options(const core_options &opts, const astring &opt_name) - { - astring opt_val = opts.value(opt_name); - if (opt_val == "auto") - opt_val = ""; - else if (!m_mod_man.type_has_name(opt_name, opt_val)) - { - osd_printf_warning("Value %s not supported for option %s - falling back to auto\n", opt_val.cstr(), opt_name.cstr()); - opt_val = ""; - } - return m_mod_man.select_module(opt_name, opt_val); - } - - template<class C> - C select_module_options(const core_options &opts, const astring &opt_name) - { - return dynamic_cast<C>(select_module_options(opts, opt_name)); - } + // FIXME: should be elsewhere + osd_module *select_module_options(const core_options &opts, const astring &opt_name) + { + astring opt_val = opts.value(opt_name); + if (opt_val == "auto") + opt_val = ""; + else if (!m_mod_man.type_has_name(opt_name, opt_val)) + { + osd_printf_warning("Value %s not supported for option %s - falling back to auto\n", opt_val.cstr(), opt_name.cstr()); + opt_val = ""; + } + return m_mod_man.select_module(opt_name, opt_val); + } + + template<class C> + C select_module_options(const core_options &opts, const astring &opt_name) + { + return dynamic_cast<C>(select_module_options(opts, opt_name)); + } protected: sound_module* m_sound; diff --git a/src/osd/modules/midi/none.c b/src/osd/modules/midi/none.c index 2f5658fc973..4319eef5ea8 100644 --- a/src/osd/modules/midi/none.c +++ b/src/osd/modules/midi/none.c @@ -10,12 +10,12 @@ struct osd_midi_device { - int dummy; + int dummy; }; bool osd_midi_init() { - return true; + return true; } void osd_midi_exit() @@ -24,17 +24,17 @@ void osd_midi_exit() void osd_list_midi_devices(void) { - osd_printf_warning("\nMIDI is not supported in this build\n"); + osd_printf_warning("\nMIDI is not supported in this build\n"); } osd_midi_device *osd_open_midi_input(const char *devname) { - return NULL; + return NULL; } osd_midi_device *osd_open_midi_output(const char *devname) { - return NULL; + return NULL; } void osd_close_midi_channel(osd_midi_device *dev) @@ -43,12 +43,12 @@ void osd_close_midi_channel(osd_midi_device *dev) bool osd_poll_midi_channel(osd_midi_device *dev) { - return false; + return false; } int osd_read_midi_channel(osd_midi_device *dev, UINT8 *pOut) { - return 0; + return 0; } void osd_write_midi_channel(osd_midi_device *dev, UINT8 data) diff --git a/src/osd/modules/midi/portmidi.c b/src/osd/modules/midi/portmidi.c index 2e0add931a3..0b93bf690dd 100644 --- a/src/osd/modules/midi/portmidi.c +++ b/src/osd/modules/midi/portmidi.c @@ -16,405 +16,405 @@ static const int RX_EVENT_BUF_SIZE = 512; struct osd_midi_device { - PortMidiStream *pmStream; - PmEvent rx_evBuf[RX_EVENT_BUF_SIZE]; - UINT8 xmit_in[4]; // Pm_Messages mean we can at most have 3 residue bytes - int xmit_cnt; - UINT8 last_status; - bool rx_sysex; + PortMidiStream *pmStream; + PmEvent rx_evBuf[RX_EVENT_BUF_SIZE]; + UINT8 xmit_in[4]; // Pm_Messages mean we can at most have 3 residue bytes + int xmit_cnt; + UINT8 last_status; + bool rx_sysex; }; bool osd_midi_init() { - Pm_Initialize(); - return true; + Pm_Initialize(); + return true; } void osd_midi_exit() { - Pm_Terminate(); + Pm_Terminate(); } void osd_list_midi_devices(void) { - int num_devs = Pm_CountDevices(); - const PmDeviceInfo *pmInfo; - - printf("\n"); - - if (num_devs == 0) - { - printf("No MIDI ports were found\n"); - return; - } - - printf("MIDI input ports:\n"); - for (int i = 0; i < num_devs; i++) - { - pmInfo = Pm_GetDeviceInfo(i); - - if (pmInfo->input) - { - printf("%s %s\n", pmInfo->name, (i == Pm_GetDefaultInputDeviceID()) ? "(default)" : ""); - } - } - - printf("\nMIDI output ports:\n"); - for (int i = 0; i < num_devs; i++) - { - pmInfo = Pm_GetDeviceInfo(i); - - if (pmInfo->output) - { - printf("%s %s\n", pmInfo->name, (i == Pm_GetDefaultOutputDeviceID()) ? "(default)" : ""); - } - } + int num_devs = Pm_CountDevices(); + const PmDeviceInfo *pmInfo; + + printf("\n"); + + if (num_devs == 0) + { + printf("No MIDI ports were found\n"); + return; + } + + printf("MIDI input ports:\n"); + for (int i = 0; i < num_devs; i++) + { + pmInfo = Pm_GetDeviceInfo(i); + + if (pmInfo->input) + { + printf("%s %s\n", pmInfo->name, (i == Pm_GetDefaultInputDeviceID()) ? "(default)" : ""); + } + } + + printf("\nMIDI output ports:\n"); + for (int i = 0; i < num_devs; i++) + { + pmInfo = Pm_GetDeviceInfo(i); + + if (pmInfo->output) + { + printf("%s %s\n", pmInfo->name, (i == Pm_GetDefaultOutputDeviceID()) ? "(default)" : ""); + } + } } osd_midi_device *osd_open_midi_input(const char *devname) { - int num_devs = Pm_CountDevices(); - int found_dev = -1; - const PmDeviceInfo *pmInfo; - PortMidiStream *stm; - osd_midi_device *ret; - - if (!strcmp("default", devname)) - { - found_dev = Pm_GetDefaultInputDeviceID(); - } - else - { - for (int i = 0; i < num_devs; i++) - { - pmInfo = Pm_GetDeviceInfo(i); - - if (pmInfo->input) - { - if (!strcmp(devname, pmInfo->name)) - { - found_dev = i; - break; - } - } - } - } - - if (found_dev >= 0) - { - if (Pm_OpenInput(&stm, found_dev, NULL, RX_EVENT_BUF_SIZE, NULL, NULL) == pmNoError) - { - ret = (osd_midi_device *)osd_malloc(sizeof(osd_midi_device)); - memset(ret, 0, sizeof(osd_midi_device)); - ret->pmStream = stm; - return ret; - } - else - { - printf("Couldn't open PM device\n"); - return NULL; - } - } - else - { - return NULL; - } + int num_devs = Pm_CountDevices(); + int found_dev = -1; + const PmDeviceInfo *pmInfo; + PortMidiStream *stm; + osd_midi_device *ret; + + if (!strcmp("default", devname)) + { + found_dev = Pm_GetDefaultInputDeviceID(); + } + else + { + for (int i = 0; i < num_devs; i++) + { + pmInfo = Pm_GetDeviceInfo(i); + + if (pmInfo->input) + { + if (!strcmp(devname, pmInfo->name)) + { + found_dev = i; + break; + } + } + } + } + + if (found_dev >= 0) + { + if (Pm_OpenInput(&stm, found_dev, NULL, RX_EVENT_BUF_SIZE, NULL, NULL) == pmNoError) + { + ret = (osd_midi_device *)osd_malloc(sizeof(osd_midi_device)); + memset(ret, 0, sizeof(osd_midi_device)); + ret->pmStream = stm; + return ret; + } + else + { + printf("Couldn't open PM device\n"); + return NULL; + } + } + else + { + return NULL; + } } osd_midi_device *osd_open_midi_output(const char *devname) { - int num_devs = Pm_CountDevices(); - int found_dev = -1; - const PmDeviceInfo *pmInfo; - PortMidiStream *stm; - osd_midi_device *ret; - - if (!strcmp("default", devname)) - { - found_dev = Pm_GetDefaultOutputDeviceID(); - } - else - { - for (int i = 0; i < num_devs; i++) - { - pmInfo = Pm_GetDeviceInfo(i); - - if (pmInfo->output) - { - if (!strcmp(devname, pmInfo->name)) - { - found_dev = i; - break; - } - } - } - } - - if (found_dev >= 0) - { - if (Pm_OpenOutput(&stm, found_dev, NULL, 100, NULL, NULL, 0) == pmNoError) - { - ret = (osd_midi_device *)osd_malloc(sizeof(osd_midi_device)); - memset(ret, 0, sizeof(osd_midi_device)); - ret->pmStream = stm; - return ret; - } - else - { - printf("Couldn't open PM device\n"); - return NULL; - } - } - else - { - return NULL; - } - return NULL; + int num_devs = Pm_CountDevices(); + int found_dev = -1; + const PmDeviceInfo *pmInfo; + PortMidiStream *stm; + osd_midi_device *ret; + + if (!strcmp("default", devname)) + { + found_dev = Pm_GetDefaultOutputDeviceID(); + } + else + { + for (int i = 0; i < num_devs; i++) + { + pmInfo = Pm_GetDeviceInfo(i); + + if (pmInfo->output) + { + if (!strcmp(devname, pmInfo->name)) + { + found_dev = i; + break; + } + } + } + } + + if (found_dev >= 0) + { + if (Pm_OpenOutput(&stm, found_dev, NULL, 100, NULL, NULL, 0) == pmNoError) + { + ret = (osd_midi_device *)osd_malloc(sizeof(osd_midi_device)); + memset(ret, 0, sizeof(osd_midi_device)); + ret->pmStream = stm; + return ret; + } + else + { + printf("Couldn't open PM device\n"); + return NULL; + } + } + else + { + return NULL; + } + return NULL; } void osd_close_midi_channel(osd_midi_device *dev) { - Pm_Close(dev->pmStream); - osd_free(dev); + Pm_Close(dev->pmStream); + osd_free(dev); } bool osd_poll_midi_channel(osd_midi_device *dev) { - PmError chk = Pm_Poll(dev->pmStream); + PmError chk = Pm_Poll(dev->pmStream); - return (chk == pmGotData) ? true : false; + return (chk == pmGotData) ? true : false; } int osd_read_midi_channel(osd_midi_device *dev, UINT8 *pOut) { - int msgsRead = Pm_Read(dev->pmStream, dev->rx_evBuf, RX_EVENT_BUF_SIZE); - int bytesOut = 0; - - if (msgsRead <= 0) - { - return 0; - } - - for (int msg = 0; msg < msgsRead; msg++) - { - UINT8 status = Pm_MessageStatus(dev->rx_evBuf[msg].message); - - if (dev->rx_sysex) - { - if (status & 0x80) // sys real-time imposing on us? - { - if ((status == 0xf2) || (status == 0xf3)) - { - *pOut++ = status; - *pOut++ = Pm_MessageData1(dev->rx_evBuf[msg].message); - *pOut++ = Pm_MessageData2(dev->rx_evBuf[msg].message); - bytesOut += 3; - } - else - { - *pOut++ = status; - bytesOut++; - if (status == MIDI_EOX) - { - dev->rx_sysex = false; - } - } - } - else // shift out the sysex bytes - { - for (int i = 0; i < 4; i++) - { - UINT8 byte = dev->rx_evBuf[msg].message & 0xff; - *pOut++ = byte; - bytesOut++; - if (byte == MIDI_EOX) - { - dev->rx_sysex = false; - break; - } - dev->rx_evBuf[msg].message >>= 8; - } - } - } - else - { - switch ((status>>4) & 0xf) - { - case 0xc: // 2-byte messages - case 0xd: - *pOut++ = status; - *pOut++ = Pm_MessageData1(dev->rx_evBuf[msg].message); - bytesOut += 2; - break; - - case 0xf: // system common - switch (status & 0xf) - { - case 0: // System Exclusive - { - *pOut++ = status; // this should be OK: the shortest legal sysex is F0 tt dd F7, I believe - *pOut++ = (dev->rx_evBuf[msg].message>>8) & 0xff; - *pOut++ = (dev->rx_evBuf[msg].message>>16) & 0xff; - UINT8 last = *pOut++ = (dev->rx_evBuf[msg].message>>24) & 0xff; - bytesOut += 4; - dev->rx_sysex = (last != MIDI_EOX); - break; - } - - case 7: // End of System Exclusive - *pOut++ = status; - bytesOut += 1; - dev->rx_sysex = false; - break; - - case 2: // song pos - case 3: // song select - *pOut++ = status; - *pOut++ = Pm_MessageData1(dev->rx_evBuf[msg].message); - *pOut++ = Pm_MessageData2(dev->rx_evBuf[msg].message); - bytesOut += 3; - break; - - default: // all other defined Fx messages are 1 byte - break; - } - break; - - default: - *pOut++ = status; - *pOut++ = Pm_MessageData1(dev->rx_evBuf[msg].message); - *pOut++ = Pm_MessageData2(dev->rx_evBuf[msg].message); - bytesOut += 3; - break; - } - } - } - - return bytesOut; + int msgsRead = Pm_Read(dev->pmStream, dev->rx_evBuf, RX_EVENT_BUF_SIZE); + int bytesOut = 0; + + if (msgsRead <= 0) + { + return 0; + } + + for (int msg = 0; msg < msgsRead; msg++) + { + UINT8 status = Pm_MessageStatus(dev->rx_evBuf[msg].message); + + if (dev->rx_sysex) + { + if (status & 0x80) // sys real-time imposing on us? + { + if ((status == 0xf2) || (status == 0xf3)) + { + *pOut++ = status; + *pOut++ = Pm_MessageData1(dev->rx_evBuf[msg].message); + *pOut++ = Pm_MessageData2(dev->rx_evBuf[msg].message); + bytesOut += 3; + } + else + { + *pOut++ = status; + bytesOut++; + if (status == MIDI_EOX) + { + dev->rx_sysex = false; + } + } + } + else // shift out the sysex bytes + { + for (int i = 0; i < 4; i++) + { + UINT8 byte = dev->rx_evBuf[msg].message & 0xff; + *pOut++ = byte; + bytesOut++; + if (byte == MIDI_EOX) + { + dev->rx_sysex = false; + break; + } + dev->rx_evBuf[msg].message >>= 8; + } + } + } + else + { + switch ((status>>4) & 0xf) + { + case 0xc: // 2-byte messages + case 0xd: + *pOut++ = status; + *pOut++ = Pm_MessageData1(dev->rx_evBuf[msg].message); + bytesOut += 2; + break; + + case 0xf: // system common + switch (status & 0xf) + { + case 0: // System Exclusive + { + *pOut++ = status; // this should be OK: the shortest legal sysex is F0 tt dd F7, I believe + *pOut++ = (dev->rx_evBuf[msg].message>>8) & 0xff; + *pOut++ = (dev->rx_evBuf[msg].message>>16) & 0xff; + UINT8 last = *pOut++ = (dev->rx_evBuf[msg].message>>24) & 0xff; + bytesOut += 4; + dev->rx_sysex = (last != MIDI_EOX); + break; + } + + case 7: // End of System Exclusive + *pOut++ = status; + bytesOut += 1; + dev->rx_sysex = false; + break; + + case 2: // song pos + case 3: // song select + *pOut++ = status; + *pOut++ = Pm_MessageData1(dev->rx_evBuf[msg].message); + *pOut++ = Pm_MessageData2(dev->rx_evBuf[msg].message); + bytesOut += 3; + break; + + default: // all other defined Fx messages are 1 byte + break; + } + break; + + default: + *pOut++ = status; + *pOut++ = Pm_MessageData1(dev->rx_evBuf[msg].message); + *pOut++ = Pm_MessageData2(dev->rx_evBuf[msg].message); + bytesOut += 3; + break; + } + } + } + + return bytesOut; } void osd_write_midi_channel(osd_midi_device *dev, UINT8 data) { - int bytes_needed = 0; - PmEvent ev; - ev.timestamp = 0; // use the current time + int bytes_needed = 0; + PmEvent ev; + ev.timestamp = 0; // use the current time // printf("write: %02x (%d)\n", data, dev->xmit_cnt); - // reject data bytes when no valid status exists - if ((dev->last_status == 0) && !(data & 0x80)) - { - dev->xmit_cnt = 0; - return; - } - - if (dev->xmit_cnt >= 4) - { - printf("MIDI out: packet assembly overflow, contact MAMEdev!\n"); - return; - } - - // handle sysex - if (dev->last_status == MIDI_SYSEX) - { + // reject data bytes when no valid status exists + if ((dev->last_status == 0) && !(data & 0x80)) + { + dev->xmit_cnt = 0; + return; + } + + if (dev->xmit_cnt >= 4) + { + printf("MIDI out: packet assembly overflow, contact MAMEdev!\n"); + return; + } + + // handle sysex + if (dev->last_status == MIDI_SYSEX) + { // printf("sysex: %02x (%d)\n", data, dev->xmit_cnt); - // if we get a status that isn't sysex, assume it's system common - if ((data & 0x80) && (data != MIDI_EOX)) - { + // if we get a status that isn't sysex, assume it's system common + if ((data & 0x80) && (data != MIDI_EOX)) + { // printf("common during sysex!\n"); - ev.message = Pm_Message(data, 0, 0); - Pm_Write(dev->pmStream, &ev, 1); - return; - } + ev.message = Pm_Message(data, 0, 0); + Pm_Write(dev->pmStream, &ev, 1); + return; + } - dev->xmit_in[dev->xmit_cnt++] = data; + dev->xmit_in[dev->xmit_cnt++] = data; - // if EOX or 4 bytes filled, transmit 4 bytes - if ((dev->xmit_cnt == 4) || (data == MIDI_EOX)) - { - ev.message = dev->xmit_in[0] | (dev->xmit_in[1]<<8) | (dev->xmit_in[2]<<16) | (dev->xmit_in[3]<<24); - Pm_Write(dev->pmStream, &ev, 1); - dev->xmit_in[0] = dev->xmit_in[1] = dev->xmit_in[2] = dev->xmit_in[3] = 0; - dev->xmit_cnt = 0; + // if EOX or 4 bytes filled, transmit 4 bytes + if ((dev->xmit_cnt == 4) || (data == MIDI_EOX)) + { + ev.message = dev->xmit_in[0] | (dev->xmit_in[1]<<8) | (dev->xmit_in[2]<<16) | (dev->xmit_in[3]<<24); + Pm_Write(dev->pmStream, &ev, 1); + dev->xmit_in[0] = dev->xmit_in[1] = dev->xmit_in[2] = dev->xmit_in[3] = 0; + dev->xmit_cnt = 0; // printf("SysEx packet: %08x\n", ev.message); - // if this is EOX, kill the running status - if (data == MIDI_EOX) - { - dev->last_status = 0; - } - } - - return; - } - - // handle running status. don't allow system real-time messages to be considered as running status. - if ((dev->xmit_cnt == 0) && (data & 0x80) && (data < 0xf8)) - { - dev->last_status = data; - } - - if ((dev->xmit_cnt == 0) && !(data & 0x80)) - { - dev->xmit_in[dev->xmit_cnt++] = dev->last_status; - dev->xmit_in[dev->xmit_cnt++] = data; + // if this is EOX, kill the running status + if (data == MIDI_EOX) + { + dev->last_status = 0; + } + } + + return; + } + + // handle running status. don't allow system real-time messages to be considered as running status. + if ((dev->xmit_cnt == 0) && (data & 0x80) && (data < 0xf8)) + { + dev->last_status = data; + } + + if ((dev->xmit_cnt == 0) && !(data & 0x80)) + { + dev->xmit_in[dev->xmit_cnt++] = dev->last_status; + dev->xmit_in[dev->xmit_cnt++] = data; // printf("\trunning status: [%d] = %02x, [%d] = %02x, last_status = %02x\n", dev->xmit_cnt-2, dev->last_status, dev->xmit_cnt-1, data, dev->last_status); - } - else - { - dev->xmit_in[dev->xmit_cnt++] = data; + } + else + { + dev->xmit_in[dev->xmit_cnt++] = data; // printf("\tNRS: [%d] = %02x\n", dev->xmit_cnt-1, data); - } + } - if ((dev->xmit_cnt == 1) && (dev->xmit_in[0] == MIDI_SYSEX)) - { + if ((dev->xmit_cnt == 1) && (dev->xmit_in[0] == MIDI_SYSEX)) + { // printf("Start SysEx!\n"); - dev->last_status = MIDI_SYSEX; - return; - } + dev->last_status = MIDI_SYSEX; + return; + } - // are we there yet? + // are we there yet? // printf("status check: %02x\n", dev->xmit_in[0]); - switch ((dev->xmit_in[0]>>4) & 0xf) - { - case 0xc: // 2-byte messages - case 0xd: - bytes_needed = 2; - break; - - case 0xf: // system common - switch (dev->xmit_in[0] & 0xf) - { - case 0: // System Exclusive is handled above - break; - - case 7: // End of System Exclusive - bytes_needed = 1; - break; - - case 2: // song pos - case 3: // song select - bytes_needed = 3; - break; - - default: // all other defined Fx messages are 1 byte - bytes_needed = 1; - break; - } - break; - - default: - bytes_needed = 3; - break; - } - - if (dev->xmit_cnt == bytes_needed) - { - ev.message = Pm_Message(dev->xmit_in[0], dev->xmit_in[1], dev->xmit_in[2]); - Pm_Write(dev->pmStream, &ev, 1); - dev->xmit_cnt = 0; - } + switch ((dev->xmit_in[0]>>4) & 0xf) + { + case 0xc: // 2-byte messages + case 0xd: + bytes_needed = 2; + break; + + case 0xf: // system common + switch (dev->xmit_in[0] & 0xf) + { + case 0: // System Exclusive is handled above + break; + + case 7: // End of System Exclusive + bytes_needed = 1; + break; + + case 2: // song pos + case 3: // song select + bytes_needed = 3; + break; + + default: // all other defined Fx messages are 1 byte + bytes_needed = 1; + break; + } + break; + + default: + bytes_needed = 3; + break; + } + + if (dev->xmit_cnt == bytes_needed) + { + ev.message = Pm_Message(dev->xmit_in[0], dev->xmit_in[1], dev->xmit_in[2]); + Pm_Write(dev->pmStream, &ev, 1); + dev->xmit_cnt = 0; + } } diff --git a/src/osd/modules/osdmodule.c b/src/osd/modules/osdmodule.c index e907d89249e..06c36b0e3d4 100644 --- a/src/osd/modules/osdmodule.c +++ b/src/osd/modules/osdmodule.c @@ -7,110 +7,108 @@ osd_module_manager::osd_module_manager() { - for (int i=0; i<MAX_MODULES; i++) - { - m_modules[i] = NULL; - m_selected[i] = NULL; - } + for (int i=0; i<MAX_MODULES; i++) + { + m_modules[i] = NULL; + m_selected[i] = NULL; + } } osd_module_manager::~osd_module_manager() { - for (int i = 0; m_modules[i] != NULL; i++) - { - m_modules[i]->~osd_module(); - osd_free(m_modules[i]); - } + for (int i = 0; m_modules[i] != NULL; i++) + { + m_modules[i]->~osd_module(); + osd_free(m_modules[i]); + } } void osd_module_manager::register_module(const module_type &mod_type) { - osd_module *module = mod_type(); - if (module->probe()) - { - osd_printf_verbose("===> registered module %s %s\n", module->name(), module->type()); + osd_module *module = mod_type(); + if (module->probe()) + { + osd_printf_verbose("===> registered module %s %s\n", module->name(), module->type()); - int i; - for (i = 0; m_modules[i] != NULL; i++) - ; - m_modules[i] = module; - } - else - { - osd_printf_verbose("===> not supported %s %s\n", module->name(), module->type()); - module->~osd_module(); - osd_free(module); - } + int i; + for (i = 0; m_modules[i] != NULL; i++) + ; + m_modules[i] = module; + } + else + { + osd_printf_verbose("===> not supported %s %s\n", module->name(), module->type()); + module->~osd_module(); + osd_free(module); + } } bool osd_module_manager::type_has_name(const char *type, const char *name) { - return (get_module_index(type, name) >= 0); + return (get_module_index(type, name) >= 0); } osd_module *osd_module_manager::get_module_generic(const char *type, const char *name) { - int i = get_module_index(type, name); - if (i>=0) - return m_modules[i]; - else - return NULL; + int i = get_module_index(type, name); + if (i>=0) + return m_modules[i]; + else + return NULL; } osd_module *osd_module_manager::select_module(const char *type, const char *name) { - osd_module *m = get_module_generic(type, name); + osd_module *m = get_module_generic(type, name); - // FIXME: check if already exists! - int i; - for (i = 0; m_selected[i] != NULL; i++) - ; - m_selected[i] = m; - return m; + // FIXME: check if already exists! + int i; + for (i = 0; m_selected[i] != NULL; i++) + ; + m_selected[i] = m; + return m; } void osd_module_manager::init() { - for (int i = 0; m_selected[i] != NULL; i++) - { - m_selected[i]->init(); - } + for (int i = 0; m_selected[i] != NULL; i++) + { + m_selected[i]->init(); + } } void osd_module_manager::exit() { - // Find count - int cnt; - for (cnt = 0; m_selected[cnt] != NULL; cnt++) - ; - for (int i = cnt - 1; i >= 0; i--) - { - m_selected[i]->exit(); - m_selected[i] = NULL; - } + // Find count + int cnt; + for (cnt = 0; m_selected[cnt] != NULL; cnt++) + ; + for (int i = cnt - 1; i >= 0; i--) + { + m_selected[i]->exit(); + m_selected[i] = NULL; + } } int osd_module_manager::get_module_index(const char *type, const char *name) { - for (int i = 0; m_modules[i] != NULL; i++) - { - if (strcmp(m_modules[i]->type(), type) == 0 && ((name[0] == 0) || (strcmp(name, m_modules[i]->name())==0))) - return i; - } - return -1; + for (int i = 0; m_modules[i] != NULL; i++) + { + if (strcmp(m_modules[i]->type(), type) == 0 && ((name[0] == 0) || (strcmp(name, m_modules[i]->name())==0))) + return i; + } + return -1; } void osd_module_manager::get_module_names(const char *type, const int max, int *num, const char *names[]) { - *num = 0; - for (int i = 0; m_modules[i] != NULL; i++) - { - if ((strcmp(m_modules[i]->type(), type) == 0) && (*num < max)) - { - names[*num] = m_modules[i]->name(); - *num = *num + 1; - } + *num = 0; + for (int i = 0; m_modules[i] != NULL; i++) + { + if ((strcmp(m_modules[i]->type(), type) == 0) && (*num < max)) + { + names[*num] = m_modules[i]->name(); + *num = *num + 1; + } - } + } } - - diff --git a/src/osd/modules/osdmodule.h b/src/osd/modules/osdmodule.h index 9d24f56a0ec..15748d39ca9 100644 --- a/src/osd/modules/osdmodule.h +++ b/src/osd/modules/osdmodule.h @@ -26,22 +26,22 @@ class osd_module { public: - osd_module(const char *type, const char *name) - : m_name(name), m_type(type) - {} - virtual ~osd_module() { } + osd_module(const char *type, const char *name) + : m_name(name), m_type(type) + {} + virtual ~osd_module() { } - const char * name() const { return m_name; } - const char * type() const { return m_type; } + const char * name() const { return m_name; } + const char * type() const { return m_type; } - virtual bool probe() const { return true; } + virtual bool probe() const { return true; } - virtual int init() { return 0; } - virtual void exit() { } + virtual int init() { return 0; } + virtual void exit() { } private: - astring m_name; - astring m_type; + astring m_name; + astring m_type; }; // a module_type is simply a pointer to its alloc function @@ -51,56 +51,56 @@ typedef osd_module *(*module_type)(); template<class _ModuleClass> osd_module *module_creator() { - void *p = osd_malloc(sizeof(_ModuleClass)); - return new(p) _ModuleClass; + void *p = osd_malloc(sizeof(_ModuleClass)); + return new(p) _ModuleClass; } class osd_module_manager { public: - static const int MAX_MODULES = 32; + static const int MAX_MODULES = 32; - osd_module_manager(); - ~osd_module_manager(); + osd_module_manager(); + ~osd_module_manager(); - void register_module(const module_type &mod_type); - bool type_has_name(const char *type, const char *name); + void register_module(const module_type &mod_type); + bool type_has_name(const char *type, const char *name); - osd_module *get_module_generic(const char *type, const char *name); + osd_module *get_module_generic(const char *type, const char *name); - template<class C> - C select_module(const char *type, const char *name = "") - { - return dynamic_cast<C>(select_module(type, name)); - } + template<class C> + C select_module(const char *type, const char *name = "") + { + return dynamic_cast<C>(select_module(type, name)); + } - osd_module *select_module(const char *type, const char *name = ""); + osd_module *select_module(const char *type, const char *name = ""); - void get_module_names(const char *type, const int max, int *num, const char *names[]); + void get_module_names(const char *type, const int max, int *num, const char *names[]); - void init(); + void init(); - void exit(); + void exit(); private: - int get_module_index(const char *type, const char *name); + int get_module_index(const char *type, const char *name); - osd_module *m_modules[MAX_MODULES]; - osd_module *m_selected[MAX_MODULES]; + osd_module *m_modules[MAX_MODULES]; + osd_module *m_selected[MAX_MODULES]; }; #define MODULE_DEFINITION(_id, _class) \ - extern const module_type _id ; \ - const module_type _id = &module_creator< _class >; + extern const module_type _id ; \ + const module_type _id = &module_creator< _class >; #define MODULE_NOT_SUPPORTED(_mod, _type, _name) \ - class _mod : public osd_module { \ - public: \ - _mod () \ - : osd_module(_type, _name) {} \ - bool probe() const { return false; } \ - }; + class _mod : public osd_module { \ + public: \ + _mod () \ + : osd_module(_type, _name) {} \ + bool probe() const { return false; } \ + }; #endif /* __OSDMODULE_H__ */ diff --git a/src/osd/modules/sound/direct_sound.c b/src/osd/modules/sound/direct_sound.c index 95e033b3351..bd30d730ee7 100644 --- a/src/osd/modules/sound/direct_sound.c +++ b/src/osd/modules/sound/direct_sound.c @@ -51,26 +51,26 @@ class sound_direct_sound : public osd_module, public sound_module { public: - sound_direct_sound() - : osd_module(OSD_SOUND_PROVIDER, "dsound"), sound_module() - { - } - virtual ~sound_direct_sound() { } + sound_direct_sound() + : osd_module(OSD_SOUND_PROVIDER, "dsound"), sound_module() + { + } + virtual ~sound_direct_sound() { } - virtual int init(); - virtual void exit(); + virtual int init(); + virtual void exit(); - // sound_module + // sound_module - virtual void update_audio_stream(bool is_throttled, const INT16 *buffer, int samples_this_frame); - virtual void set_mastervolume(int attenuation); + virtual void update_audio_stream(bool is_throttled, const INT16 *buffer, int samples_this_frame); + virtual void set_mastervolume(int attenuation); private: - HRESULT dsound_init(); - void dsound_kill(); - HRESULT dsound_create_buffers(); - void dsound_destroy_buffers(); - void copy_sample_data(const INT16 *data, int bytes_to_copy); + HRESULT dsound_init(); + void dsound_kill(); + HRESULT dsound_create_buffers(); + void dsound_destroy_buffers(); + void copy_sample_data(const INT16 *data, int bytes_to_copy); }; @@ -448,7 +448,7 @@ void sound_direct_sound::dsound_destroy_buffers(void) } #else /* SDLMAME_UNIX */ - MODULE_NOT_SUPPORTED(sound_direct_sound, OSD_SOUND_PROVIDER, "dsound") + MODULE_NOT_SUPPORTED(sound_direct_sound, OSD_SOUND_PROVIDER, "dsound") #endif MODULE_DEFINITION(SOUND_DSOUND, sound_direct_sound) diff --git a/src/osd/modules/sound/js_sound.c b/src/osd/modules/sound/js_sound.c index f3e11785633..93d76a22c4f 100644 --- a/src/osd/modules/sound/js_sound.c +++ b/src/osd/modules/sound/js_sound.c @@ -19,36 +19,36 @@ class sound_js : public osd_module, public sound_module { public: - sound_js() - : osd_module(OSD_SOUND_PROVIDER, "js"), sound_module() - { - } - virtual ~sound_js() { } - - virtual int init(); - virtual void exit(); - - // sound_module - - virtual void update_audio_stream(bool is_throttled, const INT16 *buffer, int samples_this_frame) - { - EM_ASM_ARGS({ - // Forward audio stream update on to JS backend implementation. - jsmess_update_audio_stream($1, $2); - }, (unsigned int)buffer, samples_this_frame); - } - virtual void set_mastervolume(int attenuation) - { - EM_ASM_ARGS({ - // Forward volume update on to JS backend implementation. - jsmess_set_mastervolume($0); - }, attenuation); - } + sound_js() + : osd_module(OSD_SOUND_PROVIDER, "js"), sound_module() + { + } + virtual ~sound_js() { } + + virtual int init(); + virtual void exit(); + + // sound_module + + virtual void update_audio_stream(bool is_throttled, const INT16 *buffer, int samples_this_frame) + { + EM_ASM_ARGS({ + // Forward audio stream update on to JS backend implementation. + jsmess_update_audio_stream($1, $2); + }, (unsigned int)buffer, samples_this_frame); + } + virtual void set_mastervolume(int attenuation) + { + EM_ASM_ARGS({ + // Forward volume update on to JS backend implementation. + jsmess_set_mastervolume($0); + }, attenuation); + } }; #else /* SDLMAME_UNIX */ - MODULE_NOT_SUPPORTED(sound_js, OSD_SOUND_PROVIDER, "js") + MODULE_NOT_SUPPORTED(sound_js, OSD_SOUND_PROVIDER, "js") #endif MODULE_DEFINITION(SOUND_JS, sound_js) diff --git a/src/osd/modules/sound/none.c b/src/osd/modules/sound/none.c index e0173d39d59..501b064afab 100644 --- a/src/osd/modules/sound/none.c +++ b/src/osd/modules/sound/none.c @@ -14,19 +14,19 @@ class sound_none : public osd_module, public sound_module { public: - sound_none() - : osd_module(OSD_SOUND_PROVIDER, "none"), sound_module() - { - } - virtual ~sound_none() { } + sound_none() + : osd_module(OSD_SOUND_PROVIDER, "none"), sound_module() + { + } + virtual ~sound_none() { } - virtual int init() { return 0; } - virtual void exit() { } + virtual int init() { return 0; } + virtual void exit() { } - // sound_module + // sound_module - virtual void update_audio_stream(bool is_throttled, const INT16 *buffer, int samples_this_frame) { } - virtual void set_mastervolume(int attenuation) { } + virtual void update_audio_stream(bool is_throttled, const INT16 *buffer, int samples_this_frame) { } + virtual void set_mastervolume(int attenuation) { } }; diff --git a/src/osd/modules/sound/sdl_sound.c b/src/osd/modules/sound/sdl_sound.c index bb46e9f6b91..1c80ab85082 100644 --- a/src/osd/modules/sound/sdl_sound.c +++ b/src/osd/modules/sound/sdl_sound.c @@ -43,53 +43,53 @@ class sound_sdl : public osd_module, public sound_module { public: - friend void sdl_callback(void *userdata, Uint8 *stream, int len); + friend void sdl_callback(void *userdata, Uint8 *stream, int len); - // number of samples per SDL callback - static const int SDL_XFER_SAMPLES = 512; + // number of samples per SDL callback + static const int SDL_XFER_SAMPLES = 512; - sound_sdl() - : osd_module(OSD_SOUND_PROVIDER, "sdl"), sound_module(), - stream_in_initialized(0), - stream_loop(0), - attenuation(0) - { - sdl_xfer_samples = SDL_XFER_SAMPLES; - } - virtual ~sound_sdl() { } + sound_sdl() + : osd_module(OSD_SOUND_PROVIDER, "sdl"), sound_module(), + stream_in_initialized(0), + stream_loop(0), + attenuation(0) + { + sdl_xfer_samples = SDL_XFER_SAMPLES; + } + virtual ~sound_sdl() { } - virtual int init(); - virtual void exit(); + virtual int init(); + virtual void exit(); - // sound_module + // sound_module - virtual void update_audio_stream(bool is_throttled, const INT16 *buffer, int samples_this_frame); - virtual void set_mastervolume(int attenuation); + virtual void update_audio_stream(bool is_throttled, const INT16 *buffer, int samples_this_frame); + virtual void set_mastervolume(int attenuation); private: - int lock_buffer(bool is_throttled, long offset, long size, void **buffer1, long *length1, void **buffer2, long *length2); - void unlock_buffer(void); - void att_memcpy(void *dest, const INT16 *data, int bytes_to_copy); - void copy_sample_data(bool is_throttled, const INT16 *data, int bytes_to_copy); - int sdl_create_buffers(void); - void sdl_destroy_buffers(void); + int lock_buffer(bool is_throttled, long offset, long size, void **buffer1, long *length1, void **buffer2, long *length2); + void unlock_buffer(void); + void att_memcpy(void *dest, const INT16 *data, int bytes_to_copy); + void copy_sample_data(bool is_throttled, const INT16 *data, int bytes_to_copy); + int sdl_create_buffers(void); + void sdl_destroy_buffers(void); - int sdl_xfer_samples; - int stream_in_initialized; - int stream_loop; - int attenuation; + int sdl_xfer_samples; + int stream_in_initialized; + int stream_loop; + int attenuation; - int buf_locked; + int buf_locked; - INT8 *stream_buffer; - volatile INT32 stream_playpos; + INT8 *stream_buffer; + volatile INT32 stream_playpos; - UINT32 stream_buffer_size; - UINT32 stream_buffer_in; + UINT32 stream_buffer_size; + UINT32 stream_buffer_in; - // buffer over/underflow counts - int buffer_underflows; - int buffer_overflows; + // buffer over/underflow counts + int buffer_underflows; + int buffer_overflows; }; @@ -354,7 +354,7 @@ void sound_sdl::set_mastervolume(int _attenuation) //============================================================ static void sdl_callback(void *userdata, Uint8 *stream, int len) { - sound_sdl *thiz = (sound_sdl *) userdata; + sound_sdl *thiz = (sound_sdl *) userdata; int len1, len2, sb_in; sb_in = thiz->stream_buffer_in; @@ -379,20 +379,20 @@ static void sdl_callback(void *userdata, Uint8 *stream, int len) len2 = 0; } - memcpy(stream, thiz->stream_buffer + thiz->stream_playpos, len1); - memset(thiz->stream_buffer + thiz->stream_playpos, 0, len1); // no longer needed - if (len2) - { - memcpy(stream+len1, thiz->stream_buffer, len2); - memset(thiz->stream_buffer, 0, len2); // no longer needed - } + memcpy(stream, thiz->stream_buffer + thiz->stream_playpos, len1); + memset(thiz->stream_buffer + thiz->stream_playpos, 0, len1); // no longer needed + if (len2) + { + memcpy(stream+len1, thiz->stream_buffer, len2); + memset(thiz->stream_buffer, 0, len2); // no longer needed + } // move the play cursor - thiz->stream_playpos += len1 + len2; + thiz->stream_playpos += len1 + len2; if (thiz->stream_playpos >= thiz->stream_buffer_size) { - thiz->stream_playpos -= thiz->stream_buffer_size; + thiz->stream_playpos -= thiz->stream_buffer_size; thiz->stream_loop = 0; if (LOG_SOUND) @@ -416,81 +416,81 @@ int sound_sdl::init() SDL_AudioSpec aspec, obtained; char audio_driver[16] = ""; - if (LOG_SOUND) - sound_log = fopen(SDLMAME_SOUND_LOG, "w"); - - // skip if sound disabled - if (sample_rate() != 0) - { - if (SDL_InitSubSystem(SDL_INIT_AUDIO)) { - osd_printf_error("Could not initialize SDL %s\n", SDL_GetError()); - return -1; - } - - osd_printf_verbose("Audio: Start initialization\n"); - #if (SDLMAME_SDL2) - strncpy(audio_driver, SDL_GetCurrentAudioDriver(), sizeof(audio_driver)); - #else - SDL_AudioDriverName(audio_driver, sizeof(audio_driver)); - #endif - osd_printf_verbose("Audio: Driver is %s\n", audio_driver); - - sdl_xfer_samples = SDL_XFER_SAMPLES; - stream_in_initialized = 0; - stream_loop = 0; - - // set up the audio specs - aspec.freq = sample_rate(); - aspec.format = AUDIO_S16SYS; // keep endian independent - aspec.channels = n_channels; - aspec.samples = sdl_xfer_samples; - aspec.callback = sdl_callback; - aspec.userdata = this; - - if (SDL_OpenAudio(&aspec, &obtained) < 0) - goto cant_start_audio; - - osd_printf_verbose("Audio: frequency: %d, channels: %d, samples: %d\n", - obtained.freq, obtained.channels, obtained.samples); - - sdl_xfer_samples = obtained.samples; - - audio_latency = m_audio_latency; - - // pin audio latency - if (audio_latency > MAX_AUDIO_LATENCY) - { - audio_latency = MAX_AUDIO_LATENCY; - } - else if (audio_latency < 1) - { - audio_latency = 1; - } - - // compute the buffer sizes - stream_buffer_size = (sample_rate() * 2 * sizeof(INT16) * (2 + audio_latency)) / 30; - stream_buffer_size = (stream_buffer_size / 1024) * 1024; - if (stream_buffer_size < 1024) - stream_buffer_size = 1024; - - // create the buffers - if (sdl_create_buffers()) - goto cant_create_buffers; - - // set the startup volume - set_mastervolume(attenuation); - osd_printf_verbose("Audio: End initialization\n"); - return 0; - - // error handling - cant_create_buffers: - cant_start_audio: - osd_printf_verbose("Audio: Initialization failed. SDL error: %s\n", SDL_GetError()); - - return -1; - } - - return 0; + if (LOG_SOUND) + sound_log = fopen(SDLMAME_SOUND_LOG, "w"); + + // skip if sound disabled + if (sample_rate() != 0) + { + if (SDL_InitSubSystem(SDL_INIT_AUDIO)) { + osd_printf_error("Could not initialize SDL %s\n", SDL_GetError()); + return -1; + } + + osd_printf_verbose("Audio: Start initialization\n"); + #if (SDLMAME_SDL2) + strncpy(audio_driver, SDL_GetCurrentAudioDriver(), sizeof(audio_driver)); + #else + SDL_AudioDriverName(audio_driver, sizeof(audio_driver)); + #endif + osd_printf_verbose("Audio: Driver is %s\n", audio_driver); + + sdl_xfer_samples = SDL_XFER_SAMPLES; + stream_in_initialized = 0; + stream_loop = 0; + + // set up the audio specs + aspec.freq = sample_rate(); + aspec.format = AUDIO_S16SYS; // keep endian independent + aspec.channels = n_channels; + aspec.samples = sdl_xfer_samples; + aspec.callback = sdl_callback; + aspec.userdata = this; + + if (SDL_OpenAudio(&aspec, &obtained) < 0) + goto cant_start_audio; + + osd_printf_verbose("Audio: frequency: %d, channels: %d, samples: %d\n", + obtained.freq, obtained.channels, obtained.samples); + + sdl_xfer_samples = obtained.samples; + + audio_latency = m_audio_latency; + + // pin audio latency + if (audio_latency > MAX_AUDIO_LATENCY) + { + audio_latency = MAX_AUDIO_LATENCY; + } + else if (audio_latency < 1) + { + audio_latency = 1; + } + + // compute the buffer sizes + stream_buffer_size = (sample_rate() * 2 * sizeof(INT16) * (2 + audio_latency)) / 30; + stream_buffer_size = (stream_buffer_size / 1024) * 1024; + if (stream_buffer_size < 1024) + stream_buffer_size = 1024; + + // create the buffers + if (sdl_create_buffers()) + goto cant_create_buffers; + + // set the startup volume + set_mastervolume(attenuation); + osd_printf_verbose("Audio: End initialization\n"); + return 0; + + // error handling + cant_create_buffers: + cant_start_audio: + osd_printf_verbose("Audio: Initialization failed. SDL error: %s\n", SDL_GetError()); + + return -1; + } + + return 0; } @@ -501,27 +501,27 @@ int sound_sdl::init() void sound_sdl::exit() { - // if nothing to do, don't do it - if (sample_rate() == 0) - return; + // if nothing to do, don't do it + if (sample_rate() == 0) + return; - osd_printf_verbose("sdl_kill: closing audio\n"); + osd_printf_verbose("sdl_kill: closing audio\n"); SDL_CloseAudio(); SDL_QuitSubSystem(SDL_INIT_AUDIO); - // kill the buffers - sdl_destroy_buffers(); + // kill the buffers + sdl_destroy_buffers(); - // print out over/underflow stats - if (buffer_overflows || buffer_underflows) - osd_printf_verbose("Sound buffer: overflows=%d underflows=%d\n", buffer_overflows, buffer_underflows); + // print out over/underflow stats + if (buffer_overflows || buffer_underflows) + osd_printf_verbose("Sound buffer: overflows=%d underflows=%d\n", buffer_overflows, buffer_underflows); - if (LOG_SOUND) - { - fprintf(sound_log, "Sound buffer: overflows=%d underflows=%d\n", buffer_overflows, buffer_underflows); - fclose(sound_log); - } + if (LOG_SOUND) + { + fprintf(sound_log, "Sound buffer: overflows=%d underflows=%d\n", buffer_overflows, buffer_underflows); + fclose(sound_log); + } } @@ -555,7 +555,7 @@ void sound_sdl::sdl_destroy_buffers(void) #else /* SDLMAME_UNIX */ - MODULE_NOT_SUPPORTED(sound_sdl, OSD_SOUND_PROVIDER, "sdl") + MODULE_NOT_SUPPORTED(sound_sdl, OSD_SOUND_PROVIDER, "sdl") #endif MODULE_DEFINITION(SOUND_SDL, sound_sdl) diff --git a/src/osd/modules/sound/sound_module.h b/src/osd/modules/sound/sound_module.h index d339af55973..087ace0a714 100644 --- a/src/osd/modules/sound/sound_module.h +++ b/src/osd/modules/sound/sound_module.h @@ -18,17 +18,17 @@ class sound_module { public: - sound_module() : m_sample_rate(0), m_audio_latency(1) { } + sound_module() : m_sample_rate(0), m_audio_latency(1) { } - virtual ~sound_module() { } + virtual ~sound_module() { } - virtual void update_audio_stream(bool is_throttled, const INT16 *buffer, int samples_this_frame) = 0; - virtual void set_mastervolume(int attenuation) = 0; + virtual void update_audio_stream(bool is_throttled, const INT16 *buffer, int samples_this_frame) = 0; + virtual void set_mastervolume(int attenuation) = 0; - int sample_rate() { return m_sample_rate; } + int sample_rate() { return m_sample_rate; } - int m_sample_rate; - int m_audio_latency; + int m_sample_rate; + int m_audio_latency; }; #endif /* FONT_MODULE_H_ */ diff --git a/src/osd/modules/sync/sync_mini.c b/src/osd/modules/sync/sync_mini.c index e710cc7f214..a09303aed80 100644 --- a/src/osd/modules/sync/sync_mini.c +++ b/src/osd/modules/sync/sync_mini.c @@ -160,4 +160,3 @@ int osd_thread_cpu_affinity(osd_thread *thread, UINT32 mask) void osd_thread_wait_free(osd_thread *thread) { } - diff --git a/src/osd/modules/sync/sync_ntc.c b/src/osd/modules/sync/sync_ntc.c index ecd5cd51eaf..9da576b5149 100644 --- a/src/osd/modules/sync/sync_ntc.c +++ b/src/osd/modules/sync/sync_ntc.c @@ -411,7 +411,7 @@ int osd_event_wait(osd_event *event, osd_ticks_t timeout) { if (timeout == OSD_EVENT_WAIT_INFINITE) timeout = osd_ticks_per_second() * (osd_ticks_t)10000; - + pthread_mutex_lock(&event->mutex); if (!timeout) { @@ -531,4 +531,3 @@ void osd_thread_wait_free(osd_thread *thread) pthread_join(thread->thread, NULL); free(thread); } - diff --git a/src/osd/modules/sync/sync_os2.c b/src/osd/modules/sync/sync_os2.c index e6df73d083d..9c0612c1288 100644 --- a/src/osd/modules/sync/sync_os2.c +++ b/src/osd/modules/sync/sync_os2.c @@ -388,7 +388,7 @@ int osd_event_wait(osd_event *event, osd_ticks_t timeout) { ULONG rc; ULONG timeout_param; - + if (timeout == OSD_EVENT_WAIT_INFINITE) timeout_param = SEM_INDEFINITE_WAIT; else diff --git a/src/osd/modules/sync/sync_sdl.c b/src/osd/modules/sync/sync_sdl.c index edfc3d105d4..cea1337c7f8 100644 --- a/src/osd/modules/sync/sync_sdl.c +++ b/src/osd/modules/sync/sync_sdl.c @@ -326,9 +326,9 @@ osd_thread *osd_thread_create(osd_thread_callback callback, void *cbparam) thread->callback = callback; thread->param = cbparam; #ifdef SDLMAME_SDL2 - thread->thread = SDL_CreateThread(worker_thread_entry, "Thread", thread); + thread->thread = SDL_CreateThread(worker_thread_entry, "Thread", thread); #else - thread->thread = SDL_CreateThread(worker_thread_entry, thread); + thread->thread = SDL_CreateThread(worker_thread_entry, thread); #endif if ( thread->thread == NULL ) { @@ -366,4 +366,3 @@ void osd_thread_wait_free(osd_thread *thread) SDL_WaitThread(thread->thread, &status); free(thread); } - diff --git a/src/osd/modules/sync/sync_tc.c b/src/osd/modules/sync/sync_tc.c index 6c05599baef..b3f63e7c05b 100644 --- a/src/osd/modules/sync/sync_tc.c +++ b/src/osd/modules/sync/sync_tc.c @@ -246,7 +246,7 @@ int osd_event_wait(osd_event *event, osd_ticks_t timeout) { if (timeout == OSD_EVENT_WAIT_INFINITE) timeout = osd_ticks_per_second() * (osd_ticks_t)10000; - + pthread_mutex_lock(&event->mutex); if (!timeout) { @@ -389,4 +389,3 @@ void osd_thread_wait_free(osd_thread *thread) pthread_join(thread->thread, NULL); free(thread); } - diff --git a/src/osd/modules/sync/sync_windows.c b/src/osd/modules/sync/sync_windows.c index b7d266a52ad..85ee4f35fd7 100644 --- a/src/osd/modules/sync/sync_windows.c +++ b/src/osd/modules/sync/sync_windows.c @@ -244,7 +244,7 @@ int osd_event_wait(osd_event *event, osd_ticks_t timeout) timeout_param = INFINITE; else timeout_param = timeout * 1000 / osd_ticks_per_second(); - + int ret = WaitForSingleObject((HANDLE) event, timeout_param); return (ret == WAIT_OBJECT_0); } diff --git a/src/osd/modules/sync/work_osd.c b/src/osd/modules/sync/work_osd.c index 6c080b5a2ed..89dec09b122 100644 --- a/src/osd/modules/sync/work_osd.c +++ b/src/osd/modules/sync/work_osd.c @@ -70,22 +70,22 @@ typedef void *PVOID; template<typename _PtrType> static void spin_while(const volatile _PtrType * volatile ptr, const _PtrType val, const osd_ticks_t timeout, const int invert = 0) { - osd_ticks_t stopspin = osd_ticks() + timeout; - - do { - int spin = 10000; - while (--spin) - { - if ((*ptr != val) ^ invert) - return; - } - } while (((*ptr == val) ^ invert) && osd_ticks() < stopspin); + osd_ticks_t stopspin = osd_ticks() + timeout; + + do { + int spin = 10000; + while (--spin) + { + if ((*ptr != val) ^ invert) + return; + } + } while (((*ptr == val) ^ invert) && osd_ticks() < stopspin); } template<typename _PtrType> static void spin_while_not(const volatile _PtrType * volatile ptr, const _PtrType val, const osd_ticks_t timeout) { - spin_while(ptr, val, timeout, 1); + spin_while(ptr, val, timeout, 1); } @@ -553,7 +553,7 @@ int osd_work_item_wait(osd_work_item *item, osd_ticks_t timeout) if (item->event == NULL) { // TODO: do we need to measure the spin time here as well? and how can we do it? - spin_while(&item->done, 0, timeout); + spin_while(&item->done, 0, timeout); } // otherwise, block on the event until done |