view test/ps2.c @ 928:96c53f76b360

fix
author kono
date Sun, 13 Apr 2014 10:21:40 +0900
parents 5313ed059cee
children
line wrap: on
line source

#ifndef INLINE
#define INLINE
#endif

int printf(const char *,...);
void bzero(void *b, unsigned int len);


int align100 ;
int align101 __attribute__((aligned (16)));
int align102 __attribute__((aligned (8)));
char align103;
char align104;
int align105;
int align106 __attribute__((aligned (8)));

void *aligns[] = {
    &align100,
    &align101,
    &align102,
    &align103,
    &align104,
    &align105,
    &align106,
};

void *aligns1[] = {
    &align100,
    &align101,
    &align102,
    &align103,
    &align104,
    &align105,
    &align106
};


typedef float        ps2_vu0_fmatrix[4][4] __attribute__((aligned (16)));
typedef ps2_vu0_fmatrix FMATRIX;

typedef float        ps2_vu0_fmatrix1[4][4];
typedef ps2_vu0_fmatrix1 FMATRIX1;

typedef struct objNode {
    void* object;
    void (*mtd)(struct objNode*);
    void (*draw)(struct objNode*, FMATRIX, FMATRIX);
    struct objNode *next;
    struct objNode *parent;
    struct objNode *child;
} ObjNode, *ObjNodePtr;

INLINE void  draw(ObjNode *this, FMATRIX m, FMATRIX n)
{
    printf("#0054:work %g ",m[1][1]);
    printf("#0055:base %g\n",n[1][1]);
    m[1][1] += -0.7;
    n[1][1] += 0.7;
}

ObjNode c = {
    0, 0, draw, 0, 0, 0
};

ObjNode p = {
    0, 0, draw, &c, 0, &c
};


INLINE void
graphic_ObjNode_draw( ObjNode *this, FMATRIX base )
{
    FMATRIX work;
    bzero(&work,sizeof(work)); work[1][1] = 0.33;

    if(!this) return;
    if(this->mtd)  this->mtd( this );
    if(this->draw) this->draw( this, work, base );
    printf("#0078:offset draw %ld\n",(long)((char*)(&this->draw) - ((char*)&this->object)));
    printf("#0079:offset next %ld\n",(long)((char*)(&this->next) - ((char*)&this->object)));

    if(this->child) graphic_ObjNode_draw( this->child, work );
    if(this->next)  graphic_ObjNode_draw( this->next,  base );
    return;
}


INLINE void  ps2_vu0_unit_matrix(ps2_vu0_fmatrix m)
{
    printf("#0089:%g\n",m[1][1]);
    m[1][1] = -0.5;
}


#define mod16(a) (((long)(&a))%16)

int
align16(int i, FMATRIX a, FMATRIX b) {
   FMATRIX m;
   FMATRIX n;
   int k = i;
   FMATRIX o;
   if (i==0) return i;
#ifdef OFFSET
   printf("#0104:offset %ld\n",((char*)a) - ((char*)(&m)));
#endif
   printf("#0106:%ld %ld %ld\n",mod16(m),mod16(n),mod16(o));
   align16(i-1,m,n);
   return k;
}

int
align16_1(int i, FMATRIX1 a, FMATRIX1 b) {
   FMATRIX1 m;
   FMATRIX1 n;
   int k = i;
   FMATRIX1 o;
   if (i==0) return i;
#ifdef OFFSET
   printf("#0119:offset %ld\n",((char*)a) - ((char*)(&m)));
#endif
   printf("#0121:%ld %ld %ld\n",mod16(m),mod16(n),mod16(o));
   align16_1(i-1,m,n);
   return k;
}


int
main(int ac, char *av[])
{
    FMATRIX m;
    int i;
    int aligned = 10;

    m[1][1] = 0.5;
    ps2_vu0_unit_matrix(m);
    printf("#0136:%g %d\n",m[1][1],aligned);
    align16(2,m,m);
    align16_1(2,m,m);
    graphic_ObjNode_draw( &p, m);

    printf("#0141:sizeof(aligns)==%ld %ld\n",
        sizeof(aligns),sizeof(aligns1));
    printf("#0143:sizeof(aligns)/sizeof(void *)==%ld\n",
        sizeof(aligns)/sizeof(void *));

    for(i=0;i<sizeof(aligns)/sizeof(void *);i++) {
        printf("#0147:align10%d %ld\n",i,mod16(aligns[i]));
    }

}


/* end */