1 // license:BSD-3-Clause 2 // copyright-holders:Pierpaolo Prazzoli, Bryan McPhail 3 /************************************************************************* 4 5 SNK/Alpha 68000 based games 6 7 *************************************************************************/ 8 #ifndef MAME_INCLUDES_ALPHA68K_H 9 #define MAME_INCLUDES_ALPHA68K_H 10 11 #pragma once 12 13 #include "cpu/m68000/m68000.h" 14 #include "cpu/mcs48/mcs48.h" 15 #include "cpu/z80/z80.h" 16 #include "sound/2203intf.h" 17 #include "sound/3812intf.h" 18 #include "sound/ay8910.h" 19 #include "sound/dac.h" 20 #include "sound/ym2413.h" 21 #include "machine/74259.h" 22 #include "machine/gen_latch.h" 23 #include "video/snk68_spr.h" 24 #include "video/alpha68k_palette.h" 25 #include "emupal.h" 26 #include "screen.h" 27 #include "tilemap.h" 28 #include "speaker.h" 29 30 31 class alpha68k_state : public driver_device 32 { 33 public: alpha68k_state(const machine_config & mconfig,device_type type,const char * tag)34 alpha68k_state(const machine_config &mconfig, device_type type, const char *tag) : 35 driver_device(mconfig, type, tag), 36 m_maincpu(*this, "maincpu"), 37 m_audiocpu(*this, "audiocpu"), 38 m_gfxdecode(*this, "gfxdecode"), 39 m_screen(*this, "screen"), 40 m_outlatch(*this, "outlatch"), 41 m_soundlatch(*this, "soundlatch"), 42 m_shared_ram(*this, "shared_ram"), 43 m_spriteram(*this, "spriteram"), 44 m_videoram(*this, "videoram"), 45 m_in(*this, "IN%u", 0U), 46 m_audiobank(*this, "audiobank") 47 { } 48 49 protected: 50 /* devices */ 51 required_device<cpu_device> m_maincpu; 52 required_device<cpu_device> m_audiocpu; 53 required_device<gfxdecode_device> m_gfxdecode; 54 required_device<screen_device> m_screen; 55 optional_device<ls259_device> m_outlatch; 56 required_device<generic_latch_8_device> m_soundlatch; 57 58 /* memory pointers */ 59 optional_shared_ptr<u16> m_shared_ram; 60 required_shared_ptr<u16> m_spriteram; 61 optional_shared_ptr<u16> m_videoram; 62 63 optional_ioport_array<7> m_in; 64 optional_memory_bank m_audiobank; 65 66 int m_flipscreen; 67 68 // MCU sims 69 void alpha_microcontroller_w(offs_t offset, u16 data, u16 mem_mask); 70 int m_invert_controls; 71 int m_microcontroller_id; 72 unsigned m_game_id; // see below 73 unsigned m_deposits1; 74 unsigned m_deposits2; 75 unsigned m_credits; 76 unsigned m_coinvalue; 77 int m_coin_id; 78 unsigned m_microcontroller_data; 79 unsigned m_trigstate; 80 int m_latch; 81 82 void set_screen_raw_params(machine_config &config); 83 84 DECLARE_MACHINE_START(common); 85 DECLARE_MACHINE_RESET(common); 86 87 }; 88 89 class alpha68k_II_state : public alpha68k_state 90 { 91 public: alpha68k_II_state(const machine_config & mconfig,device_type type,const char * tag)92 alpha68k_II_state(const machine_config &mconfig, device_type type, const char *tag) 93 : alpha68k_state(mconfig, type, tag) 94 , m_sprites(*this, "sprites") 95 , m_palette(*this, "palette") 96 {} 97 98 void alpha68k_II(machine_config &config); 99 void btlfieldb(machine_config &config); 100 101 void init_skysoldr(); 102 void init_timesold(); 103 void init_timesold1(); 104 void init_btlfield(); 105 void init_btlfieldb(); 106 protected: 107 uint32_t screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect); 108 required_device<snk68_spr_device> m_sprites; 109 required_device<alpha68k_palette_device> m_palette; 110 111 void base_config(machine_config &config); 112 DECLARE_VIDEO_START(alpha68k); 113 void video_config(machine_config &config, u16 num_pens); 114 void tile_callback(int &tile, int& fx, int& fy, int& region); 115 void tile_callback_noflipx(int &tile, int& fx, int& fy, int& region); 116 void tile_callback_noflipy(int &tile, int& fx, int& fy, int& region); 117 118 INTERRUPT_GEN_MEMBER(sound_nmi); 119 void sound_bank_w(u8 data); 120 void flipscreen_w(int flip); 121 void porta_w(u8 data); 122 u8 m_sound_nmi_mask; 123 u8 m_sound_pa_latch; 124 125 DECLARE_MACHINE_START(alpha68k_II); 126 DECLARE_MACHINE_RESET(alpha68k_II); 127 void video_bank_w(u8 data); 128 void alpha68k_II_map(address_map &map); 129 void sound_map(address_map &map); 130 void sound_portmap(address_map &map); 131 132 u16 alpha_II_trigger_r(offs_t offset); 133 134 /* video-related */ 135 tilemap_t *m_fix_tilemap; 136 int m_bank_base; 137 138 void outlatch_w(offs_t offset, u8 data = 0); 139 u16 control_1_r(); 140 u16 control_2_r(); 141 u16 control_3_r(); 142 u16 control_4_r(); 143 void videoram_w(offs_t offset, u16 data); 144 DECLARE_WRITE_LINE_MEMBER(video_control2_w); 145 DECLARE_WRITE_LINE_MEMBER(video_control3_w); 146 private: 147 TILE_GET_INFO_MEMBER(get_tile_info); 148 }; 149 150 class goldmedal_II_state : public alpha68k_II_state 151 { 152 public: goldmedal_II_state(const machine_config & mconfig,device_type type,const char * tag)153 goldmedal_II_state(const machine_config &mconfig, device_type type, const char *tag) 154 : alpha68k_II_state(mconfig, type, tag) 155 {} 156 157 void init_goldmedl(); 158 void goldmedal(machine_config &config); 159 }; 160 161 class alpha68k_III_state : public alpha68k_II_state 162 { 163 public: alpha68k_III_state(const machine_config & mconfig,device_type type,const char * tag)164 alpha68k_III_state(const machine_config &mconfig, device_type type, const char *tag) 165 : alpha68k_II_state(mconfig, type, tag) 166 {} 167 168 void alpha68k_III(machine_config &config); 169 protected: 170 DECLARE_MACHINE_START(alpha68k_V); 171 DECLARE_MACHINE_RESET(alpha68k_V); 172 void alpha68k_III_map(address_map &map); 173 void alpha68k_V_map(address_map &map); 174 u16 alpha_V_trigger_r(offs_t offset); 175 }; 176 177 class goldmedal_III_state : public alpha68k_III_state 178 { 179 public: goldmedal_III_state(const machine_config & mconfig,device_type type,const char * tag)180 goldmedal_III_state(const machine_config &mconfig, device_type type, const char *tag) 181 : alpha68k_III_state(mconfig, type, tag) 182 {} 183 184 void init_goldmedla(); 185 void goldmedal(machine_config &config); 186 }; 187 188 class alpha68k_V_state : public alpha68k_III_state 189 { 190 public: alpha68k_V_state(const machine_config & mconfig,device_type type,const char * tag)191 alpha68k_V_state(const machine_config &mconfig, device_type type, const char *tag) 192 : alpha68k_III_state(mconfig, type, tag) 193 {} 194 195 void init_skyadvnt(); 196 void init_skyadvntu(); 197 void init_sbasebal(); 198 void init_sbasebalj(); 199 void init_gangwarsu(); 200 void init_gangwars(); 201 void alpha68k_V(machine_config &config); 202 }; 203 204 class skyadventure_state : public alpha68k_V_state 205 { 206 public: skyadventure_state(const machine_config & mconfig,device_type type,const char * tag)207 skyadventure_state(const machine_config &mconfig, device_type type, const char *tag) 208 : alpha68k_V_state(mconfig, type, tag) 209 {} 210 211 void skyadventure(machine_config &config); 212 }; 213 214 class gangwars_state : public alpha68k_V_state 215 { 216 public: gangwars_state(const machine_config & mconfig,device_type type,const char * tag)217 gangwars_state(const machine_config &mconfig, device_type type, const char *tag) 218 : alpha68k_V_state(mconfig, type, tag) 219 {} 220 221 void gangwars(machine_config &config); 222 }; 223 224 /* 225 * Base class for HWs with 4bpp PROMs for colors 226 */ 227 228 class alpha68k_prom_state : public alpha68k_state 229 { 230 public: alpha68k_prom_state(const machine_config & mconfig,device_type type,const char * tag)231 alpha68k_prom_state(const machine_config &mconfig, device_type type, const char *tag) 232 : alpha68k_state(mconfig, type, tag), 233 m_palette(*this, "palette"), 234 m_color_proms(*this, "color_proms") 235 {} 236 237 protected: 238 void palette_init(palette_device &palette) const; 239 240 required_device<palette_device> m_palette; 241 optional_region_ptr<u8> m_color_proms; 242 }; 243 244 /* 245 * 246 * Alpha68k N games 247 * 248 */ 249 class alpha68k_N_state : public alpha68k_prom_state 250 { 251 public: alpha68k_N_state(const machine_config & mconfig,device_type type,const char * tag)252 alpha68k_N_state(const machine_config &mconfig, device_type type, const char *tag) 253 : alpha68k_prom_state(mconfig, type, tag) 254 {} 255 256 protected: 257 void main_map(address_map &map); 258 259 void base_config(machine_config &config); 260 void video_config(machine_config &config, u8 tile_transchar, u8 tile_bankshift, bool is_super_stingray); 261 262 void draw_sprites(bitmap_ind16 &bitmap, const rectangle &cliprect, int c, int d); 263 u32 screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect); 264 265 u16 kyros_alpha_trigger_r(offs_t offset); 266 void sound_map(address_map &map); 267 void sound_iomap(address_map &map); 268 269 private: 270 u16 m_tile_transchar; 271 int m_tile_bankshift; 272 bool m_is_super_stingray; 273 }; 274 275 class sstingray_state : public alpha68k_N_state 276 { 277 public: sstingray_state(const machine_config & mconfig,device_type type,const char * tag)278 sstingray_state(const machine_config &mconfig, device_type type, const char *tag) 279 : alpha68k_N_state(mconfig, type, tag) 280 , m_alpha8511(*this, "alpha8511") 281 {} 282 283 void init_sstingry(); 284 void sstingry(machine_config &config); 285 286 private: 287 u8 alpha8511_command_r(offs_t offset); 288 void alpha8511_command_w(offs_t offset, u8 data); 289 TIMER_CALLBACK_MEMBER(alpha8511_sync); 290 u8 alpha8511_bus_r(); 291 void alpha8511_bus_w(u8 data); 292 u8 alpha8511_address_r(); 293 u8 alpha8511_rw_r(); 294 void alpha8511_control_w(u8 data); 295 296 void main_map(address_map &map); 297 void sound_map(address_map &map); 298 299 required_device<mcs48_cpu_device> m_alpha8511; 300 u8 m_alpha8511_address; 301 u8 m_alpha8511_control; 302 bool m_alpha8511_read_mode; 303 emu_timer *m_alpha8511_sync_timer; 304 }; 305 306 class kyros_state : public alpha68k_N_state 307 { 308 public: kyros_state(const machine_config & mconfig,device_type type,const char * tag)309 kyros_state(const machine_config &mconfig, device_type type, const char *tag) 310 : alpha68k_N_state(mconfig, type, tag) 311 {} 312 313 void kyros(machine_config &config); 314 void init_kyros(); 315 }; 316 317 class jongbou_state : public alpha68k_N_state 318 { 319 public: jongbou_state(const machine_config & mconfig,device_type type,const char * tag)320 jongbou_state(const machine_config &mconfig, device_type type, const char *tag) 321 : alpha68k_N_state(mconfig, type, tag) 322 {} 323 324 void jongbou(machine_config &config); 325 void init_jongbou(); 326 327 private: 328 void main_map(address_map &map); 329 void sound_map(address_map &map); 330 void sound_iomap(address_map &map); 331 u16 dial_inputs_r(); 332 }; 333 334 /* 335 * 336 * Alpha68k I games 337 * 338 */ 339 class alpha68k_I_state : public alpha68k_prom_state 340 { 341 public: alpha68k_I_state(const machine_config & mconfig,device_type type,const char * tag)342 alpha68k_I_state(const machine_config &mconfig, device_type type, const char *tag) 343 : alpha68k_prom_state(mconfig, type, tag) 344 {} 345 346 347 protected: 348 void base_config(machine_config &config); 349 void video_config(machine_config &config, int yshift); 350 void draw_sprites(bitmap_ind16 &bitmap, const rectangle &cliprect, int c, int d); 351 u32 screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect); 352 353 int m_yshift; 354 }; 355 356 class paddlemania_state : public alpha68k_I_state 357 { 358 public: paddlemania_state(const machine_config & mconfig,device_type type,const char * tag)359 paddlemania_state(const machine_config &mconfig, device_type type, const char *tag) 360 : alpha68k_I_state(mconfig, type, tag) 361 {} 362 363 void paddlema(machine_config &config); 364 void init_paddlema(); 365 366 private: 367 void main_map(address_map &map); 368 void sound_map(address_map &map); 369 }; 370 371 class thenextspace_state : public alpha68k_I_state 372 { 373 public: thenextspace_state(const machine_config & mconfig,device_type type,const char * tag)374 thenextspace_state(const machine_config &mconfig, device_type type, const char *tag) 375 : alpha68k_I_state(mconfig, type, tag) 376 {} 377 378 void tnextspc(machine_config &config); 379 void init_tnextspc(); 380 381 private: 382 void main_map(address_map &map); 383 void sound_map(address_map &map); 384 void sound_iomap(address_map &map); 385 386 void tnextspc_coin_counters_w(offs_t offset, u16 data); 387 void tnextspc_unknown_w(offs_t offset, u16 data); 388 void tnextspc_soundlatch_w(u8 data); 389 u16 sound_cpu_r(); 390 }; 391 392 /* game_id - used to deal with a few game specific situations */ 393 enum 394 { 395 ALPHA68K_BTLFIELDB = 1, // used in alpha_II_trigger_r 396 ALPHA68K_JONGBOU, // used in kyros_alpha_trigger_r & kyros_draw_sprites 397 ALPHA68K_KYROS // used in kyros_draw_sprites 398 }; 399 400 #define ALPHA68K_PLAYER_INPUT_LSB( player, button3, start, active ) \ 401 PORT_BIT( 0x0001, active, IPT_JOYSTICK_UP ) PORT_PLAYER(player) \ 402 PORT_BIT( 0x0002, active, IPT_JOYSTICK_DOWN ) PORT_PLAYER(player) \ 403 PORT_BIT( 0x0004, active, IPT_JOYSTICK_LEFT ) PORT_PLAYER(player) \ 404 PORT_BIT( 0x0008, active, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(player) \ 405 PORT_BIT( 0x0010, active, IPT_BUTTON1 ) PORT_PLAYER(player) \ 406 PORT_BIT( 0x0020, active, IPT_BUTTON2 ) PORT_PLAYER(player) \ 407 PORT_BIT( 0x0040, active, button3 ) PORT_PLAYER(player) \ 408 PORT_BIT( 0x0080, active, start ) 409 410 #define ALPHA68K_PLAYER_INPUT_MSB( player, button3, start, active ) \ 411 PORT_BIT( 0x0100, active, IPT_JOYSTICK_UP ) PORT_PLAYER(player) \ 412 PORT_BIT( 0x0200, active, IPT_JOYSTICK_DOWN ) PORT_PLAYER(player) \ 413 PORT_BIT( 0x0400, active, IPT_JOYSTICK_LEFT ) PORT_PLAYER(player) \ 414 PORT_BIT( 0x0800, active, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(player) \ 415 PORT_BIT( 0x1000, active, IPT_BUTTON1 ) PORT_PLAYER(player) \ 416 PORT_BIT( 0x2000, active, IPT_BUTTON2 ) PORT_PLAYER(player) \ 417 PORT_BIT( 0x4000, active, button3 ) PORT_PLAYER(player) \ 418 PORT_BIT( 0x8000, active, start ) 419 420 #define ALPHA68K_MCU \ 421 PORT_START("IN2") /* Coin input to microcontroller */\ 422 PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_COIN1 )\ 423 PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_COIN2 ) 424 425 #endif // MAME_INCLUDES_ALPHA68K_H 426