Author Topic: Fun with write handlers and memory mapping  (Read 5984 times)

Offline iq_132

  • Administrator
  • *****
  • Posts: 3724
  • Karma: +411/-0
  • Definitely not Dink!
    • NeoSource
Fun with write handlers and memory mapping
« on: February 17, 2006, 12:39:06 AM »
Here's an implementation of the kof2002 px descramble that uses 0 bytes of ram to descramble.
I wouldn't suggest using this as your default driver, but it may be of interest to someone.

Code: [Select]

void __fastcall kof2002WriteWordBankswitch(unsigned int /*sekAddress*/, unsigned short wordValue)
{
unsigned int nBank[] = {
0x100000, 0x280000, 0x300000, 0x180000, 0x000000, 0x380000, 0x200000, 0x080000
};

if (wordValue != nNeo68KROMBank && wordValue < 4) {
nNeo68KROMBank = wordValue;
SekMapMemory(Neo68KROM + 0x100000 + nBank[wordValue * 2 + 0], 0x200000, 0x27FFFF, SM_ROM);
SekMapMemory(Neo68KROM + 0x100000 + nBank[wordValue * 2 + 1], 0x280000, 0x2FFFFF, SM_ROM);
}
}

static int kof2002Init()
{
int nRet;

nNeoTextROMSize = 0x080000;
nNeoProtectionXor = 0xEC;

nRet = NeoInit();

if (nRet == 0) {
// Install protection handler
SekMapHandler(5, 0x2FFFF0, 0x2FFFFF, SM_WRITE);
SekSetWriteWordHandler(5,  kof2002WriteWordBankswitch);

PCM2DecryptVInfo Info = { 0x0A5000, 0x000000, { 0xF9, 0xE0, 0x5D, 0xF3, 0xEA, 0x92, 0xBE, 0xEF } };

PCM2DecryptV(&Info);
}

return nRet;
}

« Last Edit: February 17, 2006, 12:42:40 AM by iq_132 »


Offline James33

  • Expert
  • *****
  • Posts: 532
  • Karma: +3/-0
  • The Mame Man
    • Emulation Zone
Re: Fun with write handlers and memory mapping
« Reply #1 on: February 17, 2006, 06:47:20 AM »
Wow thats cool  :biggrin:
IQ Forum Member

Offline iq_132

  • Administrator
  • *****
  • Posts: 3724
  • Karma: +411/-0
  • Definitely not Dink!
    • NeoSource
Re: Fun with write handlers and memory mapping
« Reply #2 on: February 17, 2006, 03:32:40 PM »
The same can be done for samsho5 and samsh5sp

Code: [Select]

void __fastcall samsho5WriteWordBankswitch(unsigned int /*sekAddress*/, unsigned short wordValue)
{
unsigned int nBank[14] = {
0x700000, 0x680000, 0x500000, 0x180000, 0x200000, 0x480000, 0x300000,
0x780000, 0x600000, 0x280000, 0x100000, 0x580000, 0x400000, 0x380000
};

if (wordValue != nNeo68KROMBank && wordValue < 8)
{
nNeo68KROMBank = wordValue;
SekMapMemory(Neo68KROM + nBank[wordValue * 2 + 0], 0x200000, 0x27FFFF, SM_ROM);
SekMapMemory(Neo68KROM + nBank[wordValue * 2 + 1], 0x280000, 0x2FFFFF, SM_ROM);
}
}


SekMapHandler(5, 0x2FFFF0, 0x2FFFFF, SM_WRITE);
SekSetWriteWordHandler(5,  samsho5WriteWordBankswitch);



Code: [Select]

void __fastcall samsh5spWriteWordBankswitch(unsigned int /*sekAddress*/, unsigned short wordValue)
{
unsigned int nBank[14] = {
0x500000, 0x480000, 0x600000, 0x580000, 0x700000, 0x280000, 0x100000, 
0x680000, 0x400000, 0x780000, 0x200000, 0x380000, 0x300000, 0x180000
};

if (wordValue != nNeo68KROMBank && wordValue < 8)
{
nNeo68KROMBank = wordValue;
SekMapMemory(Neo68KROM + nBank[wordValue * 2 + 0], 0x200000, 0x27FFFF, SM_ROM);
SekMapMemory(Neo68KROM + nBank[wordValue * 2 + 1], 0x280000, 0x2FFFFF, SM_ROM);
}
}


SekMapHandler(5,   0x2FFFF0, 0x2FFFFF, SM_WRITE);
SekSetWriteWordHandler(5,  samsh5spWriteWordBankswitch);




Offline FerchogtX

  • FBNeo Dev
  • ******
  • Posts: 375
  • Karma: +7/-0
  • FB Alpha Team ;)
    • FB Alpha Plus! Web Site
Re: Fun with write handlers and memory mapping
« Reply #3 on: February 21, 2006, 09:28:47 AM »
Uhm... looks very interesting this... I hope that is certifyed that is a bank descrambling what is used on this games, because is very... weird that you can descramble a rom wih this XD... but maybe the real MVS work like that and NOT descrambling a ROM directly...

Anyway you gave me an idea... can this be done for patching the AES protection? for example sengoku 3? just wondering
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 Shoometsu

  • Jr. Member
  • **
  • Posts: 66
  • Karma: +0/-0
  • I finally have an avatar XD
Re: Fun with write handlers and memory mapping
« Reply #4 on: February 28, 2006, 09:21:01 PM »
the code for kof2002 works on matrim too, thanks XD
<- Who are you?