some changes to the 315-5881 to allow basic multiple stream support, astrass needs this - we were ignoring a size value in the header, when the 'size' is reached the stream ends, and a new header needs to be read.

I need to review the changes w/regards the naomi code later (don't have the material to test here) also this will need looking at w/regards compressed streams, as they can be mixed.

the data decrypted from astrass is now a 100% match for the data that was extracted from the saturn version.
This commit is contained in:
David Haywood 2015-01-20 16:53:09 +00:00
parent f8096960a9
commit cd61a2736d
2 changed files with 70 additions and 45 deletions

View File

@ -632,6 +632,7 @@ UINT16 sega_315_5881_crypt_device::block_decrypt(UINT32 game_key, UINT16 sequenc
return aux;
}
UINT16 sega_315_5881_crypt_device::get_decrypted_16()
{
UINT16 enc;
@ -643,20 +644,34 @@ UINT16 sega_315_5881_crypt_device::get_decrypted_16()
dec_hist = dec;
prot_cur_address ++;
return res;
}
void sega_315_5881_crypt_device::enc_start()
{
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.
block_pos = 0;
buffer_pos = BUFFER_SIZE;
dec_header = get_decrypted_16() << 16;
dec_header |= get_decrypted_16();
// the lower header bits are 2 values that multiply together to get the current stream length
// in astrass the first block is 0xffff (for a 0x10000 block) followed by 0x3f3f (for a 0x1000 block)
// etc. after each block a new header must be read, it looks like compressed and uncompressed blocks
// can be mixed like this, I don't know if the length is src length of decompressed length.
int blockx = ((dec_header & 0x00ff) >> 0) + 1;
int blocky = ((dec_header & 0xff00) >> 8) + 1;
block_size = blockx * blocky;
if(dec_header & FLAG_COMPRESSED) {
line_buffer_size = dec_header & FLAG_LINE_SIZE_512 ? 512 : 256;
line_buffer_pos = line_buffer_size;
buffer_bit = 7;
}
// printf("header %08x\n", dec_header);
enc_ready = true;
}
@ -667,6 +682,14 @@ void sega_315_5881_crypt_device::enc_fill()
UINT16 val = get_decrypted_16();
buffer[i] = val;
buffer[i+1] = val >> 8;
block_pos+=2;
if (block_pos == block_size)
{
// if we reach the size specified we need to read a new header
// todo: how should this work with compressed blocks??
enc_start();
}
}
buffer_pos = 0;
}

View File

@ -40,7 +40,7 @@ protected:
private:
enum {
BUFFER_SIZE = 32768, LINE_SIZE = 512,
BUFFER_SIZE = 32768*8, LINE_SIZE = 512*8,
FLAG_COMPRESSED = 0x10000, FLAG_LINE_SIZE_512 = 0x20000
};
@ -54,6 +54,8 @@ private:
bool enc_ready;
int buffer_pos, line_buffer_pos, line_buffer_size, buffer_bit;
int block_size;
int block_pos;
struct sbox {
UINT8 table[64];