⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 d_rainbow.cpp

📁 motorola ezx 平台下的fba模拟器
💻 CPP
📖 第 1 页 / 共 2 页
字号:
		p2scrolly=-d;
		return;

	case 0xc40000:
		if (PC080SN_ctrl_word_0[0]&0x01) {
			d= -d;
		}
		p1scrollx=-d;
		return;

	case 0xc40002:
		if (PC080SN_ctrl_word_0[0]&0x01) {
			d= -d;
		}
		p2scrollx=-d;
		return;

	default:

		return;

	}
}

void __fastcall rainbowWriteByte(unsigned int a,unsigned char d)
{
	if (a>=0x800000&&a<=0x8007ff)
	{
		rainbow_cchip_ram_w((a-0x800001)/2,d);
		return;
	}

	if (a>=0x800802&&a<=0x800803)
	{
		return;
	}

	if (a>=0x800c00&&a<=0x800c01)
	{
		rainbow_cchip_bank_w(d);
		return;
	}

	switch (a)
	{
	case 0x3e0001:
		tc0140_port_w(d);
		return;
	case 0x3e0003:
		tc0140_comm_w(d);
		return;
	}
}

static int drvDoReset()
{
	SekOpen(0);
	SekReset();
	SekClose();
	ZetOpen(0);
	ZetReset();
	ZetClose();
	ZetRun(4000000/60);
	BurnYM2151Reset();
	return 0;
}

int rainbowInit()
{
	int nRet=0; int nLen=0;

	//--------------Allocate Memory-----------------
	Mem=NULL;
	MemIndex();
	nLen=MemEnd-(unsigned char *)0;
	Mem=(unsigned char *)malloc(nLen);
	if (Mem==NULL)
		return 1;
	memset(Mem,0,nLen); // blank all memory
	MemIndex(); // Index the allocated memory

	//--------------- Load Roms -------------------
	nRet=LoadRoms();
	if (nRet!=0)
		return 1; // Load the roms into memory


	// Map in memory:
	// ----------------- Cpu 1 68k ------------------------
	SekInit(0, 0x68000); // Allocate 1 68000
	SekOpen(0);
	SekMapMemory(    Rom  ,0x000000,0x07ffff,SM_ROM); // 68000 Rom
	SekMapMemory(rainbow_ram,0x10c000,0x10ffff,SM_RAM); //0x4000
	SekMapMemory(rainbow_src_pal,0x200000,0x200fff,SM_RAM);
	SekMapMemory(rainbow_ram+0x4000,0x201000,0x203fff,SM_RAM); //0x3000
	SekMapMemory(PC090OJ_spritectrl,0x3a0000,0x3a0001,SM_WRITE);
	SekMapMemory(rainbow_ram+0x7000,0x3c0000,0x3c0003,SM_RAM);
	SekMapMemory(PC080SN_word_0,0xc00000,0xc0ffff,SM_RAM);
	SekMapMemory(PC080SN_ctrl_word_0,0xc50000,0xc50003,SM_WRITE);
	SekMapMemory(PC090OJ_word_0,0xd00000,0xd03fff,SM_RAM);
	SekSetWriteWordHandler(0, rainbowWriteWord);
	SekSetReadWordHandler(0, rainbowReadWord);
	SekSetReadByteHandler(0, rainbowReadByte);
	SekSetWriteByteHandler(0, rainbowWriteByte);
	SekClose();
	// ------------------------------------------------
	// ----------------- Cpu 2 Z80 ------------------------
	ZetInit(1);
	ZetOpen(0);
	ZetSetReadHandler(rainbowZ80Read);
	ZetSetWriteHandler(rainbowZ80Write);
	ZetMapArea (0x0000,0x3FFF,0,z80_rom);
	ZetMapArea (0x0000,0x3FFF,2,z80_rom);
//	ZetMapArea (0x4000,0x7FFF,0,z80_rom+0x4000);
//	ZetMapArea (0x4000,0x7FFF,2,z80_rom+0x4000);
	ZetMapArea (0x8000,0x8FFF,0,z80_ram);
	ZetMapArea (0x8000,0x8FFF,2,z80_ram);
	ZetMapArea (0x8000,0x8FFF,1,z80_ram);
	ZetMemEnd();
	ZetMemCallback(0x9000, 0xa001, 0);			// Read
	ZetMemCallback(0x9000, 0xa001, 1);			// Write
	ZetReset();
	ZetClose();
	//-------------------------------------------------

	//-------- sound stuff ----------------------------
	//---------- YM2151 Setup ----------------------
	BurnYM2151Init(4000000, 50.0);
	BurnYM2151SetIrqHandler(&rainbowYM2151IRQHandler);
	BurnYM2151SetPortHandler(&rainbowBankSwitch);
	nCurrentBank=-1;

	//--------------------------------------------------
	// ------- GFX Init -------------------
	taito_pal=rainbow_pal;
	init_taito_gfx();
	//-------------------------------------
	if (!strcmp(BurnDrvGetTextA(DRV_NAME), "rainbowe"))
	{
		rainbow_cchip_init(1); // protection chip
	} else
	{
		rainbow_cchip_init(0); // protection chip
	}
	drvDoReset();
	return 0;
	}

int rainbowExit()
{
	rainbow_cchip_exit();
	free(tsprites);
	free(ttiles);
	BurnYM2151Exit();
	SekExit(); // Deallocate 68000
	ZetExit();
	if (Mem!=NULL)
		free(Mem);
	Mem=NULL;
	return 0;
}


static int rainbowGFX()
{
	PC080SN_bg();
	PC090OJ_draw_sprites();
	PC080SN_fg();
	return 0;
}


static int rainbowDraw()
{
	rainbowPalUpdate();
	rainbowGFX();
	return 0;
}



int rainbowFrame()
{
	if (drvReset) {	// Reset machine
		drvDoReset();
	}

	rainbowInpMake();
	cchip_timer();


	int nInterleave = 10;

	SekNewFrame();

	SekOpen(0);
	ZetOpen(0);
	nCyclesTotal[0] = 8000000/60;
	nCyclesTotal[1] = 4000000/60;
	rCyclesDone[0] = rCyclesDone[1] = 0;

	int nSoundBufferPos = 0;

	for (int i = 0; i < nInterleave; i++) {
    	int nCurrentCPU;
		int nNext;
		// Run 68000
		nCurrentCPU = 0;
		nNext = (i + 1) * nCyclesTotal[nCurrentCPU] / nInterleave;

		nCyclesSegment = nNext - rCyclesDone[nCurrentCPU];
		rCyclesDone[nCurrentCPU] += SekRun(nCyclesSegment);
		// Run Z80
		nCurrentCPU = 1;

		nNext = (i + 1) * nCyclesTotal[nCurrentCPU] / nInterleave;
		nCyclesSegment = nNext - rCyclesDone[nCurrentCPU];

		nCyclesSegment = ZetRun(nCyclesSegment);
		rCyclesDone[nCurrentCPU] += nCyclesSegment;
		{
			// Render sound segment
			if (pBurnSoundOut) {
				int nSegmentLength = nBurnSoundLen / nInterleave;
				short* pSoundBuf = pBurnSoundOut + (nSoundBufferPos << 1);
				BurnYM2151Render(pSoundBuf, nSegmentLength);
				nSoundBufferPos += nSegmentLength;
			}
		}
	}

	{
		// Make sure the buffer is entirely filled.
		if (pBurnSoundOut) {
			int nSegmentLength = nBurnSoundLen - nSoundBufferPos;
			short* pSoundBuf = pBurnSoundOut + (nSoundBufferPos << 1);
			if (nSegmentLength) {
				BurnYM2151Render(pSoundBuf, nSegmentLength);
			}
		}
	}

	SekSetIRQLine(4, SEK_IRQSTATUS_AUTO);
	ZetClose();
	SekClose();

	if (pBurnDraw) {
		rainbowDraw();														// Draw screen if needed
	}

	return 0;
}

int rainbowScan(int nAction,int *pnMin)
{
		SekScan(nAction);										// Scan 68000 state

		ZetOpen(0);
		ZetScan(nAction);										// Scan Z80 state
		ZetClose();

	struct BurnArea ba;
		memset(&ba, 0, sizeof(ba));
    	ba.Data		= RamStart;
		ba.nLen		= RamEnd-RamStart;
		ba.szName	= "All Ram";
		BurnAcb(&ba);

		SCAN_VAR(Z80Bank);
		SCAN_VAR(nCurrentBank);


		SCAN_VAR(nCyclesTotal);
		SCAN_VAR(nCyclesSegment);

		SCAN_VAR(rainbowInputPort0);
		SCAN_VAR(rainbowInputPort1);
		SCAN_VAR(rainbowInputPort2);
		SCAN_VAR(rainbowInputPort3);

		SCAN_VAR(rainbowDip);


		BurnYM2151Scan(nAction);

	return 0;
}


/// Rom information
static struct BurnRomInfo rainbowRomDesc[] = {
	{ "b22-10-1.19",   0x10000, 0xe34a50ca, BRF_ESS | BRF_PRG }, //  0 68000 code (even)
	{ "b22-11-1.20",   0x10000, 0x6a31a093, BRF_ESS | BRF_PRG }, //  1            (odd)
	{ "b22-08-1.21",   0x10000, 0x15d6e17a, BRF_ESS | BRF_PRG }, //  0 68000 code (even)
	{ "b22-09-1.22",   0x10000, 0x454e66bc, BRF_ESS | BRF_PRG }, //  1            (odd)
	{ "b22-03.23",     0x20000, 0x3ebb0fb8, BRF_ESS | BRF_PRG }, //  0 68000 code (even)
	{ "b22-04.24",     0x20000, 0x91625e7f, BRF_ESS | BRF_PRG }, //  1            (odd)

	{ "b22-14.43",     0x10000, 0x113c1a5b, BRF_GRA },			 //  2 z80 code

	{ "b22-01.2",      0x80000, 0xb76c9168, BRF_GRA },			 //  2 8x8 tile bitmaps

	{ "b22-01.5",      0x80000, 0x1b87ecf0, BRF_GRA },			 //  6 Sprite
	{ "b22-12.7",      0x10000, 0x67a76dc6, BRF_GRA },			 //  7
	{ "b22-13.6",      0x10000, 0x2fda099f, BRF_GRA },			 //  8
};


STD_ROM_PICK(rainbow);
STD_ROM_FN(rainbow);
// Rom info

static struct BurnRomInfo rainbowoRomDesc[] = {
	{ "b22-10.19",     0x10000, 0x3b013495, BRF_ESS | BRF_PRG }, //  0 68000 code (even)
	{ "b22-11.20",     0x10000, 0x80041a3d, BRF_ESS | BRF_PRG }, //  1            (odd)
	{ "b22-08.21",     0x10000, 0x962fb845, BRF_ESS | BRF_PRG }, //  0 68000 code (even)
	{ "b22-09.22",     0x10000, 0xf43efa27, BRF_ESS | BRF_PRG }, //  1            (odd)
	{ "b22-03.23",     0x20000, 0x3ebb0fb8, BRF_ESS | BRF_PRG }, //  0 68000 code (even)
	{ "b22-04.24",     0x20000, 0x91625e7f, BRF_ESS | BRF_PRG }, //  1            (odd)

	{ "b22-14.43",     0x10000, 0x113c1a5b, BRF_GRA },			 //  2 z80 code

	{ "b22-01.2",      0x80000, 0xb76c9168, BRF_GRA },			 //  2 8x8 tile bitmaps

	{ "b22-01.5",      0x80000, 0x1b87ecf0, BRF_GRA },			 //  6 Sprite
	{ "b22-12.7",      0x10000, 0x67a76dc6, BRF_GRA },			 //  7
	{ "b22-13.6",      0x10000, 0x2fda099f, BRF_GRA },			 //  8
};


STD_ROM_PICK(rainbowo);
STD_ROM_FN(rainbowo);

// Rom info
static struct BurnRomInfo rainboweRomDesc[] = {
	{ "b39-01.19",     0x10000, 0x50690880, BRF_ESS | BRF_PRG }, //  0 68000 code (even)
	{ "b39-02.20",     0x10000, 0x4dead71f, BRF_ESS | BRF_PRG }, //  1            (odd)
	{ "b39-03.21",     0x10000, 0x4a4cb785, BRF_ESS | BRF_PRG }, //  0 68000 code (even)
	{ "b39-04.22",     0x10000, 0x4caa53bd, BRF_ESS | BRF_PRG }, //  1            (odd)
	{ "b22-03.23",     0x20000, 0x3ebb0fb8, BRF_ESS | BRF_PRG }, //  0 68000 code (even)
	{ "b22-04.24",     0x20000, 0x91625e7f, BRF_ESS | BRF_PRG }, //  1            (odd)

	{ "b22-14.43",     0x10000, 0x113c1a5b, BRF_GRA },			 //  2 z80 code

	{ "b22-01.2",      0x80000, 0xb76c9168, BRF_GRA },			 //  2 8x8 tile bitmaps

	{ "b22-01.5",      0x80000, 0x1b87ecf0, BRF_GRA },			 //  6 Sprite
	{ "b22-12.7",      0x10000, 0x67a76dc6, BRF_GRA },			 //  7
	{ "b22-13.6",      0x10000, 0x2fda099f, BRF_GRA },			 //  8
};


STD_ROM_PICK(rainbowe);
STD_ROM_FN(rainbowe);

struct BurnDriver BurnDrvrainbow = {
	"rainbow", NULL, NULL, "1987",
	"Rainbow Islands (new version)\0", NULL, "Taito Corporation", "Custom Taito",
	NULL, NULL, NULL, NULL,
	1,2,HARDWARE_MISC_MISC,
	NULL,rainbowRomInfo,rainbowRomName,rainbowInputInfo, rainbowDIPInfo,
	rainbowInit,rainbowExit,rainbowFrame,NULL,rainbowScan,
	&taitoRecalcPal,320,240,4,3
};

struct BurnDriver BurnDrvrainbowo = {
	"rainbowo", "rainbow", NULL, "1987",
	"Rainbow Islands (old version)\0", NULL, "Taito Corporation", "Custom Taito",
	NULL, NULL, NULL, NULL,
	1 | BDF_CLONE,2,HARDWARE_MISC_MISC,
	NULL,rainbowoRomInfo,rainbowoRomName,rainbowInputInfo, rainbowDIPInfo,
	rainbowInit,rainbowExit,rainbowFrame,NULL,rainbowScan,
	&taitoRecalcPal,320,240,4,3
};

struct BurnDriver BurnDrvrainbowe = {
	"rainbowe", "rainbow", NULL, "1988",
	"Rainbow Islands (Extra)\0", NULL, "Taito Corporation", "Custom Taito",
	NULL, NULL, NULL, NULL,
	1 | BDF_CLONE,2,HARDWARE_MISC_MISC,
	NULL,rainboweRomInfo,rainboweRomName,rainbowInputInfo, rainbowDIPInfo,
	rainbowInit,rainbowExit,rainbowFrame,NULL,rainbowScan,
	&taitoRecalcPal,320,240,4,3
};


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -