From 3c90492b100dc50cc3109660d54ddb3346f8810e Mon Sep 17 00:00:00 2001 From: Barry Harris <44396066+barry65536@users.noreply.github.com> Date: Mon, 19 Dec 2011 21:35:52 +0000 Subject: [PATCH] Initial tidying of Sega drivers --- src/burn/drivers/sega/d_hangon.cpp | 16 ++--- src/burn/drivers/sega/d_outrun.cpp | 17 ++--- src/burn/drivers/sega/genesis_vid.cpp | 23 ++---- src/burn/drivers/sega/sys16_fd1094.cpp | 7 +- src/burn/drivers/sega/sys16_gfx.cpp | 84 ++++++++-------------- src/burn/drivers/sega/sys16_run.cpp | 96 +++++++++++--------------- 6 files changed, 89 insertions(+), 154 deletions(-) diff --git a/src/burn/drivers/sega/d_hangon.cpp b/src/burn/drivers/sega/d_hangon.cpp index 3ff18c0d6..f064bc06c 100644 --- a/src/burn/drivers/sega/d_hangon.cpp +++ b/src/burn/drivers/sega/d_hangon.cpp @@ -1224,15 +1224,12 @@ static INT32 EndurorInit() INT32 nRet = System16Init(); - UINT8 *pTemp = (UINT8*)malloc(0x10000); + UINT8 *pTemp = (UINT8*)BurnMalloc(0x10000); memcpy(pTemp, System16PCMData, 0x10000); memset(System16PCMData, 0, 0x18000); memcpy(System16PCMData + 0x00000, pTemp + 0x00000, 0x8000); memcpy(System16PCMData + 0x10000, pTemp + 0x08000, 0x8000); - if (pTemp) { - free(pTemp); - pTemp = NULL; - } + BurnFree(pTemp); return nRet; } @@ -1251,7 +1248,7 @@ static INT32 Enduror1Init() INT32 EnduroblLoadRom() { INT32 nRet = 1; - UINT8 *pTemp = (UINT8*)malloc(0x40000); + UINT8 *pTemp = (UINT8*)BurnMalloc(0x40000); if (pTemp) { memcpy(pTemp, System16Rom, 0x40000); @@ -1259,13 +1256,10 @@ INT32 EnduroblLoadRom() memcpy(System16Rom + 0x00000, pTemp + 0x10000, 0x10000); memcpy(System16Rom + 0x10000, pTemp + 0x20000, 0x20000); memcpy(System16Rom + 0x30000, pTemp + 0x00000, 0x10000); - if (pTemp) { - free(pTemp); - pTemp = NULL; - } + BurnFree(pTemp); nRet = 0; } - + return nRet; } diff --git a/src/burn/drivers/sega/d_outrun.cpp b/src/burn/drivers/sega/d_outrun.cpp index ede5fe0fc..df8169a2b 100644 --- a/src/burn/drivers/sega/d_outrun.cpp +++ b/src/burn/drivers/sega/d_outrun.cpp @@ -1404,7 +1404,7 @@ static INT32 OutrunInit() INT32 nRet = System16Init(); if (!nRet) { - UINT8 *pTemp = (UINT8*)malloc(0x30000); + UINT8 *pTemp = (UINT8*)BurnMalloc(0x30000); memcpy(pTemp, System16PCMData, 0x30000); memset(System16PCMData, 0, 0x60000); memcpy(System16PCMData + 0x00000, pTemp + 0x00000, 0x8000); @@ -1419,10 +1419,7 @@ static INT32 OutrunInit() memcpy(System16PCMData + 0x48000, pTemp + 0x20000, 0x8000); memcpy(System16PCMData + 0x50000, pTemp + 0x28000, 0x8000); memcpy(System16PCMData + 0x58000, pTemp + 0x28000, 0x8000); - if (pTemp) { - free(pTemp); - pTemp = NULL; - } + BurnFree(pTemp); } return nRet; @@ -1475,7 +1472,7 @@ static INT32 OutrunbInit() byte[i] = BITSWAP08(byte[i], 7,5,6,4,3,2,1,0); } - UINT8 *pTemp = (UINT8*)malloc(0x30000); + UINT8 *pTemp = (UINT8*)BurnMalloc(0x30000); memcpy(pTemp, System16PCMData, 0x30000); memset(System16PCMData, 0, 0x60000); memcpy(System16PCMData + 0x00000, pTemp + 0x00000, 0x8000); @@ -1484,10 +1481,7 @@ static INT32 OutrunbInit() memcpy(System16PCMData + 0x30000, pTemp + 0x18000, 0x8000); memcpy(System16PCMData + 0x40000, pTemp + 0x20000, 0x8000); memcpy(System16PCMData + 0x50000, pTemp + 0x28000, 0x8000); - if (pTemp) { - free(pTemp); - pTemp = NULL; - } + BurnFree(pTemp); } return nRet; @@ -1515,7 +1509,7 @@ static INT32 ShangonInit() System16RoadColorOffset2 = 0x7c0; System16RoadColorOffset3 = 0x7c0; - UINT8 *pTemp = (UINT8*)malloc(0x20000); + UINT8 *pTemp = (UINT8*)BurnMalloc(0x20000); memcpy(pTemp, System16PCMData, 0x20000); memset(System16PCMData, 0, 0x40000); memcpy(System16PCMData + 0x00000, pTemp + 0x00000, 0x8000); @@ -1526,6 +1520,7 @@ static INT32 ShangonInit() memcpy(System16PCMData + 0x28000, pTemp + 0x10000, 0x8000); memcpy(System16PCMData + 0x30000, pTemp + 0x18000, 0x8000); memcpy(System16PCMData + 0x38000, pTemp + 0x18000, 0x8000); + BurnFree(pTemp); } return nRet; diff --git a/src/burn/drivers/sega/genesis_vid.cpp b/src/burn/drivers/sega/genesis_vid.cpp index fffa915a5..b27f5e2e9 100644 --- a/src/burn/drivers/sega/genesis_vid.cpp +++ b/src/burn/drivers/sega/genesis_vid.cpp @@ -255,7 +255,7 @@ static void VDPDataWrite(UINT16 data) } case 0x03: { - int offset = (VdpAddress >> 1) % CRAM_SIZE; + INT32 offset = (VdpAddress >> 1) % CRAM_SIZE; //palette_set_color(Machine, offset + genesis_palette_base, pal3bit(data >> 1), pal3bit(data >> 5), pal3bit(data >> 9)); //System16Palette[offset + 0x1800 /*GenesisPaletteBase*/] = BurnHighCol(pal3bit(data >> 1), pal3bit(data >> 5), pal3bit(data >> 9), 0); GenesisPalette[offset + GenesisPaletteBase] = BurnHighCol(pal3bit(data >> 1), pal3bit(data >> 5), pal3bit(data >> 9), 0); @@ -310,9 +310,9 @@ INT32 StartGenesisVDP(INT32 ScreenNum, UINT32* pal) GenesisPalette = pal; - VdpVRAM = (UINT8*)malloc(VRAM_SIZE); - VdpVSRAM = (UINT8*)malloc(VSRAM_SIZE); - VdpTransLookup = (UINT16*)malloc(0x1000 * sizeof(UINT16)); + VdpVRAM = (UINT8*)BurnMalloc(VRAM_SIZE); + VdpVSRAM = (UINT8*)BurnMalloc(VSRAM_SIZE); + VdpTransLookup = (UINT16*)BurnMalloc(0x1000 * sizeof(UINT16)); memset(VdpVRAM, 0, VRAM_SIZE); memset(VdpVSRAM, 0, VSRAM_SIZE); @@ -350,18 +350,9 @@ INT32 StartGenesisVDP(INT32 ScreenNum, UINT32* pal) void GenesisVDPExit() { - if (VdpVRAM) { - free(VdpVRAM); - VdpVRAM = NULL; - } - if (VdpVSRAM) { - free(VdpVSRAM); - VdpVSRAM = NULL; - } - if (VdpTransLookup) { - free(VdpTransLookup); - VdpTransLookup = NULL; - } + BurnFree(VdpVRAM); + BurnFree(VdpVSRAM); + BurnFree(VdpTransLookup); memset(GenesisVdpRegs, 0, sizeof(GenesisVdpRegs)); memset(GenesisBgPalLookup, 0, sizeof(GenesisBgPalLookup)); diff --git a/src/burn/drivers/sega/sys16_fd1094.cpp b/src/burn/drivers/sega/sys16_fd1094.cpp index 01c688296..c2aa43344 100644 --- a/src/burn/drivers/sega/sys16_fd1094.cpp +++ b/src/burn/drivers/sega/sys16_fd1094.cpp @@ -164,7 +164,7 @@ void fd1094_driver_init(INT32 nCPU) for (i=0;i= 0 && y <= 223) { UINT16* pPixel = pTransDraw + (y * 320); - int xacc = 0; + INT32 xacc = 0; /* non-flipped case */ if (!flip) @@ -2353,7 +2323,7 @@ static void YBoardSystem16BRenderSpriteLayer() /* skip drawing if not within the cliprect */ if (y >= 0 && y <= 223) { UINT16* pPixel = pTransDraw + (y * 320); - int xacc; + INT32 xacc; /* compute the initial X zoom accumulator; this is verified on the real PCB */ xacc = 4 * hzoom; diff --git a/src/burn/drivers/sega/sys16_run.cpp b/src/burn/drivers/sega/sys16_run.cpp index 0f1dce738..ab10217d9 100644 --- a/src/burn/drivers/sega/sys16_run.cpp +++ b/src/burn/drivers/sega/sys16_run.cpp @@ -1093,7 +1093,7 @@ static INT32 System16LoadRoms(bool bLoad) // Tile Roms Offset = 0; - System16TempGfx = (UINT8*)malloc(System16TileRomSize); + System16TempGfx = (UINT8*)BurnMalloc(System16TileRomSize); for (i = System16RomNum + System16Rom2Num + System16Rom3Num; i < System16RomNum + System16Rom2Num + System16Rom3Num + System16TileRomNum; i++) { nRet = BurnLoadRom(System16TempGfx + Offset, i, 1); if (nRet) return 1; @@ -1106,10 +1106,7 @@ static INT32 System16LoadRoms(bool bLoad) } } System16Decode8x8Tiles(System16Tiles, System16NumTiles, System16TileRomSize * 2 / 3, System16TileRomSize * 1 / 3, 0); - if (System16TempGfx) { - free(System16TempGfx); - System16TempGfx = NULL; - } + BurnFree(System16TempGfx); // Sprite Roms Offset = 0; @@ -1177,7 +1174,7 @@ static INT32 System16LoadRoms(bool bLoad) // Road Roms if (System16RoadRomSize) { Offset = 0; - System16TempGfx = (UINT8*)malloc(System16RoadRomSize); + System16TempGfx = (UINT8*)BurnMalloc(System16RoadRomSize); for (i = System16RomNum + System16Rom2Num + System16Rom3Num + System16TileRomNum + System16SpriteRomNum + System16Sprite2RomNum; i < System16RomNum + System16Rom2Num + System16Rom3Num + System16TileRomNum + System16SpriteRomNum + System16Sprite2RomNum + System16RoadRomNum; i++) { nRet = BurnLoadRom(System16TempGfx + Offset, i, 1); if (nRet) return 1; @@ -1186,10 +1183,7 @@ static INT32 System16LoadRoms(bool bLoad) } if ((BurnDrvGetHardwareCode() & HARDWARE_PUBLIC_MASK) == HARDWARE_SEGA_OUTRUN || (BurnDrvGetHardwareCode() & HARDWARE_PUBLIC_MASK) == HARDWARE_SEGA_SYSTEMX) OutrunDecodeRoad(); if ((BurnDrvGetHardwareCode() & HARDWARE_PUBLIC_MASK) == HARDWARE_SEGA_HANGON) HangonDecodeRoad(); - if (System16TempGfx) { - free(System16TempGfx); - System16TempGfx = NULL; - } + BurnFree(System16TempGfx); } // Z80 Program Roms @@ -1338,15 +1332,14 @@ static INT32 System16LoadRoms(bool bLoad) INT32 CustomLoadRom20000() { INT32 nRet = 1; - UINT8 *pTemp = (UINT8*)malloc(0xc0000); + UINT8 *pTemp = (UINT8*)BurnMalloc(0xc0000); if (pTemp) { memcpy(pTemp, System16Rom, 0xc0000); memset(System16Rom, 0, 0xc0000); memcpy(System16Rom + 0x00000, pTemp + 0x00000, 0x20000); memcpy(System16Rom + 0x80000, pTemp + 0x20000, 0x40000); - free(pTemp); - pTemp = NULL; + BurnFree(pTemp); nRet = 0; } @@ -1356,15 +1349,14 @@ INT32 CustomLoadRom20000() INT32 CustomLoadRom40000() { INT32 nRet = 1; - UINT8 *pTemp = (UINT8*)malloc(0xc0000); + UINT8 *pTemp = (UINT8*)BurnMalloc(0xc0000); if (pTemp) { memcpy(pTemp, System16Rom, 0xc0000); memset(System16Rom, 0, 0xc0000); memcpy(System16Rom + 0x00000, pTemp + 0x00000, 0x40000); memcpy(System16Rom + 0x80000, pTemp + 0x40000, 0x40000); - free(pTemp); - pTemp = NULL; + BurnFree(pTemp); nRet = 0; } @@ -1732,7 +1724,7 @@ INT32 System16Init() System16LoadRoms(0); // Get required rom sizes System16MemIndex(); nLen = MemEnd - (UINT8 *)0; - if ((Mem = (UINT8 *)malloc(nLen)) == NULL) return 1; + if ((Mem = (UINT8 *)BurnMalloc(nLen)) == NULL) return 1; memset(Mem, 0, nLen); System16MemIndex(); @@ -2056,6 +2048,7 @@ INT32 System16Init() if (BurnDrvGetHardwareCode() & HARDWARE_SEGA_YM2203) { BurnYM2203Init(1, 4000000, &System16YM2203IRQHandler, System16SynchroniseStream, System16GetTime, 0); + BurnYM2203SetVolumeShift(2); BurnTimerAttachZet(4000000); } else { BurnYM2151Init(4000000, 25.0); @@ -2327,29 +2320,40 @@ INT32 System16Exit() INT32 i; SekExit(); - ZetExit(); - N7751Exit(); + if (System16Z80RomNum) ZetExit(); + if (System167751ProgSize) { + N7751Exit(); + DACExit(); + } - BurnYM3438Exit(); - BurnYM2203Exit(); - BurnYM2413Exit(); - BurnYM2151Exit(); - - SegaPCMExit(); - DACExit(); - UPD7759Exit(); + if ((BurnDrvGetHardwareCode() & HARDWARE_PUBLIC_MASK) == HARDWARE_SEGA_SYSTEM18) { + BurnYM3438Exit(); + RF5C68PCMExit(); + } else { + if (BurnDrvGetHardwareCode() & HARDWARE_SEGA_YM2203) { + BurnYM2203Exit(); + } else { + if (BurnDrvGetHardwareCode() & HARDWARE_SEGA_YM2413) { + BurnYM2413Exit(); + } else { + BurnYM2151Exit(); + } + } + } + + if (System16PCMDataSize) SegaPCMExit(); + if (System16UPD7759DataSize) UPD7759Exit(); - ppi8255_exit(); + if (((BurnDrvGetHardwareCode() & HARDWARE_PUBLIC_MASK) == HARDWARE_SEGA_SYSTEM16A) || ((BurnDrvGetHardwareCode() & HARDWARE_PUBLIC_MASK) == HARDWARE_SEGA_HANGON) || ((BurnDrvGetHardwareCode() & HARDWARE_PUBLIC_MASK) == HARDWARE_SEGA_OUTRUN)) { + ppi8255_exit(); + } - BurnGunExit(); + if (nBurnGunNumPlayers) BurnGunExit(); GenericTilesExit(); System16TileMapsExit(); - if (Mem) { - free(Mem); - Mem = NULL; - } + BurnFree(Mem); // Reset Variables for (i = 0; i < 4; i++) { @@ -2732,7 +2736,7 @@ INT32 System18Frame() } ZetOpen(0); - BurnYM3438Update(pBurnSoundOut, nBurnSoundLen); + if (pBurnSoundOut) BurnYM3438Update(pBurnSoundOut, nBurnSoundLen); ZetClose(); if (pBurnDraw) { @@ -2840,8 +2844,6 @@ INT32 HangonYM2203Frame() nCyclesTotal[2] = 4000000 / 60; nSystem16CyclesDone[0] = nSystem16CyclesDone[1] = nSystem16CyclesDone[2] = 0; - INT32 nSoundBufferPos = 0; - SekNewFrame(); ZetNewFrame(); @@ -2868,16 +2870,6 @@ INT32 HangonYM2203Frame() ZetOpen(0); BurnTimerUpdate(i * (nCyclesTotal[2] / nInterleave)); ZetClose(); - - if (pBurnSoundOut) { - INT32 nSegmentLength = nBurnSoundLen - nSoundBufferPos; - INT16* pSoundBuf = pBurnSoundOut + (nSoundBufferPos << 1); - ZetOpen(0); - BurnYM2203Update(pSoundBuf, nSegmentLength); - SegaPCMUpdate(pSoundBuf, nSegmentLength); - ZetClose(); - nSoundBufferPos += nSegmentLength; - } } SekOpen(0); @@ -2889,14 +2881,10 @@ INT32 HangonYM2203Frame() ZetClose(); if (pBurnSoundOut) { - INT32 nSegmentLength = nBurnSoundLen - nSoundBufferPos; - INT16* pSoundBuf = pBurnSoundOut + (nSoundBufferPos << 1); - if (nSegmentLength) { - ZetOpen(0); - BurnYM2203Update(pSoundBuf, nSegmentLength); - SegaPCMUpdate(pSoundBuf, nSegmentLength); - ZetClose(); - } + ZetOpen(0); + BurnYM2203Update(pBurnSoundOut, nBurnSoundLen); + SegaPCMUpdate(pBurnSoundOut, nBurnSoundLen); + ZetClose(); } if (Simulate8751) Simulate8751();