Implement base Disc Control interface.
Signed-off-by: Andrea Odetti <mariofutire@gmail.com>
This commit is contained in:
parent
cca65baf97
commit
117502b774
6 changed files with 279 additions and 42 deletions
|
@ -10,6 +10,7 @@ set(SOURCE_FILES
|
|||
rdirectsound.cpp
|
||||
retroregistry.cpp
|
||||
retroframe.cpp
|
||||
diskcontrol.cpp
|
||||
)
|
||||
|
||||
set(HEADER_FILES
|
||||
|
@ -23,6 +24,7 @@ set(HEADER_FILES
|
|||
rdirectsound.h
|
||||
retroregistry.h
|
||||
retroframe.h
|
||||
diskcontrol.h
|
||||
libretro-common/include/libretro.h
|
||||
)
|
||||
|
||||
|
|
176
source/frontends/libretro/diskcontrol.cpp
Normal file
176
source/frontends/libretro/diskcontrol.cpp
Normal file
|
@ -0,0 +1,176 @@
|
|||
#include "StdAfx.h"
|
||||
#include "frontends/libretro/diskcontrol.h"
|
||||
#include "frontends/libretro/environment.h"
|
||||
|
||||
#include "Core.h"
|
||||
#include "CardManager.h"
|
||||
#include "Disk.h"
|
||||
#include "Harddisk.h"
|
||||
|
||||
namespace ra2
|
||||
{
|
||||
|
||||
DiskControl::DiskControl() : myEjected(false), myIndex(0)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool DiskControl::insertDisk(const std::string & filename)
|
||||
{
|
||||
if (filename.empty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (insertFloppyDisk(filename))
|
||||
{
|
||||
myIndex = 0;
|
||||
myImages.clear();
|
||||
myImages.push_back(filename);
|
||||
myEjected = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
return insertHardDisk(filename);
|
||||
}
|
||||
|
||||
bool DiskControl::insertFloppyDisk(const std::string & filename) const
|
||||
{
|
||||
CardManager & cardManager = GetCardMgr();
|
||||
|
||||
Disk2InterfaceCard * disk2Card = dynamic_cast<Disk2InterfaceCard*>(cardManager.GetObj(SLOT6));
|
||||
if (disk2Card)
|
||||
{
|
||||
const ImageError_e error = disk2Card->InsertDisk(DRIVE_1, filename.c_str(), IMAGE_FORCE_WRITE_PROTECTED, IMAGE_DONT_CREATE);
|
||||
|
||||
if (error == eIMAGE_ERROR_NONE)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool DiskControl::insertHardDisk(const std::string & filename) const
|
||||
{
|
||||
CardManager & cardManager = GetCardMgr();
|
||||
|
||||
if (cardManager.QuerySlot(SLOT7) != CT_GenericHDD)
|
||||
{
|
||||
cardManager.Insert(SLOT7, CT_GenericHDD);
|
||||
}
|
||||
|
||||
HarddiskInterfaceCard * harddiskCard = dynamic_cast<HarddiskInterfaceCard*>(cardManager.GetObj(SLOT7));
|
||||
if (harddiskCard)
|
||||
{
|
||||
BOOL bRes = harddiskCard->Insert(HARDDISK_1, filename);
|
||||
return bRes == TRUE;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool DiskControl::getEjectedState() const
|
||||
{
|
||||
return myEjected;
|
||||
}
|
||||
|
||||
bool DiskControl::setEjectedState(bool ejected)
|
||||
{
|
||||
if (myEjected == ejected)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
CardManager & cardManager = GetCardMgr();
|
||||
Disk2InterfaceCard * disk2Card = dynamic_cast<Disk2InterfaceCard*>(cardManager.GetObj(SLOT6));
|
||||
|
||||
bool result = false;
|
||||
if (disk2Card && myIndex < myImages.size())
|
||||
{
|
||||
if (ejected)
|
||||
{
|
||||
disk2Card->EjectDisk(DRIVE_1);
|
||||
result = true;
|
||||
myEjected = ejected;
|
||||
}
|
||||
else
|
||||
{
|
||||
// inserted
|
||||
result = insertFloppyDisk(myImages[myIndex]);
|
||||
myEjected = !result;
|
||||
ra2::log_cb(RETRO_LOG_INFO, "Insert new disk: %s -> %d\n", myImages[myIndex].c_str(), result);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
size_t DiskControl::getImageIndex() const
|
||||
{
|
||||
return myIndex;
|
||||
}
|
||||
|
||||
void DiskControl::checkState() const
|
||||
{
|
||||
if (!myEjected)
|
||||
{
|
||||
// this should not happen
|
||||
ra2::log_cb(RETRO_LOG_INFO, "WTF\n");
|
||||
}
|
||||
}
|
||||
|
||||
bool DiskControl::setImageIndex(size_t index)
|
||||
{
|
||||
checkState();
|
||||
myIndex = index;
|
||||
return true;
|
||||
}
|
||||
|
||||
size_t DiskControl::getNumImages() const
|
||||
{
|
||||
return myImages.size();
|
||||
}
|
||||
|
||||
bool DiskControl::replaceImageIndex(size_t index, const std::string & path)
|
||||
{
|
||||
if (myIndex < myImages.size())
|
||||
{
|
||||
myImages[index] = path;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool DiskControl::removeImageIndex(size_t index)
|
||||
{
|
||||
if (myIndex < myImages.size())
|
||||
{
|
||||
myImages.erase(myImages.begin() + index);
|
||||
if (myIndex == index)
|
||||
{
|
||||
myIndex = myImages.size();
|
||||
}
|
||||
else if (myIndex > index)
|
||||
{
|
||||
--myIndex;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool DiskControl::addImageIndex()
|
||||
{
|
||||
myImages.push_back(std::string());
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
38
source/frontends/libretro/diskcontrol.h
Normal file
38
source/frontends/libretro/diskcontrol.h
Normal file
|
@ -0,0 +1,38 @@
|
|||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
namespace ra2
|
||||
{
|
||||
|
||||
class DiskControl
|
||||
{
|
||||
public:
|
||||
DiskControl();
|
||||
|
||||
bool getEjectedState() const;
|
||||
bool setEjectedState(bool state);
|
||||
|
||||
size_t getImageIndex() const;
|
||||
bool setImageIndex(size_t index);
|
||||
|
||||
size_t getNumImages() const;
|
||||
|
||||
bool replaceImageIndex(size_t index, const std::string & path);
|
||||
bool removeImageIndex(size_t index);
|
||||
bool addImageIndex();
|
||||
|
||||
bool insertDisk(const std::string & filename);
|
||||
|
||||
private:
|
||||
std::vector<std::string> myImages;
|
||||
|
||||
bool myEjected;
|
||||
size_t myIndex;
|
||||
|
||||
bool insertFloppyDisk(const std::string & filename) const;
|
||||
bool insertHardDisk(const std::string & filename) const;
|
||||
|
||||
void checkState() const;
|
||||
};
|
||||
|
||||
}
|
|
@ -22,46 +22,6 @@
|
|||
|
||||
#include "libretro.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
bool insertDisk(const std::string & filename)
|
||||
{
|
||||
if (filename.empty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
CardManager & cardManager = GetCardMgr();
|
||||
|
||||
Disk2InterfaceCard * disk2Card = dynamic_cast<Disk2InterfaceCard*>(cardManager.GetObj(SLOT6));
|
||||
if (disk2Card)
|
||||
{
|
||||
const ImageError_e error = disk2Card->InsertDisk(DRIVE_1, filename.c_str(), IMAGE_FORCE_WRITE_PROTECTED, IMAGE_DONT_CREATE);
|
||||
|
||||
if (error == eIMAGE_ERROR_NONE)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (cardManager.QuerySlot(SLOT7) != CT_GenericHDD)
|
||||
{
|
||||
cardManager.Insert(SLOT7, CT_GenericHDD);
|
||||
}
|
||||
|
||||
HarddiskInterfaceCard * harddiskCard = dynamic_cast<HarddiskInterfaceCard*>(cardManager.GetObj(SLOT7));
|
||||
if (harddiskCard)
|
||||
{
|
||||
BOOL bRes = harddiskCard->Insert(HARDDISK_1, filename);
|
||||
return bRes == TRUE;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace ra2
|
||||
{
|
||||
|
||||
|
@ -300,7 +260,7 @@ namespace ra2
|
|||
|
||||
bool Game::loadGame(const std::string & path)
|
||||
{
|
||||
const bool ok = insertDisk(path);
|
||||
const bool ok = myDiskControl.insertDisk(path);
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
@ -310,4 +270,9 @@ namespace ra2
|
|||
return true;
|
||||
}
|
||||
|
||||
DiskControl & Game::getDiskControl()
|
||||
{
|
||||
return myDiskControl;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include "frontends/common2/speed.h"
|
||||
#include "frontends/libretro/environment.h"
|
||||
#include "frontends/libretro/diskcontrol.h"
|
||||
|
||||
#include "linux/context.h"
|
||||
|
||||
|
@ -29,6 +30,8 @@ namespace ra2
|
|||
|
||||
double getMousePosition(int i) const;
|
||||
|
||||
DiskControl & getDiskControl();
|
||||
|
||||
static void keyboardCallback(bool down, unsigned keycode, uint32_t character, uint16_t key_modifiers);
|
||||
|
||||
static void frameTimeCallback(retro_usec_t usec);
|
||||
|
@ -55,6 +58,8 @@ namespace ra2
|
|||
|
||||
MousePosition_t myMouse[2];
|
||||
|
||||
DiskControl myDiskControl;
|
||||
|
||||
bool checkButtonPressed(unsigned id);
|
||||
void keyboardEmulation();
|
||||
void mouseEmulation();
|
||||
|
|
|
@ -34,6 +34,52 @@ namespace
|
|||
return std::equal(ending.rbegin(), ending.rend(), value.rbegin());
|
||||
}
|
||||
|
||||
bool retro_set_eject_state(bool ejected)
|
||||
{
|
||||
ra2::log_cb(RETRO_LOG_INFO, "RA2: %s (%d)\n", __FUNCTION__, ejected);
|
||||
return ourGame->getDiskControl().setEjectedState(ejected);
|
||||
}
|
||||
|
||||
bool retro_get_eject_state()
|
||||
{
|
||||
return ourGame->getDiskControl().getEjectedState();
|
||||
}
|
||||
|
||||
unsigned retro_get_image_index()
|
||||
{
|
||||
return ourGame->getDiskControl().getImageIndex();
|
||||
}
|
||||
|
||||
bool retro_set_image_index(unsigned index)
|
||||
{
|
||||
ra2::log_cb(RETRO_LOG_INFO, "RA2: %s (%d)\n", __FUNCTION__, index);
|
||||
return ourGame->getDiskControl().setImageIndex(index);
|
||||
}
|
||||
|
||||
unsigned retro_get_num_images()
|
||||
{
|
||||
return ourGame->getDiskControl().getNumImages();
|
||||
}
|
||||
|
||||
bool retro_replace_image_index(unsigned index, const struct retro_game_info *info)
|
||||
{
|
||||
ra2::log_cb(RETRO_LOG_INFO, "RA2: %s (%s)\n", __FUNCTION__, info->path);
|
||||
if (info->path)
|
||||
{
|
||||
return ourGame->getDiskControl().replaceImageIndex(index, info->path);
|
||||
}
|
||||
else
|
||||
{
|
||||
return ourGame->getDiskControl().removeImageIndex(index);
|
||||
}
|
||||
}
|
||||
|
||||
bool retro_add_image_index()
|
||||
{
|
||||
ra2::log_cb(RETRO_LOG_INFO, "RA2: %s\n", __FUNCTION__);
|
||||
return ourGame->getDiskControl().addImageIndex();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void retro_init(void)
|
||||
|
@ -155,6 +201,11 @@ void retro_set_environment(retro_environment_t cb)
|
|||
bool achievements = true;
|
||||
cb(RETRO_ENVIRONMENT_SET_SUPPORT_ACHIEVEMENTS, &achievements);
|
||||
|
||||
static retro_disk_control_callback diskControlCallback = {
|
||||
&retro_set_eject_state, &retro_get_eject_state, &retro_get_image_index, &retro_set_image_index, &retro_get_num_images, &retro_replace_image_index, &retro_add_image_index
|
||||
};
|
||||
cb(RETRO_ENVIRONMENT_SET_DISK_CONTROL_INTERFACE, &diskControlCallback);
|
||||
|
||||
ra2::SetupRetroVariables();
|
||||
}
|
||||
|
||||
|
@ -226,7 +277,7 @@ bool retro_load_game(const retro_game_info *info)
|
|||
ok = game->loadGame(gamePath);
|
||||
}
|
||||
|
||||
ra2::log_cb(RETRO_LOG_INFO, "Game path: %s:%d\n", info->path, ok);
|
||||
ra2::log_cb(RETRO_LOG_INFO, "Game path: %s -> %d\n", info->path, ok);
|
||||
|
||||
if (ok)
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue