From c0df8070c7bd4880cbf6bb5e9d761ca237774fc9 Mon Sep 17 00:00:00 2001 From: Barry Harris <44396066+barry65536@users.noreply.github.com> Date: Fri, 23 Dec 2011 10:30:57 +0000 Subject: [PATCH] Reverted 119 and 120, broke debug tracking and some games, FB Alpha is otherwise quite stable now, please fully test all changes before committing --- src/burn/drivers/konami/d_ajax.cpp | 2 +- src/burn/drivers/konami/d_bottom9.cpp | 2 +- src/burn/drivers/konami/d_contra.cpp | 3 +- src/burn/drivers/konami/d_gyruss.cpp | 2 +- src/burn/drivers/konami/d_mainevt.cpp | 2 +- src/burn/drivers/konami/d_scotrsht.cpp | 2 +- src/burn/drivers/konami/d_spy.cpp | 2 +- src/burn/drivers/misc_post90s/d_gaelco.cpp | 2 +- src/burn/drivers/misc_post90s/d_lemmings.cpp | 2 +- src/burn/drivers/misc_pre90s/d_baraduke.cpp | 2 +- src/burn/drivers/misc_pre90s/d_ddragon.cpp | 11 +- src/burn/drivers/misc_pre90s/d_dec8.cpp | 17 ++- src/burn/drivers/misc_pre90s/d_ginganin.cpp | 2 +- src/burn/drivers/misc_pre90s/d_gng.cpp | 4 +- src/burn/drivers/misc_pre90s/d_renegade.cpp | 2 +- src/burn/drivers/misc_pre90s/d_skykid.cpp | 2 +- src/burn/drivers/misc_pre90s/d_sonson.cpp | 3 +- src/burn/drivers/misc_pre90s/d_srumbler.cpp | 2 +- src/cpu/hd6309_intf.cpp | 104 ++++++++-------- src/cpu/hd6309_intf.h | 2 +- src/cpu/m6809_intf.cpp | 120 +++++++++---------- src/cpu/m6809_intf.h | 2 +- 22 files changed, 135 insertions(+), 157 deletions(-) diff --git a/src/burn/drivers/konami/d_ajax.cpp b/src/burn/drivers/konami/d_ajax.cpp index de1b1eef4..90a9f85d3 100644 --- a/src/burn/drivers/konami/d_ajax.cpp +++ b/src/burn/drivers/konami/d_ajax.cpp @@ -570,7 +570,7 @@ static INT32 DrvInit() konamiSetReadHandler(ajax_main_read); konamiClose(); - M6809Init(0); + M6809Init(1); M6809Open(0); M6809MapMemory(DrvShareRAM, 0x2000, 0x3fff, M6809_RAM); M6809MapMemory(DrvM6809ROM + 0x10000, 0x8000, 0x9fff, M6809_ROM); diff --git a/src/burn/drivers/konami/d_bottom9.cpp b/src/burn/drivers/konami/d_bottom9.cpp index ef01c986f..dda349152 100644 --- a/src/burn/drivers/konami/d_bottom9.cpp +++ b/src/burn/drivers/konami/d_bottom9.cpp @@ -554,7 +554,7 @@ static INT32 DrvInit() DrvGfxDecode(); } - M6809Init(0); + M6809Init(1); M6809Open(0); M6809MapMemory(DrvM6809RAM, 0x4000, 0x5fff, M6809_RAM); M6809MapMemory(DrvM6809ROM + 0x10000, 0x6000, 0x7fff, M6809_ROM); diff --git a/src/burn/drivers/konami/d_contra.cpp b/src/burn/drivers/konami/d_contra.cpp index bca938d19..e2d4033a1 100644 --- a/src/burn/drivers/konami/d_contra.cpp +++ b/src/burn/drivers/konami/d_contra.cpp @@ -495,7 +495,7 @@ static INT32 DrvInit() DrvColorTableInit(); } - M6809Init(0); + M6809Init(2); M6809Open(0); M6809MapMemory(DrvPalRAM, 0x0c00, 0x0cff, M6809_ROM); M6809MapMemory(DrvM6809RAM0, 0x1000, 0x1fff, M6809_RAM); @@ -513,7 +513,6 @@ static INT32 DrvInit() M6809SetWriteByteHandler(DrvContraM6809WriteByte); M6809Close(); - M6809Init(1); M6809Open(1); M6809MapMemory(DrvM6809RAM2, 0x6000, 0x67ff, M6809_RAM); M6809MapMemory(DrvM6809ROM1 + 0x08000, 0x8000, 0xffff, M6809_ROM); diff --git a/src/burn/drivers/konami/d_gyruss.cpp b/src/burn/drivers/konami/d_gyruss.cpp index 1d0f7dd30..e30f8732b 100644 --- a/src/burn/drivers/konami/d_gyruss.cpp +++ b/src/burn/drivers/konami/d_gyruss.cpp @@ -639,7 +639,7 @@ static INT32 DrvInit() ZetMemEnd(); ZetClose(); - M6809Init(0); + M6809Init(1); M6809Open(0); M6809MapMemory(DrvM6809RAM, 0x4000, 0x47ff, M6809_RAM); M6809MapMemory(DrvShareRAM, 0x6000, 0x67ff, M6809_RAM); diff --git a/src/burn/drivers/konami/d_mainevt.cpp b/src/burn/drivers/konami/d_mainevt.cpp index c68c5ce30..e4adba0cc 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(0); + HD6309Init(1); HD6309Open(0); HD6309MapMemory(DrvHD6309RAM, 0x4000, 0x5fff, HD6309_RAM); HD6309MapMemory(DrvHD6309ROM + 0x10000, 0x6000, 0x7fff, HD6309_ROM); diff --git a/src/burn/drivers/konami/d_scotrsht.cpp b/src/burn/drivers/konami/d_scotrsht.cpp index 5acff3fab..704de17a8 100644 --- a/src/burn/drivers/konami/d_scotrsht.cpp +++ b/src/burn/drivers/konami/d_scotrsht.cpp @@ -372,7 +372,7 @@ static INT32 DrvInit() DrvGfxDecode(); } - M6809Init(0); + M6809Init(1); M6809Open(0); M6809MapMemory(DrvColRAM, 0x0000, 0x07ff, M6809_RAM); M6809MapMemory(DrvVidRAM, 0x0800, 0x0fff, M6809_RAM); diff --git a/src/burn/drivers/konami/d_spy.cpp b/src/burn/drivers/konami/d_spy.cpp index fa830f35e..b1bf5049d 100644 --- a/src/burn/drivers/konami/d_spy.cpp +++ b/src/burn/drivers/konami/d_spy.cpp @@ -548,7 +548,7 @@ static INT32 DrvInit() DrvGfxDecode(); } - M6809Init(0); + M6809Init(1); M6809Open(0); M6809MapMemory(DrvM6809RAM, 0x0800, 0x1aff, M6809_RAM); M6809MapMemory(DrvM6809ROM + 0x10000, 0x6000, 0x7fff, M6809_ROM); diff --git a/src/burn/drivers/misc_post90s/d_gaelco.cpp b/src/burn/drivers/misc_post90s/d_gaelco.cpp index 953bf83d8..fc2590106 100644 --- a/src/burn/drivers/misc_post90s/d_gaelco.cpp +++ b/src/burn/drivers/misc_post90s/d_gaelco.cpp @@ -844,7 +844,7 @@ static INT32 DrvInit(INT32 (*pRomLoadCallback)(), INT32 encrypted_ram, INT32 sou // big karnak { - M6809Init(0); + M6809Init(1); M6809Open(0); M6809MapMemory(Drv6809RAM, 0x0000, 0x07ff, M6809_RAM); M6809MapMemory(Drv6809ROM + 0x0c00, 0x0c00, 0xffff, M6809_ROM); diff --git a/src/burn/drivers/misc_post90s/d_lemmings.cpp b/src/burn/drivers/misc_post90s/d_lemmings.cpp index ed3db275b..6b30ec024 100644 --- a/src/burn/drivers/misc_post90s/d_lemmings.cpp +++ b/src/burn/drivers/misc_post90s/d_lemmings.cpp @@ -446,7 +446,7 @@ static INT32 DrvInit() SekSetReadByteHandler(0, lemmings_main_read_byte); SekClose(); - M6809Init(0); + M6809Init(1); M6809Open(0); M6809MapMemory(DrvM6809RAM, 0x0000, 0x07ff, M6809_RAM); M6809MapMemory(DrvM6809ROM + 0x8000, 0x8000, 0xffff, M6809_ROM); diff --git a/src/burn/drivers/misc_pre90s/d_baraduke.cpp b/src/burn/drivers/misc_pre90s/d_baraduke.cpp index 0c1cea083..51dde8fdc 100644 --- a/src/burn/drivers/misc_pre90s/d_baraduke.cpp +++ b/src/burn/drivers/misc_pre90s/d_baraduke.cpp @@ -489,7 +489,7 @@ static INT32 DrvInit(INT32 type) DrvPaletteInit(); } - M6809Init(0); + M6809Init(1); M6809Open(0); M6809MapMemory(DrvSprRAM, 0x0000, 0x1fff, M6809_READ | M6809_FETCH); M6809MapMemory(DrvSprRAM, 0x0000, 0x1eff, M6809_WRITE); diff --git a/src/burn/drivers/misc_pre90s/d_ddragon.cpp b/src/burn/drivers/misc_pre90s/d_ddragon.cpp index 7e3338afa..94a55a080 100644 --- a/src/burn/drivers/misc_pre90s/d_ddragon.cpp +++ b/src/burn/drivers/misc_pre90s/d_ddragon.cpp @@ -1798,7 +1798,11 @@ static INT32 DrvMachineInit() BurnSetRefreshRate(57.444853); // Setup the HD6309 emulation - HD6309Init(0); + if (DrvSubCPUType == DD_CPU_TYPE_HD6309) { + HD6309Init(2); + } else { + HD6309Init(1); + } HD6309Open(0); HD6309MapMemory(DrvHD6309Ram , 0x0000, 0x0fff, M6809_RAM); HD6309MapMemory(DrvPaletteRam1 , 0x1000, 0x11ff, M6809_RAM); @@ -1820,7 +1824,6 @@ static INT32 DrvMachineInit() } if (DrvSubCPUType == DD_CPU_TYPE_HD6309) { - HD6309Init(1); HD6309Open(1); HD6309MapMemory(DrvSubCPURom , 0xc000, 0xffff, HD6309_ROM); HD6309SetReadByteHandler(DrvDdragonbSubHD6309ReadByte); @@ -1837,7 +1840,7 @@ static INT32 DrvMachineInit() } if (DrvSoundCPUType == DD_CPU_TYPE_M6809) { - M6809Init(0); + M6809Init(1); M6809Open(0); M6809MapMemory(DrvSoundCPURam , 0x0000, 0x0fff, M6809_RAM); M6809MapMemory(DrvSoundCPURom , 0x8000, 0xffff, M6809_ROM); @@ -1875,7 +1878,7 @@ static INT32 DrvMachineInit() static INT32 Drv2MachineInit() { // Setup the HD6309 emulation - HD6309Init(0); + HD6309Init(1); 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 563ddadba..31521ac7f 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(0); + HD6309Init(1); HD6309Open(0); HD6309MapMemory(DrvMainRAM, 0x0000, 0x17ff, HD6309_RAM); HD6309MapMemory(DrvVidRAM, 0x1800, 0x1fff, HD6309_RAM); @@ -2042,7 +2042,7 @@ static INT32 CobraInit() CobraGfxDecode(); } - M6809Init(0); + M6809Init(1); M6809Open(0); M6809MapMemory(DrvMainRAM, 0x0000, 0x07ff, M6809_RAM); M6809MapMemory(DrvPf0RAM, 0x0800, 0x0fff, M6809_RAM); @@ -2577,7 +2577,7 @@ static INT32 SrdarwinInit() SrdarwinGfxDecode(); } - M6809Init(0); + M6809Init(1); M6809Open(0); M6809MapMemory(DrvMainRAM, 0x0000, 0x05ff, M6809_RAM); M6809MapMemory(DrvSprRAM, 0x0600, 0x07ff, M6809_RAM); @@ -3259,7 +3259,7 @@ static INT32 GondoInit() GondoGfxDecode(); } - HD6309Init(0); + HD6309Init(1); HD6309Open(0); HD6309MapMemory(DrvMainRAM, 0x0000, 0x17ff, HD6309_RAM); HD6309MapMemory(DrvVidRAM, 0x1800, 0x1fff, HD6309_RAM); @@ -3842,7 +3842,7 @@ static INT32 OscarInit() OscarGfxDecode(); } - HD6309Init(0); + HD6309Init(2); HD6309Open(0); HD6309MapMemory(DrvMainRAM, 0x0000, 0x1fff, HD6309_RAM); // all shared? HD6309MapMemory(DrvVidRAM, 0x2000, 0x28ff, HD6309_RAM); @@ -3855,7 +3855,6 @@ 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... @@ -4488,7 +4487,7 @@ static INT32 LastmissInit() LastmissGfxDecode(); } - M6809Init(0); + M6809Init(2); M6809Open(0); M6809MapMemory(DrvMainRAM, 0x0000, 0x0fff, M6809_RAM); M6809MapMemory(DrvPalRAM, 0x1000, 0x17ff, M6809_RAM); @@ -4502,7 +4501,6 @@ static INT32 LastmissInit() M6809SetReadByteHandler(lastmiss_main_read); M6809Close(); - M6809Init(1); M6809Open(1); M6809MapMemory(DrvMainRAM, 0x0000, 0x0fff, M6809_RAM); M6809MapMemory(DrvPalRAM, 0x1000, 0x17ff, M6809_RAM); @@ -5173,7 +5171,7 @@ static INT32 CsilverInit() LastmissGfxDecode(); } - M6809Init(0); + M6809Init(2); M6809Open(0); M6809MapMemory(DrvMainRAM + 0x00000, 0x0000, 0x0fff, M6809_RAM); M6809MapMemory(DrvPalRAM, 0x1000, 0x17ff, M6809_RAM); // xxxxbbbbggggrrrr @@ -5187,7 +5185,6 @@ static INT32 CsilverInit() M6809SetReadByteHandler(csilver_main_read); M6809Close(); - M6809Init(1); M6809Open(1); M6809MapMemory(DrvMainRAM + 0x00000, 0x0000, 0x0fff, M6809_RAM); M6809MapMemory(DrvPalRAM, 0x1000, 0x17ff, M6809_RAM); // xxxxbbbbggggrrrr diff --git a/src/burn/drivers/misc_pre90s/d_ginganin.cpp b/src/burn/drivers/misc_pre90s/d_ginganin.cpp index b7b81bc37..47cef346b 100644 --- a/src/burn/drivers/misc_pre90s/d_ginganin.cpp +++ b/src/burn/drivers/misc_pre90s/d_ginganin.cpp @@ -391,7 +391,7 @@ static INT32 DrvInit() SekSetReadByteHandler(0, ginganin_read_byte); SekClose(); - M6809Init(0); + M6809Init(1); M6809Open(0); M6809MapMemory(DrvM6809RAM, 0x0000, 0x07ff, M6809_RAM); M6809MapMemory(DrvM6809ROM + 0x4000, 0x4000, 0xffff, M6809_ROM); diff --git a/src/burn/drivers/misc_pre90s/d_gng.cpp b/src/burn/drivers/misc_pre90s/d_gng.cpp index a99c9ea93..1d33a34a4 100644 --- a/src/burn/drivers/misc_pre90s/d_gng.cpp +++ b/src/burn/drivers/misc_pre90s/d_gng.cpp @@ -878,7 +878,7 @@ static INT32 DrvInit() BurnFree(DrvTempRom); // Setup the M6809 emulation - M6809Init(0); + M6809Init(1); M6809Open(0); M6809MapMemory(DrvM6809Ram , 0x0000, 0x1dff, M6809_RAM); M6809MapMemory(DrvSpriteRam , 0x1e00, 0x1fff, M6809_RAM); @@ -965,7 +965,7 @@ static INT32 DiamondInit() BurnFree(DrvTempRom); // Setup the M6809 emulation - M6809Init(0); + M6809Init(1); M6809Open(0); M6809MapMemory(DrvM6809Ram , 0x0000, 0x1dff, M6809_RAM); M6809MapMemory(DrvSpriteRam , 0x1e00, 0x1fff, M6809_RAM); diff --git a/src/burn/drivers/misc_pre90s/d_renegade.cpp b/src/burn/drivers/misc_pre90s/d_renegade.cpp index d9cf879cd..f69df50a0 100644 --- a/src/burn/drivers/misc_pre90s/d_renegade.cpp +++ b/src/burn/drivers/misc_pre90s/d_renegade.cpp @@ -995,7 +995,7 @@ static INT32 DrvInit(INT32 nMcuType) M6502SetWriteByteHandler(RenegadeWriteByte); M6502Close(); - M6809Init(0); + M6809Init(1); M6809Open(0); M6809MapMemory(DrvM6809Ram , 0x0000, 0x0fff, M6809_RAM); M6809MapMemory(DrvM6809Rom , 0x8000, 0xffff, M6809_ROM); diff --git a/src/burn/drivers/misc_pre90s/d_skykid.cpp b/src/burn/drivers/misc_pre90s/d_skykid.cpp index 6b6903e09..224a5e955 100644 --- a/src/burn/drivers/misc_pre90s/d_skykid.cpp +++ b/src/burn/drivers/misc_pre90s/d_skykid.cpp @@ -601,7 +601,7 @@ static INT32 DrvInit() DrvPaletteInit(); } - M6809Init(0); + M6809Init(1); M6809Open(0); M6809MapMemory(DrvM6809ROM + 0x10000, 0x0000, 0x1fff, M6809_ROM); M6809MapMemory(DrvVidRAM, 0x2000, 0x2fff, M6809_RAM); diff --git a/src/burn/drivers/misc_pre90s/d_sonson.cpp b/src/burn/drivers/misc_pre90s/d_sonson.cpp index 00a1f8520..fcf3b7874 100644 --- a/src/burn/drivers/misc_pre90s/d_sonson.cpp +++ b/src/burn/drivers/misc_pre90s/d_sonson.cpp @@ -405,7 +405,7 @@ static INT32 DrvInit() DrvPaletteInit(); DrvGfxDecode(); - M6809Init(0); + M6809Init(2); M6809Open(0); M6809MapMemory(DrvM6809RAM0, 0x0000, 0x0fff, M6809_RAM); M6809MapMemory(DrvVidRAM, 0x1000, 0x13ff, M6809_RAM); @@ -416,7 +416,6 @@ static INT32 DrvInit() M6809SetWriteByteHandler(sonson_main_write); M6809Close(); - M6809Init(1); M6809Open(1); M6809MapMemory(DrvM6809RAM1, 0x0000, 0x07ff, M6809_RAM); M6809MapMemory(DrvM6809ROM1 + 0x0e000, 0xe000, 0xffff, M6809_ROM); diff --git a/src/burn/drivers/misc_pre90s/d_srumbler.cpp b/src/burn/drivers/misc_pre90s/d_srumbler.cpp index 0f96d8e08..63aa6cec8 100644 --- a/src/burn/drivers/misc_pre90s/d_srumbler.cpp +++ b/src/burn/drivers/misc_pre90s/d_srumbler.cpp @@ -369,7 +369,7 @@ static INT32 DrvInit() DrvGfxDecode(); } - M6809Init(0); + M6809Init(1); M6809Open(0); M6809MapMemory(DrvM6809RAM, 0x0000, 0x1dff, M6809_RAM); M6809MapMemory(DrvSprRAM, 0x1e00, 0x1fff, M6809_RAM); diff --git a/src/cpu/hd6309_intf.cpp b/src/cpu/hd6309_intf.cpp index 7255f79ee..45eb773a2 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[MAX_CPU]; +static HD6309Ext *HD6309CPUContext; static INT32 nHD6309CyclesDone[MAX_CPU]; INT32 nHD6309CyclesTotal; @@ -51,45 +51,39 @@ void HD6309NewFrame() nHD6309CyclesTotal = 0; } -INT32 HD6309Init(INT32 nCPU) +INT32 HD6309Init(INT32 num) { + DebugCPU_HD6309Initted = 1; + nActiveCPU = -1; - 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) { + nHD6309Count = num % MAX_CPU; + + HD6309CPUContext = (HD6309Ext*)malloc(num * sizeof(HD6309Ext)); + if (HD6309CPUContext == NULL) { return 1; } - memset(HD6309CPUContext[nCPU], 0, sizeof(HD6309Ext)); + memset(HD6309CPUContext, 0, num * sizeof(HD6309Ext)); - { - HD6309CPUContext[nCPU]->ReadByte = HD6309ReadByteDummyHandler; - HD6309CPUContext[nCPU]->WriteByte = HD6309WriteByteDummyHandler; - HD6309CPUContext[nCPU]->ReadOp = HD6309ReadOpDummyHandler; - HD6309CPUContext[nCPU]->ReadOpArg = HD6309ReadOpArgDummyHandler; + for (INT32 i = 0; i < num; i++) { + HD6309CPUContext[i].ReadByte = HD6309ReadByteDummyHandler; + HD6309CPUContext[i].WriteByte = HD6309WriteByteDummyHandler; + HD6309CPUContext[i].ReadOp = HD6309ReadOpDummyHandler; + HD6309CPUContext[i].ReadOpArg = HD6309ReadOpArgDummyHandler; - nHD6309CyclesDone[nCPU] = 0; + nHD6309CyclesDone[i] = 0; for (INT32 j = 0; j < (0x0100 * 3); j++) { - HD6309CPUContext[nCPU]->pMemMap[j] = NULL; + HD6309CPUContext[i].pMemMap[j] = NULL; } } nHD6309CyclesTotal = 0; + + hd6309_init(); - if (DebugCPU_HD6309Initted == 0) { - hd6309_init(); - } - DebugCPU_HD6309Initted = 1; - - CpuCheatRegister(0x0006, nCPU); + for (INT32 i = 0; i < num; i++) + CpuCheatRegister(0x0006, i); return 0; } @@ -102,10 +96,9 @@ void HD6309Exit() nHD6309Count = 0; - for (INT32 i = 0; i < MAX_CPU; i++) { - if (HD6309CPUContext[i]) { - BurnFree(HD6309CPUContext[i]); - } + if (HD6309CPUContext) { + free(HD6309CPUContext); + HD6309CPUContext = NULL; } DebugCPU_HD6309Initted = 0; @@ -117,12 +110,11 @@ 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]; } @@ -134,7 +126,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; @@ -214,7 +206,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) { @@ -239,7 +231,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) { @@ -263,7 +255,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)) @@ -273,7 +265,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)) @@ -283,7 +275,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)) @@ -293,20 +285,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; @@ -315,15 +307,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; } } @@ -331,14 +323,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; @@ -347,14 +339,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; @@ -368,9 +360,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; @@ -385,8 +377,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 b03fc77e7..5457d0dd9 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 nCPU); +INT32 HD6309Init(INT32 num); void HD6309Exit(); void HD6309Open(INT32 num); void HD6309Close(); diff --git a/src/cpu/m6809_intf.cpp b/src/cpu/m6809_intf.cpp index d975fde6a..057e0b8e3 100644 --- a/src/cpu/m6809_intf.cpp +++ b/src/cpu/m6809_intf.cpp @@ -6,7 +6,7 @@ INT32 nM6809Count = 0; static INT32 nActiveCPU = 0; -static M6809Ext *m6809CPUContext[MAX_CPU]; +static M6809Ext *m6809CPUContext; static INT32 nM6809CyclesDone[MAX_CPU]; INT32 nM6809CyclesTotal; @@ -18,7 +18,6 @@ static UINT8 M6809ReadByteDummyHandler(UINT16) static void M6809WriteByteDummyHandler(UINT16, UINT8) { - } static UINT8 M6809ReadOpDummyHandler(UINT16) @@ -53,48 +52,39 @@ void M6809NewFrame() nM6809CyclesTotal = 0; } -INT32 M6809Init(INT32 nCPU) +INT32 M6809Init(INT32 num) { -#if defined FBA_DEBUG - if (nCPU >= MAX_CPU) bprintf (PRINT_ERROR, _T("Too many CPUs initialized (%d)! Please change MAX_CPU = %d\n"), nCPU, MAX_CPU); -#endif - - if (DebugCPU_M6809Initted == 0) { - for (INT32 i = 0; i < MAX_CPU; i++) { - m6809CPUContext[i] = NULL; - } - } - - nActiveCPU = -1; - nM6809Count = nM6809Count++ % MAX_CPU; + DebugCPU_M6809Initted = 1; - m6809CPUContext[nCPU] = (M6809Ext*)BurnMalloc(sizeof(M6809Ext)); - if (m6809CPUContext[nCPU] == NULL) { + nActiveCPU = -1; + nM6809Count = num % MAX_CPU; + + m6809CPUContext = (M6809Ext*)malloc(num * sizeof(M6809Ext)); + if (m6809CPUContext == NULL) { return 1; } - memset(m6809CPUContext[nCPU], 0, sizeof(M6809Ext)); + memset(m6809CPUContext, 0, num * sizeof(M6809Ext)); - m6809CPUContext[nCPU]->ReadByte = M6809ReadByteDummyHandler; - m6809CPUContext[nCPU]->WriteByte = M6809WriteByteDummyHandler; - m6809CPUContext[nCPU]->ReadOp = M6809ReadOpDummyHandler; - m6809CPUContext[nCPU]->ReadOpArg = M6809ReadOpArgDummyHandler; + for (INT32 i = 0; i < num; i++) { + m6809CPUContext[i].ReadByte = M6809ReadByteDummyHandler; + m6809CPUContext[i].WriteByte = M6809WriteByteDummyHandler; + m6809CPUContext[i].ReadOp = M6809ReadOpDummyHandler; + m6809CPUContext[i].ReadOpArg = M6809ReadOpArgDummyHandler; - nM6809CyclesDone[nCPU] = 0; + nM6809CyclesDone[i] = 0; - for (INT32 j = 0; j < (0x0100 * 3); j++) { - m6809CPUContext[nCPU]->pMemMap[j] = NULL; + for (INT32 j = 0; j < (0x0100 * 3); j++) { + m6809CPUContext[i].pMemMap[j] = NULL; + } } nM6809CyclesTotal = 0; + + m6809_init(NULL); - if (DebugCPU_M6809Initted == 0) { - m6809_init(NULL); - } - - DebugCPU_M6809Initted = 1; - - CpuCheatRegister(0x0005, nCPU); + for (INT32 i = 0; i < num; i++) + CpuCheatRegister(0x0005, i); return 0; } @@ -107,12 +97,11 @@ void M6809Exit() nM6809Count = 0; - for (INT32 i = 0; i < MAX_CPU; i++) { - if (m6809CPUContext[i]) { - BurnFree(m6809CPUContext[i]); - } + if (m6809CPUContext) { + free(m6809CPUContext); + m6809CPUContext = NULL; } - + DebugCPU_M6809Initted = 0; } @@ -122,12 +111,11 @@ void M6809Open(INT32 num) if (!DebugCPU_M6809Initted) bprintf(PRINT_ERROR, _T("M6809Open called without init\n")); if (num >= nM6809Count) bprintf(PRINT_ERROR, _T("M6809Open called with invalid index %x\n"), num); if (nActiveCPU != -1) bprintf(PRINT_ERROR, _T("M6809Open called when CPU already open with index %x\n"), num); - if (m6809CPUContext[num] == NULL) bprintf (PRINT_ERROR, _T("M6809Open called for uninitialized CPU %x\n"), num); #endif nActiveCPU = num; - m6809_set_context(&m6809CPUContext[nActiveCPU]->reg); + m6809_set_context(&m6809CPUContext[nActiveCPU].reg); nM6809CyclesTotal = nM6809CyclesDone[nActiveCPU]; } @@ -139,7 +127,7 @@ void M6809Close() if (nActiveCPU == -1) bprintf(PRINT_ERROR, _T("M6809Close called when no CPU open\n")); #endif - m6809_get_context(&m6809CPUContext[nActiveCPU]->reg); + m6809_get_context(&m6809CPUContext[nActiveCPU].reg); nM6809CyclesDone[nActiveCPU] = nM6809CyclesTotal; @@ -209,7 +197,7 @@ INT32 M6809MapMemory(UINT8* pMemory, UINT16 nStart, UINT16 nEnd, INT32 nType) #endif UINT8 cStart = (nStart >> 8); - UINT8 **pMemMap = m6809CPUContext[nActiveCPU]->pMemMap; + UINT8 **pMemMap = m6809CPUContext[nActiveCPU].pMemMap; for (UINT16 i = cStart; i <= (nEnd >> 8); i++) { if (nType & M6809_READ) { @@ -222,8 +210,8 @@ INT32 M6809MapMemory(UINT8* pMemory, UINT16 nStart, UINT16 nEnd, INT32 nType) pMemMap[0x200 + i] = pMemory + ((i - cStart) << 8); } } - return 0; + } void M6809SetReadByteHandler(UINT8 (*pHandler)(UINT16)) @@ -233,7 +221,7 @@ void M6809SetReadByteHandler(UINT8 (*pHandler)(UINT16)) if (nActiveCPU == -1) bprintf(PRINT_ERROR, _T("M6809SetReadByteHandler called when no CPU open\n")); #endif - m6809CPUContext[nActiveCPU]->ReadByte = pHandler; + m6809CPUContext[nActiveCPU].ReadByte = pHandler; } void M6809SetWriteByteHandler(void (*pHandler)(UINT16, UINT8)) @@ -243,7 +231,7 @@ void M6809SetWriteByteHandler(void (*pHandler)(UINT16, UINT8)) if (nActiveCPU == -1) bprintf(PRINT_ERROR, _T("M6809SetWriteByteHandler called when no CPU open\n")); #endif - m6809CPUContext[nActiveCPU]->WriteByte = pHandler; + m6809CPUContext[nActiveCPU].WriteByte = pHandler; } void M6809SetReadOpHandler(UINT8 (*pHandler)(UINT16)) @@ -253,7 +241,7 @@ void M6809SetReadOpHandler(UINT8 (*pHandler)(UINT16)) if (nActiveCPU == -1) bprintf(PRINT_ERROR, _T("M6809SetReadOpHandler called when no CPU open\n")); #endif - m6809CPUContext[nActiveCPU]->ReadOp = pHandler; + m6809CPUContext[nActiveCPU].ReadOp = pHandler; } void M6809SetReadOpArgHandler(UINT8 (*pHandler)(UINT16)) @@ -263,20 +251,20 @@ void M6809SetReadOpArgHandler(UINT8 (*pHandler)(UINT16)) if (nActiveCPU == -1) bprintf(PRINT_ERROR, _T("M6809SetReadOpArgHandler called when no CPU open\n")); #endif - m6809CPUContext[nActiveCPU]->ReadOpArg = pHandler; + m6809CPUContext[nActiveCPU].ReadOpArg = pHandler; } UINT8 M6809ReadByte(UINT16 Address) { // check mem map - UINT8 * pr = m6809CPUContext[nActiveCPU]->pMemMap[0x000 | (Address >> 8)]; + UINT8 * pr = m6809CPUContext[nActiveCPU].pMemMap[0x000 | (Address >> 8)]; if (pr != NULL) { return pr[Address & 0xff]; } // check handler - if (m6809CPUContext[nActiveCPU]->ReadByte != NULL) { - return m6809CPUContext[nActiveCPU]->ReadByte(Address); + if (m6809CPUContext[nActiveCPU].ReadByte != NULL) { + return m6809CPUContext[nActiveCPU].ReadByte(Address); } return 0; @@ -285,15 +273,15 @@ UINT8 M6809ReadByte(UINT16 Address) void M6809WriteByte(UINT16 Address, UINT8 Data) { // check mem map - UINT8 * pr = m6809CPUContext[nActiveCPU]->pMemMap[0x100 | (Address >> 8)]; + UINT8 * pr = m6809CPUContext[nActiveCPU].pMemMap[0x100 | (Address >> 8)]; if (pr != NULL) { pr[Address & 0xff] = Data; return; } // check handler - if (m6809CPUContext[nActiveCPU]->WriteByte != NULL) { - m6809CPUContext[nActiveCPU]->WriteByte(Address, Data); + if (m6809CPUContext[nActiveCPU].WriteByte != NULL) { + m6809CPUContext[nActiveCPU].WriteByte(Address, Data); return; } } @@ -301,14 +289,14 @@ void M6809WriteByte(UINT16 Address, UINT8 Data) UINT8 M6809ReadOp(UINT16 Address) { // check mem map - UINT8 * pr = m6809CPUContext[nActiveCPU]->pMemMap[0x200 | (Address >> 8)]; + UINT8 * pr = m6809CPUContext[nActiveCPU].pMemMap[0x200 | (Address >> 8)]; if (pr != NULL) { return pr[Address & 0xff]; } // check handler - if (m6809CPUContext[nActiveCPU]->ReadOp != NULL) { - return m6809CPUContext[nActiveCPU]->ReadOp(Address); + if (m6809CPUContext[nActiveCPU].ReadOp != NULL) { + return m6809CPUContext[nActiveCPU].ReadOp(Address); } return 0; @@ -317,14 +305,14 @@ UINT8 M6809ReadOp(UINT16 Address) UINT8 M6809ReadOpArg(UINT16 Address) { // check mem map - UINT8 * pr = m6809CPUContext[nActiveCPU]->pMemMap[0x000 | (Address >> 8)]; + UINT8 * pr = m6809CPUContext[nActiveCPU].pMemMap[0x000 | (Address >> 8)]; if (pr != NULL) { return pr[Address & 0xff]; } // check handler - if (m6809CPUContext[nActiveCPU]->ReadOpArg != NULL) { - return m6809CPUContext[nActiveCPU]->ReadOpArg(Address); + if (m6809CPUContext[nActiveCPU].ReadOpArg != NULL) { + return m6809CPUContext[nActiveCPU].ReadOpArg(Address); } return 0; @@ -337,9 +325,9 @@ void M6809WriteRom(UINT16 Address, UINT8 Data) if (nActiveCPU == -1) bprintf(PRINT_ERROR, _T("M6809WriteRom called when no CPU open\n")); #endif - UINT8 * pr = m6809CPUContext[nActiveCPU]->pMemMap[0x000 | (Address >> 8)]; - UINT8 * pw = m6809CPUContext[nActiveCPU]->pMemMap[0x100 | (Address >> 8)]; - UINT8 * pf = m6809CPUContext[nActiveCPU]->pMemMap[0x200 | (Address >> 8)]; + UINT8 * pr = m6809CPUContext[nActiveCPU].pMemMap[0x000 | (Address >> 8)]; + UINT8 * pw = m6809CPUContext[nActiveCPU].pMemMap[0x100 | (Address >> 8)]; + UINT8 * pf = m6809CPUContext[nActiveCPU].pMemMap[0x200 | (Address >> 8)]; if (pr != NULL) { pr[Address & 0xff] = Data; @@ -354,8 +342,8 @@ void M6809WriteRom(UINT16 Address, UINT8 Data) } // check handler - if (m6809CPUContext[nActiveCPU]->WriteByte != NULL) { - m6809CPUContext[nActiveCPU]->WriteByte(Address, Data); + if (m6809CPUContext[nActiveCPU].WriteByte != NULL) { + m6809CPUContext[nActiveCPU].WriteByte(Address, Data); return; } } @@ -374,7 +362,7 @@ INT32 M6809Scan(INT32 nAction) for (INT32 i = 0; i < nM6809Count; i++) { - M6809Ext *ptr = m6809CPUContext[i]; + M6809Ext *ptr = &m6809CPUContext[i]; INT32 (*Callback)(INT32 irqline); @@ -383,8 +371,8 @@ INT32 M6809Scan(INT32 nAction) char szName[] = "M6809 #n"; szName[7] = '0' + i; - ba.Data = &m6809CPUContext[i]->reg; - ba.nLen = sizeof(m6809CPUContext[i]->reg); + ba.Data = &m6809CPUContext[i].reg; + ba.nLen = sizeof(m6809CPUContext[i].reg); ba.szName = szName; BurnAcb(&ba); diff --git a/src/cpu/m6809_intf.h b/src/cpu/m6809_intf.h index 64d89a386..c585ab369 100644 --- a/src/cpu/m6809_intf.h +++ b/src/cpu/m6809_intf.h @@ -38,7 +38,7 @@ extern INT32 nM6809CyclesTotal; void M6809Reset(); void M6809NewFrame(); -INT32 M6809Init(INT32 nCPU); +INT32 M6809Init(INT32 num); void M6809Exit(); void M6809Open(INT32 num); void M6809Close();