Exemplo n.º 1
0
/*
@method clip( rect ) -> [x, y, w, h]
@method clip!( rect ) -> self
Returns a new rectangle that is the given rectangle cropped to the inside of the base rectangle.
If the two rectangles do not overlaps to begin with, you will get a rectangle with 0 size.
*/
static VALUE rb_array_clip_bang(VALUE self, VALUE rect)
{
	SDL_Rect a, b;
	double x,y,w,h;
	RECT2CRECT(self, &a);
	RECT2CRECT(rect, &b);
	/* Left */
	if((a.x >= b.x) && (a.x < (b.x+b.w)))
		x = a.x;
	else if((b.x >= a.x) && (b.x < (a.x+a.w)))
		x = b.x;
	else
		goto nointersect;
	/* Right */
	if(((a.x+a.w) > b.x) && ((a.x+a.w) <= (b.x+b.w)))
		w = (a.x+a.w) - x;
	else if(((b.x+b.w) > a.x) && ((b.x+b.w) <= (a.x+a.w)))
		w = (b.x+b.w) - x;
	else
		goto nointersect;

	/* Top */
	if((a.y >= b.y) && (a.y < (b.y+b.h)))
		y = a.y;
	else if((b.y >= a.y) && (b.y < (a.y+a.h)))
		y = b.y;
	else
		goto nointersect;
	/* Bottom */
	if (((a.y+a.h) > b.y) && ((a.y+a.h) <= (b.y+b.h)))
		h = (a.y+a.h) - y;
	else if(((b.y+b.h) > a.y) && ((b.y+b.h) <= (a.y+a.h)))
		h = (b.y+b.h) - y;
	else
		goto nointersect;

	SET_X(x);
	SET_Y(y);
	SET_W(w);
	SET_H(h);
	return self;
nointersect:
	SET_X(a.x);
	SET_Y(a.y);
	SET_W(0);
	SET_H(0);
	return self;
}
Exemplo n.º 2
0
//Assembly : (Y) | ld A,(Y)
void test_ld_a_to_y(void){
  SET_Y(0X102B);
  uint8_t instr[] = {0XFB};
  
  TEST_ASSERT_EQUAL_INT8(2, ld_a_to_y(instr));
  TEST_ASSERT_EQUAL_INT8(0xAE, MEM_READ_BYTE(0X102B));
}
Exemplo n.º 3
0
/*
struct CPU_t{
  uint8_t   a;    // 0x7F00
  uint8_t   pce;  
  uint8_t   pch;     
  uint8_t   pcl;   
  uint8_t   xh;    
  uint8_t   xl;  
  uint8_t   yh;  
  uint8_t   yl;   
  uint8_t  sph; 
  uint8_t  spl; 
  Flag     ccr;   // 0x7F0A 
};



*/
void test_cpuInit_given_write_something_to_CPU_should_save_in_cpuBlock_data_because_is_pointed(void)
{ 
  cpuInit(CPU_START_ADDR, CPU_SIZE); 
  
  uint8_t *dataArr = cpuBlock->data;
  
  A = 0xAA;
  SET_PC(0x112233);
  SET_X(0xCCDD);
  SET_Y(0xEEFF);
  SET_SP(0x77BB);
  CC = 0x99;

  TEST_ASSERT_EQUAL_INT8(0xAA, *dataArr++);
  TEST_ASSERT_EQUAL_INT8(0x11, *dataArr++);
  TEST_ASSERT_EQUAL_INT8(0x22, *dataArr++);
  TEST_ASSERT_EQUAL_INT8(0x33, *dataArr++);
  TEST_ASSERT_EQUAL_INT8(0xCC, *dataArr++);
  TEST_ASSERT_EQUAL_INT8(0xDD, *dataArr++);
  TEST_ASSERT_EQUAL_INT8(0xEE, *dataArr++);
  TEST_ASSERT_EQUAL_INT8(0xFF, *dataArr++);
  TEST_ASSERT_EQUAL_INT8(0x77, *dataArr++);
  TEST_ASSERT_EQUAL_INT8(0xBB, *dataArr++);
  TEST_ASSERT_EQUAL_INT8(0x99, *dataArr++);
  TEST_ASSERT_EQUAL_INT8(0, *dataArr++);
  TEST_ASSERT_EQUAL_INT8(0, *dataArr++);
  TEST_ASSERT_EQUAL_INT8(0, *dataArr++);
}
Exemplo n.º 4
0
/**
@method union( rect ) -> [x, y, w, h]
@method union!( rect ) -> self
Returns a new rectangle that completely covers the given rectangle(s).
There may be an area inside the new rectangle that is not covered by the inputs.
Rectangles are pre-normalized.
*/
static VALUE rb_array_union_bang(VALUE self, VALUE other_rect)
{
	normalize(self);
	normalize(other_rect);
	{
		GET_X();
		GET_Y();
		GET_W();
		GET_H();
		double other_x=array_get_x(other_rect);

		double other_y=array_get_y(other_rect);
		double other_w=array_get_w(other_rect);
		double other_h=array_get_h(other_rect);

		double new_x=RUDL_MIN(x, other_x);
		double new_y=RUDL_MIN(y, other_y);

		SET_X( new_x );
		SET_Y( new_y );
		SET_W( RUDL_MAX(x+w, other_x+other_w)-new_x );
		SET_H( RUDL_MAX(y+h, other_y+other_h)-new_y );
	}
	return self;
}
Exemplo n.º 5
0
/**
@method clamp( rect ) -> [x, y, w, h]
@method clamp!( rect ) -> nil
Returns a new rectangle that is moved to be completely inside the base rectangle.
If the given rectangle is too large for the base rectangle in an axis,
it will be centered on that axis.
*/
static VALUE rb_array_clamp_bang(VALUE self, VALUE rect)
{
	SDL_Rect a, b;
	double x, y;
	RECT2CRECT(self, &a);
	RECT2CRECT(rect, &b);

	if(a.w >= b.w)
		x = b.x + b.w / 2 - a.w / 2;
	else if(a.x < b.x)
		x = b.x;
	else if(a.x + a.w > b.x + b.w)
		x = b.x + b.w - a.w;
	else
		x = a.x;

	if(a.h >= b.h)
		y = b.y + b.h / 2 - a.h / 2;
	else if(a.y < b.y)
		y = b.y;
	else if(a.y + a.h > b.y + b.h)
		y = b.y + b.h - a.h;
	else
		y = a.y;

	SET_X(x);
	SET_Y(y);
	return self;
}
Exemplo n.º 6
0
VOID arrange_tree(LONG tree, WORD wint, WORD hint,WORD *maxw, WORD *maxh)
{
	WORD	obj, x, y, rowh, wroot;

	wroot = GET_WIDTH(tree, ROOT);
	if ( wroot )
	{
		x = wint;
		y = hint;
		rowh = 0;
		*maxw = 0;

		for (obj = GET_HEAD(tree, ROOT); obj != ROOT; 
			obj = GET_NEXT(tree, obj))
		{
			if (rowh && (x + GET_WIDTH(tree, obj)) > wroot)
			{
				x = wint;
				y += (rowh + hint);
				rowh = 0;
			}
			SET_X(tree, obj, x);
			SET_Y(tree, obj, y);
			if ( !(GET_FLAGS(tree, obj) & HIDETREE) )
			{
				x += (GET_WIDTH(tree, obj) + wint); 
				*maxw = max(*maxw, x);
				rowh = max(rowh, GET_HEIGHT(tree, obj));
			}
		}
		*maxh = y + rowh + hint;
	}
}
Exemplo n.º 7
0
void test_incw_y(void){

  SET_Y(0x2222);
  uint8_t instr[] = {0XAB};
  
  TEST_ASSERT_EQUAL_INT8(2, incw_y(instr));
  TEST_ASSERT_EQUAL_INT16(0x2223, Y);
}
Exemplo n.º 8
0
//Assembly : (longoff,Y) | and A,($1000,Y)
void test_and_a_longoff_y(void){
  SET_Y(0X2B11);
  uint8_t instr[] = {0XFB, 0X11, 0x11};
  
  MEM_WRITE_BYTE(0X3c22 , src);  //0x2B11 + 0X1111 = 0X3c22
  
  TEST_ASSERT_EQUAL_INT8(4, and_a_longoff_y(instr));
  TEST_ASSERT_EQUAL_INT8(0x8C, A);
}
void test_ldw_y_longoff_y(void){
  SET_Y(0X2B11);
  uint8_t instr[] = {0XFB, 0X11, 0x11};
  
  MEM_WRITE_WORD(0X3c22 , 0xAE11);  //0x2B11 + 0X1111 = 0X3c22
  
  TEST_ASSERT_EQUAL_INT8(4, ldw_y_longoff_y(instr)); 
  TEST_ASSERT_EQUAL_INT8(0xAE11, Y );
}
Exemplo n.º 10
0
//Assembly : (shortoff,Y) | ld A,($10,Y)
void test_ld_a_to_shortoff_y(void){
  SET_Y(0X2B11);
  uint8_t instr[] = {0XFB, 0X11};
  
  //0x2B11 + 0X11 = 0X2B22
  
  TEST_ASSERT_EQUAL_INT8(3, ld_a_to_shortoff_y(instr)); 
  TEST_ASSERT_EQUAL_INT8(0xAE, MEM_READ_BYTE(0X2B22));
}
Exemplo n.º 11
0
//Assembly : (Y) | and A,(Y)
void test_and_a_y(void){
  SET_Y(0X102B);
  uint8_t instr[] = {0XFB};

  MEM_WRITE_BYTE(0X102B , src);
  
  TEST_ASSERT_EQUAL_INT8(2, and_a_y(instr));
  TEST_ASSERT_EQUAL_INT8(0x8C, A);
}
Exemplo n.º 12
0
void test_swapw_y(void)
{
  SET_Y(0x0000);
  uint8_t instr[] = {0XAB};
  
  TEST_ASSERT_EQUAL_INT8(2, swapw_y(instr));
  TEST_ASSERT_EQUAL_INT16(0x0, Y); 
  TEST_ASSERT_EQUAL_INT8(0, N); 
  TEST_ASSERT_EQUAL_INT8(1, Z); 
}
Exemplo n.º 13
0
void test_cpw_x_longoff_y(void)
{
  SET_X(0x0122);
  SET_Y(0x2B11);
  uint8_t instr[] = {0XFB, 0X11, 0x11};
  MEM_WRITE_BYTE( 0X3c22 ,  0x05);  //0x2B11 + 0X1111 = 0X3c22
  
  TEST_ASSERT_EQUAL(4, cpw_x_longoff_y(instr));
  
}
Exemplo n.º 14
0
void test_ldw_y_y(void){
  SET_Y(0X102B);
  
  uint8_t instr[] = {0XFB};

  MEM_WRITE_WORD(0X102B , 0xAE11);
  
  TEST_ASSERT_EQUAL_INT8(2, ldw_y_y(instr));
  TEST_ASSERT_EQUAL_INT8(0xAE11, Y );
}
Exemplo n.º 15
0
void test_ldw_y_shortptr_w_y(void){ 
  SET_Y(0X0011);
  uint8_t instr[] = {0XFB, 0X13};
  
  MEM_WRITE_BYTE(0X13 , 0x11);  
  MEM_WRITE_BYTE(0X14 , 0x11);  
  MEM_WRITE_WORD(0x1122 , 0xAE11);  // 0X1111 + 0X11 = 0X1122
  
  TEST_ASSERT_EQUAL_INT8(3, ldw_y_shortptr_w_y(instr));  
  TEST_ASSERT_EQUAL_INT16(0xAE11, Y);
}
Exemplo n.º 16
0
//Assembly : ([shortptr.w],Y) ld A,([$10.w],Y)
// Please refer this instruction in page 50 of stm8 programming manual
void test_ld_a_to_shortptr_w_y(void){
  SET_Y(0X0011);
  uint8_t instr[] = {0XFB, 0X13};
  
  MEM_WRITE_BYTE(0X13 , 0x11);  
  MEM_WRITE_BYTE(0X14 , 0x11);  
  // 0X1111 + 0X11 = 0X1122
  
  TEST_ASSERT_EQUAL_INT8(3, ld_a_to_shortptr_w_y(instr));
  TEST_ASSERT_EQUAL_INT8(0xAE, MEM_READ_BYTE(0X1122));
}
Exemplo n.º 17
0
//Assembly : ([shortptr.w],Y) and A,([$10.w],Y)
// Please refer this instruction in page 50 of stm8 programming manual
void test_and_a_shortptr_w_y(void){
  SET_Y(0X0011);
  uint8_t instr[] = {0XFB, 0X13};
  
  MEM_WRITE_BYTE(0X13 , 0x11);  
  MEM_WRITE_BYTE(0X14 , 0x11);  
  MEM_WRITE_BYTE(0x1122 , src);  // 0X1111 + 0X11 = 0X1122
  
  TEST_ASSERT_EQUAL_INT8(3, and_a_shortptr_w_y(instr));
  TEST_ASSERT_EQUAL_INT8(0x8C, A);
}
Exemplo n.º 18
0
void test_cpw_x_y(void)
{
  SET_X(0x0122);
  SET_Y(0X102B);
  uint8_t instr[] = {0XFB};
  MEM_WRITE_BYTE( 0X102B ,  0x05);
  
  TEST_ASSERT_EQUAL(2, cpw_x_y(instr)); 
  TEST_ASSERT_EQUAL(0, V); 
  TEST_ASSERT_EQUAL(0, N); 
  TEST_ASSERT_EQUAL(0, Z); 
  TEST_ASSERT_EQUAL(0, C);
}
Exemplo n.º 19
0
void test_cpw_x_shortoff_y(void)
{
  SET_X(0x0122);
  SET_Y(0x2B11);
  uint8_t instr[] = {0XFB, 0X11};
  MEM_WRITE_BYTE( 0X2B22 ,  0x05);  //0x2B11 + 0X11 = 0X2B22
  
  TEST_ASSERT_EQUAL(3, cpw_x_shortoff_y(instr));
  TEST_ASSERT_EQUAL(0, V); 
  TEST_ASSERT_EQUAL(0, N); 
  TEST_ASSERT_EQUAL(0, Z); 
  TEST_ASSERT_EQUAL(0, C);
}
Exemplo n.º 20
0
void test_srlw_y(void){
  SET_Y(0x0764);
  uint8_t instr[] = {0XAB};
  
  N = 1;
  Z = 1;
  C = 1;
  
  TEST_ASSERT_EQUAL_INT8(2, srlw_y(instr));
  TEST_ASSERT_EQUAL_INT16(0x03B2, Y); 
  TEST_ASSERT_EQUAL_INT8(0, N); 
  TEST_ASSERT_EQUAL_INT8(0, Z); 
  TEST_ASSERT_EQUAL_INT8(0, C); 
}
Exemplo n.º 21
0
void test_pushw_y(void)
{
  YH = 0xAA;
  YL = 0xBB;
  SET_Y(0xAABB);
  
  uint8_t instr[] = {0XAB};

  uint8_t length = pushw_y(instr);
  TEST_ASSERT_EQUAL_INT8(0xBB, MEM_READ_BYTE(inputSP) ); 
  TEST_ASSERT_EQUAL_INT8(0xAA, MEM_READ_BYTE(inputSP_DEC) ); 
  TEST_ASSERT_EQUAL_INT16( inputSP-2 , SP ); // test is SP decreament 2 time
  TEST_ASSERT_EQUAL_INT8( 2, length ); 
}
Exemplo n.º 22
0
void test_cpw_x_shortptr_w_y(void)
{
  SET_X(0x0122);
  SET_Y(0x11);
  uint8_t instr[] = {0XFB, 0X13};  
  MEM_WRITE_BYTE( 0X13 , 0x11);  
  MEM_WRITE_BYTE( 0X14 , 0x11);  
  MEM_WRITE_BYTE( 0x1122 , 0x05);  // 0X1111 + 0X11 = 0X1122
  
  TEST_ASSERT_EQUAL(3, cpw_x_shortptr_w_y(instr));
  TEST_ASSERT_EQUAL(0, V); 
  TEST_ASSERT_EQUAL(0, N); 
  TEST_ASSERT_EQUAL(0, Z); 
  TEST_ASSERT_EQUAL(0, C);
}
Exemplo n.º 23
0
/**
@method copy_from( rect ) -> self
Sets @self to the same position and size as @rect.
This is meant for optimizations.
Returns @self.
*/
static VALUE rb_array_copy_from(VALUE self, VALUE rect)
{
	if(self==rect){
		return Qtrue;
	}

	Check_Type(rect, T_ARRAY);

	SET_X(array_get_x(rect));
	SET_Y(array_get_y(rect));
	SET_W(array_get_w(rect));
	SET_H(array_get_h(rect));

	return self;
}
Exemplo n.º 24
0
static VALUE rb_array_inflate_bang(VALUE self, VALUE size)
{
	normalize(self);
	{
		GET_X();
		GET_Y();
		GET_W();
		GET_H();
		double dx=array_get_x(size);
		double dy=array_get_y(size);
		SET_X(x-dx/2);
		SET_Y(y-dy/2);
		SET_W(w+dx);
		SET_H(h+dy);
	}
	return self;
}
Exemplo n.º 25
0
void setUp(void)
{
  instantiateCPU();
  
  // Set the ramMemory occupy the memoryTable from 0000 to FFFF, for testing purpose (FFFF / 100 = FF)
  ramBlock = createMemoryBlock(0, 0xFFFF);
  setMemoryTable( ramMemory , 0 , 0xFFFF); 

  A = 0x01;
  C = 0;    // default carry is 0
  
  SET_X(0X0040);
  SET_Y(0x1170);
  SET_SP(0x2290);
 
  MEM_WRITE_BYTE( X  ,  0x07);
  MEM_WRITE_BYTE( Y  ,  0x08);
  MEM_WRITE_BYTE( SP ,  0x09);
}
Exemplo n.º 26
0
__inline__ static void normalize(VALUE self)
{
	GET_W();
	GET_H();
	if(w<0){
		GET_X();
		x=x+w;
		w=-w;
		SET_X(x);
		SET_W(w);
	}
	if(h<0){
		GET_Y();
		y=y+h;
		h=-h;
		SET_Y(y);
		SET_H(h);
	}
}
Exemplo n.º 27
0
int Msmpot_compute(Msmpot *msm,
    float *epotmap,               /* electrostatic potential map
                                     assumed to be length mx*my*mz,
                                     stored flat in row-major order, i.e.,
                                     &ep[i,j,k] == ep + ((k*my+j)*mx+i) */
    int mx, int my, int mz,       /* map lattice dimensions */
    float lx, float ly, float lz, /* map lattice lengths */
    float x0, float y0, float z0, /* map origin (lower-left corner) */
    float vx, float vy, float vz, /* periodic cell lengths along x, y, z;
                                     set to 0 for non-periodic direction */
    const float *atom,            /* atoms stored x/y/z/q (length 4*natoms) */
    int natoms                    /* number of atoms */
    ) {
  int err;

  REPORT("Performing MSM calculation of electrostatic potential map.");

  err = Msmpot_check_params(msm, epotmap, mx, my, mz, lx, ly, lz,
      vx, vy, vz, atom, natoms);
  if (err != MSMPOT_SUCCESS) return ERROR(err);

  /* store user parameters */
  msm->atom = atom;
  msm->natoms = natoms;
  msm->epotmap = epotmap;
  msm->mx = mx;
  msm->my = my;
  msm->mz = mz;
  msm->lx = lx;
  msm->ly = ly;
  msm->lz = lz;
  msm->lx0 = x0;
  msm->ly0 = y0;
  msm->lz0 = z0;
  msm->dx = lx / mx;
  msm->dy = ly / my;
  msm->dz = lz / mz;
  msm->px = vx;
  msm->py = vy;
  msm->pz = vz;
  msm->isperiodic = 0;  /* reset flags for periodicity */
  /* zero length indicates nonperiodic direction */
  if (vx > 0) SET_X(msm->isperiodic);
  if (vy > 0) SET_Y(msm->isperiodic);
  if (vz > 0) SET_Z(msm->isperiodic);

  err = Msmpot_setup(msm);
  if (err != MSMPOT_SUCCESS) return ERROR(err);

  memset(epotmap, 0, mx*my*mz*sizeof(float));  /* clear epotmap */


#if !defined(MSMPOT_LONGRANGE_ONLY)
#ifdef MSMPOT_CUDA
  if (msm->use_cuda_shortrng) {
    err = Msmpot_cuda_compute_shortrng(msm->msmcuda);
    if (err && msm->cuda_optional) {  /* fall back on CPU */
#ifdef USE_BIN_HASHING
      err = Msmpot_compute_shortrng_bins(msm);
#else
      err = Msmpot_compute_shortrng_linklist(msm, msm->atom, msm->natoms);
#endif
      if (err) return ERROR(err);
    }
    else if (err) return ERROR(err);
  }
  else {
#ifdef USE_BIN_HASHING
    err = Msmpot_compute_shortrng_bins(msm);
#else
    err = Msmpot_compute_shortrng_linklist(msm, msm->atom, msm->natoms);
#endif /* USE_BIN_HASHING */
    if (err) return ERROR(err);
  }
#else
#ifdef USE_BIN_HASHING
  err = Msmpot_compute_shortrng_bins(msm);
#else
  err = Msmpot_compute_shortrng_linklist(msm, msm->atom, msm->natoms);
#endif /* USE_BIN_HASHING */
  if (err) return ERROR(err);
#endif
#endif

#if !defined(MSMPOT_SHORTRANGE_ONLY)
  err = Msmpot_compute_longrng(msm);
  if (err) return ERROR(err);
#endif

#ifdef MSMPOT_VERBOSE
#ifdef MSMPOT_CHECKMAPINDEX
  printf("epotmap[%d]=%g\n", MAPINDEX, epotmap[MAPINDEX]);
#endif
#endif

  return MSMPOT_SUCCESS;
}
Exemplo n.º 28
0
static VALUE rb_array_set_bottom(VALUE self, VALUE new_bottom)
{
	SET_Y(NUM2DBL(new_bottom)-array_get_h(self));
	return self;
}