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

📄 d_rastan.cpp

📁 motorola ezx 平台下的fba模拟器
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/*
Rastan driver
=============
Part of FBAs Taito 68k hardware drivers
Credits: Mame team, Raine team
Coding by KEV, with help from Treble Winner and Jan_Klaassen
*/

#include "taito.h"
#include "msm5205.h"
static unsigned char *Mem=NULL,*MemEnd=NULL;
static unsigned char *RamStart=NULL,*RamEnd=NULL;
static unsigned char *Rom=NULL;
static unsigned char *rastan_ram=NULL,*rastan_src_pal=NULL;
static unsigned char drvReset = 0;

static unsigned char *z80_rom=NULL,*z80_ram=NULL;
static unsigned int *rastan_pal=NULL;

// Z80 ROM bank
static int Z80Bank;
static int nCurrentBank;

static int nCyclesTotal[2];
static int nCyclesSegment;

unsigned char RastanInputPort0[8], RastanInputPort1[8], RastanInputPort2[8];
unsigned char RastanInput[3];
unsigned char RastanDip[2];
static struct BurnInputInfo rastanInputList[]=
{
	{"P1 Coin"     , BIT_DIGITAL,	RastanInputPort2 + 5, "p1 coin"     },
	{"P1 Start"    , BIT_DIGITAL,	RastanInputPort2 + 3, "p1 start"    },
	{"P1 Up"       , BIT_DIGITAL,	RastanInputPort0 + 0, "p1 up"       },
	{"P1 Down"     , BIT_DIGITAL,	RastanInputPort0 + 1, "p1 down"     },
	{"P1 Left"     , BIT_DIGITAL,	RastanInputPort0 + 2, "p1 left"     },
	{"P1 Right"    , BIT_DIGITAL,	RastanInputPort0 + 3, "p1 right"    },
	{"P1 Button 1" , BIT_DIGITAL,	RastanInputPort0 + 4, "p1 fire 1"   },
	{"P1 Button 2" , BIT_DIGITAL,	RastanInputPort0 + 5, "p1 fire 2"   },

	{"P2 Coin"     , BIT_DIGITAL,	RastanInputPort2 + 6, "p2 coin"     },
	{"P2 Start"    , BIT_DIGITAL,	RastanInputPort2 + 4, "p2 start"    },
	{"P2 Up"       , BIT_DIGITAL,	RastanInputPort1 + 0, "p2 up"       },
	{"P2 Down"     , BIT_DIGITAL,	RastanInputPort1 + 1, "p2 down"     },
	{"P2 Left"     , BIT_DIGITAL,	RastanInputPort1 + 2, "p2 left"     },
	{"P2 Right"    , BIT_DIGITAL,	RastanInputPort1 + 3, "p2 right"    },
	{"P2 Button 1" , BIT_DIGITAL,	RastanInputPort1 + 4, "p2 fire 1"   },
	{"P2 Button 2" , BIT_DIGITAL,	RastanInputPort1 + 5, "p2 fire 2"   },

	{"Reset"	   , BIT_DIGITAL,	&drvReset			, "reset"		},
	{"Service"     , BIT_DIGITAL,	RastanInputPort2 + 0, "service"     },
	{"Tilt"        , BIT_DIGITAL,	RastanInputPort2 + 2, "tilt"        },
	{"Dip 1"       , BIT_DIPSWITCH,	RastanDip + 0       , "dip"         },
	{"Dip 2"       , BIT_DIPSWITCH,	RastanDip + 1       , "dip"         },
};

static struct BurnDIPInfo rastanDIPList[]=
{
	// Defaults
	{0x13, 0xff, 0xff, 0x00, NULL                     },
	{0x14, 0xff, 0xff, 0x00, NULL                     },

	// Dip 1
	{0   , 0xfe, 0   , 2   , "Cabinet"                },
	{0x13, 0x01, 0x01, 0x00, "Cocktail"               },
	{0x13, 0x01, 0x01, 0x01, "Upright"                },

	{0   , 0xfe, 0   , 2   , "Flip Screen"            },
	{0x13, 0x01, 0x02, 0x00, "Off"                    },
	{0x13, 0x01, 0x02, 0x02, "On"                     },

	{0   , 0xfe, 0   , 2   , "Test Mode"              },
	{0x13, 0x01, 0x04, 0x00, "Off"                    },
	{0x13, 0x01, 0x04, 0x04, "On"                     },

	{0   , 0xfe, 0   , 4   , "Coin A"                 },
	{0x13, 0x01, 0x30, 0x30, "4 Coins 1 Credit"       },
	{0x13, 0x01, 0x30, 0x20, "3 Coins 1 Credit"       },
	{0x13, 0x01, 0x30, 0x10, "2 Coins 1 Credit"       },
	{0x13, 0x01, 0x30, 0x00, "1 Coin  1 Credit"       },

	{0   , 0xfe, 0   , 4   , "Coin B"                 },
	{0x13, 0x01, 0xc0, 0xc0, "1 Coin 6 Credits"       },
	{0x13, 0x01, 0xc0, 0x80, "1 Coin 4 Credits"       },
	{0x13, 0x01, 0xc0, 0x40, "1 Coin 3 Credits"       },
	{0x13, 0x01, 0xc0, 0x00, "1 Coin 2 Credits"       },

	// Dip 2
	{0   , 0xfe, 0   , 4   , "Difficulty"             },
	{0x14, 0x01, 0x03, 0x01, "Easy"                   },
	{0x14, 0x01, 0x03, 0x00, "Medium"                 },
	{0x14, 0x01, 0x03, 0x02, "Hard"                   },
	{0x14, 0x01, 0x03, 0x03, "Hardest"                },

	{0   , 0xfe, 0   , 4   , "Bonus Life"             },
	{0x14, 0x01, 0x0c, 0x00, "100000"                 },
	{0x14, 0x01, 0x0c, 0x04, "150000"                 },
	{0x14, 0x01, 0x0c, 0x08, "200000"                 },
	{0x14, 0x01, 0x0c, 0x0c, "250000"                 },

	{0   , 0xfe, 0   , 4   , "Lives"                  },
	{0x14, 0x01, 0x30, 0x00, "3"                      },
	{0x14, 0x01, 0x30, 0x10, "4"                      },
	{0x14, 0x01, 0x30, 0x20, "5"                      },
	{0x14, 0x01, 0x30, 0x30, "6"                      },

	{0   , 0xfe, 0   , 2   , "Allow Continue"         },
	{0x14, 0x01, 0x40, 0x40, "No"                     },
	{0x14, 0x01, 0x40, 0x00, "Yes"                    },
};

STDDIPINFO(rastan);

void rastanBankSwitch(unsigned int /*a*/, unsigned int data)
{
	Z80Bank=(data^1) & 0x01;
  	if (Z80Bank != nCurrentBank) {
  			unsigned char* nStartAddress = z80_rom + 0x4000+(Z80Bank*0x4000);
  			nCurrentBank = Z80Bank;
  			ZetMapArea(0x4000, 0x7FFF, 0, nStartAddress);
  			ZetMapArea(0x4000, 0x7FFF, 2, nStartAddress);
		}
}

int rastanInpMake()
{
	RastanInput[0] = RastanInput[1] = 0xff;
	RastanInput[2] = 0x1f;

	for (int i = 0; i < 8; i++) {
		RastanInput[0] -= (RastanInputPort0[i] & 1) << i;
		RastanInput[1] -= (RastanInputPort1[i] & 1) << i;
		if (i < 5) {
			RastanInput[2] -= (RastanInputPort2[i] & 1) << i;
		} else {
			RastanInput[2] |= (RastanInputPort2[i] & 1) << i;
		}
	}

	return 0;
}

void RastanYM2151IRQHandler(int irq )
{
	if (irq)
	{
		ZetRaiseIrq(0);
	}
}

inline static unsigned int CalcCol(unsigned short nColour)
{
	int r, g, b;

	r = (nColour & 0x001F) << 3;	// Red
	r |= r >> 5;
	g = (nColour & 0x03E0) >> 2;  	// Green
	g |= g >> 5;
	b = (nColour & 0x7C00) >> 7;	// Blue
	b |= b >> 5;

	return BurnHighCol(r, g, b, 0);
}

int rastanPalUpdate()
{
	int i;
	unsigned short* ps;
	unsigned int* pd;

	for (i = 0, ps = (unsigned short*)rastan_src_pal, pd = rastan_pal; i < 0x800; i++, ps++, pd++) {
		*pd = CalcCol(*ps);
	}
	return 0;
}

////
// This routine is called first to determine how much memory is needed (MemEnd-(unsigned char *)0),

static int MemIndex()
{
	unsigned char *Next; Next=Mem;
	Rom  =Next;						Next+=0x60000; // 68000 program
    RamStart =Next;
	rastan_ram=Next;				Next+=0x4020;
	rastan_src_pal=Next;			Next+=0x1000;
	PC090OJ_spritectrl=Next;		Next+=0x10;
	PC080SN_word_0=Next;			Next+=0x10000;
	PC080SN_yscroll_word_0=Next;	Next+=0x10;
	PC080SN_xscroll_word_0=	Next;	Next+=0x10;
	PC080SN_ctrl_word_0=Next;		Next+=0x10;
	PC090OJ_word_0=Next;			Next+=0x4000;
	rastan_pal=(unsigned int*)Next; Next += 0x800 * sizeof(unsigned int);
	MSM5205ROM=Next;				Next+=0x10000;
	z80_ram=Next;					Next+=0x2000;
	RamEnd   =Next;
	z80_rom=Next;					Next+=0x10000;
    MemEnd=Next;
    return 0;
}


static int LoadRoms()
{
	int nRet=0;
	// Load program roms and byteswap
	nRet=BurnLoadRom(Rom+0x00001,0,2); if (nRet!=0) return 1;
	nRet=BurnLoadRom(Rom+0x00000,1,2); if (nRet!=0) return 1;
	nRet=BurnLoadRom(Rom+0x20001,2,2); if (nRet!=0) return 1;
	nRet=BurnLoadRom(Rom+0x20000,3,2); if (nRet!=0) return 1;
	nRet=BurnLoadRom(Rom+0x40001,4,2); if (nRet!=0) return 1;
	nRet=BurnLoadRom(Rom+0x40000,5,2); if (nRet!=0) return 1;

	nRet=BurnLoadRom(z80_rom,6,1); // load z80 code rom
	nRet=BurnLoadRom(MSM5205ROM,15,1); // adcpm

	ttiles=(unsigned char *)malloc(16384*64);
	memset(ttiles,0,16384*64);
	tsprites=(unsigned char *)malloc(5120*256);
	memset(tsprites,0,5120*256);

	unsigned char *TempGfx;
	unsigned int c,y;
	TempGfx=(unsigned char *)malloc(0x40000);
	nRet = BurnLoadRom(TempGfx + 0x00000, 11, 1); if (nRet) return 1;
	nRet = BurnLoadRom(TempGfx + 0x20000, 13, 1); if (nRet) return 1;
	for (c = 0; c < 2048; c ++) {
		for (y = 0; y < 16; y ++) { //8 12 0 4 24 28 16 20 40, 44, 32, 36, 56, 60, 48, 52
			tsprites[(c*256)+0+(y*16)] = TempGfx[0x00000 + (y * 4) + (c * 64)] >> 4;
			tsprites[(c*256)+1+(y*16)] = TempGfx[0x00000 + (y * 4) + (c * 64)] & 0x0f;
			tsprites[(c*256)+2+(y*16)] = TempGfx[0x20000 + (y * 4) + (c * 64)] >> 4;
			tsprites[(c*256)+3+(y*16)] = TempGfx[0x20000 + (y * 4) + (c * 64)] & 0x0f;
			tsprites[(c*256)+4+(y*16)] = TempGfx[0x00001 + (y * 4) + (c * 64)] >> 4;
			tsprites[(c*256)+5+(y*16)] = TempGfx[0x00001 + (y * 4) + (c * 64)] & 0x0f;
			tsprites[(c*256)+6+(y*16)] = TempGfx[0x20001 + (y * 4) + (c * 64)] >> 4;
			tsprites[(c*256)+7+(y*16)] = TempGfx[0x20001 + (y * 4) + (c * 64)] & 0x0f;
			tsprites[(c*256)+8+(y*16)] = TempGfx[0x00002 + (y * 4) + (c * 64)] >> 4;
			tsprites[(c*256)+9+(y*16)] = TempGfx[0x00002 + (y * 4) + (c * 64)] & 0x0f;
			tsprites[(c*256)+10+(y*16)] = TempGfx[0x20002 + (y * 4) + (c * 64)] >> 4;
			tsprites[(c*256)+11+(y*16)] = TempGfx[0x20002 + (y * 4) + (c * 64)] & 0x0f;
			tsprites[(c*256)+12+(y*16)] = TempGfx[0x00003 + (y * 4) + (c * 64)] >> 4;
			tsprites[(c*256)+13+(y*16)] = TempGfx[0x00003 + (y * 4) + (c * 64)] & 0x0f;
			tsprites[(c*256)+14+(y*16)] = TempGfx[0x20003 + (y * 4) + (c * 64)] >> 4;
			tsprites[(c*256)+15+(y*16)] = TempGfx[0x20003 + (y * 4) + (c * 64)] & 0x0f;
		}
	}
	nRet = BurnLoadRom(TempGfx + 0x00000, 12, 1); if (nRet) return 1;
	nRet = BurnLoadRom(TempGfx + 0x20000, 14, 1); if (nRet) return 1;
	for (c = 0; c < 2048; c ++) {
		for (y = 0; y < 16; y ++) { //8 12 0 4 24 28 16 20 40, 44, 32, 36, 56, 60, 48, 52
			tsprites[((c+2048)*256)+0+(y*16)] = TempGfx[0x00000 + (y * 4) + (c * 64)] >> 4;
			tsprites[((c+2048)*256)+1+(y*16)] = TempGfx[0x00000 + (y * 4) + (c * 64)] & 0x0f;
			tsprites[((c+2048)*256)+2+(y*16)] = TempGfx[0x20000 + (y * 4) + (c * 64)] >> 4;
			tsprites[((c+2048)*256)+3+(y*16)] = TempGfx[0x20000 + (y * 4) + (c * 64)] & 0x0f;
			tsprites[((c+2048)*256)+4+(y*16)] = TempGfx[0x00001 + (y * 4) + (c * 64)] >> 4;
			tsprites[((c+2048)*256)+5+(y*16)] = TempGfx[0x00001 + (y * 4) + (c * 64)] & 0x0f;
			tsprites[((c+2048)*256)+6+(y*16)] = TempGfx[0x20001 + (y * 4) + (c * 64)] >> 4;
			tsprites[((c+2048)*256)+7+(y*16)] = TempGfx[0x20001 + (y * 4) + (c * 64)] & 0x0f;
			tsprites[((c+2048)*256)+8+(y*16)] = TempGfx[0x00002 + (y * 4) + (c * 64)] >> 4;
			tsprites[((c+2048)*256)+9+(y*16)] = TempGfx[0x00002 + (y * 4) + (c * 64)] & 0x0f;
			tsprites[((c+2048)*256)+10+(y*16)] = TempGfx[0x20002 + (y * 4) + (c * 64)] >> 4;
			tsprites[((c+2048)*256)+11+(y*16)] = TempGfx[0x20002 + (y * 4) + (c * 64)] & 0x0f;
			tsprites[((c+2048)*256)+12+(y*16)] = TempGfx[0x00003 + (y * 4) + (c * 64)] >> 4;
			tsprites[((c+2048)*256)+13+(y*16)] = TempGfx[0x00003 + (y * 4) + (c * 64)] & 0x0f;
			tsprites[((c+2048)*256)+14+(y*16)] = TempGfx[0x20003 + (y * 4) + (c * 64)] >> 4;
			tsprites[((c+2048)*256)+15+(y*16)] = TempGfx[0x20003 + (y * 4) + (c * 64)] & 0x0f;
		}
	}
	nRet = BurnLoadRom(TempGfx + 0x00000, 7, 1); if (nRet) return 1;
	nRet = BurnLoadRom(TempGfx + 0x20000, 9, 1); if (nRet) return 1;
	for (c=0;c<8192;c++)
	{
		for (y=0;y<8;y++)
		{//8 12 0 4 24 28 16 2040, 44, 32, 36, 56, 60, 48, 52
			ttiles[(c*64)+0+(y*8)]=TempGfx[0x00000 + (y*2) + (c*16)] >>4;
			ttiles[(c*64)+1+(y*8)]=TempGfx[0x00000 + (y*2) + (c*16)]&0xF;
			ttiles[(c*64)+2+(y*8)]=TempGfx[0x20000 + (y*2) + (c*16)]>>4;
			ttiles[(c*64)+3+(y*8)]=TempGfx[0x20000 + (y*2) + (c*16)]&0xF;
			ttiles[(c*64)+4+(y*8)]=TempGfx[0x00001 + (y*2) + (c*16)] >>4;;
			ttiles[(c*64)+5+(y*8)]=TempGfx[0x00001 + (y*2) + (c*16)]&0xF;
			ttiles[(c*64)+6+(y*8)]=TempGfx[0x20001 + (y*2) + (c*16)]>>4;
			ttiles[(c*64)+7+(y*8)]=TempGfx[0x20001 + (y*2) + (c*16)]&0xF;
		}
	}
	nRet = BurnLoadRom(TempGfx + 0x00000, 8, 1); if (nRet) return 1;
	nRet = BurnLoadRom(TempGfx + 0x20000, 10, 1); if (nRet) return 1;
	for (c=0;c<8192;c++)
	{
		for (y=0;y<8;y++)
		{//8 12 0 4 24 28 16 2040, 44, 32, 36, 56, 60, 48, 52
			ttiles[((c+8192)*64)+0+(y*8)]=TempGfx[0x00000 + (y*2) + (c*16)] >>4;
			ttiles[((c+8192)*64)+1+(y*8)]=TempGfx[0x00000 + (y*2) + (c*16)]&0xF;
			ttiles[((c+8192)*64)+2+(y*8)]=TempGfx[0x20000 + (y*2) + (c*16)]>>4;
			ttiles[((c+8192)*64)+3+(y*8)]=TempGfx[0x20000 + (y*2) + (c*16)]&0xF;
			ttiles[((c+8192)*64)+4+(y*8)]=TempGfx[0x00001 + (y*2) + (c*16)] >>4;;
			ttiles[((c+8192)*64)+5+(y*8)]=TempGfx[0x00001 + (y*2) + (c*16)]&0xF;
			ttiles[((c+8192)*64)+6+(y*8)]=TempGfx[0x20001 + (y*2) + (c*16)]>>4;
			ttiles[((c+8192)*64)+7+(y*8)]=TempGfx[0x20001 + (y*2) + (c*16)]&0xF;
		}
	}
	free(TempGfx);
	return nRet;
  }

unsigned char __fastcall RastanZ80Read(unsigned short a)
{
	switch (a)
	{
	case (0x9001):
		return BurnYM2151ReadStatus();
	case (0xa001):
		return tc0140_slave_comm_r();
	default:
		bprintf(PRINT_NORMAL, _T("z80 read %x\n"),a);
		return 0xff;
	}
}

void __fastcall RastanZ80Write(unsigned short a,unsigned char d)
{
	switch (a)
	{
	case 0xb000:
		{
		UINT8 *rom = MSM5205ROM;
		int len = 0x10000;
		int start = d << 8;
		int end;

		/* look for end of sample */
		end = (start + 3) & ~3;
		while (end < len && *((unsigned int *)(&rom[end])) != 0x08080808)
			end += 4;

		MSM5205Play(start,(end-start)*2,0);
		}
		return;
	case 0xc000:
		return;
	case 0xd000:
		return;
	case 0x9000:
		BurnYM2151SelectRegister(d);
		return;
	case 0x9001:
		BurnYM2151WriteRegister(d);
		return;
	case 0xa000:
		tc0140_slave_port_w(d);
		return;
	case 0xa001:
		tc0140_slave_comm_w(d);
		return;
	default:
		bprintf(PRINT_NORMAL, _T("z80write %x\n"),a);
	}


}


unsigned short __fastcall rastanReadWord(unsigned int a)
{
	switch (a)
	{
	case 0x390000:
		return RastanInput[0];
	case 0x390002:
		return RastanInput[1];
	case 0x390005:
		return RastanInput[2];
	default:
		bprintf(PRINT_NORMAL, _T("readword %x\n"), a);
		return 0;
	}
}

unsigned char __fastcall rastanReadByte(unsigned int a)
{
	switch (a)
	{
	case 0x390001:
		return RastanInput[0];
	case 0x390003:
		return RastanInput[1];
	case 0x390005:
		return RastanInput[2];
	case 0x390007:
		return RastanInput[2];
	case 0x390009:
		return 0xff-  RastanDip[0];  //dipa
	case 0x39000b:
		return 0xff -  RastanDip[1]; //dipb
	case 0x3e0003:
		return tc0140_comm_r();
	default:
		bprintf(PRINT_NORMAL, _T("readbyte %x\n"),a);
		return 0;
	}

}


⌨️ 快捷键说明

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