1 // license:BSD-3-Clause 2 // copyright-holders:Ryan Holtz 3 /****************************************************************************** 4 * 5 * Sony Playstation 2 Graphics Synthesizer device skeleton 6 * 7 * To Do: 8 * Everything 9 * 10 */ 11 12 #ifndef MAME_VIDEO_PS2GS_H 13 #define MAME_VIDEO_PS2GS_H 14 15 #pragma once 16 17 class ps2_gs_device; 18 19 #include "ps2gif.h" 20 #include "machine/ps2intc.h" 21 #include "cpu/mips/ps2vu.h" 22 23 class ps2_gs_device : public device_t 24 { 25 public: 26 template <typename T, typename U> 27 ps2_gs_device(const machine_config & mconfig,const char * tag,device_t * owner,uint32_t clock,T && intc_tag,U && vu1_tag)28 ps2_gs_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock, T &&intc_tag, U &&vu1_tag) 29 : ps2_gs_device(mconfig, tag, owner, clock) 30 { 31 m_intc.set_tag(std::forward<T>(intc_tag)); 32 m_vu1.set_tag(std::forward<U>(vu1_tag)); 33 } 34 35 ps2_gs_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock); 36 virtual ~ps2_gs_device() override; 37 38 uint64_t priv_regs0_r(offs_t offset); 39 void priv_regs0_w(offs_t offset, uint64_t data); 40 uint64_t priv_regs1_r(offs_t offset); 41 void priv_regs1_w(offs_t offset, uint64_t data); 42 43 void regs_w(offs_t offset, uint64_t data); 44 45 uint32_t gif_r(offs_t offset); 46 void gif_w(offs_t offset, uint32_t data); 47 48 ps2_gif_device* interface(); 49 50 void reg_write(const uint8_t reg, const uint64_t value); 51 void write_packed(const uint8_t reg, const uint64_t hi, const uint64_t lo); 52 53 void vblank_start(); 54 void vblank_end(); 55 56 protected: 57 virtual void device_start() override; 58 virtual void device_reset() override; 59 virtual void device_add_mconfig(machine_config &config) override; 60 61 void copy_dword_from_host(uint64_t data); 62 63 enum : uint64_t 64 { 65 HOST_TO_LOCAL, 66 LOCAL_TO_HOST, 67 LOCAL_TO_LOCAL, 68 NO_TRANSFER 69 }; 70 71 enum : uint8_t 72 { 73 UL_TO_BR, 74 BL_TO_UR, 75 UR_TO_BL, 76 BR_TO_UL 77 }; 78 79 enum : uint8_t 80 { 81 PSMCT32 = 0x00, 82 PSMCT24 = 0x01, 83 PSMCT16 = 0x02, 84 PSMCT16S = 0x0a, 85 PSMT8 = 0x13, 86 PSMT4 = 0x14, 87 PSMT8H = 0x1b, 88 PSMT4HL = 0x24, 89 PSMT4HH = 0x2c, 90 PSMZ32 = 0x30, 91 PSMZ24 = 0x31, 92 PSMZ16 = 0x32, 93 PSMZ16S = 0x3a 94 }; 95 96 enum : uint8_t 97 { 98 ALPHA_FUNC_NEVER, 99 ALPHA_FUNC_ALWAYS, 100 ALPHA_FUNC_LESS, 101 ALPHA_FUNC_LEQUAL, 102 ALPHA_FUNC_EQUAL, 103 ALPHA_FUNC_GEQUAL, 104 ALPHA_FUNC_GREATER, 105 ALPHA_FUNC_NOTEQUAL 106 }; 107 108 enum : uint8_t 109 { 110 ALPHA_FAIL_KEEP, 111 ALPHA_FAIL_UPDATE_FB, 112 ALPHA_FAIL_UPDATE_ZB, 113 ALPHA_FAIL_UPDATE_RGB 114 }; 115 116 enum : uint8_t 117 { 118 DEPTH_FUNC_NEVER, 119 DEPTH_FUNC_ALWAYS, 120 DEPTH_FUNC_GEQUAL, 121 DEPTH_FUNC_GREATER 122 }; 123 124 enum : uint8_t 125 { 126 PRIM_TYPE_POINT, 127 PRIM_TYPE_LINE, 128 PRIM_TYPE_LINE_STRIP, 129 PRIM_TYPE_TRI, 130 PRIM_TYPE_TRI_STRIP, 131 PRIM_TYPE_TRI_FAN, 132 PRIM_TYPE_SPRITE, 133 PRIM_TYPE_INVALID 134 }; 135 136 enum : uint32_t 137 { 138 CSR_SIGNAL = 0x00000001, 139 CSR_FINISH = 0x00000002, 140 CSR_HSINT = 0x00000004, 141 CSR_VSINT = 0x00000008, 142 CSR_EDWINT = 0x00000010, 143 CSR_FLUSH = 0x00000100, 144 CSR_RESET = 0x00000200, 145 CSR_NFIELD = 0x00001000, 146 CSR_FIELD_ODD = 0x00002000, 147 CSR_FIFO_MASK = 0x0000c000, 148 CSR_FIFO_MID = 0x00000000, 149 CSR_FIFO_EMPTY = 0x00004000, 150 CSR_FIFO_HI = 0x00008000, 151 CSR_FIFO_INV = 0x0000c000, 152 CSR_REV = 0x001b0000, 153 CSR_ID = 0x55000000 154 }; 155 156 struct vertex_t 157 { 158 uint16_t m_x; 159 uint16_t m_y; 160 uint32_t m_z; 161 162 uint8_t m_r; 163 uint8_t m_g; 164 uint8_t m_b; 165 uint8_t m_a; 166 float m_q; 167 168 uint32_t m_us; 169 uint32_t m_vt; 170 171 uint8_t m_fog; 172 }; 173 174 required_device<ps2_intc_device> m_intc; 175 required_device<sonyvu1_device> m_vu1; 176 required_device<ps2_gif_device> m_gif; 177 178 std::unique_ptr<uint32_t[]> m_ram; 179 std::unique_ptr<vertex_t[]> m_vertices; 180 181 struct context_t 182 { 183 uint64_t m_xyoffset; // 0x18, 0x19 184 uint32_t m_offset_x; 185 uint32_t m_offset_y; 186 187 uint64_t m_scissor; // 0x40, 0x41 188 uint16_t m_scissor_x0; 189 uint16_t m_scissor_x1; 190 uint16_t m_scissor_y0; 191 uint16_t m_scissor_y1; 192 193 uint64_t m_test; // 0x47, 0x48 194 bool m_alpha_test; 195 uint8_t m_alpha_func; 196 uint8_t m_alpha_ref; 197 uint8_t m_alpha_fail; 198 bool m_dstalpha_test; 199 bool m_dstalpha_pass1; 200 bool m_depth_test; 201 uint8_t m_depth_func; 202 203 uint64_t m_frame; // 0x4c, 0x4d 204 uint32_t m_fb_base; 205 uint32_t m_fb_width; 206 uint8_t m_fb_format; 207 uint32_t m_fb_mask; 208 209 uint64_t m_zbuf; // 0x4e, 0x4f 210 uint32_t m_z_base; 211 uint8_t m_z_format; 212 bool m_z_mask; 213 }; 214 215 context_t m_context[2]; 216 217 uint64_t m_prim; // 0x00 218 uint8_t m_prim_type; 219 bool m_gouraud_enable; 220 bool m_texture_enable; 221 bool m_fog_enable; 222 bool m_blend_enable; 223 bool m_aa_enable; 224 bool m_no_perspective; 225 uint8_t m_curr_context; 226 bool m_fix_fragments; 227 228 uint64_t m_rgbaq; // 0x01 229 uint8_t m_vc_r; 230 uint8_t m_vc_g; 231 uint8_t m_vc_b; 232 uint8_t m_vc_a; 233 float m_q; 234 235 uint64_t m_prmodecont; // 0x1a 236 bool m_use_prim_for_attrs; 237 238 uint64_t m_dthe; // 0x45 239 bool m_dither; 240 241 uint64_t m_colclamp; // 0x46 242 bool m_clamp_color; 243 244 uint64_t m_bitbltbuf; // 0x50 245 uint32_t m_src_buf_base; 246 uint32_t m_src_buf_width; 247 uint8_t m_src_buf_fmt; 248 uint32_t m_dst_buf_base; 249 uint32_t m_dst_buf_width; 250 uint8_t m_dst_buf_fmt; 251 252 uint64_t m_trx_pos; // 0x51 253 uint32_t m_src_ul_x; 254 uint32_t m_src_ul_y; 255 uint32_t m_dst_ul_x; 256 uint32_t m_dst_ul_y; 257 uint8_t m_copy_dir; 258 259 uint64_t m_trx_reg; // 0x52 260 uint32_t m_trx_width; 261 uint32_t m_trx_height; 262 263 uint64_t m_trx_dir; // 0x53 264 265 // Privileged regs 266 uint64_t m_base_regs[15]; 267 268 uint64_t m_pmode; // Privileged 0x00 269 bool m_read_circuit_enable[2]; 270 bool m_use_fixed_alpha; 271 uint8_t m_alpha_out_select; 272 bool m_blend_to_background; 273 uint8_t m_fixed_alpha; 274 275 uint64_t m_smode2; // Privileged 0x02 276 bool m_interlace; 277 bool m_frame_interlace; 278 uint8_t m_dpms_mode; 279 280 uint64_t m_dispfb[2]; // Privileged 0x07, 0x09 281 uint32_t m_dispfb_base[2]; 282 uint32_t m_dispfb_width[2]; 283 uint8_t m_dispfb_format[2]; 284 uint32_t m_dispfb_x[2]; 285 uint32_t m_dispfb_y[2]; 286 287 uint64_t m_display[2]; // Privileged 0x08, 0x0a 288 uint32_t m_display_xpos[2]; 289 uint32_t m_display_ypos[2]; 290 uint8_t m_magh[2]; 291 uint8_t m_magv[2]; 292 uint32_t m_display_width[2]; 293 uint32_t m_display_height[2]; 294 295 uint64_t m_bgcolor; // Privileged 0x0e 296 uint8_t m_bg_r; 297 uint8_t m_bg_g; 298 uint8_t m_bg_b; 299 300 uint64_t m_csr; 301 uint64_t m_imr; 302 uint64_t m_busdir; 303 uint64_t m_sig_label_id; 304 305 uint32_t m_vertex_count; 306 uint32_t m_kick_count; 307 308 uint8_t m_curr_field; 309 310 static size_t const FORMAT_PIXEL_WIDTHS[0x40]; 311 static char const *const FORMAT_NAMES[0x40]; 312 static uint32_t const KICK_COUNTS[8]; 313 }; 314 315 DECLARE_DEVICE_TYPE(SONYPS2_GS, ps2_gs_device) 316 317 #endif // MAME_VIDEO_PS2GS_H 318