From a70210d12994c2467c85dcddae49cacdc4e54059 Mon Sep 17 00:00:00 2001 From: iq_132 <1191709+iq132@users.noreply.github.com> Date: Thu, 22 Dec 2011 20:37:21 +0000 Subject: [PATCH] Change HD6309Init(num) to HD6309Init(nCPU). Initialize a single CPU at a time. --- src/burn/drivers/konami/d_mainevt.cpp | 2 +- src/burn/drivers/misc_pre90s/d_ddragon.cpp | 9 +- src/burn/drivers/misc_pre90s/d_dec8.cpp | 7 +- src/cpu/hd6309_intf.cpp | 104 +++++++++++---------- src/cpu/hd6309_intf.h | 2 +- 5 files changed, 65 insertions(+), 59 deletions(-) diff --git a/src/burn/drivers/konami/d_mainevt.cpp b/src/burn/drivers/konami/d_mainevt.cpp index e4adba0cc..c68c5ce30 100644 --- a/src/burn/drivers/konami/d_mainevt.cpp +++ b/src/burn/drivers/konami/d_mainevt.cpp @@ -725,7 +725,7 @@ static INT32 DrvInit(INT32 type) DrvGfxDecode(gfx0_offset * 2); } - HD6309Init(1); + HD6309Init(0); HD6309Open(0); HD6309MapMemory(DrvHD6309RAM, 0x4000, 0x5fff, HD6309_RAM); HD6309MapMemory(DrvHD6309ROM + 0x10000, 0x6000, 0x7fff, HD6309_ROM); diff --git a/src/burn/drivers/misc_pre90s/d_ddragon.cpp b/src/burn/drivers/misc_pre90s/d_ddragon.cpp index dfb33d928..7e3338afa 100644 --- a/src/burn/drivers/misc_pre90s/d_ddragon.cpp +++ b/src/burn/drivers/misc_pre90s/d_ddragon.cpp @@ -1798,11 +1798,7 @@ static INT32 DrvMachineInit() BurnSetRefreshRate(57.444853); // Setup the HD6309 emulation - if (DrvSubCPUType == DD_CPU_TYPE_HD6309) { - HD6309Init(2); - } else { - HD6309Init(1); - } + HD6309Init(0); HD6309Open(0); HD6309MapMemory(DrvHD6309Ram , 0x0000, 0x0fff, M6809_RAM); HD6309MapMemory(DrvPaletteRam1 , 0x1000, 0x11ff, M6809_RAM); @@ -1824,6 +1820,7 @@ static INT32 DrvMachineInit() } if (DrvSubCPUType == DD_CPU_TYPE_HD6309) { + HD6309Init(1); HD6309Open(1); HD6309MapMemory(DrvSubCPURom , 0xc000, 0xffff, HD6309_ROM); HD6309SetReadByteHandler(DrvDdragonbSubHD6309ReadByte); @@ -1878,7 +1875,7 @@ static INT32 DrvMachineInit() static INT32 Drv2MachineInit() { // Setup the HD6309 emulation - HD6309Init(1); + HD6309Init(0); HD6309Open(0); HD6309MapMemory(DrvHD6309Ram , 0x0000, 0x17ff, M6809_RAM); HD6309MapMemory(DrvFgVideoRam , 0x1800, 0x1fff, M6809_RAM); diff --git a/src/burn/drivers/misc_pre90s/d_dec8.cpp b/src/burn/drivers/misc_pre90s/d_dec8.cpp index 063e19c49..563ddadba 100644 --- a/src/burn/drivers/misc_pre90s/d_dec8.cpp +++ b/src/burn/drivers/misc_pre90s/d_dec8.cpp @@ -1316,7 +1316,7 @@ static INT32 DrvInit() DrvGfxDecode(); } - HD6309Init(1); + HD6309Init(0); HD6309Open(0); HD6309MapMemory(DrvMainRAM, 0x0000, 0x17ff, HD6309_RAM); HD6309MapMemory(DrvVidRAM, 0x1800, 0x1fff, HD6309_RAM); @@ -3259,7 +3259,7 @@ static INT32 GondoInit() GondoGfxDecode(); } - HD6309Init(1); + HD6309Init(0); HD6309Open(0); HD6309MapMemory(DrvMainRAM, 0x0000, 0x17ff, HD6309_RAM); HD6309MapMemory(DrvVidRAM, 0x1800, 0x1fff, HD6309_RAM); @@ -3842,7 +3842,7 @@ static INT32 OscarInit() OscarGfxDecode(); } - HD6309Init(2); + HD6309Init(0); HD6309Open(0); HD6309MapMemory(DrvMainRAM, 0x0000, 0x1fff, HD6309_RAM); // all shared? HD6309MapMemory(DrvVidRAM, 0x2000, 0x28ff, HD6309_RAM); @@ -3855,6 +3855,7 @@ static INT32 OscarInit() HD6309SetReadByteHandler(oscar_main_read); HD6309Close(); + HD6309Init(1); HD6309Open(1); HD6309MapMemory(DrvMainRAM, 0x0000, 0x0eff, HD6309_RAM); // all shared? AM_RANGE(0x0f00, 0x0fff) AM_RAM not? HD6309MapMemory(DrvPalRAM + 0x400, 0x0f00, 0x0fff, HD6309_RAM); // not really pal... diff --git a/src/cpu/hd6309_intf.cpp b/src/cpu/hd6309_intf.cpp index 45eb773a2..7255f79ee 100644 --- a/src/cpu/hd6309_intf.cpp +++ b/src/cpu/hd6309_intf.cpp @@ -6,7 +6,7 @@ INT32 nHD6309Count = 0; static INT32 nActiveCPU = 0; -static HD6309Ext *HD6309CPUContext; +static HD6309Ext *HD6309CPUContext[MAX_CPU]; static INT32 nHD6309CyclesDone[MAX_CPU]; INT32 nHD6309CyclesTotal; @@ -51,39 +51,45 @@ void HD6309NewFrame() nHD6309CyclesTotal = 0; } -INT32 HD6309Init(INT32 num) +INT32 HD6309Init(INT32 nCPU) { - DebugCPU_HD6309Initted = 1; - nActiveCPU = -1; - nHD6309Count = num % MAX_CPU; - - HD6309CPUContext = (HD6309Ext*)malloc(num * sizeof(HD6309Ext)); - if (HD6309CPUContext == NULL) { + nHD6309Count = nHD6309Count++ % MAX_CPU; + + if (DebugCPU_HD6309Initted == 0) { + for (INT32 i = 0; i < MAX_CPU; i++) { + HD6309CPUContext[i] = NULL; + } + } + + HD6309CPUContext[nCPU] = (HD6309Ext*)BurnMalloc(sizeof(HD6309Ext)); + if (HD6309CPUContext[nCPU] == NULL) { return 1; } - memset(HD6309CPUContext, 0, num * sizeof(HD6309Ext)); + memset(HD6309CPUContext[nCPU], 0, sizeof(HD6309Ext)); - for (INT32 i = 0; i < num; i++) { - HD6309CPUContext[i].ReadByte = HD6309ReadByteDummyHandler; - HD6309CPUContext[i].WriteByte = HD6309WriteByteDummyHandler; - HD6309CPUContext[i].ReadOp = HD6309ReadOpDummyHandler; - HD6309CPUContext[i].ReadOpArg = HD6309ReadOpArgDummyHandler; + { + HD6309CPUContext[nCPU]->ReadByte = HD6309ReadByteDummyHandler; + HD6309CPUContext[nCPU]->WriteByte = HD6309WriteByteDummyHandler; + HD6309CPUContext[nCPU]->ReadOp = HD6309ReadOpDummyHandler; + HD6309CPUContext[nCPU]->ReadOpArg = HD6309ReadOpArgDummyHandler; - nHD6309CyclesDone[i] = 0; + nHD6309CyclesDone[nCPU] = 0; for (INT32 j = 0; j < (0x0100 * 3); j++) { - HD6309CPUContext[i].pMemMap[j] = NULL; + HD6309CPUContext[nCPU]->pMemMap[j] = NULL; } } nHD6309CyclesTotal = 0; - - hd6309_init(); - for (INT32 i = 0; i < num; i++) - CpuCheatRegister(0x0006, i); + if (DebugCPU_HD6309Initted == 0) { + hd6309_init(); + } + DebugCPU_HD6309Initted = 1; + + CpuCheatRegister(0x0006, nCPU); return 0; } @@ -96,9 +102,10 @@ void HD6309Exit() nHD6309Count = 0; - if (HD6309CPUContext) { - free(HD6309CPUContext); - HD6309CPUContext = NULL; + for (INT32 i = 0; i < MAX_CPU; i++) { + if (HD6309CPUContext[i]) { + BurnFree(HD6309CPUContext[i]); + } } DebugCPU_HD6309Initted = 0; @@ -110,11 +117,12 @@ void HD6309Open(INT32 num) if (!DebugCPU_HD6309Initted) bprintf(PRINT_ERROR, _T("HD6309Open called without init\n")); if (num >= nHD6309Count) bprintf(PRINT_ERROR, _T("HD6309Open called with invalid index %x\n"), num); if (nActiveCPU != -1) bprintf(PRINT_ERROR, _T("HD6309Open called when CPU already open with index %x\n"), num); + if (HD6309CPUContext[num] == NULL) bprintf (PRINT_ERROR, _T("HD6309Open called for unitialized CPU %x\n"), num); #endif nActiveCPU = num; - hd6309_set_context(&HD6309CPUContext[nActiveCPU].reg); + hd6309_set_context(&HD6309CPUContext[nActiveCPU]->reg); nHD6309CyclesTotal = nHD6309CyclesDone[nActiveCPU]; } @@ -126,7 +134,7 @@ void HD6309Close() if (nActiveCPU == -1) bprintf(PRINT_ERROR, _T("HD6309Close called when no CPU open\n")); #endif - hd6309_get_context(&HD6309CPUContext[nActiveCPU].reg); + hd6309_get_context(&HD6309CPUContext[nActiveCPU]->reg); nHD6309CyclesDone[nActiveCPU] = nHD6309CyclesTotal; @@ -206,7 +214,7 @@ INT32 HD6309MapMemory(UINT8* pMemory, UINT16 nStart, UINT16 nEnd, INT32 nType) #endif UINT8 cStart = (nStart >> 8); - UINT8 **pMemMap = HD6309CPUContext[nActiveCPU].pMemMap; + UINT8 **pMemMap = HD6309CPUContext[nActiveCPU]->pMemMap; for (UINT16 i = cStart; i <= (nEnd >> 8); i++) { if (nType & HD6309_READ) { @@ -231,7 +239,7 @@ INT32 HD6309MemCallback(UINT16 nStart, UINT16 nEnd, INT32 nType) #endif UINT8 cStart = (nStart >> 8); - UINT8 **pMemMap = HD6309CPUContext[nActiveCPU].pMemMap; + UINT8 **pMemMap = HD6309CPUContext[nActiveCPU]->pMemMap; for (UINT16 i = cStart; i <= (nEnd >> 8); i++) { if (nType & HD6309_READ) { @@ -255,7 +263,7 @@ void HD6309SetReadByteHandler(UINT8 (*pHandler)(UINT16)) if (nActiveCPU == -1) bprintf(PRINT_ERROR, _T("HD6309SetReadByteHandler called when no CPU open\n")); #endif - HD6309CPUContext[nActiveCPU].ReadByte = pHandler; + HD6309CPUContext[nActiveCPU]->ReadByte = pHandler; } void HD6309SetWriteByteHandler(void (*pHandler)(UINT16, UINT8)) @@ -265,7 +273,7 @@ void HD6309SetWriteByteHandler(void (*pHandler)(UINT16, UINT8)) if (nActiveCPU == -1) bprintf(PRINT_ERROR, _T("HD6309SetWriteByteHandler called when no CPU open\n")); #endif - HD6309CPUContext[nActiveCPU].WriteByte = pHandler; + HD6309CPUContext[nActiveCPU]->WriteByte = pHandler; } void HD6309SetReadOpHandler(UINT8 (*pHandler)(UINT16)) @@ -275,7 +283,7 @@ void HD6309SetReadOpHandler(UINT8 (*pHandler)(UINT16)) if (nActiveCPU == -1) bprintf(PRINT_ERROR, _T("HD6309SetReadOpHandler called when no CPU open\n")); #endif - HD6309CPUContext[nActiveCPU].ReadOp = pHandler; + HD6309CPUContext[nActiveCPU]->ReadOp = pHandler; } void HD6309SetReadOpArgHandler(UINT8 (*pHandler)(UINT16)) @@ -285,20 +293,20 @@ void HD6309SetReadOpArgHandler(UINT8 (*pHandler)(UINT16)) if (nActiveCPU == -1) bprintf(PRINT_ERROR, _T("HD6309SetReadOpArgHandler called when no CPU open\n")); #endif - HD6309CPUContext[nActiveCPU].ReadOpArg = pHandler; + HD6309CPUContext[nActiveCPU]->ReadOpArg = pHandler; } UINT8 HD6309ReadByte(UINT16 Address) { // check mem map - UINT8 * pr = HD6309CPUContext[nActiveCPU].pMemMap[0x000 | (Address >> 8)]; + UINT8 * pr = HD6309CPUContext[nActiveCPU]->pMemMap[0x000 | (Address >> 8)]; if (pr != NULL) { return pr[Address & 0xff]; } // check handler - if (HD6309CPUContext[nActiveCPU].ReadByte != NULL) { - return HD6309CPUContext[nActiveCPU].ReadByte(Address); + if (HD6309CPUContext[nActiveCPU]->ReadByte != NULL) { + return HD6309CPUContext[nActiveCPU]->ReadByte(Address); } return 0; @@ -307,15 +315,15 @@ UINT8 HD6309ReadByte(UINT16 Address) void HD6309WriteByte(UINT16 Address, UINT8 Data) { // check mem map - UINT8 * pr = HD6309CPUContext[nActiveCPU].pMemMap[0x100 | (Address >> 8)]; + UINT8 * pr = HD6309CPUContext[nActiveCPU]->pMemMap[0x100 | (Address >> 8)]; if (pr != NULL) { pr[Address & 0xff] = Data; return; } // check handler - if (HD6309CPUContext[nActiveCPU].WriteByte != NULL) { - HD6309CPUContext[nActiveCPU].WriteByte(Address, Data); + if (HD6309CPUContext[nActiveCPU]->WriteByte != NULL) { + HD6309CPUContext[nActiveCPU]->WriteByte(Address, Data); return; } } @@ -323,14 +331,14 @@ void HD6309WriteByte(UINT16 Address, UINT8 Data) UINT8 HD6309ReadOp(UINT16 Address) { // check mem map - UINT8 * pr = HD6309CPUContext[nActiveCPU].pMemMap[0x200 | (Address >> 8)]; + UINT8 * pr = HD6309CPUContext[nActiveCPU]->pMemMap[0x200 | (Address >> 8)]; if (pr != NULL) { return pr[Address & 0xff]; } // check handler - if (HD6309CPUContext[nActiveCPU].ReadOp != NULL) { - return HD6309CPUContext[nActiveCPU].ReadOp(Address); + if (HD6309CPUContext[nActiveCPU]->ReadOp != NULL) { + return HD6309CPUContext[nActiveCPU]->ReadOp(Address); } return 0; @@ -339,14 +347,14 @@ UINT8 HD6309ReadOp(UINT16 Address) UINT8 HD6309ReadOpArg(UINT16 Address) { // check mem map - UINT8 * pr = HD6309CPUContext[nActiveCPU].pMemMap[0x200 | (Address >> 8)]; + UINT8 * pr = HD6309CPUContext[nActiveCPU]->pMemMap[0x200 | (Address >> 8)]; if (pr != NULL) { return pr[Address & 0xff]; } // check handler - if (HD6309CPUContext[nActiveCPU].ReadOpArg != NULL) { - return HD6309CPUContext[nActiveCPU].ReadOpArg(Address); + if (HD6309CPUContext[nActiveCPU]->ReadOpArg != NULL) { + return HD6309CPUContext[nActiveCPU]->ReadOpArg(Address); } return 0; @@ -360,9 +368,9 @@ void HD6309WriteRom(UINT16 Address, UINT8 Data) #endif // check mem map - UINT8 * pr = HD6309CPUContext[nActiveCPU].pMemMap[0x000 | (Address >> 8)]; - UINT8 * pw = HD6309CPUContext[nActiveCPU].pMemMap[0x100 | (Address >> 8)]; - UINT8 * pf = HD6309CPUContext[nActiveCPU].pMemMap[0x200 | (Address >> 8)]; + UINT8 * pr = HD6309CPUContext[nActiveCPU]->pMemMap[0x000 | (Address >> 8)]; + UINT8 * pw = HD6309CPUContext[nActiveCPU]->pMemMap[0x100 | (Address >> 8)]; + UINT8 * pf = HD6309CPUContext[nActiveCPU]->pMemMap[0x200 | (Address >> 8)]; if (pr != NULL) { pr[Address & 0xff] = Data; @@ -377,8 +385,8 @@ void HD6309WriteRom(UINT16 Address, UINT8 Data) } // check handler - if (HD6309CPUContext[nActiveCPU].WriteByte != NULL) { - HD6309CPUContext[nActiveCPU].WriteByte(Address, Data); + if (HD6309CPUContext[nActiveCPU]->WriteByte != NULL) { + HD6309CPUContext[nActiveCPU]->WriteByte(Address, Data); return; } } diff --git a/src/cpu/hd6309_intf.h b/src/cpu/hd6309_intf.h index 5457d0dd9..b03fc77e7 100644 --- a/src/cpu/hd6309_intf.h +++ b/src/cpu/hd6309_intf.h @@ -38,7 +38,7 @@ extern INT32 nHD6309CyclesTotal; void HD6309Reset(); void HD6309NewFrame(); -INT32 HD6309Init(INT32 num); +INT32 HD6309Init(INT32 nCPU); void HD6309Exit(); void HD6309Open(INT32 num); void HD6309Close();