1 #pragma once
2 
3 #include "Types.h"
4 #include "zip/ZipArchiveWriter.h"
5 #include "zip/ZipArchiveReader.h"
6 #include "../gs/GSHandler.h"
7 #include "../Profiler.h"
8 
9 class CGIF
10 {
11 public:
12 	enum REGISTER
13 	{
14 		GIF_STAT = 0x10003020
15 	};
16 
17 	enum
18 	{
19 		GIF_STAT_M3P = 0x002,
20 		GIF_STAT_APATH3 = 0xC00,
21 	};
22 
23 	enum
24 	{
25 		REGS_START = 0x10003000,
26 		REGS_END = 0x100030B0,
27 	};
28 
29 	struct TAG
30 	{
31 		unsigned int loops : 15;
32 		unsigned int eop : 1;
33 		unsigned int reserved0 : 16;
34 		unsigned int reserved1 : 14;
35 		unsigned int pre : 1;
36 		unsigned int prim : 11;
37 		unsigned int cmd : 2;
38 		unsigned int nreg : 4;
39 		uint64 regs;
40 	};
41 	static_assert(sizeof(TAG) == 0x10, "Size of TAG must be 16 bytes.");
42 
43 	CGIF(CGSHandler*&, uint8*, uint8*);
44 	virtual ~CGIF() = default;
45 
46 	void Reset();
47 	uint32 ReceiveDMA(uint32, uint32, uint32, bool);
48 
49 	uint32 ProcessSinglePacket(const uint8*, uint32, uint32, uint32, const CGsPacketMetadata&);
50 	uint32 ProcessMultiplePackets(const uint8*, uint32, uint32, uint32, const CGsPacketMetadata&);
51 
52 	uint32 GetRegister(uint32);
53 	void SetRegister(uint32, uint32);
54 
55 	CGSHandler* GetGsHandler();
56 
57 	void SetPath3Masked(bool);
58 
59 	void LoadState(Framework::CZipArchiveReader&);
60 	void SaveState(Framework::CZipArchiveWriter&);
61 
62 private:
63 	enum SIGNAL_STATE
64 	{
65 		SIGNAL_STATE_NONE,
66 		SIGNAL_STATE_ENCOUNTERED,
67 		SIGNAL_STATE_PENDING,
68 	};
69 
70 	uint32 ProcessPacked(const uint8*, uint32, uint32);
71 	uint32 ProcessRegList(const uint8*, uint32, uint32);
72 	uint32 ProcessImage(const uint8*, uint32, uint32, uint32);
73 
74 	void DisassembleGet(uint32);
75 	void DisassembleSet(uint32, uint32);
76 
77 	bool m_path3Masked = false;
78 	uint32 m_activePath = 0;
79 
80 	uint16 m_loops = 0;
81 	uint8 m_cmd = 0;
82 	uint8 m_regs = 0;
83 	uint8 m_regsTemp = 0;
84 	uint64 m_regList = 0;
85 	bool m_eop = false;
86 	uint32 m_qtemp;
87 	SIGNAL_STATE m_signalState = SIGNAL_STATE_NONE;
88 	uint8* m_ram;
89 	uint8* m_spr;
90 	CGSHandler*& m_gs;
91 
92 	CProfiler::ZoneHandle m_gifProfilerZone = 0;
93 };
94