2017-11-20 04:08:23 +00:00
|
|
|
#pragma once
|
|
|
|
#include "stdafx.h"
|
2022-07-25 10:36:08 +00:00
|
|
|
#include <memory>
|
2017-11-20 04:08:23 +00:00
|
|
|
#include "SystemActionManager.h"
|
|
|
|
#include "FDS.h"
|
|
|
|
|
|
|
|
class FdsSystemActionManager : public SystemActionManager
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
const uint8_t ReinsertDiskFrameDelay = 120;
|
|
|
|
|
|
|
|
std::weak_ptr<FDS> _mapper;
|
|
|
|
|
|
|
|
bool _needEjectDisk = false;
|
|
|
|
uint8_t _insertDiskNumber = 0;
|
|
|
|
uint8_t _insertDiskDelay = 0;
|
|
|
|
uint32_t _sideCount;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
string GetKeyNames() override
|
|
|
|
{
|
|
|
|
return string("RPE0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ").substr(0, _sideCount + 3);
|
|
|
|
}
|
|
|
|
|
|
|
|
void StreamState(bool saving) override
|
|
|
|
{
|
|
|
|
SystemActionManager::StreamState(saving);
|
|
|
|
Stream(_needEjectDisk, _insertDiskNumber, _insertDiskDelay);
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
enum FdsButtons { EjectDiskButton = 2, InsertDisk1 };
|
|
|
|
|
2022-07-25 10:36:08 +00:00
|
|
|
FdsSystemActionManager(std::shared_ptr<Console> console, std::shared_ptr<BaseMapper> mapper) : SystemActionManager(console)
|
2017-11-20 04:08:23 +00:00
|
|
|
{
|
|
|
|
_mapper = std::dynamic_pointer_cast<FDS>(mapper);
|
|
|
|
_sideCount = std::dynamic_pointer_cast<FDS>(mapper)->GetSideCount();
|
|
|
|
|
2018-07-14 02:19:26 +00:00
|
|
|
if(console->GetSettings()->CheckFlag(EmulationFlags::FdsAutoLoadDisk)) {
|
2017-11-20 04:08:23 +00:00
|
|
|
InsertDisk(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnAfterSetState() override
|
|
|
|
{
|
|
|
|
SystemActionManager::OnAfterSetState();
|
|
|
|
if(_needEjectDisk) {
|
|
|
|
SetBit(FdsSystemActionManager::FdsButtons::EjectDiskButton);
|
|
|
|
_needEjectDisk = false;
|
|
|
|
}
|
|
|
|
if(_insertDiskDelay > 0) {
|
|
|
|
_insertDiskDelay--;
|
|
|
|
if(_insertDiskDelay == 0) {
|
|
|
|
SetBit(FdsSystemActionManager::FdsButtons::InsertDisk1 + _insertDiskNumber);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-29 00:55:08 +00:00
|
|
|
bool needEject = IsPressed(FdsSystemActionManager::FdsButtons::EjectDiskButton);
|
|
|
|
int diskToInsert = -1;
|
|
|
|
for(int i = 0; i < 16; i++) {
|
|
|
|
if(IsPressed(FdsSystemActionManager::FdsButtons::InsertDisk1 + i)) {
|
|
|
|
diskToInsert = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-11-20 04:08:23 +00:00
|
|
|
|
2017-12-29 00:55:08 +00:00
|
|
|
if(needEject || diskToInsert >= 0) {
|
2022-07-25 10:36:08 +00:00
|
|
|
std::shared_ptr<FDS> mapper = _mapper.lock();
|
|
|
|
if(needEject)
|
2017-11-20 04:08:23 +00:00
|
|
|
mapper->EjectDisk();
|
|
|
|
|
2022-07-25 10:36:08 +00:00
|
|
|
if(diskToInsert >= 0)
|
2017-12-29 00:55:08 +00:00
|
|
|
mapper->InsertDisk(diskToInsert);
|
2017-11-20 04:08:23 +00:00
|
|
|
}
|
|
|
|
}
|
2017-12-29 00:55:08 +00:00
|
|
|
|
2017-11-20 04:08:23 +00:00
|
|
|
void EjectDisk()
|
|
|
|
{
|
|
|
|
_needEjectDisk = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void InsertDisk(uint8_t diskNumber)
|
|
|
|
{
|
2022-07-25 10:36:08 +00:00
|
|
|
std::shared_ptr<FDS> mapper = _mapper.lock();
|
2017-11-20 04:08:23 +00:00
|
|
|
if(mapper) {
|
|
|
|
if(mapper->IsDiskInserted()) {
|
|
|
|
//Eject disk on next frame, then insert new disk 2 seconds later
|
|
|
|
_needEjectDisk = true;
|
|
|
|
_insertDiskNumber = diskNumber;
|
|
|
|
_insertDiskDelay = FdsSystemActionManager::ReinsertDiskFrameDelay;
|
|
|
|
} else {
|
|
|
|
//Insert disk on next frame
|
|
|
|
_insertDiskNumber = diskNumber;
|
|
|
|
_insertDiskDelay = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SwitchDiskSide()
|
|
|
|
{
|
2018-01-08 04:16:50 +00:00
|
|
|
if(!IsAutoInsertDiskEnabled()) {
|
2022-07-25 10:36:08 +00:00
|
|
|
std::shared_ptr<FDS> mapper = _mapper.lock();
|
2018-01-08 04:16:50 +00:00
|
|
|
if(mapper && mapper->IsDiskInserted()) {
|
2018-06-03 22:20:40 +00:00
|
|
|
InsertDisk((mapper->GetCurrentDisk() ^ 0x01) % mapper->GetSideCount());
|
2018-01-08 04:16:50 +00:00
|
|
|
}
|
2017-11-20 04:08:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void InsertNextDisk()
|
|
|
|
{
|
2018-01-08 04:16:50 +00:00
|
|
|
if(!IsAutoInsertDiskEnabled()) {
|
2022-07-25 10:36:08 +00:00
|
|
|
std::shared_ptr<FDS> mapper = _mapper.lock();
|
2018-01-08 04:16:50 +00:00
|
|
|
if(mapper) {
|
|
|
|
InsertDisk(((mapper->GetCurrentDisk() & 0xFE) + 2) % mapper->GetSideCount());
|
|
|
|
}
|
2017-11-20 04:08:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t GetSideCount()
|
|
|
|
{
|
2022-07-25 10:36:08 +00:00
|
|
|
std::shared_ptr<FDS> mapper = _mapper.lock();
|
2017-11-20 04:08:23 +00:00
|
|
|
if(mapper) {
|
|
|
|
return mapper->GetSideCount();
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsAutoInsertDiskEnabled()
|
|
|
|
{
|
2022-07-25 10:36:08 +00:00
|
|
|
std::shared_ptr<FDS> mapper = _mapper.lock();
|
2017-11-20 04:08:23 +00:00
|
|
|
if(mapper) {
|
|
|
|
return mapper->IsAutoInsertDiskEnabled();
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|