Ejemplo n.º 1
0
void ZTransform::AddToScene(ZScene *pScene)
{
	ZASSERT( (!mParent), "Can't add a child transform to scene. Unlink it or add its parent");
	ZASSERT( (!mScene), "Transform already attached to a scene" );

	AddTransformToScene(pScene);
	pScene->AddRootTransform(this);
}
Ejemplo n.º 2
0
void zsave5(void)
{
  zterp_io *savefile;
  size_t n;

  if(znargs == 0)
  {
    zsave();
    return;
  }

  /* This should be able to suggest a filename, but Glk doesn’t support that. */
  savefile = zterp_io_open(NULL, ZTERP_IO_WRONLY | ZTERP_IO_SAVE);
  if(savefile == NULL)
  {
    store(0);
    return;
  }

  ZASSERT(zargs[0] + zargs[1] < memory_size, "attempt to save beyond the end of memory");
  n = zterp_io_write(savefile, &memory[zargs[0]], zargs[1]);

  zterp_io_close(savefile);

  store(n == zargs[1]);
}
Ejemplo n.º 3
0
void branch_if(int do_branch)
{
  uint8_t branch;
  uint16_t offset;

  branch = BYTE(pc++);

  if(!do_branch) branch ^= 0x80;

  offset = branch & 0x3f;

  if((branch & 0x40) == 0)
  {
    offset = (offset << 8) | BYTE(pc++);

    /* Get the sign right. */
    if(offset & 0x2000) offset |= 0xc000;
  }

  if(branch & 0x80)
  {
    if(offset > 1)
    {
      pc += (int16_t)offset - 2;
      ZASSERT(pc < memory_size, "branch to invalid address 0x%lx", (unsigned long)pc);
    }
    else
    {
      do_return(offset);
    }
  }
}
Ejemplo n.º 4
0
int zinet_addr(zsockaddr_in *addr, const char *host, uint16_t port){
  int ret;

  ret = ZOK;
  ZASSERT(!addr || !host);// || (port > 0 && port < 65535));
  memset(addr, 0, sizeof(zsockaddr_in));
  addr->sin_family = AF_INET;
  addr->sin_port = htons(port);
#ifdef ZSYS_WINDOWS
  if(INADDR_NONE == (addr->sin_addr.S_un.S_addr = inet_addr(host))){
    ret = ZFUN_FAIL;
  }
#else
  if(inet_pton(AF_INET, host, &addr->sin_addr) <=0){
    ret = ZFUN_FAIL;
  }
#endif

#if ZTRACE_SOCKET
  zdbg("zinet(addr<%p>, host<%s>, port<%d>); %s", addr, host, port, zstrerr(ret));
#endif

  ZERRCX(ret);
  return(ret);
}
Ejemplo n.º 5
0
void zjump(void)
{
  /* -= 2 because pc has been advanced past the jump instruction. */
  pc += (int16_t)zargs[0];
  pc -= 2;

  ZASSERT(pc < memory_size, "@jump to invalid address 0x%lx", (unsigned long)pc);
}
Ejemplo n.º 6
0
/*! Forward real FFT */
void Fft::FftReal(const audio_real *X, Cmplx *Y) const
{
	if (m_sFFT == 1) {
		Y[0].re = X[0];
		Y[0].im = 0;
		return;
	}
	else if (m_sFFT == 2) {
		Y[0].re = X[0] + X[1];
		Y[1].re = X[0] - X[1];
		Y[0].im = Y[1].im = 0;
		return;
	}
	// Separate even and odd points
	const uint ND2 = m_sFFT>>1;
	const uint ND4 = ND2>>1;
	if ( static_cast<const void*>(X) != Y ) {
		const Cmplx *Z = reinterpret_cast<const Cmplx*>(X);
		for (uint i=0; i<ND2; ++i)
			Y[i] = Z[i];
	}
	// Calculate N/2 point complex FFT
	m_pChild->FftComplex_InPlace( Y );
	// Even/odd frequency domain decomposition
	for (uint i=1; i<ND4; ++i) {
		uint im = ND2 - i;
		uint ip2 = i + ND2;
		uint ipm = im + ND2;
		ZASSERT(im>=0 && im<m_sFFT && ipm>=0 && ipm<m_sFFT && ip2>=0 && ip2<m_sFFT);
		Y[ipm].re = Y[ip2].re = (Y[i].im + Y[im].im)*audio_real(0.5);
		Y[ip2].im = (Y[i].re - Y[im].re)*audio_real(-0.5);
		Y[ipm].im =  -Y[ip2].im;
		Y[im].re = Y[i].re = (Y[i].re + Y[im].re)*audio_real(0.5);
		Y[i].im = (Y[i].im - Y[im].im)*audio_real(0.5);
		Y[im].im = -Y[i].im;
	}
	Y[ND2+ND4].re = Y[ND4].im;
	Y[ND2].re = Y[0].im;
	Y[ND2+ND4].im = Y[ND2].im = Y[ND4].im = Y[0].im = 0;
	// Complete the last FFT stage
	// Calculate Y[0] and Y[N/2]
	audio_real TR = Y[ND2].re;
	audio_real TI = Y[ND2].im;
	Y[ND2].re = Y[0].re - TR;
	Y[ND2].im = Y[0].im - TI;
	Y[0].re += TR;
	Y[0].im += TI;
	// Calculate the rest of coefficients
	const audio_real *pRot = &m_Rotors[0];
	for (uint i=1; i<ND2; ++i) {
		Y[i].re += Y[i+ND2].re*pRot[0] - Y[i+ND2].im*pRot[1];
		Y[i].im += Y[i+ND2].re*pRot[1] + Y[i+ND2].im*pRot[0];
		pRot += 2;
	}
}
Ejemplo n.º 7
0
void ZTransform::RemoveFromScene()
{
	if (!mScene) 
		return;

	//ZASSERT( (mScene), "Transform not assigned to a scene");
	ZASSERT( (!mParent), "Can't unassign child transform from scene. Unlink it before");

	mScene->RemoveRootTransform(this);
	RemoveTransformFromScene(mScene);
}
Ejemplo n.º 8
0
static uint16_t OBJECT(uint16_t n)
{
  /* Use 32-bit arithmetic to detect 16-bit overflow. */
  uint32_t base = header.objects, obj = n, addr;
  int objsize;

  if(zversion <= 3)
  {
    ZASSERT(n <= 255, "illegal object %u referenced", (unsigned)n);
    addr = base + (31 * 2) + (9 * (obj - 1));
    objsize = 9;
  }
  else
  {
    addr = base + (63 * 2) + (14 * (obj - 1));
    objsize = 14;
  }

  ZASSERT(addr + objsize < header.static_start, "object %u out of range", (unsigned)n);

  return addr;
}
Ejemplo n.º 9
0
/*! Sets FFT size */
void Fft::SetMode(FftModes iMode, uint FftSize)
{
	ZASSERT(iMode==FFT_COMPLEX && FftSize>=1 || iMode==FFT_REAL && FftSize>=1);
	m_sFFT = FftSize;
	// Get FFT size order
	m_uOrder = 1;
	while ((1U<<m_uOrder)<m_sFFT) ++m_uOrder;
	ZASSERT((1U<<m_uOrder)==m_sFFT);	// FFT size must be a power of 2
	if ( iMode == FFT_COMPLEX ) {
		// Precalculate permutation indexes for bit-reverse algorithm
		m_Perm.resize( m_sFFT-1 );
		CachePerms( &m_Perm[0], m_sFFT );
		// Precalculate rotating multipliers for complex FFT
		m_Rotors.resize( m_sFFT );
		CacheRotors( &m_Rotors[0], m_uOrder );
	} // end if FFT_COMPLEX
	else {
		// Setup child complex FFT with m_sFFT/2 points
		if ( m_pChild != 0 ) delete m_pChild;
		m_pChild = new Fft;
		m_pChild->SetMode( FFT_COMPLEX, m_sFFT/2 );
		// Precalculate rotating multipliers for real FFT
		m_Rotors.resize( m_sFFT-2 );
		double UR = cos(2*dPi/m_sFFT);
		double UI = -sin(2*dPi/m_sFFT);
		double SR = UR, SI = UI;
		audio_real *pRot = &m_Rotors[0];
		for (uint i=1; i<m_sFFT/2; ++i) {
			*(pRot++) = static_cast<audio_real>(UR);
			*(pRot++) = static_cast<audio_real>(UI);
			double TR = UR;
			UR = TR*SR - UI*SI;
			UI = TR*SI + UI*SR;
		}
	} // end FFT_REAL
}
Ejemplo n.º 10
0
/*! Sets FFT size */
void Fft::SetMode(uint FftSize)
{
	if (m_Spec!=0)
	{
		Free(m_Buf);
		FFTFree(m_Spec);
	}
	m_sFFT = FftSize;
	// Setup IPP structures
	int Order = 1;
	while ((1<<Order)<m_sFFT) ++Order;
	ZASSERT((1<<Order)==m_sFFT);	// FFT size must be a power of 2
	FFTInit(&m_Spec, Order);
	uint sBuffer;
	FFTGetBufSize(m_Spec, &sBuffer);
	m_Buf = Malloc_Byte(sBuffer);
}