Commit 177c8642 authored by barbudreadmon's avatar barbudreadmon
Browse files

Merge branch 'master' of https://github.com/barry65536/FBAlpha into barry65536-master

parents f4ff1c11 834282a4
......@@ -359,6 +359,7 @@ INT32 BurnDrvGetHDDName(char** pszName, UINT32 i, INT32 nAka);
void Reinitialise();
extern bool bDoIpsPatch;
extern INT32 nIpsMaxFileLen;
void IpsApplyPatches(UINT8* base, char* rom_name);
// ---------------------------------------------------------------------------
......
......@@ -16,7 +16,6 @@ static UINT8 *Ram01;
static UINT8 *DefaultEEPROM = NULL;
static UINT8 DrvReset = 0;
static UINT8 bDrawScreen;
static bool bVBlank;
static INT8 nVideoIRQ;
......@@ -200,7 +199,6 @@ void __fastcall espradeWriteWord(UINT32 sekAddress, UINT16 wordValue)
nCaveYOffset = wordValue;
return;
case 0x800008:
CaveSpriteBuffer();
nCaveSpriteBank = wordValue;
return;
......@@ -292,14 +290,13 @@ static INT32 DrvDoReset()
EEPROMReset();
nVideoIRQ = 1;
YMZ280BReset();
nVideoIRQ = 1;
nSoundIRQ = 1;
nUnknownIRQ = 1;
nIRQPending = 0;
YMZ280BReset();
nCyclesExtra = 0;
HiscoreReset();
......@@ -312,24 +309,15 @@ static INT32 DrvDraw()
CavePalUpdate8Bit(0, 128); // Update the palette
CaveClearScreen(CavePalette[0x0000]);
if (bDrawScreen) {
// CaveGetBitmap();
CaveTileRender(1); // Render tiles
}
return 0;
}
CaveTileRender(1); // Render tiles
inline static INT32 CheckSleep(INT32)
{
return 0;
}
static INT32 DrvFrame()
{
INT32 nCyclesVBlank;
INT32 nInterleave = 8;
INT32 nInterleave = 32;
if (DrvReset) { // Reset machine
DrvDoReset();
......@@ -377,38 +365,28 @@ static INT32 DrvFrame()
nNext = i * nCyclesTotal[nCurrentCPU] / nInterleave;
// See if we need to trigger the VBlank interrupt
if (!bVBlank && nNext > nCyclesVBlank) {
if (!bVBlank && nNext >= nCyclesVBlank) {
if (nCyclesDone[nCurrentCPU] < nCyclesVBlank) {
nCyclesSegment = nCyclesVBlank - nCyclesDone[nCurrentCPU];
if (!CheckSleep(nCurrentCPU)) { // See if this CPU is busywaiting
nCyclesDone[nCurrentCPU] += SekRun(nCyclesSegment);
} else {
nCyclesDone[nCurrentCPU] += SekIdle(nCyclesSegment);
}
}
if (pBurnDraw != NULL) {
DrvDraw(); // Draw screen if needed
nCyclesDone[nCurrentCPU] += SekRun(nCyclesSegment);
}
bVBlank = true;
nVideoIRQ = 0;
UpdateIRQStatus();
CaveSpriteBuffer();
}
nCyclesSegment = nNext - nCyclesDone[nCurrentCPU];
if (!CheckSleep(nCurrentCPU)) { // See if this CPU is busywaiting
nCyclesDone[nCurrentCPU] += SekRun(nCyclesSegment+nCyclesExtra);
nCyclesExtra = 0;
} else {
nCyclesDone[nCurrentCPU] += SekIdle(nCyclesSegment);
}
nCyclesDone[nCurrentCPU] += SekRun(nCyclesSegment - nCyclesExtra);
nCyclesExtra = 0;
nCurrentCPU = -1;
}
// Make sure the buffer is entirely filled.
{
// Make sure the buffer is entirely filled.
if (pBurnSoundOut) {
INT32 nSegmentLength = nBurnSoundLen - nSoundBufferPos;
INT16* pSoundBuf = pBurnSoundOut + (nSoundBufferPos << 1);
......@@ -421,6 +399,10 @@ static INT32 DrvFrame()
nCyclesExtra = SekTotalCycles() - nCyclesTotal[0];
SekClose();
if (pBurnDraw != NULL) {
DrvDraw(); // Draw screen if needed
}
return 0;
}
......@@ -534,8 +516,6 @@ static INT32 DrvScan(INT32 nAction, INT32 *pnMin)
SCAN_VAR(bVBlank);
CaveScanGraphics();
SCAN_VAR(DrvInput);
}
if (nAction & ACB_WRITE) {
......@@ -607,8 +587,6 @@ static INT32 DrvInit()
YMZ280BSetRoute(BURN_SND_YMZ280B_YMZ280B_ROUTE_2, 1.00, BURN_SND_ROUTE_RIGHT);
bESPRaDeMixerKludge = true;
bDrawScreen = true;
DrvDoReset(); // Reset machine
return 0;
......
......@@ -15,7 +15,6 @@ static UINT8 *Ram01;
static UINT8 *DefaultEEPROM = NULL;
static UINT8 DrvReset = 0;
static UINT8 bDrawScreen;
static bool bVBlank;
static INT8 nVideoIRQ;
......@@ -183,7 +182,6 @@ void __fastcall guwangeWriteWord(UINT32 sekAddress, UINT16 wordValue)
nCaveYOffset = wordValue;
return;
case 0x300008:
CaveSpriteBuffer();
nCaveSpriteBank = wordValue;
return;
......@@ -299,11 +297,7 @@ static INT32 DrvDraw()
CavePalUpdate8Bit(0, 128); // Update the palette
CaveClearScreen(CavePalette[0x7F00]);
if (bDrawScreen) {
// CaveGetBitmap();
CaveTileRender(1); // Render tiles
}
CaveTileRender(1); // Render tiles
return 0;
}
......@@ -318,15 +312,10 @@ inline static void guwangeClearOpposites(UINT8* nJoystickInputs)
}
}
inline static INT32 CheckSleep(INT32)
{
return 0;
}
static INT32 DrvFrame()
{
INT32 nCyclesVBlank;
INT32 nInterleave = 8;
INT32 nInterleave = 32;
if (DrvReset) { // Reset machine
DrvDoReset();
......@@ -372,32 +361,22 @@ static INT32 DrvFrame()
nNext = i * nCyclesTotal[nCurrentCPU] / nInterleave;
// See if we need to trigger the VBlank interrupt
if (!bVBlank && nNext > nCyclesVBlank) {
if (!bVBlank && nNext >= nCyclesVBlank) {
if (nCyclesDone[nCurrentCPU] < nCyclesVBlank) {
nCyclesSegment = nCyclesVBlank - nCyclesDone[nCurrentCPU];
if (!CheckSleep(nCurrentCPU)) { // See if this CPU is busywaiting
nCyclesDone[nCurrentCPU] += SekRun(nCyclesSegment);
} else {
nCyclesDone[nCurrentCPU] += SekIdle(nCyclesSegment);
}
}
if (pBurnDraw != NULL) {
DrvDraw(); // Draw screen if needed
nCyclesDone[nCurrentCPU] += SekRun(nCyclesSegment);
}
bVBlank = true;
nVideoIRQ = 0;
UpdateIRQStatus();
CaveSpriteBuffer();
}
nCyclesSegment = nNext - nCyclesDone[nCurrentCPU];
if (!CheckSleep(nCurrentCPU)) { // See if this CPU is busywaiting
nCyclesDone[nCurrentCPU] += SekRun(nCyclesSegment+nCyclesExtra);
nCyclesExtra = 0;
} else {
nCyclesDone[nCurrentCPU] += SekIdle(nCyclesSegment);
}
nCyclesDone[nCurrentCPU] += SekRun(nCyclesSegment - nCyclesExtra);
nCyclesExtra = 0;
nCurrentCPU = -1;
}
......@@ -412,10 +391,14 @@ static INT32 DrvFrame()
}
}
}
nCyclesExtra = SekTotalCycles() - nCyclesTotal[0];
nCyclesExtra = SekTotalCycles() - nCyclesTotal[0];
SekClose();
if (pBurnDraw != NULL) {
DrvDraw(); // Draw screen if needed
}
return 0;
}
......@@ -483,26 +466,7 @@ static INT32 LoadRoms()
BurnLoadRom(CaveSpriteROM + 0x1000001, 5, 2);
NibbleSwap3(CaveSpriteROM, 0xC00000);
#if 0
// I don't think this is needed anymore, dink aug 14 2016.
// note: if enabled-this causes the screen fade-in effect after starting
// a game @ the character selection screen to display garbage sprite data.
for (INT32 i = 0; i < 0x100000; i++) {
UINT16 nValue = rand() & 0x0101;
if (nValue & 0x0001) {
nValue |= 0x00FF;
}
if (nValue & 0x0100) {
nValue |= 0xFF00;
}
((UINT16*)(CaveSpriteROM + 0x1800000))[i] = nValue;
((UINT16*)(CaveSpriteROM + 0x1A00000))[i] = nValue;
((UINT16*)(CaveSpriteROM + 0x1C00000))[i] = nValue;
((UINT16*)(CaveSpriteROM + 0x1E00000))[i] = nValue;
}
#else
memcpy(CaveSpriteROM + 0x1800000, CaveSpriteROM + 0x1000000, 0x800000);
#endif
BurnLoadRom(CaveTileROM[0] + 0x000000, 6, 1);
NibbleSwap4(CaveTileROM[0], 0x400000);
......@@ -548,8 +512,6 @@ static INT32 DrvScan(INT32 nAction, INT32 *pnMin)
SCAN_VAR(bVBlank);
CaveScanGraphics();
SCAN_VAR(DrvInput);
}
if (nAction & ACB_WRITE) {
......@@ -622,8 +584,6 @@ static INT32 DrvInit()
YMZ280BSetRoute(BURN_SND_YMZ280B_YMZ280B_ROUTE_1, 1.00, BURN_SND_ROUTE_LEFT);
YMZ280BSetRoute(BURN_SND_YMZ280B_YMZ280B_ROUTE_2, 1.00, BURN_SND_ROUTE_RIGHT);
bDrawScreen = true;
DrvDoReset(); // Reset machine
return 0;
......
// FB Alpha ColecoVision console driver module
// Code by iq_132, fixups & bring up-to-date by dink Aug 19, 2014
// SGM added April 2019 -dink
#include "tiles_generic.h"
#include "z80_intf.h"
#include "driver.h"
#include "sn76496.h"
#include "ay8910.h" // sgm
#include "tms9928a.h"
static UINT8 *AllMem;
......@@ -14,6 +16,8 @@ static UINT8 *RamEnd;
static UINT8 *DrvZ80BIOS;
static UINT8 *DrvCartROM;
static UINT8 *DrvZ80RAM;
static UINT8 *DrvSGM24kRAM;
static UINT8 *DrvSGM8kRAM;
static INT32 joy_mode;
static INT32 joy_status[2];
......@@ -29,6 +33,10 @@ static UINT8 DrvReset;
static UINT32 MegaCart;
static UINT32 MegaCartBank;
static INT32 use_SGM = 0;
static INT32 SGM_map_24k;
static INT32 SGM_map_8k;
static struct BurnRomInfo emptyRomDesc[] = {
{ "", 0, 0, 0 },
};
......@@ -217,9 +225,55 @@ static void paddle_callback()
}
}
void update_map()
{
if (!use_SGM) return;
if (SGM_map_24k) {
ZetMapMemory(DrvSGM24kRAM, 0x2000, 0x7fff, MAP_RAM);
} else {
ZetUnmapMemory(0x2000, 0x7fff, MAP_RAM);
// normal CV 1k ram +mirrored
for (INT32 i = 0x6000; i < 0x8000; i+=0x0400) {
ZetMapMemory(DrvZ80RAM, i + 0x0000, i + 0x03ff, MAP_RAM);
}
}
if (SGM_map_8k) {
ZetMapMemory(DrvSGM8kRAM, 0x0000, 0x1fff, MAP_RAM);
} else {
ZetUnmapMemory(0x0000, 0x1fff, MAP_RAM);
ZetMapMemory(DrvZ80BIOS, 0x0000, 0x1fff, MAP_ROM);
}
}
static void __fastcall coleco_write_port(UINT16 port, UINT8 data)
{
switch (port & ~0xff1e)
if (use_SGM) {
switch (port & 0xff) // SGM
{
case 0x50:
AY8910Write(0, 0, data);
return;
case 0x51:
AY8910Write(0, 1, data);
return;
case 0x53:
SGM_map_24k = data & 1;
update_map();
return;
case 0x7f:
SGM_map_8k = ~data & 2;
update_map();
return;
}
}
switch (port & ~0xff1e)
{
case 0x80:
case 0x81:
......@@ -250,6 +304,13 @@ static UINT8 __fastcall coleco_read_port(UINT16 port)
{
port &= 0xff;
if (use_SGM) {
switch (port)
{
case 0x52: return AY8910Read(0);
}
}
switch (port & ~0x1e)
{
case 0xa0:
......@@ -296,6 +357,8 @@ static INT32 DrvDoReset()
BurnLoadRom(DrvZ80BIOS, 0x80 + (DrvDips[1] & 3), 1);
CVFastLoadHack();
AY8910Reset(0);
ZetOpen(0);
ZetReset();
ZetSetVector(0xff);
......@@ -307,6 +370,8 @@ static INT32 DrvDoReset()
last_state = 0; // irq state...
MegaCartBank = 0;
SGM_map_24k = 0;
SGM_map_8k = 0;
return 0;
}
......@@ -350,7 +415,10 @@ static INT32 MemIndex()
DrvZ80RAM = Next; Next += 0x000400;
RamEnd = Next;
DrvSGM24kRAM = Next; Next += 0x006000; // SGM
DrvSGM8kRAM = Next; Next += 0x002000;
RamEnd = Next;
MemEnd = Next;
return 0;
......@@ -391,13 +459,10 @@ static INT32 DrvInit()
ZetInit(0);
ZetOpen(0);
ZetMapArea(0x0000, 0x1fff, 0, DrvZ80BIOS);
ZetMapArea(0x0000, 0x1fff, 2, DrvZ80BIOS);
ZetMapMemory(DrvZ80BIOS, 0x0000, 0x1fff, MAP_ROM);
for (INT32 i = 0x6000; i < 0x8000; i+=0x0400) {
ZetMapArea(i + 0x0000, i + 0x03ff, 0, DrvZ80RAM);
ZetMapArea(i + 0x0000, i + 0x03ff, 1, DrvZ80RAM);
ZetMapArea(i + 0x0000, i + 0x03ff, 2, DrvZ80RAM);
ZetMapMemory(DrvZ80RAM, i + 0x0000, i + 0x03ff, MAP_RAM);
}
if (MegaCart) {
......@@ -405,17 +470,14 @@ static INT32 DrvInit()
UINT32 MegaCartBanks = MegaCart / 0x4000;
UINT32 lastbank = (MegaCartBanks - 1) * 0x4000;
bprintf(0, _T("ColecoVision MegaCart: mapping cartrom[%X] to 0x8000 - 0xbfff.\n"), lastbank);
ZetMapArea(0x8000, 0xbfff, 0, DrvCartROM + lastbank);
ZetMapArea(0x8000, 0xbfff, 2, DrvCartROM + lastbank);
ZetMapMemory(DrvCartROM + lastbank, 0x8000, 0xbfff, MAP_ROM);
ZetSetReadHandler(main_read);
//ZetSetWriteHandler(main_write);
} else {
// Regular CV Cart
ZetMapArea(0x8000, 0xffff, 0, DrvCartROM);
ZetMapArea(0x8000, 0xffff, 2, DrvCartROM);
ZetMapMemory(DrvCartROM, 0x8000, 0xffff, MAP_ROM);
}
ZetSetOutHandler(coleco_write_port);
ZetSetInHandler(coleco_read_port);
ZetClose();
......@@ -424,19 +486,32 @@ static INT32 DrvInit()
SN76489AInit(0, 3579545, 0);
AY8910Init(0, 3579545, 1); // SGM
AY8910SetAllRoutes(0, 0.30, BURN_SND_ROUTE_BOTH);
DrvDoReset();
return 0;
}
static INT32 DrvInitSGM() // w/SGM
{
use_SGM = 1;
return DrvInit();
}
static INT32 DrvExit()
{
TMS9928AExit();
ZetExit();
SN76496Exit();
AY8910Exit(0);
BurnFree (AllMem);
use_SGM = 0;
return 0;
}
......@@ -459,6 +534,7 @@ static INT32 DrvFrame()
INT32 nInterleave = 256;
INT32 nCyclesTotal = 3579545 / 60;
INT32 nCyclesDone = 0;
INT32 nSoundBufferPos = 0;
ZetOpen(0);
......@@ -469,12 +545,27 @@ static INT32 DrvFrame()
TMS9928AScanline(i);
if ((i%5)==4) paddle_callback(); // 50x / frame (3000x / sec)
// Render Sound Segment
if (pBurnSoundOut && (i%4)==3) {
INT32 nSegmentLength = nBurnSoundLen / (nInterleave/4);
INT16* pSoundBuf = pBurnSoundOut + (nSoundBufferPos << 1);
SN76496Update(0, pSoundBuf, nSegmentLength);
AY8910Render(pSoundBuf, nSegmentLength);
nSoundBufferPos += nSegmentLength;
}
}
ZetClose();
// Make sure the buffer is entirely filled.
if (pBurnSoundOut) {
SN76496Update(0, pBurnSoundOut, nBurnSoundLen);
INT32 nSegmentLength = nBurnSoundLen - nSoundBufferPos;
INT16* pSoundBuf = pBurnSoundOut + (nSoundBufferPos << 1);
if (nSegmentLength) {
SN76496Update(0, pSoundBuf, nSegmentLength);
AY8910Render(pSoundBuf, nSegmentLength);
}
}
if (pBurnDraw) {
......@@ -503,6 +594,9 @@ static INT32 DrvScan(INT32 nAction, INT32 *pnMin)
ZetScan(nAction);
SN76496Scan(nAction, pnMin);
if (use_SGM)
AY8910Scan(nAction, pnMin);
TMS9928AScan(nAction, pnMin);
SCAN_VAR(joy_mode);
......@@ -619,7 +713,7 @@ struct BurnDriver BurnDrvcv_princessquest = {
NULL, NULL, NULL, NULL,
BDF_GAME_WORKING | BDF_CLONE, 2, HARDWARE_COLECO, GBF_MISC, 0,
CVGetZipName, cv_princessquestRomInfo, cv_princessquestRomName, NULL, NULL, NULL, NULL, ColecoInputInfo, ColecoDIPInfo,
DrvInit, DrvExit, DrvFrame, TMS9928ADraw, DrvScan, NULL, TMS9928A_PALETTE_SIZE,
DrvInitSGM, DrvExit, DrvFrame, TMS9928ADraw, DrvScan, NULL, TMS9928A_PALETTE_SIZE,
272, 228, 4, 3
};
......@@ -4105,10 +4199,10 @@ STDROMPICKEXT(cv_dlair, cv_dlair, cv_coleco)
STD_ROM_FN(cv_dlair)
struct BurnDriver BurnDrvcv_dlair = {
"cv_dlair", NULL, "cv_coleco", NULL, "1984",
"cv_dlair", "cv_dlairsgm", "cv_coleco", NULL, "1984",
"Dragon's Lair (Prototype, 0416)\0", NULL, "Coleco", "ColecoVision",
NULL, NULL, NULL, NULL,
BDF_GAME_WORKING, 2, HARDWARE_COLECO, GBF_MISC, 0,
BDF_GAME_WORKING | BDF_CLONE, 2, HARDWARE_COLECO, GBF_MISC, 0,
CVGetZipName, cv_dlairRomInfo, cv_dlairRomName, NULL, NULL, NULL, NULL, ColecoInputInfo, ColecoDIPInfo,
DrvInit, DrvExit, DrvFrame, TMS9928ADraw, DrvScan, NULL, TMS9928A_PALETTE_SIZE,
272, 228, 4, 3
......@@ -4999,3 +5093,135 @@ struct BurnDriver BurnDrvcv_cvjoytest = {
DrvInit, DrvExit, DrvFrame, TMS9928ADraw, DrvScan, NULL, TMS9928A_PALETTE_SIZE,
272, 228, 4, 3
};
// CV SGM Test
static struct BurnRomInfo cv_sgmtestRomDesc[] = {
{ "super_game_module_test.rom", 0x002000, 0xabc4763d, BRF_PRG | BRF_ESS },
};
STDROMPICKEXT(cv_sgmtest, cv_sgmtest, cv_coleco)
STD_ROM_FN(cv_sgmtest)
struct BurnDriver BurnDrvcv_sgmtest = {
"cv_sgmtest", NULL, "cv_coleco", NULL, "200x",
"ColecoVision SuperGame Module (SGM) Test\0", NULL, "Coleco", "ColecoVision",
NULL, NULL, NULL, NULL,
BDF_GAME_WORKING, 2, HARDWARE_COLECO, GBF_MISC, 0,
CVGetZipName, cv_sgmtestRomInfo, cv_sgmtestRomName, NULL, NULL, NULL, NULL, ColecoInputInfo, ColecoDIPInfo,
DrvInitSGM, DrvExit, DrvFrame, TMS9928ADraw, DrvScan, NULL, TMS9928A_PALETTE_SIZE,
272, 228, 4, 3
};
// Mecha 8
static struct BurnRomInfo cv_mecha8RomDesc[] = {
{ "mecha_8.rom", 0x020000, 0x53da40bc, BRF_PRG | BRF_ESS },
};
STDROMPICKEXT(cv_mecha8, cv_mecha8, cv_coleco)
STD_ROM_FN(cv_mecha8)
struct BurnDriver BurnDrvcv_mecha8 = {
"cv_mecha8", NULL, "cv_coleco", NULL, "2013",
"Mecha-8\0", NULL, "Oscar Toledo G.", "ColecoVision",
NULL, NULL, NULL, NULL,
BDF_GAME_WORKING, 2, HARDWARE_COLECO, GBF_MISC, 0,
CVGetZipName, cv_mecha8RomInfo, cv_mecha8RomName, NULL, NULL, NULL, NULL, ColecoInputInfo, ColecoDIPInfo,
DrvInitSGM, DrvExit, DrvFrame, TMS9928ADraw, DrvScan, NULL, TMS9928A_PALETTE_SIZE,
272, 228, 4, 3
};
// Zaxxon SuperGame (SGM)
static struct BurnRomInfo cv_zaxxonsgmRomDesc[] = {
{ "zaxxon_super_game_colecovision_sgm.rom", 0x020000, 0xa5a90f63, BRF_PRG | BRF_ESS },
};
STDROMPICKEXT(cv_zaxxonsgm, cv_zaxxonsgm, cv_coleco)
STD_ROM_FN(cv_zaxxonsgm)
struct BurnDriver BurnDrvcv_zaxxonsgm = {
"cv_zaxxonsgm", NULL, "cv_coleco", NULL, "1982",
"Zaxxon Super Game\0", NULL, "Coleco", "ColecoVision",
NULL, NULL, NULL, NULL,
BDF_GAME_WORKING, 2, HARDWARE_COLECO, GBF_MISC, 0,
CVGetZipName, cv_zaxxonsgmRomInfo, cv_zaxxonsgmRomName, NULL, NULL, NULL, NULL, ColecoInputInfo, ColecoDIPInfo,
DrvInitSGM, DrvExit, DrvFrame, TMS9928ADraw, DrvScan, NULL, TMS9928A_PALETTE_SIZE,
272, 228, 4, 3
};
// Dragon's Lair (SGM)
static struct BurnRomInfo cv_dlairsgmRomDesc[] = {
{ "dragons_lair_colecovision_sgm.rom", 0x040000, 0x12ceee08, BRF_PRG | BRF_ESS },
};
STDROMPICKEXT(cv_dlairsgm, cv_dlairsgm, cv_coleco)
STD_ROM_FN(cv_dlairsgm)
struct BurnDriver BurnDrvcv_dlairsgm = {
"cv_dlairsgm", NULL, "cv_coleco", NULL, "1982",
"Dragon's Lair SGM\0", NULL, "Coleco", "ColecoVision",
NULL, NULL, NULL, NULL,
BDF_GAME_WORKING, 2, HARDWARE_COLECO, GBF_MISC, 0,
CVGetZipName, cv_dlairsgmRomInfo, cv_dlairsgmRomName, NULL, NULL, NULL, NULL, ColecoInputInfo, ColecoDIPInfo,
DrvInitSGM, DrvExit, DrvFrame, TMS9928ADraw, DrvScan, NULL, TMS9928A_PALETTE_SIZE,
272, 228, 4, 3
};