Enable multiple h6280s

This commit is contained in:
iq_132 2012-01-26 04:39:01 +00:00
parent 74b0152ff8
commit b1cdb48a67
7 changed files with 204 additions and 143 deletions

View File

@ -3286,7 +3286,7 @@ static INT32 HippodrmInit()
SekSetWriteWordHandler(1, HippodrmShared68KWriteWord);
SekClose();
h6280Init(1);
h6280Init(0);
h6280Open(0);
h6280MapMemory(DrvH6280Rom , 0x000000, 0x00ffff, H6280_ROM);
h6280MapMemory(DrvSharedRam, 0x180000, 0x1800ff, H6280_RAM);
@ -3358,7 +3358,7 @@ static INT32 RobocopInit()
SekSetWriteWordHandler(1, RobocopShared68KWriteWord);
SekClose();
h6280Init(1);
h6280Init(0);
h6280Open(0);
h6280MapMemory(DrvH6280Rom , 0x000000, 0x00ffff, H6280_ROM);
h6280MapMemory(DrvH6280Ram , 0x1f0000, 0x1f1fff, H6280_RAM);
@ -3461,7 +3461,7 @@ static INT32 SlyspyDrvInit()
SekSetWriteWordHandler(0, Slyspy68KWriteWord);
SekClose();
h6280Init(1);
h6280Init(0);
h6280Open(0);
h6280MapMemory(DrvH6280Rom , 0x000000, 0x00ffff, H6280_ROM);
h6280MapMemory(DrvH6280Ram , 0x1f0000, 0x1f1fff, H6280_RAM);
@ -3664,7 +3664,7 @@ static INT32 MidresInit()
SekSetWriteWordHandler(0, Midres68KWriteWord);
SekClose();
h6280Init(1);
h6280Init(0);
h6280Open(0);
h6280MapMemory(DrvH6280Rom , 0x000000, 0x00ffff, H6280_ROM);
h6280MapMemory(DrvH6280Ram , 0x1f0000, 0x1f1fff, H6280_RAM);

View File

@ -846,7 +846,7 @@ void deco16SoundReset()
void deco16SoundInit(UINT8 *rom, UINT8 *ram, INT32 huc_clock, INT32 ym2203, void (ym2151_port)(UINT32,UINT32), double ym2151vol, INT32 msmclk0, double msmvol0, INT32 msmclk1, double msmvol1)
{
#ifdef ENABLE_HUC6280
h6280Init(1);
h6280Init(0);
h6280Open(0);
h6280MapMemory(rom, 0x000000, 0x00ffff, H6280_ROM);
h6280MapMemory(ram, 0x1f0000, 0x1f1fff, H6280_RAM);

View File

@ -545,7 +545,7 @@ static INT32 CommonInit(int type)
if (type == 0 || type == 1) // pce / tg-16
{
h6280Init(1);
h6280Init(0);
h6280Open(0);
h6280MapMemory(PCECartROM + 0x000000, 0x000000, 0x0fffff, H6280_ROM);
h6280MapMemory(PCEUserRAM + 0x000000, 0x1f0000, 0x1f1fff, H6280_RAM); // mirrored
@ -567,7 +567,7 @@ static INT32 CommonInit(int type)
}
else if (type == 2) // sgx
{
h6280Init(1);
h6280Init(0);
h6280Open(0);
h6280MapMemory(PCECartROM, 0x000000, 0x0fffff, H6280_ROM);
h6280MapMemory(PCEUserRAM, 0x1f0000, 0x1f7fff, H6280_RAM);

View File

@ -124,39 +124,7 @@
#define H6280_INLINE static
static int h6280_ICount = 0;
static unsigned int h6280_totalcycles = 0;
/****************************************************************************
* The 6280 registers.
****************************************************************************/
typedef struct
{
PAIR ppc; /* previous program counter */
PAIR pc; /* program counter */
PAIR sp; /* stack pointer (always 100 - 1FF) */
PAIR zp; /* zero page address */
PAIR ea; /* effective address */
UINT8 a; /* Accumulator */
UINT8 x; /* X index register */
UINT8 y; /* Y index register */
UINT8 p; /* Processor status */
UINT8 mmr[8]; /* Hu6280 memory mapper registers */
UINT8 irq_mask; /* interrupt enable/disable */
UINT8 timer_status; /* timer status */
UINT8 timer_ack; /* timer acknowledge */
UINT8 clocks_per_cycle; /* 4 = low speed mode, 1 = high speed mode */
INT32 timer_value; /* timer interrupt */
INT32 timer_load; /* reload value */
UINT8 nmi_state;
UINT8 irq_state[3];
UINT8 irq_pending;
int (*irq_callback)(int irqline);
#if LAZY_FLAGS
INT32 NZ; /* last value (lazy N and Z flag) */
#endif
UINT8 io_buffer; /* last value written to the PSG, timer, and interrupt pages */
} h6280_Regs;
//static unsigned int h6280_totalcycles = 0;
static h6280_Regs h6280;
@ -243,7 +211,7 @@ void h6280Reset(void)
h6280.irq_pending = 0;
h6280_totalcycles = 0;
h6280.h6280_totalcycles = 0;
}
#if 0
@ -261,6 +229,7 @@ int h6280Run(int cycles)
int in;
h6280_ICount = cycles;
h6280.h6280_iCycles = cycles;
if ( h6280.irq_pending == 2 ) {
h6280.irq_pending--;
@ -305,23 +274,25 @@ int h6280Run(int cycles)
}
} while (h6280_ICount > 0);
h6280_totalcycles += cycles - h6280_ICount;
h6280.h6280_totalcycles += cycles - h6280_ICount;
h6280_ICount = 0;
h6280.h6280_iCycles = 0;
return cycles - h6280_ICount;
}
//static void h6280_get_context (void *dst)
//{
// if( dst )
// *(h6280_Regs*)dst = h6280;
//}
void h6280_get_context(void *dst)
{
if( dst )
*(h6280_Regs*)dst = h6280;
}
//static void h6280_set_context (void *src)
//{
// if( src )
// h6280 = *(h6280_Regs*)src;
// CHANGE_PC;
//}
void h6280_set_context(void *src)
{
if( src )
h6280 = *(h6280_Regs*)src;
CHANGE_PC;
}
int h6280TotalCycles()
{
@ -329,16 +300,7 @@ int h6280TotalCycles()
if (!DebugCPU_H6280Initted) bprintf(PRINT_ERROR, _T("h6280TotalCycles called without init\n"));
#endif
return h6280_totalcycles;
}
void h6280NewFrame()
{
#if defined FBA_DEBUG
if (!DebugCPU_H6280Initted) bprintf(PRINT_ERROR, _T("h6280NewFrame called without init\n"));
#endif
h6280_totalcycles = 0;
return h6280.h6280_totalcycles;
}
void h6280RunEnd()
@ -480,31 +442,6 @@ void h6280io_set_buffer(UINT8 data)
h6280.io_buffer=data;
}
INT32 h6280CpuScan(INT32 nAction)
{
struct BurnArea ba;
if (nAction & ACB_DRIVER_DATA) {
h6280_Regs *p = &h6280;
int (*irq_callback)(int);
irq_callback = h6280.irq_callback;
memset(&ba, 0, sizeof(ba));
ba.Data = p;
ba.nLen = sizeof(h6280_Regs);
ba.szName = "h6280 Registers";
BurnAcb(&ba);
h6280.irq_callback = irq_callback;
SCAN_VAR(h6280_ICount);
SCAN_VAR(h6280_totalcycles);
}
return 0;
}
#if 0
/*****************************************************************************/

View File

@ -15,7 +15,46 @@
#ifndef __H6280_H__
#define __H6280_H__
//#include "cpuintrf.h"
#define LAZY_FLAGS 0
/****************************************************************************
* The 6280 registers.
****************************************************************************/
typedef struct
{
PAIR ppc; /* previous program counter */
PAIR pc; /* program counter */
PAIR sp; /* stack pointer (always 100 - 1FF) */
PAIR zp; /* zero page address */
PAIR ea; /* effective address */
UINT8 a; /* Accumulator */
UINT8 x; /* X index register */
UINT8 y; /* Y index register */
UINT8 p; /* Processor status */
UINT8 mmr[8]; /* Hu6280 memory mapper registers */
UINT8 irq_mask; /* interrupt enable/disable */
UINT8 timer_status; /* timer status */
UINT8 timer_ack; /* timer acknowledge */
UINT8 clocks_per_cycle; /* 4 = low speed mode, 1 = high speed mode */
INT32 timer_value; /* timer interrupt */
INT32 timer_load; /* reload value */
UINT8 nmi_state;
UINT8 irq_state[3];
UINT8 irq_pending;
int (*irq_callback)(int irqline);
unsigned int h6280_iCycles;
unsigned int h6280_totalcycles;
#if LAZY_FLAGS
INT32 NZ; /* last value (lazy N and Z flag) */
#endif
UINT8 io_buffer; /* last value written to the PSG, timer, and interrupt pages */
} h6280_Regs;
void h6280_set_context(void *ptr);
void h6280_get_context(void *ptr);
enum
{
@ -26,8 +65,6 @@ enum
H6280_M5, H6280_M6, H6280_M7, H6280_M8
};
#define LAZY_FLAGS 0
#define H6280_RESET_VEC 0xfffe
#define H6280_NMI_VEC 0xfffc
#define H6280_TIMER_VEC 0xfffa

View File

@ -1,6 +1,9 @@
#include "burnint.h"
#include "h6280.h"
#include "h6280_intf.h"
#define MAX_H6280 2 //
#define MEMORY_SPACE 0x200000
#define PAGE_SIZE 0x800
#define PAGE_MASK 0x7ff
@ -11,16 +14,23 @@
#define WRITE 1
#define FETCH 2
struct h6280_handler
{
UINT8 (*h6280Read)(UINT32 address);
void (*h6280Write)(UINT32 address, UINT8 data);
void (*h6280WriteIO)(UINT8 port, UINT8 data);
INT32 (*irqcallback)(INT32);
UINT8 *mem[3][PAGE_COUNT];
h6280_Regs *h6280;
};
static struct h6280_handler sHandler[MAX_H6280];
static struct h6280_handler *sPointer;
INT32 nh6280CpuCount = 0;
static INT32 nh6280CpuActive = -1;
static UINT8 *mem[3][PAGE_COUNT];
static UINT8 (*h6280Read)(UINT32 address);
static void (*h6280Write)(UINT32 address, UINT8 data);
static void (*h6280WriteIO)(UINT8 port, UINT8 data);
static INT32 (*irqcallback)(INT32);
void h6280MapMemory(UINT8 *src, UINT32 start, UINT32 finish, INT32 type)
{
#if defined FBA_DEBUG
@ -32,9 +42,9 @@ void h6280MapMemory(UINT8 *src, UINT32 start, UINT32 finish, INT32 type)
for (UINT32 i = 0; i < len+1; i++)
{
UINT32 offset = i + (start >> PAGE_SHIFT);
if (type & (1 << READ)) mem[ READ][offset] = src + (i << PAGE_SHIFT);
if (type & (1 << WRITE)) mem[WRITE][offset] = src + (i << PAGE_SHIFT);
if (type & (1 << FETCH)) mem[FETCH][offset] = src + (i << PAGE_SHIFT);
if (type & (1 << READ)) sPointer->mem[ READ][offset] = src + (i << PAGE_SHIFT);
if (type & (1 << WRITE)) sPointer->mem[WRITE][offset] = src + (i << PAGE_SHIFT);
if (type & (1 << FETCH)) sPointer->mem[FETCH][offset] = src + (i << PAGE_SHIFT);
}
}
@ -49,7 +59,7 @@ void h6280SetIrqCallbackHandler(INT32 (*callback)(INT32))
if (!DebugCPU_H6280Initted) bprintf(PRINT_ERROR, _T("h6280SetIrqCallbackHandler called without init\n"));
#endif
irqcallback = callback;
sPointer->irqcallback = callback;
}
void h6280SetWriteHandler(void (*write)(UINT32, UINT8))
@ -58,7 +68,7 @@ void h6280SetWriteHandler(void (*write)(UINT32, UINT8))
if (!DebugCPU_H6280Initted) bprintf(PRINT_ERROR, _T("h6280SetWriteHandler called without init\n"));
#endif
h6280Write = write;
sPointer->h6280Write = write;
}
void h6280SetWritePortHandler(void (*write)(UINT8, UINT8))
@ -67,7 +77,7 @@ void h6280SetWritePortHandler(void (*write)(UINT8, UINT8))
if (!DebugCPU_H6280Initted) bprintf(PRINT_ERROR, _T("h6280SetWritePortHandler called without init\n"));
#endif
h6280WriteIO = write;
sPointer->h6280WriteIO = write;
}
void h6280SetReadHandler(UINT8 (*read)(UINT32))
@ -76,7 +86,7 @@ void h6280SetReadHandler(UINT8 (*read)(UINT32))
if (!DebugCPU_H6280Initted) bprintf(PRINT_ERROR, _T("h6280SetReadHandler called without init\n"));
#endif
h6280Read = read;
sPointer->h6280Read = read;
}
void h6280_write_rom(UINT32 address, UINT8 data)
@ -85,20 +95,22 @@ void h6280_write_rom(UINT32 address, UINT8 data)
if (!DebugCPU_H6280Initted) bprintf(PRINT_ERROR, _T("h6280_write_rom called without init\n"));
#endif
if (mem[READ][address >> PAGE_SHIFT] != NULL) {
mem[READ][address >> PAGE_SHIFT][address & PAGE_MASK] = data;
address &= 0x1fffff;
if (sPointer->mem[READ][address >> PAGE_SHIFT] != NULL) {
sPointer->mem[READ][address >> PAGE_SHIFT][address & PAGE_MASK] = data;
}
if (mem[FETCH][address >> PAGE_SHIFT] != NULL) {
mem[FETCH][address >> PAGE_SHIFT][address & PAGE_MASK] = data;
if (sPointer->mem[FETCH][address >> PAGE_SHIFT] != NULL) {
sPointer->mem[FETCH][address >> PAGE_SHIFT][address & PAGE_MASK] = data;
}
if (mem[WRITE][address >> PAGE_SHIFT] != NULL) {
mem[WRITE][address >> PAGE_SHIFT][address & PAGE_MASK] = data;
if (sPointer->mem[WRITE][address >> PAGE_SHIFT] != NULL) {
sPointer->mem[WRITE][address >> PAGE_SHIFT][address & PAGE_MASK] = data;
}
if (h6280Write != NULL) {
h6280Write(address, data);
if (sPointer->h6280Write != NULL) {
sPointer->h6280Write(address, data);
}
}
@ -110,8 +122,8 @@ void h6280_write_port(UINT8 port, UINT8 data)
// bprintf (0, _T("%5.5x write port\n"), port);
if (h6280WriteIO != NULL) {
h6280WriteIO(port, data);
if (sPointer->h6280WriteIO != NULL) {
sPointer->h6280WriteIO(port, data);
return;
}
@ -124,15 +136,17 @@ void h6280_write(UINT32 address, UINT8 data)
if (!DebugCPU_H6280Initted) bprintf(PRINT_ERROR, _T("h6280_write called without init\n"));
#endif
address &= 0x1fffff;
// bprintf (0, _T("%5.5x write\n"), address);
if (mem[WRITE][address >> PAGE_SHIFT] != NULL) {
mem[WRITE][address >> PAGE_SHIFT][address & PAGE_MASK] = data;
if (sPointer->mem[WRITE][address >> PAGE_SHIFT] != NULL) {
sPointer->mem[WRITE][address >> PAGE_SHIFT][address & PAGE_MASK] = data;
return;
}
if (h6280Write != NULL) {
h6280Write(address, data);
if (sPointer->h6280Write != NULL) {
sPointer->h6280Write(address, data);
return;
}
@ -145,14 +159,16 @@ UINT8 h6280_read(UINT32 address)
if (!DebugCPU_H6280Initted) bprintf(PRINT_ERROR, _T("h6280_read called without init\n"));
#endif
address &= 0x1fffff;
// bprintf (0, _T("%5.5x read\n"), address);
if (mem[ READ][address >> PAGE_SHIFT] != NULL) {
return mem[ READ][address >> PAGE_SHIFT][address & PAGE_MASK];
if (sPointer->mem[ READ][address >> PAGE_SHIFT] != NULL) {
return sPointer->mem[ READ][address >> PAGE_SHIFT][address & PAGE_MASK];
}
if (h6280Read != NULL) {
return h6280Read(address);
if (sPointer->h6280Read != NULL) {
return sPointer->h6280Read(address);
}
return 0;
@ -164,27 +180,29 @@ UINT8 h6280_fetch1(UINT32 address)
if (!DebugCPU_H6280Initted) bprintf(PRINT_ERROR, _T("h6280_fetch1 called without init\n"));
#endif
// address &= 0xffff;
address &= 0x1fffff;
if (mem[FETCH][address >> PAGE_SHIFT] != NULL) {
return mem[FETCH][address >> PAGE_SHIFT][address & PAGE_MASK];
if (sPointer->mem[FETCH][address >> PAGE_SHIFT] != NULL) {
return sPointer->mem[FETCH][address >> PAGE_SHIFT][address & PAGE_MASK];
}
if (h6280Read != NULL) {
return h6280Read(address);
if (sPointer->h6280Read != NULL) {
return sPointer->h6280Read(address);
}
return 0;
}
UINT8 h6280_fetch(UINT32 a)
UINT8 h6280_fetch(UINT32 address)
{
#if defined FBA_DEBUG
if (!DebugCPU_H6280Initted) bprintf(PRINT_ERROR, _T("h6280_fetch called without init\n"));
#endif
// bprintf (0, _T("%5.5x %5.5x, %2.2x fetch\n"), a, a&0xffff, h6280_fetch1(a));
return h6280_fetch1(a);
address &= 0x1fffff;
// bprintf (0, _T("%5.5x %5.5x, %2.2x fetch\n"), address, address&0xffff, h6280_fetch1(address));
return h6280_fetch1(address);
}
void h6280SetIRQLine(INT32 line, INT32 state)
@ -202,24 +220,27 @@ void h6280SetIRQLine(INT32 line, INT32 state)
}
}
void h6280Init(INT32 num) // only 1 cpu (No examples exist of multi-cpu h6280 games)
void h6280Init(INT32 nCpu)
{
DebugCPU_H6280Initted = 1;
nh6280CpuCount = 1;
// h6280_init(h6280DummyIrqCallback);
sPointer = &sHandler[nCpu % MAX_H6280];
sPointer->h6280 = (h6280_Regs*)BurnMalloc(sizeof(h6280_Regs));
if (nCpu >= nh6280CpuCount) nh6280CpuCount = nCpu+1;
for (INT32 i = 0; i < 3; i++) {
for (INT32 j = 0; j < (MEMORY_SPACE / PAGE_SIZE); j++) {
mem[i][j] = NULL;
sPointer->mem[i][j] = NULL;
}
}
h6280Write = NULL;
h6280Read = NULL;
h6280WriteIO = NULL;
sPointer->h6280Write = NULL;
sPointer->h6280Read = NULL;
sPointer->h6280WriteIO = NULL;
CpuCheatRegister(0x0009, num);
CpuCheatRegister(0x0009, nCpu);
}
void h6280Exit()
@ -228,11 +249,19 @@ void h6280Exit()
if (!DebugCPU_H6280Initted) bprintf(PRINT_ERROR, _T("h6280Exit called without init\n"));
#endif
for (INT32 i = 0; i < MAX_H6280; i++) {
sPointer = &sHandler[i];
sPointer->h6280Write = NULL;
sPointer->h6280Read = NULL;
sPointer->h6280WriteIO = NULL;
if (sPointer->h6280) {
BurnFree(sPointer->h6280);
}
}
nh6280CpuCount = 0;
h6280Write = NULL;
h6280Read = NULL;
h6280WriteIO = NULL;
DebugCPU_H6280Initted = 0;
}
@ -242,6 +271,10 @@ void h6280Open(INT32 num)
if (!DebugCPU_H6280Initted) bprintf(PRINT_ERROR, _T("h6280Open called without init\n"));
#endif
sPointer = &sHandler[num % MAX_H6280];
h6280_set_context(sPointer->h6280);
nh6280CpuActive = num;
}
@ -251,6 +284,10 @@ void h6280Close()
if (!DebugCPU_H6280Initted) bprintf(PRINT_ERROR, _T("h6280Close called without init\n"));
#endif
h6280_get_context(sPointer->h6280);
// sPointer = NULL; // not safe...
nh6280CpuActive = -1;
}
@ -263,3 +300,49 @@ INT32 h6280GetActive()
return nh6280CpuActive;
}
void h6280NewFrame()
{
#if defined FBA_DEBUG
if (!DebugCPU_H6280Initted) bprintf(PRINT_ERROR, _T("h6280NewFrame called without init\n"));
#endif
h6280_handler *ptr;
for (INT32 i = 0; i < MAX_H6280; i++)
{
ptr = &sHandler[i % MAX_H6280];
sHandler->h6280->h6280_totalcycles = 0;
}
}
INT32 h6280CpuScan(INT32 nAction)
{
struct BurnArea ba;
char name[128];
if (nAction & ACB_DRIVER_DATA) {
for (INT32 i = 0; i < MAX_H6280; i++)
{
h6280_handler *ptr = &sHandler[i];
h6280_Regs *p = ptr->h6280;
if (p == NULL) continue;
int (*irq_callback)(int);
irq_callback = p->irq_callback;
memset(&ba, 0, sizeof(ba));
ba.Data = p;
ba.nLen = sizeof(h6280_Regs);
sprintf (name, "h6280 Registers for Chip #%d", i);
ba.szName = name;
BurnAcb(&ba);
p->irq_callback = irq_callback;
}
}
return 0;
}

View File

@ -61,3 +61,7 @@ void h6280_timer_w(UINT32 offset, UINT8 data);
UINT8 h6280io_get_buffer(void);
void h6280io_set_buffer(UINT8);
// internal