Skip to content

Commit

Permalink
GBA.emu update and code cleanup
Browse files Browse the repository at this point in the history
* Imagine: Clean up PixelFormat code
* Imagine: Remove -funsafe-loop-optimizations GCC flag which has no effect in recent versions
* 2600.emu: Replace FilesystemNode class with a smaller and simpler version
* GBA.emu: Update to VBA-M GIT 05c09ff (2024.05.10), mostly code reorg
  • Loading branch information
Robert Broglia committed May 12, 2024
1 parent 540c1e6 commit ab49bdc
Show file tree
Hide file tree
Showing 149 changed files with 3,424 additions and 17,689 deletions.
1 change: 0 additions & 1 deletion 2600.emu/build.mk
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ ControllerDetector.cxx \
DispatchResult.cxx \
Driving.cxx \
EmulationTiming.cxx \
FSNode.cxx \
Genesis.cxx \
Joystick.cxx \
Keyboard.cxx \
Expand Down
49 changes: 49 additions & 0 deletions 2600.emu/src/FSNode.hxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#pragma once

/* This file is part of 2600.emu.
2600.emu is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
2600.emu is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with 2600.emu. If not, see <http://www.gnu.org/licenses/> */

#include "bspf.hxx"
#include <utility>

class FilesystemNode
{
public:
constexpr FilesystemNode() = default;
template<class T>
FilesystemNode(T&& path): path{std::forward<T>(path)} {}

friend ostream& operator<<(ostream& os, const FilesystemNode& node)
{
return os << node.getPath();
}

bool exists() const;
const string& getName() const;
const string& getPath() const;
bool isDirectory() const;
bool isFile() const;
bool isReadable() const;
bool isWritable() const;
size_t read(ByteBuffer& buffer, size_t size = 0) const { return 0; }
size_t read(stringstream& buffer) const { return 0; }
size_t write(const ByteBuffer& buffer, size_t size) const { return 0; }
size_t write(const stringstream& buffer) const { return 0; }
string getNameWithExt(const string& ext) const;
string getPathWithExt(const string& ext) const;

protected:
string path;
};
43 changes: 0 additions & 43 deletions 2600.emu/src/FSNodeEmuEx.hh

This file was deleted.

15 changes: 11 additions & 4 deletions 2600.emu/src/FrameBufferEmuEx.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,20 @@
#include <stella/emucore/EventHandlerConstants.hxx>
#include <stella/common/PaletteHandler.hxx>
#include <stella/common/VideoModeHandler.hxx>
#include <imagine/pixmap/Pixmap.hh>
#include <array>

class Console;
class OSystem;
class TIA;

namespace IG
{
template <class PixData>
class PixmapViewBase;
using MutablePixmapView = PixmapViewBase<char>;
enum class PixelFormatId : uint8_t;
}

namespace EmuEx
{
class EmuApp;
Expand Down Expand Up @@ -70,8 +77,8 @@ public:

void setTIAPalette(const PaletteArray& rgb_palette);

void setPixelFormat(IG::PixelFormat);
IG::PixelFormat pixelFormat() const;
void setPixelFormat(IG::PixelFormatId);
IG::PixelFormatId pixelFormat() const;

void showTextMessage(const string& message,
MessagePosition position = MessagePosition::BottomCenter,
Expand Down Expand Up @@ -107,7 +114,7 @@ private:
Common::Rect myImageRect{};
float myPhosphorPercent = 0.80f;
bool myUsePhosphor{};
IG::PixelFormat format;
IG::PixelFormatId format;

std::array<uInt8, 3> getRGBPhosphorTriple(uInt32 c, uInt32 p) const;
template <int outputBits>
Expand Down
6 changes: 2 additions & 4 deletions 2600.emu/src/OSystemEmuEx.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,16 @@ class VideoDialog;
#include <stella/common/bspf.hxx>
#include <stella/common/StateManager.hxx>
#include <stella/common/AudioSettings.hxx>
#include <stella/common/TimerManager.hxx>
#include <stella/emucore/PropsSet.hxx>
#include <stella/emucore/Console.hxx>
#include <stella/emucore/FSNode.hxx>
#include <stella/emucore/FrameBufferConstants.hxx>
#include <stella/emucore/EventHandlerConstants.hxx>
#include <stella/emucore/Settings.hxx>
#include <stella/emucore/Random.hxx>
#include <FSNode.hxx>
#include <SoundEmuEx.hh>
#include <EventHandler.hxx>
#include <FrameBuffer.hxx>
#include <imagine/time/Time.hh>
#include <optional>

namespace EmuEx
Expand Down Expand Up @@ -90,7 +88,7 @@ protected:
std::optional<Console> myConsole{};
Settings mySettings{};
AudioSettings myAudioSettings{mySettings};
Random myRandom{uInt32(TimerManager::getTicks())};
Random myRandom;
FrameBuffer myFrameBuffer{*this};
EventHandler myEventHandler{*this};
PropertiesSet myPropSet{};
Expand Down
65 changes: 19 additions & 46 deletions 2600.emu/src/main/FSNodeEmuEx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,81 +13,54 @@
You should have received a copy of the GNU General Public License
along with 2600.emu. If not, see <http://www.gnu.org/licenses/> */

#include <FSNodeEmuEx.hh>
#include <imagine/logger/logger.h>
#include <assert.h>
#include <FSNode.hxx>

FilesystemNodeEmuEx::FilesystemNodeEmuEx()
{}

FilesystemNodeEmuEx::FilesystemNodeEmuEx(const string& path):name(path), path(path)
{}

bool FilesystemNodeEmuEx::exists() const
bool FilesystemNode::exists() const
{
return true;
}

const string& FilesystemNodeEmuEx::getName() const
{
return name;
}

void FilesystemNodeEmuEx::setName(const string& name)
const string& FilesystemNode::getName() const
{
this->name = name;
return path;
}

const string& FilesystemNodeEmuEx::getPath() const
const string& FilesystemNode::getPath() const
{
return path;
}
bool FilesystemNodeEmuEx::isReadable() const
{
return true;
}

bool FilesystemNodeEmuEx::isWritable() const
bool FilesystemNode::isReadable() const
{
return true;
}

string FilesystemNodeEmuEx::getShortPath() const
{
return ".";
}

bool FilesystemNodeEmuEx::hasParent() const
{
return false;
}

bool FilesystemNodeEmuEx::isDirectory() const
{
return false;
}

bool FilesystemNodeEmuEx::isFile() const
bool FilesystemNode::isWritable() const
{
return true;
}

bool FilesystemNodeEmuEx::makeDir()
bool FilesystemNode::isDirectory() const
{
return false;
}

bool FilesystemNodeEmuEx::rename(const string& newfile)
bool FilesystemNode::isFile() const
{
return false;
return true;
}

bool FilesystemNodeEmuEx::getChildren(AbstractFSList& myList, ListMode mode) const
string FilesystemNode::getNameWithExt(const string& ext) const
{
return false;
size_t pos = getName().find_last_of("/\\");
string s = pos == string::npos ? getName() : getName().substr(pos+1);
pos = s.find_last_of('.');
return (pos != string::npos) ? s.replace(pos, string::npos, ext) : s + ext;
}

AbstractFSNodePtr FilesystemNodeEmuEx::getParent() const
string FilesystemNode::getPathWithExt(const string& ext) const
{
return nullptr;
string s = path;
const size_t pos = s.find_last_of('.');
return (pos != string::npos) ? s.replace(pos, string::npos, ext) : s + ext;
}
20 changes: 10 additions & 10 deletions 2600.emu/src/main/FrameBuffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,31 +61,31 @@ uint8_t FrameBuffer::getPhosphor(uInt8 c1, uInt8 c2) const
void FrameBuffer::setTIAPalette(const PaletteArray& palette)
{
logMsg("setTIAPalette");
auto desc32 = format == IG::PIXEL_BGRA8888 ? IG::PIXEL_DESC_BGRA8888.nativeOrder() : IG::PIXEL_DESC_RGBA8888_NATIVE;
auto desc32 = format == IG::PixelFmtBGRA8888 ? IG::PixelDescBGRA8888Native : IG::PixelDescRGBA8888Native;
for(auto i : IG::iotaCount(256))
{
uint8_t r = (palette[i] >> 16) & 0xff;
uint8_t g = (palette[i] >> 8) & 0xff;
uint8_t b = palette[i] & 0xff;
tiaColorMap16[i] = IG::PIXEL_DESC_RGB565.build(r >> 3, g >> 2, b >> 3, 0);
tiaColorMap16[i] = IG::PixelDescRGB565.build(r >> 3, g >> 2, b >> 3, 0);
tiaColorMap32[i] = desc32.build((int)r, (int)g, (int)b, 0);
}
}

void FrameBuffer::setPixelFormat(IG::PixelFormat fmt)
void FrameBuffer::setPixelFormat(IG::PixelFormatId fmt)
{
format = fmt;
}

IG::PixelFormat FrameBuffer::pixelFormat() const
IG::PixelFormatId FrameBuffer::pixelFormat() const
{
return format;
}

std::array<uInt8, 3> FrameBuffer::getRGBPhosphorTriple(uInt32 c, uInt32 p) const
{
auto [rc, gc, bc, ac] = IG::PIXEL_DESC_RGBA8888_NATIVE.rgba(c);
auto [rp, gp, bp, ap] = IG::PIXEL_DESC_RGBA8888_NATIVE.rgba(p);
auto [rc, gc, bc, ac] = IG::PixelDescRGBA8888Native.rgba(c);
auto [rp, gp, bp, ap] = IG::PixelDescRGBA8888Native.rgba(p);

// Mix current calculated frame with previous displayed frame
const uInt8 rn = myPhosphorPalette[rc][rp];
Expand All @@ -97,19 +97,19 @@ std::array<uInt8, 3> FrameBuffer::getRGBPhosphorTriple(uInt32 c, uInt32 p) const
uInt16 FrameBuffer::getRGBPhosphor16(const uInt32 c, const uInt32 p) const
{
auto [rn, gn, bn] = getRGBPhosphorTriple(c, p);
return IG::PIXEL_DESC_RGB565.build(rn >> 3, gn >> 2, bn >> 3, 0);
return IG::PixelDescRGB565.build(rn >> 3, gn >> 2, bn >> 3, 0);
}

uInt32 FrameBuffer::getRGBPhosphor32(const uInt32 c, const uInt32 p) const
{
auto [rn, gn, bn] = getRGBPhosphorTriple(c, p);
return IG::PIXEL_DESC_RGBA8888_NATIVE.build(rn, gn, bn, (uInt8)0);
return IG::PixelDescRGBA8888Native.build(rn, gn, bn, (uInt8)0);
}

template <int outputBits>
void FrameBuffer::renderOutput(IG::MutablePixmapView pix, TIA &tia)
{
IG::PixmapView framePix{{{(int)tia.width(), (int)tia.height()}, IG::PIXEL_I8}, tia.frameBuffer()};
IG::PixmapView framePix{{{(int)tia.width(), (int)tia.height()}, IG::PixelFmtI8}, tia.frameBuffer()};
assumeExpr(pix.size() == framePix.size());
assumeExpr(pix.format().bytesPerPixel() == outputBits / 8);
assumeExpr(framePix.format().bytesPerPixel() == 1);
Expand Down Expand Up @@ -147,7 +147,7 @@ void FrameBuffer::renderOutput(IG::MutablePixmapView pix, TIA &tia)

void FrameBuffer::render(IG::MutablePixmapView pix, TIA &tia)
{
if(format == IG::PIXEL_RGB565)
if(format == IG::PixelFmtRGB565)
{
renderOutput<16>(pix, tia);
}
Expand Down
5 changes: 3 additions & 2 deletions 2600.emu/src/main/OSystem.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include <OSystem.hxx>
#include <FrameBuffer.hxx>
#include <EventHandler.hxx>
#include <FSNodeEmuEx.hh>
#include <FSNode.hxx>
#include <SoundEmuEx.hh>
#include <stella/emucore/Console.hxx>
#include <stella/emucore/PropsSet.hxx>
Expand All @@ -35,7 +35,8 @@
#undef Debugger

OSystem::OSystem(EmuEx::EmuApp &app):
appPtr{&app}
appPtr{&app},
myRandom{uInt32(TimerManager::getTicks())}
{
mySettings.setValue(AudioSettings::SETTING_PRESET, static_cast<int>(AudioSettings::Preset::custom));
mySettings.setValue(AudioSettings::SETTING_FRAGMENT_SIZE, 128);
Expand Down
6 changes: 3 additions & 3 deletions 2600.emu/src/main/SoundEmuEx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ void SoundEmuEx::setEmuAudio(EmuEx::EmuAudio *audio)
audioQueue->onFragmentEnqueued =
[this, audio](AudioQueue &queue, uInt32 fragFrames)
{
const uint32_t samplesPerFrame = 1; //audioQueue->isStereo() ? 2 : 1;
const uint32_t fragSamples = fragFrames * samplesPerFrame;
uint32_t wroteFrames = 0;
const int samplesPerFrame = 1; //audioQueue->isStereo() ? 2 : 1;
const int fragSamples = fragFrames * samplesPerFrame;
int wroteFrames = 0;
//logDMsg("%d fragments of %d size ready", audioQueue->size(), fragFrames);
while(queue.size())
{
Expand Down
3 changes: 0 additions & 3 deletions 2600.emu/src/stella/common/FSNodeFactory.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class AbstractFSNode;
#elif defined(BSPF_WINDOWS)
#include "FSNodeWINDOWS.hxx"
#elif defined(EMU_EX_PLATFORM)
#include "FSNodeEmuEx.hh"
#elif defined(__LIB_RETRO__)
#include "FSNodeLIBRETRO.hxx"
#else
Expand All @@ -55,8 +54,6 @@ class FilesystemNodeFactory
return make_unique<FilesystemNodePOSIX>(path);
#elif defined(BSPF_WINDOWS)
return make_unique<FilesystemNodeWINDOWS>(path);
#elif defined(EMU_EX_PLATFORM)
return make_unique<FilesystemNodeEmuEx>(path);
#elif defined(__LIB_RETRO__)
return make_unique<FilesystemNodeLIBRETRO>(path);
#endif
Expand Down
Loading

0 comments on commit ab49bdc

Please sign in to comment.