1 // license:BSD-3-Clause 2 // copyright-holders:Aaron Giles 3 /*************************************************************************** 4 5 Sega System 16B hardware 6 7 ***************************************************************************/ 8 #ifndef MAME_INCLUDES_SEGAS16B_H 9 #define MAME_INCLUDES_SEGAS16B_H 10 11 #pragma once 12 13 #include "cpu/m68000/m68000.h" 14 #include "cpu/mcs51/mcs51.h" 15 #include "cpu/z80/z80.h" 16 #include "machine/315_5195.h" 17 #include "machine/cxd1095.h" 18 #include "machine/gen_latch.h" 19 #include "machine/nvram.h" 20 #include "machine/segaic16.h" 21 #include "machine/upd4701.h" 22 #include "sound/ym2151.h" 23 #include "sound/ym2413.h" 24 #include "sound/upd7759.h" 25 #include "sound/dac.h" 26 #include "video/segaic16.h" 27 #include "video/sega16sp.h" 28 #include "screen.h" 29 30 31 // ======================> segas16b_state 32 33 class segas16b_state : public sega_16bit_common_base 34 { 35 public: 36 // construction/destruction segas16b_state(const machine_config & mconfig,device_type type,const char * tag)37 segas16b_state(const machine_config &mconfig, device_type type, const char *tag) 38 : sega_16bit_common_base(mconfig, type, tag) 39 , m_mapper(*this, "mapper") 40 , m_maincpu(*this, "maincpu") 41 , m_soundcpu(*this, "soundcpu") 42 , m_mcu(*this, "mcu") 43 , m_ym2151(*this, "ym2151") 44 , m_ym2413(*this, "ym2413") 45 , m_upd7759(*this, "upd") 46 , m_multiplier(*this, "multiplier") 47 , m_cmptimer_1(*this, "cmptimer_1") 48 , m_cmptimer_2(*this, "cmptimer_2") 49 , m_nvram(*this, "nvram") 50 , m_screen(*this, "screen") 51 , m_sprites(*this, "sprites") 52 , m_segaic16vid(*this, "segaic16vid") 53 , m_soundlatch(*this, "soundlatch") 54 , m_cxdio(*this, "cxdio") 55 , m_upd4701a(*this, "upd4701a%u", 1U) 56 , m_workram(*this, "workram") 57 , m_romboard(ROM_BOARD_INVALID) 58 , m_tilemap_type(segaic16_video_device::TILEMAP_16B) 59 , m_custom_io_r(*this) 60 , m_custom_io_w(*this) 61 , m_disable_screen_blanking(false) 62 , m_i8751_initial_config(nullptr) 63 , m_atomicp_sound_divisor(0) 64 , m_atomicp_sound_count(0) 65 , m_hwc_input_value(0) 66 , m_hwc_monitor(*this, "MONITOR") 67 , m_hwc_left(*this, "LEFT") 68 , m_hwc_right(*this, "RIGHT") 69 , m_hwc_left_limit(*this, "LEFT_LIMIT") 70 , m_hwc_right_limit(*this, "RIGHT_LIMIT") 71 , m_mj_input_num(0) 72 , m_mj_last_val(0) 73 , m_mj_inputs(*this, "MJ%u", 0U) 74 , m_spritepalbase(0x400) 75 , m_gfxdecode(*this, "gfxdecode") 76 , m_sound_decrypted_opcodes(*this, "sound_decrypted_opcodes") 77 , m_decrypted_opcodes(*this, "decrypted_opcodes") 78 , m_bootleg_scroll(*this, "bootleg_scroll") 79 , m_bootleg_page(*this, "bootleg_page") 80 , m_lamps(*this, "lamp%u", 0U) 81 { } 82 83 void rom_5797_fragment(machine_config &config); 84 void system16b_fd1094_5797(machine_config &config); 85 void fpointbla(machine_config &config); 86 void atomicp(machine_config &config); 87 void aceattacb_fd1094(machine_config &config); 88 void system16b_i8751(machine_config &config); 89 void system16c(machine_config &config); 90 void system16b_mc8123(machine_config &config); 91 void system16b_i8751_5797(machine_config &config); 92 void system16b_fd1089a(machine_config &config); 93 void system16b_5797(machine_config &config); 94 void system16b_split(machine_config &config); 95 void system16b_fd1089b(machine_config &config); 96 void system16b(machine_config &config); 97 void system16b_fd1094(machine_config &config); 98 void fpointbl(machine_config &config); 99 void lockonph(machine_config &config); 100 101 // ROM board-specific driver init 102 void init_generic_5521(); 103 void init_generic_5358(); 104 void init_generic_5704(); 105 void init_generic_5358_small(); 106 void init_generic_5797(); 107 void init_generic_korean(); 108 void init_generic_bootleg(); 109 void init_lockonph(); 110 // game-specific driver init 111 void init_isgsm(); 112 void init_tturf_5704(); 113 void init_wb3_5704(); 114 void init_hwchamp_5521(); 115 void init_sdi_5358_small(); 116 void init_fpointbla(); 117 void init_altbeasj_5521(); 118 void init_snapper(); 119 void init_shinobi4_5521(); 120 void init_defense_5358_small(); 121 void init_sjryuko_5358_small(); 122 void init_exctleag_5358(); 123 void init_tetrbx(); 124 void init_aceattac_5358(); 125 void init_passshtj_5358(); 126 void init_cencourt_5358(); 127 void init_shinfz(); 128 void init_dunkshot_5358_small(); 129 void init_timescan_5358_small(); 130 void init_shinobi3_5358(); 131 void init_altbeas4_5521(); 132 void init_aliensyn7_5358_small(); 133 134 protected: 135 // memory mapping 136 void memory_mapper(sega_315_5195_mapper_device &mapper, uint8_t index); 137 138 // main CPU read/write handlers 139 void rom_5704_bank_w(address_space &space, offs_t offset, uint16_t data, uint16_t mem_mask = ~0); 140 uint16_t rom_5797_bank_math_r(address_space &space, offs_t offset, uint16_t mem_mask = ~0); 141 void rom_5797_bank_math_w(address_space &space, offs_t offset, uint16_t data, uint16_t mem_mask = ~0); 142 uint16_t unknown_rgn2_r(address_space &space, offs_t offset, uint16_t mem_mask = ~0); 143 void unknown_rgn2_w(address_space &space, offs_t offset, uint16_t data, uint16_t mem_mask = ~0); 144 uint16_t standard_io_r(address_space &space, offs_t offset, uint16_t mem_mask = ~0); 145 void standard_io_w(address_space &space, offs_t offset, uint16_t data, uint16_t mem_mask = ~0); 146 void atomicp_sound_w(address_space &space, offs_t offset, uint16_t data, uint16_t mem_mask = ~0); 147 148 uint16_t bootleg_custom_io_r(address_space &space, offs_t offset, uint16_t mem_mask = ~0); 149 void bootleg_custom_io_w(address_space &space, offs_t offset, uint16_t data, uint16_t mem_mask = ~0); 150 151 // sound CPU read/write handlers 152 void upd7759_control_w(uint8_t data); 153 uint8_t upd7759_status_r(); 154 void sound_w16(uint16_t data); 155 156 // other callbacks 157 DECLARE_WRITE_LINE_MEMBER(upd7759_generate_nmi); 158 INTERRUPT_GEN_MEMBER( i8751_main_cpu_vblank ); 159 void spin_68k_w(uint8_t data); 160 161 // video updates 162 uint32_t screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect); 163 164 void tileram_w(address_space &space, offs_t offset, uint16_t data, uint16_t mem_mask = ~0) { m_segaic16vid->tileram_w(offset,data,mem_mask); }; 165 void textram_w(address_space &space, offs_t offset, uint16_t data, uint16_t mem_mask = ~0) { m_segaic16vid->textram_w(offset,data,mem_mask); }; 166 167 // bootleg stuff 168 void tilemap_16b_fpointbl_fill_latch(int i, uint16_t* latched_pageselect, uint16_t* latched_yscroll, uint16_t* latched_xscroll, uint16_t* textram); 169 170 void decrypted_opcodes_map(address_map &map); 171 void decrypted_opcodes_map_fpointbla(address_map &map); 172 void decrypted_opcodes_map_x(address_map &map); 173 void fpointbl_map(address_map &map); 174 void fpointbl_sound_map(address_map &map); 175 void lockonph_map(address_map &map); 176 void lockonph_sound_iomap(address_map &map); 177 void lockonph_sound_map(address_map &map); 178 void map_fpointbla(address_map &map); 179 void mcu_io_map(address_map &map); 180 void sound_decrypted_opcodes_map(address_map &map); 181 void sound_map(address_map &map); 182 void sound_portmap(address_map &map); 183 void bootleg_sound_map(address_map &map); 184 void bootleg_sound_portmap(address_map &map); 185 void system16b_bootleg_map(address_map &map); 186 void system16b_map(address_map &map); 187 void system16c_map(address_map &map); 188 189 // internal types 190 typedef delegate<void ()> i8751_sim_delegate; 191 192 // timer IDs 193 enum 194 { 195 TID_INIT_I8751, 196 TID_ATOMICP_SOUND_IRQ 197 }; 198 199 // rom board types 200 enum segas16b_rom_board 201 { 202 ROM_BOARD_INVALID, 203 ROM_BOARD_171_5358_SMALL, // 171-5358 with smaller ROMs 204 ROM_BOARD_171_5358, // 171-5358 205 ROM_BOARD_171_5521, // 171-5521 206 ROM_BOARD_171_5704, // 171-5704 - don't know any diff between this and 171-5521 207 ROM_BOARD_171_5797, // 171-5797 208 ROM_BOARD_KOREAN // (custom Korean) 209 }; 210 211 // device overrides 212 virtual void video_start() override; machine_start()213 virtual void machine_start() override { m_lamps.resolve(); } 214 virtual void machine_reset() override; 215 virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) override; 216 217 // internal helpers 218 void init_generic(segas16b_rom_board rom_board); 219 220 // i8751 simulations 221 void altbeast_common_i8751_sim(offs_t soundoffs, offs_t inputoffs, int alt_bank); 222 void altbeasj_i8751_sim(); 223 void tturf_i8751_sim(); 224 void wb3_i8751_sim(); 225 226 // custom I/O handlers 227 uint16_t aceattac_custom_io_r(address_space &space, offs_t offset, uint16_t mem_mask = ~0); 228 void aceattac_custom_io_w(address_space &space, offs_t offset, uint16_t data, uint16_t mem_mask = ~0); 229 uint16_t dunkshot_custom_io_r(address_space &space, offs_t offset, uint16_t mem_mask = ~0); 230 uint16_t hwchamp_custom_io_r(address_space &space, offs_t offset, uint16_t mem_mask = ~0); 231 void hwchamp_custom_io_w(address_space &space, offs_t offset, uint16_t data, uint16_t mem_mask = ~0); 232 uint16_t passshtj_custom_io_r(address_space &space, offs_t offset, uint16_t mem_mask = ~0); 233 uint16_t sdi_custom_io_r(address_space &space, offs_t offset, uint16_t mem_mask = ~0); 234 uint16_t sjryuko_custom_io_r(address_space &space, offs_t offset, uint16_t mem_mask = ~0); 235 void sjryuko_custom_io_w(address_space &space, offs_t offset, uint16_t data, uint16_t mem_mask = ~0); 236 237 // devices 238 optional_device<sega_315_5195_mapper_device> m_mapper; 239 required_device<m68000_device> m_maincpu; 240 optional_device<z80_device> m_soundcpu; 241 optional_device<i8751_device> m_mcu; 242 optional_device<ym2151_device> m_ym2151; 243 optional_device<ym2413_device> m_ym2413; 244 optional_device<upd7759_device> m_upd7759; 245 optional_device<sega_315_5248_multiplier_device> m_multiplier; 246 optional_device<sega_315_5250_compare_timer_device> m_cmptimer_1; 247 optional_device<sega_315_5250_compare_timer_device> m_cmptimer_2; 248 required_device<nvram_device> m_nvram; 249 required_device<screen_device> m_screen; 250 optional_device<sega_sys16b_sprite_device> m_sprites; 251 required_device<segaic16_video_device> m_segaic16vid; 252 optional_device<generic_latch_8_device> m_soundlatch; // not for atomicp 253 optional_device<cxd1095_device> m_cxdio; // for aceattac 254 optional_device_array<upd4701_device, 2> m_upd4701a; // for aceattac 255 256 // memory pointers 257 required_shared_ptr<uint16_t> m_workram; 258 259 // configuration 260 segas16b_rom_board m_romboard; 261 int m_tilemap_type; 262 read16_delegate m_custom_io_r; 263 write16_delegate m_custom_io_w; 264 bool m_disable_screen_blanking; 265 const uint8_t * m_i8751_initial_config; 266 i8751_sim_delegate m_i8751_vblank_hook; 267 uint8_t m_atomicp_sound_divisor; 268 269 // game-specific state 270 uint8_t m_atomicp_sound_count; 271 uint8_t m_hwc_input_value; 272 optional_ioport m_hwc_monitor; 273 optional_ioport m_hwc_left; 274 optional_ioport m_hwc_right; 275 optional_ioport m_hwc_left_limit; 276 optional_ioport m_hwc_right_limit; 277 uint8_t m_mj_input_num; 278 uint8_t m_mj_last_val; 279 optional_ioport_array<6> m_mj_inputs; 280 int m_spritepalbase; 281 282 required_device<gfxdecode_device> m_gfxdecode; 283 optional_shared_ptr<uint8_t> m_sound_decrypted_opcodes; 284 optional_shared_ptr<uint16_t> m_decrypted_opcodes; 285 optional_shared_ptr<uint16_t> m_bootleg_scroll; 286 optional_shared_ptr<uint16_t> m_bootleg_page; 287 output_finder<2> m_lamps; 288 }; 289 290 class dfjail_state : public segas16b_state 291 { 292 public: 293 // construction/destruction dfjail_state(const machine_config & mconfig,device_type type,const char * tag)294 dfjail_state(const machine_config &mconfig, device_type type, const char *tag) 295 : segas16b_state(mconfig, type, tag) 296 , m_nmi_enable(false) 297 , m_dac_data(0) 298 , m_dac(*this, "dac") 299 { } 300 301 void dfjail(machine_config &config); 302 303 protected: 304 void sound_control_w(uint8_t data); 305 void dac_data_w(uint8_t data); 306 INTERRUPT_GEN_MEMBER( soundirq_cb ); 307 bool m_nmi_enable; 308 uint16_t m_dac_data; 309 310 void dfjail_map(address_map &map); 311 void dfjail_sound_iomap(address_map &map); 312 313 virtual void machine_start() override; 314 virtual void machine_reset() override; 315 316 required_device<dac_word_interface> m_dac; 317 }; 318 319 class afighter_16b_analog_state : public segas16b_state 320 { 321 public: 322 // construction/destruction afighter_16b_analog_state(const machine_config & mconfig,device_type type,const char * tag)323 afighter_16b_analog_state(const machine_config &mconfig, device_type type, const char *tag) 324 : segas16b_state(mconfig, type, tag) 325 , m_accel(*this, "ACCEL") 326 , m_steer(*this, "STEER") 327 { } 328 329 DECLARE_CUSTOM_INPUT_MEMBER(afighter_accel_r); 330 DECLARE_CUSTOM_INPUT_MEMBER(afighter_handl_left_r); 331 DECLARE_CUSTOM_INPUT_MEMBER(afighter_handl_right_r); 332 333 private: 334 required_ioport m_accel; 335 required_ioport m_steer; 336 }; 337 338 339 // ======================> isgsm_state 340 341 class isgsm_state : public segas16b_state 342 { 343 public: 344 // construction/destruction isgsm_state(const machine_config & mconfig,device_type type,const char * tag)345 isgsm_state(const machine_config &mconfig, device_type type, const char *tag) 346 : segas16b_state(mconfig, type, tag) 347 , m_read_xor(0) 348 , m_cart_addrlatch(0) 349 , m_cart_addr(0) 350 , m_data_type(0) 351 , m_data_addr(0) 352 , m_data_mode(0) 353 , m_addr_latch(0) 354 , m_security_value(0) 355 , m_security_latch(0) 356 , m_rle_control_position(8) 357 , m_rle_control_byte(0) 358 , m_rle_latched(false) 359 , m_rle_byte(0) 360 { } 361 362 void isgsm(machine_config &config); 363 364 // driver init 365 void init_isgsm(); 366 void init_shinfz(); 367 void init_tetrbx(); 368 369 private: 370 // read/write handlers 371 void cart_addr_high_w(uint16_t data); 372 void cart_addr_low_w(uint16_t data); 373 uint16_t cart_data_r(); 374 void data_w(uint16_t data); 375 void datatype_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0); 376 void addr_high_w(uint16_t data); 377 void addr_low_w(uint16_t data); 378 void cart_security_high_w(uint16_t data); 379 void cart_security_low_w(uint16_t data); 380 uint16_t cart_security_low_r(); 381 uint16_t cart_security_high_r(); 382 void sound_reset_w(uint16_t data); 383 void main_bank_change_w(uint16_t data); 384 385 // security callbacks 386 uint32_t shinfz_security(uint32_t input); 387 uint32_t tetrbx_security(uint32_t input); 388 389 // driver overrides 390 virtual void machine_start() override; 391 virtual void machine_reset() override; 392 393 // configuration 394 uint8_t m_read_xor; 395 typedef delegate<uint32_t (uint32_t)> security_callback_delegate; 396 security_callback_delegate m_security_callback; 397 398 // internal state 399 uint16_t m_cart_addrlatch; 400 uint32_t m_cart_addr; 401 uint8_t m_data_type; 402 uint32_t m_data_addr; 403 uint8_t m_data_mode; 404 uint16_t m_addr_latch; 405 uint32_t m_security_value; 406 uint16_t m_security_latch; 407 uint8_t m_rle_control_position; 408 uint8_t m_rle_control_byte; 409 bool m_rle_latched; 410 uint8_t m_rle_byte; 411 void isgsm_map(address_map &map); 412 }; 413 414 #endif // MAME_INCLUDES_SEGAS16B_H 415