Author Topic: Some shortcuts for MAME32 PLus!  (Read 4342 times)

Offline FerchogtX

  • FBA Dev
  • ******
  • Posts: 375
  • Karma: +7/-0
  • FB Alpha Team ;)
    • FB Alpha Plus! Web Site
Some shortcuts for MAME32 PLus!
« on: July 18, 2004, 12:20:50 AM »
Well, maybe this should work for newer versions of mame (i actually use 081u4 XD)...
To avoid filling around drivers\neogeo.c with inits and inits and codes and fuking stuff duplicated, i used this:
before your diver init sevtion add this:
Code: [Select]
/* DRIVER INIT section */
/* ============================================================================================== */
/* | Non Officially Supported Games | */
/* | This games are not supported by MAME, because they are too early to be supported on an | */
/* | emulator. This section has inits and functions for newer sets either encrypted or | */
/* | encrypted, this is for cleaning up the src... | */
/* ============================================================================================== */
/* ============================================================================================== */

// Sound handlers
static void neoPCM2ms4(void)// Neo-PCM2 sound encription info
{
data16_t *rom;
int i,j;

/* thanks to Elsemi for the NEO-PCM2 info */
rom = (data16_t *)(memory_region(REGION_SOUND1));
if( rom != NULL )
{
/* swap address lines on the whole ROMs */
for( i = 0; i < 0x1000000 / 2; i += 8 / 2 )
{
data16_t buffer[ 8 / 2 ];
memcpy( buffer, &rom[ i ], 8 );
for( j = 0; j < 8 / 2; j++ )
{
rom[ i + j ] = buffer[ j ^ 2 ];
}
}
}
}

static void neoPCM2rotd(void)// Neo-PCM2 sound emulation info
{
data16_t *rom;
int i,j;

/* thanks to Elsemi for the NEO-PCM2 info */
rom = (data16_t *)(memory_region(REGION_SOUND1));
if( rom != NULL )
{
/* swap address lines on the whole ROMs */
for( i = 0; i < 0x1000000 / 2; i += 16 / 2 )
{
data16_t buffer[ 16 / 2 ];
memcpy( buffer, &rom[ i ], 16 );
for( j = 0; j < 16 / 2; j++ )
{
rom[ i + j ] = buffer[ j ^ 4 ];
}
}
}
}
/* ------------------------------------------------------------------------------------------------------------------ */

// handlers for 68000k
static void kof2002_decrypt(void)
{
UINT8 *src = memory_region(REGION_CPU1)+0x100000;
UINT8 *dst = malloc(0x400000);
int i;
unsigned int sec[]={0x100000,0x280000,0x300000,0x180000,0x000000,0x380000,0x200000,0x080000};

if (dst)
{
memcpy(dst,src,0x400000);

for(i=0;i<8;++i)
{
memcpy(src+i*0x80000,dst+sec[i],0x80000);
}
free(dst);
}
}

static void samsho5_decrypt(void)
{
UINT8 *src = memory_region(REGION_CPU1);
UINT8 *dst = malloc(0x800000);
int i;
unsigned int sec[]={0x000000,0x080000,0x700000,0x680000,0x500000,0x180000,0x200000,0x480000,0x300000,0x780000,0x600000,0x280000,0x100000,0x580000,0x400000,0x380000};

if (dst)
{
memcpy(dst,src,0x800000);
for(i=0;i<16;++i)
{
memcpy(src+i*0x80000,dst+sec[i],0x80000);
}
free(dst);
}
}

static void kof2003b_decrypt(void)
{
/* Descrambling Px by X-or */
int i;
unsigned int sec[]={0x700000,0x000000,0x100000,0x200000,0x300000,0x400000,0x500000};
UINT8 *prom = memory_region(REGION_CPU1);
UINT8 *dst1 = malloc(0x800000);
if (dst1)
{
memcpy( dst1, prom, 0x800000 );
for( i=0; i<8; ++i )
{
memcpy( prom+i*0x100000, dst1+sec[i], 0x100000 );
}
free(dst1);
}
}

// Bankswitches
int ms5_bank_offset = 0;
static WRITE16_HANDLER( mslug5_calc_bankoffset_w )
{
        ms5_bank_offset = (data>>12)%0x03;
}

static WRITE16_HANDLER( mslug5_bankswitch_w )
{
        neogeo_set_cpu1_second_bank( (neogeo_ram16[0x10/2] + ms5_bank_offset) << 20 );
}
/* ------------------------------------------------------------------------------------------------------------------ */

// Text layer handlers
static void kof2003b_text_fix(void)
{
UINT8 *dst = malloc(0x20000);
        UINT8 *roms1 = (memory_region(REGION_GFX1));
        int j;
        if ( dst )
        {
                memcpy(dst,roms1,0x20000);
                // descrambling the S1 by dorriGa
                for (j=0;j<0x20000 ; j+=0x000010)
                {
                        memcpy( roms1+j, dst+j+0x000008,8);
                        memcpy( roms1+j+0x000008, dst+j,8);
                      
                }
        }
        free( dst );
}

static void kof2k3ba_text_fix(void)
{
/* Descrambling S1 by dorriga */
UINT8 *srom = memory_region(REGION_GFX1);
UINT8 *dst2 = (UINT8*)malloc(0x80000);
memcpy( dst2+0x00000, srom+0x60000, 0x20000 );
memcpy( dst2+0x20000, srom+0x40000, 0x20000 );
memcpy( dst2+0x40000, srom+0x20000, 0x20000 );
memcpy( dst2+0x60000, srom+0x00000, 0x20000 );
memcpy( srom, dst2, 0x80000 );
free(dst2);
}

void init_sfixdec(void)
{
neogeo_sfix_decrypt();
init_neogeo();
}

static void text_layer_render(void)
{
int i;
extern int neogeo_fix_bank_type;
int tx_size = memory_region_length(REGION_GFX1);
int rom_size = memory_region_length(REGION_GFX3);
UINT8 *src = memory_region(REGION_GFX3)+rom_size-tx_size;
UINT8 *dst = memory_region(REGION_GFX1);

for (i = 0;i < tx_size;i++)
dst [ i ] = src[(i & ~0x1f) + ((i & 7) << 2) + ((~i & 8) >> 2) + ((i & 0x10) >> 4)];
}
/* ======================================(end of NOSG)================================================== */
and delete all duplicated functions in the driver inits that uses them... now you can use an init like this:

DRIVER_INIT( kof2k3ba )
{
kof2k3ba_text_fix();
kof2003b_decrypt();
neogeo_fix_bank_type = 2;
init_neogeo();
}

or like this one:

DRIVER_INIT( ms4plus )// Using encrypted roms
{
neoPCM2ms4();
neogeo_gfx_decrypt = 2
init_neogeo();
}

or:

DRIVER_INIT( rotdnd )
{
neoPCM2rotd();
text_layer_render();
neogeo_fix_bank_type = 1
init_neogeo();
}

I hope this will help you, this callback can be combined however you want.
See ya!!!!! :D
P.D. dont use sfixdec function in the drivers... use it in the init column in the driver name, parent and stuff like that section.
« Last Edit: May 10, 2005, 01:15:59 PM by iq_132 »

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

  • FBA Dev
  • ******
  • Posts: 375
  • Karma: +7/-0
  • FB Alpha Team ;)
    • FB Alpha Plus! Web Site
Some shortcuts for MAME32 PLus!
« Reply #1 on: November 30, 2004, 01:47:13 AM »
NeoPCM2 PLAYMORE for mame... my version XD, like the skn 1999 one posted by IQ_132
Code: [Select]
// © PLAYMORE 2002
/* Analyzed & original code by vconv (from 2ch) */
static void neo_pcm2_playmore_2002(int value)
{
        const unsigned char *PCM2_xor;
const unsigned char kof2002_xor[0x08] = {0xf9,0xe0,0x5d,0xf3,0xea,0x92,0xbe,0xef};
const unsigned char matrim_xor[0x08] = {0xc4,0x83,0xa8,0x5f,0x21,0x27,0x64,0xaf};
const unsigned char ms5_xor[0x08] = {0xc3,0xfd,0x81,0xac,0x6d,0xe7,0xbf,0x9e};
const unsigned char ss5_xor[0x08] = {0xcb,0x29,0x7d,0x43,0xd2,0x3a,0xc2,0xb4};
const unsigned char ss5sp_xor[0x08] = {0x4b,0xa4,0x63,0x46,0xf0,0x91,0xea,0x62};

int v_size = memory_region_length( REGION_SOUND1 );
UINT8 *rom = memory_region( REGION_SOUND1 );;
UINT8 *buf = malloc( v_size );
int ofst;

memcpy( buf, rom, v_size );

for( int i = 0; i < v_size; i++ ){
ofst = (i & 0xfefffe) | ((i & 0x010000) >> 16) | ((i & 0x000001) << 16);

// for kof2002
if (value == 1) {
PCM2_xor = kof2002_xor;
ofst ^= 0xa5000;
rom[ ofst ] = buf[ (i & 0xffffff) ] ^ PCM2_xor[ (ofst & 0x07) ];
}
// for matrim
if (value == 2) {
PCM2_xor = matrim_xor;
ofst ^= 0x01000;
rom[ ofst ] = buf[ ((i + 0xffce20) & 0xffffff) ] ^ PCM2_xor[ (ofst & 0x07) ];
}
// for mslug5
if (value == 3) {
PCM2_xor = ms5_xor;
ofst ^= 0x4e001;
rom[ ofst ] = buf[ ((i + 0xfe2cf6) & 0xffffff) ] ^ PCM2_xor[ (ofst & 0x07) ];
}
// for svcchaos
if (value == 4) {
PCM2_xor = ms5_xor;
ofst ^= 0xc2000;
rom[ ofst ] = buf[ ((i + 0xffac28) & 0xffffff) ] ^ PCM2_xor[ (ofst & 0x07) ];
}
// for samsho5
if (value == 5) {
PCM2_xor = ss5_xor;
ofst ^= 0x0a000;
rom[ ofst ] = buf[ ((i + 0xfeb2c0) & 0xffffff) ] ^ PCM2_xor[ (ofst & 0x07) ];
}
// for samsh5sp
if (value == 6) {
PCM2_xor = ss5sp_xor;
ofst ^= 0x02000;
rom[ ofst ] = buf[ ((i + 0xffb440) & 0xffffff) ] ^ PCM2_xor[ (ofst & 0x07) ];
}
}
free( buf );
}
dont forget to link on your driver init like this:
Code: [Select]
DRIVER_INIT( kof2002 )
{
          ...
          neo_pcm2_playmore_2002(1);
          init_neogeo();
}
change the value depending of the game
See ya!!!! :D
« Last Edit: May 10, 2005, 01:16:18 PM by iq_132 »

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 fataku

  • Newbies
  • *
  • Posts: 22
  • Karma: +0/-0
  • Junior Member
Some shortcuts for MAME32 PLus!
« Reply #2 on: November 30, 2004, 02:00:53 AM »
i dont understand why you change the original code, even if you didnt put a little of your part... anyway this is my version of the code

Code: [Select]
// © SNK 1999
/* thanks to Elsemi for the NEO-PCM2 info */
static void neo_pcm2_snk_1999(int value)
{
//rotd, mslug4, pnyaa
data16_t *rom = (data16_t *)memory_region(REGION_SOUND1);
int size = memory_region_length(REGION_SOUND1);
int i, j;

if( rom != NULL )
{
// swap address lines on the whole ROMs /
for( i = 0; i < size / 2; i += ( value / 2 ) ){
data16_t buffer[ (value / 2) ];
memcpy( buffer, &rom[ i ], value );
for( j = 0; j < (value / 2); j++ ){
rom[ i + j ] = buffer[ j ^ (value/4) ];
}
}
}
}

// © PLAYMORE 2002 20-09-2004
static void neo_pcm2_playmore_2002(int value)
{
        //kof2002,matrimelee,mslug5 (pcb and mvs),samsho5,svcchaos (pcb and mvs),kof2003 (pcb and mvs),samsh5sp (mvs and aes)
        //offset,xor address
        unsigned int addrs[7][2]={
                 {0x000000,0xA5000}, //kof2002
                 {0xFFCE20,0x01000}, //matrimelee
                 {0xFE2CF6,0x4E001}, //mslug5
                 {0xFEB2C0,0x0A000}, //samsho5
                 {0xFFAC28,0xC2000}, //svcchaos
                 {0x000000,0x00000}, //kof2003
                 {0xFFB440,0x02000}, //samsh5sp
                 };
        unsigned int xordata[7][8]={
                 {0xF9,0xE0,0x5D,0xF3,0xEA,0x92,0xBE,0xEF}, //kof2002
                 {0xC4,0x83,0xA8,0x5F,0x21,0x27,0x64,0xAF}, //matrimelee
                 {0xC3,0xFD,0x81,0xAC,0x6D,0xE7,0xBF,0x9E}, //mslug5
                 {0xCB,0x29,0x7D,0x43,0xD2,0x3A,0xC2,0xB4}, //samsho5
                 {0xC3,0xFD,0x81,0xAC,0x6D,0xE7,0xBF,0x9E}, //svcchaos
                 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, //kof2003
                 {0x4B,0xA4,0x63,0x46,0xF0,0x91,0xEA,0x62}, //samsh5sp
                 };

UINT8 *src = memory_region(REGION_SOUND1);
UINT8 *buf = malloc(0x1000000);
int i, j, d;

        memcpy(buf,src,0x1000000);
        for (i=0;i<0x1000000;i++){
            j=BITSWAP24(i,23,22,21,20,19,18,17,0,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,16);
            j=j^addrs[value][1];
            d=((i+addrs[value][0])&0xffffff);
            src[j]=buf[d]^xordata[value][j&0x7];
        }
        free(buf);
}
kof2003 was disabled because the dumper doesnt wanna make it public, anyway thats a shame.
« Last Edit: May 10, 2005, 01:16:32 PM by iq_132 »

Online iq_132

  • Administrator
  • *****
  • Posts: 3612
  • Karma: +385/-0
  • Bare Knuckle!
    • NeoSource
Some shortcuts for MAME32 PLus!
« Reply #3 on: November 30, 2004, 02:17:31 AM »
Wow! Thanks fataku :)


Offline James33

  • Expert
  • *****
  • Posts: 532
  • Karma: +3/-0
  • The Mame Man
    • Emulation Zone
Some shortcuts for MAME32 PLus!
« Reply #4 on: November 30, 2004, 04:36:22 AM »
I am not 100% sure how to use fataku's code :(
IQ Forum Member

Online iq_132

  • Administrator
  • *****
  • Posts: 3612
  • Karma: +385/-0
  • Bare Knuckle!
    • NeoSource
Some shortcuts for MAME32 PLus!
« Reply #5 on: November 30, 2004, 04:56:43 AM »
neo_pcm2_playmore_2002(0); // kof2002
neo_pcm2_playmore_2002(1); // Matrimelee
neo_pcm2_playmore_2002(2); // Mslug5
...


Offline James33

  • Expert
  • *****
  • Posts: 532
  • Karma: +3/-0
  • The Mame Man
    • Emulation Zone
Some shortcuts for MAME32 PLus!
« Reply #6 on: November 30, 2004, 06:01:08 AM »
Ok thanks I get it now :)
IQ Forum Member

Offline X-or

  • Newbies
  • *
  • Posts: 38
  • Karma: +0/-0
Some shortcuts for MAME32 PLus!
« Reply #7 on: December 18, 2004, 10:03:47 AM »
Quote from: fataku
kof2003 was disabled because the dumper doesnt wanna make it public, anyway thats a shame.


I think kof2003 pcm2v2 code is public by now

Offline James33

  • Expert
  • *****
  • Posts: 532
  • Karma: +3/-0
  • The Mame Man
    • Emulation Zone
Some shortcuts for MAME32 PLus!
« Reply #8 on: December 18, 2004, 11:24:00 AM »
Yes

Code: [Select]

// © PLAYMORE 2002 20-09-2004
static void neo_pcm2_playmore_2002(int value)
{
        //kof2002,matrimelee,mslug5 (pcb and mvs),samsho5,svcchaos (pcb and mvs),kof2003 (pcb and mvs),samsh5sp (mvs and aes)
        //offset,xor address
        unsigned int addrs[7][2]={
                 {0x000000,0xA5000}, //kof2002
                 {0xFFCE20,0x01000}, //matrimelee
                 {0xFE2CF6,0x4E001}, //mslug5
                 {0xFEB2C0,0x0A000}, //samsho5
                 {0xFFAC28,0xC2000}, //svcchaos
                 {0xFF14EA,0xA7001}, //kof2003
                 {0xFFB440,0x02000}, //samsh5sp
                 };
        unsigned int xordata[7][8]={
                 {0xF9,0xE0,0x5D,0xF3,0xEA,0x92,0xBE,0xEF}, //kof2002
                 {0xC4,0x83,0xA8,0x5F,0x21,0x27,0x64,0xAF}, //matrimelee
                 {0xC3,0xFD,0x81,0xAC,0x6D,0xE7,0xBF,0x9E}, //mslug5
                 {0xCB,0x29,0x7D,0x43,0xD2,0x3A,0xC2,0xB4}, //samsho5
                 {0xC3,0xFD,0x81,0xAC,0x6D,0xE7,0xBF,0x9E}, //svcchaos
                 {0x4B,0xA4,0x63,0x46,0xF0,0x91,0xEA,0x62}, //kof2003
                 {0x4B,0xA4,0x63,0x46,0xF0,0x91,0xEA,0x62}, //samsh5sp
                 };

UINT8 *src = memory_region(REGION_SOUND1);
UINT8 *buf = malloc(0x1000000);
int i, j, d;

        memcpy(buf,src,0x1000000);
        for (i=0;i<0x1000000;i++){
            j=BITSWAP24(i,23,22,21,20,19,18,17,0,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,16);
            j=j^addrs[value][1];
            d=((i+addrs[value][0])&0xffffff);
            src[j]=buf[d]^xordata[value][j&0x7];
        }
        free(buf);
}
IQ Forum Member

Offline X-or

  • Newbies
  • *
  • Posts: 38
  • Karma: +0/-0
enjoy
« Reply #9 on: January 07, 2005, 04:28:53 AM »
Code: [Select]
/******************/
/* neo-descambler */
/******************/
// original code by X-or

static void neo_desc(int n)
{
unsigned int length[5][3]=
{
{0x100000,0x400000,0x080000}, //kof2002,matrim
{0x100000,0x400000,0x100000}, //kof02se
{0x000000,0x800000,0x080000}, //samsho5
{0x000000,0x000000,0x000000}, //kof2003b
{0x000000,0x800000,0x080000}, //samsh5sp
};

unsigned int matrix[5][16]=
{
{0x02,0x05,0x06,0x03,0x00,0x07,0x04,0x01}, //kof2002,matrim
{0x03,0x02,0x01,0x00}, //kof02se
{0x00,0x01,0x0e,0x0d,0x0a,0x03,0x04,0x09,0x06,0x0f,0x0c,0x05,0x02,0x0b,0x08,0x07}, //samsho5
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, //kof2003b
{0x00,0x01,0x0a,0x09,0x0c,0x0b,0x0e,0x05,0x02,0x0d,0x08,0x0f,0x04,0x07,0x06,0x03}, //samsh5sp
};

UINT8 *src = memory_region(REGION_CPU1)+length[n][0];
UINT8 *dst = malloc(length[n][1]);
int i;
if (dst)
{
memcpy(dst,src,length[n][1]);
for(i=0;i<length[n][1]/length[n][2];i++)
{
memcpy(src+i*length[n][2],dst+matrix[n][i]*length[n][2],length[n][2]);
}
free(dst);
}
}

PS:
thanks to fataku who helped me to fix a matrix pointer warning :)
kof02se = kof special edition 2004
kob2003b is nuked for now altho it could use the neo-descrambler, there's a faster way to load the rom
« Last Edit: May 10, 2005, 01:16:58 PM by iq_132 »