2016-01-29 01:47:16 +00:00
|
|
|
#pragma once
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include <assert.h>
|
|
|
|
#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:
|
2018-07-01 19:21:05 +00:00
|
|
|
static constexpr uint32_t NoDiskInserted = 0xFF;
|
2017-11-20 04:08:23 +00:00
|
|
|
bool _disableAutoInsertDisk;
|
2016-01-29 01:47:16 +00:00
|
|
|
|
2016-01-30 19:57:50 +00:00
|
|
|
unique_ptr<FdsAudio> _audio;
|
2018-07-14 02:19:26 +00:00
|
|
|
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;
|
2017-09-23 16:07:57 +00:00
|
|
|
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;
|
|
|
|
|
2017-05-05 02:55:46 +00:00
|
|
|
int32_t _autoDiskEjectCounter = -1;
|
|
|
|
int32_t _autoDiskSwitchCounter = -1;
|
2018-01-11 04:08:08 +00:00
|
|
|
int32_t _restartAutoInsertCounter = -1;
|
|
|
|
uint32_t _previousFrame = 0;
|
|
|
|
int32_t _lastDiskCheckFrame = 0;
|
|
|
|
int32_t _successiveChecks = 0;
|
|
|
|
uint32_t _previousDiskNumber = FDS::NoDiskInserted;
|
2017-05-05 02:55:46 +00:00
|
|
|
|
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
|
2017-11-20 04:08:23 +00:00
|
|
|
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;
|
2017-05-05 02:55:46 +00:00
|
|
|
vector<vector<uint8_t>> _fdsDiskHeaders;
|
2016-01-29 01:47:16 +00:00
|
|
|
string _romFilepath;
|
|
|
|
|
2017-05-20 00:28:00 +00:00
|
|
|
bool _gameStarted;
|
2016-01-30 20:58:29 +00:00
|
|
|
|
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;
|
2017-11-20 04:08:23 +00:00
|
|
|
void LoadDiskData(vector<uint8_t> ipsData = vector<uint8_t>());
|
|
|
|
vector<uint8_t> CreateIpsPatch();
|
2017-05-05 03:38:27 +00:00
|
|
|
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
|
|
|
|
2018-01-11 04:08:08 +00:00
|
|
|
void ProcessAutoDiskInsert();
|
|
|
|
|
2016-01-30 19:57:50 +00:00
|
|
|
void ClockIrq();
|
2017-07-16 02:52:37 +00:00
|
|
|
|
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-01-30 20:58:29 +00:00
|
|
|
|
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;
|
2017-11-20 04:08:23 +00:00
|
|
|
ConsoleFeatures GetAvailableFeatures() override;
|
2017-07-16 02:52:37 +00:00
|
|
|
|
2017-11-20 04:08:23 +00:00
|
|
|
uint32_t GetSideCount();
|
|
|
|
|
|
|
|
void EjectDisk();
|
|
|
|
void InsertDisk(uint32_t diskNumber);
|
|
|
|
uint32_t GetCurrentDisk();
|
|
|
|
bool IsDiskInserted();
|
2016-01-29 01:47:16 +00:00
|
|
|
|
2017-11-20 04:08:23 +00:00
|
|
|
bool IsAutoInsertDiskEnabled();
|
2016-01-29 01:47:16 +00:00
|
|
|
};
|