Duckstation/src/core/memory_card.h
Connor McLaughlin b6f871d2b9
JIT optimizations and refactoring (#675)
* CPU/Recompiler: Use rel32 call where possible for no-args

* JitCodeBuffer: Support using preallocated buffer

* CPU/Recompiler/AArch64: Use bl instead of blr for short branches

* CPU/CodeCache: Allocate recompiler buffer in program space

This means we don't need 64-bit moves for every call out of the
recompiler.

* GTE: Don't store as u16 and load as u32

* CPU/Recompiler: Add methods to emit global load/stores

* GTE: Convert class to namespace

* CPU/Recompiler: Call GTE functions directly

* Settings: Turn into a global variable

* GPU: Replace local pointers with global

* InterruptController: Turn into a global pointer

* System: Replace local pointers with global

* Timers: Turn into a global instance

* DMA: Turn into a global instance

* SPU: Turn into a global instance

* CDROM: Turn into a global instance

* MDEC: Turn into a global instance

* Pad: Turn into a global instance

* SIO: Turn into a global instance

* CDROM: Move audio FIFO to the heap

* CPU/Recompiler: Drop ASMFunctions

No longer needed since we have code in the same 4GB window.

* CPUCodeCache: Turn class into namespace

* Bus: Local pointer -> global pointers

* CPU: Turn class into namespace

* Bus: Turn into namespace

* GTE: Store registers in CPU state struct

Allows relative addressing on ARM.

* CPU/Recompiler: Align code storage to page size

* CPU/Recompiler: Fix relative branches on A64

* HostInterface: Local references to global

* System: Turn into a namespace, move events out

* Add guard pages

* Android: Fix build
2020-07-31 17:09:18 +10:00

101 lines
1.8 KiB
C++

#pragma once
#include "common/bitfield.h"
#include "controller.h"
#include <array>
#include <memory>
#include <string>
#include <string_view>
class TimingEvent;
class MemoryCard final
{
public:
enum : u32
{
DATA_SIZE = 128 * 1024, // 1mbit
SECTOR_SIZE = 128,
NUM_SECTORS = DATA_SIZE / SECTOR_SIZE
};
MemoryCard();
~MemoryCard();
static std::unique_ptr<MemoryCard> Create();
static std::unique_ptr<MemoryCard> Open(std::string_view filename);
void Reset();
bool DoState(StateWrapper& sw);
void ResetTransferState();
bool Transfer(const u8 data_in, u8* data_out);
void Format();
private:
enum : u32
{
// save in three seconds, that should be long enough for everything to finish writing
SAVE_DELAY_IN_SECONDS = 5,
SAVE_DELAY_IN_SYSCLK_TICKS = MASTER_CLOCK * SAVE_DELAY_IN_SECONDS,
};
union FLAG
{
u8 bits;
BitField<u8, bool, 3, 1> no_write_yet;
BitField<u8, bool, 2, 1> write_error;
};
enum class State : u8
{
Idle,
Command,
ReadCardID1,
ReadCardID2,
ReadAddressMSB,
ReadAddressLSB,
ReadACK1,
ReadACK2,
ReadConfirmAddressMSB,
ReadConfirmAddressLSB,
ReadData,
ReadChecksum,
ReadEnd,
WriteCardID1,
WriteCardID2,
WriteAddressMSB,
WriteAddressLSB,
WriteData,
WriteChecksum,
WriteACK1,
WriteACK2,
WriteEnd,
};
static u8 ChecksumFrame(const u8* fptr);
u8* GetSectorPtr(u32 sector);
bool LoadFromFile();
bool SaveIfChanged(bool display_osd_message);
void QueueFileSave();
std::unique_ptr<TimingEvent> m_save_event;
State m_state = State::Idle;
FLAG m_FLAG = {};
u16 m_address = 0;
u8 m_sector_offset = 0;
u8 m_checksum = 0;
u8 m_last_byte = 0;
bool m_changed = false;
std::array<u8, DATA_SIZE> m_data{};
std::string m_filename;
};