2011-07-12 04:57:12 +00:00
|
|
|
/**
|
|
|
|
** Supermodel
|
|
|
|
** A Sega Model 3 Arcade Emulator.
|
|
|
|
** Copyright 2011 Bart Trzynadlowski
|
|
|
|
**
|
|
|
|
** This file is part of Supermodel.
|
|
|
|
**
|
|
|
|
** Supermodel 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 3 of the License, or (at your option)
|
|
|
|
** any later version.
|
|
|
|
**
|
|
|
|
** Supermodel 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 Supermodel. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
**/
|
|
|
|
|
|
|
|
/*
|
2011-07-31 02:37:31 +00:00
|
|
|
* 68K.cpp
|
2011-07-12 04:57:12 +00:00
|
|
|
*
|
|
|
|
* 68K CPU interface. This is presently just a wrapper for the Musashi 68K core
|
|
|
|
* and therefore, only a single CPU is supported. In the future, we may want to
|
|
|
|
* add in another 68K core (eg., Turbo68K, A68K, or a recompiler).
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "Supermodel.h"
|
|
|
|
#include "Musashi/m68k.h" // Musashi 68K core
|
|
|
|
|
2011-07-31 02:37:31 +00:00
|
|
|
|
2011-07-12 04:57:12 +00:00
|
|
|
/******************************************************************************
|
2011-07-31 02:37:31 +00:00
|
|
|
Internal Context
|
|
|
|
|
|
|
|
An active context must be mapped before calling M68K interface functions. Only
|
|
|
|
the bus and IRQ handlers are copied here; the CPU context is passed directly
|
|
|
|
to Musashi.
|
2011-07-12 04:57:12 +00:00
|
|
|
******************************************************************************/
|
|
|
|
|
2011-07-31 02:37:31 +00:00
|
|
|
// Bus
|
|
|
|
static CBus *Bus = NULL;
|
2011-07-12 04:57:12 +00:00
|
|
|
|
2011-07-31 02:37:31 +00:00
|
|
|
// IRQ callback
|
|
|
|
static int (*IRQAck)(int nIRQ) = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
68K Interface
|
|
|
|
******************************************************************************/
|
2011-07-12 04:57:12 +00:00
|
|
|
|
2011-07-31 02:37:31 +00:00
|
|
|
// CPU state
|
|
|
|
|
2011-07-12 04:57:12 +00:00
|
|
|
UINT32 M68KGetARegister(int n)
|
|
|
|
{
|
|
|
|
m68k_register_t r;
|
|
|
|
|
|
|
|
switch (n)
|
|
|
|
{
|
|
|
|
case 0: r = M68K_REG_A0; break;
|
|
|
|
case 1: r = M68K_REG_A1; break;
|
|
|
|
case 2: r = M68K_REG_A2; break;
|
|
|
|
case 3: r = M68K_REG_A3; break;
|
|
|
|
case 4: r = M68K_REG_A4; break;
|
|
|
|
case 5: r = M68K_REG_A5; break;
|
|
|
|
case 6: r = M68K_REG_A6; break;
|
|
|
|
case 7: r = M68K_REG_A7; break;
|
|
|
|
default: r = M68K_REG_A7; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return m68k_get_reg(NULL, r);
|
|
|
|
}
|
|
|
|
|
|
|
|
UINT32 M68KGetDRegister(int n)
|
|
|
|
{
|
|
|
|
m68k_register_t r;
|
|
|
|
|
|
|
|
switch (n)
|
|
|
|
{
|
|
|
|
case 0: r = M68K_REG_D0; break;
|
|
|
|
case 1: r = M68K_REG_D1; break;
|
|
|
|
case 2: r = M68K_REG_D2; break;
|
|
|
|
case 3: r = M68K_REG_D3; break;
|
|
|
|
case 4: r = M68K_REG_D4; break;
|
|
|
|
case 5: r = M68K_REG_D5; break;
|
|
|
|
case 6: r = M68K_REG_D6; break;
|
|
|
|
case 7: r = M68K_REG_D7; break;
|
|
|
|
default: r = M68K_REG_D7; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return m68k_get_reg(NULL, r);
|
|
|
|
}
|
|
|
|
|
|
|
|
UINT32 M68KGetPC(void)
|
|
|
|
{
|
|
|
|
return m68k_get_reg(NULL, M68K_REG_PC);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Emulation functions
|
|
|
|
|
|
|
|
void M68KSetIRQ(int irqLevel)
|
|
|
|
{
|
|
|
|
m68k_set_irq(irqLevel);
|
|
|
|
}
|
|
|
|
|
|
|
|
int M68KRun(int numCycles)
|
|
|
|
{
|
|
|
|
return m68k_execute(numCycles);
|
|
|
|
}
|
|
|
|
|
|
|
|
void M68KReset(void)
|
|
|
|
{
|
|
|
|
m68k_pulse_reset();
|
2011-07-31 02:37:31 +00:00
|
|
|
DebugLog("68K reset\n");
|
2011-07-12 04:57:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Callback setup
|
|
|
|
|
|
|
|
void M68KSetIRQCallback(int (*F)(int nIRQ))
|
|
|
|
{
|
|
|
|
IRQAck = F;
|
|
|
|
}
|
|
|
|
|
2011-07-31 02:37:31 +00:00
|
|
|
void M68KAttachBus(CBus *BusPtr)
|
2011-07-12 04:57:12 +00:00
|
|
|
{
|
2011-07-31 02:37:31 +00:00
|
|
|
Bus = BusPtr;
|
|
|
|
DebugLog("Attached bus to 68K\n");
|
2011-07-12 04:57:12 +00:00
|
|
|
}
|
|
|
|
|
2011-07-31 02:37:31 +00:00
|
|
|
// Context switching
|
2011-07-12 04:57:12 +00:00
|
|
|
|
2011-07-31 02:37:31 +00:00
|
|
|
void M68KGetContext(M68KCtx *Dest)
|
2011-07-12 04:57:12 +00:00
|
|
|
{
|
2011-07-31 02:37:31 +00:00
|
|
|
Dest->IRQAck = IRQAck;
|
|
|
|
Dest->Bus = Bus;
|
|
|
|
m68k_get_context(Dest->musashiCtx);
|
2011-07-12 04:57:12 +00:00
|
|
|
}
|
|
|
|
|
2011-07-31 02:37:31 +00:00
|
|
|
void M68KSetContext(M68KCtx *Src)
|
2011-07-12 04:57:12 +00:00
|
|
|
{
|
2011-07-31 02:37:31 +00:00
|
|
|
IRQAck = Src->IRQAck;
|
|
|
|
Bus = Src->Bus;
|
|
|
|
m68k_set_context(Src->musashiCtx);
|
2011-07-12 04:57:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// One-time initialization
|
|
|
|
|
|
|
|
BOOL M68KInit(void)
|
|
|
|
{
|
|
|
|
m68k_init();
|
|
|
|
m68k_set_cpu_type(M68K_CPU_TYPE_68000);
|
|
|
|
m68k_set_int_ack_callback(M68KIRQCallback);
|
2011-07-31 02:37:31 +00:00
|
|
|
Bus = NULL;
|
|
|
|
|
|
|
|
DebugLog("Initialized 68K\n");
|
2011-07-12 04:57:12 +00:00
|
|
|
return OKAY;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
Musashi 68K Handlers
|
|
|
|
|
|
|
|
Musashi/m68kconf.h has been configured to call these directly.
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
|
|
|
|
int M68KIRQCallback(int nIRQ)
|
|
|
|
{
|
2011-07-31 02:37:31 +00:00
|
|
|
if (NULL == IRQAck) // no handler, use default behavior
|
|
|
|
{
|
|
|
|
m68k_set_irq(0); // clear line
|
2011-07-12 04:57:12 +00:00
|
|
|
return M68K_IRQ_AUTOVECTOR;
|
2011-07-31 02:37:31 +00:00
|
|
|
}
|
2011-07-12 04:57:12 +00:00
|
|
|
else
|
|
|
|
return IRQAck(nIRQ);
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int FASTCALL M68KFetch8(unsigned int a)
|
|
|
|
{
|
2011-07-31 02:37:31 +00:00
|
|
|
return Bus->Read8(a);
|
2011-07-12 04:57:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int FASTCALL M68KFetch16(unsigned int a)
|
|
|
|
{
|
2011-07-31 02:37:31 +00:00
|
|
|
return Bus->Read16(a);
|
2011-07-12 04:57:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int FASTCALL M68KFetch32(unsigned int a)
|
|
|
|
{
|
2011-07-31 02:37:31 +00:00
|
|
|
return Bus->Read32(a);
|
2011-07-12 04:57:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int FASTCALL M68KRead8(unsigned int a)
|
|
|
|
{
|
2011-07-31 02:37:31 +00:00
|
|
|
return Bus->Read8(a);
|
2011-07-12 04:57:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int FASTCALL M68KRead16(unsigned int a)
|
|
|
|
{
|
2011-07-31 02:37:31 +00:00
|
|
|
return Bus->Read16(a);
|
2011-07-12 04:57:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int FASTCALL M68KRead32(unsigned int a)
|
|
|
|
{
|
2011-07-31 02:37:31 +00:00
|
|
|
return Bus->Read32(a);
|
2011-07-12 04:57:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FASTCALL M68KWrite8(unsigned int a, unsigned int d)
|
|
|
|
{
|
2011-07-31 02:37:31 +00:00
|
|
|
Bus->Write8(a, d);
|
2011-07-12 04:57:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FASTCALL M68KWrite16(unsigned int a, unsigned int d)
|
|
|
|
{
|
2011-07-31 02:37:31 +00:00
|
|
|
Bus->Write16(a, d);
|
2011-07-12 04:57:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FASTCALL M68KWrite32(unsigned int a, unsigned int d)
|
|
|
|
{
|
2011-07-31 02:37:31 +00:00
|
|
|
Bus->Write32(a, d);
|
2011-07-12 04:57:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // extern "C"
|