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. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
//============================================================================ //============================================================================
#include "bspf.hxx"
#include "FSNodeLIBRETRO.hxx" #include "FSNodeLIBRETRO.hxx"
#ifdef _WIN32 #ifdef _WIN32
@ -92,7 +93,7 @@ AbstractFSNodePtr FilesystemNodeLIBRETRO::getParent() const
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
size_t FilesystemNodeLIBRETRO::read(ByteBuffer& image) 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); extern uInt32 libretro_read_rom(void* data);
return libretro_read_rom(image.get()); return libretro_read_rom(image.get());

View File

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

View File

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