Mesen/Core/FDS.h

128 lines
3.1 KiB
C
Raw Normal View History

2016-01-29 01:47:16 +00:00
#pragma once
#include "stdafx.h"
#include <assert.h>
2022-07-25 10:36:08 +00:00
#include <memory>
2016-01-29 01:47:16 +00:00
#include "BaseMapper.h"
#include "CPU.h"
#include "EmulationSettings.h"
#include "FdsLoader.h"
#include "Console.h"
2016-01-30 19:57:50 +00:00
class FdsAudio;
2016-01-29 01:47:16 +00:00
class FDS : public BaseMapper
{
private:
static constexpr uint32_t NoDiskInserted = 0xFF;
bool _disableAutoInsertDisk;
2016-01-29 01:47:16 +00:00
2022-07-25 10:36:08 +00:00
std::unique_ptr<FdsAudio> _audio;
EmulationSettings* _settings = nullptr;
2016-01-30 19:57:50 +00:00
2016-01-29 01:47:16 +00:00
//Write registers
uint16_t _irqReloadValue = 0;
uint16_t _irqCounter = 0;
bool _irqEnabled = false;
bool _irqRepeatEnabled = false;
2016-01-29 01:47:16 +00:00
bool _diskRegEnabled = true;
bool _soundRegEnabled = true;
uint8_t _writeDataReg = 0;
bool _motorOn = false;
bool _resetTransfer = false;
bool _readMode = false;
bool _crcControl = false;
bool _diskReady = false;
bool _diskIrqEnabled = false;
int32_t _autoDiskEjectCounter = -1;
int32_t _autoDiskSwitchCounter = -1;
int32_t _restartAutoInsertCounter = -1;
uint32_t _previousFrame = 0;
int32_t _lastDiskCheckFrame = 0;
int32_t _successiveChecks = 0;
uint32_t _previousDiskNumber = FDS::NoDiskInserted;
2016-01-29 01:47:16 +00:00
uint8_t _extConWriteReg = 0;
//Read registers
bool _badCrc = false;
bool _endOfHead = false;
bool _readWriteEnabled = false;
uint8_t _readDataReg = 0;
bool _diskWriteProtected = false;
//Internal values
uint32_t _diskNumber = FDS::NoDiskInserted;
2016-01-29 01:47:16 +00:00
uint32_t _diskPosition = 0;
uint32_t _delay = 0;
uint16_t _crcAccumulator;
bool _previousCrcControlFlag = false;
bool _gapEnded = true;
bool _scanningDisk = false;
bool _transferComplete = false;
vector<uint8_t> _fdsRawData;
vector<vector<uint8_t>> _fdsDiskSides;
vector<vector<uint8_t>> _fdsDiskHeaders;
2016-01-29 01:47:16 +00:00
string _romFilepath;
vector<vector<uint8_t>> _orgDiskSides;
vector<vector<uint8_t>> _orgDiskHeaders;
bool _gameStarted = false;
bool _needSave = false;
2016-01-29 01:47:16 +00:00
protected:
2016-12-18 04:14:47 +00:00
virtual uint16_t GetPRGPageSize() override { return 0x2000; }
virtual uint16_t GetCHRPageSize() override { return 0x2000; }
virtual uint32_t GetWorkRamPageSize() override { return 0x8000; }
virtual uint32_t GetWorkRamSize() override { return 0x8000; }
uint16_t RegisterStartAddress() override { return 0x4020; }
uint16_t RegisterEndAddress() override { return 0x4092; }
bool AllowRegisterRead() override { return true; }
2016-01-29 01:47:16 +00:00
2016-12-18 04:14:47 +00:00
void InitMapper() override;
void InitMapper(RomData &romData) override;
void LoadDiskData(vector<uint8_t> ipsData = vector<uint8_t>());
vector<uint8_t> CreateIpsPatch();
void Reset(bool softReset) override;
2016-01-29 01:47:16 +00:00
2016-01-30 19:57:50 +00:00
uint32_t GetFdsDiskSideSize(uint8_t side);
uint8_t ReadFdsDisk();
void WriteFdsDisk(uint8_t value);
2016-01-29 01:47:16 +00:00
void ProcessAutoDiskInsert();
2016-01-30 19:57:50 +00:00
void ClockIrq();
2016-12-18 04:14:47 +00:00
void ProcessCpuClock() override;
2016-01-30 19:57:50 +00:00
void UpdateCrc(uint8_t value);
2016-01-29 01:47:16 +00:00
2016-12-18 04:14:47 +00:00
void WriteRegister(uint16_t addr, uint8_t value) override;
uint8_t ReadRegister(uint16_t addr) override;
2016-01-29 01:47:16 +00:00
2016-12-18 04:14:47 +00:00
uint8_t ReadRAM(uint16_t addr) override;
2016-12-18 04:14:47 +00:00
void StreamState(bool saving) override;
2016-01-29 01:47:16 +00:00
public:
2016-01-30 19:57:50 +00:00
~FDS();
2016-01-29 01:47:16 +00:00
2017-08-06 15:55:23 +00:00
void SaveBattery() override;
ConsoleFeatures GetAvailableFeatures() override;
uint32_t GetSideCount();
void EjectDisk();
void InsertDisk(uint32_t diskNumber);
uint32_t GetCurrentDisk();
bool IsDiskInserted();
2016-01-29 01:47:16 +00:00
bool IsAutoInsertDiskEnabled();
2022-07-25 10:36:08 +00:00
};