From ebadd722b02948cb70703e01549a9f09c21048dc Mon Sep 17 00:00:00 2001 From: Fabio Priuli Date: Fri, 22 Mar 2013 06:18:38 +0000 Subject: [PATCH] (MESS) megadriv.c: temporarily duplicated some DMA code while working towards a reduction of global variables. nw. --- src/mame/includes/megadriv.h | 10 +++------ src/mame/machine/megacd.c | 6 ------ src/mame/machine/megadriv.c | 39 ++++++++++++++++++++++++++++-------- src/mame/machine/megavdp.c | 28 ++++---------------------- src/mame/machine/megavdp.h | 3 +++ src/mess/drivers/megadriv.c | 27 +++++++++++++++++++++++-- src/mess/includes/md.h | 2 -- src/mess/machine/md_slot.h | 2 ++ 8 files changed, 68 insertions(+), 49 deletions(-) diff --git a/src/mame/includes/megadriv.h b/src/mame/includes/megadriv.h index dd03321871e..b3ffa074731 100644 --- a/src/mame/includes/megadriv.h +++ b/src/mame/includes/megadriv.h @@ -25,8 +25,6 @@ #define MD_CPU_REGION_SIZE 0x800000 -extern int sega_cd_connected; - /*----------- defined in machine/megadriv.c -----------*/ @@ -41,8 +39,6 @@ MACHINE_CONFIG_EXTERN( md_ntsc ); MACHINE_CONFIG_EXTERN( md_pal ); MACHINE_CONFIG_EXTERN( md_bootleg ); // for topshoot.c & hshavoc.c -extern cpu_device *_svp_cpu; - extern UINT8 megatech_bios_port_cc_dc_r(running_machine &machine, int offset, int ctrl); extern void megadriv_stop_scanline_timer(running_machine &machine); @@ -85,11 +81,11 @@ public: md_base_state(const machine_config &mconfig, device_type type, const char *tag) : driver_device(mconfig, type, tag), m_vdp(*this,"gen_vdp"), + m_segacd(*this,"segacd"), m_megadrive_ram(*this,"megadrive_ram") - { - sega_cd_connected = 0; - } + { } required_device m_vdp; + optional_device m_segacd; optional_shared_ptr m_megadrive_ram; DECLARE_DRIVER_INIT(megadriv_c2); diff --git a/src/mame/machine/megacd.c b/src/mame/machine/megacd.c index 1431d71e231..9d050c1ead7 100644 --- a/src/mame/machine/megacd.c +++ b/src/mame/machine/megacd.c @@ -4,11 +4,6 @@ #include "sound/rf5c68.h" - -// the main MD emulation needs to know the state of these because it appears in the MD regs / affect DMA operations -int sega_cd_connected = 0x00; - - // not in the state because the IRQ_CALLBACK needs it, and that can't be a member function? UINT16 a12000_halt_reset_reg = 0x0000; @@ -1568,7 +1563,6 @@ READ16_MEMBER( sega_segacd_device::segacd_font_converted_r ) void sega_segacd_device::device_start() { _segacd_68k_cpu = machine().device(":segacd:segacd_68k"); - sega_cd_connected = 1; segacd_gfx_conversion_timer = machine().device(":segacd:stamp_timer"); segacd_irq3_timer = machine().device(":segacd:irq3_timer"); diff --git a/src/mame/machine/megadriv.c b/src/mame/machine/megadriv.c index 9c16406cba9..fa202a535bb 100644 --- a/src/mame/machine/megadriv.c +++ b/src/mame/machine/megadriv.c @@ -33,7 +33,6 @@ static cpu_device *_genesis_snd_z80_cpu; int genesis_other_hacks = 0; // misc hacks timer_device* megadriv_scanline_timer; -cpu_device *_svp_cpu; struct genesis_z80_vars { @@ -380,6 +379,7 @@ static UINT8 megadrive_io_read_sctrl_port(int portnum) READ16_HANDLER( megadriv_68k_io_read ) { + md_base_state *state = space.machine().driver_data(); UINT8 retdata; retdata = 0; @@ -401,7 +401,7 @@ READ16_HANDLER( megadriv_68k_io_read ) logerror("%06x read version register\n", space.device().safe_pc()); retdata = megadrive_region_export<<7 | // Export megadrive_region_pal<<6 | // NTSC - (sega_cd_connected?0x00:0x20) | // 0x20 = no sega cd + (state->m_segacd ? 0x00 : 0x20) | // 0x20 = no sega cd 0x00 | // Unused (Always 0) 0x00 | // Bit 3 of Version Number 0x00 | // Bit 2 of Version Number @@ -1201,6 +1201,24 @@ static int megadriv_tas_callback(device_t *device) return 0; // writeback not allowed } +// the SVP introduces some kind of DMA 'lag', which we have to compensate for, this is obvious even on gfx DMAd from ROM (the Speedometer) +// likewise segaCD, at least when reading wordram? we might need to check what mode we're in here.. +UINT16 vdp_get_word_from_68k_mem_delayed(running_machine &machine, UINT32 source, address_space & space68k) +{ + if (source <= 0x3fffff) + { + source -= 2; // compensate DMA lag + return space68k.read_word(source); + } + else if ((source >= 0xe00000) && (source <= 0xffffff)) + return space68k.read_word(source); + else + { + printf("DMA Read unmapped %06x\n",source); + return machine.rand(); + } +} + void md_base_state::megadriv_init_common() { /* Look to see if this system has the standard Sound Z80 */ @@ -1227,18 +1245,23 @@ void md_base_state::megadriv_init_common() printf("32x SLAVE SH2 cpu found '%s'\n", _32x_slave_cpu->tag() ); } - _svp_cpu = machine().device("svp"); - if (_svp_cpu != NULL) - { - printf("SVP (cpu) found '%s'\n", _svp_cpu->tag()); - } - machine().device("maincpu")->execute().set_irq_acknowledge_callback(device_irq_acknowledge_delegate(FUNC(md_base_state::genesis_int_callback),this)); megadriv_backupram = NULL; megadriv_backupram_length = 0; vdp_get_word_from_68k_mem = vdp_get_word_from_68k_mem_default; + if (machine().device("svp")) + { + printf("SVP (cpu) found '%s'\n", machine().device("svp")->tag()); + vdp_get_word_from_68k_mem = vdp_get_word_from_68k_mem_delayed; + } + if (machine().device("segacd")) + { + printf("SegaCD found '%s'\n", machine().device("segacd")->tag()); + vdp_get_word_from_68k_mem = vdp_get_word_from_68k_mem_delayed; + } + m68k_set_tas_callback(machine().device("maincpu"), megadriv_tas_callback); // the drivers which need 6 buttons pad set this to 1 in their init befare calling the megadrive init diff --git a/src/mame/machine/megavdp.c b/src/mame/machine/megavdp.c index 6f9582cd288..5f891e3b4da 100644 --- a/src/mame/machine/megavdp.c +++ b/src/mame/machine/megavdp.c @@ -9,13 +9,9 @@ #include "sound/sn76496.h" -extern cpu_device *_svp_cpu; -extern int sega_cd_connected; extern timer_device* megadriv_scanline_timer; - - #define MAX_HPOSITION 480 @@ -470,6 +466,8 @@ void sega_genesis_vdp_device::update_m_vdp_code_and_address(void) UINT16 (*vdp_get_word_from_68k_mem)(running_machine &machine, UINT32 source, address_space& space68k); +// if either SVP CPU or segaCD is present, there is a lag we have to compensate for +// hence, variants of this call will be defined in megadriv_init_common for segacd and svp UINT16 vdp_get_word_from_68k_mem_default(running_machine &machine, UINT32 source, address_space & space68k) { // should we limit the valid areas here? @@ -478,33 +476,15 @@ UINT16 vdp_get_word_from_68k_mem_default(running_machine &machine, UINT32 source //printf("vdp_get_word_from_68k_mem_default %08x\n", source); - if ( source <= 0x3fffff ) - { - if (_svp_cpu != NULL) - { - source -= 2; // the SVP introduces some kind of DMA 'lag', which we have to compensate for, this is obvious even on gfx DMAd from ROM (the Speedometer) - } - - // likewise segaCD, at least when reading wordram? - // we might need to check what mode we're in here.. - if (sega_cd_connected) - { - source -= 2; - } - + if (source <= 0x3fffff) return space68k.read_word(source); - } - else if (( source >= 0xe00000 ) && ( source <= 0xffffff )) - { + else if ((source >= 0xe00000) && (source <= 0xffffff)) return space68k.read_word(source); - } else { printf("DMA Read unmapped %06x\n",source); return machine.rand(); } - - } /* Table from Charles Macdonald diff --git a/src/mame/machine/megavdp.h b/src/mame/machine/megavdp.h index 0527f1dabd2..e5111427e48 100644 --- a/src/mame/machine/megavdp.h +++ b/src/mame/machine/megavdp.h @@ -154,6 +154,9 @@ extern void megadriv_reset_vdp(running_machine &machine); extern int genvdp_use_cram; +UINT16 vdp_get_word_from_68k_mem_default(running_machine &machine, UINT32 source, address_space & space68k); + + class sega_genesis_vdp_device : public sega315_5124_device { public: diff --git a/src/mess/drivers/megadriv.c b/src/mess/drivers/megadriv.c index ecf0507fbb9..ce3eb9c566e 100644 --- a/src/mess/drivers/megadriv.c +++ b/src/mess/drivers/megadriv.c @@ -271,17 +271,40 @@ INPUT_PORTS_END * *************************************/ + +UINT16 vdp_get_word_from_68k_mem_console(running_machine &machine, UINT32 source, address_space & space68k) +{ + md_cons_state *state = machine.driver_data(); + + if (source <= 0x3fffff) + { + if (state->m_slotcart->get_type() == SEGA_SVP) + { + source -= 2; // the SVP introduces some kind of DMA 'lag', which we have to compensate for, this is obvious even on gfx DMAd from ROM (the Speedometer) + } + return space68k.read_word(source); + } + else if ((source >= 0xe00000) && (source <= 0xffffff)) + return space68k.read_word(source); + else + { + printf("DMA Read unmapped %06x\n",source); + return machine.rand(); + } +} + static MACHINE_START( ms_megadriv ) { md_cons_state *state = machine.driver_data(); mess_init_6buttons_pad(machine); - + // small hack, until SVP is converted to be a slot device if (machine.device("svp") != NULL) svp_init(machine); else - { + { + vdp_get_word_from_68k_mem = vdp_get_word_from_68k_mem_console; machine.device("maincpu")->memory().space(AS_PROGRAM).install_readwrite_handler(0x000000, 0x7fffff, read16_delegate(FUNC(base_md_cart_slot_device::read),(base_md_cart_slot_device*)state->m_slotcart), write16_delegate(FUNC(base_md_cart_slot_device::write),(base_md_cart_slot_device*)state->m_slotcart)); machine.device("maincpu")->memory().space(AS_PROGRAM).install_readwrite_handler(0xa13000, 0xa130ff, read16_delegate(FUNC(base_md_cart_slot_device::read_a13),(base_md_cart_slot_device*)state->m_slotcart), write16_delegate(FUNC(base_md_cart_slot_device::write_a13),(base_md_cart_slot_device*)state->m_slotcart)); machine.device("maincpu")->memory().space(AS_PROGRAM).install_readwrite_handler(0xa15000, 0xa150ff, read16_delegate(FUNC(base_md_cart_slot_device::read_a15),(base_md_cart_slot_device*)state->m_slotcart), write16_delegate(FUNC(base_md_cart_slot_device::write_a15),(base_md_cart_slot_device*)state->m_slotcart)); diff --git a/src/mess/includes/md.h b/src/mess/includes/md.h index b32194529fa..c637098369a 100644 --- a/src/mess/includes/md.h +++ b/src/mess/includes/md.h @@ -58,7 +58,5 @@ public: ADDRESS_MAP_EXTERN( svp_ssp_map, driver_device ); ADDRESS_MAP_EXTERN( svp_ext_map, driver_device ); extern void svp_init(running_machine &machine); -extern cpu_device *_svp_cpu; - #endif diff --git a/src/mess/machine/md_slot.h b/src/mess/machine/md_slot.h index 9076e73bee6..c559dc23caf 100644 --- a/src/mess/machine/md_slot.h +++ b/src/mess/machine/md_slot.h @@ -163,6 +163,8 @@ public: // slot interface overrides virtual const char * get_default_card_software(const machine_config &config, emu_options &options); + int get_type() { return m_type; } + int load_list(); int load_nonlist(); int get_cart_type(UINT8 *ROM, UINT32 len);