145 for( i=0; i<=(_size-4); ++i ) {
150 sequenceValue->
offset = _input+i;
154 memcpy( literal, sequenceValue->
offset, 4 );
167 if ( ! actual->
first ) {
168 actual->
first = sequenceValue;
171 while( actualValue ) {
172 if ( ! actualValue->
next ) {
173 actualValue->
next = sequenceValue;
176 actualValue = actualValue->
next;
190 memcpy( actual->
value, literal, 4 );
191 actual->
first = sequenceValue;
194 if ( ! sequences->
first ) {
195 sequences->
first = actual;
196 sequences->
count = 1;
199 sequences->
first = actual;
318 printf(
"MSC1_CS_READY");
323 printf(
"MSC1_CS_STORE");
328 printf(
"MSC1_CS_MOVE1");
333 printf(
"MSC1_CS_LITERAL");
338 printf(
"MSC1_CS_LITERAL_DUPE");
343 printf(
"MSC1_CS_READY\n");
348 printf(
"MSC1_CS_DUPE_STORE");
353 printf(
"MSC1_CS_DUPE_MOVE4");
358 printf(
"MSC1_CS_DUPES");
362 printf(
"MSC1_CS_END_OF_BLOCK");
366 printf(
" rp=%4.4x wp=%4.4x il=%d rep=%d\n", _read, _write, _iliteral, _repeats );
368 for(
int i=0; i<_iliteral; ++i ) {
369 printf(
"%2.2x ", (
unsigned char)(_literal[i]) );
372 if ( _actual && _actual->
used && _output ) {
375 printf(
" seq=%p[%2.2x%2.2x%2.2x%2.2x] used=%4.4x\n", _actual, (_actual)?(_actual->
value[0]):0, (_actual)?(_actual->
value[1]):0, (_actual)?(_actual->
value[2]):0, (_actual)?(_actual->
value[3]):0,
used );
376 printf(
" RP=...%2.2x%2.2x%2.2x%2.2x\n", (
unsigned char)(*(_pointer-3)), (
unsigned char)(*(_pointer-2)), (
unsigned char)(*(_pointer-1)), (
unsigned char)(*(_pointer)) );
377 printf(
" WP=...%2.2x%2.2x%2.2x%2.2x\n", (
unsigned char)(*(_wpointer-4)), (
unsigned char)(*(_wpointer-3)), (
unsigned char)(*(_wpointer-2)), (
unsigned char)(*(_wpointer-1)) );
384 MemoryBlock * pointer = _input, * endPointer = pointer + _size;
388 memset( output, 0, _size );
398 memset( literal, 0, 128 );
409 switch( _msc1->
state ) {
417 if ( pointer == endPointer ) {
425 else if ( ! actual ) {
427 memset( literal, 0, 128 );
452 literal[iliteral] = *pointer;
460 if ( pointer == endPointer ) {
468 if ( iliteral == 127 ) {
473 if ( iliteral > 3 ) {
515 if( actual->
used && ( wpointer - actual->
used ) > 1000 ) {
519 if ( ! actual->
used ) {
532 *wpointer = iliteral;
534 memcpy( wpointer, literal, iliteral );
535 wpointer += ( iliteral );
537 actual->
used = ( wpointer - 4 );
543 if ( iliteral > 4 ) {
557 *wpointer = iliteral-4;
559 memcpy( wpointer, literal, iliteral-4 );
560 wpointer += ( iliteral - 4 );
582 *wpointer = iliteral;
584 memcpy( wpointer, literal, iliteral );
585 wpointer += iliteral;
624 if ( ( pointer + 4 ) >= endPointer ) {
631 if ( memcmp( pointer, &literal[iliteral-4], 4 ) == 0 ) {
659 if ( pointer >= endPointer ) {
667 if ( repeats == 32 ) {
680 if ( wpointer - actual->
used + 2 > 1000 ) {
691 memcpy( wpointer, actual->
value, 4 );
693 actual->
used = ( wpointer - 4 );
701 MemoryBlock token1 = 0x80 | ( ( repeats & 0x1f ) << 2 ) | ( ( ( wpointer - actual->
used + 2 ) >> 8 ) & 0x03 );
708 *wpointer++ = token1;
709 *wpointer++ = token2;
712 if ( repeats == 32 ) {
734 *_output_size = (wpointer - output);
750 *_output_size = 200 * _size;
780 else if ((token & 0x80) == 0x00) {
784 int count = token & 0x7f;
789 if ( ((wpointer-output)+
count) > *_output_size ) {
790 *_output_size = (*_output_size)<<1;
791 int reallocOffset = wpointer - output;
793 output = realloc( output, *_output_size );
794 wpointer = output + reallocOffset;
807 memcpy(wpointer, pointer,
count);
816 else if ((token & 0x80) == 0x80) {
819 int repetitions = (token & 0x7f) >> 2;
824 int offset = tmp | ((token & 0x03) << 8);
828 if (repetitions == 0) repetitions = 32;
839 while( repetitions ) {
840 for(
int j=0; j<4; ++j ) {
842 *wpointer = *(sourcePointer+j);
849 if ( (wpointer-output) > *_output_size ) {
850 *_output_size = (*_output_size)<<1;
851 int reallocOffset = wpointer - output;
853 output = realloc( output, *_output_size );
854 wpointer = output + reallocOffset;
863 *_output_size = (wpointer - output);
void msc1_echo_state(MSC1CompressorState _state, int _read, int _write, int _repeats, int _iliteral, char *_literal, char *_pointer, char *_wpointer, MSC1Sequence *_actual, MemoryBlock *_output)