/* @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; }
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; } }
/** @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; }
//Assembly : (X) | ld A,(X) void test_ld_a_to_x(void){ SET_X(0X102B); uint8_t instr[] = {0XFB}; TEST_ASSERT_EQUAL_INT8(1, ld_a_to_x(instr)); TEST_ASSERT_EQUAL_INT8(0xAE, MEM_READ_BYTE(0X102B)); }
/* 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++); }
/** @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; }
void test_incw_x(void){ SET_X(0x2222); uint8_t instr[] = {0XAB}; TEST_ASSERT_EQUAL_INT8(1, incw_x(instr)); TEST_ASSERT_EQUAL_INT16(0x2223, X); }
//Assembly : (shortoff,X) | ld A,($10,X) void test_ld_a_to_shortoff_x(void){ SET_X(0X2B11); uint8_t instr[] = {0XFB, 0X11}; //0x2B11 + 0X11 = 0X2B22 TEST_ASSERT_EQUAL_INT8(2, ld_a_to_shortoff_x(instr)); TEST_ASSERT_EQUAL_INT8(0xAE, MEM_READ_BYTE(0X2B22)); }
void test_incw_x_set_V_flag(void){ SET_X(0x7FFF); uint8_t instr[] = {0XAB}; TEST_ASSERT_EQUAL_INT8(1, incw_x(instr)); TEST_ASSERT_EQUAL_INT16(0x8000, X); TEST_ASSERT_EQUAL_INT8(1, V); }
//Assembly : (longoff,X) | and A,($1000,X) void test_and_a_longoff_x(void){ SET_X(0X2B11); uint8_t instr[] = {0XFB, 0X11, 0x11}; MEM_WRITE_BYTE(0X3c22 , src); //0x2B11 + 0X1111 = 0X3c22 TEST_ASSERT_EQUAL_INT8(3, and_a_longoff_x(instr)); TEST_ASSERT_EQUAL_INT8(0x8C, A); }
//Assembly : (X) | and A,(X) void test_and_a_x(void){ SET_X(0X102B); uint8_t instr[] = {0XFB}; MEM_WRITE_BYTE(0X102B , src); TEST_ASSERT_EQUAL_INT8(1, and_a_x(instr)); TEST_ASSERT_EQUAL_INT8(0x8C, A); }
void test_ldw_x_longoff_x(void){ SET_X(0X2B11); uint8_t instr[] = {0XFB, 0X11, 0x11}; MEM_WRITE_WORD(0X3c22 , 0xAE11); //0x2B11 + 0X1111 = 0X3c22 TEST_ASSERT_EQUAL_INT8(3, ldw_x_longoff_x(instr)); TEST_ASSERT_EQUAL_INT8(0xAE11, X ); }
void test_cpw_x_shortoff_sp(void) { SET_X(0x0122); SET_SP(0x2B11); uint8_t instr[] = {0XFB, 0X11}; MEM_WRITE_BYTE( 0X2B22 , 0x05); //0x2B11 + 0X11 = 0X2B22 TEST_ASSERT_EQUAL(2, cpw_x_shortoff_sp(instr)); }
void test_ldw_x_x(void){ SET_X(0X102B); uint8_t instr[] = {0XFB}; MEM_WRITE_WORD(0X102B , 0xAE11); TEST_ASSERT_EQUAL_INT8(1, ldw_x_x(instr)); TEST_ASSERT_EQUAL_INT8(0xAE11, X ); }
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)); }
void test_swapw_x(void) { SET_X(0xBBCC); uint8_t instr[] = {0XAB}; TEST_ASSERT_EQUAL_INT8(1, swapw_x(instr)); TEST_ASSERT_EQUAL_INT16(0xCCBB, X); TEST_ASSERT_EQUAL_INT8(1, N); //bit 15 is 1 TEST_ASSERT_EQUAL_INT8(0, Z); }
//Assembly : ([shortptr.w],X) | ld A,([$10.w],X) // Please refer this instruction in page 50 of stm8 programming manual void test_ld_a_to_shortptr_w_x(void){ SET_X(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_x(instr)); TEST_ASSERT_EQUAL_INT8(0xAE, MEM_READ_BYTE(0x1122)); }
void test_ldw_x_shortptr_w_x(void){ SET_X(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_x_shortptr_w_x(instr)); TEST_ASSERT_EQUAL_INT16(0xAE11, X); }
void test_ldw_x_longptr_w_x(void){ SET_X(0X0011); uint8_t instr[] = {0XFB, 0X13, 0X00}; MEM_WRITE_BYTE(0X1300 , 0xAA ); MEM_WRITE_BYTE(0X1301 , 0xBB); MEM_WRITE_WORD(0xAACC , 0xAE11); // 0XAABB + 0X11 = 0XAACC TEST_ASSERT_EQUAL_INT8(4, ldw_x_longptr_w_x(instr)); TEST_ASSERT_EQUAL_INT16(0xAE11, X ); }
void test_cpw_x_word(void) { SET_X(0x0122); uint8_t instr[] = {0XAB, 0x0, 0X05}; TEST_ASSERT_EQUAL(3, cpw_x_word(instr)); TEST_ASSERT_EQUAL(0, V); TEST_ASSERT_EQUAL(0, N); TEST_ASSERT_EQUAL(0, Z); TEST_ASSERT_EQUAL(0, C); }
// Assembly : ([longptr.w],X) | and A,([$1000.w],X) // Please refer this instruction in page 50 of stm8 programming manual void test_and_a_longptr_w_x(void){ SET_X(0X0011); uint8_t instr[] = {0XFB, 0X13, 0X00}; MEM_WRITE_BYTE(0X1300 , 0xAA); MEM_WRITE_BYTE(0X1301 , 0xBB); MEM_WRITE_BYTE(0xAACC , src); // 0XAABB + 0X11 = 0XAACC TEST_ASSERT_EQUAL_INT8(4, and_a_longptr_w_x(instr)); TEST_ASSERT_EQUAL_INT8(0x8C, A); }
//Assembly : ([shortptr.w],X) | and A,([$10.w],X) // Please refer this instruction in page 50 of stm8 programming manual void test_and_a_shortptr_w_x(void){ SET_X(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_x(instr)); TEST_ASSERT_EQUAL_INT8(0x8C, A); }
// Assembly : ([longptr.w],X) | ld A,([$1000.w],X) // Please refer this instruction in page 50 of stm8 programming manual void test_ld_a_to_longptr_w_x(void){ SET_X(0X0011); uint8_t instr[] = {0XFB, 0X13, 0X00}; MEM_WRITE_BYTE(0X1300 , 0xAA); MEM_WRITE_BYTE(0X1301 , 0xBB); // 0XAABB + 0X11 = 0XAACC TEST_ASSERT_EQUAL_INT8(4, ld_a_to_longptr_w_x(instr)); TEST_ASSERT_EQUAL_INT8(0xAE, MEM_READ_BYTE(0XAACC)); }
void test_cpw_x_shortmem(void) { SET_X(0x0122); uint8_t addr = 0xAD; uint8_t instr[] = {0XBB, addr}; MEM_WRITE_BYTE( addr, 0x05); TEST_ASSERT_EQUAL(2, cpw_x_shortmem(instr)); TEST_ASSERT_EQUAL(0, V); TEST_ASSERT_EQUAL(0, N); TEST_ASSERT_EQUAL(0, Z); TEST_ASSERT_EQUAL(0, C); }
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); }
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); }
void test_srlw_x_make_Z_to_1_C_to_0(void){ SET_X(0x0); uint8_t instr[] = {0XAB}; N = 1; Z = 0; C = 1; TEST_ASSERT_EQUAL_INT8(1, srlw_x(instr)); TEST_ASSERT_EQUAL_INT16(0x0, X); TEST_ASSERT_EQUAL_INT8(0, N); TEST_ASSERT_EQUAL_INT8(1, Z); TEST_ASSERT_EQUAL_INT8(0, C); }
void test_srlw_x(void){ SET_X(0x8765); uint8_t instr[] = {0XAB}; N = 1; Z = 1; C = 0; TEST_ASSERT_EQUAL_INT8(1, srlw_x(instr)); TEST_ASSERT_EQUAL_INT16(0x43B2, X); TEST_ASSERT_EQUAL_INT8(0, N); TEST_ASSERT_EQUAL_INT8(0, Z); TEST_ASSERT_EQUAL_INT8(1, C); }
void test_pushw_x(void) { XH = 0xAA; XL = 0xBB; SET_X(0xAABB); uint8_t instr[] = {0XAB}; uint8_t length = pushw_x(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( 1, length ); }
void test_cpw_x_longmem(void) { SET_X(0x0122); uint8_t addrMSB = 0x11; uint8_t addrLSB = 0x01; uint8_t instr[] = {0XBB, addrMSB, addrLSB}; MEM_WRITE_BYTE( 0x1101, 0x05); TEST_ASSERT_EQUAL(3, cpw_x_longmem(instr)); TEST_ASSERT_EQUAL(0, V); TEST_ASSERT_EQUAL(0, N); TEST_ASSERT_EQUAL(0, Z); TEST_ASSERT_EQUAL(0, C); }