Improved Common::Base hexadecimal handling:

- Fixed warnings generated by clang about 'nonliteral' format specifiers
- Upper/lowercase hex output (uhex command) now works for BUS/CDF schemes
This commit is contained in:
Stephen Anthony 2018-08-19 21:32:47 -02:30
parent 9037af617d
commit 6184d8e130
3 changed files with 23 additions and 50 deletions

View File

@ -49,9 +49,6 @@
* Fixed bug in autodetecting Genesis controllers.
* The Linux builds now use the system-installed PNG and ZLIB libraries
by default.
* When starting Stella for the first time, the first ROM selected will
determine which path to use by default for subsequent runs.
@ -63,20 +60,23 @@
* Fixed missing debug color update when switching display type.
* 'Fill to scanline' now works for scanlines above current scanline too
* 'Fill to scanline' now works for scanlines above current scanline too.
* For UNIX systems: in the ROM launcher, when using symlinks use the
symlink pathname instead of the underlying filesystem pathname.
* The debugger 'uhex' command is now honoured in CDF and BUS schemes.
* Updated PAL palette.
* Updated included PNG library to latest stable version.
* For UNIX systems: in the ROM launcher, when using symlinks use the
symlink pathname instead of the underlying filesystem pathname.
* The Linux builds now use the system-installed PNG and ZLIB libraries
by default.
* For better compatibility, the Windows 32-bit version does not require SSE2
anymore.
* Simplified first start, ROM path is now set by first played ROM.
-Have fun!

View File

@ -19,21 +19,6 @@
namespace Common {
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Base::setHexUppercase(bool enable)
{
if(enable)
{
myHexflags |= std::ios_base::uppercase;
myFmt = Base::myUpperFmt;
}
else
{
myHexflags &= ~std::ios_base::uppercase;
myFmt = Base::myLowerFmt;
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
string Base::toString(int value, Common::Base::Format outputBase)
{
@ -42,7 +27,6 @@ string Base::toString(int value, Common::Base::Format outputBase)
if(outputBase == Base::F_DEFAULT)
outputBase = myDefaultBase;
// Note: generates warnings about 'nonliteral' format
switch(outputBase)
{
case Base::F_2: // base 2: 8 or 16 bits (depending on value)
@ -77,32 +61,34 @@ string Base::toString(int value, Common::Base::Format outputBase)
break;
case Base::F_16_1: // base 16: 1 byte wide
std::snprintf(vToS_buf, 2, myFmt[0], value);
std::snprintf(vToS_buf, 2, hexUppercase() ? "%1X" : "%1x", value);
break;
case Base::F_16_2: // base 16: 2 bytes wide
std::snprintf(vToS_buf, 3, myFmt[1], value);
std::snprintf(vToS_buf, 3, hexUppercase() ? "%02X" : "%02x", value);
break;
case Base::F_16_2_2:
std::snprintf(vToS_buf, 6, "%02X.%02X", value >> 8, value & 0xff );
std::snprintf(vToS_buf, 6, hexUppercase() ? "%02X.%02X" : "%02x.%02x",
value >> 8, value & 0xff );
break;
case Base::F_16_3_2:
std::snprintf(vToS_buf, 7, "%03X.%02X", value >> 8, value & 0xff );
std::snprintf(vToS_buf, 7, hexUppercase() ? "%03X.%02X" : "%03x.%02x",
value >> 8, value & 0xff );
break;
case Base::F_16_4: // base 16: 4 bytes wide
std::snprintf(vToS_buf, 5, myFmt[2], value);
std::snprintf(vToS_buf, 5, hexUppercase() ? "%04X" : "%04x", value);
break;
case Base::F_16_8: // base 16: 8 bytes wide
std::snprintf(vToS_buf, 9, myFmt[3], value);
std::snprintf(vToS_buf, 9, hexUppercase() ? "%08X" : "%08x", value);
break;
case Base::F_16: // base 16: 2, 4, 8 bytes (depending on value)
default:
if(value < 0x100)
std::snprintf(vToS_buf, 3, myFmt[1], value);
std::snprintf(vToS_buf, 3, hexUppercase() ? "%02X" : "%02x", value);
else if(value < 0x10000)
std::snprintf(vToS_buf, 5, myFmt[2], value);
std::snprintf(vToS_buf, 5, hexUppercase() ? "%04X" : "%04x", value);
else
std::snprintf(vToS_buf, 9, myFmt[3], value);
std::snprintf(vToS_buf, 9, hexUppercase() ? "%08X" : "%08x", value);
break;
}
@ -115,13 +101,4 @@ Base::Format Base::myDefaultBase = Base::F_16;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
std::ios_base::fmtflags Base::myHexflags = std::ios_base::hex;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
const char* const Base::myLowerFmt[4] = {
"%1x", "%02x", "%04x", "%08x"
};
const char* const Base::myUpperFmt[4] = {
"%1X", "%02X", "%04X", "%08X"
};
const char* const* Base::myFmt = Base::myLowerFmt;
} // Namespace Common

View File

@ -61,7 +61,10 @@ class Base
static Base::Format format() { return myDefaultBase; }
/** Get/set HEX output to be upper/lower case */
static void setHexUppercase(bool enable);
static void setHexUppercase(bool enable) {
if(enable) myHexflags |= std::ios_base::uppercase;
else myHexflags &= ~std::ios_base::uppercase;
}
static bool hexUppercase() { return myHexflags & std::ios_base::uppercase; }
/** Output HEX digits in 0.5/1/2/4 byte format */
@ -98,13 +101,6 @@ class Base
// Upper or lower case for HEX digits
static std::ios_base::fmtflags myHexflags;
// Format specifiers to use for sprintf (eventually we may convert
// to C++ streams
static ostringstream buf;
static const char* const myLowerFmt[4];
static const char* const myUpperFmt[4];
static const char* const* myFmt;
private:
// Following constructors and assignment operators not supported
Base() = delete;