trunk/src/mame/machine/stvprot.c
| r243018 | r243019 | |
| 92 | 92 | #include "emu.h" |
| 93 | 93 | #include "includes/stv.h" |
| 94 | 94 | |
| 95 | //FILE *fp; |
| 96 | //FILE *fp2; |
| 95 | 97 | |
| 96 | 98 | |
| 97 | 99 | /************************ |
| r243018 | r243019 | |
| 494 | 496 | } |
| 495 | 497 | } |
| 496 | 498 | |
| 497 | | UINT32 astrass_prot_read_callback( address_space &space, int protaddr, UINT32 key ) |
| 498 | | { |
| 499 | | /* we're reading from a custom region where we've loaded the data from the Saturn version |
| 500 | | NOT the rom address, so we're based at 0. The real data likely exists at the given |
| 501 | | address in encrypted form */ |
| 502 | | int read_offset_hack = 0x4ec260; |
| 503 | | int useoffset = (protaddr-read_offset_hack); |
| 504 | | UINT32 data = 0; |
| 505 | | UINT32 *prot_data = (UINT32 *)space.machine().root_device().memregion("user2")->base(); |
| 506 | | int prot_size = space.machine().root_device().memregion("user2")->bytes(); |
| 507 | 499 | |
| 508 | | if (useoffset<prot_size) |
| 509 | | { |
| 510 | | data = prot_data[useoffset/4]; |
| 511 | | return data; |
| 512 | | } |
| 513 | | return 0x00; |
| 514 | | } |
| 515 | 500 | |
| 516 | | |
| 517 | 501 | UINT32 elandore_prot_read_callback( address_space &space, int protaddr, UINT32 key ) |
| 518 | 502 | { |
| 519 | 503 | UINT32 *ROM = (UINT32 *)space.machine().root_device().memregion("abus")->base(); |
| r243018 | r243019 | |
| 585 | 569 | #ifdef MAME_DEBUG |
| 586 | 570 | popmessage("Prot read at %06x with data = %08x",space.device().safe_pc(),m_abus_protkey); |
| 587 | 571 | #endif |
| 588 | | UINT32 realret = space.read_dword(0x2000000+m_ctrl_index); |
| 589 | | UINT32 retdata = m_prot_readback(space, m_ctrl_index, m_abus_protkey); |
| 572 | if (!m_using_crypt_device) // decrypt using hacks |
| 573 | { |
| 574 | UINT32 realret = space.read_dword(0x2000000 + m_ctrl_index); |
| 575 | UINT32 retdata = m_prot_readback(space, m_ctrl_index, m_abus_protkey); |
| 576 | //fwrite(&realret, 1, 4, fp); |
| 577 | //fwrite(&retdata, 1, 4, fp2); |
| 590 | 578 | |
| 591 | | logerror("A-Bus control protection read at %06x with data = %08x Returning = %08x Would otherwise return = %08x\n",space.device().safe_pc(),m_abus_protkey, retdata, realret); |
| 592 | | |
| 593 | | //UINT16 res = m_cryptdevice->do_decrypt(base); |
| 594 | | |
| 595 | | m_ctrl_index += 4; |
| 596 | | return retdata; |
| 597 | | |
| 579 | logerror("A-Bus control protection read at %06x with data = %08x Returning = %08x Would otherwise return = %08x\n", space.device().safe_pc(), m_abus_protkey, retdata, realret); |
| 580 | m_ctrl_index += 4; |
| 581 | return retdata; |
| 582 | } |
| 583 | else // decrypt using real decryption device |
| 584 | { |
| 585 | UINT8* base; |
| 586 | UINT16 res = m_cryptdevice->do_decrypt(base); |
| 587 | UINT16 res2 = m_cryptdevice->do_decrypt(base); |
| 588 | res = ((res & 0xff00) >> 8) | ((res & 0x00ff) << 8); |
| 589 | res2 = ((res2 & 0xff00) >> 8) | ((res2 & 0x00ff) << 8); |
| 590 | |
| 591 | return res2 | (res << 16); |
| 592 | } |
| 593 | |
| 598 | 594 | } |
| 599 | 595 | return m_a_bus[offset]; |
| 600 | 596 | } |
| r243018 | r243019 | |
| 608 | 604 | |
| 609 | 605 | UINT16 stv_state::crypt_read_callback(UINT32 addr) |
| 610 | 606 | { |
| 611 | | const UINT8 *base = m_cart_reg[0]->base() + 2*addr; |
| 612 | | return base[1] | (base[0] << 8); |
| 607 | UINT16 dat= m_maincpu->space().read_word((0x02000000+2*addr)); |
| 608 | return ((dat&0xff00)>>8)|((dat&0x00ff)<<8); |
| 613 | 609 | } |
| 614 | 610 | |
| 615 | 611 | WRITE32_MEMBER ( stv_state::common_prot_w ) |
| r243018 | r243019 | |
| 640 | 636 | a_bus_vector = m_abus_prot_addr >> 16; |
| 641 | 637 | a_bus_vector|= (m_abus_prot_addr & 0xffff) << 16; |
| 642 | 638 | a_bus_vector<<= 1; |
| 639 | /* |
| 640 | if (fp) |
| 641 | { |
| 642 | fclose(fp); |
| 643 | fp = 0; |
| 644 | } |
| 645 | if (fp2) |
| 646 | { |
| 647 | fclose(fp2); |
| 648 | fp2 = 0; |
| 649 | } |
| 650 | char filename[256]; |
| 651 | sprintf(filename,"encrypted_%s_key_%04x_address_%08x", machine().system().name, m_abus_protkey>>16, a_bus_vector); |
| 652 | fp=fopen(filename, "w+b"); |
| 653 | sprintf(filename,"not-encrypted_%s_key_%04x_address_%08x", machine().system().name, m_abus_protkey>>16, a_bus_vector); |
| 654 | fp2=fopen(filename, "w+b"); |
| 655 | */ |
| 656 | |
| 643 | 657 | //printf("MAIN : %08x DATA : %08x %08x\n",m_abus_protkey,m_abus_prot_addr,a_bus_vector); |
| 644 | 658 | |
| 645 | 659 | // if you look at the first transfer in ffreveng this is clearly a ROM address from a table | MAIN : 10d70000 DATA : 0b780013 002616f0 |
| r243018 | r243019 | |
| 659 | 673 | void stv_state::install_common_protection() |
| 660 | 674 | { |
| 661 | 675 | m_maincpu->space(AS_PROGRAM).install_readwrite_handler(0x4fffff0, 0x4ffffff, read32_delegate(FUNC(stv_state::common_prot_r), this), write32_delegate(FUNC(stv_state::common_prot_w), this)); |
| 676 | |
| 677 | |
| 662 | 678 | } |
| 663 | 679 | |
| 664 | 680 | void stv_state::install_sss_protection() |
| r243018 | r243019 | |
| 670 | 686 | void stv_state::install_astrass_protection() |
| 671 | 687 | { |
| 672 | 688 | install_common_protection(); |
| 673 | | m_prot_readback = astrass_prot_read_callback; |
| 674 | | // m_cryptdevice->set_key(0x00000000); |
| 689 | // m_prot_readback = astrass_prot_read_callback; |
| 690 | m_cryptdevice->set_key(0x052e2901); // same key as wldkicks / toukon4 |
| 691 | m_using_crypt_device = 1; |
| 675 | 692 | } |
| 676 | 693 | |
| 677 | 694 | void stv_state::install_ffreveng_protection() |
| r243018 | r243019 | |
| 696 | 713 | { |
| 697 | 714 | install_common_protection(); |
| 698 | 715 | m_prot_readback = twcup98_prot_read_callback; |
| 699 | | |
| 716 | m_cryptdevice->set_key(0x05200913 ); |
| 717 | m_using_crypt_device = 0; // doesn't currently work |
| 700 | 718 | } |
| 701 | 719 | |
| 702 | 720 | |
| 703 | 721 | |
| 704 | 722 | void stv_state::stv_register_protection_savestates() |
| 705 | 723 | { |
| 724 | |
| 725 | |
| 706 | 726 | save_item(NAME(m_a_bus)); |
| 707 | 727 | save_item(NAME(m_ctrl_index)); |
| 708 | 728 | save_item(NAME(m_internal_counter)); |