Author Topic: New SMA decryption code  (Read 4811 times)

Offline FerchogtX

  • FBNeo Dev
  • ******
  • Posts: 375
  • Karma: +7/-0
  • FB Alpha Team ;)
    • FB Alpha Plus! Web Site
New SMA decryption code
« on: April 04, 2006, 08:21:22 PM »
I've not fully tested this yet... I hope is bug free, it's based on IQ's PVC decryption code:
Code: [Select]
/* kof99, garou, garouo, mslug3 and kof2000 have and SMA chip which contains program code and decrypts the 68k roms */
void neo_sma_snk_1999(INT32 value)
{
/* thanks to Razoola and Mr K for the info */
const UINT8 tbl0[5][16] = {
{ 13, 7, 3, 0, 9, 4, 5, 6, 1, 12, 8, 14, 10, 11, 2, 15 },
{ 13, 12, 14, 10, 8, 2, 3, 1, 5, 9, 11, 4, 15, 0, 6, 7 },
{ 14, 5, 1, 11, 7, 4, 10, 15, 3, 12, 8, 13, 0, 2, 9, 6 },
{ 4, 11, 14, 3, 1, 13, 0, 7, 2, 8, 12, 15, 10, 9, 5, 6 },
{ 12, 8, 11, 3, 15, 14, 7, 0, 10, 13, 6, 5, 9, 2, 1, 4 },
};

const UINT8 tbl1[5][2][18] = {
{ { 11, 6, 14, 17, 16, 5, 8, 10, 12, 0, 4, 3, 2, 7, 9, 15, 13, 1 }, { 17, 16, 15, 14, 13, 12, 11, 10, 6, 2, 4, 9, 8, 3, 1, 7, 0, 5 }, },
{ { 4, 5, 16, 14, 7, 9, 6, 13, 17, 15, 3, 1, 2, 12, 11, 8, 10, 0 }, { 17, 16, 15, 14, 9, 4, 8, 3, 13, 6, 2, 7, 0, 12, 1, 11, 10, 5 }, },
{ { 5, 16, 11, 2, 6, 7, 17, 3, 12, 8, 14, 4, 0, 9, 1, 10, 15, 13 }, { 17, 16, 15, 14, 12, 8, 1, 7, 11, 3, 13, 10, 6, 9, 5, 4, 0, 2 }, },
{ { 15, 2, 1, 13, 3, 0, 9, 6, 16, 4, 11, 5, 7, 12, 17, 14, 10, 8 }, { 17, 16, 15, 2, 11, 0, 14, 6, 4, 13, 8, 9, 3, 10, 7, 5, 12, 1 }, },
{ { 8, 4, 15, 13, 3, 14, 16, 2, 6, 17, 7, 12, 10, 0, 5, 11, 1, 9 }, { 17, 16, 15, 14, 13, 12, 11, 10, 4, 1, 3, 8, 6, 2, 7, 0, 9, 5 }, },
};

INT32 offset[5][2] = {
{ 0x700000, 0x600000 },
{ 0x710000, 0x800000 },
{ 0x7f8000, 0x800000 },
{ 0x5d0000, 0x800000 },
{ 0x73a000, 0x63a000 },
};

INT32 bufsize[5] = { 0x800, 0x8000, 0x8000, 0x10000, 0x800 };

UINT16 *rom;
INT32 i, j, g = value;

/* swap data lines on the whole ROMs */
rom = (UINT16*)(memory_region(REGION_CPU1) + 0x100000);
for (i = 0; i < 0x800000 / 2; i++) {
rom[i] = BITSWAP16(rom[i], tbl0[g][0], tbl0[g][1], tbl0[g][2], tbl0[g][3], tbl0[g][4], tbl0[g][5], tbl0[g][6], tbl0[g][7], tbl0[g][8], tbl0[g][9], tbl0[g][10], tbl0[g][11], tbl0[g][12], tbl0[g][13], tbl0[g][14], tbl0[g][15]);
}

/* swap address lines & relocate fixed part */
rom = (UINT16*)memory_region(REGION_CPU1);
for (i = 0; i < 0x0c0000 / 2; i++) {
rom[i] = rom[(offset[g][0] / 2) + BITSWAP24(i, 23, 22, 21, 20, 19, 18, tbl1[g][0][0], tbl1[g][0][1], tbl1[g][0][2], tbl1[g][0][3], tbl1[g][0][4], tbl1[g][0][5], tbl1[g][0][6], tbl1[g][0][7], tbl1[g][0][8], tbl1[g][0][9], tbl1[g][0][10], tbl1[g][0][11], tbl1[g][0][12], tbl1[g][0][13], tbl1[g][0][14], tbl1[g][0][15], tbl1[g][0][16], tbl1[g][0][17])];
}

/* swap address lines for the banked part */
rom = (UINT16*)(memory_region(REGION_CPU1) + 0x100000);
for (i = 0; i < (offset[g][1] / 2); i += (bufsize[g] / 2)) {
UINT16 *buffer = malloc((bufsize[g] / 2) * sizeof(UINT16));
memcpy(buffer, &rom[i], bufsize[g]);
for (j = 0; j < (bufsize[g] / 2); j++) {
rom[i + j] = buffer[BITSWAP24(j, 23, 22, 21, 20, 19, 18, tbl1[g][1][0], tbl1[g][1][1], tbl1[g][1][2], tbl1[g][1][3], tbl1[g][1][4], tbl1[g][1][5], tbl1[g][1][6], tbl1[g][1][7], tbl1[g][1][8], tbl1[g][1][9], tbl1[g][1][10], tbl1[g][1][11], tbl1[g][1][12], tbl1[g][1][13], tbl1[g][1][14], tbl1[g][1][15], tbl1[g][1][16], tbl1[g][1][17])];
}
}
}
How to use:
Declare this in includes\neogeo.h:
extern void neo_sma_snk_1999(INT32 value);
now in your driver innits instead of
Code: [Select]
GameName_decrypt_68k();add:
for kof99
Code: [Select]
neo_sma_snk_1999(0);for garou
Code: [Select]
neo_sma_snk_1999(1);for garouo
Code: [Select]
neo_sma_snk_1999(2);for mslug3
Code: [Select]
neo_sma_snk_1999(3);for kof2000
Code: [Select]
neo_sma_snk_1999(4);I hope that it works properly...
See ya!!!!!! :biggrin:
« Last Edit: April 10, 2006, 01:13:51 PM by FerchogtX »

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 FerchogtX

  • FBNeo Dev
  • ******
  • Posts: 375
  • Karma: +7/-0
  • FB Alpha Team ;)
    • FB Alpha Plus! Web Site
Re: New SMA decryption code
« Reply #1 on: April 05, 2006, 10:54:25 PM »
Made some tweaks... now the code works perfectly :D

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 FerchogtX

  • FBNeo Dev
  • ******
  • Posts: 375
  • Karma: +7/-0
  • FB Alpha Team ;)
    • FB Alpha Plus! Web Site
Re: New SMA decryption code
« Reply #2 on: April 10, 2006, 01:14:44 PM »
Updated code... It had problems with garou...
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...