2022-12-04 11:03:45 +00:00
|
|
|
// SPDX-FileCopyrightText: 2019-2022 Connor McLaughlin <stenzek@gmail.com> and contributors.
|
|
|
|
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0)
|
|
|
|
|
2021-01-21 07:59:40 +00:00
|
|
|
#pragma once
|
|
|
|
#include "common/types.h"
|
|
|
|
#include "controller.h"
|
|
|
|
#include "memory_card.h"
|
2022-07-08 12:43:38 +00:00
|
|
|
#include "util/state_wrapper.h"
|
2021-01-21 07:59:40 +00:00
|
|
|
#include <array>
|
|
|
|
|
|
|
|
class Multitap final
|
|
|
|
{
|
|
|
|
public:
|
2021-03-01 22:59:59 +00:00
|
|
|
Multitap();
|
2021-01-21 07:59:40 +00:00
|
|
|
|
|
|
|
void Reset();
|
|
|
|
|
2021-03-01 22:59:59 +00:00
|
|
|
void SetEnable(bool enable, u32 base_index);
|
2021-01-21 07:59:40 +00:00
|
|
|
ALWAYS_INLINE bool IsEnabled() const { return m_enabled; };
|
|
|
|
|
|
|
|
bool DoState(StateWrapper& sw);
|
|
|
|
|
|
|
|
void ResetTransferState();
|
|
|
|
bool Transfer(const u8 data_in, u8* data_out);
|
2021-03-01 22:59:59 +00:00
|
|
|
ALWAYS_INLINE bool IsReadingMemoryCard() { return IsEnabled() && m_transfer_state == TransferState::MemoryCard; };
|
2021-01-21 07:59:40 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
ALWAYS_INLINE static constexpr u8 GetMultitapIDByte() { return 0x80; };
|
|
|
|
ALWAYS_INLINE static constexpr u8 GetStatusByte() { return 0x5A; };
|
|
|
|
|
|
|
|
bool TransferController(u32 slot, const u8 data_in, u8* data_out) const;
|
|
|
|
bool TransferMemoryCard(u32 slot, const u8 data_in, u8* data_out) const;
|
|
|
|
|
|
|
|
enum class TransferState : u8
|
|
|
|
{
|
|
|
|
Idle,
|
|
|
|
MemoryCard,
|
|
|
|
ControllerCommand,
|
|
|
|
SingleController,
|
|
|
|
AllControllers
|
|
|
|
};
|
|
|
|
|
|
|
|
TransferState m_transfer_state = TransferState::Idle;
|
|
|
|
u8 m_selected_slot = 0;
|
|
|
|
|
|
|
|
u32 m_controller_transfer_step = 0;
|
|
|
|
|
|
|
|
bool m_invalid_transfer_all_command = false;
|
|
|
|
bool m_transfer_all_controllers = false;
|
|
|
|
bool m_current_controller_done = false;
|
|
|
|
|
|
|
|
std::array<u8, 32> m_transfer_buffer{};
|
|
|
|
|
2021-03-01 22:59:59 +00:00
|
|
|
u32 m_base_index;
|
2021-01-21 07:59:40 +00:00
|
|
|
bool m_enabled = false;
|
|
|
|
};
|