MACHINE_DRIVER_END static DRIVER_INIT(pesadelo) { int i; UINT8 *mem = memory_region(machine, "maincpu"); int memsize = memory_region_length(machine, "maincpu"); UINT8 *buf; // data swap for ( i = 0; i < memsize; i++ ) { mem[i] = BITSWAP8(mem[i],3,5,6,7,0,4,2,1); } // address line swap buf = alloc_array_or_die(UINT8, memsize); memcpy(buf, mem, memsize); for ( i = 0; i < memsize; i++ ) { mem[BITSWAP16(i,11,9,8,13,14,15,12,7,6,5,4,3,2,1,0,10)] = buf[i]; } free(buf); }
ROM_END static DRIVER_INIT( wink ) { UINT32 i; UINT8 *ROM = memory_region(machine, "maincpu"); UINT8 *buffer = alloc_array_or_die(UINT8, 0x8000); // protection module reverse engineered by HIGHWAYMAN memcpy(buffer,ROM,0x8000); for (i = 0x0000; i <= 0x1fff; i++) ROM[i] = buffer[BITSWAP16(i,15,14,13, 11,12, 7, 9, 8,10, 6, 4, 5, 1, 2, 3, 0)]; for (i = 0x2000; i <= 0x3fff; i++) ROM[i] = buffer[BITSWAP16(i,15,14,13, 10, 7,12, 9, 8,11, 6, 3, 1, 5, 2, 4, 0)]; for (i = 0x4000; i <= 0x5fff; i++) ROM[i] = buffer[BITSWAP16(i,15,14,13, 7,10,11, 9, 8,12, 6, 1, 3, 4, 2, 5, 0)]; for (i = 0x6000; i <= 0x7fff; i++) ROM[i] = buffer[BITSWAP16(i,15,14,13, 11,12, 7, 9, 8,10, 6, 4, 5, 1, 2, 3, 0)]; free(buffer); for (i = 0; i < 0x8000; i++) ROM[i] += BITSWAP8(i & 0xff, 7,5,3,1,6,4,2,0); }
void deco156_decrypt(running_machine *machine) { UINT32 *rom = (UINT32 *)memory_region(machine, "maincpu"); int length = memory_region_length(machine, "maincpu"); UINT32 *buf = alloc_array_or_die(UINT32, length/4); memcpy(buf, rom, length); decrypt(buf, rom, length); free(buf); }
ROM_END static DRIVER_INIT( motorace ) { int A,j; UINT8 *rom = memory_region(machine, "maincpu"); UINT8 *buffer = alloc_array_or_die(UINT8, 0x2000); memcpy(buffer,rom,0x2000); /* The first CPU ROM has the address and data lines scrambled */ for (A = 0;A < 0x2000;A++) { j = BITSWAP16(A,15,14,13,9,7,5,3,1,12,10,8,6,4,2,0,11); rom[j] = BITSWAP8(buffer[A],2,7,4,1,6,3,0,5); } free(buffer); }
ROM_END #define ROL(x,n) (BITSWAP8((x),(7+8-n)&7,(6+8-n)&7,(5+8-n)&7,(4+8-n)&7,(3+8-n)&7,(2+8-n)&7,(1+8-n)&7,(0+8-n)&7)) #define WRITEDEST( n ) \ dest[idx]=n; \ dest[idx+0x10000]=(n)^0xff; \ idx++; static DRIVER_INIT(tcl) { /* only the first part is decrypted (and verified)*/ const address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM); UINT8 *dest = memory_region(machine, "maincpu"); int len = memory_region_length(machine, "maincpu"); UINT8 *src = alloc_array_or_die(UINT8, len); int i,idx=0; memcpy(src, dest, len); for(i=0;i<64*1024;i+=4) { if(i&0x8000) { WRITEDEST(ROL(src[idx]^0x44,4)); // abcdefgh -> aFghaBcd WRITEDEST(ROL(src[idx]^0x44,7)); // abcdefgh -> haBcdeFg WRITEDEST(ROL(src[idx]^0x44,2)); // abcdefgh -> cdeFghaB WRITEDEST((src[idx]^0x44)^0xf0); // abcdefgh -> AbCEeFgh } else { WRITEDEST(ROL(src[idx]^0x11,4)); // abcdefgh -> efgHabcD WRITEDEST(ROL(src[idx]^0x11,7)); // abcdefgh -> HabcDefg WRITEDEST(ROL(src[idx]^0x11,2)); // abcdefgh -> cDefgHab WRITEDEST((src[idx]^0x11)^0xf0); // abcdefgh -> ABCdefgH } } free(src); memory_set_decrypted_region(space, 0x0000, 0x7fff, dest+0x10000); }
ROM_END static DRIVER_INIT( panicr ) { UINT8 *buf = alloc_array_or_die(UINT8, 0x80000); UINT8 *rom; int size; int i; rom = memory_region(machine, "gfx1"); size = memory_region_length(machine, "gfx1"); // text data lines for (i = 0; i < size/2; i++) { int w1; w1 = (rom[i + 0*size/2] << 8) + rom[i + 1*size/2]; w1 = BITSWAP16(w1, 9,12,7,3, 8,13,6,2, 11,14,1,5, 10,15,4,0); buf[i + 0*size/2] = w1 >> 8; buf[i + 1*size/2] = w1 & 0xff; } // text address lines for (i = 0; i < size; i++) { rom[i] = buf[BITSWAP24(i,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6, 2,3,1,0,5,4)]; } rom = memory_region(machine, "gfx2"); size = memory_region_length(machine, "gfx2"); // tiles data lines for (i = 0; i < size/4; i++) { int w1,w2; w1 = (rom[i + 0*size/4] << 8) + rom[i + 3*size/4]; w2 = (rom[i + 1*size/4] << 8) + rom[i + 2*size/4]; w1 = BITSWAP16(w1, 14,12,11,9, 3,2,1,0, 10,15,13,8, 7,6,5,4); w2 = BITSWAP16(w2, 3,13,15,4, 12,2,5,11, 14,6,1,10, 8,7,9,0); buf[i + 0*size/4] = w1 >> 8; buf[i + 1*size/4] = w1 & 0xff; buf[i + 2*size/4] = w2 >> 8; buf[i + 3*size/4] = w2 & 0xff; } // tiles address lines for (i = 0; i < size; i++) { rom[i] = buf[BITSWAP24(i,23,22,21,20,19,18,17,16,15,14,13,12, 5,4,3,2, 11,10,9,8,7,6, 0,1)]; } rom = memory_region(machine, "gfx3"); size = memory_region_length(machine, "gfx3"); // sprites data lines for (i = 0; i < size/2; i++) { int w1; w1 = (rom[i + 0*size/2] << 8) + rom[i + 1*size/2]; w1 = BITSWAP16(w1, 11,5,7,12, 4,10,13,3, 6,14,9,2, 0,15,1,8); buf[i + 0*size/2] = w1 >> 8; buf[i + 1*size/2] = w1 & 0xff; } // sprites address lines for (i = 0; i < size; i++) { rom[i] = buf[i]; } //rearrange bg tilemaps a bit.... rom = memory_region(machine, "user1"); size = memory_region_length(machine, "user1"); memcpy(buf,rom, size); { int j; for(j=0; j<16; j++) for (i = 0; i < size/16; i+=8) { memcpy(&rom[i+(size/16)*j],&buf[i*16+8*j],8); } } rom = memory_region(machine, "user2"); size = memory_region_length(machine, "user2"); memcpy(buf,rom, size); { int j; for(j=0; j<16; j++) for (i = 0; i < size/16; i+=8) { memcpy(&rom[i+(size/16)*j],&buf[i*16+8*j],8); } } free(buf); }
static DRIVER_INIT(darkmist) { const address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM); int i, len; UINT8 *ROM = memory_region(machine, "maincpu"); UINT8 *buffer = alloc_array_or_die(UINT8, 0x10000); UINT8 *decrypt = auto_alloc_array(machine, UINT8, 0x8000); decrypt_gfx(machine); decrypt_snd(machine); for(i=0;i<0x8000;i++) { UINT8 p, d; p = d = ROM[i]; if(((i & 0x20) == 0x00) && ((i & 0x8) != 0)) p ^= 0x20; if(((i & 0x20) == 0x00) && ((i & 0xa) != 0)) d ^= 0x20; if(((i & 0x200) == 0x200) && ((i & 0x408) != 0)) p ^= 0x10; if((i & 0x220) != 0x200) { p = BITSWAP8(p, 7,6,5,2,3,4,1,0); d = BITSWAP8(d, 7,6,5,2,3,4,1,0); } ROM[i] = d; decrypt[i] = p; } memory_set_decrypted_region(space, 0x0000, 0x7fff, decrypt); memory_set_bankptr(space->machine, 1,&ROM[0x010000]); /* adr line swaps */ ROM = memory_region(machine, "user1"); len = memory_region_length(machine, "user1"); memcpy( buffer, ROM, len ); for(i=0;i<len;i++) { ROM[i]=buffer[BITSWAP24(i,23,22,21,20,19,18,17,16,15,6,5,4,3,2,14,13,12,11,8,7,1,0,10,9)]; } ROM = memory_region(machine, "user2"); len = memory_region_length(machine, "user2"); memcpy( buffer, ROM, len ); for(i=0;i<len;i++) { ROM[i]=buffer[BITSWAP24(i,23,22,21,20,19,18,17,16,15,6,5,4,3,2,14,13,12,11,8,7,1,0,10,9)]; } ROM = memory_region(machine, "user3"); len = memory_region_length(machine, "user3"); memcpy( buffer, ROM, len ); for(i=0;i<len;i++) { ROM[i]=buffer[BITSWAP24(i,23,22,21,20,19,18,17,16,15,14 ,5,4,3,2,11,10,9,8,13,12,1,0,7,6)]; } ROM = memory_region(machine, "user4"); len = memory_region_length(machine, "user4"); memcpy( buffer, ROM, len ); for(i=0;i<len;i++) { ROM[i]=buffer[BITSWAP24(i,23,22,21,20,19,18,17,16,15,14 ,5,4,3,2,11,10,9,8,13,12,1,0,7,6)]; } free(buffer); }
ROM_END static void decrypt_gfx(running_machine *machine) { UINT8 *buf = alloc_array_or_die(UINT8, 0x40000); UINT8 *rom; int size; int i; rom = memory_region(machine, "gfx1"); size = memory_region_length(machine, "gfx1"); /* data lines */ for (i = 0;i < size/2;i++) { int w1; w1 = (rom[i + 0*size/2] << 8) + rom[i + 1*size/2]; w1 = BITSWAP16(w1, 9,14,7,2, 6,8,3,15, 10,13,5,12, 0,11,4,1); buf[i + 0*size/2] = w1 >> 8; buf[i + 1*size/2] = w1 & 0xff; } /* address lines */ for (i = 0;i < size;i++) { rom[i] = buf[BITSWAP24(i,23,22,21,20,19,18,17,16,15,14,13,12, 3,2,1, 11,10,9,8, 0, 7,6,5,4)]; } rom = memory_region(machine, "gfx2"); size = memory_region_length(machine, "gfx2"); /* data lines */ for (i = 0;i < size/2;i++) { int w1; w1 = (rom[i + 0*size/2] << 8) + rom[i + 1*size/2]; w1 = BITSWAP16(w1, 9,14,7,2, 6,8,3,15, 10,13,5,12, 0,11,4,1); buf[i + 0*size/2] = w1 >> 8; buf[i + 1*size/2] = w1 & 0xff; } /* address lines */ for (i = 0;i < size;i++) { rom[i] = buf[BITSWAP24(i,23,22,21,20,19,18,17,16,15,14,13, 5,4,3,2, 12,11,10,9,8, 1,0, 7,6)]; } rom = memory_region(machine, "gfx3"); size = memory_region_length(machine, "gfx3"); /* data lines */ for (i = 0;i < size/2;i++) { int w1; w1 = (rom[i + 0*size/2] << 8) + rom[i + 1*size/2]; w1 = BITSWAP16(w1, 9,14,7,2, 6,8,3,15, 10,13,5,12, 0,11,4,1); buf[i + 0*size/2] = w1 >> 8; buf[i + 1*size/2] = w1 & 0xff; } /* address lines */ for (i = 0;i < size;i++) { rom[i] = buf[BITSWAP24(i, 23,22,21,20,19,18,17,16,15,14, 12,11,10,9,8, 5,4,3, 13, 7,6, 1,0, 2)]; } free(buf); }