Skip to content

Commit

Permalink
Move codebase to requiring C++20, and fix resultant non-standard code.
Browse files Browse the repository at this point in the history
  • Loading branch information
sa666666 committed May 8, 2024
1 parent 4aba8a1 commit ce6cc2e
Show file tree
Hide file tree
Showing 35 changed files with 104 additions and 40 deletions.
7 changes: 5 additions & 2 deletions Changes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@

* Added Joy2B+ controller support.

* Added auto detection for QuadTari attached controllers
* Added auto detection for QuadTari attached controllers.

* Enhanced Kid Vid support to play tape audio.

* Added port selection, used for controller default mapping.

* Added missing PlusROM support for E7 bankswitching.

* Enhanced movie cart (MVC) support
* Enhanced movie cart (MVC) support.

* Accelerated emulation up to ~15% (ARM).

Expand All @@ -60,6 +60,9 @@

* Removed 'launcherroms' option, since it was causing some issues.

* Codebase now uses C++20 features, which means a minimum of gcc-11
or clang-10 for Linux/Mac, and Visual Studio 2022 for Windows.

-Have fun!


Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ CXXFLAGS+= -Wall -Wextra -Wno-unused-parameter
CFLAGS+= -Wall -Wextra -Wno-unused-parameter

ifdef HAVE_GCC
CXXFLAGS+= -Wno-multichar -Wunused -Woverloaded-virtual -Wnon-virtual-dtor -std=c++17
CXXFLAGS+= -Wno-multichar -Wunused -Woverloaded-virtual -Wnon-virtual-dtor -std=c++20
CFLAGS+= -Wno-multichar -Wunused
endif

ifdef HAVE_CLANG
CXXFLAGS+= -Wno-multichar -Wunused -Woverloaded-virtual -Wnon-virtual-dtor -std=c++17
CXXFLAGS+= -Wno-multichar -Wunused -Woverloaded-virtual -Wnon-virtual-dtor -std=c++20
CFLAGS+= -Wno-multichar -Wunused
endif

Expand Down
2 changes: 1 addition & 1 deletion configure
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ else
fi

for compiler in $compilers; do
if test_compiler "$compiler -std=c++17"; then
if test_compiler "$compiler -std=c++20"; then
CXX=$compiler
echo $CXX
break
Expand Down
4 changes: 2 additions & 2 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ <h2>Contents</h2>
<h2><b><a name="Features">Features</a></b></h2>

<ul>
<li>High speed emulation using optimized C++17 code</li>
<li>High speed emulation using optimized C++20 code</li>
<li>Supports high quality TIA emulation using the cycle-exact TIA core from
<a href="https://github.com/6502ts/6502.ts">6502.ts</a> by
Christian Speckner</li>
Expand Down Expand Up @@ -359,7 +359,7 @@ <h3><b><u>Linux/UNIX</u></b></h3>
<li>i386 or x86_64 class machine, with 32 or 64-bit distribution</li>
<li>Other architectures (MIPS, PPC, PPC64, etc.) have been confirmed to work,
but aren't as well tested as i386/x86_64</li>
<li>GNU g++ v/7 or Clang v/5 (with C++17 support) and the make utility are required for compiling the Stella source code</li>
<li>GNU g++ v/11 or Clang v/10 (with C++20 support) and the make utility are required for compiling the Stella source code</li>
</ul>

<p>
Expand Down
3 changes: 2 additions & 1 deletion src/common/FSNodeFactory.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ class FSNodeFactory
return make_unique<FSNodeZIP>(path);
#endif
break;
default:
return nullptr;
}
return nullptr;
}

private:
Expand Down
1 change: 1 addition & 0 deletions src/common/FSNodeZIP.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ size_t FSNodeZIP::read(ByteBuffer& buffer, size_t) const
case zip_error::NOT_A_FILE: throw runtime_error("ZIP file contains errors/not found");
case zip_error::NOT_READABLE: throw runtime_error("ZIP file not readable");
case zip_error::NO_ROMS: throw runtime_error("ZIP file doesn't contain any ROMs");
default: throw runtime_error("FSNodeZIP::read default case hit");
}

myZipHandler->open(_zipFile);
Expand Down
25 changes: 10 additions & 15 deletions src/common/FpsMeter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -46,32 +46,27 @@ void FpsMeter::render(uInt32 frameCount)
}

const size_t queueSize = myQueue.capacity();
entry first, last;
entry e_first, e_last;

last.frames = frameCount;
last.timestamp = high_resolution_clock::now();
e_last.frames = frameCount;
e_last.timestamp = high_resolution_clock::now();

if (myQueue.size() < queueSize) {
myQueue.push_back(last);
myQueue.push_back(e_last);
myFrameCount += frameCount;

first = myQueue.at(myQueueOffset);
e_first = myQueue.at(myQueueOffset);
} else {
myFrameCount = myFrameCount - myQueue.at(myQueueOffset).frames + frameCount;
myQueue.at(myQueueOffset) = last;
myQueue.at(myQueueOffset) = e_last;

myQueueOffset = (myQueueOffset + 1) % queueSize;
first = myQueue.at(myQueueOffset);
e_first = myQueue.at(myQueueOffset);
}

const float myTimeInterval =
duration_cast<duration<float>>(last.timestamp - first.timestamp).count();
duration_cast<duration<float>>(e_last.timestamp - e_first.timestamp).count();

if (myTimeInterval > 0) myFps = (myFrameCount - first.frames) / myTimeInterval;
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
float FpsMeter::fps() const
{
return myFps;
if (myTimeInterval > 0)
myFps = (myFrameCount - e_first.frames) / myTimeInterval;
}
2 changes: 1 addition & 1 deletion src/common/FpsMeter.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class FpsMeter

void render(uInt32 frameCount);

float fps() const;
float fps() const { return myFps; }

private:

Expand Down
2 changes: 1 addition & 1 deletion src/common/LinkedObjectPool.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class LinkedObjectPool
/*
Create a pool of size CAPACITY; the active list starts out empty.
*/
LinkedObjectPool<T, CAPACITY>() { resize(CAPACITY); }
LinkedObjectPool() { resize(CAPACITY); }

/**
Return node data that the 'current' iterator points to.
Expand Down
2 changes: 2 additions & 0 deletions src/common/MouseControl.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ MouseControl::MouseControl(Console& console, string_view mode)
id = 1;
msg << "Right MindLink";
break;
default:
break; // Not supposed to get here
}
};

Expand Down
1 change: 1 addition & 0 deletions src/common/SDL_lib.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#pragma clang diagnostic ignored "-Wimplicit-fallthrough"
#pragma clang diagnostic ignored "-Wreserved-id-macro"
#pragma clang diagnostic ignored "-Wold-style-cast"
#pragma clang diagnostic ignored "-Wswitch-default"
#include <SDL.h>
#pragma clang diagnostic pop
#elif defined(BSPF_WINDOWS)
Expand Down
4 changes: 4 additions & 0 deletions src/common/SoundSDL2.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,8 @@ string SoundSDL2::about() const
case AudioSettings::Preset::ultraQualityMinimalLag:
buf << "Ultra quality, minimal lag\n";
break;
default:
break; // Not supposed to get here
}
buf << " Fragment size: " << static_cast<uInt32>(myHardwareSpec.samples)
<< " bytes\n"
Expand All @@ -300,6 +302,8 @@ string SoundSDL2::about() const
case AudioSettings::ResamplingQuality::lanczos_3:
buf << "Quality 3, Lanczos (a = 3)\n";
break;
default:
break; // Not supposed to get here
}
buf << " Headroom: " << std::fixed << std::setprecision(1)
<< (0.5 * myAudioSettings.headroom()) << " frames\n"
Expand Down
2 changes: 1 addition & 1 deletion src/common/Stack.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class FixedStack
public:
using StackFunction = std::function<void(T&)>;

FixedStack<T, CAPACITY>() = default;
FixedStack() = default;

bool empty() const { return _size == 0; }
bool full() const { return _size >= CAPACITY; }
Expand Down
5 changes: 5 additions & 0 deletions src/common/VideoModeHandler.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ VideoModeHandler::Mode::Mode(uInt32 iw, uInt32 ih, uInt32 sw, uInt32 sh,
iw = std::min(static_cast<uInt32>(iw * zoomLevel), screenS.w) * overscan;
ih = std::min(static_cast<uInt32>(ih * zoomLevel), screenS.h) * overscan;
break;
default:
break; // Not supposed to get here
}
}
else
Expand All @@ -157,6 +159,9 @@ VideoModeHandler::Mode::Mode(uInt32 iw, uInt32 ih, uInt32 sw, uInt32 sh,

case Stretch::None: // UI Mode
break; // Do not change image or screen rects whatsoever

default:
break; // Not supposed to get here
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/common/tv_filters/AtariNTSC.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ void AtariNTSC::render(const uInt8* atari_in, const uInt32 in_width,
// Spawn the threads...
for(uInt32 i = 0; i < myWorkerThreads; ++i)
{
myThreads[i] = std::thread([=] // NOLINT (cppcoreguidelines-misleading-capture-default-by-value
myThreads[i] = std::thread([=, this]
{
rgb_in == nullptr ?
renderThread(atari_in, in_width, in_height, myTotalThreads,
Expand Down
3 changes: 3 additions & 0 deletions src/debugger/CartDebug.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,9 @@ bool CartDebug::getLabel(ostream& buf, uInt16 addr, bool isRead,
}
break;
}

default:
break; // Not supposed to get here
}

switch(places)
Expand Down
7 changes: 7 additions & 0 deletions src/debugger/DebuggerParser.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,8 @@ bool DebuggerParser::getArgs(string_view command, string& verb)
curArg += c;
}
break;
default:
break; // Not supposed to get here
} // switch(state)
}
while(i < length);
Expand Down Expand Up @@ -505,6 +507,9 @@ bool DebuggerParser::validateArgs(int cmd)

case Parameters::ARG_END_ARGS:
break;

default:
break; // Not supposed to get here
}
++curCount;
++p;
Expand Down Expand Up @@ -2645,6 +2650,8 @@ void DebuggerParser::executeTrapRW(uInt32 addr, bool read, bool write, bool add)
}
break;
}
default:
break; // Not supposed to get here
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/debugger/TIADebug.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -505,8 +505,10 @@ bool TIADebug::collision(CollisionBit id, bool toggle) const
if(toggle)
myTIA.toggleCollM0M1();
return myTIA.collCXPPMM() & 0x40;

default:
return false; // Not supposed to get here
}
return false; // make compiler happy
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Expand Down
3 changes: 3 additions & 0 deletions src/debugger/yacc/YaccParser.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,9 @@ int yylex() {
return yylval.val;
}
break;

default:
break; // Not supposed to get here
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/emucore/CartMVC.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1516,6 +1516,9 @@ bool MovieCart::process(uInt16 address)
case TitleState::Stream:
runStateMachine();
break;

default:
break; // Not supposed to get here
}

return a12;
Expand Down
3 changes: 3 additions & 0 deletions src/emucore/FBSurface.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,9 @@ void FBSurface::frameRect(uInt32 x, uInt32 y, uInt32 w, uInt32 h,
vLine(x + w - 1, i, i, color);
}
break;

default:
break; // Not supposed to get here
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/emucore/FSNode.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class FSNode

/**
* Append the given path to the node, adding a directory separator
* when necessary. Modelled on the C++17 fs::path API.
* when necessary.
*/
FSNode& operator/=(string_view path);

Expand Down
3 changes: 3 additions & 0 deletions src/emucore/FrameBuffer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -890,6 +890,9 @@ inline bool FrameBuffer::drawMessage()
myMsg.x = imageRect().w() - dst.w() - 5;
myMsg.y = imageRect().h() - dst.h() - 5;
break;

default:
break; // Not supposed to get here
}

myMsg.surface->setDstPos(myMsg.x + imageRect().x(), myMsg.y + imageRect().y());
Expand Down
2 changes: 1 addition & 1 deletion src/emucore/PlusROM.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ void PlusROM::send()
// as the thread is running. Thus, the request can only be destructed once
// the thread has finished, and we can safely evict it from the deque at
// any time.
std::thread thread([=]() // NOLINT (cppcoreguidelines-misleading-capture-default-by-value)
std::thread thread([=, this]()
{
request->execute();
switch(request->getState())
Expand Down
12 changes: 11 additions & 1 deletion src/emucore/TIASurface.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,8 @@ string TIASurface::effectsInfo() const
case Filter::BlarggPhosphor:
buf << myNTSCFilter.getPreset() << ", phosphor=" << myPBlend;
break;
default:
break; // Not supposed to get here
}
if(attr.blendalpha)
buf << ", scanlines=" << attr.blendalpha
Expand Down Expand Up @@ -585,6 +587,9 @@ void TIASurface::render(bool shade)
myNTSCFilter.render(myTIA->frameBuffer(), width, height, out, outPitch << 2, myRGBFramebuffer.data());
break;
}

default:
break; // Not supposed to get here
}

// Draw TIA image
Expand Down Expand Up @@ -624,7 +629,7 @@ void TIASurface::renderForSnapshot()
myTiaSurface->basePtr(outPtr, outPitch);

mySaveSnapFlag = false;
switch (myFilter)
switch(myFilter)
{
// For non-phosphor modes, render the frame again
case Filter::Normal:
Expand All @@ -650,11 +655,16 @@ void TIASurface::renderForSnapshot()
}

case Filter::BlarggPhosphor:
{
uInt32 bufofs = 0;
for(uInt32 y = height; y; --y)
for(uInt32 x = outPitch; x; --x)
outPtr[pos++] = averageBuffers(bufofs++);
break;
}

default:
break; // Not supposed to get here
}

if(myPhosphorHandler.phosphorEnabled())
Expand Down
3 changes: 3 additions & 0 deletions src/emucore/tia/Playfield.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ void Playfield::applyColors()
myColorRight = myColorP1 &= 0xfe;
}
break;

default:
break; // Not supposed to get here
}
}
}
Expand Down
Loading

0 comments on commit ce6cc2e

Please sign in to comment.