1 // license:BSD-3-Clause
2 // copyright-holders:Ryan Holtz
3 /******************************************************************************
4 *
5 *   Sony Playstation 2 Vector Unit device skeleton
6 *
7 *   To Do:
8 *     Everything
9 *
10 */
11 
12 #ifndef MAME_CPU_MIPS_PS2VU_H
13 #define MAME_CPU_MIPS_PS2VU_H
14 
15 #pragma once
16 
17 class sonyvu0_device;
18 class sonyvu1_device;
19 
20 #include "video/ps2gs.h"
21 #include "ps2vif1.h"
22 
23 enum
24 {
25 	SONYVU_TPC,
26 	SONYVU_SF,
27 	SONYVU_MF,
28 	SONYVU_CF,
29 	SONYVU_R,
30 	SONYVU_I,
31 	SONYVU_Q,
32 	SONYVU_ACCx,  SONYVU_ACCy,  SONYVU_ACCz,  SONYVU_ACCw,
33 	SONYVU_VF00x, SONYVU_VF00y, SONYVU_VF00z, SONYVU_VF00w,
34 	SONYVU_VF01x, SONYVU_VF01y, SONYVU_VF01z, SONYVU_VF01w,
35 	SONYVU_VF02x, SONYVU_VF02y, SONYVU_VF02z, SONYVU_VF02w,
36 	SONYVU_VF03x, SONYVU_VF03y, SONYVU_VF03z, SONYVU_VF03w,
37 	SONYVU_VF04x, SONYVU_VF04y, SONYVU_VF04z, SONYVU_VF04w,
38 	SONYVU_VF05x, SONYVU_VF05y, SONYVU_VF05z, SONYVU_VF05w,
39 	SONYVU_VF06x, SONYVU_VF06y, SONYVU_VF06z, SONYVU_VF06w,
40 	SONYVU_VF07x, SONYVU_VF07y, SONYVU_VF07z, SONYVU_VF07w,
41 	SONYVU_VF08x, SONYVU_VF08y, SONYVU_VF08z, SONYVU_VF08w,
42 	SONYVU_VF09x, SONYVU_VF09y, SONYVU_VF09z, SONYVU_VF09w,
43 	SONYVU_VF10x, SONYVU_VF10y, SONYVU_VF10z, SONYVU_VF10w,
44 	SONYVU_VF11x, SONYVU_VF11y, SONYVU_VF11z, SONYVU_VF11w,
45 	SONYVU_VF12x, SONYVU_VF12y, SONYVU_VF12z, SONYVU_VF12w,
46 	SONYVU_VF13x, SONYVU_VF13y, SONYVU_VF13z, SONYVU_VF13w,
47 	SONYVU_VF14x, SONYVU_VF14y, SONYVU_VF14z, SONYVU_VF14w,
48 	SONYVU_VF15x, SONYVU_VF15y, SONYVU_VF15z, SONYVU_VF15w,
49 	SONYVU_VF16x, SONYVU_VF16y, SONYVU_VF16z, SONYVU_VF16w,
50 	SONYVU_VF17x, SONYVU_VF17y, SONYVU_VF17z, SONYVU_VF17w,
51 	SONYVU_VF18x, SONYVU_VF18y, SONYVU_VF18z, SONYVU_VF18w,
52 	SONYVU_VF19x, SONYVU_VF19y, SONYVU_VF19z, SONYVU_VF19w,
53 	SONYVU_VF20x, SONYVU_VF20y, SONYVU_VF20z, SONYVU_VF20w,
54 	SONYVU_VF21x, SONYVU_VF21y, SONYVU_VF21z, SONYVU_VF21w,
55 	SONYVU_VF22x, SONYVU_VF22y, SONYVU_VF22z, SONYVU_VF22w,
56 	SONYVU_VF23x, SONYVU_VF23y, SONYVU_VF23z, SONYVU_VF23w,
57 	SONYVU_VF24x, SONYVU_VF24y, SONYVU_VF24z, SONYVU_VF24w,
58 	SONYVU_VF25x, SONYVU_VF25y, SONYVU_VF25z, SONYVU_VF25w,
59 	SONYVU_VF26x, SONYVU_VF26y, SONYVU_VF26z, SONYVU_VF26w,
60 	SONYVU_VF27x, SONYVU_VF27y, SONYVU_VF27z, SONYVU_VF27w,
61 	SONYVU_VF28x, SONYVU_VF28y, SONYVU_VF28z, SONYVU_VF28w,
62 	SONYVU_VF29x, SONYVU_VF29y, SONYVU_VF29z, SONYVU_VF29w,
63 	SONYVU_VF30x, SONYVU_VF30y, SONYVU_VF30z, SONYVU_VF30w,
64 	SONYVU_VF31x, SONYVU_VF31y, SONYVU_VF31z, SONYVU_VF31w,
65 	SONYVU_VI00,  SONYVU_VI01,  SONYVU_VI02,  SONYVU_VI03,
66 	SONYVU_VI04,  SONYVU_VI05,  SONYVU_VI06,  SONYVU_VI07,
67 	SONYVU_VI08,  SONYVU_VI09,  SONYVU_VI10,  SONYVU_VI11,
68 	SONYVU_VI12,  SONYVU_VI13,  SONYVU_VI14,  SONYVU_VI15,
69 
70 	SONYVU0_VPU_STAT,
71 	SONYVU0_FBRST,
72 	SONYVU0_CMSAR0,
73 	SONYVU0_CMSAR1,
74 
75 	SONYVU1_P = SONYVU0_VPU_STAT
76 };
77 
78 class sonyvu_device : public cpu_device
79 {
80 public:
81 	// construction/destruction
~sonyvu_device()82 	virtual ~sonyvu_device() {}
83 
84 	void write_vu_mem(uint32_t address, uint32_t data);
85 	void write_micro_mem(uint32_t address, uint64_t data);
vector_regs()86 	float* vector_regs() { return m_v; }
micro_mem()87 	uint64_t *micro_mem() { return &m_micro_mem[0]; }
vu_mem()88 	uint32_t *vu_mem() { return &m_vu_mem[0]; }
mem_mask()89 	uint32_t mem_mask() const { return m_mem_mask; }
90 
running()91 	bool running() const { return m_running; }
92 	void start(uint32_t address);
93 
94 protected:
95 	enum chip_type
96 	{
97 		CHIP_TYPE_VU0,
98 		CHIP_TYPE_VU1,
99 	};
100 
101 	sonyvu_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock, address_map_constructor micro_cons, address_map_constructor vu_cons, chip_type chiptype, uint32_t mem_size);
102 
103 	enum : uint64_t
104 	{
105 		OP_UPPER_I = 0x8000000000000000ULL,
106 		OP_UPPER_E = 0x4000000000000000ULL,
107 		OP_UPPER_M = 0x2000000000000000ULL,
108 		OP_UPPER_D = 0x1000000000000000ULL,
109 		OP_UPPER_T = 0x0800000000000000ULL
110 	};
111 
112 	// device-level overrides
113 	virtual void device_start() override;
114 	virtual void device_reset() override;
115 
116 	// device_execute_interface overrides
execute_min_cycles()117 	virtual uint32_t execute_min_cycles() const noexcept override { return 1; }
execute_max_cycles()118 	virtual uint32_t execute_max_cycles() const noexcept override { return 1; }
execute_input_lines()119 	virtual uint32_t execute_input_lines() const noexcept override { return 0; }
120 	virtual void execute_run() override;
execute_set_input(int inputnum,int state)121 	virtual void execute_set_input(int inputnum, int state) override { }
122 
123 	// device_memory_interface overrides
124 	virtual space_config_vector memory_space_config() const override;
125 
126 	// device_state_interface overrides
127 	virtual void state_import(const device_state_entry &entry) override;
128 	virtual void state_export(const device_state_entry &entry) override;
129 	virtual void state_string_export(const device_state_entry &entry, std::string &str) const override;
130 
131 	// device_disasm_interface overrides
132 	virtual std::unique_ptr<util::disasm_interface> create_disassembler() override;
133 
134 	void execute_upper(const uint32_t op);
135 	void execute_lower(const uint32_t op);
136 
137 	virtual void execute_xgkick(uint32_t rs) = 0;
138 
139 	static int16_t immediate_s11(const uint32_t op);
140 
141 	// address spaces
142 	const address_space_config m_micro_config;
143 	const address_space_config m_vu_config;
144 	address_space   *m_micro_space;
145 	address_space   *m_vu_space;
146 
147 	// core registers
148 	uint32_t        m_mem_size;
149 	uint32_t        m_mem_mask;
150 	required_shared_ptr<uint64_t> m_micro_mem;
151 	required_shared_ptr<uint32_t> m_vu_mem;
152 	float*          m_vfmem;
153 	uint32_t*       m_vimem;
154 
155 	float           m_vfr[32][4]; // 0..3 = x..w
156 	uint32_t        m_vcr[32];
157 	float           m_acc[4];
158 
159 	float*          m_v;
160 
161 	uint32_t        m_status_flag;
162 	uint32_t        m_mac_flag;
163 	uint32_t        m_clip_flag;
164 	uint32_t        m_r;
165 	float           m_i;
166 	float           m_q;
167 
168 	uint32_t        m_pc;
169 	uint32_t        m_delay_pc;
170 	uint32_t        m_start_pc;
171 
172 	bool            m_running;
173 
174 	int             m_icount;
175 };
176 
177 class sonyvu1_device : public sonyvu_device
178 {
179 public:
180 	template <typename T>
sonyvu1_device(const machine_config & mconfig,const char * tag,device_t * owner,uint32_t clock,T && gs_tag)181 	sonyvu1_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock, T &&gs_tag)
182 		: sonyvu1_device(mconfig, tag, owner, clock)
183 	{
184 		m_gs.set_tag(std::forward<T>(gs_tag));
185 	}
186 
187 	sonyvu1_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
188 
189 	ps2_vif1_device* interface();
190 
191 	uint64_t vif_r(offs_t offset);
192 	void vif_w(offs_t offset, uint64_t data);
193 
194 protected:
195 	virtual void device_start() override;
196 	virtual void device_reset() override;
197 	virtual void device_add_mconfig(machine_config &config) override;
198 
199 	virtual void state_string_export(const device_state_entry &entry, std::string &str) const override;
200 
201 	void micro_map(address_map &map);
202 	void vu_map(address_map &map);
203 
204 	void execute_xgkick(uint32_t rs) override;
205 
206 	required_device<ps2_gs_device> m_gs;
207 	required_device<ps2_vif1_device> m_vif;
208 
209 	float m_p;
210 };
211 
212 class sonyvu0_device : public sonyvu_device
213 {
214 public:
215 	template <typename T>
sonyvu0_device(const machine_config & mconfig,const char * tag,device_t * owner,uint32_t clock,T && vu1_tag)216 	sonyvu0_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock, T &&vu1_tag)
217 		: sonyvu0_device(mconfig, tag, owner, clock)
218 	{
219 		m_vu1.set_tag(std::forward<T>(vu1_tag));
220 	}
221 
222 	sonyvu0_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
223 
224 protected:
225 	virtual void device_start() override;
226 	virtual void device_reset() override;
227 
228 	void micro_map(address_map &map);
229 	void vu_map(address_map &map);
230 
231 	void execute_xgkick(uint32_t rs) override;
232 
233 	uint32_t vu1_reg_r(offs_t offset);
234 	void vu1_reg_w(offs_t offset, uint32_t data);
235 
236 	required_device<sonyvu1_device> m_vu1;
237 
238 	float*          m_vu1_regs;
239 	uint32_t        m_control;
240 	uint32_t        m_vpu_stat;
241 	uint32_t        m_cmsar0;
242 	uint32_t        m_cmsar1;
243 };
244 
245 DECLARE_DEVICE_TYPE(SONYPS2_VU1, sonyvu1_device)
246 DECLARE_DEVICE_TYPE(SONYPS2_VU0, sonyvu0_device)
247 
248 #endif // MAME_CPU_MIPS_PS2VU_H
249