Author Topic: Some PVC Bankswitch code  (Read 19498 times)

Offline bms888

  • Jr. Member
  • **
  • Posts: 93
  • Karma: +0/-0
  • Member
Some PVC Bankswitch code
« on: January 18, 2005, 10:52:21 PM »
Code: [Select]

/***************************** Neo PVC protection *********************/

static unsigned short CartRAM[0x1000];
// for save states
unsigned char *NeoCartRAM = (unsigned char *)CartRAM;

unsigned char pvc_r8(unsigned int sekAddress)
{
return *(((unsigned char *)CartRAM)+((sekAddress^1)-0x2fe000));
}

void pvc_w8(unsigned int sekAddress,unsigned char byteValue)
{
*(((unsigned char *)CartRAM)+((sekAddress^1)-0x2fe000))=byteValue;
}

unsigned char __fastcall pvcReadByteBankSwitch(unsigned int sekAddress)
{
return pvc_r8(sekAddress);
}

unsigned short __fastcall pvcReadWordBankSwitch(unsigned int sekAddress)
{
return CartRAM[(sekAddress-0x2fe000)/2];
}


Code: [Select]

// Special Bankswitch
void pvc_CalcBank2() // on writes to f0-f3
{
unsigned int offset;
// Make this universal for kof2003b + kof2003p
if ((!strcmp(BurnDrvText(0), "kof2k4eh")) || (!strcmp(BurnDrvText(0), "kof2k4ex"))) {
offset=(pvc_r8(0x2ffff2)<<16)|(pvc_r8(0x2ffff3)<<8)|(pvc_r8(0x2ffff1)<<0);
*((unsigned char *) (CartRAM+((0x2ffff1-0x2fe000)^1)))&=0xfe;
*((unsigned char *) (CartRAM+((0x2ffff2-0x2fe000)^1)))&=0x7f;
} else {
offset=(pvc_r8(0x2ffff2)<<16)|(pvc_r8(0x2ffff3)<<8)|(pvc_r8(0x2ffff0)<<0);
*((unsigned char *) (CartRAM+((0x2ffff0-0x2fe000)^1)))&=0xfe;
*((unsigned char *) (CartRAM+((0x2ffff1-0x2fe000)^1)))=0xa0;
*((unsigned char *) (CartRAM+((0x2ffff2-0x2fe000)^1)))&=0x7f;
Neo68KROM01[0x58196]=pvc_r8(0x2ffff3);
}
SekMapMemory(Neo68KROM02+offset,0x200000,0x2fdfff,SM_ROM);
}

void __fastcall pvcWriteByteBankSwitch2(unsigned int sekAddress, unsigned char byteValue)
{
pvc_w8(sekAddress,byteValue);
if(sekAddress>=0x2ffff0 && sekAddress<=0x2ffff3)pvc_CalcBank2();
}

void __fastcall pvcWriteWordBankSwitch2(unsigned int sekAddress, unsigned short wordValue)
{
CartRAM[(sekAddress-0x2fe000)/2]=wordValue;
if(sekAddress>=0x2ffff0 && sekAddress<=0x2ffff3)pvc_CalcBank2();
}


Code: [Select]

static void pvcMapHandler2()
{
// Install BankSwitch handler
SekMapHandler(5, 0x2fe000, 0x2fffff, SM_READ);
SekSetReadWordHandler(5,  pvcReadWordBankSwitch);
SekSetReadByteHandler(5,  pvcReadByteBankSwitch);

SekMapHandler(5, 0x2fe000, 0x2fffff, SM_WRITE);
SekSetWriteWordHandler(5, pvcWriteWordBankSwitch2);
SekSetWriteByteHandler(5, pvcWriteByteBankSwitch2);
}

static void pcbBiosMapHandler()
{
SekMapMemory(Neo68KBIOS+0x20000,0xC20000,0xC3FFFF,SM_ROM); // for PCB BIOS
}

Offline bms888

  • Jr. Member
  • **
  • Posts: 93
  • Karma: +0/-0
  • Member
Some PVC Bankswitch code
« Reply #1 on: January 18, 2005, 10:54:22 PM »
these code can working on mslug5,mslug5b,svcboot,svcsplus,kof2003b,kof2k3up,kof2k4ex....^_^

Offline bms888

  • Jr. Member
  • **
  • Posts: 93
  • Karma: +0/-0
  • Member
Some PVC Bankswitch code
« Reply #2 on: January 18, 2005, 10:57:27 PM »
maybe I will open the pvc_port code in someday,bye.

Offline bms888

  • Jr. Member
  • **
  • Posts: 93
  • Karma: +0/-0
  • Member
Some PVC Bankswitch code
« Reply #3 on: January 18, 2005, 11:00:39 PM »
oh,everyone! this code maybe help you:

Code: [Select]

// Code by iq_132 -- http://neosource.1emu.net/
static void interleave_pdata()
{
int i, j=0;
UINT8 *src = Neo68KROM01;
UINT8 *dst = (UINT8 *)malloc(0x800000);
for (i=0;i<0x800000;i=i+4){
dst[i+0]=src[j];
dst[i+1]=src[j+1];
dst[i+2]=src[j+0x400000];
dst[i+3]=src[j+0x400001];
j=j+2;
}
memcpy(Neo68KROM01,dst,0x800000);
free(dst);
}

// Neo-PVC Code for PCB and MVS games with this protection
// Original code by(?) HalRIN -- http://www52.tok2.com/home/foge/
static void do_neopvc(int game)
{
unsigned int xor1[ 2 ][ 0x20 ] = { // kof2003 does not use xor1
// for svcchaos
{0x3b, 0x6a, 0xf7, 0xb7, 0xe8, 0xa9, 0x20, 0x99, 0x9f, 0x39, 0x34, 0x0c, 0xc3, 0x9a, 0xa5, 0xc8,
0xb8, 0x18, 0xce, 0x56, 0x94, 0x44, 0xe3, 0x7a, 0xf7, 0xdd, 0x42, 0xf0, 0x18, 0x60, 0x92, 0x9f},
// for mslug5
{0xc2, 0x4b, 0x74, 0xfd, 0x0b, 0x34, 0xeb, 0xd7, 0x10, 0x6d, 0xf9, 0xce, 0x5d, 0xd5, 0x61, 0x29,
0xf5, 0xbe, 0x0d, 0x82, 0x72, 0x45, 0x0f, 0x24, 0xb3, 0x34, 0x1b, 0x99, 0xea, 0x09, 0xf3, 0x03},
};

unsigned int xor2[ 3 ][ 0x20 ] = {
// for kof2003
{0xb4, 0x0f, 0x40, 0x6c, 0x38, 0x07, 0xd0, 0x3f, 0x53, 0x08, 0x80, 0xaa, 0xbe, 0x07, 0xc0, 0xfa,
0xd0, 0x08, 0x10, 0xd2, 0xf1, 0x03, 0x70, 0x7e, 0x87, 0x0B, 0x40, 0xf6, 0x2a, 0x0a, 0xe0, 0xf9},
// for svcchaos
{0x69, 0x0b, 0x60, 0xd6, 0x4f, 0x01, 0x40, 0x1a, 0x9f, 0x0b, 0xf0, 0x75, 0x58, 0x0e, 0x60, 0xb4,
0x14, 0x04, 0x20, 0xe4, 0xb9, 0x0d, 0x10, 0x89, 0xeb, 0x07, 0x30, 0x90, 0x50, 0x0e, 0x20, 0x26},
// for mslug5
{0x36, 0x09, 0xb0, 0x64, 0x95, 0x0f, 0x90, 0x42, 0x6e, 0x0f, 0x30, 0xf6, 0xe5, 0x08, 0x30, 0x64,
0x08, 0x04, 0x00, 0x2f, 0x72, 0x09, 0xa0, 0x13, 0xc9, 0x0b, 0xa0, 0x3e, 0xc2, 0x00, 0x40, 0x2b},
};

int i, ofst, ofst2 = 0x00300, rom_size = 0x800000;
unsigned char *rom = Neo68KROM01;
unsigned char *buf = (unsigned char*)malloc( rom_size );

if (game!=1)
for( i = 0; i < 0x100000; i++ )
rom[ i ] ^= xor1[ game-2 ][ (i % 0x20) ];

for( i = 0x100000; i < 0x800000; i++ )
rom[ i ] ^= xor2[ game-1 ][ (i % 0x20) ];

for( i = 0x100000; i < 0x800000; i += 4 ){
unsigned short *rom16 = (unsigned short *)&rom[ i + 1 ];
if (game==1) *rom16 = BITSWAP16( *rom16, 15, 14, 13, 12, 4, 5, 6, 7, 8, 9, 10, 11, 3, 2, 1, 0 );
if (game!=1) *rom16 = BITSWAP16( *rom16, 15, 14, 13, 12, 10, 11, 8, 9, 6, 7, 4, 5, 3, 2, 1, 0 );
}

memcpy( buf, rom, rom_size );

for( i = 0; i < 0x10; i++ ){
ofst = (i & 0xf0) + BITSWAP08( (i & 0x0f), 7, 6, 5, 4, 1, 0, 3, 2 );
if (game==2)
ofst = (i & 0xf0) + BITSWAP08( (i & 0x0f), 7, 6, 5, 4, 2, 3, 0, 1 );

memcpy( &rom[ i * 0x10000 ], &buf[ ofst * 0x10000 ], 0x10000 );
}

for( i = 0x100000; i < 0x800000; i += 0x100 ){
if (game==2) ofst2=0x00a00;
ofst = (i & 0xf000ff) + ((i & 0x000f00) ^ ofst2) + (BITSWAP08( ((i & 0x0ff000) >> 12), 4, 5, 6, 7, 1, 0, 3, 2 ) << 12);
if (game==3)
ofst = (i & 0xf000ff) + ((i & 0x000f00) ^ 0x00700) + (BITSWAP08( ((i & 0x0ff000) >> 12), 5, 4, 7, 6, 1, 0, 3, 2 ) << 12);

memcpy( &rom[ i ], &buf[ ofst ], 0x100 );
}

if (game==1) {
buf = (unsigned char*)malloc( 0x900000 );
memcpy( buf, rom, 0x900000 );
memcpy( &rom[ 0x100000 ], &buf[ 0x800000 ], 0x100000 );
memcpy( &rom[ 0x200000 ], &buf[ 0x100000 ], 0x700000 );
} else {
memcpy( buf, rom, rom_size );
memcpy( &rom[ 0x100000 ], &buf[ 0x700000 ], 0x100000 );
memcpy( &rom[ 0x200000 ], &buf[ 0x100000 ], 0x600000 );
}

free(buf);
}

Offline bms888

  • Jr. Member
  • **
  • Posts: 93
  • Karma: +0/-0
  • Member
Some PVC Bankswitch code
« Reply #4 on: January 18, 2005, 11:08:17 PM »
kof2003b you can try this code:

Code: [Select]

static void kof2003bDecrypt()
{
int sec[]={ 0x07, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 };

int i, rom_size = 0x800000;
UINT8 *src = Neo68KROM01;
UINT8 *dst = (UINT8 *)malloc( rom_size );

memcpy( dst, src, rom_size );
for( i=0; i<8; ++i ){
memcpy( src+i*0x100000, dst+sec[i]*0x100000, 0x100000 );
}
free( dst );
}

static int kof2003bInit()
{
int nRet;

memset(CartRAM,0,0x2000);

nNeoTextROMFixType = 3;
pNeoInitCallback = kof2003bDecrypt;

nRet=NeoInit();
if(!nRet)
pvcMapHandler2();
pcbBiosMapHandler();
return nRet;
}

Offline bms888

  • Jr. Member
  • **
  • Posts: 93
  • Karma: +0/-0
  • Member
Some PVC Bankswitch code
« Reply #5 on: January 18, 2005, 11:28:25 PM »
Ms5plus BankSwitch code is here:

Code: [Select]

void __fastcall ms5plusWriteWordBankSwitch(unsigned int sekAddress, unsigned short wordValue)
{
if (sekAddress==0x2ffff4){
unsigned int offset=wordValue<<0x10;
SekMapMemory(Neo68KROM01+offset,0x200000,0x2fdfff,SM_ROM);
}
}

static void ms5plusMapHandler()
{
SekMapHandler(5, 0x2fe000, 0x2fffff, SM_WRITE);
SekSetWriteWordHandler(5, ms5plusWriteWordBankSwitch);
}

Offline bms888

  • Jr. Member
  • **
  • Posts: 93
  • Karma: +0/-0
  • Member
Some PVC Bankswitch code
« Reply #6 on: January 18, 2005, 11:34:19 PM »
If the next... FBA can't support chinese roms path and use GCC,i will give up to updata FBA,just updata Mame Plus,that's one reason of i open this BankSwitch code.

Offline iq_132

  • Administrator
  • *****
  • Posts: 3723
  • Karma: +411/-0
  • Definitely not Dink!
    • NeoSource
Some PVC Bankswitch code
« Reply #7 on: January 18, 2005, 11:53:53 PM »
Holy cow! Thanks bms :)


Offline bms888

  • Jr. Member
  • **
  • Posts: 93
  • Karma: +0/-0
  • Member
Some PVC Bankswitch code
« Reply #8 on: January 18, 2005, 11:57:29 PM »
Quote from: iq_132
Holy cow! Thanks bms :)


No thx,you can remove all kof2003b_tbl and old BankSwitch code now,^_^!

Offline James33

  • Expert
  • *****
  • Posts: 532
  • Karma: +3/-0
  • The Mame Man
    • Emulation Zone
Some PVC Bankswitch code
« Reply #9 on: January 19, 2005, 02:25:07 AM »
Thanks BMS  :D  
But now I have no idea where to add this code :(
IQ Forum Member

Offline iq_132

  • Administrator
  • *****
  • Posts: 3723
  • Karma: +411/-0
  • Definitely not Dink!
    • NeoSource
Some PVC Bankswitch code
« Reply #10 on: January 19, 2005, 07:06:58 AM »
James.   It's essentially the same as the bootleg bankswitch code; just set it up like that.


Offline bms888

  • Jr. Member
  • **
  • Posts: 93
  • Karma: +0/-0
  • Member
Some PVC Bankswitch code
« Reply #11 on: January 19, 2005, 08:33:49 AM »
Code: [Select]

static void mslug5PVCDecrypt()
{
interleave_pdata();
do_neopvc(3);

// AES Patch
unsigned short *mem16 = (unsigned short *)Neo68KROM01;
mem16[ 0x122A/2 ] = 0x4e71;
mem16[ 0x122C/2 ] = 0x4e71;
}

Offline bms888

  • Jr. Member
  • **
  • Posts: 93
  • Karma: +0/-0
  • Member
Some PVC Bankswitch code
« Reply #12 on: January 19, 2005, 08:35:57 AM »
Code: [Select]

static void svcchaos_px_patch()
{
// To patch svcchaos NEO LOGO Loop bug in FBA
unsigned short *mem16 = (unsigned short *)Neo68KROM01;
mem16[ 0x9DF0/2 ] = 0x4E71;
mem16[ 0x9DF2/2 ] = 0x4E71;
mem16[ 0x9E08/2 ] = 0x4E71;
mem16[ 0x9E0A/2 ] = 0x4E71;
}

static void svcchaosPVCDecrypt()
{
do_neopvc(2);
svcchaos_px_patch();
}

Offline bms888

  • Jr. Member
  • **
  • Posts: 93
  • Karma: +0/-0
  • Member
Some PVC Bankswitch code
« Reply #13 on: January 19, 2005, 08:38:28 AM »
Code: [Select]

static void kof2003PVCDecrypt()
{
interleave_pdata();
do_neopvc(1);

// 0xF9 for Good CRC, 0x75 to patch black screen in FBA
Neo68KROM01[ 0x0816 ] = 0x75;
}

Offline bms888

  • Jr. Member
  • **
  • Posts: 93
  • Karma: +0/-0
  • Member
Some PVC Bankswitch code
« Reply #14 on: January 19, 2005, 08:55:39 AM »
But svcchaos & kof2003 use pvcMapHandler, not pvcMapHandler2,bye!