1 // license:BSD-3-Clause 2 // copyright-holders:Paul Leaman 3 /*************************************************************************** 4 5 Capcom CPS1/2 hardware 6 7 ***************************************************************************/ 8 9 #ifndef MAME_INCLUDES_CPS1_H 10 #define MAME_INCLUDES_CPS1_H 11 12 #pragma once 13 14 #include "sound/msm5205.h" 15 #include "sound/qsound.h" 16 #include "sound/okim6295.h" 17 #include "machine/gen_latch.h" 18 #include "machine/74157.h" 19 #include "machine/timekpr.h" 20 #include "machine/timer.h" 21 #include "cpu/m68000/m68000.h" 22 #include "emupal.h" 23 #include "screen.h" 24 #include "tilemap.h" 25 26 // Video raw params 27 // measured clocks: 28 // CPS2(Guru): V = 59.6376Hz, H = 15,4445kHz *H is probably measured too low! 29 // CPS1 GNG: V = 59.61Hz 30 /* CPS1(Charles MacDonald): 31 Pixel clock: 8.00 MHz 32 Total pixel clocks per scanline: 512 clocks 33 Horizontal sync pulse width : 36 clocks 34 Horizontal display and blanking period: 476 clocks 35 Frame size: 262 scanlines 36 Refresh rate: 59.63 MHz. 37 */ 38 #define CPS_PIXEL_CLOCK (XTAL(16'000'000)/2) 39 40 #define CPS_HTOTAL (512) 41 #define CPS_HBEND (64) 42 #define CPS_HBSTART (448) 43 44 #define CPS_VTOTAL (262) 45 #define CPS_VBEND (16) 46 #define CPS_VBSTART (240) 47 48 49 struct gfx_range 50 { 51 // start and end are as passed by the game (shift adjusted to be all 52 // in the same scale a 8x8 tiles): they don't necessarily match the 53 // position in ROM. 54 int type; 55 int start; 56 int end; 57 int bank; 58 }; 59 60 struct CPS1config 61 { 62 const char *name; /* game driver name */ 63 64 /* Some games interrogate a couple of registers on bootup. */ 65 /* These are CPS1 board B self test checks. They wander from game to */ 66 /* game. */ 67 int cpsb_addr; /* CPS board B test register address */ 68 int cpsb_value; /* CPS board B test register expected value */ 69 70 /* some games use as a protection check the ability to do 16-bit multiplies */ 71 /* with a 32-bit result, by writing the factors to two ports and reading the */ 72 /* result from two other ports. */ 73 /* It looks like this feature was introduced with 3wonders (CPSB ID = 08xx) */ 74 int mult_factor1; 75 int mult_factor2; 76 int mult_result_lo; 77 int mult_result_hi; 78 79 /* unknown registers which might be related to the multiply protection */ 80 int unknown1; 81 int unknown2; 82 int unknown3; 83 84 int layer_control; 85 int priority[4]; 86 int palette_control; 87 88 /* ideally, the layer enable masks should consist of only one bit, */ 89 /* but in many cases it is unknown which bit is which. */ 90 int layer_enable_mask[5]; 91 92 /* these depend on the B-board model and PAL */ 93 int bank_sizes[4]; 94 const struct gfx_range *bank_mapper; 95 96 /* some C-boards have additional I/O for extra buttons/extra players */ 97 int in2_addr; 98 int in3_addr; 99 int out2_addr; 100 101 int bootleg_kludge; 102 }; 103 104 105 class cps_state : public driver_device 106 { 107 public: cps_state(const machine_config & mconfig,device_type type,const char * tag)108 cps_state(const machine_config &mconfig, device_type type, const char *tag) 109 : cps_state(mconfig, type, tag, 1) 110 { } 111 112 protected: cps_state(const machine_config & mconfig,device_type type,const char * tag,int version)113 cps_state(const machine_config &mconfig, device_type type, const char *tag, int version) 114 : driver_device(mconfig, type, tag) 115 , m_mainram(*this, "mainram") 116 , m_gfxram(*this, "gfxram") 117 , m_cps_a_regs(*this, "cps_a_regs") 118 , m_cps_b_regs(*this, "cps_b_regs") 119 , m_qsound_sharedram1(*this, "qsound_ram1") 120 , m_qsound_sharedram2(*this, "qsound_ram2") 121 , m_cps_version(version) 122 , m_maincpu(*this, "maincpu") 123 , m_audiocpu(*this, "audiocpu") 124 , m_oki(*this, "oki") 125 , m_m48t35(*this,"m48t35") 126 , m_gfxdecode(*this, "gfxdecode") 127 , m_screen(*this, "screen") 128 , m_palette(*this, "palette") 129 , m_soundlatch(*this, "soundlatch") 130 , m_soundlatch2(*this, "soundlatch2") 131 , m_region_stars(*this, "stars") 132 , m_led_cboard(*this, "led_cboard%u", 0U) 133 { } 134 135 public: 136 void cps1_10MHz(machine_config &config); 137 void forgottn(machine_config &config); 138 void cps1_12MHz(machine_config &config); 139 void pang3(machine_config &config); 140 void ganbare(machine_config &config); 141 void qsound(machine_config &config); 142 void wofhfh(machine_config &config); 143 void sf2m3(machine_config &config); 144 void sf2cems6(machine_config &config); 145 void sf2m10(machine_config &config); 146 void varthb2(machine_config &config); 147 148 void init_cps1(); 149 void init_sf2ee(); 150 void init_wof(); 151 void init_dino(); 152 void init_punisher(); 153 void init_slammast(); 154 void init_pang3(); 155 void init_ganbare(); 156 void init_pang3b(); 157 void init_sf2rb(); 158 void init_sf2rb2(); 159 void init_sf2thndr(); 160 void init_sf2hack(); 161 void init_sf2rk(); 162 void init_sf2dongb(); 163 void init_sf2ceblp(); 164 void init_sf2m8(); 165 void init_dinohunt(); 166 167 protected: 168 DECLARE_MACHINE_START(common); 169 DECLARE_MACHINE_START(cps1); 170 DECLARE_MACHINE_START(qsound); 171 DECLARE_MACHINE_START(ganbare); 172 DECLARE_MACHINE_RESET(cps); 173 174 uint16_t cps1_dsw_r(offs_t offset); 175 uint16_t cps1_in1_r(); 176 uint16_t cps1_in2_r(); 177 uint16_t cps1_in3_r(); 178 void cps1_coinctrl_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0); 179 void cpsq_coinctrl2_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0); 180 void cps1_cps_a_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0); 181 uint16_t cps1_cps_b_r(offs_t offset); 182 void cps1_cps_b_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0); 183 void cps1_gfxram_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0); 184 void cps1_soundlatch_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0); 185 void cps1_soundlatch2_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0); 186 void cps1_snd_bankswitch_w(uint8_t data); 187 void cps1_oki_pin7_w(uint8_t data); 188 uint16_t qsound_rom_r(offs_t offset); 189 uint16_t qsound_sharedram1_r(offs_t offset); 190 void qsound_sharedram1_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0); 191 uint16_t qsound_sharedram2_r(offs_t offset); 192 void qsound_sharedram2_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0); 193 void qsound_banksw_w(uint8_t data); 194 uint16_t ganbare_ram_r(offs_t offset, uint16_t mem_mask = ~0); 195 void ganbare_ram_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0); 196 uint16_t cps1_hack_dsw_r(offs_t offset); 197 uint16_t sf2rb_prot_r(offs_t offset); 198 uint16_t sf2rb2_prot_r(offs_t offset); 199 uint16_t sf2dongb_prot_r(offs_t offset); 200 uint16_t sf2ceblp_prot_r(); 201 void sf2ceblp_prot_w(uint16_t data); 202 void sf2m3_layer_w(offs_t offset, uint16_t data); 203 uint16_t dinohunt_sound_r(); 204 void varthb2_cps_a_w(offs_t offset, uint16_t data); 205 206 TILEMAP_MAPPER_MEMBER(tilemap0_scan); 207 TILEMAP_MAPPER_MEMBER(tilemap1_scan); 208 TILEMAP_MAPPER_MEMBER(tilemap2_scan); 209 TILE_GET_INFO_MEMBER(get_tile0_info); 210 TILE_GET_INFO_MEMBER(get_tile1_info); 211 TILE_GET_INFO_MEMBER(get_tile2_info); 212 virtual void video_start() override; 213 214 INTERRUPT_GEN_MEMBER(cps1_interrupt); 215 TIMER_DEVICE_CALLBACK_MEMBER(ganbare_interrupt); 216 217 virtual void render_layers(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect); 218 uint32_t screen_update_cps1(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect); 219 DECLARE_WRITE_LINE_MEMBER(screen_vblank_cps1); 220 221 void kabuki_setup(void (*decode)(uint8_t *src, uint8_t *dst)); 222 223 /* maps */ 224 void cpu_space_map(address_map &map); 225 void main_map(address_map &map); 226 void forgottn_map(address_map &map); 227 void qsound_main_map(address_map &map); 228 void qsound_decrypted_opcodes_map(address_map &map); 229 void sub_map(address_map &map); 230 void qsound_sub_map(address_map &map); 231 void sf2m3_map(address_map &map); 232 void sf2cems6_map(address_map &map); 233 void sf2m10_map(address_map &map); 234 void varthb2_map(address_map &map); 235 236 // game-specific 237 uint16_t sf2ceblp_prot; 238 239 /* video-related */ 240 tilemap_t *m_bg_tilemap[3]; 241 int m_scanline1; 242 int m_scanline2; 243 int m_scancalls; 244 245 int m_scroll1x; 246 int m_scroll1y; 247 int m_scroll2x; 248 int m_scroll2y; 249 int m_scroll3x; 250 int m_scroll3y; 251 252 int m_stars_enabled[2]; /* Layer enabled [Y/N] */ 253 int m_stars1x; 254 int m_stars1y; 255 int m_stars2x; 256 int m_stars2y; 257 int m_last_sprite_offset; /* Offset of the last sprite */ 258 259 bitmap_ind16 m_dummy_bitmap; 260 261 /* video config (never changed after video_start) */ 262 const struct CPS1config *m_game_config; 263 int m_scroll_size; 264 int m_obj_size; 265 int m_other_size; 266 int m_palette_align; 267 int m_palette_size; 268 int m_stars_rom_size; 269 uint8_t m_empty_tile[32*32]; 270 271 /* video/cps1.cpp */ 272 inline uint16_t *cps1_base( int offset, int boundary ); 273 void cps1_get_video_base(); 274 int gfxrom_bank_mapper(int type, int code); 275 void cps1_update_transmasks(); 276 void cps1_build_palette(const uint16_t* const palette_base); 277 virtual void find_last_sprite(); 278 void cps1_render_sprites(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect); 279 void cps1_render_stars(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect); 280 void cps1_render_layer(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect, int layer, int primask); 281 void cps1_render_high_layer(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect, int layer); 282 283 /* memory pointers */ 284 optional_shared_ptr<uint16_t> m_mainram; 285 required_shared_ptr<uint16_t> m_gfxram; 286 required_shared_ptr<uint16_t> m_cps_a_regs; 287 required_shared_ptr<uint16_t> m_cps_b_regs; 288 uint16_t * m_scroll1; 289 uint16_t * m_scroll2; 290 uint16_t * m_scroll3; 291 uint16_t * m_obj; 292 uint16_t * m_other; 293 std::unique_ptr<uint16_t[]> m_buffered_obj; 294 optional_shared_ptr<uint8_t> m_qsound_sharedram1; 295 optional_shared_ptr<uint8_t> m_qsound_sharedram2; 296 std::unique_ptr<uint8_t[]> m_decrypt_kabuki; 297 int m_cps_version; 298 299 /* devices */ 300 required_device<m68000_base_device> m_maincpu; 301 optional_device<cpu_device> m_audiocpu; 302 optional_device<okim6295_device> m_oki; 303 optional_device<m48t35_device> m_m48t35; 304 required_device<gfxdecode_device> m_gfxdecode; 305 required_device<screen_device> m_screen; 306 required_device<palette_device> m_palette; 307 optional_device<generic_latch_8_device> m_soundlatch; 308 optional_device<generic_latch_8_device> m_soundlatch2; 309 optional_memory_region m_region_stars; 310 output_finder<3> m_led_cboard; 311 }; 312 313 class cps2_state : public cps_state 314 { 315 public: cps2_state(const machine_config & mconfig,device_type type,const char * tag)316 cps2_state(const machine_config &mconfig, device_type type, const char *tag) 317 : cps_state(mconfig, type, tag, 2) 318 , m_decrypted_opcodes(*this, "decrypted_opcodes") 319 , m_region_key(*this, "key") 320 , m_qsound(*this, "qsound") 321 , m_objram1(*this, "objram1") 322 , m_objram2(*this, "objram2") 323 , m_output(*this, "output") 324 , m_io_in0(*this, "IN0") 325 , m_io_in1(*this, "IN1") 326 , m_cps2_dial_type(0) 327 , m_ecofghtr_dial_direction0(0) 328 , m_ecofghtr_dial_direction1(0) 329 , m_ecofghtr_dial_last0(0) 330 , m_ecofghtr_dial_last1(0) 331 { } 332 333 void cps2(machine_config &config); 334 void gigaman2(machine_config &config); 335 void dead_cps2(machine_config &config); 336 void init_cps2_video(); 337 void init_cps2(); 338 void init_cps2nc(); 339 void init_cps2crypt(); 340 void init_gigaman2(); 341 void init_ssf2tb(); 342 void init_pzloop2(); 343 void init_singbrd(); 344 void init_ecofghtr(); 345 346 private: 347 void init_digital_volume(); 348 uint16_t gigaman2_dummyqsound_r(offs_t offset); 349 void gigaman2_dummyqsound_w(offs_t offset, uint16_t data); 350 void gigaman2_gfx_reorder(); 351 void cps2_eeprom_port_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0); 352 uint16_t cps2_qsound_volume_r(); 353 uint16_t kludge_r(); 354 uint16_t joy_or_paddle_r(); 355 uint16_t joy_or_paddle_ecofghtr_r(); 356 TIMER_DEVICE_CALLBACK_MEMBER(cps2_interrupt); 357 TIMER_CALLBACK_MEMBER(cps2_update_digital_volume); 358 359 void cps2_objram_bank_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0); 360 uint16_t cps2_objram1_r(offs_t offset); 361 uint16_t cps2_objram2_r(offs_t offset); 362 void cps2_objram1_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0); 363 void cps2_objram2_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0); 364 365 void unshuffle(uint64_t *buf, int len); 366 void cps2_gfx_decode(); 367 virtual void find_last_sprite() override; 368 void cps2_render_sprites(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect, int *primasks); 369 void cps2_set_sprite_priorities(); 370 void cps2_objram_latch(); 371 uint16_t *cps2_objbase(); 372 virtual void render_layers(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect) override; 373 uint32_t screen_update_cps2(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect); 374 375 DECLARE_MACHINE_START(cps2); 376 virtual void video_start() override; 377 378 void cps2_map(address_map &map); 379 void dead_cps2_map(address_map &map); 380 void decrypted_opcodes_map(address_map &map); 381 382 optional_shared_ptr<uint16_t> m_decrypted_opcodes; 383 optional_memory_region m_region_key; 384 385 optional_device<qsound_device> m_qsound; 386 387 required_shared_ptr<uint16_t> m_objram1; 388 required_shared_ptr<uint16_t> m_objram2; 389 required_shared_ptr<uint16_t> m_output; 390 391 optional_ioport m_io_in0; 392 optional_ioport m_io_in1; 393 394 std::unique_ptr<uint16_t[]> m_cps2_buffered_obj; 395 std::unique_ptr<uint16_t[]> m_gigaman2_dummyqsound_ram; 396 397 /* video-related */ 398 int m_cps2_last_sprite_offset; /* Offset of the last sprite */ 399 int m_pri_ctrl; /* Sprite layer priorities */ 400 int m_objram_bank; 401 int m_cps2_obj_size; 402 403 /* misc */ 404 int m_readpaddle; // pzloop2 405 int m_cps2networkpresent; 406 int m_cps2digitalvolumelevel; 407 int m_cps2disabledigitalvolume; 408 emu_timer *m_digital_volume_timer; 409 int m_cps2_dial_type; 410 int m_ecofghtr_dial_direction0; 411 int m_ecofghtr_dial_direction1; 412 int m_ecofghtr_dial_last0; 413 int m_ecofghtr_dial_last1; 414 }; 415 416 417 /*----------- defined in drivers/cps1.cpp -----------*/ 418 419 extern gfx_decode_entry const gfx_cps1[]; 420 421 INPUT_PORTS_EXTERN( dino ); 422 INPUT_PORTS_EXTERN( knights ); 423 INPUT_PORTS_EXTERN( mtwins ); 424 INPUT_PORTS_EXTERN( punisher ); 425 INPUT_PORTS_EXTERN( sf2 ); 426 INPUT_PORTS_EXTERN( slammast ); 427 INPUT_PORTS_EXTERN( varth ); 428 INPUT_PORTS_EXTERN( captcomm ); 429 INPUT_PORTS_EXTERN( wof ); 430 431 #endif // MAME_INCLUDES_CPS1_H 432