libretro: Use ROM size from core, update formatting and add const.

This commit is contained in:
Stephen Anthony 2020-05-25 18:37:35 -02:30
parent ad781da69d
commit 32ede9da09
3 changed files with 96 additions and 78 deletions

View File

@ -15,6 +15,7 @@
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//============================================================================
#include "bspf.hxx"
#include "FSNodeLIBRETRO.hxx"
#ifdef _WIN32
@ -92,7 +93,7 @@ AbstractFSNodePtr FilesystemNodeLIBRETRO::getParent() const
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
size_t FilesystemNodeLIBRETRO::read(ByteBuffer& image) const
{
image = make_unique<uInt8[]>(512 * 1024);
image = make_unique<uInt8[]>(BSPF::romMaxSize());
extern uInt32 libretro_read_rom(void* data);
return libretro_read_rom(image.get());

View File

@ -188,7 +188,6 @@ void StellaLIBRETRO::updateVideo()
if(tia.scanlines() == 0) break;
}
video_ready = tia.newFramePending();
if (video_ready)
@ -221,7 +220,7 @@ bool StellaLIBRETRO::loadState(const void* data, size_t size)
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool StellaLIBRETRO::saveState(void* data, size_t size)
bool StellaLIBRETRO::saveState(void* data, size_t size) const
{
Serializer state;
@ -236,7 +235,7 @@ bool StellaLIBRETRO::saveState(void* data, size_t size)
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
size_t StellaLIBRETRO::getStateSize()
size_t StellaLIBRETRO::getStateSize() const
{
Serializer state;
@ -247,52 +246,52 @@ size_t StellaLIBRETRO::getStateSize()
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
float StellaLIBRETRO::getVideoAspectPar()
float StellaLIBRETRO::getVideoAspectPar() const
{
float par;
if (getVideoNTSC())
{
if (!video_aspect_ntsc)
{
if (video_filter != NTSCFilter::Preset::OFF)
if (!video_aspect_ntsc)
{
// non-interlace square pixel clock -- 1.0 pixel @ color burst -- double-width pixels
par = (6.1363635f / 3.579545454f) / 2.0;
if (video_filter != NTSCFilter::Preset::OFF)
{
// non-interlace square pixel clock -- 1.0 pixel @ color burst -- double-width pixels
par = (6.1363635f / 3.579545454f) / 2.0;
}
else
{
// blargg filter
par = 1.0;
}
}
else
{
// blargg filter
par = 1.0;
}
}
else
par = video_aspect_ntsc / 100.0;
par = video_aspect_ntsc / 100.0;
}
else
{
if (!video_aspect_pal)
{
if (video_filter != NTSCFilter::Preset::OFF)
if (!video_aspect_pal)
{
// non-interlace square pixel clock -- 0.8 pixel @ color burst -- double-width pixels
par = (7.3750000f / (4.43361875f * 4.0f / 5.0f)) / 2.0f;
if (video_filter != NTSCFilter::Preset::OFF)
{
// non-interlace square pixel clock -- 0.8 pixel @ color burst -- double-width pixels
par = (7.3750000f / (4.43361875f * 4.0f / 5.0f)) / 2.0f;
}
else
{
// blargg filter
par = 1.0;
}
}
else
{
// blargg filter
par = 1.0;
}
}
else
par = video_aspect_pal / 100.0;
par = video_aspect_pal / 100.0;
}
return par;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
float StellaLIBRETRO::getVideoAspect()
float StellaLIBRETRO::getVideoAspect() const
{
uInt32 width = myOSystem->console().tia().width() * 2;
@ -301,7 +300,7 @@ float StellaLIBRETRO::getVideoAspect()
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void* StellaLIBRETRO::getVideoBuffer()
void* StellaLIBRETRO::getVideoBuffer() const
{
FrameBufferLIBRETRO& frame = static_cast<FrameBufferLIBRETRO&>(myOSystem->frameBuffer());
@ -309,7 +308,7 @@ void* StellaLIBRETRO::getVideoBuffer()
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool StellaLIBRETRO::getVideoNTSC()
bool StellaLIBRETRO::getVideoNTSC() const
{
const ConsoleInfo& console_info = myOSystem->console().about();
string format = console_info.DisplayFormat;
@ -348,13 +347,13 @@ void StellaLIBRETRO::setConsoleFormat(uInt32 mode)
{
switch(mode)
{
case 0: console_format = "AUTO"; break;
case 1: console_format = "NTSC"; break;
case 2: console_format = "PAL"; break;
case 3: console_format = "SECAM"; break;
case 4: console_format = "NTSC50"; break;
case 5: console_format = "PAL60"; break;
case 6: console_format = "SECAM60"; break;
case 0: console_format = "AUTO"; break;
case 1: console_format = "NTSC"; break;
case 2: console_format = "PAL"; break;
case 3: console_format = "SECAM"; break;
case 4: console_format = "NTSC50"; break;
case 5: console_format = "PAL60"; break;
case 6: console_format = "SECAM60"; break;
}
if (system_ready)
@ -388,9 +387,9 @@ void StellaLIBRETRO::setVideoPhosphor(uInt32 mode, uInt32 blend)
{
switch (mode)
{
case 0: video_phosphor = "byrom"; break;
case 1: video_phosphor = "never"; break;
case 2: video_phosphor = "always"; break;
case 0: video_phosphor = "byrom"; break;
case 1: video_phosphor = "never"; break;
case 2: video_phosphor = "always"; break;
}
video_phosphor_blend = blend;
@ -414,9 +413,9 @@ void StellaLIBRETRO::setAudioStereo(int mode)
{
switch (mode)
{
case 0: audio_mode = "byrom"; break;
case 1: audio_mode = "mono"; break;
case 2: audio_mode = "stereo"; break;
case 0: audio_mode = "byrom"; break;
case 1: audio_mode = "mono"; break;
case 2: audio_mode = "stereo"; break;
}
if (system_ready)

View File

@ -32,7 +32,6 @@
#include "TIA.hxx"
#include "TIASurface.hxx"
/**
This class wraps Stella core for easier libretro maintenance
*/
@ -52,46 +51,59 @@ class StellaLIBRETRO
void runFrame();
bool loadState(const void* data, size_t size);
bool saveState(void* data, size_t size);
bool saveState(void* data, size_t size) const;
public:
const char* getCoreName() { return "Stella"; }
const char* getROMExtensions() { return "a26|bin"; }
const char* getCoreName() const { return "Stella"; }
const char* getROMExtensions() const { return "a26|bin"; }
void* getROM() { return rom_image.get(); }
uInt32 getROMSize() { return rom_size; }
uInt32 getROMMax() { return 512 * 1024; }
void* getROM() const { return rom_image.get(); }
uInt32 getROMSize() const { return rom_size; }
constexpr uInt32 getROMMax() const { return BSPF::romMaxSize(); }
uInt8* getRAM() { return system_ram; }
uInt32 getRAMSize() { return 128; }
constexpr uInt32 getRAMSize() const { return 128; }
size_t getStateSize();
size_t getStateSize() const;
bool getConsoleNTSC() { return console_timing == ConsoleTiming::ntsc; }
bool getConsoleNTSC() const { return console_timing == ConsoleTiming::ntsc; }
float getVideoAspectPar();
float getVideoAspect();
bool getVideoNTSC();
float getVideoRate() { return getVideoNTSC() ? 60.0 : 50.0; }
float getVideoAspectPar() const;
float getVideoAspect() const;
bool getVideoNTSC() const;
float getVideoRate() const { return getVideoNTSC() ? 60.0 : 50.0; }
bool getVideoReady() { return video_ready; }
uInt32 getVideoZoom() { return myOSystem->frameBuffer().tiaSurface().ntscEnabled() ? 2 : 1; }
bool getVideoReady() const { return video_ready; }
uInt32 getVideoZoom() const {
return myOSystem->frameBuffer().tiaSurface().ntscEnabled() ? 2 : 1;
}
bool getVideoResize();
void* getVideoBuffer();
uInt32 getVideoWidth() { return getVideoZoom()==1 ? myOSystem->console().tia().width() : getVideoWidthMax(); }
uInt32 getVideoHeight() { return myOSystem->console().tia().height(); }
uInt32 getVideoPitch() { return getVideoWidthMax() * 4; }
void* getVideoBuffer() const;
uInt32 getVideoWidth() const {
return getVideoZoom() == 1 ? myOSystem->console().tia().width() : getVideoWidthMax();
}
uInt32 getVideoHeight() const {
return myOSystem->console().tia().height();
}
constexpr uInt32 getVideoPitch() const { return getVideoWidthMax() * 4; }
uInt32 getVideoWidthMax() { return AtariNTSC::outWidth(160); }
uInt32 getVideoHeightMax() { return 312; }
constexpr uInt32 getVideoWidthMax() const { return AtariNTSC::outWidth(160); }
constexpr uInt32 getVideoHeightMax() const { return 312; }
uInt32 getRenderWidth() { return getVideoZoom()==1 ? myOSystem->console().tia().width() * 2 : getVideoWidthMax(); }
uInt32 getRenderHeight() { return myOSystem->console().tia().height() * getVideoZoom(); }
uInt32 getRenderWidth() const {
return getVideoZoom() == 1 ? myOSystem->console().tia().width() * 2
: getVideoWidthMax();
}
uInt32 getRenderHeight() const {
return myOSystem->console().tia().height() * getVideoZoom();
}
float getAudioRate() { return getConsoleNTSC() ? (262 * 76 * 60) / 38.0 : (312 * 76 * 50) / 38.0; }
bool getAudioReady() { return audio_samples > 0; }
uInt32 getAudioSize() { return audio_samples; }
float getAudioRate() const {
return getConsoleNTSC() ? (262 * 76 * 60) / 38.0 : (312 * 76 * 50) / 38.0;
}
bool getAudioReady() const { return audio_samples > 0; }
uInt32 getAudioSize() const { return audio_samples; }
Int16* getAudioBuffer() { return audio_buffer.get(); }
@ -101,7 +113,7 @@ class StellaLIBRETRO
void setConsoleFormat(uInt32 mode);
void setVideoAspectNTSC(uInt32 value) { video_aspect_ntsc = value; };
void setVideoAspectPAL(uInt32 value) { video_aspect_pal = value; };
void setVideoAspectPAL(uInt32 value) { video_aspect_pal = value; };
void setVideoFilter(NTSCFilter::Preset mode);
void setVideoPalette(const string& mode);
@ -109,12 +121,18 @@ class StellaLIBRETRO
void setAudioStereo(int mode);
void setInputEvent(Event::Type type, Int32 state) { myOSystem->eventHandler().handleEvent(type, state); }
void setInputEvent(Event::Type type, Int32 state) {
myOSystem->eventHandler().handleEvent(type, state);
}
Controller::Type getLeftControllerType() { return myOSystem->console().leftController().type(); }
Controller::Type getRightControllerType() { return myOSystem->console().rightController().type(); }
Controller::Type getLeftControllerType() const {
return myOSystem->console().leftController().type();
}
Controller::Type getRightControllerType() const {
return myOSystem->console().rightController().type();
}
void setPaddleJoypadSensitivity(int sensitivity)
void setPaddleJoypadSensitivity(int sensitivity)
{
if(getLeftControllerType() == Controller::Type::Paddles)
static_cast<Paddles&>(myOSystem->console().leftController()).setDigitalSensitivity(sensitivity);
@ -137,7 +155,7 @@ class StellaLIBRETRO
unique_ptr<OSystemLIBRETRO> myOSystem;
uInt32 system_ready;
unique_ptr<uInt8[]> rom_image;
ByteBuffer rom_image;
uInt32 rom_size;
string rom_path;