changeset 193:102dad2949a0

fix
author gongo@localhost.localdomain
date Tue, 13 Jan 2009 19:06:13 +0900
parents 4f5c64e713c7
children 72dcf908ec52
files TaskManager/Cell/spe/SchedTask.cc TaskManager/Cell/spe/main.cc TaskManager/Makefile.def TaskManager/Test/test_render/Tapestry.h TaskManager/Test/test_render/spe/DrawSpan.cpp TaskManager/Test/test_render/spe/DrawSpan.h TaskManager/Test/test_render/spe/DrawSpanRenew.cpp TaskManager/Test/test_render/spe/DrawSpanRenew.h TaskManager/Test/test_render/task/DrawSpan.cpp TaskManager/Test/test_render/task/DrawSpan.h TaskManager/Test/test_render/task/DrawSpanRenew.cpp TaskManager/Test/test_render/task/DrawSpanRenew.h TaskManager/Test/test_render/viewer.cpp TaskManager/Test/test_render/viewer_types.h include/TaskManager/Task.h include/TaskManager/base.h
diffstat 16 files changed, 542 insertions(+), 374 deletions(-) [+]
line wrap: on
line diff
--- a/TaskManager/Cell/spe/SchedTask.cc	Tue Jan 13 10:41:05 2009 +0900
+++ b/TaskManager/Cell/spe/SchedTask.cc	Tue Jan 13 19:06:13 2009 +0900
@@ -182,7 +182,7 @@
 	// SchedTask::write(void) でも wait 掛けてるんだけど、
         // 実際にはここに wait しないとちゃんと書き込まれてない感じがする
 	// wait はされてるはずなんだがなー
-	//__scheduler->dma_wait(DMA_WRITE);
+	__scheduler->dma_wait(DMA_WRITE);
     }
 
     (this->*ex_exec)();
--- a/TaskManager/Cell/spe/main.cc	Tue Jan 13 10:41:05 2009 +0900
+++ b/TaskManager/Cell/spe/main.cc	Tue Jan 13 19:06:13 2009 +0900
@@ -14,9 +14,15 @@
     unsigned code_size = (unsigned)&_end;
     unsigned heap_size = ls_size - code_size;
 
+#if 0
     __debug("  ls_size:%10d bytes\n", ls_size);
     __debug("code_size:%10d bytes\n", code_size);
     __debug("heap_size:%10d bytes\n", heap_size);
+#else
+    printf("  ls_size:%10d bytes\n", ls_size);
+    printf("code_size:%10d bytes\n", code_size);
+    printf("heap_size:%10d bytes\n", heap_size);
+#endif
 
     manager = new CellScheduler();
     manager->init();
--- a/TaskManager/Makefile.def	Tue Jan 13 10:41:05 2009 +0900
+++ b/TaskManager/Makefile.def	Tue Jan 13 19:06:13 2009 +0900
@@ -25,7 +25,7 @@
 IMPL_CELL_OBJS = $(IMPL_CELL_SRCS:.cc=.o)
 
 CC     = g++   
-CFLAGS = -O9 -Wall `sdl-config --cflags` -g
+CFLAGS = -O0 -Wall `sdl-config --cflags` -g
 LIBS   = 
 
 INCLUDE = -I../include/TaskManager
\ No newline at end of file
--- a/TaskManager/Test/test_render/Tapestry.h	Tue Jan 13 10:41:05 2009 +0900
+++ b/TaskManager/Test/test_render/Tapestry.h	Tue Jan 13 19:06:13 2009 +0900
@@ -86,7 +86,7 @@
     int pad[3];
 } Tile, *TilePtr;
 
-#define MAX_TILE 64
+#define MAX_TILE 128
 
 /**
  * TileList 筝 Tile 菴純冴憜 FIFO у茖
--- a/TaskManager/Test/test_render/spe/DrawSpan.cpp	Tue Jan 13 10:41:05 2009 +0900
+++ b/TaskManager/Test/test_render/spe/DrawSpan.cpp	Tue Jan 13 19:06:13 2009 +0900
@@ -9,11 +9,18 @@
 
 #define SPAN_PACK_LOAD 0
 #define TEX_LOAD 1
+#define FB_STORE 2
 
 SchedDefineTask(DrawSpan);
 
+DrawSpan::~DrawSpan(void)
+{
+    smanager->dma_wait(FB_STORE);
+    free((void*)((int)linebuf*doneWrite));
+}
+
 /**
- * テクスチャは、TEXTURE_SPLIT_PIXEL^2 のブロックに分割する
+ * 鴻cTEXTURE_SPLIT_PIXEL^2 蚊
  *
  * +---+---+---+---+---+---+
  * | 0 | 1 | 2 | 3 | 4 | 5 |
@@ -29,13 +36,13 @@
  * |   |   |   |   |   |35 |
  * +---+---+---+---+---+---+
  *
- * 一辺を TEXTURE_SPLIT とする
- * 各ブロックの数字がブロックIDとなる。
+ * 筝莨冴 TEXTURE_SPLIT 
+ * 医ID
  */
 
 /**
- * テクスチャの座標から、
- * テクスチャのどのブロックかを求める
+ * 鴻c綺ф
+ * 鴻c羆
  *
  * @param[in] tx X coordinates of texture
  * @param[in] tx Y coordinates of texture
@@ -54,13 +61,13 @@
 }
 
 /**
- * block ID と、テクスチャの TOP address から
- * (tx,ty) で使われるテクスチャの Tile addres を求める
+ * block ID 鴻c TOP address 
+ * (tx,ty) т戎鴻c Tile addres 羆
  *
  * @param[in] tx X coordinates of texture
  * @param[in] tx Y coordinates of texture
  * @param[in] tw Width of texture
- * @param[in] tex_addr_top (tx,ty) で使うテクスチャの先頭address
+ * @param[in] tex_addr_top (tx,ty) т戎鴻caddress
  * @return block ID
  */
 uint32*
@@ -70,19 +77,52 @@
     return tex_addr_top + block*TEXTURE_BLOCK_SIZE;
 }
 
-void
-DrawSpan::linebuf_init(int *buf, int x, int rgb)
+/**
+ * FrameBuffer 吾莨若 rgb 
+ *
+ * @param width  Width of Buffer
+ * @param height Height of Buffer
+ * @param rgb    Initial value of RGB at Buffer
+ * @return Buffer
+ */
+int*
+DrawSpan::linebuf_init(int width, int height, int rgb)
 {
-    for (int i = 0; i < x; i++) {
+    int *buf = (int*)smanager->allocate(sizeof(int)*width*height);
+
+    for (int i = 0; i < width*height; i++) {
 	buf[i] = rgb;
     }
+
+    return buf;
 }
 
 /**
- * Span が使う Texture Tile があるか
+ * Z-Buffer 
  *
- * @retval != NULL 存在する
- * @retval NULL    存在しない
+ * @param width  Width of Z-Buffer
+ * @param height Height of Z-Buffer
+ * @return Z-Buffer
+ */
+float*
+DrawSpan::zRow_init(int width, int height)
+{
+    float *buf = (float*)smanager->allocate(sizeof(float)*width*height);
+    float def = 65535.0f;
+
+    for (int i = 0; i < width*height; i++) {
+	buf[i] = def;
+    }
+
+    return buf;
+}
+
+
+/**
+ * Span 篏帥 Texture Tile 
+ *
+ * @retval != NULL 絖
+ * @retval NULL    絖
  */
 TilePtr
 DrawSpan::isAvailableTile(uint32 *addr)
@@ -95,22 +135,18 @@
 {
     TilePtr tile;
 
-    if (!isAvailableTile(addr)) {
-	tile = tileList->nextTile();
-	/**
-	 * FIFO なので、もし前のが残っていれば削除
-	 */
-	hash->remove(tile->texture_addr);
-	
-	tile->texture_addr = addr;
-	
-	hash->put(tile->texture_addr, tile);
-	
-	smanager->dma_load(tile->pixel, (uint32)addr,
-			   sizeof(uint32)*TEXTURE_BLOCK_SIZE, TEX_LOAD);
-	
-	//smanager->dma_wait(TEX_LOAD);
-    }
+    tile = tileList->nextTile();
+    /**
+     * FIFO с罧c医
+     */
+    hash->remove(tile->texture_addr);
+    
+    tile->texture_addr = addr;
+    
+    hash->put(tile->texture_addr, tile);
+    
+    smanager->dma_load(tile->pixel, (uint32)addr,
+		       sizeof(uint32)*TEXTURE_BLOCK_SIZE, TEX_LOAD);
 }
 
 void
@@ -118,16 +154,16 @@
 {
     uint32 start = (uint32)addr;
     uint32 end = (uint32)max_addr;
-    uint32 length = end-start;
-    uint32 diff = sizeof(uint32)*TEXTURE_BLOCK_SIZE;
-    uint32 max_tile = 16;
-    
-    for (uint32 i = 0, j = 0; i <= length && j < max_tile; i += diff, j++) {
+    int length = (int)end-start;
+    int diff = sizeof(int)*TEXTURE_BLOCK_SIZE;
+    int max_tile = 16;
+
+    for (int i = 0, j = 0; i <= length && j < max_tile; i += diff, j++) {
 	set_rgb((uint32*)(start + i));
     }
 }
 
-Uint32
+uint32
 DrawSpan::get_rgb(int tx, int ty, uint32 *addr)
 {
     TilePtr tile;
@@ -137,93 +173,99 @@
 }
 
 /**
- * DrawSpan の再起動 (DrawSpanRenew 生成)
+ * DrawSpan 莎桁 (DrawSpanRenew )
  *
- * @param[in] spack 現在処理している SpanPack
- * @param[in] cur_span_x span->length_x != 1 の時の Span の処理で
- *                       どこまで進んでいるか
+ * @param[in] spack 憜 SpanPack
+ * @param[in] cur_span_x span->length_x != 1  Span 
+ *                       障ч蚊с
  */
 void
 DrawSpan::reboot(SpanPackPtr spack, int cur_span_x)
 {
+    DrawSpanArgPtr args =
+	(DrawSpanArgPtr)smanager->allocate(sizeof(DrawSpanArg));
     TaskPtr renew_task = smanager->create_task(TASK_DRAW_SPAN2);
-    int rangey = smanager->get_param(2);
+
+    // 違紊ф篏ф検
+    args->display      = smanager->get_param(0);
+    args->screen_width = smanager->get_param(1);
+    args->rangex_start = smanager->get_param(2);
+    args->rangex_end   = smanager->get_param(3);
+    args->rangey       = smanager->get_param(4);
+    renew_task->add_param((int)args);
 
     /**
-     * 共通の outData, param はそのまま渡す
-     */
-    for (int i = 0; i < rangey; i++) {
-	renew_task->add_outData(smanager->get_outputAddr(i),
-			   smanager->get_outputSize(i));
-    }
-
-    // rangex_start, rangex_end, rangey
-    renew_task->add_param(smanager->get_param(0));
-    renew_task->add_param(smanager->get_param(1)); 
-    renew_task->add_param(smanager->get_param(2));
-
-    /**
-     * SpanPack は続きから開始するので、
-     * 現在の状態をコピーしておく。
-     * spack は rbuf から取得してる可能性があり
-     * rbuf はシステムが自動的に free() するため
-     * アドレスだけ渡すのはNG
+     * SpanPack 膓紮с
+     * 憜倶潟若
+     * spack  rbuf 緇醇с
+     * rbuf 激鴻 free() 
+     * ≪鴻羝<NG
      */ 
     SpanPackPtr curr = (SpanPackPtr)smanager->allocate(sizeof(SpanPack));
     memcpy(curr, spack, sizeof(SpanPack));
     renew_task->add_param((int)curr);
     renew_task->add_param(cur_span_x);
 
-    fprintf(stderr, "[%p] start %u\n",
-	    curr, spu_readch(SPU_RdDec));
+    // linebuf  zRow 綣膓
+    renew_task->add_param((int)linebuf);
+    renew_task->add_param((int)zRow);
+
+    //fprintf(stderr, "[%p] start %u\n", curr, spu_readch(SPU_RdDec));
 
     /**
-     * 再起動したタスクを待つ
+     * 莎桁帥鴻緇
      */ 
     smanager->wait_task(renew_task);
 
-    // next_spack は free() するので wait する
+    // next_spack  free()  wait 
     smanager->dma_wait(SPAN_PACK_LOAD);
 }
 
+void
+DrawSpan::writebuffer(unsigned int display, int buf_width, int height,
+		      int screen_width)
+{
+    for (int i = 0; i < height; i++) {
+	smanager->dma_store(&linebuf[i*buf_width],
+			    display + (sizeof(int)*screen_width*i),
+			    sizeof(int)*buf_width, FB_STORE);
+    }
+
+    doneWrite = 1;
+}
+
 int
 DrawSpan::run(void *rbuf, void *wbuf)
 {
+    SpanPackPtr spack = (SpanPackPtr)smanager->get_input(0);
+    SpanPackPtr next_spack = (SpanPackPtr)smanager->allocate(sizeof(SpanPack));
+    SpanPackPtr free_spack = next_spack; // next_spack  free() 
+    Span *span;
+
+    uint32 display   = smanager->get_param(0);
+    int screen_width = smanager->get_param(1);
+    int rangex_start = smanager->get_param(2);
+    int rangex_end   = smanager->get_param(3); 
+
+    // 帥鴻綵 x 膀
+    int rangex = rangex_end - rangex_start + 1;
+
+    // y 膀
+    int rangey = smanager->get_param(4);
+    
     hash = (TileHashPtr)smanager->global_get(GLOBAL_TEXTURE_HASH);
     tileList = (TileListPtr)smanager->global_get(GLOBAL_TILE_LIST);
 
-    int rangex_start  = smanager->get_param(0);
-    int rangex_end    = smanager->get_param(1); 
-
-    // このタスクが担当する x の範囲
-    int rangex        = rangex_end - rangex_start + 1;
-
-    // y の範囲 (render_y + rangey - 1)
-    int rangey        = smanager->get_param(2);
-    
-    float *zRow = (float*)smanager->allocate(sizeof(float)*rangex*rangey);
+    zRow = zRow_init(rangex, rangey);
+    linebuf = linebuf_init(rangex, rangey, 0xffffffff);
 
-    for (int i = 0; i < rangex*rangey; i++) {
-	zRow[i] = 65535.0f;
-    }
-
-    int **linebuf = (int**)smanager->allocate(sizeof(int*)*rangey);
-
-    for (int i = 0; i < rangey; i++) {
-	linebuf[i] = (int*)smanager->get_output(i);
-	linebuf_init(linebuf[i], rangex, 0xffffffff);
-    }
-
-    SpanPackPtr spack = (SpanPackPtr)smanager->get_input(0);
-    SpanPackPtr next_spack = (SpanPackPtr)smanager->allocate(sizeof(SpanPack));
-    SpanPackPtr free_spack = next_spack; // next_spack の free() 用
-    Span *span;
+    doneWrite = 0;
 
     do {
 	/**
-	 * SpanPack->next が存在する場合、
-	 * 現在の SpanPack を処理してる間に
-	 * 次の SpanPack の DMA 転送を行う
+	 * SpanPack->next 絖翫
+	 * 憜 SpanPack 
+	 * 罨< SpanPack  DMA 荵∫茵
 	 */
 	if (spack->next != NULL) {
 	    smanager->dma_load(next_spack, (uint32)spack->next,
@@ -235,22 +277,22 @@
 	for (int t = 0; t < spack->info.size; t++) {	  
 	    span = &spack->span[t];
 
-	    Uint32 rgb = 0x00ff00;
+	    uint32 rgb = 0x0000ff00;
 	    float tex1 = span->tex_x1;
 	    float tex2 = span->tex_x2;
 	    float tey1 = span->tex_y1;
 	    float tey2 = span->tex_y2;
 
 	    /**
-	     * Span が持つ 1 pixel 毎の
-	     * テクスチャの座標
+	     * Span  1 pixel 罸
+	     * 鴻c綺ф
 	     */
 	    int tex_xpos;
 	    int tex_ypos;
 
 	    /**
-	     * (tex_xpos, tex_ypos) の、ブロック内(上の図参照)での座標と
-	     * そのブロックのアドレス(MainMemory)
+	     * (tex_xpos, tex_ypos) (筝喝)с綺ф
+	     * ≪(MainMemory)
 	     */
 	    int tex_localx;
 	    int tex_localy;
@@ -262,7 +304,7 @@
 	    float z = span->start_z;
 	    float zpos = span->end_z;
 
-	    // 座標が [0 .. split_screen_w-1] に入るように x,y を -1
+	    // 綺ф [0 .. split_screen_w-1] ャ x,y  -1
 	    int localx = getLocalX(x-1);
 	    int localy = getLocalY(y-1);
 
@@ -274,30 +316,21 @@
 		tex_xpos = (int)((span->tex_width-1) * tex1);
 		tex_ypos = (int)((span->tex_height-1) * tey1);
 
-		if (zpos < zRow[localx + (rangex * localy)]) {
+		if (zpos < zRow[localx + (rangex*localy)]) {
 		    tex_addr = getTile(tex_xpos, tex_ypos,
 				       span->tex_width, span->tex_addr);
 		    tex_localx = tex_xpos % TEXTURE_SPLIT_PIXEL;
 		    tex_localy = tex_ypos % TEXTURE_SPLIT_PIXEL;
 		    
-		    /**
-		     * Tile が無い場合、一旦タスクはここで中断し、
-		     * Tile をロードするタスクを走らせた後に再起動する
-		     */
 		    if (!isAvailableTile(tex_addr)) {
-			spack->info.start = t;
 			set_rgb(tex_addr);
-			//set_rgbs(tex_addr,
-			//getTile(span->tex_width-1, tex_ypos,
-			//span->tex_width, span->tex_addr));
-			//reboot(spack, 0);
-			//goto FINISH;
+			smanager->dma_wait(TEX_LOAD);
 		    }
 
 		    rgb = get_rgb(tex_localx, tex_localy, tex_addr);
 
-		    zRow[localx + (rangex * localy)] = zpos;
-		    linebuf[localy][localx] = rgb;
+		    zRow[localx + (rangex*localy)] = zpos;
+		    linebuf[localx + (rangex*localy)] = rgb;
 		}
 	    } else {
 		int js = (x < rangex_start) ? rangex_start - x : 0;
@@ -324,20 +357,29 @@
 			tex_localx = tex_xpos % TEXTURE_SPLIT_PIXEL;
 			tex_localy = tex_ypos % TEXTURE_SPLIT_PIXEL;
 
+			/**
+			 * Tile <翫筝帥鴻т賢
+			 * Tile 若帥鴻莎違緇莎桁
+			 */
 			if (!isAvailableTile(tex_addr)) {
 			    spack->info.start = t;
-			    //set_rgb(tex_addr);
+#if 1
 			    set_rgbs(tex_addr,
 				     getTile(span->tex_width-1, tex_ypos,
 					     span->tex_width, span->tex_addr));
+			    //smanager->dma_wait(TEX_LOAD);
 			    reboot(spack, j);
 			    goto FINISH;
+#else
+			    set_rgb(tex_addr);
+			    smanager->dma_wait(TEX_LOAD);
+#endif
 			}
 			
 			rgb = get_rgb(tex_localx, tex_localy, tex_addr);
 		    
 			zRow[localx + (rangex*localy)] = tex_z;
-			linebuf[localy][localx] = rgb;
+			linebuf[localx + (rangex*localy)] = rgb;
 		    }
 		}
 	    }
@@ -350,11 +392,19 @@
 	next_spack = tmp_spack;
     } while (spack);
 
+    writebuffer(display, rangex, rangey, screen_width);
+
+    // linebuf writebuffer()  dma_store  wait 
+    // DrawSpan::~DrawSpan()  free 
+    //free(linebuf);
+    free(zRow);
 
 FINISH:
+    /**
+     * goto FINISH;  reboot 
+     * linebuf, zRow  free() 
+     */
     free(free_spack);
-    free(linebuf);
-    free(zRow);
 
     return 0;
 }
--- a/TaskManager/Test/test_render/spe/DrawSpan.h	Tue Jan 13 10:41:05 2009 +0900
+++ b/TaskManager/Test/test_render/spe/DrawSpan.h	Tue Jan 13 19:06:13 2009 +0900
@@ -17,32 +17,39 @@
 #  include "TileHash.h"
 #endif
 
-typedef int8_t          Sint8;
-typedef uint8_t         Uint8;
-typedef int16_t         Sint16;
-typedef uint16_t        Uint16;
-typedef int32_t         Sint32;
-typedef uint32_t        Uint32;
-typedef unsigned short  GLushort;
-
 class DrawSpan : public SchedTask {
 public:
     SchedConstructor(DrawSpan);
 
+    int *linebuf;
+    float *zRow;
     TileHashPtr hash;
     TileListPtr tileList;
+    int doneWrite;
+
+    ~DrawSpan(void);
 
     int run(void *rbuf, void *wbuf);
 
-    void linebuf_init(int *buf, int width, int rgb);    
+    int* linebuf_init(int width, int height, int rgb);
+    float* zRow_init(int width, int height);
     void set_rgb(uint32 *addr);
     void set_rgbs(uint32 *addr, uint32 *max_addr);
-    Uint32 get_rgb(int tx, int ty, uint32 *addr);
+    uint32 get_rgb(int tx, int ty, uint32 *addr);
     TilePtr isAvailableTile(uint32 *addr);
     uint32* getTile(int tx, int ty, int tw, uint32 *tex_addr_top);
     int getTexBlock(int tx, int ty, int twidth);
+    void writebuffer(unsigned int display, int width, int height, int screen_width);
 
     void reboot(SpanPackPtr spack, int cur_span_x);
 };
 
+typedef struct {
+    uint32 display;
+    int screen_width;
+    int rangex_start;
+    int rangex_end;
+    int rangey;
+} DrawSpanArg, *DrawSpanArgPtr;
+
 #endif
--- a/TaskManager/Test/test_render/spe/DrawSpanRenew.cpp	Tue Jan 13 10:41:05 2009 +0900
+++ b/TaskManager/Test/test_render/spe/DrawSpanRenew.cpp	Tue Jan 13 19:06:13 2009 +0900
@@ -10,51 +10,73 @@
 
 #define SPAN_PACK_LOAD 0
 #define TEX_LOAD 1
+#define FB_STORE 2
 
 SchedDefineTask(DrawSpanRenew);
 
+void
+DrawSpanRenew::reboot(SpanPackPtr spack, int cur_span_x)
+{
+    TaskPtr renew_task = smanager->create_task(TASK_DRAW_SPAN2);
+
+    renew_task->add_param((int)args);
+
+    SpanPackPtr curr = (SpanPackPtr)smanager->allocate(sizeof(SpanPack));
+    memcpy(curr, spack, sizeof(SpanPack));
+    renew_task->add_param((int)curr);
+    renew_task->add_param(cur_span_x);
+
+    // linebuf と zRow も引き継がせる
+    renew_task->add_param((int)linebuf);
+    renew_task->add_param((int)zRow);
+
+    //fprintf(stderr, "[%p] start %u\n", curr, spu_readch(SPU_RdDec));
+
+    /**
+     * 再起動したタスクを待つ
+     */ 
+    smanager->wait_task(renew_task);
+
+    // next_spack は free() するので wait する
+    smanager->dma_wait(SPAN_PACK_LOAD);
+}
+
 int
 DrawSpanRenew::run(void *rbuf, void *wbuf)
 {
-    hash = (TileHashPtr)smanager->global_get(GLOBAL_TEXTURE_HASH);
-    tileList = (TileListPtr)smanager->global_get(GLOBAL_TILE_LIST);
-
-    int rangex_start  = smanager->get_param(0);
-    int rangex_end    = smanager->get_param(1); 
-
-    // このタスクが担当する x の範囲
-    int rangex        = rangex_end - rangex_start + 1;
-
-    // y の範囲 (render_y + rangey - 1)
-    int rangey        = smanager->get_param(2);
-    
-    float *zRow = (float*)smanager->allocate(sizeof(float)*rangex*rangey);
-
-    for (int i = 0; i < rangex*rangey; i++) {
-	zRow[i] = 65535.0f;
-    }
-
-    int **linebuf = (int**)smanager->allocate(sizeof(int*)*rangey);
-
-    for (int i = 0; i < rangey; i++) {
-	linebuf[i] = (int*)smanager->get_output(i);
-	linebuf_init(linebuf[i], rangex, 0xffffffff);
-    }
-
-    SpanPackPtr spack = (SpanPackPtr)smanager->get_param(3);
+    SpanPackPtr spack = (SpanPackPtr)smanager->get_param(1);
     SpanPackPtr next_spack = (SpanPackPtr)smanager->allocate(sizeof(SpanPack));
     SpanPackPtr free_spack1 = spack;
     SpanPackPtr free_spack2 = next_spack;
     Span *span;
-    
-    // span->length_x の処理での再起動位置
-    int js_cont = smanager->get_param(4);
+
+    args = (DrawSpanArgPtr)smanager->get_param(0);
+    uint32 display   = args->display;
+    int screen_width = args->screen_width;
+    int rangex_start = args->rangex_start;
+    int rangex_end   = args->rangex_end;
+
+    // このタスクが担当する x の範囲
+    int rangex = rangex_end - rangex_start + 1;
+
+    // y の範囲 (render_y + rangey - 1)
+    int rangey = args->rangey;
 
-    fprintf(stderr, "[%p] end   %u\n",
-	    spack, spu_readch(SPU_RdDec));
+    hash = (TileHashPtr)smanager->global_get(GLOBAL_TEXTURE_HASH);
+    tileList = (TileListPtr)smanager->global_get(GLOBAL_TILE_LIST);
+    
+    linebuf = (int*)smanager->get_param(3);
+    zRow = (float*)smanager->get_param(4);
+
+    doneWrite = 0;
+
+    // span->length_x の処理での再起動位置
+    int js_cont = smanager->get_param(2);
+
+    //fprintf(stderr, "[%p] end   %u\n", spack, spu_readch(SPU_RdDec));
+
     smanager->dma_wait(TEX_LOAD);
 
-
     do {
 	/**
 	 * SpanPack->next が存在する場合、
@@ -71,7 +93,7 @@
 	for (int t = spack->info.start; t < spack->info.size; t++) {	  
 	    span = &spack->span[t];
 
-	    Uint32 rgb = 0x00ff0000;
+	    uint32 rgb = 0x00ff0000;
 	    float tex1 = span->tex_x1;
 	    float tex2 = span->tex_x2;
 	    float tey1 = span->tex_y1;
@@ -116,24 +138,15 @@
 		    tex_localx = tex_xpos % TEXTURE_SPLIT_PIXEL;
 		    tex_localy = tex_ypos % TEXTURE_SPLIT_PIXEL;
 
-		    /**
-		     * Tile が無い場合、一旦タスクはここで中断し、
-		     * Tile をロードするタスクを走らせた後に再起動する
-		     */
 		    if (!isAvailableTile(tex_addr)) {
-			spack->info.start = t;
 			set_rgb(tex_addr);
-			//set_rgbs(tex_addr,
-			//getTile(span->tex_width-1, tex_ypos,
-			//span->tex_width, span->tex_addr));
-			//reboot(spack, 0);
-			//goto FINISH;
+			smanager->dma_wait(TEX_LOAD);
 		    }
 		    
 		    rgb = get_rgb(tex_localx, tex_localy, tex_addr);
 
-		    zRow[localx + (rangex * localy)] = zpos;
-		    linebuf[localy][localx] = rgb;
+		    zRow[localx + (rangex*localy)] = zpos;
+		    linebuf[localx + (rangex*localy)] = rgb;
 		}
 	    } else {
 		int js = (x < rangex_start) ? rangex_start - x : 0;
@@ -167,20 +180,25 @@
 					   span->tex_width, span->tex_addr);
 			tex_localx = tex_xpos % TEXTURE_SPLIT_PIXEL;
 			tex_localy = tex_ypos % TEXTURE_SPLIT_PIXEL;
+
 			if (!isAvailableTile(tex_addr)) {
 			    spack->info.start = t;
+#if 0
+			    set_rgbs(tex_addr,
+				     getTile(span->tex_width-1, tex_ypos,
+					     span->tex_width, span->tex_addr));
+			    reboot(spack, j);
+			    goto FINISH;
+#else
 			    set_rgb(tex_addr);
-			    //set_rgbs(tex_addr,
-			    //getTile(span->tex_width-1, tex_ypos,
-			    //span->tex_width, span->tex_addr));
-			    //reboot(spack, j);
-			    //goto FINISH;
+			    smanager->dma_wait(TEX_LOAD);
+#endif
 			}
 			
 			rgb = get_rgb(tex_localx, tex_localy, tex_addr);
 		    
 			zRow[localx + (rangex*localy)] = tex_z;
-			linebuf[localy][localx] = rgb;
+			linebuf[localx + (rangex*localy)] = rgb;
 		    }
 		}
 	    }
@@ -193,19 +211,17 @@
 	next_spack = tmp_spack;
     } while (spack);
 
+    writebuffer(display, rangex, rangey, screen_width);
+
+    free(zRow);
+    free(args);
 
 FINISH:
-    smanager->dma_wait(SPAN_PACK_LOAD);
-    //free(next_spack);
-    free(linebuf);
-    free(zRow);
-
-    // Renew したタスクで allocate されたものなので、これも free
-    //free(spack);
-
+    /**
+     * linebuf, zRow, args は RenewTask が引き継ぐ
+     */
     free(free_spack1);
     free(free_spack2);
 
-
     return 0;
 }
--- a/TaskManager/Test/test_render/spe/DrawSpanRenew.h	Tue Jan 13 10:41:05 2009 +0900
+++ b/TaskManager/Test/test_render/spe/DrawSpanRenew.h	Tue Jan 13 19:06:13 2009 +0900
@@ -9,7 +9,12 @@
 public:
     SchedConstructor(DrawSpanRenew);
 
+    DrawSpanArgPtr args;
+
     int run(void *rbuf, void *wbuf);
+
+    // override
+    void reboot(SpanPackPtr spack, int cur_span_x);
 };
 
 #endif
--- a/TaskManager/Test/test_render/task/DrawSpan.cpp	Tue Jan 13 10:41:05 2009 +0900
+++ b/TaskManager/Test/test_render/task/DrawSpan.cpp	Tue Jan 13 19:06:13 2009 +0900
@@ -8,11 +8,18 @@
 
 #define SPAN_PACK_LOAD 0
 #define TEX_LOAD 1
+#define FB_STORE 2
 
 SchedDefineTask(DrawSpan);
 
+DrawSpan::~DrawSpan(void)
+{
+    smanager->dma_wait(FB_STORE);
+    free((void*)((int)linebuf*doneWrite));
+}
+
 /**
- * テクスチャは、TEXTURE_SPLIT_PIXEL^2 のブロックに分割する
+ * 鴻cTEXTURE_SPLIT_PIXEL^2 蚊
  *
  * +---+---+---+---+---+---+
  * | 0 | 1 | 2 | 3 | 4 | 5 |
@@ -28,13 +35,13 @@
  * |   |   |   |   |   |35 |
  * +---+---+---+---+---+---+
  *
- * 一辺を TEXTURE_SPLIT とする
- * 各ブロックの数字がブロックIDとなる。
+ * 筝莨冴 TEXTURE_SPLIT 
+ * 医ID
  */
 
 /**
- * テクスチャの座標から、
- * テクスチャのどのブロックかを求める
+ * 鴻c綺ф
+ * 鴻c羆
  *
  * @param[in] tx X coordinates of texture
  * @param[in] tx Y coordinates of texture
@@ -53,13 +60,13 @@
 }
 
 /**
- * block ID と、テクスチャの TOP address から
- * (tx,ty) で使われるテクスチャの Tile addres を求める
+ * block ID 鴻c TOP address 
+ * (tx,ty) т戎鴻c Tile addres 羆
  *
  * @param[in] tx X coordinates of texture
  * @param[in] tx Y coordinates of texture
  * @param[in] tw Width of texture
- * @param[in] tex_addr_top (tx,ty) で使うテクスチャの先頭address
+ * @param[in] tex_addr_top (tx,ty) т戎鴻caddress
  * @return block ID
  */
 uint32*
@@ -69,19 +76,52 @@
     return tex_addr_top + block*TEXTURE_BLOCK_SIZE;
 }
 
-void
-DrawSpan::linebuf_init(int *buf, int x, int rgb)
+/**
+ * FrameBuffer 吾莨若 rgb 
+ *
+ * @param width  Width of Buffer
+ * @param height Height of Buffer
+ * @param rgb    Initial value of RGB at Buffer
+ * @return Buffer
+ */
+int*
+DrawSpan::linebuf_init(int width, int height, int rgb)
 {
-    for (int i = 0; i < x; i++) {
+    int *buf = (int*)smanager->allocate(sizeof(int)*width*height);
+
+    for (int i = 0; i < width*height; i++) {
 	buf[i] = rgb;
     }
+
+    return buf;
 }
 
 /**
- * Span が使う Texture Tile があるか
+ * Z-Buffer 
  *
- * @retval != NULL 存在する
- * @retval NULL    存在しない
+ * @param width  Width of Z-Buffer
+ * @param height Height of Z-Buffer
+ * @return Z-Buffer
+ */
+float*
+DrawSpan::zRow_init(int width, int height)
+{
+    float *buf = (float*)smanager->allocate(sizeof(float)*width*height);
+    float def = 65535.0f;
+
+    for (int i = 0; i < width*height; i++) {
+	buf[i] = def;
+    }
+
+    return buf;
+}
+
+
+/**
+ * Span 篏帥 Texture Tile 
+ *
+ * @retval != NULL 絖
+ * @retval NULL    絖
  */
 TilePtr
 DrawSpan::isAvailableTile(uint32 *addr)
@@ -94,22 +134,18 @@
 {
     TilePtr tile;
 
-    if (!isAvailableTile(addr)) {
-	tile = tileList->nextTile();
-	/**
-	 * FIFO なので、もし前のが残っていれば削除
-	 */
-	hash->remove(tile->texture_addr);
-	
-	tile->texture_addr = addr;
-	
-	hash->put(tile->texture_addr, tile);
-	
-	smanager->dma_load(tile->pixel, (uint32)addr,
-			   sizeof(uint32)*TEXTURE_BLOCK_SIZE, TEX_LOAD);
-	
-	//smanager->dma_wait(TEX_LOAD);
-    }
+    tile = tileList->nextTile();
+    /**
+     * FIFO с罧c医
+     */
+    hash->remove(tile->texture_addr);
+    
+    tile->texture_addr = addr;
+    
+    hash->put(tile->texture_addr, tile);
+    
+    smanager->dma_load(tile->pixel, (uint32)addr,
+		       sizeof(uint32)*TEXTURE_BLOCK_SIZE, TEX_LOAD);
 }
 
 void
@@ -117,16 +153,16 @@
 {
     uint32 start = (uint32)addr;
     uint32 end = (uint32)max_addr;
-    uint32 length = end-start;
-    uint32 diff = sizeof(uint32)*TEXTURE_BLOCK_SIZE;
-    uint32 max_tile = 16;
-    
-    for (uint32 i = 0, j = 0; i <= length && j < max_tile; i += diff, j++) {
+    int length = (int)end-start;
+    int diff = sizeof(int)*TEXTURE_BLOCK_SIZE;
+    int max_tile = 16;
+
+    for (int i = 0, j = 0; i <= length && j < max_tile; i += diff, j++) {
 	set_rgb((uint32*)(start + i));
     }
 }
 
-Uint32
+uint32
 DrawSpan::get_rgb(int tx, int ty, uint32 *addr)
 {
     TilePtr tile;
@@ -136,90 +172,97 @@
 }
 
 /**
- * DrawSpan の再起動 (DrawSpanRenew 生成)
+ * DrawSpan 莎桁 (DrawSpanRenew )
  *
- * @param[in] spack 現在処理している SpanPack
- * @param[in] cur_span_x span->length_x != 1 の時の Span の処理で
- *                       どこまで進んでいるか
+ * @param[in] spack 憜 SpanPack
+ * @param[in] cur_span_x span->length_x != 1  Span 
+ *                       障ч蚊с
  */
 void
 DrawSpan::reboot(SpanPackPtr spack, int cur_span_x)
 {
+    DrawSpanArgPtr args =
+	(DrawSpanArgPtr)smanager->allocate(sizeof(DrawSpanArg));
     TaskPtr renew_task = smanager->create_task(TASK_DRAW_SPAN2);
-    int rangey = smanager->get_param(2);
+
+    // 違紊ф篏ф検
+    args->display      = smanager->get_param(0);
+    args->screen_width = smanager->get_param(1);
+    args->rangex_start = smanager->get_param(2);
+    args->rangex_end   = smanager->get_param(3);
+    args->rangey       = smanager->get_param(4);
+    renew_task->add_param((int)args);
 
     /**
-     * 共通の outData, param はそのまま渡す
-     */
-    for (int i = 0; i < rangey; i++) {
-	renew_task->add_outData(smanager->get_outputAddr(i),
-			   smanager->get_outputSize(i));
-    }
-
-    // rangex_start, rangex_end, rangey
-    renew_task->add_param(smanager->get_param(0));
-    renew_task->add_param(smanager->get_param(1)); 
-    renew_task->add_param(smanager->get_param(2));
-
-    /**
-     * SpanPack は続きから開始するので、
-     * 現在の状態をコピーしておく。
-     * spack は rbuf から取得してる可能性があり
-     * rbuf はシステムが自動的に free() するため
-     * アドレスだけ渡すのはNG
+     * SpanPack 膓紮с
+     * 憜倶潟若
+     * spack  rbuf 緇醇с
+     * rbuf 激鴻 free() 
+     * ≪鴻羝<NG
      */ 
     SpanPackPtr curr = (SpanPackPtr)smanager->allocate(sizeof(SpanPack));
     memcpy(curr, spack, sizeof(SpanPack));
     renew_task->add_param((int)curr);
     renew_task->add_param(cur_span_x);
 
+    // linebuf  zRow 綣膓
+    renew_task->add_param((int)linebuf);
+    renew_task->add_param((int)zRow);
+
     /**
-     * 再起動したタスクを待つ
+     * 莎桁帥鴻緇
      */ 
     smanager->wait_task(renew_task);
 
-    // next_spack は free() するので wait する
+    // next_spack  free()  wait 
     smanager->dma_wait(SPAN_PACK_LOAD);
 }
 
+void
+DrawSpan::writebuffer(unsigned int display, int buf_width, int height,
+		      int screen_width)
+{
+    for (int i = 0; i < height; i++) {
+	smanager->dma_store(&linebuf[i*buf_width],
+			    display + (sizeof(int)*screen_width*i),
+			    sizeof(int)*buf_width, FB_STORE);
+    }
+
+    doneWrite = 1;
+}
+
 int
 DrawSpan::run(void *rbuf, void *wbuf)
 {
+    SpanPackPtr spack = (SpanPackPtr)smanager->get_input(0);
+    SpanPackPtr next_spack = (SpanPackPtr)smanager->allocate(sizeof(SpanPack));
+    SpanPackPtr free_spack = next_spack; // next_spack  free() 
+    Span *span;
+
+    uint32 display   = smanager->get_param(0);
+    int screen_width = smanager->get_param(1);
+    int rangex_start = smanager->get_param(2);
+    int rangex_end   = smanager->get_param(3); 
+
+    // 帥鴻綵 x 膀
+    int rangex = rangex_end - rangex_start + 1;
+
+    // y 膀
+    int rangey = smanager->get_param(4);
+    
     hash = (TileHashPtr)smanager->global_get(GLOBAL_TEXTURE_HASH);
     tileList = (TileListPtr)smanager->global_get(GLOBAL_TILE_LIST);
 
-    int rangex_start  = smanager->get_param(0);
-    int rangex_end    = smanager->get_param(1); 
-
-    // このタスクが担当する x の範囲
-    int rangex        = rangex_end - rangex_start + 1;
-
-    // y の範囲 (render_y + rangey - 1)
-    int rangey        = smanager->get_param(2);
-    
-    float *zRow = (float*)smanager->allocate(sizeof(float)*rangex*rangey);
+    zRow = zRow_init(rangex, rangey);
+    linebuf = linebuf_init(rangex, rangey, 0xffffffff);
 
-    for (int i = 0; i < rangex*rangey; i++) {
-	zRow[i] = 65535.0f;
-    }
-
-    int **linebuf = (int**)smanager->allocate(sizeof(int*)*rangey);
-
-    for (int i = 0; i < rangey; i++) {
-	linebuf[i] = (int*)smanager->get_output(i);
-	linebuf_init(linebuf[i], rangex, 0xffffffff);
-    }
-
-    SpanPackPtr spack = (SpanPackPtr)smanager->get_input(0);
-    SpanPackPtr next_spack = (SpanPackPtr)smanager->allocate(sizeof(SpanPack));
-    SpanPackPtr free_spack = next_spack; // next_spack の free() 用
-    Span *span;
+    doneWrite = 0;
 
     do {
 	/**
-	 * SpanPack->next が存在する場合、
-	 * 現在の SpanPack を処理してる間に
-	 * 次の SpanPack の DMA 転送を行う
+	 * SpanPack->next 絖翫
+	 * 憜 SpanPack 
+	 * 罨< SpanPack  DMA 荵∫茵
 	 */
 	if (spack->next != NULL) {
 	    smanager->dma_load(next_spack, (uint32)spack->next,
@@ -231,22 +274,22 @@
 	for (int t = 0; t < spack->info.size; t++) {	  
 	    span = &spack->span[t];
 
-	    Uint32 rgb = 0x00ff00;
+	    uint32 rgb = 0x0000ff00;
 	    float tex1 = span->tex_x1;
 	    float tex2 = span->tex_x2;
 	    float tey1 = span->tex_y1;
 	    float tey2 = span->tex_y2;
 
 	    /**
-	     * Span が持つ 1 pixel 毎の
-	     * テクスチャの座標
+	     * Span  1 pixel 罸
+	     * 鴻c綺ф
 	     */
 	    int tex_xpos;
 	    int tex_ypos;
 
 	    /**
-	     * (tex_xpos, tex_ypos) の、ブロック内(上の図参照)での座標と
-	     * そのブロックのアドレス(MainMemory)
+	     * (tex_xpos, tex_ypos) (筝喝)с綺ф
+	     * ≪(MainMemory)
 	     */
 	    int tex_localx;
 	    int tex_localy;
@@ -258,7 +301,7 @@
 	    float z = span->start_z;
 	    float zpos = span->end_z;
 
-	    // 座標が [0 .. split_screen_w-1] に入るように x,y を -1
+	    // 綺ф [0 .. split_screen_w-1] ャ x,y  -1
 	    int localx = getLocalX(x-1);
 	    int localy = getLocalY(y-1);
 
@@ -270,30 +313,21 @@
 		tex_xpos = (int)((span->tex_width-1) * tex1);
 		tex_ypos = (int)((span->tex_height-1) * tey1);
 
-		if (zpos < zRow[localx + (rangex * localy)]) {
+		if (zpos < zRow[localx + (rangex*localy)]) {
 		    tex_addr = getTile(tex_xpos, tex_ypos,
 				       span->tex_width, span->tex_addr);
 		    tex_localx = tex_xpos % TEXTURE_SPLIT_PIXEL;
 		    tex_localy = tex_ypos % TEXTURE_SPLIT_PIXEL;
 		    
-		    /**
-		     * Tile が無い場合、一旦タスクはここで中断し、
-		     * Tile をロードするタスクを走らせた後に再起動する
-		     */
 		    if (!isAvailableTile(tex_addr)) {
-			spack->info.start = t;
-			//set_rgb(tex_addr);
-			set_rgbs(tex_addr,
-				 getTile(span->tex_width-1, tex_ypos,
-					 span->tex_width, span->tex_addr));
-			//reboot(spack, 0);
-			//goto FINISH;
+			set_rgb(tex_addr);
+			smanager->dma_wait(TEX_LOAD);
 		    }
 
 		    rgb = get_rgb(tex_localx, tex_localy, tex_addr);
 
-		    zRow[localx + (rangex * localy)] = zpos;
-		    linebuf[localy][localx] = rgb;
+		    zRow[localx + (rangex*localy)] = zpos;
+		    linebuf[localx + (rangex*localy)] = rgb;
 		}
 	    } else {
 		int js = (x < rangex_start) ? rangex_start - x : 0;
@@ -320,20 +354,29 @@
 			tex_localx = tex_xpos % TEXTURE_SPLIT_PIXEL;
 			tex_localy = tex_ypos % TEXTURE_SPLIT_PIXEL;
 
+			/**
+			 * Tile <翫筝帥鴻т賢
+			 * Tile 若帥鴻莎違緇莎桁
+			 */
 			if (!isAvailableTile(tex_addr)) {
 			    spack->info.start = t;
-			    //set_rgb(tex_addr);
+#if 1
 			    set_rgbs(tex_addr,
 				     getTile(span->tex_width-1, tex_ypos,
 					     span->tex_width, span->tex_addr));
+			    //smanager->dma_wait(TEX_LOAD);
 			    reboot(spack, j);
 			    goto FINISH;
+#else
+			    set_rgb(tex_addr);
+			    smanager->dma_wait(TEX_LOAD);
+#endif
 			}
 			
 			rgb = get_rgb(tex_localx, tex_localy, tex_addr);
 		    
 			zRow[localx + (rangex*localy)] = tex_z;
-			linebuf[localy][localx] = rgb;
+			linebuf[localx + (rangex*localy)] = rgb;
 		    }
 		}
 	    }
@@ -346,11 +389,19 @@
 	next_spack = tmp_spack;
     } while (spack);
 
+    writebuffer(display, rangex, rangey, screen_width);
+
+    // linebuf writebuffer()  dma_store  wait 
+    // DrawSpan::~DrawSpan()  free 
+    //free(linebuf);
+    free(zRow);
 
 FINISH:
+    /**
+     * goto FINISH;  reboot 
+     * linebuf, zRow  free() 
+     */
     free(free_spack);
-    free(linebuf);
-    free(zRow);
 
     return 0;
 }
--- a/TaskManager/Test/test_render/task/DrawSpan.h	Tue Jan 13 10:41:05 2009 +0900
+++ b/TaskManager/Test/test_render/task/DrawSpan.h	Tue Jan 13 19:06:13 2009 +0900
@@ -17,32 +17,39 @@
 #  include "TileHash.h"
 #endif
 
-typedef int8_t          Sint8;
-typedef uint8_t         Uint8;
-typedef int16_t         Sint16;
-typedef uint16_t        Uint16;
-typedef int32_t         Sint32;
-typedef uint32_t        Uint32;
-typedef unsigned short  GLushort;
-
 class DrawSpan : public SchedTask {
 public:
     SchedConstructor(DrawSpan);
 
+    int *linebuf;
+    float *zRow;
     TileHashPtr hash;
     TileListPtr tileList;
+    int doneWrite;
+
+    ~DrawSpan(void);
 
     int run(void *rbuf, void *wbuf);
 
-    void linebuf_init(int *buf, int width, int rgb);    
+    int* linebuf_init(int width, int height, int rgb);
+    float* zRow_init(int width, int height);
     void set_rgb(uint32 *addr);
     void set_rgbs(uint32 *addr, uint32 *max_addr);
-    Uint32 get_rgb(int tx, int ty, uint32 *addr);
+    uint32 get_rgb(int tx, int ty, uint32 *addr);
     TilePtr isAvailableTile(uint32 *addr);
     uint32* getTile(int tx, int ty, int tw, uint32 *tex_addr_top);
     int getTexBlock(int tx, int ty, int twidth);
+    void writebuffer(unsigned int display, int width, int height, int screen_width);
 
     void reboot(SpanPackPtr spack, int cur_span_x);
 };
 
+typedef struct {
+    uint32 display;
+    int screen_width;
+    int rangex_start;
+    int rangex_end;
+    int rangey;
+} DrawSpanArg, *DrawSpanArgPtr;
+
 #endif
--- a/TaskManager/Test/test_render/task/DrawSpanRenew.cpp	Tue Jan 13 10:41:05 2009 +0900
+++ b/TaskManager/Test/test_render/task/DrawSpanRenew.cpp	Tue Jan 13 19:06:13 2009 +0900
@@ -9,45 +9,68 @@
 
 #define SPAN_PACK_LOAD 0
 #define TEX_LOAD 1
+#define FB_STORE 2
 
 SchedDefineTask(DrawSpanRenew);
 
+void
+DrawSpanRenew::reboot(SpanPackPtr spack, int cur_span_x)
+{
+    TaskPtr renew_task = smanager->create_task(TASK_DRAW_SPAN2);
+
+    renew_task->add_param((int)args);
+
+    SpanPackPtr curr = (SpanPackPtr)smanager->allocate(sizeof(SpanPack));
+    memcpy(curr, spack, sizeof(SpanPack));
+    renew_task->add_param((int)curr);
+    renew_task->add_param(cur_span_x);
+
+    // linebuf と zRow も引き継がせる
+    renew_task->add_param((int)linebuf);
+    renew_task->add_param((int)zRow);
+
+    /**
+     * 再起動したタスクを待つ
+     */ 
+    smanager->wait_task(renew_task);
+
+    // next_spack は free() するので wait する
+    smanager->dma_wait(SPAN_PACK_LOAD);
+}
+
 int
 DrawSpanRenew::run(void *rbuf, void *wbuf)
 {
-    hash = (TileHashPtr)smanager->global_get(GLOBAL_TEXTURE_HASH);
-    tileList = (TileListPtr)smanager->global_get(GLOBAL_TILE_LIST);
-
-    int rangex_start  = smanager->get_param(0);
-    int rangex_end    = smanager->get_param(1); 
-
-    // このタスクが担当する x の範囲
-    int rangex        = rangex_end - rangex_start + 1;
-
-    // y の範囲 (render_y + rangey - 1)
-    int rangey        = smanager->get_param(2);
-    
-    float *zRow = (float*)smanager->allocate(sizeof(float)*rangex*rangey);
-
-    for (int i = 0; i < rangex*rangey; i++) {
-	zRow[i] = 65535.0f;
-    }
-
-    int **linebuf = (int**)smanager->allocate(sizeof(int*)*rangey);
-
-    for (int i = 0; i < rangey; i++) {
-	linebuf[i] = (int*)smanager->get_output(i);
-	linebuf_init(linebuf[i], rangex, 0xffffffff);
-    }
-
-    SpanPackPtr spack = (SpanPackPtr)smanager->get_param(3);
+    SpanPackPtr spack = (SpanPackPtr)smanager->get_param(1);
     SpanPackPtr next_spack = (SpanPackPtr)smanager->allocate(sizeof(SpanPack));
     SpanPackPtr free_spack1 = spack;
     SpanPackPtr free_spack2 = next_spack;
     Span *span;
+
+    args = (DrawSpanArgPtr)smanager->get_param(0);
+    uint32 display   = args->display;
+    int screen_width = args->screen_width;
+    int rangex_start = args->rangex_start;
+    int rangex_end   = args->rangex_end;
+
+    // このタスクが担当する x の範囲
+    int rangex = rangex_end - rangex_start + 1;
+
+    // y の範囲 (render_y + rangey - 1)
+    int rangey = args->rangey;
+
+    hash = (TileHashPtr)smanager->global_get(GLOBAL_TEXTURE_HASH);
+    tileList = (TileListPtr)smanager->global_get(GLOBAL_TILE_LIST);
     
+    linebuf = (int*)smanager->get_param(3);
+    zRow = (float*)smanager->get_param(4);
+
+    doneWrite = 0;
+
     // span->length_x の処理での再起動位置
-    int js_cont = smanager->get_param(4);
+    int js_cont = smanager->get_param(2);
+
+    //fprintf(stderr, "[%p] end   %u\n", spack, spu_readch(SPU_RdDec));
 
     smanager->dma_wait(TEX_LOAD);
 
@@ -67,7 +90,7 @@
 	for (int t = spack->info.start; t < spack->info.size; t++) {	  
 	    span = &spack->span[t];
 
-	    Uint32 rgb = 0x00ff0000;
+	    uint32 rgb = 0x00ff0000;
 	    float tex1 = span->tex_x1;
 	    float tex2 = span->tex_x2;
 	    float tey1 = span->tex_y1;
@@ -112,24 +135,15 @@
 		    tex_localx = tex_xpos % TEXTURE_SPLIT_PIXEL;
 		    tex_localy = tex_ypos % TEXTURE_SPLIT_PIXEL;
 
-		    /**
-		     * Tile が無い場合、一旦タスクはここで中断し、
-		     * Tile をロードするタスクを走らせた後に再起動する
-		     */
 		    if (!isAvailableTile(tex_addr)) {
-			spack->info.start = t;
-			//set_rgb(tex_addr);
-			set_rgbs(tex_addr,
-				 getTile(span->tex_width-1, tex_ypos,
-					 span->tex_width, span->tex_addr));
-			//reboot(spack, 0);
-			//goto FINISH;
+			set_rgb(tex_addr);
+			smanager->dma_wait(TEX_LOAD);
 		    }
 		    
 		    rgb = get_rgb(tex_localx, tex_localy, tex_addr);
 
-		    zRow[localx + (rangex * localy)] = zpos;
-		    linebuf[localy][localx] = rgb;
+		    zRow[localx + (rangex*localy)] = zpos;
+		    linebuf[localx + (rangex*localy)] = rgb;
 		}
 	    } else {
 		int js = (x < rangex_start) ? rangex_start - x : 0;
@@ -163,20 +177,25 @@
 					   span->tex_width, span->tex_addr);
 			tex_localx = tex_xpos % TEXTURE_SPLIT_PIXEL;
 			tex_localy = tex_ypos % TEXTURE_SPLIT_PIXEL;
+
 			if (!isAvailableTile(tex_addr)) {
 			    spack->info.start = t;
-			    //set_rgb(tex_addr);
+#if 0
 			    set_rgbs(tex_addr,
 				     getTile(span->tex_width-1, tex_ypos,
 					     span->tex_width, span->tex_addr));
-			    //reboot(spack, j);
-			    //goto FINISH;
+			    reboot(spack, j);
+			    goto FINISH;
+#else
+			    set_rgb(tex_addr);
+			    smanager->dma_wait(TEX_LOAD);
+#endif
 			}
 			
 			rgb = get_rgb(tex_localx, tex_localy, tex_addr);
 		    
 			zRow[localx + (rangex*localy)] = tex_z;
-			linebuf[localy][localx] = rgb;
+			linebuf[localx + (rangex*localy)] = rgb;
 		    }
 		}
 	    }
@@ -189,19 +208,17 @@
 	next_spack = tmp_spack;
     } while (spack);
 
+    writebuffer(display, rangex, rangey, screen_width);
+
+    free(zRow);
+    free(args);
 
 FINISH:
-    smanager->dma_wait(SPAN_PACK_LOAD);
-    //free(next_spack);
-    free(linebuf);
-    free(zRow);
-
-    // Renew したタスクで allocate されたものなので、これも free
-    //free(spack);
-
+    /**
+     * linebuf, zRow, args は RenewTask が引き継ぐ
+     */
     free(free_spack1);
     free(free_spack2);
 
-
     return 0;
 }
--- a/TaskManager/Test/test_render/task/DrawSpanRenew.h	Tue Jan 13 10:41:05 2009 +0900
+++ b/TaskManager/Test/test_render/task/DrawSpanRenew.h	Tue Jan 13 19:06:13 2009 +0900
@@ -9,7 +9,12 @@
 public:
     SchedConstructor(DrawSpanRenew);
 
+    DrawSpanArgPtr args;
+
     int run(void *rbuf, void *wbuf);
+
+    // override
+    void reboot(SpanPackPtr spack, int cur_span_x);
 };
 
 #endif
--- a/TaskManager/Test/test_render/viewer.cpp	Tue Jan 13 10:41:05 2009 +0900
+++ b/TaskManager/Test/test_render/viewer.cpp	Tue Jan 13 19:06:13 2009 +0900
@@ -326,17 +326,21 @@
 		// Draw SpanPack
 		task_draw = manager->create_task(TASK_DRAW_SPAN);
 		task_draw->add_inData(spack, sizeof(SpanPack));
+		
+		task_draw->add_param(
+		    (uint32)&pixels[(startx-1) + this->width*(starty-1)]);
+		task_draw->add_param(this->width);
 	    } else {
-		break;
+		//break;
 		// Draw Background (憜紂ゃ吟)
 		task_draw = manager->create_task(TASK_DRAW_BACK);
 		task_draw->add_param(0xffffffff);
-	    }
 	    
-	    for (int k = 0; k < rangey; k++) {
-		task_draw->add_outData(
-		    &pixels[(startx-1)+this->width*(k+starty-1)],
-		    (endx - startx + 1)*sizeof(int));
+		for (int k = 0; k < rangey; k++) {
+		    task_draw->add_outData(
+			&pixels[(startx-1)+this->width*(k+starty-1)],
+			(endx - startx + 1)*sizeof(int));
+		}
 	    }
 
 	    task_draw->add_param(startx);
--- a/TaskManager/Test/test_render/viewer_types.h	Tue Jan 13 10:41:05 2009 +0900
+++ b/TaskManager/Test/test_render/viewer_types.h	Tue Jan 13 19:06:13 2009 +0900
@@ -7,7 +7,7 @@
 const int TEXTURE_BLOCK_SIZE = TEXTURE_SPLIT_PIXEL*TEXTURE_SPLIT_PIXEL;
 
 // 一個の SPE が描画担当する width, height (pixel)
-const int split_screen_w = 512;
+const int split_screen_w = 256;
 const int split_screen_h = 8;
 
 enum video_type {
--- a/include/TaskManager/Task.h	Tue Jan 13 10:41:05 2009 +0900
+++ b/include/TaskManager/Task.h	Tue Jan 13 19:06:13 2009 +0900
@@ -13,7 +13,7 @@
 #  include "ListData.h"
 #endif
 
-#define MAX_PARAMS 7
+#define MAX_PARAMS 8
 
 class Task {
 public: // variables
--- a/include/TaskManager/base.h	Tue Jan 13 10:41:05 2009 +0900
+++ b/include/TaskManager/base.h	Tue Jan 13 19:06:13 2009 +0900
@@ -3,8 +3,8 @@
 #include <stdio.h>
 
 
-//#ifdef __SPU__
-#if 0
+#ifdef __SPU__
+//#if 0
 #  define BASE_NEW_DELETE(T)						\
     /* override new/detele */                                           \
     static void* operator new(size_t size) {                            \