Genesis-Plus-GX/source/memz80.c

188 lines
4.4 KiB
C
Raw Normal View History

2008-08-07 14:26:07 +02:00
/***************************************************************************************
* Genesis Plus
* 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)
* 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
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
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
}
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:
{
2008-08-07 14:26:07 +02:00
return zram[address & 0x1fff];
}
2008-08-07 14:26:07 +02:00
case 2: /* YM2612 */
{
return fm_read(mcycles_68k, address & 3);
}
2008-08-07 14:26:07 +02:00
case 3: /* VDP */
{
if ((address >> 8) == 0x7f)
{
return (*zbank_memory_map[0xc0].read)(address);
}
return z80_unused_r(address);
}
2008-08-07 14:26:07 +02:00
default: /* V-bus bank */
2008-12-04 20:32:22 +01:00
{
address = zbank | (address & 0x7fff);
unsigned int slot = address >> 16;
if (zbank_memory_map[slot].read)
{
return (*zbank_memory_map[slot].read)(address);
}
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:
{
2008-08-07 14:26:07 +02:00
zram[address & 0x1fff] = data;
return;
}
2008-08-07 14:26:07 +02:00
case 2: /* YM2612 */
{
fm_write(mcycles_z80, address & 3, data);
2008-08-07 14:26:07 +02:00
return;
}
2008-08-07 14:26:07 +02:00
case 3: /* Bank register and VDP */
{
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:
{
gen_zbank_w(data & 1);
2008-08-07 14:26:07 +02:00
return;
}
2008-08-07 14:26:07 +02:00
2008-12-04 20:32:22 +01:00
case 0x7f:
{
(*zbank_memory_map[0xc0].write)(address, data);
2008-08-07 14:26:07 +02:00
return;
}
2008-08-07 14:26:07 +02:00
default:
{
2008-08-07 14:26:07 +02:00
z80_unused_w(address, data);
return;
}
2008-08-07 14:26:07 +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);
unsigned int slot = address >> 16;
if (zbank_memory_map[slot].write)
{
(*zbank_memory_map[slot].write)(address, data);
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)
{
#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
return 0xff;
2008-08-07 14:26:07 +02:00
}
void cpu_writeport16(unsigned int port, unsigned int data)
{
#if LOGERROR
2008-08-07 14:26:07 +02:00
error("Z80 write %02X to port %04X\n", data, port);
#endif
}