Author Topic: KOF2003b load state problem  (Read 6547 times)

Offline youngshare

  • Newbies
  • *
  • Posts: 17
  • Karma: +0/-0
  • Junior Member
KOF2003b load state problem
« on: July 22, 2005, 07:42:14 AM »
In KOF2003b we cound not use load state function, what's the reason of the problem?
Thx :confused:

Offline iq_132

  • Administrator
  • *****
  • Posts: 3724
  • Karma: +411/-0
  • Definitely not Dink!
    • NeoSource
Re: KOF2003b load state problem
« Reply #1 on: July 25, 2005, 07:21:27 PM »
You should try to load states with any of the romsets that are kof2003/svc based and have a bankswitch.
The game should have major problems.  I have a fix for this and will try to post it soon.


Offline FerchogtX

  • FBNeo Dev
  • ******
  • Posts: 375
  • Karma: +7/-0
  • FB Alpha Team ;)
    • FB Alpha Plus! Web Site
Re: KOF2003b load state problem
« Reply #2 on: July 25, 2005, 07:28:52 PM »
This games requires something like kof10th... the memory scan (like NeoSMAScan function)... I made one some time ago, but didn't work :( I hope IQ can find out what oit needs
See ya!!!! :biggrin:

Good and evil co-exist because of the balance, lies are not part of it...

FB Alpha Plus! site infos updated, see the latest info clicking on my profile link...

Offline iq_132

  • Administrator
  • *****
  • Posts: 3724
  • Karma: +411/-0
  • Definitely not Dink!
    • NeoSource
Re: KOF2003b load state problem
« Reply #3 on: August 15, 2005, 01:21:37 AM »
Ok, now that I have some time, I can post the fix :)

If you are running fba 0.2.95.21, 0.2.95.22, or 0.2.95.23

Remove whichever of these you have in your build:
Code: [Select]
| HARDWARE_SNK_CUSTOM_BANKING
or
Code: [Select]
| HARDWARE_SNK_NEWBANKSYSTEM

Next, add this to your bankswitch code:

Code: [Select]
// Don't map anything to 0x200000 - 0x2FFFFF on reset/save state
void NULLMapBank()
{
      return;
}

Next, add this to your init code for every game that uses that particular bankswitch
Code: [Select]
pNeoBankswitchCallback = NULLMapBank;

This code will fix the save states for games like svcchaos, svcboot, svcsplus, kof2003, kof2003b, etc.


« Last Edit: August 15, 2005, 01:22:42 AM by iq_132 »


Offline CaptainCPS

  • FBNeo Dev
  • ******
  • Posts: 1513
  • Karma: +127/-0
  • FB Alpha Team
    • CaptainCPS's Home
Re: KOF2003b load state problem
« Reply #4 on: August 15, 2005, 01:42:26 AM »
ThanX IQ_132 i was having that prob a time back ^^..so thanX
for that code...

i finally can fix it! :-D

SeeYaa!!!
:-D

Offline Shoometsu

  • Jr. Member
  • **
  • Posts: 66
  • Karma: +0/-0
  • I finally have an avatar XD
Re: KOF2003b load state problem
« Reply #5 on: August 20, 2005, 03:28:10 PM »
Ok, now that I have some time, I can post the fix :)

If you are running fba 0.2.95.21, 0.2.95.22, or 0.2.95.23

Remove whichever of these you have in your build:
Code: [Select]
| HARDWARE_SNK_CUSTOM_BANKING
or
Code: [Select]
| HARDWARE_SNK_NEWBANKSYSTEM

Next, add this to your bankswitch code:

Code: [Select]
// Don't map anything to 0x200000 - 0x2FFFFF on reset/save state
void NULLMapBank()
{
      return;
}

Next, add this to your init code for every game that uses that particular bankswitch
Code: [Select]
pNeoBankswitchCallback = NULLMapBank;

This code will fix the save states for games like svcchaos, svcboot, svcsplus, kof2003, kof2003b, etc.




can you be more specific? I'm using this code:
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];
}

// Special Bankswitch
void pvc_CalcBank()// on writes to f0-f3
{
unsigned int 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;
SekMapMemory(Neo68KROM+0x100000+offset,0x200000,0x2fdfff,SM_ROM);
}

// These perform some palette calculations
// Unpack palette word to RGB dword
void pvc_prot1()// on writes to e0/e1
{
unsigned char b1, b2;
b1 = pvc_r8(0x2fffe0);
b2 = pvc_r8(0x2fffe1);
pvc_w8(0x2fffe3,(((b2>>0)&0xf)<<1)|((b1>>4)&1));
pvc_w8(0x2fffe2,(((b2>>4)&0xf)<<1)|((b1>>5)&1));
pvc_w8(0x2fffe5,(((b1>>0)&0xf)<<1)|((b1>>6)&1));
pvc_w8(0x2fffe4,  (b1>>7));
}

// pack RGB dword to palette word
void pvc_prot2()// on writes to e8/e9/ea/eb
{
unsigned char b1, b2, b3, b4;
b1 = pvc_r8(0x2fffe8);
b2 = pvc_r8(0x2fffe9);
b3 = pvc_r8(0x2fffea);
b4 = pvc_r8(0x2fffeb);

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

void __fastcall pvcWriteByteBankSwitch(unsigned int sekAddress, unsigned char byteValue)
{
pvc_w8(sekAddress,byteValue);
if (sekAddress>=0x2fffe0 && sekAddress<=0x2fffe1)pvc_prot1();
else if(sekAddress>=0x2fffe8 && sekAddress<=0x2fffeb)pvc_prot2();
else if(sekAddress>=0x2ffff0 && sekAddress<=0x2ffff3)pvc_CalcBank();
}

void __fastcall pvcWriteWordBankSwitch(unsigned int sekAddress, unsigned short wordValue)
{
CartRAM[(sekAddress-0x2fe000)/2]=wordValue;
if (sekAddress>=0x2fffe0 && sekAddress<=0x2fffe1)pvc_prot1();
else if(sekAddress>=0x2fffe8 && sekAddress<=0x2fffeb)pvc_prot2();
else if(sekAddress>=0x2ffff0 && sekAddress<=0x2ffff3)pvc_CalcBank();
}

// Special Bankswitch
void pvc_CalcBank2()// on writes to f0-f3
{
unsigned int offset;
// Make this universal for kof2003b + kof2003p
if ((!strcmp(BurnDrvGetTextA(DRV_NAME), "kof2k4eh")) || (!strcmp(BurnDrvGetTextA(DRV_NAME), "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;
Neo68KROM[0x58196]=pvc_r8(0x2ffff3);
}
SekMapMemory(Neo68KROM+0x100000+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();
}

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

SekMapHandler(5,0x2fe000, 0x2fffff, SM_WRITE);
SekSetWriteWordHandler(5, pvcWriteWordBankSwitch);
SekSetWriteByteHandler(5, pvcWriteByteBankSwitch);
}

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
}

static void kof03pvcMapHandler()
{
pvcMapHandler();

pcbBiosMapHandler();// for PCB BIOS
}

static void interleave_pdata()
{
int i, j=0;
UINT8 *src = Neo68KROM;
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(Neo68KROM,dst,0x800000);
free(dst);
}

// Neo-PVC Code for PCB and MVS games with this protection
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 = Neo68KROM;
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);
}

<- Who are you?

Offline iq_132

  • Administrator
  • *****
  • Posts: 3724
  • Karma: +411/-0
  • Definitely not Dink!
    • NeoSource
Re: KOF2003b load state problem
« Reply #6 on: August 20, 2005, 09:31:24 PM »
What exactly do you need specified??