Author Topic: Bankswitch code for kof2003, svcchaos, mslug5, etc  (Read 14292 times)

Offline iq_132

  • Administrator
  • *****
  • Posts: 3621
  • Karma: +385/-0
  • Bare Knuckle!
    • NeoSource
Bankswitch code for kof2003, svcchaos, mslug5, etc
« on: September 16, 2005, 01:34:12 AM »
Here's a port of BMS888's fantastic pvc bankswitch code.

Code: [Select]
// thanks to BMS888 and Halrin for much of this code
// MAME port by IQ_132 - neosource.1emu.net
static unsigned short CartRAM[0x1000];

void pvc_w8(unsigned int offset, unsigned char data)
{
*(((unsigned char*)CartRAM)+offset)=data;
}

unsigned char pvc_r8(unsigned int offset)
{
return *(((unsigned char*)CartRAM)+offset);
}

// These perform some palette calculations
// Unpack palette word to RGB dword
void pvc_prot1( void ) // on writes to e0/e1
{
unsigned char b1, b2;
b1 = pvc_r8(0x1fe1);
b2 = pvc_r8(0x1fe0);

pvc_w8(0x1fe2,(((b2>>0)&0xf)<<1)|((b1>>4)&1));
pvc_w8(0x1fe3,(((b2>>4)&0xf)<<1)|((b1>>5)&1));
pvc_w8(0x1fe4,(((b1>>0)&0xf)<<1)|((b1>>6)&1));
pvc_w8(0x1fe5, (b1>>7));
}

// Pack RGB dword to palette word
void pvc_prot2( void ) // on writes to e8/e9/ea/eb
{
unsigned char b1, b2, b3, b4;
b1 = pvc_r8(0x1fe9);
b2 = pvc_r8(0x1fe8);
b3 = pvc_r8(0x1feb);
b4 = pvc_r8(0x1fea);

pvc_w8(0x1fec,(b2>>1)|((b1>>1)<<4));
pvc_w8(0x1fed,(b4>>1)|((b2&1)<<4)|((b1&1)<<5)|((b4&1)<<6)|((b3&1)<<7));
}

void pvc_write_bankswitch( void )
{
UINT32 bankaddress;
bankaddress = ((CartRAM[0xff8]>>8)|(CartRAM[0xff9]<<8));
*(((unsigned char *)CartRAM) + 0x1ff0) = 0xA0;
*(((unsigned char *)CartRAM) + 0x1ff1) &= 0xFE;
*(((unsigned char *)CartRAM) + 0x1ff3) &= 0x7F;
neogeo_set_cpu1_second_bank(bankaddress+0x100000);
}

static READ16_HANDLER( pvc_prot_r )
{
return CartRAM[ offset ];
}

static WRITE16_HANDLER( pvc_prot_w )
{
COMBINE_DATA( &CartRAM[ offset ] );

if (offset == 0xFF0)pvc_prot1();
else if(offset >= 0xFF4 && offset <= 0xFF5)pvc_prot2();
else if(offset >= 0xFF8)pvc_write_bankswitch();
}

for kof2003, use this init:

Code: [Select]
DRIVER_INIT( kof2003 )
{
kof2003_px_decrypt();
kof2003_sx_decrypt();
kof2003_vx_decrypt();

neogeo_fix_bank_type = 2;
init_neogeo();

memory_install_read16_handler(0, ADDRESS_SPACE_PROGRAM, 0x2fe000, 0x2fffff, 0, 0, pvc_prot_r);
memory_install_write16_handler(0, ADDRESS_SPACE_PROGRAM, 0x2fe000, 0x2fffff, 0, 0, pvc_prot_w);

memory_install_read16_handler( 0, ADDRESS_SPACE_PROGRAM, 0xc00000, 0xc3ffff, 0, 0, MRA16_BANK3 );  // 256k bios
}


for kof2003b:

Code: [Select]
static READ16_HANDLER( kof2003b_prot_r )
{
return CartRAM[0xff9];
}

DRIVER_INIT( kof2003b )
{
kof2003b_px_decrypt();
kof2003b_sx_decrypt();

init_neogeo();

memory_install_read16_handler(0, ADDRESS_SPACE_PROGRAM, 0x2fe000, 0x2fffff, 0, 0, pvc_prot_r);
memory_install_write16_handler(0, ADDRESS_SPACE_PROGRAM, 0x2fe000, 0x2fffff, 0, 0, pvc_prot_w);

memory_install_read16_handler(0, ADDRESS_SPACE_PROGRAM, 0x058196, 0x058197, 0, 0, kof2003b_prot_r);
}


Code: [Select]
DRIVER_INIT( kof2k3up )
{
kof2003b_px_decrypt();
kof2k3up_px_decrypt();
kof2k3up_sx_decrypt();

init_neogeo();

memory_install_read16_handler(0, ADDRESS_SPACE_PROGRAM, 0x2fe000, 0x2fffff, 0, 0, pvc_prot_r);
memory_install_write16_handler(0, ADDRESS_SPACE_PROGRAM, 0x2fe000, 0x2fffff, 0, 0, pvc_prot_w);

memory_install_read16_handler(0, ADDRESS_SPACE_PROGRAM, 0x058196, 0x058197, 0, 0, kof2003b_prot_r);
}


Code: [Select]
DRIVER_INIT( svcchaos )
{
svcchaos_px_decrypt();
svcchaos_gfx_decrypt();
svcchaos_vx_decrypt();

neogeo_fix_bank_type = 2;
init_neogeo();

memory_install_read16_handler(0, ADDRESS_SPACE_PROGRAM, 0x2fe000, 0x2fffff, 0, 0, pvc_prot_r);
memory_install_write16_handler(0, ADDRESS_SPACE_PROGRAM, 0x2fe000, 0x2fffff, 0, 0, pvc_prot_w);
}

Code: [Select]
DRIVER_INIT( svchaosa )
{
svcchaos_px_decrypt();
kof2000_neogeo_gfx_decrypt(0x57);
svcchaos_vx_decrypt();

neogeo_fix_bank_type = 2;
init_neogeo();

memory_install_read16_handler(0, ADDRESS_SPACE_PROGRAM, 0x2fe000, 0x2fffff, 0, 0, pvc_prot_r);
memory_install_write16_handler(0, ADDRESS_SPACE_PROGRAM, 0x2fe000, 0x2fffff, 0, 0, pvc_prot_w);
}

Code: [Select]
DRIVER_INIT( svcboot )
{
svcboot_px_decrypt();
svcboot_cx_decrypt();

init_neogeo();

memory_install_read16_handler(0, ADDRESS_SPACE_PROGRAM, 0x2fe000, 0x2fffff, 0, 0, pvc_prot_r);
memory_install_write16_handler(0, ADDRESS_SPACE_PROGRAM, 0x2fe000, 0x2fffff, 0, 0, pvc_prot_w);
}

Code: [Select]
DRIVER_INIT( svcsplus )
{
svcsplus_px_decrypt();
svcsplus_sx_decrypt();
svcboot_cx_decrypt();

svcsplus_px_hack();

init_neogeo();

memory_install_read16_handler(0, ADDRESS_SPACE_PROGRAM, 0x2fe000, 0x2fffff, 0, 0, pvc_prot_r);
memory_install_write16_handler(0, ADDRESS_SPACE_PROGRAM, 0x2fe000, 0x2fffff, 0, 0, pvc_prot_w);
}

Code: [Select]
DRIVER_INIT( mslug5 )
{
mslug5_px_decrypt();
mslug5_vx_decrypt();

neogeo_fix_bank_type = 1;
kof2000_neogeo_gfx_decrypt(0x19);

memory_install_read16_handler(0, ADDRESS_SPACE_PROGRAM, 0x2fe000, 0x2fffff, 0, 0, pvc_prot_r);
memory_install_write16_handler(0, ADDRESS_SPACE_PROGRAM, 0x2fe000, 0x2fffff, 0, 0, pvc_prot_w);

init_neogeo();
}


Offline neo04

  • Jr. Member
  • **
  • Posts: 90
  • Karma: +1/-0
Re: Bankswitch code for kof2003, svcchaos, mslug5, etc
« Reply #1 on: September 16, 2005, 03:30:42 AM »
thx for all the help :)

Offline James33

  • Expert
  • *****
  • Posts: 532
  • Karma: +3/-0
  • The Mame Man
    • Emulation Zone
Re: Bankswitch code for kof2003, svcchaos, mslug5, etc
« Reply #2 on: September 17, 2005, 05:49:21 AM »
Thanks IQ :)
IQ Forum Member

Offline MAXCHAOBISA

  • Newbies
  • *
  • Posts: 2
  • Karma: +0/-0
Re: Bankswitch code for kof2003, svcchaos, mslug5, etc
« Reply #3 on: September 17, 2005, 12:08:07 PM »
Thanks IQ

Offline iq_132

  • Administrator
  • *****
  • Posts: 3621
  • Karma: +385/-0
  • Bare Knuckle!
    • NeoSource
Re: Bankswitch code for kof2003, svcchaos, mslug5, etc
« Reply #4 on: September 19, 2005, 10:38:53 PM »
Had a question about kf2k4ex, ms5plus, and mslug5b

ms5plus bankswitch

Code: [Select]
// Credits to neoaethyr
static WRITE16_HANDLER ( mslug5p_bankswitch_w ) /* Bootleg, Plus */
{
if (offset == 2)
{
neogeo_set_cpu1_second_bank(data<<16);
}
}

// put this in the ms5plus init

Code: [Select]

memory_install_write16_handler(0, ADDRESS_SPACE_PROGRAM, 0x2ffff0, 0x2fffff, 0, 0, mslug5p_bankswitch_w);



for mslug5b, just swap the second and third meg of the P rom

« Last Edit: September 19, 2005, 10:41:37 PM by iq_132 »


Offline neo04

  • Jr. Member
  • **
  • Posts: 90
  • Karma: +1/-0
Re: Bankswitch code for kof2003, svcchaos, mslug5, etc
« Reply #5 on: September 20, 2005, 12:59:23 AM »
nice! thx neoaethyr & iq :)

Offline Ashura-X

  • Member
  • ***
  • Posts: 136
  • Karma: +0/-0
Re: Bankswitch code for kof2003, svcchaos, mslug5, etc
« Reply #6 on: September 21, 2005, 08:34:09 AM »
Hmmm any mslug5b driver for mame please ???? :P

Offline iq_132

  • Administrator
  • *****
  • Posts: 3621
  • Karma: +385/-0
  • Bare Knuckle!
    • NeoSource
Re: Bankswitch code for kof2003, svcchaos, mslug5, etc
« Reply #7 on: September 21, 2005, 10:15:05 AM »
Not tested (I'm not at my pc right now) but it should work...

Code: [Select]
DRIVER_INIT( mslug5b )
{
UINT8 *src = memory_region(REGION_CPU1);
UINT8 *dst = malloc(0x100000);
if (dst)
{
// Just swap parts 2 and 3 of the P data
memcpy (dst + 0x000000, src + 0x300000, 0x100000);
memcpy (src + 0x300000, src + 0x200000, 0x100000);
memcpy (src + 0x200000, dst + 0x000000, 0x100000);

free (dst);
}

memory_install_read16_handler(0, ADDRESS_SPACE_PROGRAM, 0x2fe000, 0x2fffff, 0, 0, pvc_prot_r);
memory_install_write16_handler(0, ADDRESS_SPACE_PROGRAM, 0x2fe000, 0x2fffff, 0, 0, pvc_prot_w);

init_neogeo();
}


Offline Ashura-X

  • Member
  • ***
  • Posts: 136
  • Karma: +0/-0
Re: Bankswitch code for kof2003, svcchaos, mslug5, etc
« Reply #8 on: September 21, 2005, 01:01:06 PM »
Not tested (I'm not at my pc right now) but it should work...

Code: [Select]
DRIVER_INIT( mslug5b )
{
UINT8 *src = memory_region(REGION_CPU1);
UINT8 *dst = malloc(0x100000);
if (dst)
{
// Just swap parts 2 and 3 of the P data
memcpy (dst + 0x000000, src + 0x300000, 0x100000);
memcpy (src + 0x300000, src + 0x200000, 0x100000);
memcpy (src + 0x200000, dst + 0x000000, 0x100000);

free (dst);
}

memory_install_read16_handler(0, ADDRESS_SPACE_PROGRAM, 0x2fe000, 0x2fffff, 0, 0, pvc_prot_r);
memory_install_write16_handler(0, ADDRESS_SPACE_PROGRAM, 0x2fe000, 0x2fffff, 0, 0, pvc_prot_w);

init_neogeo();
}


Thx iq but I want to know about the load rom driver data too :P
Which roms I do need to added that game to mame...
« Last Edit: September 21, 2005, 01:04:04 PM by Ashura-X »

Offline iq_132

  • Administrator
  • *****
  • Posts: 3621
  • Karma: +385/-0
  • Bare Knuckle!
    • NeoSource
Re: Bankswitch code for kof2003, svcchaos, mslug5, etc
« Reply #9 on: September 21, 2005, 01:46:19 PM »
Look in the old mslug5 emulation infos thread at romshare.  The bootleg is the original rom released.  The romdata should be there.


Offline James33

  • Expert
  • *****
  • Posts: 532
  • Karma: +3/-0
  • The Mame Man
    • Emulation Zone
Re: Bankswitch code for kof2003, svcchaos, mslug5, etc
« Reply #10 on: November 05, 2005, 07:55:27 AM »
Had a question about kf2k4ex, ms5plus, and mslug5b

ms5plus bankswitch

Code: [Select]
// Credits to neoaethyr
static WRITE16_HANDLER ( mslug5p_bankswitch_w ) /* Bootleg, Plus */
{
if (offset == 2)
{
neogeo_set_cpu1_second_bank(data<<16);
}
}

// put this in the ms5plus init

Code: [Select]

memory_install_write16_handler(0, ADDRESS_SPACE_PROGRAM, 0x2ffff0, 0x2fffff, 0, 0, mslug5p_bankswitch_w);



for mslug5b, just swap the second and third meg of the P rom




Do you have driver for The King of Fighters 2004 - EX - Hero ?
IQ Forum Member

Offline iq_132

  • Administrator
  • *****
  • Posts: 3621
  • Karma: +385/-0
  • Bare Knuckle!
    • NeoSource
Re: Bankswitch code for kof2003, svcchaos, mslug5, etc
« Reply #11 on: November 06, 2005, 01:51:47 AM »
This might work (If it doesn't let me know ;))

Code: [Select]
static WRITE16_HANDLER( kf2k4ex_prot_w )
{
UINT32 bankaddress;
COMBINE_DATA( &CartRAM[ offset ] );
bankaddress = CartRAM[0]|(CartRAM[1]<<8);
neogeo_set_cpu1_second_bank(bankaddress+0x100000);
}

Code: [Select]
memory_install_read16_handler(0, ADDRESS_SPACE_PROGRAM, 0x2ffff0, 0x2fffff, 0, 0, pvc_prot_r);
memory_install_write16_handler(0, ADDRESS_SPACE_PROGRAM, 0x2ffff0, 0x2fffff, 0, 0, kf2k4ex_prot_w);


Offline James33

  • Expert
  • *****
  • Posts: 532
  • Karma: +3/-0
  • The Mame Man
    • Emulation Zone
Re: Bankswitch code for kof2003, svcchaos, mslug5, etc
« Reply #12 on: November 06, 2005, 04:52:00 AM »
Ok thanks IQ I will let you know :D
IQ Forum Member

Offline James33

  • Expert
  • *****
  • Posts: 532
  • Karma: +3/-0
  • The Mame Man
    • Emulation Zone
Re: Bankswitch code for kof2003, svcchaos, mslug5, etc
« Reply #13 on: November 07, 2005, 05:43:06 AM »
Yep the code works thanks IQ .   :biggrin:
IQ Forum Member

Offline iq_132

  • Administrator
  • *****
  • Posts: 3621
  • Karma: +385/-0
  • Bare Knuckle!
    • NeoSource
Re: Bankswitch code for kof2003, svcchaos, mslug5, etc
« Reply #14 on: November 12, 2005, 10:47:24 AM »
I haven't been able to port that quite yet, there's something that keeps glitching up, and I can't quite track it down ^^