1 // license:BSD-3-Clause 2 // copyright-holders:Aaron Giles 3 /*************************************************************************** 4 5 Sega pre-System 16 & System 16A hardware 6 7 ***************************************************************************/ 8 9 #include "cpu/m68000/m68000.h" 10 #include "cpu/mcs48/mcs48.h" 11 #include "cpu/mcs51/mcs51.h" 12 #include "cpu/z80/z80.h" 13 #include "machine/cxd1095.h" 14 #include "machine/gen_latch.h" 15 #include "machine/i8255.h" 16 #include "machine/i8243.h" 17 #include "machine/nvram.h" 18 #include "machine/watchdog.h" 19 #include "sound/ym2151.h" 20 #include "video/segaic16.h" 21 #include "video/sega16sp.h" 22 #include "screen.h" 23 24 25 // ======================> segas16a_state 26 27 class segas16a_state : public sega_16bit_common_base 28 { 29 public: 30 // construction/destruction segas16a_state(const machine_config & mconfig,device_type type,const char * tag)31 segas16a_state(const machine_config &mconfig, device_type type, const char *tag) 32 : sega_16bit_common_base(mconfig, type, tag) 33 , m_maincpu(*this, "maincpu") 34 , m_soundcpu(*this, "soundcpu") 35 , m_mcu(*this, "mcu") 36 , m_i8255(*this, "i8255") 37 , m_ymsnd(*this, "ymsnd") 38 , m_n7751(*this, "n7751") 39 , m_n7751_i8243(*this, "n7751_8243") 40 , m_nvram(*this, "nvram") 41 , m_watchdog(*this, "watchdog") 42 , m_segaic16vid(*this, "segaic16vid") 43 , m_soundlatch(*this, "soundlatch") 44 , m_screen(*this, "screen") 45 , m_sprites(*this, "sprites") 46 , m_cxdio(*this, "cxdio") 47 , m_workram(*this, "nvram") 48 , m_sound_decrypted_opcodes(*this, "sound_decrypted_opcodes") 49 , m_custom_io_r(*this) 50 , m_custom_io_w(*this) 51 , m_video_control(0) 52 , m_mcu_control(0) 53 , m_n7751_command(0) 54 , m_n7751_rom_address(0) 55 , m_last_buttons1(0) 56 , m_last_buttons2(0) 57 , m_read_port(0) 58 , m_mj_input_num(0) 59 , m_mj_inputs(*this, "MJ%u", 0U) 60 , m_lamps(*this, "lamp%u", 0U) 61 { } 62 63 void system16a_no7751(machine_config &config); 64 void system16a(machine_config &config); 65 void system16a_fd1089a_no7751(machine_config &config); 66 void system16a_fd1089b_no7751(machine_config &config); 67 void system16a_fd1089a(machine_config &config); 68 void system16a_fd1094(machine_config &config); 69 void system16a_no7751p(machine_config &config); 70 void system16a_fd1094_no7751(machine_config &config); 71 void system16a_i8751(machine_config &config); 72 void system16a_fd1089b(machine_config &config); 73 void aceattaca_fd1094(machine_config &config); 74 75 // game-specific driver init 76 void init_generic(); 77 void init_dumpmtmt(); 78 void init_fantzonep(); 79 void init_sjryukoa(); 80 void init_aceattaca(); 81 void init_passsht16a(); 82 void init_mjleague(); 83 void init_sdi(); 84 85 private: 86 // PPI read/write callbacks 87 void misc_control_w(uint8_t data); 88 void tilemap_sound_w(uint8_t data); 89 90 // main CPU read/write handlers 91 uint16_t standard_io_r(offs_t offset); 92 void standard_io_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0); 93 uint16_t misc_io_r(offs_t offset); 94 void misc_io_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0); 95 96 // Z80 sound CPU read/write handlers 97 uint8_t sound_data_r(); 98 void n7751_command_w(uint8_t data); 99 void n7751_control_w(uint8_t data); 100 template<int Shift> void n7751_rom_offset_w(uint8_t data); 101 102 // N7751 sound generator CPU read/write handlers 103 uint8_t n7751_rom_r(); 104 uint8_t n7751_p2_r(); 105 void n7751_p2_w(uint8_t data); 106 107 // I8751 MCU read/write handlers 108 void mcu_control_w(uint8_t data); 109 void mcu_io_w(offs_t offset, uint8_t data); 110 uint8_t mcu_io_r(address_space &space, offs_t offset); 111 112 // I8751-related VBLANK interrupt handlers 113 DECLARE_WRITE_LINE_MEMBER(i8751_main_cpu_vblank_w); 114 115 // video updates 116 uint32_t screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect); 117 118 void decrypted_opcodes_map(address_map &map); 119 void mcu_io_map(address_map &map); 120 void sound_decrypted_opcodes_map(address_map &map); 121 void sound_map(address_map &map); 122 void sound_no7751_portmap(address_map &map); 123 void sound_portmap(address_map &map); 124 void system16a_map(address_map &map); 125 126 // internal types 127 typedef delegate<void ()> i8751_sim_delegate; 128 typedef delegate<void (uint8_t, uint8_t)> lamp_changed_delegate; 129 130 // timer IDs 131 enum 132 { 133 TID_INIT_I8751, 134 TID_PPI_WRITE 135 }; 136 137 // driver overrides 138 virtual void video_start() override; machine_start()139 virtual void machine_start() override { m_lamps.resolve(); } 140 virtual void machine_reset() override; 141 virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) override; 142 143 // I8751 simulations 144 void dumpmtmt_i8751_sim(); 145 146 // custom I/O handlers 147 uint16_t aceattaca_custom_io_r(offs_t offset); 148 void aceattaca_custom_io_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0); 149 uint16_t mjleague_custom_io_r(offs_t offset); 150 uint16_t passsht16a_custom_io_r(offs_t offset); 151 uint16_t sdi_custom_io_r(offs_t offset); 152 uint16_t sjryuko_custom_io_r(offs_t offset); 153 void sjryuko_lamp_changed_w(uint8_t changed, uint8_t newval); 154 155 // devices 156 required_device<m68000_device> m_maincpu; 157 required_device<z80_device> m_soundcpu; 158 optional_device<i8751_device> m_mcu; 159 required_device<i8255_device> m_i8255; 160 required_device<ym2151_device> m_ymsnd; 161 optional_device<n7751_device> m_n7751; 162 optional_device<i8243_device> m_n7751_i8243; 163 required_device<nvram_device> m_nvram; 164 required_device<watchdog_timer_device> m_watchdog; 165 required_device<segaic16_video_device> m_segaic16vid; 166 required_device<generic_latch_8_device> m_soundlatch; 167 required_device<screen_device> m_screen; 168 required_device<sega_sys16a_sprite_device> m_sprites; 169 optional_device<cxd1095_device> m_cxdio; 170 171 // memory pointers 172 required_shared_ptr<uint16_t> m_workram; 173 optional_shared_ptr<uint8_t> m_sound_decrypted_opcodes; 174 175 // configuration 176 read16sm_delegate m_custom_io_r; 177 write16s_delegate m_custom_io_w; 178 i8751_sim_delegate m_i8751_vblank_hook; 179 lamp_changed_delegate m_lamp_changed_w; 180 181 // internal state 182 uint8_t m_video_control; 183 uint8_t m_mcu_control; 184 uint8_t m_n7751_command; 185 uint32_t m_n7751_rom_address; 186 uint8_t m_last_buttons1; 187 uint8_t m_last_buttons2; 188 uint8_t m_read_port; 189 uint8_t m_mj_input_num; 190 optional_ioport_array<6> m_mj_inputs; 191 output_finder<2> m_lamps; 192 }; 193 194 class afighter_16a_analog_state : public segas16a_state 195 { 196 public: 197 // construction/destruction afighter_16a_analog_state(const machine_config & mconfig,device_type type,const char * tag)198 afighter_16a_analog_state(const machine_config &mconfig, device_type type, const char *tag) 199 : segas16a_state(mconfig, type, tag) 200 , m_accel(*this, "ACCEL") 201 , m_steer(*this, "STEER") 202 { } 203 204 DECLARE_CUSTOM_INPUT_MEMBER(afighter_accel_r); 205 DECLARE_CUSTOM_INPUT_MEMBER(afighter_handl_left_r); 206 DECLARE_CUSTOM_INPUT_MEMBER(afighter_handl_right_r); 207 208 private: 209 required_ioport m_accel; 210 required_ioport m_steer; 211 }; 212