1 // license:BSD-3-Clause 2 // copyright-holders:Luca Elia 3 #ifndef MAME_INCLUDES_CAVE_H 4 #define MAME_INCLUDES_CAVE_H 5 6 #pragma once 7 8 /*************************************************************************** 9 10 Cave hardware 11 12 ***************************************************************************/ 13 14 #include "machine/eepromser.h" 15 #include "machine/gen_latch.h" 16 #include "machine/timer.h" 17 #include "sound/okim6295.h" 18 #include "video/tmap038.h" 19 #include "emupal.h" 20 #include "screen.h" 21 #include "tilemap.h" 22 23 class cave_state : public driver_device 24 { 25 public: cave_state(const machine_config & mconfig,device_type type,const char * tag)26 cave_state(const machine_config &mconfig, device_type type, const char *tag) 27 : driver_device(mconfig, type, tag) 28 , m_videoregs(*this, "videoregs.%u", 0) 29 , m_spriteram(*this, "spriteram.%u", 0) 30 , m_io_in0(*this, "IN0") 31 , m_touch_x(*this, "TOUCH%u_X", 1U) 32 , m_touch_y(*this, "TOUCH%u_Y", 1U) 33 , m_spriteregion(*this, "sprites%u", 0) 34 , m_tileregion(*this, "layer%u", 0) 35 , m_okiregion(*this, "oki%u", 1) 36 , m_z80region(*this, "audiocpu") 37 , m_z80bank(*this, "z80bank") 38 , m_okibank_lo(*this, "oki%u_banklo", 1) 39 , m_okibank_hi(*this, "oki%u_bankhi", 1) 40 , m_maincpu(*this, "maincpu") 41 , m_audiocpu(*this, "audiocpu") 42 , m_oki(*this, "oki%u", 1) 43 , m_int_timer(*this, "int_timer") 44 , m_int_timer_left(*this, "int_timer_left") 45 , m_int_timer_right(*this, "int_timer_right") 46 , m_eeprom(*this, "eeprom") 47 , m_gfxdecode(*this, "gfxdecode.%u", 0U) 48 , m_spr_gfxdecode(*this, "spr_gfxdecode.%u", 0U) 49 , m_screen(*this, "screen.%u", 0U) 50 , m_palette(*this, "palette.%u", 0U) 51 , m_tilemap(*this, "tilemap.%u", 0U) 52 , m_soundlatch(*this, "soundlatch") 53 , m_startup(*this, "startup") 54 , m_led_outputs(*this, "led%u", 0U) 55 { } 56 57 DECLARE_READ_LINE_MEMBER(korokoro_hopper_r); 58 DECLARE_READ_LINE_MEMBER(tjumpman_hopper_r); 59 60 void init_uopoko(); 61 void init_donpachi(); 62 void init_mazinger(); 63 void init_gaia(); 64 void init_pwrinst2(); 65 void init_ddonpach(); 66 void init_agallet(); 67 void init_hotdogst(); 68 void init_tjumpman(); 69 void init_korokoro(); 70 void init_esprade(); 71 void init_pwrinst2j(); 72 void init_guwange(); 73 void init_feversos(); 74 void init_sailormn(); 75 void init_dfeveron(); 76 void init_metmqstr(); 77 void init_ppsatan(); 78 79 void uopoko(machine_config &config); 80 void sailormn(machine_config &config); 81 void paceight(machine_config &config); 82 void pacslot(machine_config &config); 83 void paccarn(machine_config &config); 84 void hotdogst(machine_config &config); 85 void crusherm(machine_config &config); 86 void donpachi(machine_config &config); 87 void tekkencw(machine_config &config); 88 void korokoro(machine_config &config); 89 void esprade(machine_config &config); 90 void mazinger(machine_config &config); 91 void tjumpman(machine_config &config); 92 void tekkenbs(machine_config &config); 93 void gaia(machine_config &config); 94 void metmqstr(machine_config &config); 95 void ppsatan(machine_config &config); 96 void guwange(machine_config &config); 97 void dfeveron(machine_config &config); 98 void ddonpach(machine_config &config); 99 void pwrinst2(machine_config &config); 100 101 protected: 102 virtual void device_post_load() override; 103 104 private: 105 106 enum 107 { 108 TYPE_ZOOM = 0, 109 TYPE_NOZOOM = 1, 110 TYPE_ISPWRINST2 = 2 111 }; 112 113 void (cave_state::*m_get_sprite_info)(int chip); 114 void (cave_state::*m_sprite_draw)(int chip, int priority); 115 116 void add_base_config(machine_config &config, int layer); 117 void add_ymz(machine_config &config); 118 119 u16 irq_cause_r(offs_t offset); 120 u8 soundflags_r(); 121 u16 soundflags_ack_r(); 122 void sound_cmd_w(u16 data); 123 u8 soundlatch_lo_r(); 124 u8 soundlatch_hi_r(); 125 u16 soundlatch_ack_r(); 126 void soundlatch_ack_w(u8 data); 127 void gaia_coin_w(u8 data); 128 u16 donpachi_videoregs_r(offs_t offset); 129 template<int Chip> void videoregs_w(offs_t offset, u16 data, u16 mem_mask); 130 void korokoro_leds_w(offs_t offset, u16 data, u16 mem_mask); 131 template<int Chip> void pwrinst2_vctrl_w(offs_t offset, u16 data, u16 mem_mask); 132 u16 sailormn_input0_r(); 133 void tjumpman_leds_w(u8 data); 134 void pacslot_leds_w(u8 data); 135 template<int Mask> void z80_rombank_w(u8 data); 136 template<int Mask> void oki1_bank_w(u8 data); 137 template<int Mask> void oki2_bank_w(u8 data); 138 void eeprom_w(u8 data); 139 void sailormn_eeprom_w(u8 data); 140 void hotdogst_eeprom_w(u8 data); 141 void guwange_eeprom_w(u8 data); 142 void metmqstr_eeprom_w(u8 data); 143 void korokoro_eeprom_w(offs_t offset, u16 data, u16 mem_mask); 144 u16 pwrinst2_eeprom_r(); 145 void tjumpman_eeprom_w(u8 data); 146 void ppsatan_eeprom_w(offs_t offset, u16 data, u16 mem_mask); 147 void ppsatan_io_mux_w(offs_t offset, u16 data, u16 mem_mask); 148 template<int Player> u16 ppsatan_touch_r(); 149 void ppsatan_out_w(offs_t offset, u16 data, u16 mem_mask); 150 void sailormn_get_banked_code(bool tiledim, u32 &color, u32 &pri, u32 &code); 151 DECLARE_MACHINE_RESET(sailormn); 152 DECLARE_VIDEO_START(spr_4bpp); 153 DECLARE_VIDEO_START(spr_8bpp); 154 DECLARE_VIDEO_START(ppsatan); 155 void cave_palette(palette_device &palette); 156 void dfeveron_palette(palette_device &palette); 157 void korokoro_palette(palette_device &palette); 158 void mazinger_palette(palette_device &palette); 159 void pwrinst2_palette(palette_device &palette); 160 void sailormn_palette(palette_device &palette); 161 void ppsatan_palette(palette_device &palette); 162 u32 screen_update(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect); 163 u32 screen_update_ppsatan_core (screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect, int chip); 164 u32 screen_update_ppsatan_top (screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect); 165 u32 screen_update_ppsatan_left (screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect); 166 u32 screen_update_ppsatan_right(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect); 167 INTERRUPT_GEN_MEMBER(interrupt); 168 INTERRUPT_GEN_MEMBER(interrupt_ppsatan); 169 TIMER_CALLBACK_MEMBER(vblank_end); 170 TIMER_DEVICE_CALLBACK_MEMBER(vblank_start); 171 TIMER_DEVICE_CALLBACK_MEMBER(vblank_start_left); 172 TIMER_DEVICE_CALLBACK_MEMBER(vblank_start_right); 173 TIMER_DEVICE_CALLBACK_MEMBER(timer_lev2_cb); 174 TIMER_DEVICE_CALLBACK_MEMBER(sailormn_startup); 175 void get_sprite_info(int chip); 176 void sailormn_tilebank_w(int bank); 177 DECLARE_WRITE_LINE_MEMBER(sound_irq_gen); 178 void update_irq_state(); 179 void unpack_sprites(int chip); 180 void sailormn_unpack_tiles(int chip); 181 182 virtual void machine_start() override; 183 virtual void machine_reset() override; 184 185 /* memory pointers */ 186 optional_shared_ptr_array<u16, 4> m_videoregs; 187 optional_shared_ptr_array<u16, 4> m_spriteram; 188 189 optional_ioport m_io_in0; 190 optional_ioport_array<2> m_touch_x; 191 optional_ioport_array<2> m_touch_y; 192 193 /* memory regions */ 194 optional_memory_region_array<4> m_spriteregion; 195 optional_memory_region_array<4> m_tileregion; 196 optional_memory_region_array<2> m_okiregion; 197 optional_memory_region m_z80region; 198 optional_memory_bank m_z80bank; 199 optional_memory_bank_array<2> m_okibank_lo; 200 optional_memory_bank_array<2> m_okibank_hi; 201 202 /* video-related */ 203 enum 204 { 205 MAX_PRIORITY = 4, 206 MAX_SPRITE_NUM = 0x400 207 }; 208 209 struct sprite_cave 210 { sprite_cavesprite_cave211 sprite_cave() { } 212 213 int priority = 0, flags = 0; 214 215 const u8 *pen_data = nullptr; /* points to top left corner of tile data */ 216 int line_offset = 0; 217 218 pen_t base_pen = 0; 219 int tile_width = 0, tile_height = 0; 220 int total_width = 0, total_height = 0; /* in screen coordinates */ 221 int x = 0, y = 0, xcount0 = 0, ycount0 = 0; 222 int zoomx_re = 0, zoomy_re = 0; 223 }; 224 225 struct 226 { 227 int clip_left, clip_right, clip_top, clip_bottom; 228 u8 *baseaddr; 229 int line_offset; 230 u8 *baseaddr_zbuf; 231 int line_offset_zbuf; 232 } m_blit; 233 234 std::unique_ptr<sprite_cave []> m_sprite[4]; 235 sprite_cave *m_sprite_table[4][MAX_PRIORITY][MAX_SPRITE_NUM + 1]; 236 237 bitmap_ind16 m_sprite_zbuf[4]; 238 u16 m_sprite_zbuf_baseval; 239 240 std::unique_ptr<u8[]> m_sprite_gfx[4]; 241 offs_t m_sprite_gfx_mask[4]; 242 243 int m_num_sprites[4]; 244 245 int m_spriteram_bank[4]; 246 int m_spriteram_bank_delay[4]; 247 248 int m_layers_offs_x; 249 int m_layers_offs_y; 250 int m_row_effect_offs_n; 251 int m_row_effect_offs_f; 252 u16 m_background_pen[4]; 253 254 int m_spritetype[2]; 255 int m_kludge; 256 emu_timer *m_vblank_end_timer; 257 258 u16 m_sprite_granularity; 259 u32 m_max_sprite_clk[4]; // max usable clock for sprites 260 261 /* misc */ 262 int m_time_vblank_irq; 263 u8 m_irq_level; 264 u8 m_vblank_irq; 265 u8 m_sound_irq; 266 u8 m_unknown_irq; 267 u8 m_agallet_vblank_irq; 268 269 /* sound related */ 270 int m_soundbuf_wptr; 271 int m_soundbuf_rptr; 272 u8 m_soundbuf_data[32]; 273 bool m_soundbuf_empty; 274 //u8 m_sound_flag[2]; 275 276 /* game specific */ 277 // sailormn 278 int m_sailormn_tilebank; 279 // korokoro 280 u16 m_leds[2]; 281 int m_hopper; 282 // ppsatan 283 u16 m_ppsatan_io_mux; 284 285 /* devices */ 286 required_device<cpu_device> m_maincpu; 287 optional_device<cpu_device> m_audiocpu; 288 optional_device_array<okim6295_device, 2> m_oki; 289 required_device<timer_device> m_int_timer; 290 optional_device<timer_device> m_int_timer_left; 291 optional_device<timer_device> m_int_timer_right; 292 optional_device<eeprom_serial_93cxx_device> m_eeprom; 293 optional_device_array<gfxdecode_device, 4> m_gfxdecode; 294 optional_device_array<gfxdecode_device, 4> m_spr_gfxdecode; 295 optional_device_array<screen_device, 4> m_screen; 296 optional_device_array<palette_device, 4> m_palette; 297 optional_device_array<tilemap038_device, 4> m_tilemap; 298 optional_device<generic_latch_16_device> m_soundlatch; 299 optional_device<timer_device> m_startup; 300 output_finder<9> m_led_outputs; 301 302 int m_rasflag; 303 int m_old_rasflag; 304 305 inline void tilemap_draw(int chip, screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect, u32 flags, u32 priority, u32 priority2, int GFX); 306 void set_pens(int chip); 307 void vh_start(u16 sprcol_granularity); 308 void get_sprite_info_cave(int chip); 309 void get_sprite_info_donpachi(int chip); 310 void sprite_init(); 311 void sprite_check(int chip, int screen_no, screen_device &screen, const rectangle &clip); 312 void do_blit_zoom32(int chip, const sprite_cave *sprite); 313 void do_blit_zoom32_zb(int chip, const sprite_cave *sprite); 314 void do_blit_32(int chip, const sprite_cave *sprite); 315 void do_blit_32_zb(int chip, const sprite_cave *sprite); 316 void sprite_draw_cave(int chip, int priority); 317 void sprite_draw_cave_zbuf(int chip, int priority); 318 void sprite_draw_donpachi(int chip, int priority); 319 void sprite_draw_donpachi_zbuf(int chip, int priority); 320 void init_cave(); 321 void init_z80_bank(); 322 void init_oki_bank(int chip); 323 void show_leds(); 324 325 void crusherm_map(address_map &map); 326 void ddonpach_map(address_map &map); 327 void dfeveron_map(address_map &map); 328 void donpachi_map(address_map &map); 329 void esprade_map(address_map &map); 330 void gaia_map(address_map &map); 331 void guwange_map(address_map &map); 332 void hotdogst_map(address_map &map); 333 void hotdogst_sound_map(address_map &map); 334 void hotdogst_sound_portmap(address_map &map); 335 void korokoro_map(address_map &map); 336 void mazinger_map(address_map &map); 337 void mazinger_sound_map(address_map &map); 338 void mazinger_sound_portmap(address_map &map); 339 void metmqstr_map(address_map &map); 340 void metmqstr_sound_map(address_map &map); 341 void metmqstr_sound_portmap(address_map &map); 342 void oki2_map(address_map &map); 343 void oki_map(address_map &map); 344 void paccarn_map(address_map &map); 345 void paceight_map(address_map &map); 346 void pacslot_map(address_map &map); 347 void ppsatan_map(address_map &map); 348 void pwrinst2_map(address_map &map); 349 void pwrinst2_sound_map(address_map &map); 350 void pwrinst2_sound_portmap(address_map &map); 351 void sailormn_map(address_map &map); 352 void sailormn_sound_map(address_map &map); 353 void sailormn_sound_portmap(address_map &map); 354 void tekkenbs_map(address_map &map); 355 void tekkencw_map(address_map &map); 356 void tjumpman_map(address_map &map); 357 void uopoko_map(address_map &map); 358 }; 359 360 #endif // MAME_INCLUDES_CAVE_H 361