diff --git a/src/mame/audio/cps3.c b/src/mame/audio/cps3.c index 7f3fefb1b0f..065d334b6fe 100644 --- a/src/mame/audio/cps3.c +++ b/src/mame/audio/cps3.c @@ -10,6 +10,7 @@ #define CPS3_VOICES 16 static sound_stream *cps3_stream; +extern UINT8* cps3_user5region; typedef struct _cps3_voice_ { @@ -22,12 +23,12 @@ static struct { cps3_voice voice[CPS3_VOICES]; UINT16 key; + INT8* base; } chip; static STREAM_UPDATE( cps3_stream_update ) { int i; - INT8 *base = (INT8*)memory_region(device->machine, "user5"); /* Clear the buffers */ memset(outputs[0], 0, samples*sizeof(*outputs[0])); @@ -82,7 +83,7 @@ static STREAM_UPDATE( cps3_stream_update ) } } - sample = base[BYTE4_XOR_LE(start + pos)]; + sample = chip.base[BYTE4_XOR_LE(start + pos)]; frac += step; outputs[0][j] += (sample * (vol_l >> 8)); @@ -103,6 +104,8 @@ CUSTOM_START( cps3_sh_start ) memset(&chip, 0, sizeof(chip)); + chip.base = (INT8*)cps3_user5region; + return auto_malloc(1); } diff --git a/src/mame/drivers/cps3.c b/src/mame/drivers/cps3.c index 1e061f41c7a..ffd4eb5149c 100644 --- a/src/mame/drivers/cps3.c +++ b/src/mame/drivers/cps3.c @@ -326,10 +326,14 @@ Notes: #include "includes/cps3.h" #include "machine/wd33c93.h" +#define MASTER_CLOCK 42954500 + /* load extracted cd content? */ #define LOAD_CD_CONTENT 1 #define DEBUG_PRINTF 0 + + #define DMA_XOR(a) ((a) ^ NATIVE_ENDIAN_VALUE_LE_BE(1,2)) @@ -366,6 +370,10 @@ static UINT32* cps3_mame_colours;//[0x20000]; // actual values to write to 32-bi static bitmap_t *renderbuffer_bitmap; static rectangle renderbuffer_clip; +static UINT8* cps3_user4region; +UINT8* cps3_user5region; +#define USER4REGION_LENGTH 0x800000*2 +#define USER5REGION_LENGTH 0x800000*10 #define CPS3_TRANSPARENCY_NONE 0 #define CPS3_TRANSPARENCY_PEN 1 @@ -642,40 +650,6 @@ static UINT32 cps3_mask(UINT32 address, UINT32 key1, UINT32 key2) return val | (val << 16); } -struct game_keys2 -{ - const char *name; /* game driver name */ - const UINT32 keys[2]; - int isSpecial; -}; - -static const struct game_keys2 keys_table2[] = -{ - // name key1 key2 - { "jojo", { 0x02203ee3, 0x01301972 },0 }, - { "jojon", { 0x02203ee3, 0x01301972 },0 }, - { "jojoalt", { 0x02203ee3, 0x01301972 },0 }, - { "jojoaltn", { 0x02203ee3, 0x01301972 },0 }, - { "jojoba", { 0x23323ee3, 0x03021972 },0 }, - { "jojoban", { 0x23323ee3, 0x03021972 },0 }, - { "jojobane", { 0x23323ee3, 0x03021972 },0 }, - { "sfiii", { 0xb5fe053e, 0xfc03925a },0 }, - { "sfiiiu", { 0xb5fe053e, 0xfc03925a },0 }, - { "sfiiij", { 0xb5fe053e, 0xfc03925a },0 }, - { "sfiiin", { 0xb5fe053e, 0xfc03925a },0 }, - { "sfiii2", { 0x00000000, 0x00000000 },1 }, - { "sfiii2u", { 0x00000000, 0x00000000 },1 }, - { "sfiii2j", { 0x00000000, 0x00000000 },1 }, - { "sfiii2n", { 0x00000000, 0x00000000 },1 }, - { "sfiii3", { 0xa55432b4, 0x0c129981 },0 }, - { "sfiii3n", { 0xa55432b4, 0x0c129981 },0 }, - { "sfiii3a", { 0xa55432b4, 0x0c129981 },0 }, - { "sfiii3an", { 0xa55432b4, 0x0c129981 },0 }, - { "warzard", { 0x9e300ab1, 0xa175b82c },0 }, - { "redearth", { 0x9e300ab1, 0xa175b82c },0 }, - { 0 } // end of table -}; - static void cps3_decrypt_bios(running_machine *machine) { int i; @@ -687,16 +661,7 @@ static void cps3_decrypt_bios(running_machine *machine) { UINT32 dword = coderegion[i/4]; UINT32 xormask = cps3_mask(i, cps3_key1, cps3_key2); - - /* a bit of a hack, don't decrypt the FLASH commands which are transfered by SH2 DMA */ -// if (((i<0x1ff00) || (i>0x1ff6b)) && (i<0x20000) ) -// { - decrypted_bios[i/4] = dword ^ xormask; -// } -// else -// { -// decrypted_bios[i/4] = dword; -// } + decrypted_bios[i/4] = dword ^ xormask; } #if 0 /* Dump to file */ @@ -716,32 +681,21 @@ static void cps3_decrypt_bios(running_machine *machine) #endif } + static DRIVER_INIT( cps3 ) { - const char *gamename = machine->gamedrv->name; - const struct game_keys2 *k = &keys_table2[0]; int i; + + // cache pointers to regions + cps3_user4region = memory_region(machine,"user4"); + cps3_user5region = memory_region(machine,"user5"); + if (!cps3_user4region) cps3_user4region = auto_malloc(USER4REGION_LENGTH); + if (!cps3_user5region) cps3_user5region = auto_malloc(USER5REGION_LENGTH); + // set strict verify device_set_info_int(machine->cpu[0], CPUINFO_INT_SH2_DRC_OPTIONS, SH2DRC_STRICT_VERIFY); - cps3_key1 = -1; - cps3_key2 = -1; - cps3_altEncryption = -1; - - while (k->name) - { - if (strcmp(k->name, gamename) == 0) - { - // we have a proper key set the global variables to it (so that we can decrypt code in ram etc.) - cps3_key1 = k->keys[0]; - cps3_key2 = k->keys[1]; - cps3_altEncryption = k->isSpecial; - break; - } - ++k; - } - cps3_decrypt_bios(machine); decrypted_gamerom = auto_malloc(0x1000000); @@ -760,11 +714,16 @@ static DRIVER_INIT( cps3 ) intelflash_init( machine, i, FLASH_FUJITSU_29F016A, NULL ); cps3_eeprom = auto_malloc(0x400); - - - } +static DRIVER_INIT( jojo ) { cps3_key1 = 0x02203ee3; cps3_key2 = 0x01301972; cps3_altEncryption = 0; DRIVER_INIT_CALL(cps3); } +static DRIVER_INIT( jojoba ) { cps3_key1 = 0x23323ee3; cps3_key2 = 0x03021972; cps3_altEncryption = 0; DRIVER_INIT_CALL(cps3); } +static DRIVER_INIT( sfiii ) { cps3_key1 = 0xb5fe053e; cps3_key2 = 0xfc03925a; cps3_altEncryption = 0; DRIVER_INIT_CALL(cps3); } +static DRIVER_INIT( sfiii2 ) { cps3_key1 = 0x00000000; cps3_key2 = 0x00000000; cps3_altEncryption = 1; DRIVER_INIT_CALL(cps3); } +static DRIVER_INIT( sfiii3 ) { cps3_key1 = 0xa55432b4; cps3_key2 = 0x0c129981; cps3_altEncryption = 0; DRIVER_INIT_CALL(cps3); } +static DRIVER_INIT( redearth ){ cps3_key1 = 0x9e300ab1; cps3_key2 = 0xa175b82c; cps3_altEncryption = 0; DRIVER_INIT_CALL(cps3); } + + /* GFX decodes */ @@ -1320,7 +1279,7 @@ static DIRECT_UPDATE_HANDLER( cps3_direct_handler ) direct->decrypted = (UINT8*)decrypted_gamerom-0x06000000; direct->raw = (UINT8*)decrypted_gamerom-0x06000000; - if (cps3_altEncryption) direct->raw = (UINT8*) memory_region(space->machine, "user4")-0x06000000; + if (cps3_altEncryption) direct->raw = (UINT8*) cps3_user4region-0x06000000; return ~0; @@ -1467,7 +1426,7 @@ static WRITE32_HANDLER( cps3_gfxflash_w ) /* make a copy in the linear memory region we actually use for drawing etc. having it stored in interleaved flash roms isnt' very useful */ { - UINT32* romdata = (UINT32*)memory_region(space->machine, "user5"); + UINT32* romdata = (UINT32*)cps3_user5region; int real_offset = 0; UINT32 newdata; UINT8* ptr1 = intelflash_getmemptr(flash1); @@ -1569,7 +1528,7 @@ static void cps3_flashmain_w(running_machine *machine, int base, UINT32 offset, /* copy data into regions to execute from */ { - UINT32* romdata = (UINT32*)memory_region(machine, "user4"); + UINT32* romdata = (UINT32*)cps3_user4region; UINT32* romdata2 = (UINT32*)decrypted_gamerom; int real_offset = 0; UINT32 newdata; @@ -1834,7 +1793,7 @@ static WRITE32_HANDLER( cps3_palettedma_w ) if (data & 0x0002) { int i; - UINT16* src = (UINT16*)memory_region(space->machine, "user5"); + UINT16* src = (UINT16*)cps3_user5region; // if(DEBUG_PRINTF) printf("CPS3 pal dma start %08x (real: %08x) dest %08x fade %08x other2 %08x (length %04x)\n", paldma_source, paldma_realsource, paldma_dest, paldma_fade, paldma_other2, paldma_length); for (i=0;i