1 #pragma once
2 
3 #include "Types.h"
4 #include "../MIPS.h"
5 #include "../Profiler.h"
6 #include "Convertible.h"
7 #include "zip/ZipArchiveWriter.h"
8 #include "zip/ZipArchiveReader.h"
9 
10 class CVif;
11 class CGIF;
12 class CINTC;
13 
14 class CVpu
15 {
16 public:
17 	enum VU1REGISTERS
18 	{
19 		VU_TOP = 0x8400,
20 		VU_XGKICK = 0x8410,
21 		VU_ITOP = 0x8420,
22 		VU_CMSAR1 = 0x1000FFC0, //This is meant to be used by the EE through CTC2
23 	};
24 
25 	struct VPUINIT
26 	{
VPUINITVPUINIT27 		VPUINIT(uint8* microMem, uint8* vuMem, CMIPS* context)
28 		    : microMem(microMem)
29 		    , vuMem(vuMem)
30 		    , context(context)
31 		{
32 		}
33 
34 		uint8* microMem;
35 		uint8* vuMem;
36 		CMIPS* context;
37 	};
38 
39 	typedef Framework::CSignal<void(bool)> VuStateChangedEvent;
40 
41 	CVpu(unsigned int, const VPUINIT&, CGIF&, CINTC&, uint8*, uint8*);
42 	virtual ~CVpu();
43 
44 	void Execute(int32);
45 	void Reset();
46 	void SaveState(Framework::CZipArchiveWriter&);
47 	void LoadState(Framework::CZipArchiveReader&);
48 
49 	CMIPS& GetContext() const;
50 	uint8* GetMicroMemory() const;
51 	uint32 GetMicroMemorySize() const;
52 	uint8* GetVuMemory() const;
53 	uint32 GetVuMemorySize() const;
54 	bool IsVuRunning() const;
55 
56 	CVif& GetVif();
57 
58 	void ExecuteMicroProgram(uint32);
59 	void InvalidateMicroProgram();
60 	void InvalidateMicroProgram(uint32, uint32);
61 
62 	void ProcessXgKick(uint32);
63 
64 #ifdef DEBUGGER_INCLUDED
65 	void SaveMiniState();
66 	const MIPSSTATE& GetVuMiniState() const;
67 	uint8* GetVuMemoryMiniState() const;
68 	uint8* GetMicroMemoryMiniState() const;
69 	uint32 GetVuTopMiniState() const;
70 	uint32 GetVuItopMiniState() const;
71 #endif
72 
73 	VuStateChangedEvent VuStateChanged;
74 
75 protected:
76 	typedef std::unique_ptr<CVif> VifPtr;
77 
78 	uint8* m_microMem = nullptr;
79 	uint32 m_microMemSize = 0;
80 	uint8* m_vuMem = nullptr;
81 	uint32 m_vuMemSize = 0;
82 	CMIPS* m_ctx = nullptr;
83 	CGIF& m_gif;
84 	VifPtr m_vif;
85 
86 #ifdef DEBUGGER_INCLUDED
87 	MIPSSTATE m_vuMiniState;
88 	uint8* m_microMemMiniState;
89 	uint8* m_vuMemMiniState;
90 	uint32 m_topMiniState;
91 	uint32 m_itopMiniState;
92 #endif
93 
94 	unsigned int m_number = 0;
95 	bool m_running = false;
96 
97 	CProfiler::ZoneHandle m_vuProfilerZone = 0;
98 };
99