1 // license:BSD-3-Clause 2 // copyright-holders:David Haywood 3 #ifndef MAME_VIDEO_K001005_H 4 #define MAME_VIDEO_K001005_H 5 6 #pragma once 7 8 #include "video/poly.h" 9 #include "cpu/sharc/sharc.h" 10 #include "video/k001006.h" 11 12 #include <cfloat> 13 14 15 struct k001005_polydata 16 { 17 uint32_t color; 18 int texture_x, texture_y; 19 int texture_width, texture_height; 20 int texture_page; 21 int texture_palette; 22 int texture_mirror_x; 23 int texture_mirror_y; 24 int light_r, light_g, light_b; 25 int ambient_r, ambient_g, ambient_b; 26 int fog_r, fog_g, fog_b; 27 uint32_t flags; 28 }; 29 30 enum k001005_param 31 { 32 K001005_LIGHT_R, 33 K001005_LIGHT_G, 34 K001005_LIGHT_B, 35 K001005_AMBIENT_R, 36 K001005_AMBIENT_G, 37 K001005_AMBIENT_B, 38 K001005_FOG_R, 39 K001005_FOG_G, 40 K001005_FOG_B, 41 K001005_FAR_Z 42 }; 43 44 45 class k001005_renderer : public poly_manager<float, k001005_polydata, 8, 50000> 46 { 47 public: 48 k001005_renderer(device_t &parent, screen_device &screen, device_t *k001006); 49 50 void reset(); 51 void push_data(uint32_t data); 52 void render_polygons(); 53 void swap_buffers(); 54 bool fifo_filled(); 55 void draw(bitmap_rgb32 &bitmap, const rectangle &cliprect); 56 void set_param(k001005_param param, uint32_t value); 57 58 void draw_scanline_2d(int32_t scanline, const extent_t &extent, const k001005_polydata &extradata, int threadid); 59 void draw_scanline_2d_tex(int32_t scanline, const extent_t &extent, const k001005_polydata &extradata, int threadid); 60 void draw_scanline(int32_t scanline, const extent_t &extent, const k001005_polydata &extradata, int threadid); 61 void draw_scanline_tex(int32_t scanline, const extent_t &extent, const k001005_polydata &extradata, int threadid); 62 void draw_scanline_gouraud_blend(int32_t scanline, const extent_t &extent, const k001005_polydata &extradata, int threadid); 63 64 static constexpr int POLY_Z = 0; 65 static constexpr int POLY_FOG = 1; 66 static constexpr int POLY_BRI = 2; 67 static constexpr int POLY_U = 3; 68 static constexpr int POLY_V = 4; 69 static constexpr int POLY_W = 5; 70 static constexpr int POLY_A = 2; 71 static constexpr int POLY_R = 3; 72 static constexpr int POLY_G = 4; 73 static constexpr int POLY_B = 5; 74 75 private: 76 std::unique_ptr<bitmap_rgb32> m_fb[2]; 77 std::unique_ptr<bitmap_ind32> m_zb; 78 rectangle m_cliprect; 79 int m_fb_page; 80 81 std::unique_ptr<uint32_t[]> m_3dfifo; 82 int m_3dfifo_ptr; 83 84 vertex_t m_prev_v[4]; 85 86 uint32_t m_light_r; 87 uint32_t m_light_g; 88 uint32_t m_light_b; 89 uint32_t m_ambient_r; 90 uint32_t m_ambient_g; 91 uint32_t m_ambient_b; 92 uint32_t m_fog_r; 93 uint32_t m_fog_g; 94 uint32_t m_fog_b; 95 float m_far_z; 96 97 device_t *m_k001006; 98 99 std::unique_ptr<int[]> m_tex_mirror_table[2][8]; 100 }; 101 102 103 class k001005_device : public device_t, public device_video_interface 104 { 105 public: 106 k001005_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock); 107 k001005_device(const machine_config & mconfig,const char * tag,device_t * owner,uint32_t clock,T && texel_tag)108 template <typename T> k001005_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock, T &&texel_tag) 109 : k001005_device(mconfig, tag, owner, clock) 110 { 111 set_texel_tag(std::forward<T>(texel_tag)); 112 } 113 114 set_texel_tag(T && tag)115 template <typename T> void set_texel_tag(T &&tag) { m_k001006.set_tag(std::forward<T>(tag)); } 116 117 void draw(bitmap_rgb32 &bitmap, const rectangle &cliprect); 118 void swap_buffers(); 119 120 uint32_t read(address_space &space, offs_t offset, uint32_t mem_mask = ~0); 121 void write(address_space &space, offs_t offset, uint32_t data, uint32_t mem_mask = ~0); 122 123 protected: 124 // device-level overrides 125 virtual void device_start() override; 126 virtual void device_stop() override; 127 virtual void device_reset() override; 128 129 private: 130 // internal state 131 optional_device<k001006_device> m_k001006; 132 133 std::unique_ptr<uint16_t[]> m_ram[2]; 134 std::unique_ptr<uint32_t[]> m_fifo; 135 uint32_t m_status; 136 137 int m_ram_ptr; 138 int m_fifo_read_ptr; 139 int m_fifo_write_ptr; 140 uint32_t m_reg_far_z; 141 142 143 k001005_renderer *m_renderer; 144 }; 145 146 DECLARE_DEVICE_TYPE(K001005, k001005_device) 147 148 #endif // MAME_VIDEO_K001005_H 149