Mesen-X/Core/FDS.h

112 lines
2.4 KiB
C
Raw Normal View History

2016-01-28 20:47:16 -05: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 14:57:50 -05:00
class FdsAudio;
2016-01-28 20:47:16 -05:00
class FDS : public BaseMapper
{
private:
static const uint32_t NoDiskInserted = 0xFF;
static const uint32_t DiskInsertDelay = 3600000; //approx 2 sec delay
static FDS* Instance;
2016-01-30 14:57:50 -05:00
unique_ptr<FdsAudio> _audio;
2016-01-28 20:47:16 -05:00
//Write registers
uint16_t _irqReloadValue = 0;
uint16_t _irqCounter = 0;
bool _irqEnabled = false;
bool _irqReloadEnabled = false;
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;
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 = 0;
uint32_t _newDiskNumber = 0;
uint32_t _newDiskInsertDelay = 0;
uint32_t _diskPosition = 0;
uint32_t _delay = 0;
uint16_t _crcAccumulator;
bool _previousCrcControlFlag = false;
bool _gapEnded = true;
bool _scanningDisk = false;
bool _needIrq = false;
bool _transferComplete = false;
bool _isDirty = false;
vector<uint8_t> _fdsRawData;
vector<vector<uint8_t>> _fdsDiskSides;
string _romFilepath;
uint8_t _gameStarted = 0;
uint32_t _previousSpeed = 0;
bool _fastForwarding = false;
2016-01-28 20:47:16 -05:00
protected:
virtual uint16_t GetPRGPageSize() { return 0x2000; }
virtual uint16_t GetCHRPageSize() { return 0x2000; }
virtual uint32_t GetWorkRamPageSize() { return 0x8000; }
virtual uint32_t GetWorkRamSize() { return 0x8000; }
uint16_t RegisterStartAddress() { return 0x4020; }
uint16_t RegisterEndAddress() { return 0x4092; }
bool AllowRegisterRead() { return true; }
2016-01-30 14:57:50 -05:00
void InitMapper();
void InitMapper(RomData &romData);
2016-01-28 20:47:16 -05:00
2016-01-30 14:57:50 -05:00
uint32_t GetFdsDiskSideSize(uint8_t side);
uint8_t ReadFdsDisk();
void WriteFdsDisk(uint8_t value);
2016-01-28 20:47:16 -05:00
2016-01-30 14:57:50 -05:00
void ClockIrq();
2016-01-28 20:47:16 -05:00
2016-01-30 14:57:50 -05:00
void ProcessCpuClock();
void UpdateCrc(uint8_t value);
2016-01-28 20:47:16 -05:00
2016-01-30 14:57:50 -05:00
bool IsDiskInserted();
2016-01-28 20:47:16 -05:00
2016-01-30 14:57:50 -05:00
void WriteRegister(uint16_t addr, uint8_t value);
uint8_t ReadRegister(uint16_t addr);
2016-01-28 20:47:16 -05:00
uint8_t ReadRAM(uint16_t addr);
2016-01-30 14:57:50 -05:00
void StreamState(bool saving);
2016-01-28 20:47:16 -05:00
public:
2016-01-30 14:57:50 -05:00
FDS();
~FDS();
2016-01-28 20:47:16 -05:00
2016-01-30 14:57:50 -05:00
static uint32_t GetSideCount();
2016-01-28 20:47:16 -05:00
2016-01-30 14:57:50 -05:00
static void InsertDisk(uint32_t diskNumber);
static void SwitchDiskSide();
static void EjectDisk();
2016-01-28 20:47:16 -05:00
};