Skip to content

Commit

Permalink
added automatic bezel name generation
Browse files Browse the repository at this point in the history
  • Loading branch information
thrust26 committed Aug 22, 2023
1 parent 2134eed commit f6d020d
Show file tree
Hide file tree
Showing 11 changed files with 239 additions and 214 deletions.
15 changes: 10 additions & 5 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2690,12 +2690,16 @@ <h2><b><a name="CommandLine">Using the Command Line</a></b></h2>
</tr>

<tr>
<td><pre>-showbezel &lt;1|0&gt;</pre></td>
<td><pre>-bezel.show &lt;1|0&gt;</pre></td>
<td>Enable or disable bezel display.</td>
</tr>
<tr>
<td><pre>-bezeldir &lt;path&gt;</pre></td>
<td>Specifies from where bezel images are loaded..</td>
<td><pre>-bezel.dir &lt;path&gt;</pre></td>
<td>Specifies from where bezel images are loaded.</td>
</tr>
<tr>
<td><pre>-bezel.windowed &lt;path&gt;</pre></td>
<td>Disable to show bezels only in fullscreen modes.</td>
</tr>

<tr>
Expand Down Expand Up @@ -3769,8 +3773,9 @@ <h2><b><a name="Options">Changing Options</a></b></h2>
<table border="1" cellpadding="4">
<tr><th>Item</th><th>Brief description</th><th>For more information,<br>see <a href="#CommandLine">Command Line</a></th></tr>
<tr><td>Enable bezels</td><td>Enables the bezel display if a ROM name matching bezel image or a
default image (named 'default.png') can be found using the bezel path.</td><td>-showbezel</td></tr>
<tr><td>Bezel path</td><td>Specifies the path from where bezel images are loaded.</td><td>-bezeldir</td></tr>
default image (named 'default.png') can be found using the bezel path.</td><td>-bezel.show</td></tr>
<tr><td>Bezel path</td><td>Specifies the path from where bezel images are loaded.</td><td>-bezel.dir</td></tr>
<tr><td>Show in windowed modes</td><td>Disable to show bezels only in fullscreen modes.</td><td>-bezel.windowed</td></tr>
</table>
</td>
</tr>
Expand Down
204 changes: 102 additions & 102 deletions src/emucore/DefProps.hxx

Large diffs are not rendered by default.

79 changes: 69 additions & 10 deletions src/emucore/FrameBuffer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1272,7 +1272,10 @@ FBInitStatus FrameBuffer::applyVideoMode()

const bool inTIAMode = myOSystem.eventHandler().inTIAMode();
#ifdef IMAGE_SUPPORT
const bool showBezel = inTIAMode && myOSystem.settings().getBool("showbezel") && checkBezel();
const bool showBezel = inTIAMode &&
myOSystem.settings().getBool("bezel.show") &&
(fullScreen() || myOSystem.settings().getBool("bezel.windowed")) &&
checkBezel();
#else
const bool showBezel = false;
#endif
Expand Down Expand Up @@ -1332,29 +1335,85 @@ FBInitStatus FrameBuffer::applyVideoMode()
}

#ifdef IMAGE_SUPPORT
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
const string FrameBuffer::getBezelName(int& index) const
{
if(++index == 1)
return myOSystem.console().properties().get(PropType::Bezel_Name);

// Try to generate bezel name from cart name
const string& cartName = myOSystem.console().properties().get(PropType::Cart_Name);
const size_t pos = cartName.find_first_of("(");
if(index < 10 && pos != std::string::npos && pos > 0)
{
// The following suffixes are from "The Official No-Intro Convention",
// covering all used combinations by "The Bezel Project" (except single ones)
// (Unl) = unlicensed (Homebrews)
const std::array<string, 8> suffixes = {
" (USA)", " (USA) (Proto)", " (USA) (Unl)", " (USA) (Hack)",
" (Europe)", " (Germany)", " (France) (Unl)", " (Australia)"
};
return cartName.substr(0, pos - 1) + suffixes[index - 2];
}

if(index == 10)
{
index = -1;
return "default";
}
return "";
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool FrameBuffer::checkBezel()
{
const string& path = myOSystem.bezelDir().getPath();
const string& bezelName = myOSystem.console().properties().get(PropType::Bezel_Name);
FSNode node(path + bezelName + ".png");
int index = 0;

do
{
const string& name = getBezelName(index);

return node.exists();
if(name != EmptyString)
{
FSNode node(path + name + ".png");
if(node.exists())
return true;
}
} while (index != -1);
return false;
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool FrameBuffer::loadBezel()
{
const string& path = myOSystem.bezelDir().getPath();
const string& bezelName = myOSystem.console().properties().get(PropType::Bezel_Name);
bool isValid = true;
bool isValid = false;
double aspectRatio = 1;

myBezelSurface = allocateSurface(myActiveVidMode.screenS.w, myActiveVidMode.screenS.h);
try
{
const string& path = myOSystem.bezelDir().getPath();
string imageName;
VariantList metaData;
myOSystem.png().loadImage(path + bezelName + ".png", *myBezelSurface, &aspectRatio, metaData);
int index = 0;

do
{
const string& name = getBezelName(index);
if(name != EmptyString)
{
imageName = path + name + ".png";
FSNode node(imageName);
if(node.exists())
{
isValid = true;
break;
}
}
} while (index != -1);
if(isValid)
myOSystem.png().loadImage(imageName, *myBezelSurface, &aspectRatio, metaData);
}
catch(const runtime_error&)
{
Expand All @@ -1370,7 +1429,7 @@ bool FrameBuffer::loadBezel()
const uInt32 bezelH = std::min(
myActiveVidMode.screenS.h,
myActiveVidMode.imageR.h());
cerr << bezelW << " x " << bezelH << endl;
//cerr << bezelW << " x " << bezelH << endl;
myBezelSurface->setDstSize(bezelW, bezelH);
myBezelSurface->setDstPos((myActiveVidMode.screenS.w - bezelW) / 2,
(myActiveVidMode.screenS.h - bezelH) / 2); // center
Expand All @@ -1393,7 +1452,7 @@ float FrameBuffer::maxWindowZoom() const
const int display = displayId(BufferType::Emulator);
float multiplier = 1;

const bool showBezel = myOSystem.settings().getBool("showbezel");
const bool showBezel = myOSystem.settings().getBool("bezel.show");
const double scaleW = showBezel ? (16. / 9.) / (4. / 3.) : 1; // = 1.333

for(;;)
Expand Down
10 changes: 10 additions & 0 deletions src/emucore/FrameBuffer.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,16 @@ class FrameBuffer
FBInitStatus applyVideoMode();

#ifdef IMAGE_SUPPORT
/**
Return bezel names, which are either read from the properties
or generated from the cart name.
@param The index of the returned bezel name
@return The bezel name for the given index
*/
const string FrameBuffer::getBezelName(int& index) const;

/**
Check if a bezel for the current ROM name exists.
Expand Down
2 changes: 1 addition & 1 deletion src/emucore/OSystem.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ const FSNode& OSystem::snapshotLoadDir()
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
const FSNode& OSystem::bezelDir()
{
const string_view bezelDir = mySettings->getString("bezeldir");
const string_view bezelDir = mySettings->getString("bezel.dir");
if(bezelDir == EmptyString)
myBezelDir = userDir();
else
Expand Down
2 changes: 1 addition & 1 deletion src/emucore/Props.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ std::array<string, Properties::NUM_PROPS> Properties::ourDefaultProperties =
"0", // Display.VCenter
"NO", // Display.Phosphor
"0", // Display.PPBlend
"default" // Bezel.Name
"" // Bezel.Name
};

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Expand Down
18 changes: 10 additions & 8 deletions src/emucore/Settings.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ Settings::Settings()
setPermanent("display", 0);
setPermanent("uimessages", "true");
setPermanent("pausedim", "true");
setPermanent("showbezel", "true");
setPermanent("bezel.show", "true");
setPermanent("bezel.windowed", "false");
// TIA specific options
setPermanent("tia.inter", "false");
setPermanent("tia.zoom", "3");
Expand Down Expand Up @@ -161,7 +162,7 @@ Settings::Settings()
setPermanent("romdir", "");
setPermanent("userdir", "");
setPermanent("saveuserdir", "false");
setPermanent("bezeldir", "");
setPermanent("bezel.dir", "");

// ROM browser options
setPermanent("exitlauncher", "false");
Expand Down Expand Up @@ -536,11 +537,12 @@ void Settings::usage()
<< " -detectpal60 <1|0> Enable PAL-60 autodetection\n"
<< " -detectntsc50 <1|0> Enable NTSC-50 autodetection\n"
<< endl
<< " -speed <number> Run emulation at the given speed\n"
<< " -turbo <1|0> Enable 'Turbo' mode for maximum emulation speed\n"
<< " -uimessages <1|0> Show onscreen UI messages for different events\n"
<< " -pausedim <1|0> Enable emulation dimming in pause mode\n"
<< " -showbezel <1|0> Show bezel left and right of emulation\n"
<< " -speed <number> Run emulation at the given speed\n"
<< " -turbo <1|0> Enable 'Turbo' mode for maximum emulation speed\n"
<< " -uimessages <1|0> Show onscreen UI messages for different events\n"
<< " -pausedim <1|0> Enable emulation dimming in pause mode\n"
<< " -bezel.show <1|0> Show bezel left and right of emulation\n"
<< " -bezel.windowed <1|0> Show bezel in windowed modes\n"
<< endl
#ifdef SOUND_SUPPORT
<< " -audio.enabled <1|0> Enable audio\n"
Expand Down Expand Up @@ -658,7 +660,7 @@ void Settings::usage()
<< " -followlauncher <0|1> Default ROM path follows launcher navigation\n"
<< " -userdir <dir> Set the path to save user files to\n"
<< " -saveuserdir <0|1> Update user path when navigating in browser\n"
<< " -bezeldir <dir> Set the path to load bezels from\n"
<< " -bezel.dir <dir> Set the path to load bezels from\n"
<< " -lastrom <name> Last played ROM, automatically selected in\n"
<< " launcher\n"
<< " -romloadcount <number> Number of ROM to load next from multicard\n"
Expand Down
Loading

0 comments on commit f6d020d

Please sign in to comment.