trunk/src/mame/machine/315-5881_crypt.c
| r243044 | r243045 | |
| 70 | 70 | if(!enc_ready) |
| 71 | 71 | enc_start(); |
| 72 | 72 | if(dec_header & FLAG_COMPRESSED) { |
| 73 | | if(line_buffer_pos == line_buffer_size) |
| 73 | if (line_buffer_pos == line_buffer_size) // if there's no data left to read.. |
| 74 | { |
| 75 | if (done_compression == 1) |
| 76 | enc_start(); |
| 77 | |
| 78 | |
| 79 | |
| 74 | 80 | line_fill(); |
| 81 | } |
| 75 | 82 | base = line_buffer + line_buffer_pos; |
| 76 | 83 | line_buffer_pos += 2; |
| 77 | 84 | } else { |
| r243044 | r243045 | |
| 94 | 101 | { |
| 95 | 102 | prot_cur_address = (prot_cur_address & 0x0000ffff) | (data << 16); |
| 96 | 103 | enc_ready = false; |
| 104 | |
| 105 | buffer_bit = 7; |
| 106 | buffer_bit2 = 15; |
| 97 | 107 | } |
| 98 | 108 | |
| 99 | 109 | void sega_315_5881_crypt_device::set_subkey(UINT16 data) |
| r243044 | r243045 | |
| 645 | 655 | |
| 646 | 656 | prot_cur_address ++; |
| 647 | 657 | |
| 658 | // printf("get_decrypted_16 %04x\n", res); |
| 659 | |
| 648 | 660 | return res; |
| 649 | 661 | } |
| 650 | 662 | |
| 651 | 663 | |
| 652 | 664 | void sega_315_5881_crypt_device::enc_start() |
| 653 | 665 | { |
| 654 | | dec_hist = 0; // seems to be needed by astrass at least otherwise any call after the first one will be influenced by the one before it. |
| 655 | 666 | block_pos = 0; |
| 667 | done_compression = 0; |
| 656 | 668 | buffer_pos = BUFFER_SIZE; |
| 657 | | dec_header = get_decrypted_16() << 16; |
| 669 | |
| 670 | if (buffer_bit2 != 15) // if we have remaining bits in the decompression buffer we shouldn't read the next word yet but should instead use the bits we have?? (twcup98) (might just be because we should be pulling bytes not words?) |
| 671 | { |
| 672 | // printf("buffer_bit2 is %d\n", buffer_bit2); |
| 673 | dec_header = (buffer2a & 0x0003) << 16; |
| 674 | } |
| 675 | else |
| 676 | { |
| 677 | dec_hist = 0; // seems to be needed by astrass at least otherwise any call after the first one will be influenced by the one before it. |
| 678 | dec_header = get_decrypted_16() << 16; |
| 679 | } |
| 680 | |
| 658 | 681 | dec_header |= get_decrypted_16(); |
| 659 | 682 | |
| 660 | 683 | // the lower header bits are 2 values that multiply together to get the current stream length |
| r243044 | r243045 | |
| 782 | 805 | if (buffer_bit2 == 15) |
| 783 | 806 | { |
| 784 | 807 | buffer_bit2 = 0; |
| 785 | | UINT16 buffer2a = get_decrypted_16(); |
| 808 | buffer2a = get_decrypted_16(); |
| 786 | 809 | buffer2[0] = buffer2a; |
| 787 | 810 | buffer2[1] = buffer2a >> 8; |
| 788 | 811 | // block_pos+=2; |
| r243044 | r243045 | |
| 857 | 880 | } |
| 858 | 881 | } |
| 859 | 882 | |
| 883 | block_pos++; |
| 860 | 884 | if (block_numlines == block_pos) |
| 861 | 885 | { |
| 862 | | enc_start(); |
| 886 | done_compression = 1; |
| 863 | 887 | } |
| 864 | 888 | else |
| 865 | 889 | { |
| 866 | | block_pos++; |
| 867 | 890 | } |
| 868 | 891 | } |