2008-08-07 14:26:07 +02:00
|
|
|
/***************************************************************************************
|
2009-05-13 16:26:55 +02:00
|
|
|
* Genesis Plus
|
2010-06-14 10:05:45 +02:00
|
|
|
* Z80 bus address decoding (Genesis mode)
|
2008-08-07 14:26:07 +02:00
|
|
|
*
|
|
|
|
* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Charles Mac Donald (original code)
|
2009-05-13 16:26:55 +02:00
|
|
|
* Eke-Eke (2007,2008,2009), additional code & fixes for the GCN/Wii port
|
2008-08-07 14:26:07 +02:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
****************************************************************************************/
|
|
|
|
#include "shared.h"
|
|
|
|
|
|
|
|
/*
|
2008-12-10 19:16:30 +01:00
|
|
|
Handlers for access to unused addresses and those which make the
|
|
|
|
machine lock up.
|
2008-08-07 14:26:07 +02:00
|
|
|
*/
|
|
|
|
static inline void z80_unused_w(unsigned int address, unsigned int data)
|
|
|
|
{
|
|
|
|
#ifdef LOGERROR
|
|
|
|
error("Z80 unused write %04X = %02X\n", address, data);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline unsigned int z80_unused_r(unsigned int address)
|
|
|
|
{
|
|
|
|
#ifdef LOGERROR
|
|
|
|
error("Z80 unused read %04X\n", address);
|
|
|
|
#endif
|
2008-12-10 19:16:30 +01:00
|
|
|
return 0xff;
|
2008-08-07 14:26:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void z80_lockup_w(unsigned int address, unsigned int data)
|
|
|
|
{
|
|
|
|
#ifdef LOGERROR
|
|
|
|
error("Z80 lockup write %04X = %02X\n", address, data);
|
|
|
|
#endif
|
2010-05-30 20:42:03 +02:00
|
|
|
if (!config.force_dtack)
|
|
|
|
{
|
|
|
|
mcycles_z80 = 0xffffffff;
|
|
|
|
zstate = 0;
|
|
|
|
}
|
2008-08-07 14:26:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline unsigned int z80_lockup_r(unsigned int address)
|
|
|
|
{
|
|
|
|
#ifdef LOGERROR
|
|
|
|
error("Z80 lockup read %04X\n", address);
|
|
|
|
#endif
|
2010-05-30 20:42:03 +02:00
|
|
|
if (!config.force_dtack)
|
|
|
|
{
|
|
|
|
mcycles_z80 = 0xffffffff;
|
|
|
|
zstate = 0;
|
|
|
|
}
|
2008-12-10 19:16:30 +01:00
|
|
|
return 0xff;
|
2008-08-07 14:26:07 +02:00
|
|
|
}
|
2010-06-15 08:14:35 +02:00
|
|
|
|
|
|
|
|
2008-08-07 14:26:07 +02:00
|
|
|
/*
|
|
|
|
Z80 memory handlers
|
|
|
|
*/
|
|
|
|
unsigned int cpu_readmem16(unsigned int address)
|
|
|
|
{
|
|
|
|
switch((address >> 13) & 7)
|
|
|
|
{
|
|
|
|
case 0: /* Work RAM */
|
|
|
|
case 1:
|
2010-06-14 10:05:45 +02:00
|
|
|
{
|
2008-08-07 14:26:07 +02:00
|
|
|
return zram[address & 0x1fff];
|
2010-06-14 10:05:45 +02:00
|
|
|
}
|
2008-08-07 14:26:07 +02:00
|
|
|
|
|
|
|
case 2: /* YM2612 */
|
2010-06-14 10:05:45 +02:00
|
|
|
{
|
2010-01-24 12:41:53 +01:00
|
|
|
return fm_read(mcycles_68k, address & 3);
|
2010-06-14 10:05:45 +02:00
|
|
|
}
|
2008-08-07 14:26:07 +02:00
|
|
|
|
|
|
|
case 3: /* VDP */
|
2010-06-14 10:05:45 +02:00
|
|
|
{
|
2010-06-15 08:14:35 +02:00
|
|
|
if ((address >> 8) == 0x7f)
|
2010-06-14 10:05:45 +02:00
|
|
|
{
|
2010-06-15 08:14:35 +02:00
|
|
|
return (*zbank_memory_map[0xc0].read)(address);
|
2010-06-14 10:05:45 +02:00
|
|
|
}
|
2010-06-15 08:14:35 +02:00
|
|
|
return z80_unused_r(address);
|
2010-06-14 10:05:45 +02:00
|
|
|
}
|
|
|
|
|
2008-08-07 14:26:07 +02:00
|
|
|
default: /* V-bus bank */
|
2008-12-04 20:32:22 +01:00
|
|
|
{
|
|
|
|
address = zbank | (address & 0x7fff);
|
2010-06-14 10:05:45 +02:00
|
|
|
unsigned int slot = address >> 16;
|
2010-01-24 12:41:53 +01:00
|
|
|
if (zbank_memory_map[slot].read)
|
2010-06-14 10:05:45 +02:00
|
|
|
{
|
2010-01-24 12:41:53 +01:00
|
|
|
return (*zbank_memory_map[slot].read)(address);
|
2010-06-14 10:05:45 +02:00
|
|
|
}
|
|
|
|
return READ_BYTE(m68k_memory_map[slot].base, address & 0xffff);
|
2008-12-04 20:32:22 +01:00
|
|
|
}
|
2008-08-07 14:26:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void cpu_writemem16(unsigned int address, unsigned int data)
|
|
|
|
{
|
|
|
|
switch((address >> 13) & 7)
|
|
|
|
{
|
|
|
|
case 0: /* Work RAM */
|
|
|
|
case 1:
|
2010-06-14 10:05:45 +02:00
|
|
|
{
|
2008-08-07 14:26:07 +02:00
|
|
|
zram[address & 0x1fff] = data;
|
|
|
|
return;
|
2010-06-14 10:05:45 +02:00
|
|
|
}
|
2008-08-07 14:26:07 +02:00
|
|
|
|
|
|
|
case 2: /* YM2612 */
|
2010-06-14 10:05:45 +02:00
|
|
|
{
|
2010-01-24 12:41:53 +01:00
|
|
|
fm_write(mcycles_z80, address & 3, data);
|
2008-08-07 14:26:07 +02:00
|
|
|
return;
|
2010-06-14 10:05:45 +02:00
|
|
|
}
|
2008-08-07 14:26:07 +02:00
|
|
|
|
|
|
|
case 3: /* Bank register and VDP */
|
2010-06-14 10:05:45 +02:00
|
|
|
{
|
2008-12-04 20:32:22 +01:00
|
|
|
switch(address >> 8)
|
2008-08-07 14:26:07 +02:00
|
|
|
{
|
2008-12-04 20:32:22 +01:00
|
|
|
case 0x60:
|
2010-06-14 10:05:45 +02:00
|
|
|
{
|
|
|
|
gen_zbank_w(data & 1);
|
2008-08-07 14:26:07 +02:00
|
|
|
return;
|
2010-06-14 10:05:45 +02:00
|
|
|
}
|
2008-08-07 14:26:07 +02:00
|
|
|
|
2008-12-04 20:32:22 +01:00
|
|
|
case 0x7f:
|
2010-06-14 10:05:45 +02:00
|
|
|
{
|
|
|
|
(*zbank_memory_map[0xc0].write)(address, data);
|
2008-08-07 14:26:07 +02:00
|
|
|
return;
|
2010-06-14 10:05:45 +02:00
|
|
|
}
|
2008-08-07 14:26:07 +02:00
|
|
|
|
|
|
|
default:
|
2010-06-14 10:05:45 +02:00
|
|
|
{
|
2008-08-07 14:26:07 +02:00
|
|
|
z80_unused_w(address, data);
|
|
|
|
return;
|
2010-06-14 10:05:45 +02:00
|
|
|
}
|
2008-08-07 14:26:07 +02:00
|
|
|
}
|
2010-06-14 10:05:45 +02:00
|
|
|
}
|
2008-08-07 14:26:07 +02:00
|
|
|
|
|
|
|
default: /* V-bus bank */
|
2008-12-04 20:32:22 +01:00
|
|
|
{
|
|
|
|
address = zbank | (address & 0x7fff);
|
2010-06-14 10:05:45 +02:00
|
|
|
unsigned int slot = address >> 16;
|
2010-01-24 12:41:53 +01:00
|
|
|
if (zbank_memory_map[slot].write)
|
2010-06-14 10:05:45 +02:00
|
|
|
{
|
2010-01-24 12:41:53 +01:00
|
|
|
(*zbank_memory_map[slot].write)(address, data);
|
2010-06-14 10:05:45 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
WRITE_BYTE(m68k_memory_map[slot].base, address & 0xffff, data);
|
2008-08-07 14:26:07 +02:00
|
|
|
return;
|
2008-12-10 19:16:30 +01:00
|
|
|
}
|
2008-08-07 14:26:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2008-12-10 19:16:30 +01:00
|
|
|
Port handlers. Ports are unused when not in Mark III compatability mode.
|
2008-08-07 14:26:07 +02:00
|
|
|
|
2008-12-10 19:16:30 +01:00
|
|
|
Games that access ports anyway:
|
|
|
|
Thunder Force IV reads port $BF in it's interrupt handler.
|
2008-08-07 14:26:07 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
unsigned int cpu_readport16(unsigned int port)
|
|
|
|
{
|
2010-01-13 23:05:52 +01:00
|
|
|
#if LOGERROR
|
2008-08-07 14:26:07 +02:00
|
|
|
error("Z80 read port %04X\n", port);
|
2008-12-10 19:16:30 +01:00
|
|
|
#endif
|
2010-06-14 10:05:45 +02:00
|
|
|
return 0xff;
|
2008-08-07 14:26:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void cpu_writeport16(unsigned int port, unsigned int data)
|
|
|
|
{
|
2010-01-13 23:05:52 +01:00
|
|
|
#if LOGERROR
|
2008-08-07 14:26:07 +02:00
|
|
|
error("Z80 write %02X to port %04X\n", data, port);
|
|
|
|
#endif
|
|
|
|
}
|