Exemplo n.º 1
0
tt_int16 ReadInt16( InputStream *t )
{
	register unsigned char *ptr = t->privateBase;
	tt_uint32 pos = t->pos;
	register tt_uint16 word;
#ifdef ENABLE_NON_RAM_STREAM
	unsigned char base[2];
	
	if ( ptr != NULL ) {		/* ptr == t->privateBase */
		ptr += pos; 			/* ptr == &t->privateBase[pos] */
		#ifdef USE_PRE_CACHING
			if ( t->ReadToRamFunc != NULL ) {
				EnsureWeHaveDataInT2KInputStream( t, 2 );
				ptr -= t->cachePosition; /* ptr = &t->privateBase[pos - t->cachePosition]; */
			}
		#endif
	} else {
		ptr = base;
		t->ReadToRamFunc( t->nonRamID, ptr, pos, 2 );
	}
#else
	ptr += pos;
#endif
	
	pos = pos + 2;
	assert( pos <= t->maxPos ); 
	t->pos = pos;
	
	word = *ptr++;
	word <<= 8;
	word |= *ptr;
	
	return (tt_int16)word; /*****/
}
Exemplo n.º 2
0
int32 ReadInt32( InputStream *t )
{
    register unsigned char *ptr = t->privateBase;
    unsigned long pos = t->pos;
    register uint32 lword;
#ifdef ENABLE_NON_RAM_STREAM
    unsigned long delta;
    unsigned char base[4];

    if ( ptr != NULL ) {		/* ptr == t->privateBase */
        delta = pos; 			/* ptr == &t->privateBase[pos] */
#ifdef USE_PRE_CACHING
        if ( t->ReadToRamFunc != NULL ) {
            EnsureWeHaveDataInT2KInputStream( t, 4 );
            /* Combine additions into one step wo we never have a pointer out of bounds. */
            delta -= t->cachePosition; /* ptr = &t->privateBase[pos - t->cachePosition]; */
        }
#endif
        ptr += delta;
    } else {
        int ioCode;
        ptr = base;
        ioCode = t->ReadToRamFunc( t->nonRamID, ptr, pos, 4 );
        tsi_Assert( t->mem, ioCode >= 0, T2K_EXT_IO_CALLBACK_ERR );
    }
#else
    ptr += pos;
#endif

    pos = pos + 4;
    assert( pos <= t->maxPos );
    t->pos = pos;

    lword = *ptr++;
    lword <<= 8;
    lword |= *ptr++;
    lword <<= 8;
    lword |= *ptr++;
    lword <<= 8;
    lword |= *ptr;

    return (int32)lword; /*****/
}