changeset 94:588ab5f0e659

*** empty log message ***
author gongo
date Thu, 28 Feb 2008 17:41:08 +0900
parents dd33ec2e51b9
children 6315da182c66
files TaskManager/Cell/spe/CellScheduler.cc TaskManager/Cell/spe/SchedExit.cc TaskManager/Cell/spe/SchedMail.cc TaskManager/Cell/spe/SchedNop.cc TaskManager/Cell/spe/SchedNop2Ready.cc TaskManager/Cell/spe/Scheduler.cc TaskManager/Cell/spe/main.cc TaskManager/Test/simple_render/Makefile TaskManager/Test/simple_render/fb.cpp TaskManager/Test/simple_render/main.cpp TaskManager/Test/simple_render/span_pack.h TaskManager/Test/simple_render/spe/Makefile TaskManager/Test/simple_render/spe/SpuDraw.cpp TaskManager/Test/simple_render/spe/SpuDraw.h TaskManager/Test/simple_render/spe/spe-main.cpp TaskManager/Test/simple_render/viewer.cpp TaskManager/kernel/ppe/BufferManager.cc TaskManager/kernel/ppe/TaskManagerImpl.cc TaskManager/kernel/ppe/TaskQueueInfo.cc
diffstat 19 files changed, 751 insertions(+), 54 deletions(-) [+]
line wrap: on
line diff
--- a/TaskManager/Cell/spe/CellScheduler.cc	Thu Feb 28 17:32:18 2008 +0900
+++ b/TaskManager/Cell/spe/CellScheduler.cc	Thu Feb 28 17:41:08 2008 +0900
@@ -1,4 +1,5 @@
 #include <malloc.h>
+#include <stdio.h>
 #include "CellScheduler.h"
 #include "CellDmaManager.h"
 #include "error.h"
@@ -12,8 +13,12 @@
 {
     connector = new CellDmaManager;
 
+    printf("%d\n", DMA_MAX_SIZE);
+    printf("%d\n", sizeof(TaskList));
+
     for (int i = 0; i < 2; i++) {
-	listBuf[i] = (TaskListPtr)memalign(DEFAULT_ALIGNMENT, DMA_MAX_SIZE);
+	//listBuf[i] = (TaskListPtr)memalign(DEFAULT_ALIGNMENT, DMA_MAX_SIZE);
+	listBuf[i] = (TaskListPtr)memalign(DEFAULT_ALIGNMENT, sizeof(TaskList));
 	readBuf[i] = memalign(DEFAULT_ALIGNMENT, DMA_MAX_SIZE);
 	writeBuf[i] = memalign(DEFAULT_ALIGNMENT, DMA_MAX_SIZE);
     }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TaskManager/Cell/spe/SchedExit.cc	Thu Feb 28 17:41:08 2008 +0900
@@ -0,0 +1,13 @@
+#include <stdio.h>
+#include "SchedExit.h"
+#include "error.h"
+
+SchedTaskBase*
+SchedExit::next(Scheduler *m, SchedTaskBase *p)
+{
+    delete p;
+
+    __debug("SchedExit::next()\n");
+
+    return NULL;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TaskManager/Cell/spe/SchedMail.cc	Thu Feb 28 17:41:08 2008 +0900
@@ -0,0 +1,35 @@
+#include "SchedMail.h"
+#include "SchedTaskList.h"
+#include "SchedExit.h"
+#include "error.h"
+
+SchedMail::SchedMail(DmaManager *cn)
+{
+    connector = cn;
+}
+
+void
+SchedMail::read(void)
+{
+
+    __debug("[SchedMail:%s]\n", __FUNCTION__);
+    
+    params_addr = connector->mail_read();
+    
+    __debug("  params_addr = 0x%x\n", params_addr);
+}
+
+SchedTaskBase*
+SchedMail::next(Scheduler *m, SchedTaskBase *p)
+{
+    delete p;
+
+    __debug("[SchedMail:%s]\n", __FUNCTION__);
+
+    // if 文なくすには・・・関数ポインタ?
+    if ((int)params_addr == MY_SPE_COMMAND_EXIT) {
+	return new SchedExit();
+    } else {
+	return new SchedTaskList(params_addr, m->get_curListBuf(), connector);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TaskManager/Cell/spe/SchedNop.cc	Thu Feb 28 17:41:08 2008 +0900
@@ -0,0 +1,14 @@
+#include <stdio.h>
+#include "SchedNop.h"
+#include "SchedMail.h"
+#include "error.h"
+
+SchedTaskBase*
+SchedNop::next(Scheduler *m, SchedTaskBase *p)
+{
+    __debug("SchedNop::next()");
+    
+    delete p;
+
+    return new SchedMail(m->connector);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TaskManager/Cell/spe/SchedNop2Ready.cc	Thu Feb 28 17:41:08 2008 +0900
@@ -0,0 +1,27 @@
+#include <stdio.h>
+#include "SchedNop2Ready.h"
+#include "SchedMail.h"
+#include "error.h"
+
+SchedNop2Ready::SchedNop2Ready(DmaManager *cn)
+{
+    connector = cn;
+}
+
+void
+SchedNop2Ready::exec(void)
+{
+    __debug("[SchedNop2Ready:%s]\n", __FUNCTION__);
+
+    connector->mail_write(MY_SPE_STATUS_READY);
+}
+
+SchedTaskBase*
+SchedNop2Ready::next(Scheduler *m, SchedTaskBase *p)
+{
+    __debug("[SchedNop2Ready:%s]\n", __FUNCTION__);
+    
+    delete p;
+
+    return new SchedMail(connector);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TaskManager/Cell/spe/Scheduler.cc	Thu Feb 28 17:41:08 2008 +0900
@@ -0,0 +1,75 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include "Scheduler.h"
+#include "SchedNop.h"
+#include "error.h"
+
+void
+Scheduler::init(void)
+{
+    init_impl();
+    
+    listBufFlg = 0;
+    readBufFlg = 0;
+    writeBufFlg = 0;
+}
+
+void
+Scheduler::run(void)
+{
+    SchedTaskBase* taskTmp;
+    task1 = new SchedNop();
+    task2 = new SchedNop();
+    task3 = new SchedNop();
+
+    // main loop
+    do {
+	__debug("----------\n");
+	task3->write();
+	task2->exec();
+	task1->read();
+
+	taskTmp = task3;
+	task3 = task2;
+	task2 = task1;
+	task1 = task1->next(this, taskTmp);
+    } while (task1);
+
+    delete task3;
+    delete task2;
+}
+
+
+void
+Scheduler::finish(void)
+{
+    free(listBuf[0]);
+    free(listBuf[1]);
+    free(readBuf[0]);
+    free(readBuf[1]);
+    free(writeBuf[0]);
+    free(writeBuf[1]);
+}
+
+TaskListPtr
+Scheduler::get_curListBuf(void)
+{
+    listBufFlg ^= 1;
+    return listBuf[listBufFlg];
+}
+
+
+void *
+Scheduler::get_curWriteBuf(void)
+{
+    writeBufFlg ^= 1;
+    return writeBuf[writeBufFlg];
+}
+
+
+void*
+Scheduler::get_curReadBuf(void)
+{
+    readBufFlg ^= 1;
+    return readBuf[readBufFlg];
+}
--- a/TaskManager/Cell/spe/main.cc	Thu Feb 28 17:32:18 2008 +0900
+++ b/TaskManager/Cell/spe/main.cc	Thu Feb 28 17:41:08 2008 +0900
@@ -1,14 +1,25 @@
 #include <stdio.h>
 #include "CellScheduler.h"
 
+extern unsigned char _end[];
+
 int
 main(unsigned long long speid,
      unsigned long long argc, unsigned long long argv)
 {
     CellScheduler *manager;
 
+    const unsigned ls_size   = (unsigned)&argc;
+    unsigned code_size = (unsigned)&_end;
+    unsigned heap_size = ls_size - code_size;
+
+    printf("  ls_size:%10d bytes\n", ls_size);
+    printf("code_size:%10d bytes\n", code_size);
+    printf("heap_size:%10d bytes\n", heap_size);
+
     manager = new CellScheduler();
     manager->init();
+
     manager->run();
     manager->finish();
 
--- a/TaskManager/Test/simple_render/Makefile	Thu Feb 28 17:32:18 2008 +0900
+++ b/TaskManager/Test/simple_render/Makefile	Thu Feb 28 17:41:08 2008 +0900
@@ -13,13 +13,13 @@
 
 EXTRA_CFLAGS = `sdl-config --cflags` `xml2-config --cflags`\
 
-#EXTRA_LIBS = -lCellManager -lspe2 -lpthread
-EXTRA_LIBS = -lFifoManager
+EXTRA_LIBS = -lCellManager -lspe2 -lpthread
+#EXTRA_LIBS = -lFifoManager
 
-#LIBS = `sdl-config --libs` -lSDL_image -lGL \
-#       `xml2-config --libs` -L../.. $(EXTRA_LIBS)
-LIBS = `sdl-config --libs` -lSDL_image -Wl,-framework,OpenGL \
-      `xml2-config --libs` -L../.. $(EXTRA_LIBS)
+LIBS = `sdl-config --libs` -lSDL_image -lGL \
+       `xml2-config --libs` -L../.. $(EXTRA_LIBS)
+#LIBS = `sdl-config --libs` -lSDL_image -Wl,-framework,OpenGL \
+#      `xml2-config --libs` -L../.. $(EXTRA_LIBS)
 
 .SUFFIXES: .cpp .o
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TaskManager/Test/simple_render/fb.cpp	Thu Feb 28 17:41:08 2008 +0900
@@ -0,0 +1,102 @@
+/*
+ * fbtst.c 
+ *    2006.7.19 Kensuke Ooyu
+ */
+#include <unistd.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <linux/fb.h>
+#include <linux/fs.h>
+#include <sys/mman.h>
+#include <sys/ioctl.h>
+#include <stdlib.h>
+#include <iostream>
+using namespace std;
+
+#define DEVICE_NAME "/dev/fb0"
+#define DIV_BYTE 8
+
+#define X_PIXEL_MAX 320
+#define Y_LINE_MAX  240
+
+#define BORDER1 80
+#define BORDER2 160
+
+#define COLOR_RED    0xf800
+#define COLOR_GREEN  0x07e0
+#define COLOR_BLUE   0x001f
+#define COLOR_WHITE  0xffff
+#define COLOR_BLACK  0x0000
+#define COLOR_YELLOW 0xffe0
+
+/* function prototype */
+void send_current_error_msg(char *ptr);
+void send_current_information(char *ptr);
+
+int get_fbdev_addr(void)
+{
+	int fd_framebuffer ;
+	struct fb_var_screeninfo vinfo;
+	struct fb_fix_screeninfo finfo;
+	long int screensize ;
+	long int location;
+	char *fbptr ;
+	char tmp[DIV_BYTE*10];
+
+	int x , y ;
+	int xres,yres,vbpp,line_len;
+	unsigned short tcolor ;
+
+	/* 茯炊吾<ゃ */
+	fd_framebuffer = open( DEVICE_NAME , O_RDWR);
+	if ( !fd_framebuffer ) {
+		send_current_error_msg("Framebuffer device open error !");
+		exit(1);
+	}
+	send_current_information("The framebuffer device was opened !");
+
+	/* 阪鴻若恰怨緇 */
+	if ( ioctl( fd_framebuffer , FBIOGET_FSCREENINFO , &finfo ) ) {
+		send_current_error_msg("Fixed information not gotton !");
+		exit(2);
+	}
+
+	/* 紊鴻若恰怨緇 */
+	if ( ioctl( fd_framebuffer , FBIOGET_VSCREENINFO , &vinfo ) ) {
+		send_current_error_msg("Variable information not gotton !");
+		exit(3);
+	}
+	xres = vinfo.xres ;
+	yres = vinfo.yres ;
+	vbpp = vinfo.bits_per_pixel ;
+	line_len = finfo.line_length ;
+	sprintf( tmp , "%d(pixel)x%d(line), %dbpp(bits per pixel)",xres,yres,vbpp);
+	send_current_information( tmp );
+
+	/* ゃ篏с鴻若潟泣ゃ冴荐膊 */
+	screensize = xres * yres * vbpp / DIV_BYTE ;
+
+	/* ゃ鴻<≪ */
+	fbptr = (char *)mmap(0,screensize,PROT_READ | PROT_WRITE,MAP_SHARED,fd_framebuffer,0);
+	if ( (int)fbptr == -1 ) {
+		send_current_error_msg("Don't get framebuffer device to memory !");
+		exit(4);
+	}
+	send_current_information("The framebuffer device was mapped !");
+
+	printf("fb: %x \n",fbptr);
+	return (int)fbptr;
+	//munmap(fbptr,screensize);
+	//close(fd_framebuffer);
+	//return 0;
+}
+
+void send_current_error_msg(char *ptr)
+{
+	fprintf( stderr , "%s\n" , ptr );
+}
+
+void send_current_information(char *ptr)
+{
+	fprintf( stdout , "%s\n" , ptr );
+}
--- a/TaskManager/Test/simple_render/main.cpp	Thu Feb 28 17:32:18 2008 +0900
+++ b/TaskManager/Test/simple_render/main.cpp	Thu Feb 28 17:41:08 2008 +0900
@@ -84,15 +84,17 @@
 
 int run_loop(void *r, void *w)
 {
-    __debug("[%s]\n", __FUNCTION__);
+    __debug("[%s] start\n", __FUNCTION__);
     screen->run_loop();
+    __debug("[%s] end\n", __FUNCTION__);
     return 0;
 }
 
 int run_draw(void *r, void *w)
 {
-    __debug("[%s]\n", __FUNCTION__);
+    __debug("[%s] start\n", __FUNCTION__);
     screen->run_draw();
+    __debug("[%s] end\n", __FUNCTION__);
     return 0;
 }
 
--- a/TaskManager/Test/simple_render/span_pack.h	Thu Feb 28 17:32:18 2008 +0900
+++ b/TaskManager/Test/simple_render/span_pack.h	Thu Feb 28 17:41:08 2008 +0900
@@ -9,13 +9,14 @@
 } SPAN, *SPAN_PTR;
 
 typedef struct SpanPack {
-  struct SPAN_INFO {
-    int size;
-    int light_pos[3];
-    int light_rgb[3];
-  } info;
-  SPAN span[70];
-  //SPAN *span;
+    struct SPAN_INFO {
+	int size;
+	int light_pos[3];
+	int light_rgb[3];
+    } info;
+    SPAN span[70];
+    //SPAN *span;
+    int pad[1];
 } SPANPACK, *SPANPACK_PTR;
 
 /*
--- a/TaskManager/Test/simple_render/spe/Makefile	Thu Feb 28 17:32:18 2008 +0900
+++ b/TaskManager/Test/simple_render/spe/Makefile	Thu Feb 28 17:41:08 2008 +0900
@@ -4,7 +4,7 @@
 OBJS = $(SRCS:.cpp=.o)
 
 CC      = spu-g++
-CFLAGS  = -O9 #-g -Wall# -DDEBUG
+CFLAGS  = -O9 -Os -g -Wall -DDEBUG
 INCLUDE = -I../../../../include/TaskManager -I. -I..
 LIBS    = -L../../.. -lspemanager# -lm
 
@@ -23,4 +23,4 @@
 
 clean:
 	rm -f $(TARGET) $(OBJS)
-	rm -f *~ \#*
+	rm -f *~ \#*
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TaskManager/Test/simple_render/spe/SpuDraw.cpp	Thu Feb 28 17:41:08 2008 +0900
@@ -0,0 +1,320 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <spu_mfcio.h>
+#include "SpuDraw.h"
+#include "polygon_pack.h"
+#include "span_pack.h"
+#include "spu_span.h"
+#include "error.h"
+
+#define PIXELSIZE 11520 //32 line pixel size
+
+SpuDraw::~SpuDraw(void)
+{
+    free(*zRow);
+    free(zRow);
+
+    free(*linebuf);
+    free(linebuf);
+}
+
+void
+SpuDraw::linebuf_init()
+{
+    // memset, memzero ? とか
+    // DMAで取ってくるって手もある
+    int x = 8;
+    int y = IMG_MAX_Y;
+
+    linebuf = (int**)malloc(sizeof(int*)*x);
+    int *linebuf_head = (int*)malloc(sizeof(int)*x*y);
+
+    for (int i = 0; i < x; i++) {
+	linebuf[i] = linebuf_head + i*y;
+    }
+
+#if 0
+    for (int t = 0; t < 8; t++) {
+	for (int i = 0; i < IMG_MAX_Y; i++) {
+	    linebuf[t][i] = 0;
+	}
+    }
+#else
+    bzero(linebuf_head, sizeof(int)*x*y);
+    //memset(linebuf_head, 0, sizeof(float)*x*y);
+#endif
+}
+
+void
+SpuDraw::zRow_init(void)
+{
+    int x = 8;
+    int y = IMG_MAX_Y;
+
+    zRow = (float**)malloc(sizeof(float*)*x);
+    float *zRow_head = (float*)malloc(sizeof(float)*x*y);
+
+    for (int i = 0; i < x; i++) {
+	zRow[i] = zRow_head + i*y;
+    }
+
+#if 0
+    for (int t = 0; t < 8; t++) {
+	for (int i = 0; i < IMG_MAX_Y; i++) {
+	    zRow[t][i] = 65535;                
+	}  
+    }       
+#else
+    // memset や bzero でもいいし、
+    // DMAで取ってくるって手もある
+    memset(zRow_head, 0xffff, sizeof(float)*x*y);
+#endif
+}
+
+
+char*
+SpuDraw::get_pixel(int tx, int ty, void *texture_image)
+{
+    //return (char*)texture_image->pixels+(texture_image->format->BytesPerPixel*((texture_image->w)*ty+tx));
+    return (char*)texture_image+(3*((128)*ty+tx));
+}
+
+Uint32
+SpuDraw::SDL_MapRGB(SDL_PixelFormat *format,
+		    Uint8 r, Uint8 g, Uint8 b)
+{
+    if ( format->palette == NULL ) {
+	return (r >> format->Rloss) << format->Rshift
+	    | (g >> format->Gloss) << format->Gshift
+	    | (b >> format->Bloss) << format->Bshift
+	    | format->Amask;
+    } else {
+	return SDL_FindColor(format->palette, r, g, b);
+    }
+}
+
+Uint8
+SpuDraw::SDL_FindColor(SDL_Palette *pal, Uint8 r, Uint8 g, Uint8 b)
+{
+    /* Do colorspace distance matching */
+    unsigned int smallest;
+    unsigned int distance;
+    int rd, gd, bd;
+    int i;
+    Uint8 pixel=0;
+
+    smallest = ~0;
+    for ( i=0; i<pal->ncolors; ++i ) {
+	rd = pal->colors[i].r - r;
+	gd = pal->colors[i].g - g;
+	bd = pal->colors[i].b - b;
+	distance = (rd*rd)+(gd*gd)+(bd*bd);
+	if ( distance < smallest ) {
+	    pixel = i;
+	    if ( distance == 0 ) { /* Perfect match! */
+		break;
+	    }
+	    smallest = distance;
+	}
+    }
+    return(pixel);
+}
+
+Uint32
+SpuDraw::get_rgb(int tx, int ty, void *texture)
+{
+    Uint8 red, green, blue, alpha;
+  
+    if (tx<0) tx = 0;
+    if (128-1< tx) tx = 128-1 ;
+    if (ty<0) ty = 0;
+    if (128-1< ty) ty = 128-1 ;
+
+    char *p = get_pixel(tx,ty,texture);
+
+    blue  = (Uint8) p[0];
+    green = (Uint8) p[1];
+    red   = (Uint8) p[2];
+	  
+    SDL_PixelFormat pf;
+    pf.BitsPerPixel = 32;
+    pf.BytesPerPixel = 4;
+    alpha = 255;
+
+    return SDL_MapRGB(&pf, red, green, blue);
+}
+
+
+//int spu_draw(SPUSPAN *ss, unsigned int fbdev_addr)
+#if 0
+int
+SpuDraw::run(void *rbuf, void *writebuf)
+{
+    SPUSPAN *ss = (SPUSPAN*)rbuf;
+    unsigned int fbdev_addr = task->out_addr;
+
+    SPANPACK_PTR spanPack;
+    SPAN_PTR;
+
+    //void *texture = new char[128*128*3];
+    void **buff;
+    void *texture;
+    long *addr = ss->spp[0].tex_addr;
+    //GLushort zRow[8][IMG_MAX_Y];
+    GLushort *zRow; // あとで new
+    zRow = new GLushort[8][IMG_MAX_Y];
+    int j = 0;
+    int render_y = 0;
+
+    zRow_init();
+    linebuf_init(j);
+
+    render_y = ss->spp[0].span[0].y;
+    
+    for (int i = 0; i < 10; i++) {
+	spanPack = &ss->spp[i];
+
+	for (int t; t<ss->spp[i].info.size; t++) {
+	    span = &spanPack->span[t];
+
+	    int end = span->length_x;
+	    Uint32 rgb;
+	    float tex1 = span->tex_x1;
+	    float tex2 = span->tex_x2;
+	    float tey1 = span->tex_y1;
+	    float tey2 = span->tex_y2;
+	    int tex_xpos;
+	    int tex_ypos;
+	    int tex_zpos;
+	    int x = span->x;
+	    int y = span->y;
+	    float z = span->start_z;
+	    float zpos = span->end_z;
+	    float tex_x, tex_y, tex_z;
+	  
+	    if (end == 1) {
+		tex_xpos = (int)((span->tex_height-1) * tex1);
+		tex_ypos = (int)((span->tex_width-1) * tey1);
+		tex_zpos = (int)z;
+
+		if (z < zRow[x][y%8]) {
+		    //rgb = get_rgb(tex_xpos,tex_ypos);
+		    //viewer->write_pixel(x,y,zpos,rgb);
+		    //linebuf[j][x][y%8] = rgb;
+		    linebuf[x][y%8] = rgb
+		}
+
+	    } else {
+		//printf("end != 1\n");
+		for (int j = 0; j < end; j++) {
+		    tex_x = tex1*(end-1-j)/(end-1) + tex2*j/(end-1);
+		    tex_y = tey1*(end-1-j)/(end-1) + tey2*j/(end-1);
+		    tex_z = z*(end-1-j)/(end-1) + zpos*j/(end-1);
+		    if (tex_x > 1) tex_x = 1;
+		    if (tex_y > 1) tex_y = 1;
+		    tex_xpos = (int)((span->tex_height-1) * tex_x);
+		    tex_ypos = (int)((span->tex_width-1) * tex_y);
+
+		    if (z < zRow[x][y%8]) {
+			//rgb = get_rgb(tex_xpos,tex_ypos);
+			linebuf[j][x][y%8] = rgb;
+			//viewer->write_pixel(j+x,y,tex_z,rgb);
+		    }
+		}
+	    }
+	}
+	writebuffer(j,fbdev_addr,render_y);
+    }
+
+    return 0;
+}
+#else
+int
+SpuDraw::run(void *rbuf, void *writebuf)
+{
+    SPANPACK_PTR sp = (SPANPACK_PTR)rbuf;
+    unsigned int fbdev_addr = task->out_addr;
+    SPAN_PTR span;
+
+    __debug("[SpuDraw]:%s\n", __FUNCTION__);
+
+    //void *texture = new char[128*128*3];
+    //void **buff;
+    //void *texture;
+    //long *addr = ss->spp[0].tex_addr;
+    //GLushort zRow[8][IMG_MAX_Y];
+    //GLushort *zRow; // あとで new
+    //zRow = new GLushort[8][IMG_MAX_Y];
+    int render_y = 0;
+
+    zRow_init();
+    linebuf_init();
+
+    render_y = sp->span[0].y;
+    
+    //for (int t; t<sp->spp[i].info.size; t++) {
+    for (int t = 0; t < sp->info.size; t++) {
+	span = &sp->span[t];
+ 
+	int end = span->length_x;
+	Uint32 rgb = 0;
+	float tex1 = span->tex_x1;
+	float tex2 = span->tex_x2;
+	float tey1 = span->tex_y1;
+	float tey2 = span->tex_y2;
+	int tex_xpos;
+	int tex_ypos;
+	int tex_zpos;
+	int x = span->x;
+	int y = span->y;
+	float z = span->start_z;
+	float zpos = span->end_z;
+	float tex_x, tex_y, tex_z;
+	
+	if (end == 1) {
+	    tex_xpos = (int)((span->tex_height-1) * tex1);
+	    tex_ypos = (int)((span->tex_width-1) * tey1);
+	    tex_zpos = (int)z;
+
+	    if (z < zRow[x][y%8]) {
+		//rgb = get_rgb(tex_xpos,tex_ypos);
+		linebuf[x][y%8] = rgb;
+		//viewer->write_pixel(x,y,zpos,rgb);
+	    }
+
+	} else {
+	    for (int j = 0; j < end; j++) {
+		tex_x = tex1*(end-1-j)/(end-1) + tex2*j/(end-1);
+		tex_y = tey1*(end-1-j)/(end-1) + tey2*j/(end-1);
+		tex_z = z*(end-1-j)/(end-1) + zpos*j/(end-1);
+		if (tex_x > 1) tex_x = 1;
+		if (tex_y > 1) tex_y = 1;
+		tex_xpos = (int)((span->tex_height-1) * tex_x);
+		tex_ypos = (int)((span->tex_width-1) * tex_y);
+
+		if (z < zRow[x][y%8]) {
+		    //rgb = get_rgb(tex_xpos,tex_ypos);
+		    linebuf[x][y%8] = rgb;
+		    //viewer->write_pixel(j+x,y,tex_z,rgb);
+		}
+	    }
+	}
+    }
+    writebuffer(0,fbdev_addr,render_y);
+    return 0;
+}
+#endif
+
+void
+SpuDraw::writebuffer(int i, unsigned int fbdev_addr, int y) {
+    spu_mfcdma32(&linebuf[0][0], fbdev_addr, PIXELSIZE, 21, MFC_PUT_CMD);
+}
+
+
+SchedTask*
+createTask_spuDraw(TaskListPtr _taskList, TaskPtr _task,
+		   void *rbuff, void *wbuff, DmaManager *dma)
+{
+    return new SpuDraw(_taskList, _task, rbuff, wbuff, dma);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TaskManager/Test/simple_render/spe/SpuDraw.h	Thu Feb 28 17:41:08 2008 +0900
@@ -0,0 +1,73 @@
+#ifndef INCLUDED_TASK_SPU_DRAW
+#define INCLUDED_TASK_SPU_DRAW
+
+#ifndef INCLUDED_SCHED_TASK
+#  include "SchedTask.h"
+#endif
+
+//#define IMG_MAX_Y 1080
+#define IMG_MAX_Y 480
+
+#ifndef NULL
+#  define NULL ((void*)0)
+#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;
+
+typedef struct{
+    Uint8 r;
+    Uint8 g;
+    Uint8 b;
+    Uint8 unused;
+} SDL_Color;
+
+typedef struct{
+    int ncolors;
+    SDL_Color *colors;
+} SDL_Palette;
+
+typedef struct{
+    SDL_Palette *palette;
+    Uint8  BitsPerPixel;
+    Uint8  BytesPerPixel;
+    Uint32 Rmask, Gmask, Bmask, Amask;
+    Uint8  Rshift, Gshift, Bshift, Ashift;
+    Uint8  Rloss, Gloss, Bloss, Aloss;
+    Uint32 colorkey;
+    Uint8  alpha;
+} SDL_PixelFormat;
+
+
+class SpuDraw : public SchedTask {
+public:
+    SpuDraw(TaskListPtr _tlist, TaskPtr _task,
+	    void* _rbuf, void* _wbuf, DmaManager* _con)
+	:SchedTask(_tlist, _task, _rbuf, _wbuf, _con) {}
+
+    ~SpuDraw(void);
+
+    //int linebuf[8][IMG_MAX_Y];
+    //float zRow[8][IMG_MAX_Y];
+    int **linebuf;
+    float **zRow;
+    int run(void *readbuf, void *writebuf);
+
+private:
+    void zRow_init(void);
+    void linebuf_init(void);
+    void writebuffer(int i, unsigned int fbdev_addr, int y);
+
+    char* get_pixel(int tx, int ty, void *texture_image);
+    Uint32 get_rgb(int tx, int ty, void *texture);
+    Uint32 SDL_MapRGB(SDL_PixelFormat *fmt, Uint8 r, Uint8 g, Uint8 b);
+    Uint8 SDL_FindColor(SDL_Palette *pal, Uint8 r, Uint8 g, Uint8 b);
+};
+
+#endif
--- a/TaskManager/Test/simple_render/spe/spe-main.cpp	Thu Feb 28 17:32:18 2008 +0900
+++ b/TaskManager/Test/simple_render/spe/spe-main.cpp	Thu Feb 28 17:41:08 2008 +0900
@@ -1,10 +1,14 @@
 #include "SchedTask.h"
 
+//extern SchedTask*
+//createTask_createPolygonPack(TaskListPtr _taskList, TaskPtr _task,
+//		     void *rbuff, void *wbuff, DmaManager *dma);
+
 extern SchedTask*
-createTask_createPolygonPack(TaskListPtr _taskList, TaskPtr _task,
-			     void *rbuff, void *wbuff, DmaManager *dma);
+createTask_spuDraw(TaskListPtr _taskList, TaskPtr _task,
+		   void *rbuff, void *wbuff, DmaManager *dma);
 
-SchedTask::TaskObject task_list[16] = {0, 0, createTask_createPolygonPack, 0};
+SchedTask::TaskObject task_list[16];// = {0, 0, createTask_createPolygonPack, 0};
 
 static void
 set_task(int cmd, SchedTask::TaskObject task)
@@ -12,8 +16,11 @@
     task_list[cmd] = task;
 }
 
+class SpuDraw;
+
 void
 task_init(void)
 {
-    set_task(2, createTask_createPolygonPack);
+    //set_task(2, createTask_createPolygonPack);
+    set_task(0, createTask_spuDraw);
 }
--- a/TaskManager/Test/simple_render/viewer.cpp	Thu Feb 28 17:32:18 2008 +0900
+++ b/TaskManager/Test/simple_render/viewer.cpp	Thu Feb 28 17:41:08 2008 +0900
@@ -30,7 +30,7 @@
 	exit( 1 );
     }
     
-#ifndef _DEBUG
+#ifdef _DEBUG
     screen = SDL_SetVideoMode( width, height, bpp, SDL_HWSURFACE);
     if (screen == NULL) {
 	fprintf(stderr, "Couldn't set GL mode: %s\n", SDL_GetError());
@@ -225,6 +225,10 @@
 DmaBuffer *pp_buff;
 DmaBuffer *ssl_buff;
 
+SPANPACK send_pack[10] __attribute__((aligned(16)));
+unsigned int fbdev_addr;
+
+extern int get_fbdev_addr(void);
 
 void
 Viewer::run_init()
@@ -263,11 +267,12 @@
 	ssl_buff->swap_buffer();
     }
 #else
-    //posix_memalign((void**)&sgp, 16, sizeof(SceneGraphPack));
-    //posix_memalign((void**)&pp, 16, sizeof(SceneGraphPack));
-    sgp = new SceneGraphPack;
-    pp  = new PolygonPack;
-    ssl = new SPUSPANLIST;
+    posix_memalign((void**)&sgp, 16, sizeof(SceneGraphPack));
+    posix_memalign((void**)&pp, 16, sizeof(SceneGraphPack));
+    posix_memalign((void**)&ssl, 16, sizeof(SceneGraphPack));
+    //sgp = new SceneGraphPack;
+    //pp  = new PolygonPack;
+    //ssl = new SPUSPANLIST;
     create_sgp(polygon, sgp);
     sgp->ssl = ssl;
 #endif
@@ -283,6 +288,8 @@
     fd = manager->open("ViewerRunLoop");
     task = manager->create_task(fd, 0, 0, 0, NULL);      
     task->spawn();
+
+    fbdev_addr = get_fbdev_addr();
 }
 
 void
@@ -314,8 +321,8 @@
     // clean_pixels や zRow_init は、
     // spe で fb に draw する時は必要ない。
     // ppe 側で draw する時にだけ呼ぶべき。
-    clean_pixels();
-    zRow_init();
+    //clean_pixels();
+    //zRow_init();
 
     // これ自身、一つのタスクとして回す方がよいか
     graph_line();
@@ -381,14 +388,37 @@
  */
 
 //#define DRAW_POLYGON
-//#define DRAW_SPANPACK
-#define DRAW_SPUSPAN
+#define DRAW_SPANPACK
+//#define DRAW_SPUSPAN
 void
 Viewer::run_draw(void)
 {
     HTaskPtr task;
+    HTaskPtr task_draw[10];
     int fd;
 
+    fd = manager->open("ViewerRunLoop");
+    task = manager->create_task(fd, 0, 0, 0, NULL);
+
+    for (int i = 0; i < 10; i++) {
+	memcpy(&send_pack[i], &ssl->ss[0].spp[i], sizeof(SPANPACK));
+	task_draw[i]
+	    = manager->create_task(0, sizeof(SPANPACK),
+				   (uint32)&send_pack[i], fbdev_addr, NULL);
+	task_draw[i]->set_cpu(CPU_SPE);
+	task->set_depend(task_draw[i]);
+	task_draw[i]->spawn();
+    }
+
+    task->spawn();
+
+    SDL_BlitSurface(bitmap, NULL, screen, NULL);
+    SDL_UpdateRect(screen, 0, 0, 0, 0);    
+
+    frames++;
+
+    return;
+
 #if 0 // USE DOUBLE BUFFER
     PolygonPack *pp;
     SPUSPANLIST *ssl;
@@ -402,7 +432,7 @@
 
 #else
 #  ifdef DRAW_SPANPACK // test draw of SpanPack
-    for (int i = 0; i < 10; i++) {
+    for (int i = 0; i < 1; i++) {
 	polygon->draw(&ssl->ss[0].spp[i]);
 	polygon->draw(&ssl->ss[1].spp[i]);
 	polygon->draw(&ssl->ss[2].spp[i]);
@@ -419,15 +449,6 @@
     polygon->draw(&ssl->ss[5]);
 #  endif
 #endif
-
-    SDL_BlitSurface(bitmap, NULL, screen, NULL);
-    SDL_UpdateRect(screen, 0, 0, 0, 0);    
-
-    frames++;
-
-    fd = manager->open("ViewerRunLoop");
-    task = manager->create_task(fd, 0, 0, 0, NULL);
-    task->spawn();
 }
 
 #if 0
--- a/TaskManager/kernel/ppe/BufferManager.cc	Thu Feb 28 17:32:18 2008 +0900
+++ b/TaskManager/kernel/ppe/BufferManager.cc	Thu Feb 28 17:41:08 2008 +0900
@@ -120,8 +120,8 @@
 {
     TaskQueuePtr p = list;
     TaskQueuePtr p1;
-
-    if (!p) return p;
+    
+    if (p == NULL) return p;
 
     if (p->task == task) {
 	list = list->next;
--- a/TaskManager/kernel/ppe/TaskManagerImpl.cc	Thu Feb 28 17:32:18 2008 +0900
+++ b/TaskManager/kernel/ppe/TaskManagerImpl.cc	Thu Feb 28 17:41:08 2008 +0900
@@ -62,7 +62,7 @@
     s = bufferManager->create_taskQueue(slave);
 
     master->wait_me = TaskQueueInfo::append(master->wait_me, s);
-    slave->wait_i = TaskQueueInfo::append(slave->wait_i, m);
+    slave->wait_i   = TaskQueueInfo::append(slave->wait_i, m);
 }
 
 void
--- a/TaskManager/kernel/ppe/TaskQueueInfo.cc	Thu Feb 28 17:32:18 2008 +0900
+++ b/TaskManager/kernel/ppe/TaskQueueInfo.cc	Thu Feb 28 17:41:08 2008 +0900
@@ -47,10 +47,6 @@
 {
     TaskQueuePtr q;
     
-    static int i = 0;
-
-    printf("create %d\n", ++i);
- 
     if (freeTaskQueue == NULL) {
 	extend_pool(100);
     }
@@ -67,11 +63,6 @@
 void
 TaskQueueInfo::free(TaskQueuePtr q)
 {
-    static int i = 0;
-
-    printf("free   %d\n", ++i);
-    printf("## command %d ##\n", q->task->command);
-
     q->next = freeTaskQueue;
     freeTaskQueue = q;
 }