duckstation

duckstation, but archived from the revision just before upstream changed it to a proprietary software project, this version is the libre one
git clone https://git.neptards.moe/u3shit/duckstation.git
Log | Files | Refs | README | LICENSE

multitap.h (1423B)


      1 // SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com> and contributors.
      2 // SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0)
      3 
      4 #pragma once
      5 
      6 #include "controller.h"
      7 
      8 #include "common/types.h"
      9 
     10 #include <array>
     11 
     12 class Multitap final
     13 {
     14 public:
     15   Multitap();
     16 
     17   void Reset();
     18 
     19   void SetEnable(bool enable, u32 base_index);
     20   ALWAYS_INLINE bool IsEnabled() const { return m_enabled; };
     21 
     22   bool DoState(StateWrapper& sw);
     23 
     24   void ResetTransferState();
     25   bool Transfer(const u8 data_in, u8* data_out);
     26   ALWAYS_INLINE bool IsReadingMemoryCard() { return IsEnabled() && m_transfer_state == TransferState::MemoryCard; };
     27 
     28 private:
     29   ALWAYS_INLINE static constexpr u8 GetMultitapIDByte() { return 0x80; };
     30   ALWAYS_INLINE static constexpr u8 GetStatusByte() { return 0x5A; };
     31 
     32   bool TransferController(u32 slot, const u8 data_in, u8* data_out) const;
     33   bool TransferMemoryCard(u32 slot, const u8 data_in, u8* data_out) const;
     34 
     35   enum class TransferState : u8
     36   {
     37     Idle,
     38     MemoryCard,
     39     ControllerCommand,
     40     SingleController,
     41     AllControllers
     42   };
     43 
     44   TransferState m_transfer_state = TransferState::Idle;
     45   u8 m_selected_slot = 0;
     46 
     47   u32 m_controller_transfer_step = 0;
     48 
     49   bool m_invalid_transfer_all_command = false;
     50   bool m_transfer_all_controllers = false;
     51   bool m_current_controller_done = false;
     52 
     53   std::array<u8, 32> m_transfer_buffer{};
     54 
     55   u32 m_base_index;
     56   bool m_enabled = false;
     57 };