Initial tidying of Sega drivers

This commit is contained in:
Barry Harris 2011-12-19 21:35:52 +00:00
parent eba6851149
commit 3c90492b10
6 changed files with 89 additions and 154 deletions

View File

@ -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;
}

View File

@ -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;

View File

@ -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));

View File

@ -164,7 +164,7 @@ void fd1094_driver_init(INT32 nCPU)
for (i=0;i<S16_NUMCACHE;i++)
{
fd1094_cacheregion[i]=(UINT16*)malloc(fd1094_cpuregionsize);
fd1094_cacheregion[i]=(UINT16*)BurnMalloc(fd1094_cpuregionsize);
}
/* flush the cached state array */
@ -181,10 +181,7 @@ void fd1094_exit()
nFD1094CPU = 0;
for (INT32 i = 0; i < S16_NUMCACHE; i++) {
if (fd1094_cacheregion[i]) {
free(fd1094_cacheregion[i]);
fd1094_cacheregion[i] = NULL;
}
BurnFree(fd1094_cacheregion[i]);
}
fd1094_current_cacheposition = 0;

View File

@ -162,75 +162,45 @@ static void RenderTile_Mask(UINT16* pDestDraw, INT32 nTileNumber, INT32 StartX,
void System16ATileMapsInit(INT32 bOpaque)
{
if (bOpaque) {
pSys16BgTileMapOpaque = (UINT16*)malloc(1024 * 512 * sizeof(UINT16));
pSys16BgTileMapOpaque = (UINT16*)BurnMalloc(1024 * 512 * sizeof(UINT16));
}
pSys16BgTileMapPri0 = (UINT16*)malloc(1024 * 512 * sizeof(UINT16));
pSys16BgTileMapPri1 = (UINT16*)malloc(1024 * 512 * sizeof(UINT16));
pSys16FgTileMapPri0 = (UINT16*)malloc(1024 * 512 * sizeof(UINT16));
pSys16FgTileMapPri1 = (UINT16*)malloc(1024 * 512 * sizeof(UINT16));
pSys16BgTileMapPri0 = (UINT16*)BurnMalloc(1024 * 512 * sizeof(UINT16));
pSys16BgTileMapPri1 = (UINT16*)BurnMalloc(1024 * 512 * sizeof(UINT16));
pSys16FgTileMapPri0 = (UINT16*)BurnMalloc(1024 * 512 * sizeof(UINT16));
pSys16FgTileMapPri1 = (UINT16*)BurnMalloc(1024 * 512 * sizeof(UINT16));
}
void System16BTileMapsInit(INT32 bOpaque)
{
if (bOpaque) {
pSys16BgTileMapOpaque = (UINT16*)malloc(1024 * 512 * sizeof(UINT16));
pSys16BgAltTileMapOpaque = (UINT16*)malloc(1024 * 512 * sizeof(UINT16));
pSys16BgTileMapOpaque = (UINT16*)BurnMalloc(1024 * 512 * sizeof(UINT16));
pSys16BgAltTileMapOpaque = (UINT16*)BurnMalloc(1024 * 512 * sizeof(UINT16));
}
pSys16BgTileMapPri0 = (UINT16*)malloc(1024 * 512 * sizeof(UINT16));
pSys16BgTileMapPri1 = (UINT16*)malloc(1024 * 512 * sizeof(UINT16));
pSys16FgTileMapPri0 = (UINT16*)malloc(1024 * 512 * sizeof(UINT16));
pSys16FgTileMapPri1 = (UINT16*)malloc(1024 * 512 * sizeof(UINT16));
pSys16BgTileMapPri0 = (UINT16*)BurnMalloc(1024 * 512 * sizeof(UINT16));
pSys16BgTileMapPri1 = (UINT16*)BurnMalloc(1024 * 512 * sizeof(UINT16));
pSys16FgTileMapPri0 = (UINT16*)BurnMalloc(1024 * 512 * sizeof(UINT16));
pSys16FgTileMapPri1 = (UINT16*)BurnMalloc(1024 * 512 * sizeof(UINT16));
pSys16BgAltTileMapPri0 = (UINT16*)malloc(1024 * 512 * sizeof(UINT16));
pSys16BgAltTileMapPri1 = (UINT16*)malloc(1024 * 512 * sizeof(UINT16));
pSys16FgAltTileMapPri0 = (UINT16*)malloc(1024 * 512 * sizeof(UINT16));
pSys16FgAltTileMapPri1 = (UINT16*)malloc(1024 * 512 * sizeof(UINT16));
pSys16BgAltTileMapPri0 = (UINT16*)BurnMalloc(1024 * 512 * sizeof(UINT16));
pSys16BgAltTileMapPri1 = (UINT16*)BurnMalloc(1024 * 512 * sizeof(UINT16));
pSys16FgAltTileMapPri0 = (UINT16*)BurnMalloc(1024 * 512 * sizeof(UINT16));
pSys16FgAltTileMapPri1 = (UINT16*)BurnMalloc(1024 * 512 * sizeof(UINT16));
}
void System16TileMapsExit()
{
if (pSys16BgTileMapOpaque) {
free(pSys16BgTileMapOpaque);
pSys16BgTileMapOpaque = NULL;
}
if (pSys16BgAltTileMapOpaque) {
free(pSys16BgAltTileMapOpaque);
pSys16BgAltTileMapOpaque = NULL;
}
if (pSys16BgTileMapPri0) {
free(pSys16BgTileMapPri0);
pSys16BgTileMapPri0 = NULL;
}
if (pSys16BgTileMapPri1) {
free(pSys16BgTileMapPri1);
pSys16BgTileMapPri1 = NULL;
}
if (pSys16FgTileMapPri0) {
free(pSys16FgTileMapPri0);
pSys16FgTileMapPri0 = NULL;
}
if (pSys16FgTileMapPri1) {
free(pSys16FgTileMapPri1);
pSys16FgTileMapPri1 = NULL;
}
if (pSys16BgAltTileMapPri0) {
free(pSys16BgAltTileMapPri0);
pSys16BgAltTileMapPri0 = NULL;
}
if (pSys16BgAltTileMapPri1) {
free(pSys16BgAltTileMapPri1);
pSys16BgAltTileMapPri1 = NULL;
}
if (pSys16FgAltTileMapPri0) {
free(pSys16FgAltTileMapPri0);
pSys16FgAltTileMapPri0 = NULL;
}
if (pSys16FgAltTileMapPri1) {
free(pSys16FgAltTileMapPri1);
pSys16FgAltTileMapPri1 = NULL;
}
BurnFree(pSys16BgTileMapOpaque);
BurnFree(pSys16BgAltTileMapOpaque);
BurnFree(pSys16BgTileMapPri0);
BurnFree(pSys16BgTileMapPri1);
BurnFree(pSys16FgTileMapPri0);
BurnFree(pSys16FgTileMapPri1);
BurnFree(pSys16BgAltTileMapPri0);
BurnFree(pSys16BgAltTileMapPri1);
BurnFree(pSys16FgAltTileMapPri0);
BurnFree(pSys16FgAltTileMapPri1);
}
static void System16ACreateBgTileMaps()
@ -1855,7 +1825,7 @@ static void OutrunRenderSpriteLayer(INT32 Priority)
/* skip drawing if not within the cliprect */
if (y >= 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;

View File

@ -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();