changeset 920:dd060540f50e

merge
author kazz <kazz@cr.ie.u-ryukyu.ac.jp>
date Mon, 26 Jul 2010 00:38:07 +0900
parents 1a5de2a29987 (current diff) 49b3c753e209 (diff)
children 58b5bbacb207
files Renderer/Engine/spe/DataLoad.cc Renderer/Engine/spe/DataLoad.h Renderer/Engine/task/DataLoad.cc Renderer/Engine/task/DataLoad.h
diffstat 40 files changed, 817 insertions(+), 428 deletions(-) [+]
line wrap: on
line diff
--- a/Renderer/Engine/Camera.cc	Mon Jul 26 00:37:26 2010 +0900
+++ b/Renderer/Engine/Camera.cc	Mon Jul 26 00:38:07 2010 +0900
@@ -148,10 +148,6 @@
 
 #if SPE_CREATE_POLYGON
 
-    sg_matrix = (float*)malloc(sizeof(float)*32);
-    matrix = sg_matrix;
-    real_matrix = sg_matrix + 16;
-
 #endif
 
     for(int i = 0; i < 16; i++) {
--- a/Renderer/Engine/Makefile.def	Mon Jul 26 00:37:26 2010 +0900
+++ b/Renderer/Engine/Makefile.def	Mon Jul 26 00:38:07 2010 +0900
@@ -5,7 +5,7 @@
 ABIBIT = 32 
 ABI = -m$(ABIBIT)
 CC      = g++
-OPT	= -g -O9 # -DSPE_CREATE_POLYGON=1
+OPT	= -g -O9 #-DSPE_CREATE_POLYGON_CHECK -DSPE_CREATE_POLYGON=1
 CFLAGS  = -g -Wall $(ABI) $(OPT)  #  -DDEBUG
 
 INCLUDE = -I$(CERIUM)/include/TaskManager -I.
--- a/Renderer/Engine/RenderingGlobal.h	Mon Jul 26 00:37:26 2010 +0900
+++ b/Renderer/Engine/RenderingGlobal.h	Mon Jul 26 00:38:07 2010 +0900
@@ -4,3 +4,7 @@
   Light,
   LightSwitch,
   LightSysSwitch,
+
+/*spe_create_polygon 用*/
+
+  SG_COORD,
--- a/Renderer/Engine/RenderingTasks.h	Mon Jul 26 00:37:26 2010 +0900
+++ b/Renderer/Engine/RenderingTasks.h	Mon Jul 26 00:38:07 2010 +0900
@@ -2,8 +2,9 @@
      SDL_INIT,
      FINISH,
 
-     DataLoad,
+     DataAllocate,
      DataUpdate,
+     DataFree,
 
      Create_SGP,
      Update_SGP,
--- a/Renderer/Engine/SceneGraph.cc	Mon Jul 26 00:37:26 2010 +0900
+++ b/Renderer/Engine/SceneGraph.cc	Mon Jul 26 00:38:07 2010 +0900
@@ -101,14 +101,6 @@
     init();
     finalize = &SceneGraph::finalize_copy;
 
-#if SPE_CREATE_POLYGON
-
-    sg_matrix = (float*)malloc(sizeof(float)*32);
-    matrix = sg_matrix;
-    real_matrix = sg_matrix + 16;
-
-#endif 
-
     this->name = "NULLPO";
 }
 
@@ -117,6 +109,7 @@
  */
 SceneGraph::SceneGraph(SceneGraphPtr orig)
 {
+
     init();
     memcpy(this, orig, sizeof(SceneGraph));
 
@@ -150,35 +143,26 @@
     //texture_info = (texture_list_ptr)manager->allocate(sizeof(texture_list));
     //data = new float[size*3*3];
 
-#if SPE_CREATE_POLYGON
+    for (int i = 0; i < 16; i++) {
+      matrix[i] = 0;
+      real_matrix[i] = 0;
+    }
+
+#if SPE_CREATE_POLYGON_CHECK
 
-    /* CreatePolygon を spe 側でやるために。
-       size は頂点の数。speに渡す場合には、16の倍数にして
-       16Kbyte以上の場合、16Kbyte毎に分割できるようにしなければならない。
-       CreatePolygonFromSceneGraphTaskをspeで動かすために、speに渡すのは 
-       TrianglePackでよい。
-       polygon_pack 1つには triangle が 128 になってる。polygon_pack の
-       triangle 数に合わせる方が楽だよね。なんか変な気もするけど、polygon
-       クラスにもTrianglePackを持たす。SceneGraph は自分の polygon 数が入る
-       分だけ、TrianglePackを持つ。CreatePolygonTask にはSceneGraph 側の
-       TrianglePack を input に、polygon_pack の TriganlePack を output とする
-    */ 
+    for (int i = 0; i < 16; i++) {
+      printf("%f\n",matrix[i]);
+      printf("r %f\n",real_matrix[i]);
+    }
 
-    int tri_pack_size = sizeof(TrianglePack)*(size/3);
-    printf("tri_pack_size %d\n", tri_pack_size);    
-    tri_pack = (TrianglePackPtr)manager->allocate(tri_pack_size);
-    texture_info = (texture_list*)manager->allocate(sizeof(texture_list));
-    sg_matrix = (float*)manager->allocate(sizeof(float)*32);
-    matrix = sg_matrix;
-    real_matrix = sg_matrix + 16;
-
-#else 
+#endif
 
     coord_xyz = (float*)manager->allocate(sizeof(float)*size*3);
     coord_tex = (float*)manager->allocate(sizeof(float)*size*3);
     normal    = (float*)manager->allocate(sizeof(float)*size*3);
 
-#endif
+    coord_pack_size = sizeof(float)*8*size*3;     // coord_pack_vertex size is 32byte. vertex num 3.
+    coord_pack = (float*)manager->allocate(coord_pack_size);
 
     get_data(manager, surface->children);
 
@@ -206,7 +190,7 @@
 
     size = 0;
     //data = NULL;
-
+  
 #if SPE_CREATE_POLYGON
 
     //tri_pack = NULL;
@@ -251,11 +235,10 @@
 
 #if SPE_CREATE_POLYGON
 
-    free(tri_pack);
-    free(sg_matrix);
-    //free(matrix);
-    //free(real_matrix);
-    free(texture_info);
+    free(coord_pack);
+    free(coord_xyz);
+    free(coord_tex);
+    free(normal);
 
 #else 
 
@@ -560,19 +543,6 @@
         texture_id = tex_id;
     }
 
-
-#if SPE_CREATE_POLYGON
-
-    
-      texture_info->t_w = list[texture_id].t_w;
-      texture_info->t_h = list[texture_id].t_h;;
-      texture_info->pixels_orig = list[texture_id].pixels_orig;
-      texture_info->pixels = list[texture_id].pixels;
-      texture_info->scale_max = list[texture_id].scale_max;
-      
-
-#else
-
       // こんなことすると list[] のいみあるのかなーと
       // 微妙に思う、自分で書き換えた感想 by gongo
       texture_info.t_w = list[texture_id].t_w;
@@ -580,8 +550,6 @@
       texture_info.pixels_orig = list[texture_id].pixels_orig;
       texture_info.pixels = list[texture_id].pixels;
       texture_info.scale_max = list[texture_id].scale_max;
-      
-#endif
 
 }
 
--- a/Renderer/Engine/SceneGraphRoot.cc	Mon Jul 26 00:37:26 2010 +0900
+++ b/Renderer/Engine/SceneGraphRoot.cc	Mon Jul 26 00:38:07 2010 +0900
@@ -412,7 +412,7 @@
 	    /*法線用の行列。Cameraの行列を抜いている(Cameraのコンストラクタで、単位行列にしている)*/
 	    get_matrix(c->real_matrix, c->angle, c->xyz, cur_parent->real_matrix);
 	    //get_matrix(c->real_matrix, c->angle, c->xyz, camera->real_matrix);
-	    
+
 	} 
 	
 	if (t->children != NULL && c != NULL) {
@@ -717,7 +717,8 @@
   void *e  = node->propertyptr;
   int move = node->move_id;
   PostFunction post_func = node->post_func;
-  sgroot->set_game_task(move, (void*)e, size, post_func);
+  SceneGraphRoot *sgroottmp = (SceneGraphRoot*)sgroot_;
+  sgroottmp->set_game_task(move, (void*)e, size, post_func);
 }
 
 void
--- a/Renderer/Engine/main.cc	Mon Jul 26 00:37:26 2010 +0900
+++ b/Renderer/Engine/main.cc	Mon Jul 26 00:38:07 2010 +0900
@@ -31,6 +31,8 @@
     int spenum = 1;
     video_type vtype = VTYPE_SDL;
 
+    int mem_flag = 0;
+
     for(int i = 1; argv[i]; ++i)
     {
 	if (strcmp(argv[i], "-bpp") == 0) {
@@ -53,6 +55,9 @@
 	    }
 	    i++;
 	}
+	if (strcmp(argv[i], "-mem") == 0) {
+	  mem_flag = 1;
+	}
     }
 
     Viewer *screen;
@@ -67,6 +72,7 @@
 	screen = new Viewer(manager, dev, bpp, width, height, spenum);
     }
     
+    screen->mem_flag = mem_flag;
     screen->run_init(manager, application());
 
     return 0;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Renderer/Engine/matrix.h	Mon Jul 26 00:38:07 2010 +0900
@@ -0,0 +1,20 @@
+#ifndef INCLUDED_MATRIX
+#define INCLUDED_MATRIX
+
+    struct MatrixList {
+      float *matrix;
+      MatrixList *next;
+      
+    };
+    
+    struct MatrixListInfo {
+      int id;
+      float *coord_pack;
+      int coord_pack_size;
+      int list_length;
+      MatrixList *first;
+      MatrixList *last;
+      MatrixListInfo *next;
+    };
+
+#endif
--- a/Renderer/Engine/polygon.cc	Mon Jul 26 00:37:26 2010 +0900
+++ b/Renderer/Engine/polygon.cc	Mon Jul 26 00:38:07 2010 +0900
@@ -190,47 +190,54 @@
 void Polygon::pickup_coordinate(char *cont)
 {
 
-#if SPE_CREATE_POLYGON
-
-    TrianglePackPtr cur = tri_pack;
-
-    for(int n=0; n<size; n+=3)
-    {
-
-        cont = pickup_float(cont, &cur->ver1.x);
-        cont = pickup_float(cont, &cur->ver1.y);
-        cont = pickup_float(cont, &cur->ver1.z);
+    char *tmp_cont = cont;
+    int bound = 8; // coord_vertex size is 8byte.
+    int offset = 0;
 
-        cont = pickup_float(cont, &cur->ver2.x);
-        cont = pickup_float(cont, &cur->ver2.y);
-        cont = pickup_float(cont, &cur->ver2.z);
+    for(int n=0; n<size*3; n+=3)
+    {
+        tmp_cont = pickup_float(tmp_cont, coord_xyz+n);
+        tmp_cont = pickup_float(tmp_cont, coord_xyz+n+1);
+        tmp_cont = pickup_float(tmp_cont, coord_xyz+n+2);
 
-        cont = pickup_float(cont, &cur->ver3.x);
-        cont = pickup_float(cont, &cur->ver3.y);
-        cont = pickup_float(cont, &cur->ver3.z);
-
-	cur = cur + 1;
-
-        if (cont == NULL)
+        if (tmp_cont == NULL)
         {
             cout << "Analyzing obj data failed coordinate\n";
         }
     }
 
-#else
+    tmp_cont = cont;
 
-    for(int n=0; n<size*3; n+=3)
+    for(int n=0; n<size; n++)
     {
-        cont = pickup_float(cont, coord_xyz+n);
-        cont = pickup_float(cont, coord_xyz+n+1);
-        cont = pickup_float(cont, coord_xyz+n+2);
+        tmp_cont = pickup_float(tmp_cont, coord_pack+n*bound+offset);
+        tmp_cont = pickup_float(tmp_cont, coord_pack+n*bound+offset+1);
+        tmp_cont = pickup_float(tmp_cont, coord_pack+n*bound+offset+2);
 
-        if (cont == NULL)
+        if (tmp_cont == NULL)
         {
             cout << "Analyzing obj data failed coordinate\n";
         }
     }
 
+#if SPE_CREATE_POLYGON_CHECK
+
+    for (int i = 0; i < size; i++) {
+
+      if (*(coord_xyz+i*3) != *(coord_pack+i*bound+offset)) {
+	printf("hoge\n");
+      }
+
+      if (*(coord_xyz+i*3+1) != *(coord_pack+i*bound+offset+1)) {
+	printf("hoge\n");
+      }
+
+      if (*(coord_xyz+i*3+2) != *(coord_pack+i*bound+offset+2)) {
+	printf("hoge\n");
+      }
+
+    }
+
 #endif
 
 }
@@ -238,46 +245,52 @@
 void Polygon::pickup_normal(char *cont)
 {
 
-#if SPE_CREATE_POLYGON
-
-    TrianglePackPtr cur = tri_pack;
+    char *tmp_cont = cont;
+    int bound = 8; // coord_pack size is 8byte.
+    int offset = 5; // coord_pack (xyz(3) + tex_x,tex_y(2) + n_xyz(3))
 
-    for(int n=0; n<size; n+=3)
+    for (int n = 0; n<size*3; n += 3)
     {
-
-        cont = pickup_float(cont, &cur->normal1.x);
-        cont = pickup_float(cont, &cur->normal1.y);
-        cont = pickup_float(cont, &cur->normal1.z);
+        tmp_cont = pickup_float(tmp_cont, normal+n);
+        tmp_cont = pickup_float(tmp_cont, normal+n+1);
+        tmp_cont = pickup_float(tmp_cont, normal+n+2);
 
-        cont = pickup_float(cont, &cur->normal2.x);
-        cont = pickup_float(cont, &cur->normal2.y);
-        cont = pickup_float(cont, &cur->normal2.z);
+        if (tmp_cont == NULL)
+        {
+            cout << "Analyzing obj data failed normal\n";
+        }
+    }
+
+    tmp_cont = cont;
 
-        cont = pickup_float(cont, &cur->normal3.x);
-        cont = pickup_float(cont, &cur->normal3.y);
-        cont = pickup_float(cont, &cur->normal3.z);
+    for(int n=0; n<size; n++)
+    {
+        tmp_cont = pickup_float(tmp_cont, coord_pack+n*bound+offset);
+        tmp_cont = pickup_float(tmp_cont, coord_pack+n*bound+offset+1);
+        tmp_cont = pickup_float(tmp_cont, coord_pack+n*bound+offset+2);
 
-	cur = cur + 1;
-
-        if (cont == NULL)
+        if (tmp_cont == NULL)
         {
             cout << "Analyzing obj data failed coordinate\n";
         }
     }
 
-#else
+#if SPE_CREATE_POLYGON_CHECK
+
+    for (int i = 0; i < size; i++) {
 
+      if (*(normal+i*3) != *(coord_pack+i*bound+offset)) {
+	printf("hoge\n");
+      }
 
-    for (int n = 0; n<size*3; n += 3)
-    {
-        cont = pickup_float(cont, normal+n);
-        cont = pickup_float(cont, normal+n+1);
-        cont = pickup_float(cont, normal+n+2);
+      if (*(normal+i*3+1) != *(coord_pack+i*bound+offset+1)) {
+	printf("hoge\n");
+      }
 
-        if (cont == NULL)
-        {
-            cout << "Analyzing obj data failed normal\n";
-        }
+      if (*(normal+i*3+2) != *(coord_pack+i*bound+offset+2)) {
+	printf("hoge\n");
+      }
+
     }
 
 #endif
@@ -299,42 +312,48 @@
 void Polygon::pickup_texture(char *cont)
 {
 
-#if SPE_CREATE_POLYGON
-
-    TrianglePackPtr cur = tri_pack;
+    char *tmp_cont = cont;
+    int bound = 8; // coord_pack size is 8byte.
+    int offset = 3; // coord_pack (xyz(3) + tex_x,tex_y(2) + n_xyz(3))
 
-    for(int n=0; n<size; n+=3)
+    for (int n = 0; n < size*3; n += 3)
     {
-
-        cont = pickup_float(cont, &cur->ver1.tex_x);
-        cont = pickup_float(cont, &cur->ver1.tex_y);
+        tmp_cont = pickup_float(tmp_cont, coord_tex+n);
+        tmp_cont = pickup_float(tmp_cont, coord_tex+n+1);
+        coord_tex[n+2] = 1.0;
 
-        cont = pickup_float(cont, &cur->ver2.tex_x);
-        cont = pickup_float(cont, &cur->ver2.tex_y);
+        if (tmp_cont == NULL)
+        {
+            cout << "Analyzing obj data failed texture\n";
+        }
+    }
 
-        cont = pickup_float(cont, &cur->ver3.tex_x);
-        cont = pickup_float(cont, &cur->ver3.tex_y);
+    tmp_cont = cont;
 
-	cur = cur + 1;
+    for(int n=0; n<size; n++)
+    {
+        tmp_cont = pickup_float(tmp_cont, coord_pack+n*bound+offset);
+        tmp_cont = pickup_float(tmp_cont, coord_pack+n*bound+offset+1);
 
-        if (cont == NULL)
+        if (tmp_cont == NULL)
         {
             cout << "Analyzing obj data failed coordinate\n";
         }
     }
 
-#else
+#if SPE_CREATE_POLYGON_CHECK
+
+    for (int i = 0; i < size; i++) {
 
-    for (int n = 0; n < size*3; n += 3)
-    {
-        cont = pickup_float(cont, coord_tex+n);
-        cont = pickup_float(cont, coord_tex+n+1);
-        coord_tex[n+2] = 1.0;
+      if (*(coord_tex+i*3) != *(coord_pack+i*bound+offset)) {
+	printf("hoge\n");
+      }
 
-        if (cont == NULL)
-        {
-            cout << "Analyzing obj data failed texture\n";
-        }
+      if (*(coord_tex+i*3+1) != *(coord_pack+i*bound+offset+1)) {
+	printf("hoge\n");
+      }
+
+
     }
 
 #endif
--- a/Renderer/Engine/polygon.h	Mon Jul 26 00:37:26 2010 +0900
+++ b/Renderer/Engine/polygon.h	Mon Jul 26 00:38:07 2010 +0900
@@ -16,16 +16,6 @@
     //float *data;    //"vertex" and "normal" and "texture"
     int coord_pack_size;
 
-#if SPE_CREATE_POLYGON
-
-    TrianglePackPtr tri_pack;
-    float *sg_matrix;
-    float *matrix;
-    float *real_matrix;
-    texture_list *texture_info;
-
-#else
-
     float *coord_pack; //coord_xyz(4*3*size), coord_tex(4*3*size), normal(4*3*size), 
     float *coord_xyz; // vertex coordinate array
     float *coord_tex; // texture coordinate array
@@ -34,8 +24,6 @@
     float real_matrix[16];
     texture_list texture_info;
 
-#endif
-
     float xyz[4];     // position
     float angle[4];   // angle
     float c_xyz[4];   // center of rotation
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Renderer/Engine/spe/DataAllocate.cc	Mon Jul 26 00:38:07 2010 +0900
@@ -0,0 +1,25 @@
+#include <stdio.h>
+#include <string.h>
+#include "DataAllocate.h"
+#include "Func.h"
+
+/* これは必須 */
+SchedDefineTask(DataAllocate);
+
+static int
+run(SchedTask *s, void *rbuf, void *wbuf)
+{
+
+  void *idata = s->get_input(rbuf, 0);
+  long size = (long)s->get_param(0);
+  long load_id = (long)s->get_param(1);
+
+  void *buff = s->global_alloc(load_id, size);
+
+  if (idata != NULL) {
+    memcpy(buff,idata,size);
+  }
+
+  return 0;
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Renderer/Engine/spe/DataAllocate.h	Mon Jul 26 00:38:07 2010 +0900
@@ -0,0 +1,9 @@
+#ifndef INCLUDED_TASK_ALLOCATE
+#define INCLUDED_TASK_ALLOCATE
+
+#ifndef INCLUDED_SCHED_TASK
+#  include "SchedTask.h"
+#endif
+
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Renderer/Engine/spe/DataFree.cc	Mon Jul 26 00:38:07 2010 +0900
@@ -0,0 +1,24 @@
+#include <stdio.h>
+#include <string.h>
+#include "DataFree.h"
+#include "Func.h"
+
+/* これは必須 */
+SchedDefineTask(DataFree);
+
+static int
+run(SchedTask *s, void *rbuf, void *wbuf)
+{
+
+  long load_id = (long)s->get_param(0);
+
+  //printf("size %d",sizeof(float)*length);
+
+  s->global_free(load_id);
+
+  //MemList *ml = s->createMemList(length,length);
+  //s->global_set(load_id, (void *)ml);
+
+  return 0;
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Renderer/Engine/spe/DataFree.h	Mon Jul 26 00:38:07 2010 +0900
@@ -0,0 +1,9 @@
+#ifndef INCLUDED_TASK_FREE
+#define INCLUDED_TASK_FREE
+
+#ifndef INCLUDED_SCHED_TASK
+#  include "SchedTask.h"
+#endif
+
+
+#endif
--- a/Renderer/Engine/spe/DataLoad.cc	Mon Jul 26 00:37:26 2010 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,20 +0,0 @@
-#include <stdio.h>
-#include <string.h>
-#include "DataLoad.h"
-#include "Func.h"
-
-/* これは必須 */
-SchedDefineTask(DataLoad);
-
-static int
-run(SchedTask *s, void *rbuf, void *wbuf)
-{
-
-  long size = (long)s->get_param(0);
-  long load_id = (long)s->get_param(1);
-
-  s->global_alloc(load_id, size);
-
-  return 0;
-}
-
--- a/Renderer/Engine/spe/DataLoad.h	Mon Jul 26 00:37:26 2010 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,9 +0,0 @@
-#ifndef INCLUDED_TASK_LOAD
-#define INCLUDED_TASK_LOAD
-
-#ifndef INCLUDED_SCHED_TASK
-#  include "SchedTask.h"
-#endif
-
-
-#endif
--- a/Renderer/Engine/spe/DrawSpan.cc	Mon Jul 26 00:37:26 2010 +0900
+++ b/Renderer/Engine/spe/DrawSpan.cc	Mon Jul 26 00:38:07 2010 +0900
@@ -503,7 +503,12 @@
     int rangex = rangex_end - rangex_start + 1;
     int rangey = (long)smanager->get_param(4);
 
-    linebuf_init(smanager, rangex, rangey, 0);
+    for(int h = 0; h < rangey; h++) {
+	int *buf = (int*)smanager->get_output(h);
+	for (int i = 0; i < rangex; i++) {
+	    buf[i] = 0;
+	}
+    }
 
     return 0;
 
--- a/Renderer/Engine/spe/spe-main.cc	Mon Jul 26 00:37:26 2010 +0900
+++ b/Renderer/Engine/spe/spe-main.cc	Mon Jul 26 00:38:07 2010 +0900
@@ -1,8 +1,9 @@
 #include "../Func.h"
 #include "SchedTask.h"
 
-SchedExternTask(DataLoad);
+SchedExternTask(DataAllocate);
 SchedExternTask(DataUpdate);
+SchedExternTask(DataFree);
 
 SchedExternTask(LoadTexture);
 SchedExternTask(DrawSpan);
@@ -30,8 +31,9 @@
 task_init(Scheduler *s)
 {
 
-    SchedRegister( DataLoad);
+    SchedRegister( DataAllocate);
     SchedRegister( DataUpdate);
+    SchedRegister( DataFree);
 
     SchedRegister( LoadTexture);
     SchedRegister( DrawSpan);
--- a/Renderer/Engine/spe/viewer_types.cc	Mon Jul 26 00:37:26 2010 +0900
+++ b/Renderer/Engine/spe/viewer_types.cc	Mon Jul 26 00:38:07 2010 +0900
@@ -1,30 +0,0 @@
-#include "viewer_types.h"
-
-int
-getLocalPosition(int d, int offset)
-{
-    return d & (offset-1);
-}
-
-/**
- * ワールド座標における x の値を
- * split_screen_w で分割した領域(1 〜 split_screen_w)での座標に変換する
- * (ex. split_screen_w が 256 の場合、
- *      x =   1 -> 1
- *      x = 256 -> 256
- *      x = 257 -> 1
- */
-int
-getLocalX(int x)
-{
-    return getLocalPosition(x, split_screen_w);
-}
-
-/**
- * getLocalX に同じ
- */
-int
-getLocalY(int y)
-{
-    return getLocalPosition(y, split_screen_h);
-}
--- a/Renderer/Engine/task/CreatePolygonFromSceneGraph.cc	Mon Jul 26 00:37:26 2010 +0900
+++ b/Renderer/Engine/task/CreatePolygonFromSceneGraph.cc	Mon Jul 26 00:38:07 2010 +0900
@@ -15,7 +15,6 @@
 #define PP_LOAD 12
 #define PP_STORE 13
 
-#if !SPE_CREATE_POLYGON
 /**
  *  ベクトルに行列を乗算する
  * @param[out] v vector (float[4])
@@ -49,7 +48,6 @@
         v[i] = t[0]*m[i] + t[1]*m[i+4] + t[2]*m[i+8];
     }
 }
-#endif
 
 
 /**
@@ -76,7 +74,6 @@
 run(SchedTask *smanager, void *rbuf, void *wbuf)
 {
 
-#if !SPE_CREATE_POLYGON
 
     float xyz1[4], xyz2[4], xyz3[4];
     float normal1[4],normal2[4],normal3[4];
@@ -249,8 +246,6 @@
     free(pp);
     free(send_pp);
 
-
-#endif
     return 0;
 
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Renderer/Engine/task/DataAllocate.cc	Mon Jul 26 00:38:07 2010 +0900
@@ -0,0 +1,25 @@
+#include <stdio.h>
+#include <string.h>
+#include "DataAllocate.h"
+#include "Func.h"
+
+/* これは必須 */
+SchedDefineTask(DataAllocate);
+
+static int
+run(SchedTask *s, void *rbuf, void *wbuf)
+{
+
+  long size = (long)s->get_param(0);
+  long load_id = (long)s->get_param(1);
+
+  //printf("size %d",sizeof(float)*length);
+
+  s->global_alloc(load_id, size);
+
+  //MemList *ml = s->createMemList(length,length);
+  //s->global_set(load_id, (void *)ml);
+
+  return 0;
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Renderer/Engine/task/DataAllocate.h	Mon Jul 26 00:38:07 2010 +0900
@@ -0,0 +1,9 @@
+#ifndef INCLUDED_TASK_ALLOCATE
+#define INCLUDED_TASK_ALLOCATE
+
+#ifndef INCLUDED_SCHED_TASK
+#  include "SchedTask.h"
+#endif
+
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Renderer/Engine/task/DataFree.cc	Mon Jul 26 00:38:07 2010 +0900
@@ -0,0 +1,24 @@
+#include <stdio.h>
+#include <string.h>
+#include "DataFree.h"
+#include "Func.h"
+
+/* これは必須 */
+SchedDefineTask(DataFree);
+
+static int
+run(SchedTask *s, void *rbuf, void *wbuf)
+{
+
+  long load_id = (long)s->get_param(0);
+
+  //printf("size %d",sizeof(float)*length);
+
+  s->global_free(load_id);
+
+  //MemList *ml = s->createMemList(length,length);
+  //s->global_set(load_id, (void *)ml);
+
+  return 0;
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Renderer/Engine/task/DataFree.h	Mon Jul 26 00:38:07 2010 +0900
@@ -0,0 +1,9 @@
+#ifndef INCLUDED_TASK_FREE
+#define INCLUDED_TASK_FREE
+
+#ifndef INCLUDED_SCHED_TASK
+#  include "SchedTask.h"
+#endif
+
+
+#endif
--- a/Renderer/Engine/task/DataLoad.cc	Mon Jul 26 00:37:26 2010 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,25 +0,0 @@
-#include <stdio.h>
-#include <string.h>
-#include "DataLoad.h"
-#include "Func.h"
-
-/* これは必須 */
-SchedDefineTask(DataLoad);
-
-static int
-run(SchedTask *s, void *rbuf, void *wbuf)
-{
-
-  long size = (long)s->get_param(0);
-  long load_id = (long)s->get_param(1);
-
-  //printf("size %d",sizeof(float)*length);
-
-  s->global_alloc(load_id, size);
-
-  //MemList *ml = s->createMemList(length,length);
-  //s->global_set(load_id, (void *)ml);
-
-  return 0;
-}
-
--- a/Renderer/Engine/task/DataLoad.h	Mon Jul 26 00:37:26 2010 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,9 +0,0 @@
-#ifndef INCLUDED_TASK_LOAD
-#define INCLUDED_TASK_LOAD
-
-#ifndef INCLUDED_SCHED_TASK
-#  include "SchedTask.h"
-#endif
-
-
-#endif
--- a/Renderer/Engine/task/DrawSpan.cc	Mon Jul 26 00:37:26 2010 +0900
+++ b/Renderer/Engine/task/DrawSpan.cc	Mon Jul 26 00:38:07 2010 +0900
@@ -484,7 +484,12 @@
     int rangex = rangex_end - rangex_start + 1;
     int rangey = (long)smanager->get_param(4);
 
-    linebuf_init(smanager, rangex, rangey, 0);
+    for(int h = 0; h < rangey; h++) {
+	int *buf = (int*)smanager->get_output(h);
+	for (int i = 0; i < rangex; i++) {
+	    buf[i] = 0;
+	}
+    }
 
     return 0;
 
--- a/Renderer/Engine/task/task_init.cc	Mon Jul 26 00:37:26 2010 +0900
+++ b/Renderer/Engine/task/task_init.cc	Mon Jul 26 00:38:07 2010 +0900
@@ -1,8 +1,9 @@
 #include "../Func.h"
 #include "Scheduler.h"
 
-SchedExternTask(DataLoad);
+SchedExternTask(DataAllocate);
 SchedExternTask(DataUpdate);
+SchedExternTask(DataFree);
 
 SchedExternTask(Create_SGP);
 SchedExternTask(Update_SGP);
@@ -41,8 +42,9 @@
 void
 task_initialize()
 {
-    SchedRegister( DataLoad);
+    SchedRegister( DataAllocate);
     SchedRegister( DataUpdate);
+    SchedRegister( DataFree);
 
     SchedRegister( Create_SGP);
     SchedRegister( Update_SGP);
--- a/Renderer/Engine/viewer.cc	Mon Jul 26 00:37:26 2010 +0900
+++ b/Renderer/Engine/viewer.cc	Mon Jul 26 00:38:07 2010 +0900
@@ -39,6 +39,7 @@
 int spackList_length;
 int spackList_length_align;
 
+
 /**
  *
  */
@@ -118,9 +119,10 @@
       light_xyz[i] = 0.0f;
     }
 
+
     for(int i = 0; i < spe_num; i++) {
 
-	HTaskPtr data_load = manager->create_task(DataLoad);
+      HTaskPtr data_load = manager->create_task(DataAllocate);
 	data_load->set_param(0,(memaddr)size);
 	data_load->set_param(1,(memaddr)Light);
 	data_load->set_cpu((CPU_TYPE)((int)SPE_0 + i));
@@ -135,7 +137,7 @@
     }
 
     for(int i = 0; i < spe_num; i++) {
-	HTaskPtr data_load = manager->create_task(DataLoad);
+	HTaskPtr data_load = manager->create_task(DataAllocate);
 	data_load->set_param(0,(memaddr)size);
 	data_load->set_param(1,(memaddr)LightSwitch);
 	data_load->set_cpu((CPU_TYPE)((int)SPE_0 + i));
@@ -151,7 +153,7 @@
     }
 
     for(int i = 0; i < spe_num; i++) {
-	HTaskPtr data_load = manager->create_task(DataLoad);
+	HTaskPtr data_load = manager->create_task(DataAllocate);
 	data_load->set_param(0,(memaddr)size);
 	data_load->set_param(1,(memaddr)LightSysSwitch);
 	data_load->set_cpu((CPU_TYPE)((int)SPE_0 + i));
@@ -175,7 +177,7 @@
 
     spackList_length = (this->height + split_screen_h - 1) / split_screen_h;
     spackList = (SpanPack*)manager->allocate(sizeof(SpanPack)*spackList_length);
-printf("spackList %0x height %d\n",(unsigned int)spackList, this->height);
+    // printf("spackList %0lx height %d\n",(unsigned long)spackList, this->height);
 
     /**
      * SPU に送る address list は 16 バイト倍数でないといけない。
@@ -439,28 +441,249 @@
     frames++;
 }
 
-#if SPE_CREATE_POLYGON
+
+// 完全にMac仕様。。sg_matrix を allocate してやらないといけないよ。
+float*
+copy_matrix(SceneGraphPtr sg, TaskManager *manager) {
+
+  float *matrix = sg->matrix;
+  float *real_matrix = sg->real_matrix;
+
+  //変換行列は4x4 なんで、16。が二つで32.と言い訳を書いてみる。
+  float *sg_matrix = (float*)manager->allocate(sizeof(float)*32);
+
+  for (int i = 0; i < 16; i++) {
+    sg_matrix[i] = matrix[i];
+    sg_matrix[i+16] = real_matrix[i];
+  }
+
+  return sg_matrix;
+
+}
+
+void
+print_matrix(float *matrix) {
+
+  for (int i = 0; i < 32; i++) {
+    printf("%f\n",matrix[i]);
+  }
+
+}
+
+void
+add_matrix_list(SceneGraphPtr sg, TaskManager *manager, MatrixListInfo* info) {
+
+    MatrixList *matrix_list = (MatrixList*)manager->allocate(sizeof(MatrixList));
+
+#if SPE_CREATE_POLYGON_CHECK
+    print_matrix(sg->sg_matrix);
+#endif    
+
+    matrix_list->matrix = copy_matrix(sg, manager);;
+    matrix_list->next = NULL;
+
+    
+    if (info->last != NULL) {
+        info->last->next = matrix_list;
+    }
+
+    info->last = matrix_list;
+    info->list_length += 1;
+
+}
 
 void
-Viewer::create_pp_task(SceneGraphPtr sg, PolygonPackPtr pp_cur, HTaskPtr create_pp_wait,
-		       int &pp_index, int &sg_index, int tri_num) 
+new_matrix_info(SceneGraphPtr sg, TaskManager *manager, MatrixListInfo* info) {
+
+    MatrixListInfo *next = NULL;
+
+  if (info->id == -1) {
+
+    info->id = sg->sgid;
+    info->list_length = 1;
+    info->coord_pack = sg->coord_pack;
+    info->coord_pack_size = sg->coord_pack_size;
+    next = info;
+
+  } else {
+
+    MatrixListInfo* t;
+
+    for (t = info; t->next != NULL; t = t->next) {
+    }
+
+    next = (MatrixListInfo*)manager->allocate(sizeof(MatrixListInfo));
+    next->id = sg->sgid;
+    next->list_length = 1;
+    next->coord_pack = sg->coord_pack;
+    next->coord_pack_size = sg->coord_pack_size;
+    next->next = NULL;
+    t->next = next;
+
+  }
+
+    MatrixList *new_list = (MatrixList*)manager->allocate(sizeof(MatrixList));
+    new_list->matrix = copy_matrix(sg, manager);
+
+#if SPE_CREATE_POLYGON_CHECK
+    print_matrix(sg->sg_matrix);
+#endif
+
+    new_list->next = NULL;
+
+    next->first = new_list;
+    next->last = new_list;
+
+}
+
+void
+collect_matrix(SceneGraphPtr sg, MatrixListInfo *matrix_info, TaskManager *manager) {
+  
+  matrix_info->id = -1;
+  matrix_info->list_length = 0;
+  matrix_info->next = NULL;
+  matrix_info->first = NULL;
+  matrix_info->last = NULL;
+
+  while (sg) {
+    
+    if (sg->flag_drawable) {
+      
+      int flag = 0;
+      
+      for (MatrixListInfo* t = matrix_info; t != NULL; t = t->next) {
+	if (sg->sgid == t->id) {
+	  add_matrix_list(sg, manager, t);
+	  flag = 1;
+	}	    	    	    
+      }
+      
+      if (flag != 1) {
+	new_matrix_info(sg, manager, matrix_info);  
+      }
+      
+      // search SceneGraph. でも、ただのリストがあったハズだから、あとでそれに直す。はず・・
+      if (sg->children != NULL) {
+	  sg = sg->children;
+      } else if (sg->brother != NULL) {
+	sg = sg->brother;
+      } else {
+	while (sg) {
+	  if (sg->brother != NULL) {
+	    sg = sg->brother;
+	      break;
+	  } else {
+	    if (sg->parent == NULL) {
+	      sg = NULL;
+	      break;
+	    } else {
+	      sg = sg->parent;
+	    }
+	  }
+	}
+      } 
+    } 
+  }
+}
+
+void
+check_matrix(MatrixListInfo *matrix_info,SceneGraphPtr sg) {
+
+  for (MatrixListInfo* t = matrix_info; t != NULL; t = t->next) {
+    for (MatrixList* u = t->first; u != NULL; u = u->next) {
+      print_matrix(u->matrix);
+    }
+  }
+
+}
+
+
+void
+coord_allocate(int &cur_point, float *coord_pack, int spe_num,
+	       int alloc_size, HTaskPtr alloc_wait, TaskManager *manager)
 {
 
-    HTaskPtr create_pp = manager->create_task(CreatePolygon);
-    create_pp->set_inData(0, &sg->tri_pack[sg_index], sizeof(TrianglePack)*tri_num);
-    create_pp->set_inData(1, sg->texture_info, sizeof(texture_list));
-    create_pp->set_inData(2, sg->sg_matrix, sizeof(float)*32); //わーい、マジックナンバー
-    create_pp->set_outData(0, &pp_cur->tri[pp_index], sizeof(TrianglePack)*tri_num);
-    create_pp->set_param(0, (memaddr)tri_num);
-    //create_pp->set_cpu(SPE_ANY);
-    create_pp_wait->wait_for(create_pp);
-    create_pp->spawn();
+  for (int i = 0; i < spe_num; i++) {
+
+    HTaskPtr data_alloc = manager->create_task(DataAllocate);
+    //data_alloc->set_inData(0, &coord_pack[cur_point], alloc_size);
+    data_alloc->set_param(0,(memaddr)alloc_size);
+    data_alloc->set_param(1,(memaddr)SG_COORD);
+    data_alloc->set_cpu((CPU_TYPE)((int)SPE_0 + i));
+    alloc_wait->wait_for(data_alloc);
+    data_alloc->spawn();
+ 
+  } 
+
+  cur_point += alloc_size / sizeof(float);
 
-    pp_index += tri_num;
-    sg_index += tri_num;
+}
+
+void
+coord_free(int spe_num, TaskManager *manager, HTaskPtr alloc_wait)
+{
+
+  for (int i = 0; i < spe_num; i++) {
+
+    HTaskPtr data_free = manager->create_task(DataFree);
+    data_free->set_param(0,(memaddr)SG_COORD);
+    data_free->set_cpu((CPU_TYPE)((int)SPE_0 + i));
+    data_free->wait_for(alloc_wait);
+    data_free->spawn();
+ 
+  } 
+
 }
 
-#endif
+void
+create_pp_task(SceneGraphPtr sg, TaskManager *manager, int spe_num, HTaskPtr task_next)
+{
+
+  MatrixListInfo *matrix_info = (MatrixListInfo*)manager->allocate(sizeof(MatrixListInfo));
+  collect_matrix(sg, matrix_info, manager);
+
+
+  //HTaskPtr phase_wait = manager->create_task(Dummy);
+
+  for (MatrixListInfo* t = matrix_info; t != NULL; t = t->next) {
+
+    printf("list_length %d \n", t->list_length);
+
+    int alloc_size = 16*1024;
+
+    if (t->coord_pack_size < alloc_size) {
+      alloc_size = t->coord_pack_size;
+    }
+
+
+    int division_num = (t->coord_pack_size + alloc_size - 1) / alloc_size;
+    int phase_num = (division_num + spe_num -1) / spe_num;
+    int cur_point = 0;
+
+    for (int i = 0; i < phase_num; i++) {
+      
+      HTaskPtr alloc_wait = manager->create_task(Dummy);
+      coord_allocate(cur_point, t->coord_pack, spe_num,
+		     alloc_size, alloc_wait, manager);
+
+
+      for (MatrixList* u = t->first; u != NULL; u = u->next) {
+
+	//HTaskPtr free_wait = manager->create_task(Dummy);
+	
+	//phase_wait = manager->create_task(Dummy);
+	
+      }
+
+      coord_free(spe_num, manager, alloc_wait);
+      alloc_wait->spawn();
+    }
+  }
+
+  printf("-----------------------\n");
+  //return create_pp_wait;
+
+}
 
 void
 Viewer::common_rendering(HTaskPtr task_next, SceneGraphRoot *sgroot)
@@ -468,119 +691,18 @@
 
 #if SPE_CREATE_POLYGON
 
-  SceneGraphPtr sg = sgroot->getDrawSceneGraph();
-  PolygonPackPtr pp_cur = ppack;
-  HTaskPtr create_pp_wait = manager->create_task(Dummy);
-  int pp_index = 0;
-
-  pp_cur->init();
-
-  task_next->wait_for(create_pp_wait);
-
-  while (sg) {
-    
-    if (sg->flag_drawable) {
-
-      int sum_size = sg->size;
-      int tri_cur_num = MAX_SIZE_TRIANGLE;
-      int sg_index = 0;
+    SceneGraphPtr sg = sgroot->getDrawSceneGraph();
 
-      while (sum_size) {
-	
-	  tri_cur_num -= sg->size/3;
-	
-	  if (tri_cur_num < 0) {
-	    
-	      tri_cur_num = MAX_SIZE_TRIANGLE;
-	      create_pp_task(sg, pp_cur, create_pp_wait,
-			     pp_index, sg_index, tri_cur_num);
-	     
-	      PolygonPackPtr next = (PolygonPackPtr)manager->allocate(sizeof(PolygonPack));
-	      next->init();
-
-	      pp_cur->next = next;
-	      pp_cur       = next;
-	      pp_index = 0;
-	      
-	  } else {
-	  
-	      create_pp_task(sg, pp_cur, create_pp_wait,
-			     pp_index, sg_index, tri_cur_num);
-
-	  }
-
-	  sum_size -= tri_cur_num*3;
+    create_pp_task(sg, manager, spe_num, task_next);
 
-      }
-      
-      
-    }
-    
-    
-    
-    if (sg->children != NULL) {
-      sg = sg->children;
-    } else if (sg->brother != NULL) {
-      sg = sg->brother;
-    } else {
-      while (sg) {
-	if (sg->brother != NULL) {
-	  sg = sg->brother;
-	  break;
-	} else {
-	  if (sg->parent == NULL) {
-	    sg = NULL;
-	    break;
-	  } else {
-	    sg = sg->parent;
-	  }
-	}
-      }
-    } 
-  }
-  
+#if SPE_CREATE_POLYGON_CHECK
+    check_matrix(matrix_info,sg);
+#endif
 
-  int  range_base = spe_num;
-  
-    // 切り上げのつもり
-  int range = (spackList_length + range_base - 1) / range_base;
-  
-  for (int i = 0; i < range_base; i++) {
-    int index_start = range*i;
-    int index_end = (index_start + range >= spackList_length)
-      ? spackList_length : index_start + range;
-    
-    HTaskPtr task_create_sp = manager->create_task(CreateSpan);
-    
-    task_create_sp->set_param(0,index_start);
-    
-    /**
-     * ex. screen_height が 480, spenum が 6 の場合、各SPEのy担当範囲
-     *   [  1.. 80] [ 81..160] [161..240]
-     *   [241..320] [321..400] [401..480]
-     *
-     * ex. screen_height が 1080, spenum が 5 の場合、
-     *   [  1..216] [217..432] [433..648]
-     *   [649..864] [865..1080]
-     */
-    
-    task_create_sp->set_param(1,index_start*split_screen_h + 1);
-    task_create_sp->set_param(2,index_end*split_screen_h);
-    
-    task_create_sp->add_inData(ppack, sizeof(PolygonPack));
-    task_create_sp->add_inData(spackList_ptr,
-			       sizeof(SpanPack*)*spackList_length_align);
-    task_create_sp->add_inData(&spackList[index_start], sizeof(SpanPack));
-    
-    task_next->wait_for(task_create_sp);
-    task_create_sp->wait_for(create_pp_wait);
-    
-    task_create_sp->set_cpu(SPE_ANY);
-    task_create_sp->spawn();
-  }
+
   
 #else
-
+    
     HTaskPtr task_create_pp = manager->create_task(CreatePolygonFromSceneGraph);
     
     // SceneGraph(木構造) -> PolygonPack
@@ -590,6 +712,8 @@
 
     task_next->wait_for(task_create_pp);
 
+#endif
+
     int  range_base = spe_num;
 
     // 切り上げのつもり
@@ -631,8 +755,6 @@
 
     task_create_pp->spawn();
 
-#endif
-
 }
 
 HTaskPtr
@@ -702,6 +824,7 @@
     }
     
     ppack->clear();
+
     for (int i = 0; i < spackList_length; i++) {
         SpanPack *spack = &spackList[i];
         int startx = 1;
@@ -714,7 +837,8 @@
 
 #if 1
 
-	if(spack->info.size > 0) {
+	// mem_flag は spe 側で黒い部分を 0 で埋めるフラグ
+	if(spack->info.size > 0 || mem_flag == 1) {
 
 	  int array_task_num = (this->width + split_screen_w - 1) / split_screen_w;
 	  HTaskPtr task_draw_array = manager->create_task_array(DrawSpan, array_task_num, 6, 1, rangey);
@@ -755,12 +879,15 @@
 	  task_draw_array->wait_for(data_update_wait);
 	  task_draw_array->spawn();
 
-	} else {
 	  
+	 
+        } else {
+
 	  memset(&pixels[(startx-1)+this->width*(starty-1)],
 		 0, (this->width)*sizeof(int)*rangey);
 
-	}
+	} 
+	  
 
 #else
 
--- a/Renderer/Engine/viewer.h	Mon Jul 26 00:37:26 2010 +0900
+++ b/Renderer/Engine/viewer.h	Mon Jul 26 00:38:07 2010 +0900
@@ -10,6 +10,7 @@
 #include "Application.h"
 #include "SceneGraphRoot.h"
 #include "ViewerDevice.h"
+#include "matrix.h"
 
 class SceneGraphRoot;
 
@@ -49,6 +50,8 @@
     Uint32 video_flags;
     Uint32 *pixels;
 
+    int mem_flag;
+
     SceneGraphRoot *sgroot;
 
     //Uint32 *video_init(TaskManager *manager, int bpp, int width, int height);
@@ -69,8 +72,6 @@
     void run_collision();
     void rendering(HTaskPtr task_next);
     void common_draw(HTaskPtr task_next);
-    void create_pp_task(SceneGraphPtr sg, PolygonPackPtr pp_cur, HTaskPtr create_pp_wait,
-			int &pp_index, int &sg_index, int tri_num);
     void common_rendering(HTaskPtr task_next, SceneGraphRoot *sgroot);
 
     void spe_rendering(HTaskPtr task_next);
--- a/Renderer/Engine/viewer_types.cc	Mon Jul 26 00:37:26 2010 +0900
+++ b/Renderer/Engine/viewer_types.cc	Mon Jul 26 00:38:07 2010 +0900
@@ -1,38 +0,0 @@
-#include "viewer_types.h"
-
-static int
-getLocalPosition(int d, int offset)
-{
-    /**
-     * offset が 2 の冪乗の時だけ使える。
-     * 現在は offset は 2 の冪乗のみなので
-     * これで問題ないけどどうなの?
-     */
-    return d & (offset-1);
-
-    // offset が 2 の冪乗以外はこれにしないとだめ
-    //return d % offset;
-}
-
-/**
- * ワールド座標における x の値を
- * split_screen_w で分割した領域(1 〜 split_screen_w)での座標に変換する
- * (ex. split_screen_w が 256 の場合、
- *      x =   1 -> 1
- *      x = 256 -> 256
- *      x = 257 -> 1
- */
-int
-getLocalX(int x)
-{
-    return getLocalPosition(x, split_screen_w);
-}
-
-/**
- * getLocalX に同じ
- */
-int
-getLocalY(int y)
-{
-    return getLocalPosition(y, split_screen_h);
-}
--- a/Renderer/Engine/viewer_types.h	Mon Jul 26 00:37:26 2010 +0900
+++ b/Renderer/Engine/viewer_types.h	Mon Jul 26 00:38:07 2010 +0900
@@ -27,7 +27,41 @@
 const int alphaMask = 0xff000000;
 #endif
 
-extern int getLocalX(int x);
-extern int getLocalY(int y);
+static inline int
+getLocalPosition(int d, int offset)
+{
+    /**
+     * offset が 2 の冪乗の時だけ使える。
+     * 現在は offset は 2 の冪乗のみなので
+     * これで問題ないけどどうなの?
+     */
+    return d & (offset-1);
+
+    // offset が 2 の冪乗以外はこれにしないとだめ
+    //return d % offset;
+}
+
+/**
+ * ワールド座標における x の値を
+ * split_screen_w で分割した領域(1 〜 split_screen_w)での座標に変換する
+ * (ex. split_screen_w が 256 の場合、
+ *      x =   1 -> 1
+ *      x = 256 -> 256
+ *      x = 257 -> 1
+ */
+static inline int
+getLocalX(int x)
+{
+    return getLocalPosition(x, split_screen_w);
+}
+
+/**
+ * getLocalX に同じ
+ */
+static inline int
+getLocalY(int y)
+{
+    return getLocalPosition(y, split_screen_h);
+}
 
 #endif
--- a/TaskManager/ChangeLog	Mon Jul 26 00:37:26 2010 +0900
+++ b/TaskManager/ChangeLog	Mon Jul 26 00:38:07 2010 +0900
@@ -1,3 +1,10 @@
+2010-7-24 Shinji KONO <kono@ie.u-ryukyu.ac.jp>
+
+   やっぱり、load module のlinkの解決はやらないといけないので、
+   無理に、SchedTaskのAPI全部を virtual にする必要はないらしい。
+      spu-gcc  spe/ChainCal.o -Wl,-R,spe-main -o tmp.o
+   と言う形で、link してやれば良い。(ただし、必要なものが参照されている場合)
+
 2010-7-16 Shinji KONO <kono@ie.u-ryukyu.ac.jp>
 
    SimpleTask のsizeを16の倍数に。そうしないと、Taskのaligmentが16に
--- a/TaskManager/Makefile.def	Mon Jul 26 00:37:26 2010 +0900
+++ b/TaskManager/Makefile.def	Mon Jul 26 00:38:07 2010 +0900
@@ -30,7 +30,7 @@
 ABIBIT = 32
 
 #OPT = -O9
-OPT =  -g -O9  -DTASK_LIST_MAIL
+OPT =  -g -DTASK_LIST_MAIL -O9
 
 CC     = g++   
 CFLAGS = -Wall `sdl-config --cflags` -m$(ABIBIT)   $(OPT)
--- a/TaskManager/kernel/schedule/SchedTask.cc	Mon Jul 26 00:37:26 2010 +0900
+++ b/TaskManager/kernel/schedule/SchedTask.cc	Mon Jul 26 00:38:07 2010 +0900
@@ -259,6 +259,10 @@
     scheduler->wait_segment(s);
 }
 
+uint32 SchedTask::get_tag() {
+    return scheduler->get_tag();
+}
+
 
 HTaskPtr
 SchedTask::create_task(int cmd)
--- a/TaskManager/kernel/schedule/SchedTaskBase.h	Mon Jul 26 00:37:26 2010 +0900
+++ b/TaskManager/kernel/schedule/SchedTaskBase.h	Mon Jul 26 00:38:07 2010 +0900
@@ -7,6 +7,8 @@
 
 class TaskManagerImpl;
 class Scheduler;
+class MemorySegment;
+class MemList;
 
 class SchedTaskBase {
 public:
@@ -31,6 +33,44 @@
     virtual void* get_input(void *buff, int index) { return 0;}
     virtual memaddr get_param(int index) { return 0;}
     virtual int read_size() { return 0;}
+    virtual int printf(const char * format, ...) {return 0;};
+
+    virtual memaddr get_inputAddr(int index) {return 0;}
+    virtual memaddr get_outputAddr(int index) {return 0;}
+    virtual int get_inputSize(int index) {return 0;}
+    virtual int get_outputSize(int index) {return 0;}
+
+    virtual int get_cpuid() {return 0;}
+
+    virtual void* global_alloc(int id, int size) {return 0;}
+    virtual void* global_get(int id) {return 0;}
+    virtual void global_set(int id, void *addr) {}
+    virtual void global_free(int id) {}
+    virtual MemList* createMemList(int size, int count) {return 0;}
+
+    virtual void mainMem_alloc(int id, int size) {}
+    virtual void mainMem_wait() {}
+    virtual memaddr mainMem_get(int id) {return 0; }
+
+    virtual MemorySegment * get_segment(memaddr addr, MemList *m) {return 0; }
+    virtual uint32 get_tag() {return 0; }
+    virtual void put_segment(MemorySegment *s) {}
+    virtual void wait_segment(MemorySegment *s) {}
+
+    virtual void *allocate(int size) {return 0; }
+    virtual void free_(void *p)  {}
+    // virtual void polling();
+
+    /* これは禁止するべき */
+    virtual void dma_load(void *buf, memaddr addr, uint32 size, uint32 mask) {}
+    virtual void dma_store(void *buf,memaddr addr, uint32 size, uint32 mask) {}
+    virtual void dma_wait(uint32 mask) {}
+
+    virtual void show_dma_wait() {}
+    virtual void start_profile() {}
+    virtual void* allocate(int size,int align) {return 0;}
+    virtual Scheduler* get_scheduler() {return 0;}
+    virtual long get_random() {return 0;}
 
     /* variables */
 
--- a/example/get_segment/Makefile.cell	Mon Jul 26 00:37:26 2010 +0900
+++ b/example/get_segment/Makefile.cell	Mon Jul 26 00:38:07 2010 +0900
@@ -1,7 +1,7 @@
 include ./Makefile.def
 
 SRCS_TMP = $(wildcard *.cc)
-SRCS_EXCLUDE =  # ե
+SRCS_EXCLUDE =  # 除外するファイルを書く
 SRCS = $(filter-out $(SRCS_EXCLUDE),$(SRCS_TMP))
 OBJS = $(SRCS:.cc=.o)
 
--- a/example/get_segment/Makefile.def	Mon Jul 26 00:37:26 2010 +0900
+++ b/example/get_segment/Makefile.def	Mon Jul 26 00:38:07 2010 +0900
@@ -8,7 +8,7 @@
 CERIUM = ../../../Cerium
 
 CC      = g++
-CFLAGS  = -g -Wall # -O9
+CFLAGS  = -g -Wall -O9
 
 INCLUDE = -I${CERIUM}/include/TaskManager -I. -I..
 LIBS = -L${CERIUM}/TaskManager
--- a/example/get_segment/README	Mon Jul 26 00:37:26 2010 +0900
+++ b/example/get_segment/README	Mon Jul 26 00:38:07 2010 +0900
@@ -1,6 +1,28 @@
 
 - 概要
 
+Mon Jul 19 19:39:21 JST 2010
+
+overlay を使わずに、単独で link 出来ないの?
+
+文字列の相対アクセスの問題も...
+
+printf は SchedTask.cc で実行されるから、task_list から
+offset を知ることは可能なはず。(どうやって?)
+get_segment - vma で良いのかな? 
+
+でも、それは実行時にしか出来ないのか。
+
+org 0 でlink出来ればね。
+
+spu-gcc Task.cc
+
+で、compile 出来るようにしてしまう?
+
+でも、そうするとdebugが不可能になるけど? いや、今でも不可能なんだよね。
+
+だから、良いってわけ? まぁねぇ。
+
 Thu Sep 24 20:58:07 JST 2009
 
 Overly の例題
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/old/tmp/loadelf.cc	Mon Jul 26 00:38:07 2010 +0900
@@ -0,0 +1,139 @@
+/*
+      load spu elf file into memory with proper alignment.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <elf.h>
+#include "types.h"
+#include <alloca.h>
+#include <malloc.h>
+#include <strings.h>
+
+
+static int
+read_file(int fd, unsigned char *buf, int size)
+{
+    int i = 0;
+    do {
+        int j = read(fd,buf+i,size-i);
+        if (j<0) return j;
+        i+=j;
+    } while( i< size ) ;
+    return i;
+}
+
+static memaddr
+load_elf1(int fd)
+{
+    Elf32_Ehdr header;
+
+    if (read_file(fd, (unsigned char *)&header, sizeof(header))<0) return 0;
+
+    if (header.e_ident[EI_CLASS]==ELFCLASS32) printf("32bit\n");
+    printf("entry %0lx\n", (unsigned long)header.e_entry);
+    printf("program header %0lx ", (unsigned long)header.e_phoff);
+    printf("length %0lx\n", (unsigned long)header.e_phentsize);
+    printf("section header %0lx ", (unsigned long)header.e_shoff);
+    printf("length %0lx\n", (unsigned long)header.e_shentsize);
+    printf("e_shstrndx %ld\n", (unsigned long)header.e_shstrndx);
+
+    int num = header.e_shnum;
+    Elf32_Shdr section[num] ;
+
+    lseek(fd,header.e_shoff + (sizeof(Elf32_Shdr )*(header.e_shstrndx)),SEEK_SET);
+    if (read_file(fd, (unsigned char *)&section[0], sizeof(Elf32_Shdr))<0) return 0;
+    unsigned char *text = (unsigned char *)alloca(section[0].sh_size);
+    lseek(fd,section[0].sh_offset,SEEK_SET);
+    if (read_file(fd, text, section[0].sh_size)<0) return 0;
+    // for(int i=0;i<section.sh_size;i++) putchar(text[i]);
+
+    lseek(fd,header.e_shoff,SEEK_SET);
+    if (read_file(fd, (unsigned char *)&section[0], sizeof(Elf32_Shdr)*num)<0) return 0;
+    long min = 0x7fffffff;
+    long max = 0;
+
+    for(int i=0; i< num; i++) {
+        if (section[i].sh_flags & SHF_ALLOC) {
+             int adr = section[i].sh_addr;
+             if (min>adr) min = adr;
+             adr += section[i].sh_size ;
+             if (max<adr) max = adr;
+        }
+        printf("section %d ",i) ;
+        printf("  sh_name %s\n",text+section[i].sh_name) ;
+        printf("  sh_name %lx ",(unsigned long)section[i].sh_name) ;
+        printf("  sh_type %lx ",(unsigned long)section[i].sh_type) ;
+        printf("  sh_addr %lx ",(unsigned long)section[i].sh_addr) ;
+        printf("  sh_offset %lx ",(unsigned long)section[i].sh_offset) ;
+        printf("  sh_size %lx\n",(unsigned long)section[i].sh_size) ;
+    }
+    printf("\nmax %lx min %lx\n",max,min) ;
+
+#if 0
+    unsigned  char  *code = (unsigned char*)malloc(max-min);
+#else
+    unsigned  char  *code ;
+    posix_memalign((void**)&code,16,max-min);
+#endif
+
+    bzero(code,max-min);
+    printf("bzero %lx\n", (unsigned long)code) ;
+
+    long poffset = -1;    
+    unsigned char *addr = code;
+    unsigned long size  = 0;    
+    for(int i=0; i< num; i++) {
+        if ((section[i].sh_flags & SHF_ALLOC) && (section[i].sh_type!=SHT_NOBITS)) {
+	    printf("loading %lx %lx\n", 
+                   (unsigned long)(section[i].sh_addr), 
+                   (unsigned long)section[i].sh_size) ;
+            long offset = (unsigned long)(section[i].sh_addr-min)-
+                  (unsigned long)section[i].sh_offset;
+	    if (offset!=poffset) {
+                if (addr && size) {
+		    printf("   reading %lx %lx\n", 
+			   (unsigned long)addr, 
+			   (unsigned long)size) ;
+		    if (read_file(fd, addr, size)<0) return 0;
+                }
+                 // there is a hole
+                printf("   hole %0x = %0x - %0x\n", offset-poffset, offset, poffset);
+                poffset = offset;
+		lseek(fd,section[i].sh_offset,SEEK_SET);
+	        addr = code + (section[i].sh_addr-min);
+            } 
+	    unsigned char *last = 
+		 code + (section[i].sh_addr-min+section[i].sh_size);
+	    size = last - addr;
+        }
+    }
+    printf("   last reading %lx %lx\n", 
+	   (unsigned long)addr, 
+	   (unsigned long)size) ;
+    if (read_file(fd, addr, size)<0) return 0;
+    return (memaddr)code;
+}
+
+static memaddr
+load_elf(const char *name)
+{
+    Elf32_Ehdr header;
+
+    int fd = open(name,O_RDONLY);
+    if (fd<0) return 0;
+    memaddr addr = load_elf1(fd);
+    close(fd);
+    return addr;
+}
+
+int
+main(int ac, char *av[])
+{
+    load_elf(av[1]);
+    return 0;
+}
+
+