summaryrefslogtreecommitdiffstatshomepage
path: root/src
diff options
context:
space:
mode:
author Alex W. Jackson <alex.w.jackson@gmail.com>2013-06-21 10:04:30 +0000
committer Alex W. Jackson <alex.w.jackson@gmail.com>2013-06-21 10:04:30 +0000
commit6b059c8117e3f8428e27efcb2f1f545495616295 (patch)
tree49f54f2282f068176a62d1f8834787955f72bc30 /src
parent1615025734e4d5875a368401bb601a0b96dceaba (diff)
neocrypt.c cleanup part 1: simplify kf2k3pcb bios decryption, fix some endian issues (Alex Jackson)
Diffstat (limited to 'src')
-rw-r--r--src/mame/drivers/neogeo.inc2
-rw-r--r--src/mame/includes/neogeo.h2
-rw-r--r--src/mame/machine/neocrypt.c110
3 files changed, 64 insertions, 50 deletions
diff --git a/src/mame/drivers/neogeo.inc b/src/mame/drivers/neogeo.inc
index 8d27d4f48b7..29da96e9eec 100644
--- a/src/mame/drivers/neogeo.inc
+++ b/src/mame/drivers/neogeo.inc
@@ -9732,7 +9732,7 @@ DRIVER_INIT_MEMBER(neogeo_state,kf2k3pcb)
DRIVER_INIT_CALL(neogeo);
kf2k3pcb_decrypt_68k();
kf2k3pcb_gfx_decrypt();
- kof2003biosdecode();
+ kf2k3pcb_sp1_decrypt();
neogeo_cmc50_m1_decrypt();
/* extra little swap on the m1 - this must be performed AFTER the m1 decrypt
diff --git a/src/mame/includes/neogeo.h b/src/mame/includes/neogeo.h
index 7346a0d7092..2f95e0cbab8 100644
--- a/src/mame/includes/neogeo.h
+++ b/src/mame/includes/neogeo.h
@@ -450,7 +450,7 @@ protected:
void kof2003h_decrypt_68k();
void neo_pcm2_snk_1999(int value);
void neo_pcm2_swap(int value);
- void kof2003biosdecode();
+ void kf2k3pcb_sp1_decrypt();
};
diff --git a/src/mame/machine/neocrypt.c b/src/mame/machine/neocrypt.c
index a3fc5451f86..3b17c0dadbe 100644
--- a/src/mame/machine/neocrypt.c
+++ b/src/mame/machine/neocrypt.c
@@ -678,12 +678,11 @@ void neogeo_state::svcpcb_gfx_decrypt()
{
UINT32 rom32 = rom[i] | rom[i+1]<<8 | rom[i+2]<<16 | rom[i+3]<<24;
rom32 = BITSWAP32( rom32, 0x09, 0x0d, 0x13, 0x00, 0x17, 0x0f, 0x03, 0x05, 0x04, 0x0c, 0x11, 0x1e, 0x12, 0x15, 0x0b, 0x06, 0x1b, 0x0a, 0x1a, 0x1c, 0x14, 0x02, 0x0e, 0x1d, 0x18, 0x08, 0x01, 0x10, 0x19, 0x1f, 0x07, 0x16 );
- rom[i] = rom32&0xff;
- rom[i+1] = (rom32>>8)&0xff;
- rom[i+2] = (rom32>>16)&0xff;
- rom[i+3] = (rom32>>24)&0xff;
+ buf[i] = rom32 & 0xff;
+ buf[i+1] = (rom32>>8) & 0xff;
+ buf[i+2] = (rom32>>16) & 0xff;
+ buf[i+3] = (rom32>>24) & 0xff;
}
- memcpy( buf, rom, rom_size );
for( i = 0; i < rom_size / 4; i++ )
{
ofst = BITSWAP24( (i & 0x1fffff), 0x17, 0x16, 0x15, 0x04, 0x0b, 0x0e, 0x08, 0x0c, 0x10, 0x00, 0x0a, 0x13, 0x03, 0x06, 0x02, 0x07, 0x0d, 0x01, 0x11, 0x09, 0x14, 0x0f, 0x12, 0x05 );
@@ -724,12 +723,15 @@ void neogeo_state::kf2k3pcb_gfx_decrypt()
{
rom[ i ] ^= xorval[ (i % 4) ];
}
- for ( i = 0; i < rom_size; i+=4 )
+ for ( i = 0; i < rom_size; i +=4 )
{
- UINT32 *rom32 = (UINT32*)&rom[ i ];
- *rom32 = BITSWAP32( *rom32, 0x09, 0x0d, 0x13, 0x00, 0x17, 0x0f, 0x03, 0x05, 0x04, 0x0c, 0x11, 0x1e, 0x12, 0x15, 0x0b, 0x06, 0x1b, 0x0a, 0x1a, 0x1c, 0x14, 0x02, 0x0e, 0x1d, 0x18, 0x08, 0x01, 0x10, 0x19, 0x1f, 0x07, 0x16 );
+ UINT32 rom32 = rom[i] | rom[i+1]<<8 | rom[i+2]<<16 | rom[i+3]<<24;
+ rom32 = BITSWAP32( rom32, 0x09, 0x0d, 0x13, 0x00, 0x17, 0x0f, 0x03, 0x05, 0x04, 0x0c, 0x11, 0x1e, 0x12, 0x15, 0x0b, 0x06, 0x1b, 0x0a, 0x1a, 0x1c, 0x14, 0x02, 0x0e, 0x1d, 0x18, 0x08, 0x01, 0x10, 0x19, 0x1f, 0x07, 0x16 );
+ buf[i] = rom32 & 0xff;
+ buf[i+1] = (rom32>>8) & 0xff;
+ buf[i+2] = (rom32>>16) & 0xff;
+ buf[i+3] = (rom32>>24) & 0xff;
}
- memcpy( buf, rom, rom_size );
for ( i = 0; i < rom_size; i+=4 )
{
ofst = BITSWAP24( (i & 0x7fffff), 0x17, 0x15, 0x0a, 0x14, 0x13, 0x16, 0x12, 0x11, 0x10, 0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x09, 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00 );
@@ -1522,46 +1524,58 @@ NeoGeo 'SP1' (BIOS) ROM encryption
/* only found on kf2k3pcb */
-void neogeo_state::kof2003biosdecode()
+void neogeo_state::kf2k3pcb_sp1_decrypt()
{
- static const UINT8 address[0x80]={
- 0xb9,0xb8,0x36,0x37,0x3d,0x3c,0xb2,0xb3,
- 0xb9,0xb8,0x36,0x37,0x3d,0x3c,0xb2,0xb3,
- 0x65,0xea,0x6f,0xe0,0xe1,0x6e,0xeb,0x64,
- 0x65,0xea,0x6f,0xe0,0xe1,0x6e,0xeb,0x64,
- 0x45,0xca,0x47,0xc8,0xc9,0x46,0xcb,0x44,
- 0x45,0xca,0x47,0xc8,0xc9,0x46,0xcb,0x44,
- 0x9a,0x15,0x98,0x17,0x1e,0x91,0x1c,0x93,
- 0x9a,0x15,0x98,0x17,0x1e,0x91,0x1c,0x93,
- 0x7e,0xf1,0x7c,0xf3,0xf0,0x7f,0xf2,0x7d,
- 0x7e,0xf1,0x7c,0xf3,0xf0,0x7f,0xf2,0x7d,
- 0x27,0xa8,0x25,0xaa,0xa3,0x2c,0xa1,0x2e,
- 0x27,0xa8,0x25,0xaa,0xa3,0x2c,0xa1,0x2e,
- 0x04,0x8b,0x06,0x89,0x80,0x0f,0x82,0x0d,
- 0x04,0x8b,0x06,0x89,0x80,0x0f,0x82,0x0d,
- 0xd3,0xd2,0x5c,0x5d,0x57,0x56,0xd8,0xd9,
- 0xd3,0xd2,0x5c,0x5d,0x57,0x56,0xd8,0xd9,
+ static const UINT8 address[0x40] = {
+ 0x04,0x0a,0x04,0x0a,0x04,0x0a,0x04,0x0a,
+ 0x0a,0x04,0x0a,0x04,0x0a,0x04,0x0a,0x04,
+ 0x09,0x07,0x09,0x07,0x09,0x07,0x09,0x07,
+ 0x09,0x09,0x04,0x04,0x09,0x09,0x04,0x04,
+ 0x0b,0x0d,0x0b,0x0d,0x03,0x05,0x03,0x05,
+ 0x0e,0x0e,0x03,0x03,0x0e,0x0e,0x03,0x03,
+ 0x03,0x05,0x0b,0x0d,0x03,0x05,0x0b,0x0d,
+ 0x04,0x00,0x04,0x00,0x0e,0x0a,0x0e,0x0a
};
- UINT16*src= (UINT16*)memregion( "mainbios" )->base();
- UINT16*buf= auto_alloc_array(machine(), UINT16, 0x80000/2);
- int a,addr;
-
- for (a=0;a<0x80000/2;a++)
- {
- if (src[a] & (0x0004 << (8*BYTE_XOR_LE(0)))) src[a] ^= 0x0001 << (8*BYTE_XOR_LE(0));
- if (src[a] & (0x0010 << (8*BYTE_XOR_LE(0)))) src[a] ^= 0x0002 << (8*BYTE_XOR_LE(0));
- if (src[a] & (0x0020 << (8*BYTE_XOR_LE(0)))) src[a] ^= 0x0008 << (8*BYTE_XOR_LE(0));
- //address xor
- addr = a & ~0xff;
- addr |= address[BYTE_XOR_LE(a & 0x7f)];
- if ( a & 0x00008) addr ^= 0x0008;
- if ( a & 0x00080) addr ^= 0x0080;
- if ( a & 0x00200) addr ^= 0x0100;
- if (~a & 0x02000) addr ^= 0x0400;
- if (~a & 0x10000) addr ^= 0x1000;
- if ( a & 0x02000) addr ^= 0x8000;
- buf[addr]=src[a];
- }
- memcpy(src,buf,0x80000);
+
+ UINT16 *rom = (UINT16 *)memregion("mainbios")->base();
+ UINT16 *buf = auto_alloc_array(machine(), UINT16, 0x80000/2);
+ int i, addr;
+
+ for (i = 0; i < 0x80000/2; i++)
+ {
+ // address xor
+ addr = i ^ 0x0020;
+ if ( i & 0x00020) addr ^= 0x0010;
+ if (~i & 0x00010) addr ^= 0x0040;
+ if (~i & 0x00004) addr ^= 0x0080;
+ if ( i & 0x00200) addr ^= 0x0100;
+ if (~i & 0x02000) addr ^= 0x0400;
+ if (~i & 0x10000) addr ^= 0x1000;
+ if ( i & 0x02000) addr ^= 0x8000;
+ addr ^= address[((i >> 1) & 0x38) | (i & 7)];
+ buf[i] = rom[addr];
+
+ // data xor
+ if (buf[i] & 0x0004) buf[i] ^= 0x0001;
+ if (buf[i] & 0x0010) buf[i] ^= 0x0002;
+ if (buf[i] & 0x0020) buf[i] ^= 0x0008;
+ }
+
+ memcpy(rom, buf, 0x80000);
auto_free(machine(), buf);
+
+ {
+ FILE *fp;
+ const char *gamename = machine().system().name;
+ int rom_size = memregion("mainbios")->bytes();
+ char filename[256];
+ sprintf(filename, "%s_bios.dump", gamename);
+
+ fp=fopen(filename, "w+b");
+ if (fp)
+ {
+ fwrite(rom, rom_size, 1, fp);
+ fclose(fp);
+ }
+ }
}