Genesis-Plus-GX/source/memz80.c

222 lines
5.5 KiB
C
Raw Normal View History

2008-08-07 14:26:07 +02:00
/***************************************************************************************
* Genesis Plus 1.2a
* Z80 memory handler
*
* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Charles Mac Donald (original code)
* modified by Eke-Eke (compatibility fixes & additional code), GC/Wii port
*
* 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"
#define LOG_PORT 0 /* 1= Log Z80 I/O port accesses */
/*
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
2008-12-10 19:16:30 +01:00
gen_running = config.force_dtack;
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
2008-12-10 19:16:30 +01:00
gen_running = config.force_dtack;
return 0xff;
2008-08-07 14:26:07 +02:00
}
/*
VDP access
*/
static inline unsigned int z80_vdp_r(unsigned int address)
{
2008-12-04 20:32:22 +01:00
switch (address & 0xfd)
2008-08-07 14:26:07 +02:00
{
2008-12-04 20:32:22 +01:00
case 0x00: /* DATA */
return (vdp_data_r() >> 8);
2008-08-07 14:26:07 +02:00
2008-12-04 20:32:22 +01:00
case 0x01: /* DATA */
2008-08-07 14:26:07 +02:00
return (vdp_data_r() & 0xff);
2008-12-04 20:32:22 +01:00
case 0x04: /* CTRL */
2008-08-07 14:26:07 +02:00
return (0xfc | ((vdp_ctrl_r() >> 8) & 3));
2008-12-04 20:32:22 +01:00
case 0x05: /* CTRL */
2008-08-07 14:26:07 +02:00
return (vdp_ctrl_r() & 0xff);
2008-12-04 20:32:22 +01:00
case 0x08: /* HVC */
2008-08-07 14:26:07 +02:00
case 0x0c:
2008-12-04 20:32:22 +01:00
return (vdp_hvc_r() >> 8);
2008-08-07 14:26:07 +02:00
2008-12-04 20:32:22 +01:00
case 0x09: /* HVC */
2008-08-07 14:26:07 +02:00
case 0x0d:
return (vdp_hvc_r() & 0xff);
2008-12-10 19:16:30 +01:00
case 0x18: /* Unused */
case 0x19:
2008-12-04 20:32:22 +01:00
case 0x1c:
2008-12-10 19:16:30 +01:00
case 0x1d:
return z80_unused_r(address);
2008-08-07 14:26:07 +02:00
2008-12-04 20:32:22 +01:00
default: /* Invalid address */
2008-12-10 19:16:30 +01:00
return z80_lockup_r(address);
}
2008-08-07 14:26:07 +02:00
}
static inline void z80_vdp_w(unsigned int address, unsigned int data)
{
2008-12-04 20:32:22 +01:00
switch (address & 0xfc)
2008-08-07 14:26:07 +02:00
{
2008-12-10 19:16:30 +01:00
case 0x00: /* Data port */
2008-08-07 14:26:07 +02:00
vdp_data_w(data << 8 | data);
return;
2008-12-10 19:16:30 +01:00
case 0x04: /* Control port */
2008-08-07 14:26:07 +02:00
vdp_ctrl_w(data << 8 | data);
return;
2008-12-10 19:16:30 +01:00
case 0x10: /* PSG */
2008-12-04 20:32:22 +01:00
case 0x14:
if (address & 1) psg_write(0, data);
else z80_unused_w(address, data);
2008-12-10 19:16:30 +01:00
return;
2008-08-07 14:26:07 +02:00
2008-12-04 20:32:22 +01:00
case 0x18: /* Unused */
2008-08-07 14:26:07 +02:00
z80_unused_w(address, data);
return;
case 0x1c: /* Test register */
vdp_test_w(data << 8 | data);
return;
2008-12-10 19:16:30 +01:00
default: /* Invalid address */
2008-08-07 14:26:07 +02:00
z80_lockup_w(address, data);
return;
}
}
/*
Z80 memory handlers
*/
unsigned int cpu_readmem16(unsigned int address)
{
switch((address >> 13) & 7)
{
case 0: /* Work RAM */
case 1:
return zram[address & 0x1fff];
case 2: /* YM2612 */
return fm_read(1, address & 3);
case 3: /* VDP */
2008-12-04 20:32:22 +01:00
if ((address >> 8) == 0x7f) return z80_vdp_r (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);
int slot = address >> 16;
if (zbank_memory_map[slot].read) return (*zbank_memory_map[slot].read)(address);
else return READ_BYTE(m68k_memory_map[slot].base, address&0xffff);
}
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:
zram[address & 0x1fff] = data;
return;
case 2: /* YM2612 */
fm_write(1, address & 3, data);
return;
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:
2008-08-07 14:26:07 +02:00
gen_bank_w(data & 1);
return;
2008-12-04 20:32:22 +01:00
case 0x7f:
2008-08-07 14:26:07 +02:00
z80_vdp_w(address, data);
return;
default:
z80_unused_w(address, data);
return;
}
return;
default: /* V-bus bank */
2008-12-04 20:32:22 +01:00
{
address = zbank | (address & 0x7fff);
int slot = address >> 16;
if (zbank_memory_map[slot].write) (*zbank_memory_map[slot].write)(address, data);
else 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 LOG_PORT
error("Z80 read port %04X\n", port);
2008-12-10 19:16:30 +01:00
#endif
2008-08-07 14:26:07 +02:00
return 0xFF;
}
void cpu_writeport16(unsigned int port, unsigned int data)
{
#if LOG_PORT
error("Z80 write %02X to port %04X\n", data, port);
#endif
}