summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/export/extract_version_2.c36
1 files changed, 18 insertions, 18 deletions
diff --git a/src/export/extract_version_2.c b/src/export/extract_version_2.c
index ac082ca..fcbd59f 100644
--- a/src/export/extract_version_2.c
+++ b/src/export/extract_version_2.c
@@ -323,17 +323,17 @@ static int decomp(struct state *s)
323 return 0; 323 return 0;
324} 324}
325 325
326static void decompress_subchunk( uint8_t * subchunk, size_t subchunk_size, int chunks, size_t outchunk_size ) { 326static void decompress_chunk( uint8_t * chunk, size_t chunk_size, int blocks ) {
327 uint8_t output[ outchunk_size ]; 327 uint8_t output[ MAXWIN ];
328 struct state s; /* input/output state */ 328 struct state s; /* input/output state */
329 int err; /* return value */ 329 int err; /* return value */
330 330
331 memset( output, 0, outchunk_size ); 331 memset( output, 0, MAXWIN );
332 332
333 /* initialize input state */ 333 /* initialize input state */
334 s.in = subchunk; 334 s.in = chunk;
335 s.left = subchunk_size; 335 s.left = chunk_size;
336 while( chunks-- ) { 336 while( blocks-- ) {
337 /* (Re-)initialize output state */ 337 /* (Re-)initialize output state */
338 s.out = output; 338 s.out = output;
339 s.next = 0; 339 s.next = 0;
@@ -346,7 +346,7 @@ static void decompress_subchunk( uint8_t * subchunk, size_t subchunk_size, int c
346 return; 346 return;
347 347
348 /* Dump to stdout for now */ 348 /* Dump to stdout for now */
349 fwrite( output, outchunk_size, 1, stdout ); 349 fwrite( output, MAXWIN, 1, stdout );
350 } 350 }
351} 351}
352 352
@@ -368,8 +368,8 @@ static void decode_19bit_address( uint8_t const *source, uint32_t *dest, size_t
368int main( int args, char **argv ) { 368int main( int args, char **argv ) {
369 MAP file; 369 MAP file;
370 uint32_t offsets[256]; 370 uint32_t offsets[256];
371 uint16_t num_subchunks, subchunk_rest_count, subchunk_one_count; 371 uint16_t chunk_count, restchunks_size, firstchunk_size;
372 uint8_t *fp, *subchunk; 372 uint8_t *fp, *firstchunk;
373 int i; 373 int i;
374 374
375 if( args < 2 ) { 375 if( args < 2 ) {
@@ -381,19 +381,19 @@ int main( int args, char **argv ) {
381 if( !file ) exit( 1 ); 381 if( !file ) exit( 1 );
382 fp = file->addr; 382 fp = file->addr;
383 383
384 num_subchunks = *(uint16_t*)(fp+0x14); 384 chunk_count = *(uint16_t*)(fp+0x14);
385 subchunk_rest_count = *(uint16_t*)(fp+0x1c); 385 firstchunk = fp + 0x20 + ( 19*chunk_count +7 )/ 8;
386 subchunk_one_count = *(uint16_t*)(fp+0x1e); 386 firstchunk_size = *(uint16_t*)(fp+0x1e) + 1;
387 subchunk = fp + 0x20 + ( 19*num_subchunks +7 )/ 8; 387 restchunks_size = *(uint16_t*)(fp+0x1c);
388 388
389 decode_19bit_address ( fp + 0x20, offsets, num_subchunks ); 389 decode_19bit_address ( fp + 0x20, offsets, chunk_count );
390 offsets[num_subchunks] = file->size; 390 offsets[chunk_count] = file->size;
391 391
392 decompress_subchunk( subchunk, offsets[0], subchunk_one_count + 1, MAXWIN ); 392 decompress_chunk( firstchunk, offsets[0], firstchunk_size );
393 393
394 for( i=0; i< num_subchunks; ++i ) 394 for( i=0; i< chunk_count; ++i )
395 if( offsets[i] + 0x800 < file->size ) 395 if( offsets[i] + 0x800 < file->size )
396 decompress_subchunk( fp + offsets[i] + 0x800, offsets[i+1] - offsets[i], subchunk_rest_count, MAXWIN ); 396 decompress_chunk( fp + offsets[i] + 0x800, offsets[i+1] - offsets[i], restchunks_size );
397 397
398 return 0; 398 return 0;
399} 399}