1 // Copyright 2008 Dolphin Emulator Project 2 // Licensed under GPLv2+ 3 // Refer to the license.txt file included. 4 5 #pragma once 6 7 #include <array> 8 #include <string> 9 10 #include "Common/BitUtils.h" 11 #include "Core/HW/EXI/EXI_Device.h" 12 13 class PointerWrap; 14 15 namespace ExpansionInterface 16 { 17 class CEXIIPL : public IEXIDevice 18 { 19 public: 20 CEXIIPL(); 21 ~CEXIIPL() override; 22 23 void SetCS(int cs) override; 24 bool IsPresent() const override; 25 void DoState(PointerWrap& p) override; 26 27 static constexpr u32 UNIX_EPOCH = 0; // 1970-01-01 00:00:00 28 static constexpr u32 GC_EPOCH = 0x386D4380; // 2000-01-01 00:00:00 29 30 static u32 GetEmulatedTime(u32 epoch); 31 static u64 NetPlay_GetEmulatedTime(); 32 33 static void Descrambler(u8* data, u32 size); 34 35 static bool HasIPLDump(); 36 37 private: 38 std::unique_ptr<u8[]> m_rom; 39 40 // TODO these ranges are highly suspect 41 enum 42 { 43 ROM_BASE = 0, 44 ROM_SIZE = 0x200000, 45 SRAM_BASE = 0x800000, 46 SRAM_SIZE = 0x44, 47 UART_BASE = 0x800400, 48 UART_SIZE = 0x50, 49 WII_RTC_BASE = 0x840000, 50 WII_RTC_SIZE = 0x40, 51 EUART_BASE = 0xc00000, 52 EUART_SIZE = 8, 53 }; 54 55 struct 56 { is_write__anone674329c020857 bool is_write() const { return (value >> 31) & 1; } 58 // TODO this is definitely a guess 59 // Also, the low 6 bits are completely ignored address__anone674329c020860 u32 address() const { return (value >> 6) & 0x1ffffff; } low_bits__anone674329c020861 u32 low_bits() const { return value & 0x3f; } 62 u32 value; 63 } m_command{}; 64 u32 m_command_bytes_received{}; 65 // Technically each device has it's own state, but we assume the selected 66 // device will not change without toggling cs, and that each device has at 67 // most 1 interesting position to keep track of. 68 u32 m_cursor{}; 69 70 std::string m_buffer; 71 bool m_fonts_loaded{}; 72 73 void UpdateRTC(); 74 75 void TransferByte(u8& data) override; 76 77 bool LoadFileToIPL(const std::string& filename, u32 offset); 78 void LoadFontFile(const std::string& filename, u32 offset); 79 80 static std::string FindIPLDump(const std::string& path_prefix); 81 }; 82 83 // Used to indicate disc changes on the Wii, as insane as that sounds. 84 // However, the name is definitely RTCFlag, as the code that gets it is __OSGetRTCFlags and 85 // __OSClearRTCFlags in OSRtc.o (based on symbols from Kirby's Dream Collection) 86 // This may simply be a single byte that gets repeated 4 times by some EXI quirk, 87 // as reading it gives the value repeated 4 times but code only checks the first bit. 88 enum class RTCFlag : u32 89 { 90 EjectButton = 0x01010101, 91 DiscChanged = 0x02020202, 92 }; 93 94 extern Common::Flags<RTCFlag> g_rtc_flags; 95 } // namespace ExpansionInterface 96