changeset 99:c534f339ee8b

change c++
author e085768
date Thu, 02 Jun 2011 17:51:41 +0900
parents 1033fece71ce
children e5f2eb98b575
files Makefile a.out camera.c camera.cc car.c car.cc carNode.c carNode.cc col.c col.cc controler.c controler.cc field.c field.cc gFont.c gFont.cc gSprite.c gSprite.cc game.c game.cc game_time.c game_time.cc hikae light.c light.cc linda.cc main.c main.cc mytype.c mytype.cc ps2util.c ps2util.cc quotanion.c quotanion.cc schedule.c schedule.cc schedule.h sjoy.c sjoy.cc test_vector test_vector.cc title_scene.c title_scene.cc
diffstat 43 files changed, 3723 insertions(+), 2785 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile	Thu Jun 02 17:26:21 2011 +0900
+++ b/Makefile	Thu Jun 02 17:51:41 2011 +0900
@@ -1,8 +1,8 @@
 TARGET = main
-CC = gcc
-SRCS = main.c game.c car.c col.c quotanion.c controler.c field.c camera.c gSprite.c schedule.c mytype.c gFont.c carNode.c light.c title_scene.c game_time.c ps2util.c sjoy.c 
-#linda/lindaapi.c linda.c
-OBJS = ${SRCS:.c=.o}
+CC = g++
+SRCS = main.cc game.cc car.cc col.cc quotanion.cc controler.cc field.cc camera.cc gSprite.cc schedule.cc mytype.cc gFont.cc carNode.cc light.cc title_scene.cc game_time.cc ps2util.cc sjoy.cc 
+#linda/lindaapi.cc linda.c
+OBJS = ${SRCS:.cc=.o}
 VU1DIR = vu1code
 
 #MPGOBJ =  mpg.elf
@@ -41,7 +41,7 @@
 ${TARGET} : ${OBJS}
 	${CC} -o ${TARGET} ${OBJS}
 
-${TEST} : test_vector.c ps2util.c 
+${TEST} : test_vector.cc ps2util.cc 
 	${CC} -o ${TEST} $^
 
 tag:
Binary file a.out has changed
--- a/camera.c	Thu Jun 02 17:26:21 2011 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,105 +0,0 @@
-#include <stdlib.h>
-#include <string.h>
-#include "libps2.h"
-#include "ps2util.h"
-#include "car.h"
-#include "game.h"
-#include "controler.h"
-#include "camera.h"
-
-//大域変数、各部で共有
-extern SGO_PAD pad;
-
-static CAMERA camera, def_camera;
-
-
-void
-camera_init()
-{
-  
- //カメラの初期位置設定
- def_camera.xyz[0] = 0;
- def_camera.xyz[1] =-7;// -3;
- def_camera.xyz[2] =-14; //0;
- def_camera.xyz[3] = 1;
-
- def_camera.zd[0] = 0;
- def_camera.zd[1] = 2;
- def_camera.zd[2] = 7;
- def_camera.zd[3] = 1;
-
- def_camera.yd[0] = 0;
- def_camera.yd[1] = 1;
- def_camera.yd[2] = 0;
- def_camera.yd[3] = 1;
-
- def_camera.angle[0]=-0.2;//0;  //pich
- def_camera.angle[1]=0;     //yoh 
- def_camera.angle[2]=0;     //roll
- def_camera.angle[3]=0;
-
- //def_cameraをcameraにコピー
- memcpy( &camera, &def_camera, sizeof(CAMERA));
- set_camera(&def_camera);
-  
-}
-
-/*
-  ps2依存関係から拝借。
-  自分が消したのか、元々無いのかは覚えていないけど
-  呼ばれているのでとりあえず(空っぽにしておく)。
-*/
-// set_camera must be called if camera's parameters were moved                  
-void set_camera(CAMERA *camera)
-{
-  //vu0_rot_camera_matrix(world_view, camera->xyz, camera->zd, camera->yd,camera->angle);
-}
-
-
-/**
- * pose: カメラの対象物(obj)の座標行列
- * カメラがobjについていくように(そのような動きに見せるため)
- * カメラの位置ベクトル、視点ベクトルを更新
- */
-void
-camera_update(Game *game, FMATRIX pose)
-{
-  FVECTOR location, eyes, vertical, angle;
-    
-  //int type = game->camera_type;
-
-  ps2_vu0_apply_matrix(location, pose, def_camera.xyz);
-  ps2_vu0_apply_matrix(eyes, pose, def_camera.zd);
-  ps2_vu0_apply_matrix(vertical, pose, def_camera.yd);
-
-  /**When the car bends, the angle of the camera is changed**/
-  if(pad.left>0  && game->jiki->speed !=0){
-    if(game->jiki->speed !=0){
-      if(def_camera.angle[1]<=0.2){
-	def_camera.angle[1]+=0.02;
-      }
-    }
-  }
-  else if(pad.right>0 && game->jiki->speed !=0){
-    if(game->jiki->speed !=0){
-      if(def_camera.angle[1]>=-0.2){
-        def_camera.angle[1]-=0.02;
-      }
-    }
-  }
-  else {
-    if(def_camera.angle[1]<-0.01){
-      def_camera.angle[1]+=0.02;
-    }
-    else if(def_camera.angle[1]>0.01){
-      def_camera.angle[1]-=0.02;
-    }
-  } 
-  ps2_vu0_apply_matrix(angle, pose, def_camera.angle);
-  ps2_vu0_copy_vector(camera.xyz, location);
-  ps2_vu0_copy_vector(camera.zd,  eyes);
-  ps2_vu0_copy_vector(camera.yd,  vertical);
-  ps2_vu0_copy_vector(camera.angle, angle);
-  set_camera(&camera);
-    
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/camera.cc	Thu Jun 02 17:51:41 2011 +0900
@@ -0,0 +1,105 @@
+#include <stdlib.h>
+#include <string.h>
+#include "libps2.h"
+#include "ps2util.h"
+#include "car.h"
+#include "game.h"
+#include "controler.h"
+#include "camera.h"
+
+//大域変数、各部で共有
+extern SGO_PAD pad;
+
+static CAMERA camera, def_camera;
+
+
+void
+camera_init()
+{
+  
+ //カメラの初期位置設定
+ def_camera.xyz[0] = 0;
+ def_camera.xyz[1] =-7;// -3;
+ def_camera.xyz[2] =-14; //0;
+ def_camera.xyz[3] = 1;
+
+ def_camera.zd[0] = 0;
+ def_camera.zd[1] = 2;
+ def_camera.zd[2] = 7;
+ def_camera.zd[3] = 1;
+
+ def_camera.yd[0] = 0;
+ def_camera.yd[1] = 1;
+ def_camera.yd[2] = 0;
+ def_camera.yd[3] = 1;
+
+ def_camera.angle[0]=-0.2;//0;  //pich
+ def_camera.angle[1]=0;     //yoh 
+ def_camera.angle[2]=0;     //roll
+ def_camera.angle[3]=0;
+
+ //def_cameraをcameraにコピー
+ memcpy( &camera, &def_camera, sizeof(CAMERA));
+ set_camera(&def_camera);
+  
+}
+
+/*
+  ps2依存関係から拝借。
+  自分が消したのか、元々無いのかは覚えていないけど
+  呼ばれているのでとりあえず(空っぽにしておく)。
+*/
+// set_camera must be called if camera's parameters were moved                  
+void set_camera(CAMERA *camera)
+{
+  //vu0_rot_camera_matrix(world_view, camera->xyz, camera->zd, camera->yd,camera->angle);
+}
+
+
+/**
+ * pose: カメラの対象物(obj)の座標行列
+ * カメラがobjについていくように(そのような動きに見せるため)
+ * カメラの位置ベクトル、視点ベクトルを更新
+ */
+void
+camera_update(Game *game, FMATRIX pose)
+{
+  FVECTOR location, eyes, vertical, angle;
+    
+  //int type = game->camera_type;
+
+  ps2_vu0_apply_matrix(location, pose, def_camera.xyz);
+  ps2_vu0_apply_matrix(eyes, pose, def_camera.zd);
+  ps2_vu0_apply_matrix(vertical, pose, def_camera.yd);
+
+  /**When the car bends, the angle of the camera is changed**/
+  if(pad.left>0  && game->jiki->speed !=0){
+    if(game->jiki->speed !=0){
+      if(def_camera.angle[1]<=0.2){
+	def_camera.angle[1]+=0.02;
+      }
+    }
+  }
+  else if(pad.right>0 && game->jiki->speed !=0){
+    if(game->jiki->speed !=0){
+      if(def_camera.angle[1]>=-0.2){
+        def_camera.angle[1]-=0.02;
+      }
+    }
+  }
+  else {
+    if(def_camera.angle[1]<-0.01){
+      def_camera.angle[1]+=0.02;
+    }
+    else if(def_camera.angle[1]>0.01){
+      def_camera.angle[1]-=0.02;
+    }
+  } 
+  ps2_vu0_apply_matrix(angle, pose, def_camera.angle);
+  ps2_vu0_copy_vector(camera.xyz, location);
+  ps2_vu0_copy_vector(camera.zd,  eyes);
+  ps2_vu0_copy_vector(camera.yd,  vertical);
+  ps2_vu0_copy_vector(camera.angle, angle);
+  set_camera(&camera);
+    
+}
--- a/car.c	Thu Jun 02 17:26:21 2011 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,299 +0,0 @@
-/* car.c */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdbool.h>
-#include "libps2.h"
-#include "ps2util.h"
-#include "field.h"
-#include "car.h"
-#include "mytype.h"
-#include "quotanion.h"
-#include "game.h"
-#include "stdbool.h"
-
-#define DEFAULT_SET (EFFECT_TEXTURE_USE | EFFECT_ALPHABLEND_UNUSE | EFFECT_SHADING_FLAT)
-#define BUFSIZE 256
-
-/* 初期位置と初期方向 */
-static FVECTOR location  = {0, 0, 0, 1};
-static FVECTOR direction = {0, 0, 1, 1};
-
-extern FILE* main_fp;
-
-static CarPtr
-car_create(int car_id, char *filename, char *texname, float speed_accel,
-	   float speed_max, float rot, float brake)
-{
-  CarPtr car;
-  OBJECT *body;
-  TEXTURE* tex;
-  void *free_addr;
-    
-  body = ps2util_obj_Create_fromXML(filename);
-  ps2util_obj_Set_effect(body, DEFAULT_SET);
-
-  if (malloc_align16(&free_addr, &car, sizeof(Car)) == -1) {
-    fprintf(main_fp, "car.c: malloc_align16 error\n");
-    exit(EXIT_FAILURE);	
-  }
-  car->body           = body;
-  car->next           = NULL;
-  car->speed          = 0.0;
-  car->speed_accel    = speed_accel;
-  car->speed_max      = speed_max;
-  car->brake          = brake;
-  car->rotation_angle = rot;
-  car->y_angle        = 0.0;
-  car->free_addr      = free_addr;
-
-  ps2_vu0_copy_vector(car->direction, direction);
-  ps2_vu0_copy_vector(car->location, location);
-  INIT_VECTOR(car->vertical,    0, -1, 0, 1);
-  INIT_VECTOR(car->body->xyz,   0,  0, 0, 1);
-  INIT_VECTOR(car->body->angle, 0,  0, 0, 1);
-
-  ps2util_obj_Renew_transMatrix(car->body);
-  ps2util_obj_Set_effect(car->body, DEFAULT_SET);
-
-  if (*texname != 'n') {
-    tex = read_png_file(texname);
-    ps2util_tex_Set(tex);
-    ps2util_obj_Set_texture(car->body, tex);
-  }
-
-#ifdef DEBUG
-  fprintf(main_fp, "malloc car addr = %x\n", (int)free_addr);
-#endif
-
-  return car;
-}
-
-static CarPtr
-car_new_readCSV(FILE *fp, int id)
-{
-  CarPtr new;
-  int   car_id;
-  float speed_accel, speed_max, brake, rot;
-  char  buff[BUFSIZE], *bufp;
-  char  carImg[BUFSIZE], texImg[BUFSIZE];
-  bool  flag;
-
-  flag = false;
-
-  while ((bufp = fgets(buff, BUFSIZE, fp)) != NULL) {
-    bufp++;
-
-    switch (buff[0]) {
-    case 'n':
-      if (flag == false) {
-	sscanf(bufp, " %d\n", &car_id);
-	if (id == car_id) {
-	  flag = true;
-	}
-      }
-      break;
-    case 't':
-      if (flag == true) {
-	sscanf(bufp, " %s %s %f %f %f %f\n",
-	       carImg, texImg, &speed_accel, &speed_max, &rot, &brake);
-	new = car_create(id, carImg, texImg,
-			 speed_accel, speed_max, rot, brake);
-	return new;
-      }
-      break;
-    default:
-      break;
-    }
-  }
-
-  /* ここまで辿り着いたら読み込み失敗 */
-  fprintf(main_fp, "error - car_new_readCSV\n");
-  exit(EXIT_FAILURE);
-}
-
-CarPtr car_init(int id)
-{
-  CarPtr new;
-  FILE *fp;
-  char *filename = "car/car.dat";
-
-  if (!(fp = fopen(filename, "r"))) {
-    fprintf(main_fp, "error read file %s\n", filename);
-    exit(EXIT_FAILURE);
-  }
-  new = car_new_readCSV(fp, id);
-  fclose(fp);
-
-  return new;
-}
-
-/*---------------------------
-  carをY軸で回転させる
-  flg: 回転方向 1:右, -1:左
-  ---------------------------*/
-void
-car_swerve(CarPtr car, int flg)
-{
-  FMATRIX rot;
-  FVECTOR v;
-
-  car->y_angle += (float)flg*car->rotation_angle;
-  car->y_angle += (car->y_angle < 0) ? 360.0 : 0;
-  car->y_angle += (car->y_angle > 360.0) ? -360.0 : 0;
-
-  ps2_vu0_unit_matrix(rot);
-  ps2_vu0_rot_matrix_y(rot, rot, degree2radian((float)flg*car->rotation_angle));
-  ps2_vu0_copy_vector(v, car->direction);
-  ps2_vu0_apply_matrix(car->direction, rot, v); 
-}
-
-/*----------------------------
-  carを加速・減速する
-  (flg == 1) ? 加速 : 減速
-  ---------------------------*/
-void
-car_accelerate(CarPtr car, int flg)
-{
-  car->speed += (flg == 1) ? car->speed_accel : -car->brake;
-  car->speed = (car->speed < 0) ? 0 : car->speed;
-  car->speed = (car->speed > car->speed_max) ? car->speed_max : car->speed;
-}
-
-
-/*---------------------------------
-  進行後のcarに対してコース面の内外判定を行い、
-  : 現在のコース
-  : 現在のコースの次のコース
-  : 現在のコースの前のコース
-  に存在すればTRUEを返す
-  どのコースにも居ない(壁に衝突した)場合は
-  FALSEを返す。
-  ---------------------------------*/
-static bool
-car_field_check(Game *game ,CarPtr car)
-{
-  FieldPtr p;
-  FieldPtr f = field_get_actual();
-
-  // 現在のコースで衝突・内外判定
-  p = f;
-  if (col_detect(&p->colface, car->vertical, car->location) == true) {
-    goto FIELD_CHECK_OK;
-  }
-
-  // 現在のコースの次に隣接するコースで衝突・内外判定
-  p = f->next;
-  if (col_detect(&p->colface, car->vertical, car->location) == true) {
-    if (field_rap_increment(1)) {
-      game->rap++;
-    }
-    goto FIELD_CHECK_OK;
-  }
-
-  // 現在のコースの前に隣接するコースで衝突・内外判定
-  p = f->prev;
-  if (col_detect(&p->colface, car->vertical, car->location) == true) {
-    field_rap_increment(-1);
-    goto FIELD_CHECK_OK;
-  }
-
-  // どのコース上にも居ない(壁に衝突)
-  return false;
-
- FIELD_CHECK_OK:
-  field_set_actual(p);
-  return true;
-}
-
-
-/*------------------------------
-  速度speedと向きdirectionから
-  進行後の位置locationを求める。
-  また、進行後の衝突判定も行う。
-  ------------------------------*/
-static void
-car_move(Game *game,CarPtr car)
-{
-  FVECTOR mov, prev_location;
-    
-  ps2_vu0_scale_vector(mov, car->direction, car->speed);
-  ps2_vu0_copy_vector(prev_location, car->location);
-  ps2_vu0_add_vector(car->location, car->location, mov);
-
-  if (car_field_check(game,car) == false) {
-     	ps2_vu0_copy_vector(car->location, prev_location);
-	car->speed = car->speed*0.5;
-  }
-}
-
-
-static void
-car_axis_rotation(CarPtr car)
-{
-  FMATRIX pose, yrot, yrotinv;
-
-  ps2_vu0_unit_matrix(yrot);
-  ps2_vu0_rot_matrix_y(yrot, yrot, -degree2radian(car->y_angle));
-  ps2_vu0_unit_matrix(yrotinv);
-  ps2_vu0_rot_matrix_y(yrotinv, yrotinv, degree2radian(car->y_angle));
-
-  {
-    FVECTOR yd = {0, -1, 0, 1};
-    FVECTOR rotaxis;
-    FVECTOR q;
-	
-    ps2_vu0_outer_product(rotaxis, car->vertical, yd);
-    {
-      float scale=1/NORM(rotaxis);
-      rotaxis[0] *= scale;
-      rotaxis[1] *= scale;
-      rotaxis[2] *= scale;
-    }
-	
-    quotanion(q, rotaxis, acos(ps2_vu0_inner_product(yd, car->vertical)/(NORM(yd)*NORM(car->vertical))));
-    quotanion_rotmatrix(pose, q);
-  }
-
-  ps2_vu0_mul_matrix(pose, yrot, pose);
-  ps2_vu0_mul_matrix(pose, pose, yrotinv);
-  ps2_vu0_copy_matrix(car->body->transfer, pose);
-  ps2_vu0_rot_matrix_y(car->body->transfer, car->body->transfer, degree2radian(car->y_angle));
-}
-
-void car_update( Game *game, CarPtr car )
-{
-  // 移動
-  car_move(game,car);
-
-  // 摩擦による速度減少
-  car->speed -= 0.005;
-  car->speed = (car->speed < 0) ? 0 : car->speed;
-
-  // 傾き
-  car_axis_rotation(car);
-}
-
-
-void
-car_destroy(CarPtr p)
-{
-  TEXTURE *t;
-
-  if ((t = p->body->surfaces->texture)) {
-    ps2util_tex_Exclude(t);
-    free_texture(t);
-  }
-  ps2util_obj_Free(p->body);
-  free(p->free_addr);
-
-#ifdef DEBUG
-  fprintf(main_fp, "free car addr = %x\n", (int)p->free_addr);
-#endif
-}
-
-// 適当に自作 
-void car_id_update(Game *game, CarPtr jiki)
-{
-  printf("car_id_update\n");
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/car.cc	Thu Jun 02 17:51:41 2011 +0900
@@ -0,0 +1,299 @@
+/* car.c */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include "libps2.h"
+#include "ps2util.h"
+#include "field.h"
+#include "car.h"
+#include "mytype.h"
+#include "quotanion.h"
+#include "game.h"
+#include "stdbool.h"
+
+#define DEFAULT_SET (EFFECT_TEXTURE_USE | EFFECT_ALPHABLEND_UNUSE | EFFECT_SHADING_FLAT)
+#define BUFSIZE 256
+
+/* 初期位置と初期方向 */
+static FVECTOR location  = {0, 0, 0, 1};
+static FVECTOR direction = {0, 0, 1, 1};
+
+extern FILE* main_fp;
+
+static CarPtr
+car_create(int car_id, char *filename, char *texname, float speed_accel,
+	   float speed_max, float rot, float brake)
+{
+  CarPtr car;
+  OBJECT *body;
+  TEXTURE* tex;
+  void *free_addr;
+    
+  body = ps2util_obj_Create_fromXML(filename);
+  ps2util_obj_Set_effect(body, DEFAULT_SET);
+
+  if (malloc_align16(&free_addr, &car, sizeof(Car)) == -1) {
+    fprintf(main_fp, "car.c: malloc_align16 error\n");
+    exit(EXIT_FAILURE);	
+  }
+  car->body           = body;
+  car->next           = NULL;
+  car->speed          = 0.0;
+  car->speed_accel    = speed_accel;
+  car->speed_max      = speed_max;
+  car->brake          = brake;
+  car->rotation_angle = rot;
+  car->y_angle        = 0.0;
+  car->free_addr      = free_addr;
+
+  ps2_vu0_copy_vector(car->direction, direction);
+  ps2_vu0_copy_vector(car->location, location);
+  INIT_VECTOR(car->vertical,    0, -1, 0, 1);
+  INIT_VECTOR(car->body->xyz,   0,  0, 0, 1);
+  INIT_VECTOR(car->body->angle, 0,  0, 0, 1);
+
+  ps2util_obj_Renew_transMatrix(car->body);
+  ps2util_obj_Set_effect(car->body, DEFAULT_SET);
+
+  if (*texname != 'n') {
+    tex = read_png_file(texname);
+    ps2util_tex_Set(tex);
+    ps2util_obj_Set_texture(car->body, tex);
+  }
+
+#ifdef DEBUG
+  fprintf(main_fp, "malloc car addr = %x\n", (int)free_addr);
+#endif
+
+  return car;
+}
+
+static CarPtr
+car_new_readCSV(FILE *fp, int id)
+{
+  CarPtr new;
+  int   car_id;
+  float speed_accel, speed_max, brake, rot;
+  char  buff[BUFSIZE], *bufp;
+  char  carImg[BUFSIZE], texImg[BUFSIZE];
+  bool  flag;
+
+  flag = false;
+
+  while ((bufp = fgets(buff, BUFSIZE, fp)) != NULL) {
+    bufp++;
+
+    switch (buff[0]) {
+    case 'n':
+      if (flag == false) {
+	sscanf(bufp, " %d\n", &car_id);
+	if (id == car_id) {
+	  flag = true;
+	}
+      }
+      break;
+    case 't':
+      if (flag == true) {
+	sscanf(bufp, " %s %s %f %f %f %f\n",
+	       carImg, texImg, &speed_accel, &speed_max, &rot, &brake);
+	new = car_create(id, carImg, texImg,
+			 speed_accel, speed_max, rot, brake);
+	return new;
+      }
+      break;
+    default:
+      break;
+    }
+  }
+
+  /* ここまで辿り着いたら読み込み失敗 */
+  fprintf(main_fp, "error - car_new_readCSV\n");
+  exit(EXIT_FAILURE);
+}
+
+CarPtr car_init(int id)
+{
+  CarPtr new;
+  FILE *fp;
+  char *filename = "car/car.dat";
+
+  if (!(fp = fopen(filename, "r"))) {
+    fprintf(main_fp, "error read file %s\n", filename);
+    exit(EXIT_FAILURE);
+  }
+  new = car_new_readCSV(fp, id);
+  fclose(fp);
+
+  return new;
+}
+
+/*---------------------------
+  carをY軸で回転させる
+  flg: 回転方向 1:右, -1:左
+  ---------------------------*/
+void
+car_swerve(CarPtr car, int flg)
+{
+  FMATRIX rot;
+  FVECTOR v;
+
+  car->y_angle += (float)flg*car->rotation_angle;
+  car->y_angle += (car->y_angle < 0) ? 360.0 : 0;
+  car->y_angle += (car->y_angle > 360.0) ? -360.0 : 0;
+
+  ps2_vu0_unit_matrix(rot);
+  ps2_vu0_rot_matrix_y(rot, rot, degree2radian((float)flg*car->rotation_angle));
+  ps2_vu0_copy_vector(v, car->direction);
+  ps2_vu0_apply_matrix(car->direction, rot, v); 
+}
+
+/*----------------------------
+  carを加速・減速する
+  (flg == 1) ? 加速 : 減速
+  ---------------------------*/
+void
+car_accelerate(CarPtr car, int flg)
+{
+  car->speed += (flg == 1) ? car->speed_accel : -car->brake;
+  car->speed = (car->speed < 0) ? 0 : car->speed;
+  car->speed = (car->speed > car->speed_max) ? car->speed_max : car->speed;
+}
+
+
+/*---------------------------------
+  進行後のcarに対してコース面の内外判定を行い、
+  : 現在のコース
+  : 現在のコースの次のコース
+  : 現在のコースの前のコース
+  に存在すればTRUEを返す
+  どのコースにも居ない(壁に衝突した)場合は
+  FALSEを返す。
+  ---------------------------------*/
+static bool
+car_field_check(Game *game ,CarPtr car)
+{
+  FieldPtr p;
+  FieldPtr f = field_get_actual();
+
+  // 現在のコースで衝突・内外判定
+  p = f;
+  if (col_detect(&p->colface, car->vertical, car->location) == true) {
+    goto FIELD_CHECK_OK;
+  }
+
+  // 現在のコースの次に隣接するコースで衝突・内外判定
+  p = f->next;
+  if (col_detect(&p->colface, car->vertical, car->location) == true) {
+    if (field_rap_increment(1)) {
+      game->rap++;
+    }
+    goto FIELD_CHECK_OK;
+  }
+
+  // 現在のコースの前に隣接するコースで衝突・内外判定
+  p = f->prev;
+  if (col_detect(&p->colface, car->vertical, car->location) == true) {
+    field_rap_increment(-1);
+    goto FIELD_CHECK_OK;
+  }
+
+  // どのコース上にも居ない(壁に衝突)
+  return false;
+
+ FIELD_CHECK_OK:
+  field_set_actual(p);
+  return true;
+}
+
+
+/*------------------------------
+  速度speedと向きdirectionから
+  進行後の位置locationを求める。
+  また、進行後の衝突判定も行う。
+  ------------------------------*/
+static void
+car_move(Game *game,CarPtr car)
+{
+  FVECTOR mov, prev_location;
+    
+  ps2_vu0_scale_vector(mov, car->direction, car->speed);
+  ps2_vu0_copy_vector(prev_location, car->location);
+  ps2_vu0_add_vector(car->location, car->location, mov);
+
+  if (car_field_check(game,car) == false) {
+     	ps2_vu0_copy_vector(car->location, prev_location);
+	car->speed = car->speed*0.5;
+  }
+}
+
+
+static void
+car_axis_rotation(CarPtr car)
+{
+  FMATRIX pose, yrot, yrotinv;
+
+  ps2_vu0_unit_matrix(yrot);
+  ps2_vu0_rot_matrix_y(yrot, yrot, -degree2radian(car->y_angle));
+  ps2_vu0_unit_matrix(yrotinv);
+  ps2_vu0_rot_matrix_y(yrotinv, yrotinv, degree2radian(car->y_angle));
+
+  {
+    FVECTOR yd = {0, -1, 0, 1};
+    FVECTOR rotaxis;
+    FVECTOR q;
+	
+    ps2_vu0_outer_product(rotaxis, car->vertical, yd);
+    {
+      float scale=1/NORM(rotaxis);
+      rotaxis[0] *= scale;
+      rotaxis[1] *= scale;
+      rotaxis[2] *= scale;
+    }
+	
+    quotanion(q, rotaxis, acos(ps2_vu0_inner_product(yd, car->vertical)/(NORM(yd)*NORM(car->vertical))));
+    quotanion_rotmatrix(pose, q);
+  }
+
+  ps2_vu0_mul_matrix(pose, yrot, pose);
+  ps2_vu0_mul_matrix(pose, pose, yrotinv);
+  ps2_vu0_copy_matrix(car->body->transfer, pose);
+  ps2_vu0_rot_matrix_y(car->body->transfer, car->body->transfer, degree2radian(car->y_angle));
+}
+
+void car_update( Game *game, CarPtr car )
+{
+  // 移動
+  car_move(game,car);
+
+  // 摩擦による速度減少
+  car->speed -= 0.005;
+  car->speed = (car->speed < 0) ? 0 : car->speed;
+
+  // 傾き
+  car_axis_rotation(car);
+}
+
+
+void
+car_destroy(CarPtr p)
+{
+  TEXTURE *t;
+
+  if ((t = p->body->surfaces->texture)) {
+    ps2util_tex_Exclude(t);
+    free_texture(t);
+  }
+  ps2util_obj_Free(p->body);
+  free(p->free_addr);
+
+#ifdef DEBUG
+  fprintf(main_fp, "free car addr = %x\n", (int)p->free_addr);
+#endif
+}
+
+// 適当に自作 
+void car_id_update(Game *game, CarPtr jiki)
+{
+  printf("car_id_update\n");
+}
--- a/carNode.c	Thu Jun 02 17:26:21 2011 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,50 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include "libps2.h"
-#include "ps2util.h"
-#include "car.h"
-#include "game.h"
-#include "carNode.h"
-
-/* --- car.c --- */
-void car_destroy(CarPtr car);
-
-static CarPtr car_list;
-
-void
-carNode_append(CarPtr new) 
-{
-  CarPtr p = car_list;
-
-  if (!p) {
-    car_list = new;
-  } else {
-    while (p->next) p = p->next;
-    p->next = new;
-  }
-}
-
-
-void
-carNode_draw()
-{
-  CarPtr p = car_list;
-
-  while (p) {
-    ps2util_obj_Draw(p->body);
-    p = p->next;
-  }
-}
-
-
-void
-carNode_destroy()
-{
-  CarPtr p = car_list;
-
-  while (p) {
-    car_destroy(p);
-    p = p->next;
-  }
-  car_list = NULL;
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/carNode.cc	Thu Jun 02 17:51:41 2011 +0900
@@ -0,0 +1,50 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include "libps2.h"
+#include "ps2util.h"
+#include "car.h"
+#include "game.h"
+#include "carNode.h"
+
+/* --- car.c --- */
+void car_destroy(CarPtr car);
+
+static CarPtr car_list;
+
+void
+carNode_append(CarPtr new) 
+{
+  CarPtr p = car_list;
+
+  if (!p) {
+    car_list = new;
+  } else {
+    while (p->next) p = p->next;
+    p->next = new;
+  }
+}
+
+
+void
+carNode_draw()
+{
+  CarPtr p = car_list;
+
+  while (p) {
+    ps2util_obj_Draw(p->body);
+    p = p->next;
+  }
+}
+
+
+void
+carNode_destroy()
+{
+  CarPtr p = car_list;
+
+  while (p) {
+    car_destroy(p);
+    p = p->next;
+  }
+  car_list = NULL;
+}
--- a/col.c	Thu Jun 02 17:26:21 2011 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,136 +0,0 @@
-#include <stdio.h>
-#include"libps2.h"
-#include"ps2util.h"
-#include"col.h"
-#include"mytype.h"
-#include <stdbool.h>
-#include <string.h>
-
-extern FILE *main_fp;
-
-/**
- * v0, v1が描く三角形と点pの内外判定(approx detection)
- * 点pはv0, v1が描く面のどこかに位置している。
- * pが面の三角形の外側にあるときTRUEを戻し、
- * そうでなければFALSEを戻す。境界は含む。
- */
-
-
-bool 
-col_detect_approx(FVECTOR p, FVECTOR v0, FVECTOR v1){
-
-  float v_r1, v_r2, r1_r2, r1_r1, r2_r2;
-  float a, b, r;
-
-  v_r1  = ps2_vu0_inner_product( p,  v0 );
-  v_r2  = ps2_vu0_inner_product( p,  v1 );
-  r1_r2 = ps2_vu0_inner_product( v0, v1 );
-  r1_r1 = ps2_vu0_inner_product( v0, v0 );
-  r2_r2 = ps2_vu0_inner_product( v1, v1 );
-
-  a = (v_r1  * r2_r2 - v_r2  * r1_r2);
-  b = (v_r2  * r1_r1 - v_r1  * r1_r2);
-  r = (r1_r1 * r2_r2 - r1_r2 * r1_r2);
-
-  return (a>=0 && b>=0 && a+b-r<=0) ? true : false;
-}
-
-
-
-/**
- * 垂心oの算出. 点pからv0, v1が描く面へ垂線を引いたときの交点oを
- * 垂心(orthocenter)と呼ぶ。
- */
-//なんか一回も使われていないらしいので消す、はずだった
-static void
-col_orthocenter(FVECTOR o, FVECTOR p, FVECTOR p0, FVECTOR normal)
-{
-  
-  FVECTOR o0, d;
-
-  ps2_vu0_sub_vector(o0, p, p0);
-  o0[W_AXIS] = 0;
-  ps2_vu0_scale_vector(
-		       d, normal, ps2_vu0_inner_product(o0, normal));
-
-  o[X_AXIS] = p[X_AXIS] - d[X_AXIS];
-  o[Y_AXIS] = p[Y_AXIS] - d[Y_AXIS];
-  o[Z_AXIS] = p[Z_AXIS] - d[Z_AXIS];
-  o[W_AXIS] = 1;
-}
-
-/**
- * 点pと面との衝突(点pとdetection face面との垂心oがdetection face領域の
- * 中にあるかを)判定衝突時(oがdetection face領域の外)はFALSEを戻し、そう
- * でなければTRUE、 垂心(orthocenter)、垂心のある面の法線(normal
- * vector)を戻す.
- */
-
-
-bool
-col_detect(ColFaceHd* hd, FVECTOR pose, FVECTOR p)
-{
-  FVECTOR o, o0;
-  int i;
-  ColFacePtr col_face=hd->colface;
-  for (i=0; i<hd->facenum; i++) {
-
-    // * 垂心oを求める
-    col_orthocenter(o, p, col_face[i].p0, col_face[i].normal);
-
-    // * detection face上のある点p0から垂心oへのベクトルo0を求める
-    ps2_vu0_sub_vector(o0, o, col_face[i].p0);
-
-    // * ベクトルv0, v1の描く三角形とo0とで内外判定(range approx detection)を行う
-    if (col_detect_approx(o0, col_face[i].v0, col_face[i].v1)==true) {
-      goto NOCOLLISION;
-    }
-  }
-  return false;
- NOCOLLISION:
-  ps2_vu0_copy_vector(p, o);
-  ps2_vu0_copy_vector(pose, col_face[i].normal);
-  return true;
-
-  return false;
-}
-
-
-/*
- * detection face作成
- */
-
-
-void 
-col_init(ColFaceHd* hd, PolygonInfo* face)
-{
-  
-  int i;
-  FVECTOR p1, p2;
-  ColFacePtr colface;
-
-  malloc_align16(&hd->free_addr, &colface, sizeof(ColFace)*face->siz/3);
-
-  hd->facenum = face->siz/3;
-    
-  for (i=0; i<hd->facenum; i++) {
-    memcpy(colface[i].p0, ((FVECTOR*)face->pnts)[i*3], sizeof(FVECTOR));
-    memcpy(p1, ((FVECTOR*)face->pnts)[i*3+2], sizeof(FVECTOR));
-    memcpy(p2, ((FVECTOR*)face->pnts)[i*3+1], sizeof(FVECTOR));
-
-    ps2_vu0_sub_vector(colface[i].v0, p1, colface[i].p0);
-    ps2_vu0_sub_vector(colface[i].v1, p2, colface[i].p0);
-
-    ps2_vu0_outer_product(colface[i].normal, colface[i].v0, colface[i].v1);
-    ps2_vu0_normalize(colface[i].normal, colface[i].normal); 
-
-    if (colface[i].normal[1] > 0) {
-      colface[i].normal[0] = -colface[i].normal[0];
-      colface[i].normal[1] = -colface[i].normal[1];
-      colface[i].normal[2] = -colface[i].normal[2];
-    }
-  }
-
-  hd->colface = colface;
-
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/col.cc	Thu Jun 02 17:51:41 2011 +0900
@@ -0,0 +1,136 @@
+#include <stdio.h>
+#include"libps2.h"
+#include"ps2util.h"
+#include"col.h"
+#include"mytype.h"
+#include <stdbool.h>
+#include <string.h>
+
+extern FILE *main_fp;
+
+/**
+ * v0, v1が描く三角形と点pの内外判定(approx detection)
+ * 点pはv0, v1が描く面のどこかに位置している。
+ * pが面の三角形の外側にあるときTRUEを戻し、
+ * そうでなければFALSEを戻す。境界は含む。
+ */
+
+
+bool 
+col_detect_approx(FVECTOR p, FVECTOR v0, FVECTOR v1){
+
+  float v_r1, v_r2, r1_r2, r1_r1, r2_r2;
+  float a, b, r;
+
+  v_r1  = ps2_vu0_inner_product( p,  v0 );
+  v_r2  = ps2_vu0_inner_product( p,  v1 );
+  r1_r2 = ps2_vu0_inner_product( v0, v1 );
+  r1_r1 = ps2_vu0_inner_product( v0, v0 );
+  r2_r2 = ps2_vu0_inner_product( v1, v1 );
+
+  a = (v_r1  * r2_r2 - v_r2  * r1_r2);
+  b = (v_r2  * r1_r1 - v_r1  * r1_r2);
+  r = (r1_r1 * r2_r2 - r1_r2 * r1_r2);
+
+  return (a>=0 && b>=0 && a+b-r<=0) ? true : false;
+}
+
+
+
+/**
+ * 垂心oの算出. 点pからv0, v1が描く面へ垂線を引いたときの交点oを
+ * 垂心(orthocenter)と呼ぶ。
+ */
+//なんか一回も使われていないらしいので消す、はずだった
+static void
+col_orthocenter(FVECTOR o, FVECTOR p, FVECTOR p0, FVECTOR normal)
+{
+  
+  FVECTOR o0, d;
+
+  ps2_vu0_sub_vector(o0, p, p0);
+  o0[W_AXIS] = 0;
+  ps2_vu0_scale_vector(
+		       d, normal, ps2_vu0_inner_product(o0, normal));
+
+  o[X_AXIS] = p[X_AXIS] - d[X_AXIS];
+  o[Y_AXIS] = p[Y_AXIS] - d[Y_AXIS];
+  o[Z_AXIS] = p[Z_AXIS] - d[Z_AXIS];
+  o[W_AXIS] = 1;
+}
+
+/**
+ * 点pと面との衝突(点pとdetection face面との垂心oがdetection face領域の
+ * 中にあるかを)判定衝突時(oがdetection face領域の外)はFALSEを戻し、そう
+ * でなければTRUE、 垂心(orthocenter)、垂心のある面の法線(normal
+ * vector)を戻す.
+ */
+
+
+bool
+col_detect(ColFaceHd* hd, FVECTOR pose, FVECTOR p)
+{
+  FVECTOR o, o0;
+  int i;
+  ColFacePtr col_face=hd->colface;
+  for (i=0; i<hd->facenum; i++) {
+
+    // * 垂心oを求める
+    col_orthocenter(o, p, col_face[i].p0, col_face[i].normal);
+
+    // * detection face上のある点p0から垂心oへのベクトルo0を求める
+    ps2_vu0_sub_vector(o0, o, col_face[i].p0);
+
+    // * ベクトルv0, v1の描く三角形とo0とで内外判定(range approx detection)を行う
+    if (col_detect_approx(o0, col_face[i].v0, col_face[i].v1)==true) {
+      goto NOCOLLISION;
+    }
+  }
+  return false;
+ NOCOLLISION:
+  ps2_vu0_copy_vector(p, o);
+  ps2_vu0_copy_vector(pose, col_face[i].normal);
+  return true;
+
+  return false;
+}
+
+
+/*
+ * detection face作成
+ */
+
+
+void 
+col_init(ColFaceHd* hd, PolygonInfo* face)
+{
+  
+  int i;
+  FVECTOR p1, p2;
+  ColFacePtr colface;
+
+  malloc_align16(&hd->free_addr, &colface, sizeof(ColFace)*face->siz/3);
+
+  hd->facenum = face->siz/3;
+    
+  for (i=0; i<hd->facenum; i++) {
+    memcpy(colface[i].p0, ((FVECTOR*)face->pnts)[i*3], sizeof(FVECTOR));
+    memcpy(p1, ((FVECTOR*)face->pnts)[i*3+2], sizeof(FVECTOR));
+    memcpy(p2, ((FVECTOR*)face->pnts)[i*3+1], sizeof(FVECTOR));
+
+    ps2_vu0_sub_vector(colface[i].v0, p1, colface[i].p0);
+    ps2_vu0_sub_vector(colface[i].v1, p2, colface[i].p0);
+
+    ps2_vu0_outer_product(colface[i].normal, colface[i].v0, colface[i].v1);
+    ps2_vu0_normalize(colface[i].normal, colface[i].normal); 
+
+    if (colface[i].normal[1] > 0) {
+      colface[i].normal[0] = -colface[i].normal[0];
+      colface[i].normal[1] = -colface[i].normal[1];
+      colface[i].normal[2] = -colface[i].normal[2];
+    }
+  }
+
+  hd->colface = colface;
+
+}
--- a/controler.c	Thu Jun 02 17:26:21 2011 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,109 +0,0 @@
-/* controler.c */
-
-#include "libps2.h"
-#include "ps2util.h"
-#include "controler.h"
-#include <stdbool.h>
-
-#include "sjoy.h" // ps2関連ファイルから
-
-
-// 使っていないっぽい? どこで宣言してるかわからない
-/*
-#ifdef DEMO_CREATE
-qextern void setPadValue(int pad);
-#endif
-extern int getPadValue();
-*/
-
-
-
-SGO_PAD pad;
-
-bool padCheck() {
-
-  int pad1;
-
-  pad1 = sjoy_get_ps2_button( JOYPAD_1 );
-
-  if (pad1 & SJOY_PS2_START) {
-    pad.st += (pad.st < 2) ? 1 : 0;
-  } else {
-    pad.st = 0;
-  }
-
-  if (pad1 & SJOY_PS2_SELECT) {
-    pad.se += (pad.se < 2) ? 1 : 0;
-  } else {
-    pad.se = 0;
-  }
-  if (pad1 & SJOY_PS2_LEFT) {
-    pad.left += (pad.left < 2) ? 1 : 0;
-  } else {
-    pad.left = 0;
-  }
-  if (pad1 & SJOY_PS2_RIGHT) {
-    pad.right += (pad.right < 2) ? 1 : 0;
-  } else {
-    pad.right = 0;
-  }
-  if (pad1 & SJOY_PS2_UP) {
-    pad.up += (pad.up < 2) ? 1 : 0;
-  } else {
-    pad.up = 0;
-  }
-  if (pad1 & SJOY_PS2_DOWN) {
-    pad.down += (pad.down < 2) ? 1 : 0;
-  } else {
-    pad.down = 0;
-  }
-  if (pad1 & SJOY_PS2_R1) {
-    pad.r1 += (pad.r1 < 2) ? 1 : 0;
-  } else {
-    pad.r1 = 0;
-  }
-  if (pad1 & SJOY_PS2_R2) {
-    pad.r2 += (pad.r2 < 2) ? 1 : 0;
-  } else {
-    pad.r2 = 0;
-  }
-  if (pad1 & SJOY_PS2_L1) {
-    pad.l1 += (pad.l1 < 2) ? 1 : 0;
-  } else {
-    pad.l1 = 0;
-  }
-  if (pad1 & SJOY_PS2_L2) {
-    pad.l2 += (pad.l2 < 2) ? 1 : 0;
-  } else {
-    pad.l2 = 0;
-  }
-  if (pad1 & SJOY_PS2_CROSS) {
-    pad.cross += (pad.cross < 2) ? 1 : 0;
-  } else {
-    pad.cross = 0;
-  }
-  if (pad1 & SJOY_PS2_CIRCLE) {
-    pad.circle += (pad.circle < 2) ? 1 : 0;
-  } else {
-    pad.circle = 0;
-  }
-  if (pad1 & SJOY_PS2_TRIANGLE) {
-    pad.triangle += (pad.triangle < 2) ? 1 : 0;
-  } else {
-    pad.triangle = 0;
-  }
-  if (pad1 & SJOY_PS2_SQUARE) {
-    pad.square += (pad.square < 2) ? 1 : 0;
-  } else {
-    pad.square = 0;
-  }
-
-  if ( (pad1 & SJOY_PS2_SELECT) && (pad1 & SJOY_PS2_START) && 
-       (pad1 & SJOY_PS2_L1) && (pad1 & SJOY_PS2_R1) && 
-       (pad1 & SJOY_PS2_L2) && (pad1 & SJOY_PS2_R2)) {
-    return false;
-  }
-
-
-  return true;
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/controler.cc	Thu Jun 02 17:51:41 2011 +0900
@@ -0,0 +1,109 @@
+/* controler.c */
+
+#include "libps2.h"
+#include "ps2util.h"
+#include "controler.h"
+#include <stdbool.h>
+
+#include "sjoy.h" // ps2関連ファイルから
+
+
+// 使っていないっぽい? どこで宣言してるかわからない
+/*
+#ifdef DEMO_CREATE
+qextern void setPadValue(int pad);
+#endif
+extern int getPadValue();
+*/
+
+
+
+SGO_PAD pad;
+
+bool padCheck() {
+
+  int pad1;
+
+  pad1 = sjoy_get_ps2_button( JOYPAD_1 );
+
+  if (pad1 & SJOY_PS2_START) {
+    pad.st += (pad.st < 2) ? 1 : 0;
+  } else {
+    pad.st = 0;
+  }
+
+  if (pad1 & SJOY_PS2_SELECT) {
+    pad.se += (pad.se < 2) ? 1 : 0;
+  } else {
+    pad.se = 0;
+  }
+  if (pad1 & SJOY_PS2_LEFT) {
+    pad.left += (pad.left < 2) ? 1 : 0;
+  } else {
+    pad.left = 0;
+  }
+  if (pad1 & SJOY_PS2_RIGHT) {
+    pad.right += (pad.right < 2) ? 1 : 0;
+  } else {
+    pad.right = 0;
+  }
+  if (pad1 & SJOY_PS2_UP) {
+    pad.up += (pad.up < 2) ? 1 : 0;
+  } else {
+    pad.up = 0;
+  }
+  if (pad1 & SJOY_PS2_DOWN) {
+    pad.down += (pad.down < 2) ? 1 : 0;
+  } else {
+    pad.down = 0;
+  }
+  if (pad1 & SJOY_PS2_R1) {
+    pad.r1 += (pad.r1 < 2) ? 1 : 0;
+  } else {
+    pad.r1 = 0;
+  }
+  if (pad1 & SJOY_PS2_R2) {
+    pad.r2 += (pad.r2 < 2) ? 1 : 0;
+  } else {
+    pad.r2 = 0;
+  }
+  if (pad1 & SJOY_PS2_L1) {
+    pad.l1 += (pad.l1 < 2) ? 1 : 0;
+  } else {
+    pad.l1 = 0;
+  }
+  if (pad1 & SJOY_PS2_L2) {
+    pad.l2 += (pad.l2 < 2) ? 1 : 0;
+  } else {
+    pad.l2 = 0;
+  }
+  if (pad1 & SJOY_PS2_CROSS) {
+    pad.cross += (pad.cross < 2) ? 1 : 0;
+  } else {
+    pad.cross = 0;
+  }
+  if (pad1 & SJOY_PS2_CIRCLE) {
+    pad.circle += (pad.circle < 2) ? 1 : 0;
+  } else {
+    pad.circle = 0;
+  }
+  if (pad1 & SJOY_PS2_TRIANGLE) {
+    pad.triangle += (pad.triangle < 2) ? 1 : 0;
+  } else {
+    pad.triangle = 0;
+  }
+  if (pad1 & SJOY_PS2_SQUARE) {
+    pad.square += (pad.square < 2) ? 1 : 0;
+  } else {
+    pad.square = 0;
+  }
+
+  if ( (pad1 & SJOY_PS2_SELECT) && (pad1 & SJOY_PS2_START) && 
+       (pad1 & SJOY_PS2_L1) && (pad1 & SJOY_PS2_R1) && 
+       (pad1 & SJOY_PS2_L2) && (pad1 & SJOY_PS2_R2)) {
+    return false;
+  }
+
+
+  return true;
+}
--- a/field.c	Thu Jun 02 17:26:21 2011 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,264 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdbool.h>
-#include <string.h>
-#include "libps2.h"
-#include "ps2util.h"
-#include "mytype.h"
-#include "field.h"
-#include "car.h"
-#include "quotanion.h"
-#include <stdbool.h>
-
-#define BUFSIZE 256
-
-/* --- main.c --- */
-extern FILE *main_fp;
-
-static int field_num_max = 0;
-static int field_num = 1;
-
-static FieldPtr field_list;
-static FieldPtr field_actual;
-
-// 適当に自作:miya
-PolygonInfo  xml_read_file(char *colImg)
-{
-  PolygonInfo test;
-  printf("xml_read_file");
-
-  return test;
-}
-
-
-static FieldPtr
-field_create(char *fieldImg, char *colImg, TEXTURE *tex)
-{
-  FieldPtr    self;
-  OBJECT      *obj;
-  PolygonInfo *xml;
-  void *free_addr;
-
-  FVECTOR location  = {0, 0, 0, 1};
-  FVECTOR direction = {0, 0, 0, 1};
-
-  obj = ps2util_obj_Create_fromXML(fieldImg);
-  memcpy(obj->xyz,    location, sizeof(FVECTOR));
-  memcpy(obj->angle, direction, sizeof(FVECTOR));
-  ps2util_obj_Renew_transMatrix(obj);
-  ps2util_obj_Set_effect(obj, DEFAULT_SET);
-  ps2util_obj_Set_texture(obj, tex);
-
-  //  xml = xml_read_file(colImg);    //ここでコースの走れる場所(当たり判定)
-
-  if (malloc_align16(&free_addr, &self, sizeof(Field)) == -1) {
-    fprintf(stderr, "field.c: malloc_align16 error\n");
-    fflush(stderr);
-    exit(EXIT_FAILURE);
-  }
-  self->object = obj;
-  self->next   = NULL;
-  self->prev   = NULL;
-  self->free_addr = free_addr;
-#ifdef DEBUG
-  fprintf(main_fp, "malloc fieldNode addr = %x(free), %x(obj)\n", (int)free_addr, (int)self);
-#endif
-  col_init(&self->colface, xml);
-
-#ifdef DEBUG
-  fprintf(main_fp, "       facenum = %d\n", self->colface.facenum);
-  fprintf(main_fp, "       facenum = %x(free), ", (int)self->colface.free_addr);
-  fprintf(main_fp, "facenum = %x(obj)\n", (int)self->colface.colface);
-#endif
-
-  //xml_free(xml);
-
-  return self;
-}
-
-
-
-static void
-field_new_readCSV(FILE *fp, int id)
-{
-  FieldPtr fieldHead = NULL;
-  FieldPtr newField  = NULL;
-  FieldPtr prevField = NULL;
-  char buff[BUFSIZE], *bufp;
-  char fieldImg[BUFSIZE], colImg[BUFSIZE], texname[BUFSIZE];
-  TEXTURE *tex = NULL;
-  int course_id;
-  bool flag = false;
-
-  while ((bufp = fgets(buff, BUFSIZE, fp)) != NULL) {
-    bufp++;
-
-    switch (buff[0]) {
-    case 'n': // コースIDの読み取り
-      if (!flag) {
-	sscanf(bufp, " %d\n", &course_id);
-	if (id == course_id) {
-	  flag = true;
-	}
-      } else {
-	goto FINISH_LOAD;
-      }
-      break;
-    case 't': // テクスチャのロード
-      if (flag) {
-	sscanf(bufp, " %s\n", texname);
-	//tex = read_png_file(texname);
-	ps2util_tex_Set(tex);
-      }
-      break;
-    case 'c': // コースのロード
-      if (flag) {
-	sscanf(bufp, " %s %s\n", fieldImg, colImg);
-	newField = field_create(fieldImg, colImg, tex);
-	if (!fieldHead) {
-	  fieldHead = prevField = newField;
-	} else {
-	  prevField->next = newField;
-	  newField->prev = prevField;
-	  prevField = newField;
-	}
-	newField->init = fieldHead;	
-	field_num_max++;
-      }
-      break;
-    default:
-      break;
-    }
-  }
-
- FINISH_LOAD:
-  // 先頭と最後尾のリンクを張る
-  newField->next = newField->init;
-  newField->init->prev = newField;
-
-  field_list = field_actual = fieldHead;
-}
-
-
-/*---------------------/
-  FieldPtr
-  field_init:
-    指定したファイルからコースを生成する。
-  戻り値
-    コース先頭のポインタ
-/---------------------*/
-void
-field_init(int id)
-{
-    FILE *fp;
-    char *filename = "course/course.dat";
-
-    if (!(fp = fopen(filename, "r"))) {
-        fprintf(main_fp, "error read file %s\n", filename);
-	exit(EXIT_FAILURE);
-    }
-    field_new_readCSV(fp, id);
-    fclose(fp);
-}
-
-
-static void
-field_draw(FieldPtr p)
-{
-  ps2_vu0_unit_matrix(p->object->transfer);
-
-  p->object->transfer[3][0] = p->location[0];
-  p->object->transfer[3][1] = p->location[1];
-  p->object->transfer[3][2] = p->location[2];
-  p->object->transfer[3][3] = p->location[3];
-  ps2util_obj_Draw(p->object);
-}
-
-
-void field_update(CarPtr car)
-{
-  FieldPtr p;
-
-  p = field_actual;
-  // current
-  p->location[0] = -car->location[0];
-  p->location[1] = -car->location[1];
-  p->location[2] = -car->location[2];
-  p->location[3] = 1;
-  field_draw(p);
-
-  // next
-  p = field_actual->next;
-  if (p) {
-    p->location[0] = -car->location[0];
-    p->location[1] = -car->location[1];
-    p->location[2] = -car->location[2];
-    p->location[3] = 1;
-    field_draw(p);
-  }
-
-  // prev
-  p = field_actual->prev;
-  if (p) {
-    p->location[0] = -car->location[0];
-    p->location[1] = -car->location[1];
-    p->location[2] = -car->location[2];
-    p->location[3] = 1;
-    field_draw(p);
-  }
-}
-
-void
-field_destroy()
-{
-  FieldPtr p = field_list;
-  FieldPtr d;
-  TEXTURE *t;
-
-  p->prev->next = NULL;
-
-  t = p->object->surfaces->texture;
-  ps2util_tex_Exclude(t);
-  free_texture(t);
-
-  while (p) {
-    d = p;
-    p = p->next;
-    ps2util_obj_Free(d->object);
-    free(d->colface.free_addr);
-    free(d->free_addr);
-#ifdef DEBUG
-    fprintf(main_fp, "free fieldNode addr = %x\n", (int)d->free_addr);
-#endif
-  }
-
-  field_num_max = 0;
-  field_num = 1;
-}
-
-/*
- * 周回記録。1周する毎に1を返す。
- */
-int
-field_rap_increment(int n)
-{
-  field_num += n;
-  if (field_num > field_num_max) {
-    field_num = 1;
-    return 1;
-  } else {
-    return 0;
-  }
-}
-
-void
-field_set_actual(FieldPtr p)
-{
-  field_actual = p;
-}
-
-FieldPtr
-field_get_actual()
-{
-  return field_actual;
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/field.cc	Thu Jun 02 17:51:41 2011 +0900
@@ -0,0 +1,264 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <string.h>
+#include "libps2.h"
+#include "ps2util.h"
+#include "mytype.h"
+#include "field.h"
+#include "car.h"
+#include "quotanion.h"
+#include <stdbool.h>
+
+#define BUFSIZE 256
+
+/* --- main.c --- */
+extern FILE *main_fp;
+
+static int field_num_max = 0;
+static int field_num = 1;
+
+static FieldPtr field_list;
+static FieldPtr field_actual;
+
+// 適当に自作:miya
+PolygonInfo  xml_read_file(char *colImg)
+{
+  PolygonInfo test;
+  printf("xml_read_file");
+
+  return test;
+}
+
+
+static FieldPtr
+field_create(char *fieldImg, char *colImg, TEXTURE *tex)
+{
+  FieldPtr    self;
+  OBJECT      *obj;
+  PolygonInfo *xml;
+  void *free_addr;
+
+  FVECTOR location  = {0, 0, 0, 1};
+  FVECTOR direction = {0, 0, 0, 1};
+
+  obj = ps2util_obj_Create_fromXML(fieldImg);
+  memcpy(obj->xyz,    location, sizeof(FVECTOR));
+  memcpy(obj->angle, direction, sizeof(FVECTOR));
+  ps2util_obj_Renew_transMatrix(obj);
+  ps2util_obj_Set_effect(obj, DEFAULT_SET);
+  ps2util_obj_Set_texture(obj, tex);
+
+  //  xml = xml_read_file(colImg);    //ここでコースの走れる場所(当たり判定)
+
+  if (malloc_align16(&free_addr, &self, sizeof(Field)) == -1) {
+    fprintf(stderr, "field.c: malloc_align16 error\n");
+    fflush(stderr);
+    exit(EXIT_FAILURE);
+  }
+  self->object = obj;
+  self->next   = NULL;
+  self->prev   = NULL;
+  self->free_addr = free_addr;
+#ifdef DEBUG
+  fprintf(main_fp, "malloc fieldNode addr = %x(free), %x(obj)\n", (int)free_addr, (int)self);
+#endif
+  col_init(&self->colface, xml);
+
+#ifdef DEBUG
+  fprintf(main_fp, "       facenum = %d\n", self->colface.facenum);
+  fprintf(main_fp, "       facenum = %x(free), ", (int)self->colface.free_addr);
+  fprintf(main_fp, "facenum = %x(obj)\n", (int)self->colface.colface);
+#endif
+
+  //xml_free(xml);
+
+  return self;
+}
+
+
+
+static void
+field_new_readCSV(FILE *fp, int id)
+{
+  FieldPtr fieldHead = NULL;
+  FieldPtr newField  = NULL;
+  FieldPtr prevField = NULL;
+  char buff[BUFSIZE], *bufp;
+  char fieldImg[BUFSIZE], colImg[BUFSIZE], texname[BUFSIZE];
+  TEXTURE *tex = NULL;
+  int course_id;
+  bool flag = false;
+
+  while ((bufp = fgets(buff, BUFSIZE, fp)) != NULL) {
+    bufp++;
+
+    switch (buff[0]) {
+    case 'n': // コースIDの読み取り
+      if (!flag) {
+	sscanf(bufp, " %d\n", &course_id);
+	if (id == course_id) {
+	  flag = true;
+	}
+      } else {
+	goto FINISH_LOAD;
+      }
+      break;
+    case 't': // テクスチャのロード
+      if (flag) {
+	sscanf(bufp, " %s\n", texname);
+	//tex = read_png_file(texname);
+	ps2util_tex_Set(tex);
+      }
+      break;
+    case 'c': // コースのロード
+      if (flag) {
+	sscanf(bufp, " %s %s\n", fieldImg, colImg);
+	newField = field_create(fieldImg, colImg, tex);
+	if (!fieldHead) {
+	  fieldHead = prevField = newField;
+	} else {
+	  prevField->next = newField;
+	  newField->prev = prevField;
+	  prevField = newField;
+	}
+	newField->init = fieldHead;	
+	field_num_max++;
+      }
+      break;
+    default:
+      break;
+    }
+  }
+
+ FINISH_LOAD:
+  // 先頭と最後尾のリンクを張る
+  newField->next = newField->init;
+  newField->init->prev = newField;
+
+  field_list = field_actual = fieldHead;
+}
+
+
+/*---------------------/
+  FieldPtr
+  field_init:
+    指定したファイルからコースを生成する。
+  戻り値
+    コース先頭のポインタ
+/---------------------*/
+void
+field_init(int id)
+{
+    FILE *fp;
+    char *filename = "course/course.dat";
+
+    if (!(fp = fopen(filename, "r"))) {
+        fprintf(main_fp, "error read file %s\n", filename);
+	exit(EXIT_FAILURE);
+    }
+    field_new_readCSV(fp, id);
+    fclose(fp);
+}
+
+
+static void
+field_draw(FieldPtr p)
+{
+  ps2_vu0_unit_matrix(p->object->transfer);
+
+  p->object->transfer[3][0] = p->location[0];
+  p->object->transfer[3][1] = p->location[1];
+  p->object->transfer[3][2] = p->location[2];
+  p->object->transfer[3][3] = p->location[3];
+  ps2util_obj_Draw(p->object);
+}
+
+
+void field_update(CarPtr car)
+{
+  FieldPtr p;
+
+  p = field_actual;
+  // current
+  p->location[0] = -car->location[0];
+  p->location[1] = -car->location[1];
+  p->location[2] = -car->location[2];
+  p->location[3] = 1;
+  field_draw(p);
+
+  // next
+  p = field_actual->next;
+  if (p) {
+    p->location[0] = -car->location[0];
+    p->location[1] = -car->location[1];
+    p->location[2] = -car->location[2];
+    p->location[3] = 1;
+    field_draw(p);
+  }
+
+  // prev
+  p = field_actual->prev;
+  if (p) {
+    p->location[0] = -car->location[0];
+    p->location[1] = -car->location[1];
+    p->location[2] = -car->location[2];
+    p->location[3] = 1;
+    field_draw(p);
+  }
+}
+
+void
+field_destroy()
+{
+  FieldPtr p = field_list;
+  FieldPtr d;
+  TEXTURE *t;
+
+  p->prev->next = NULL;
+
+  t = p->object->surfaces->texture;
+  ps2util_tex_Exclude(t);
+  free_texture(t);
+
+  while (p) {
+    d = p;
+    p = p->next;
+    ps2util_obj_Free(d->object);
+    free(d->colface.free_addr);
+    free(d->free_addr);
+#ifdef DEBUG
+    fprintf(main_fp, "free fieldNode addr = %x\n", (int)d->free_addr);
+#endif
+  }
+
+  field_num_max = 0;
+  field_num = 1;
+}
+
+/*
+ * 周回記録。1周する毎に1を返す。
+ */
+int
+field_rap_increment(int n)
+{
+  field_num += n;
+  if (field_num > field_num_max) {
+    field_num = 1;
+    return 1;
+  } else {
+    return 0;
+  }
+}
+
+void
+field_set_actual(FieldPtr p)
+{
+  field_actual = p;
+}
+
+FieldPtr
+field_get_actual()
+{
+  return field_actual;
+}
--- a/gFont.c	Thu Jun 02 17:26:21 2011 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,169 +0,0 @@
-/*
- * $Id$
- * 
- * フォント表示。といっても結局スプライトです。
- * gSprite.c と一緒にしてもよかったんだけど
- * 文字は文字でいろいろあるので分けてみる
- */
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdbool.h>
-#include "libps2.h"
-#include "ps2util.h"
-#include "gSprite.h"
-
-#define DEFOBJ 120
-#define SPRITE_COL 0x4f
-#define SCREEN_HALF_W 320
-#define SCREEN_HALF_H 240
-#define CHAR_W_SIZE 17
-#define CHAR_H_SIZE 34
-
-static SpriteTable   sptable[DEFOBJ];
-static ps2utilSprite sp[DEFOBJ*2]; // 表示スプライト用スタック
-static unsigned int  sp_counter;
-static bool          flag_spriteInited = false; // スプライトロードフラグ
-
-static TEXTURE *font_tex;
-
-static void
-gFont_Init_Png(char *texname)
-{
-  if (!(font_tex = read_png_file(texname))) {
-    fprintf(stderr,
-	    "cannot creat texture - gFont_Init_Png().\n");
-    fflush(stderr);
-    exit(EXIT_FAILURE);
-  }
-
-  if (ps2util_tex_Set(font_tex) == -1) {
-    fprintf(stderr,
-	    "cannot set texture - gFont_Init_Png().\n");
-    fflush(stderr);
-    exit(EXIT_FAILURE);
-  }
-}
-
-static void
-gFont_Create()
-{
-  int i;
-  for (i=0; i<DEFOBJ; i++) {
-    if (ps2util_sprite_Create(&sp[i], font_tex) == -1) {
-      fprintf(stderr,
-	      "cannot create sprite - gFont_Create()\n");
-      fflush(stderr);
-      exit(EXIT_FAILURE);
-    }
-    ps2util_sprite_Unuse_alpha(&sp[i]);
-  }
-
-
-  flag_spriteInited = true;
-}
-
-static void
-gFont_DefSprite(int number, int x, int y, int w, int h)
-{
-  sptable[number].tx = x;
-  sptable[number].ty = y;
-  sptable[number].tw = w;
-  sptable[number].th = h;
-}
-
-void
-gFont_Init()
-{
-  int i, j;
-  int number = 0;
-
-  gFont_Init_Png("img/font.png");
-  gFont_Create(); // スプライト生成
-
-  for (i=0; i<7; i++) {
-    for (j=0; j<15; j++) {
-      gFont_DefSprite(number, j*17, i*34, 17, 34);
-      number++;
-    }
-  }
-}
-
-
-static void
-gFont_PutSprite(int number, int x, int y)
-{
-    ps2utilSprite *p = &sp[sp_counter];
-
-    // ushortってなんですか?:miya
-    /*
-    ps2util_sprite_Set_basicAttribute(
-	p,
-	(ushort)x, (ushort)y,
-	(ushort)sptable[number].tw*1.5, (ushort)sptable[number].th*1.5,
-	(ushort)sptable[number].tx, (ushort)sptable[number].ty,
-	(ushort)sptable[number].tw, (ushort)sptable[number].th,
-	SPRITE_PRIO_FOREGROUND);
-    */
-
-    ps2util_sprite_Request(p);
-    sp_counter++;
-}
-
-
-static void
-gFont_Clear()
-{
-    int i;
-
-    for (i=0; i<DEFOBJ; i++) {
-   	sprite_disappear(&sp[i].attribute);
-    }
-    sp_counter = 0;
-}
-
-void
-gFont_Draw_Reset()
-{
-    if (flag_spriteInited == true) {
-     	gFont_Clear();
-    }
-}
-
-static int
-get_number_char(char a)
-{
-    return (int)a-32;
-}
-
-/*
- * str をスプライド表示
- */
-void
-gFont_SetString(char *str, int x, int y)
-{
-  int number;
-
-  while (*str != '\0') {
-    number = get_number_char(*str);
-    gFont_PutSprite(number, x, y);
-    str++;
-    x += (int)CHAR_W_SIZE*1.5;
-  }
-}
-
-/*
- * numを文字列に変換してSetStringに渡す
- */
-void
-gFont_SetStringInt(int num, int x, int y)
-{
-  char bufp[256];
-
-  snprintf(bufp, 256, "%d", num);
-  gFont_SetString(bufp, x, y);
-}
-
-void
-gFont_SetFont_OP()
-{
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gFont.cc	Thu Jun 02 17:51:41 2011 +0900
@@ -0,0 +1,169 @@
+/*
+ * $Id$
+ * 
+ * フォント表示。といっても結局スプライトです。
+ * gSprite.c と一緒にしてもよかったんだけど
+ * 文字は文字でいろいろあるので分けてみる
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include "libps2.h"
+#include "ps2util.h"
+#include "gSprite.h"
+
+#define DEFOBJ 120
+#define SPRITE_COL 0x4f
+#define SCREEN_HALF_W 320
+#define SCREEN_HALF_H 240
+#define CHAR_W_SIZE 17
+#define CHAR_H_SIZE 34
+
+static SpriteTable   sptable[DEFOBJ];
+static ps2utilSprite sp[DEFOBJ*2]; // 表示スプライト用スタック
+static unsigned int  sp_counter;
+static bool          flag_spriteInited = false; // スプライトロードフラグ
+
+static TEXTURE *font_tex;
+
+static void
+gFont_Init_Png(char *texname)
+{
+  if (!(font_tex = read_png_file(texname))) {
+    fprintf(stderr,
+	    "cannot creat texture - gFont_Init_Png().\n");
+    fflush(stderr);
+    exit(EXIT_FAILURE);
+  }
+
+  if (ps2util_tex_Set(font_tex) == -1) {
+    fprintf(stderr,
+	    "cannot set texture - gFont_Init_Png().\n");
+    fflush(stderr);
+    exit(EXIT_FAILURE);
+  }
+}
+
+static void
+gFont_Create()
+{
+  int i;
+  for (i=0; i<DEFOBJ; i++) {
+    if (ps2util_sprite_Create(&sp[i], font_tex) == -1) {
+      fprintf(stderr,
+	      "cannot create sprite - gFont_Create()\n");
+      fflush(stderr);
+      exit(EXIT_FAILURE);
+    }
+    ps2util_sprite_Unuse_alpha(&sp[i]);
+  }
+
+
+  flag_spriteInited = true;
+}
+
+static void
+gFont_DefSprite(int number, int x, int y, int w, int h)
+{
+  sptable[number].tx = x;
+  sptable[number].ty = y;
+  sptable[number].tw = w;
+  sptable[number].th = h;
+}
+
+void
+gFont_Init()
+{
+  int i, j;
+  int number = 0;
+
+  gFont_Init_Png("img/font.png");
+  gFont_Create(); // スプライト生成
+
+  for (i=0; i<7; i++) {
+    for (j=0; j<15; j++) {
+      gFont_DefSprite(number, j*17, i*34, 17, 34);
+      number++;
+    }
+  }
+}
+
+
+static void
+gFont_PutSprite(int number, int x, int y)
+{
+    ps2utilSprite *p = &sp[sp_counter];
+
+    // ushortってなんですか?:miya
+    /*
+    ps2util_sprite_Set_basicAttribute(
+	p,
+	(ushort)x, (ushort)y,
+	(ushort)sptable[number].tw*1.5, (ushort)sptable[number].th*1.5,
+	(ushort)sptable[number].tx, (ushort)sptable[number].ty,
+	(ushort)sptable[number].tw, (ushort)sptable[number].th,
+	SPRITE_PRIO_FOREGROUND);
+    */
+
+    ps2util_sprite_Request(p);
+    sp_counter++;
+}
+
+
+static void
+gFont_Clear()
+{
+    int i;
+
+    for (i=0; i<DEFOBJ; i++) {
+   	sprite_disappear(&sp[i].attribute);
+    }
+    sp_counter = 0;
+}
+
+void
+gFont_Draw_Reset()
+{
+    if (flag_spriteInited == true) {
+     	gFont_Clear();
+    }
+}
+
+static int
+get_number_char(char a)
+{
+    return (int)a-32;
+}
+
+/*
+ * str をスプライド表示
+ */
+void
+gFont_SetString(char *str, int x, int y)
+{
+  int number;
+
+  while (*str != '\0') {
+    number = get_number_char(*str);
+    gFont_PutSprite(number, x, y);
+    str++;
+    x += (int)CHAR_W_SIZE*1.5;
+  }
+}
+
+/*
+ * numを文字列に変換してSetStringに渡す
+ */
+void
+gFont_SetStringInt(int num, int x, int y)
+{
+  char bufp[256];
+
+  snprintf(bufp, 256, "%d", num);
+  gFont_SetString(bufp, x, y);
+}
+
+void
+gFont_SetFont_OP()
+{
+}
--- a/gSprite.c	Thu Jun 02 17:26:21 2011 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,157 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include "libps2.h"
-#include "ps2util.h"
-#include "gSprite.h"
-#include <stdbool.h>
-
-#define DEFOBJ 100
-#define SPRITE_COL 0x4f
-#define SCREEN_HALF_W 320
-#define SCREEN_HALF_H 240
-
-static SpriteTable   sptable[DEFOBJ];
-static ps2utilSprite sp[DEFOBJ]; // 表示スプライト用スタック
-static unsigned int  sp_counter;
-static bool          flag_spriteInited = false; // スプライトロードフラグ
-
-static TEXTURE *sprite_tex;
-
-
-void
-gSprite_DefSprite(int number, int tx, int ty, int tw, int th)
-{
-  sptable[number].tx = tx;
-  sptable[number].ty = ty;
-  sptable[number].tw = tw;
-  sptable[number].th = th;
-}
-
-void
-gSprite_PutSprite(int number, int x, int y)
-{
-    ps2utilSprite *p = &sp[sp_counter];
-
-    ps2util_sprite_Set_basicAttribute(
-	p,
-	(unsigned short)x, (unsigned short)y,
-	(unsigned short)sptable[number].tw*2, (unsigned short)sptable[number].th*2,
-	(unsigned short)sptable[number].tx, (unsigned short)sptable[number].ty,
-	(unsigned short)sptable[number].tw, (unsigned short)sptable[number].th,
-	SPRITE_PRIO_FOREGROUND);
-
-    ps2util_sprite_Request(p);
-    sp_counter++;
-}
-
-void
-gSprite_PutSpriteEx(int number, int x, int y, float w, float h)
-{
-    ps2utilSprite *p = &sp[sp_counter];
-
-    ps2util_sprite_Set_basicAttribute(
-	p,
-	(unsigned short)x, (unsigned short)y,
-	(unsigned short)sptable[number].tw*w, (unsigned short)sptable[number].th*h,
-	(unsigned short)sptable[number].tx, (unsigned short)sptable[number].ty,
-	(unsigned short)sptable[number].tw, (unsigned short)sptable[number].th,
-	SPRITE_PRIO_FOREGROUND);
-
-    ps2util_sprite_Request(p);
-    sp_counter++;
-}
-
-
-static void
-gSprite_Init_Png(char *texname)
-{
-  if (!(sprite_tex = read_png_file(texname))) {
-    fprintf(stderr,
-	    "cannot creat texture - init_png().\n");
-    fflush(stderr);
-    exit(EXIT_FAILURE);
-  }
-
-  if (ps2util_tex_Set(sprite_tex) == -1) {
-    fprintf(stderr,
-	    "cannot set texture - init_png().\n");
-    fflush(stderr);
-    exit(EXIT_FAILURE);
-  }
-
-}
-
-static void
-gSprite_Create()
-{
-  int i;
-
-  for (i=0; i<DEFOBJ; i++) {
-    if (ps2util_sprite_Create(&sp[i], sprite_tex) == -1) {
-      fprintf(stderr,
-	      "cannot create sprite No.%d - create_sprite()\n", i);
-      fflush(stderr);
-      exit(EXIT_FAILURE);
-    }
-    ps2util_sprite_Unuse_alpha(&sp[i]);
-  }
-
-  flag_spriteInited = false;
-}
-
-
-void
-gSprite_Init()
-{
-  ps2util_graphic_Init();
-  gSprite_Init_Png("img/main2.png");
-  gSprite_Create(); // スプライト生成
-
-
-  // スプライトの登録 
-  gSprite_DefSprite(10,   1,   1, 512, 666); // タイトル  
-  gSprite_DefSprite(17,   1,  35,  33,  33); // 選択マーク
-  gSprite_DefSprite(23,   1,   1, 106,  34); // スピードメーター
-  gSprite_DefSprite(24,  51,  40,  18,  20); // 右矢印
-  gSprite_DefSprite(25,  33,  40,  17,  20); // 左矢印
-  gSprite_DefSprite(26,  56,  89,  55,  26); // km/h
-  gSprite_DefSprite(27,  62,  62,  39,  26); // Rap
-  gSprite_DefSprite(28, 430,  62,  53,  46); // 1p
-  gSprite_DefSprite(29, 460,   6,  53,  46); // 2P 
-  gSprite_DefSprite(51, 333, 116, 165,  140); // 選択画面の車 
-  gSprite_DefSprite(52, 181, 116, 165,  140);
-  gSprite_DefSprite(53,  12, 116, 165,  140);
-  gSprite_DefSprite(81, 115,   1, 148, 114); // 選択画面のコース 
-  // 本当は (82, 272,...)です。二つ目のコース絵がないので 
-  gSprite_DefSprite(82, 272,   1, 148, 114);
-
-}
-
-
-static void
-gSprite_Clear()
-{
-  int i;
-
-  for (i=0; i<DEFOBJ; i++) {
-    sprite_disappear(&sp[i].attribute);
-  }
-  sp_counter = 0;
-}
-
-
-
-void
-gSprite_Draw_Reset()
-{
-  if (flag_spriteInited == true) {
-    gSprite_Clear();
-  }
-}
-
-
-
-void
-gSprite_PutSprite_Pause()
-{
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gSprite.cc	Thu Jun 02 17:51:41 2011 +0900
@@ -0,0 +1,157 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include "libps2.h"
+#include "ps2util.h"
+#include "gSprite.h"
+#include <stdbool.h>
+
+#define DEFOBJ 100
+#define SPRITE_COL 0x4f
+#define SCREEN_HALF_W 320
+#define SCREEN_HALF_H 240
+
+static SpriteTable   sptable[DEFOBJ];
+static ps2utilSprite sp[DEFOBJ]; // 表示スプライト用スタック
+static unsigned int  sp_counter;
+static bool          flag_spriteInited = false; // スプライトロードフラグ
+
+static TEXTURE *sprite_tex;
+
+
+void
+gSprite_DefSprite(int number, int tx, int ty, int tw, int th)
+{
+  sptable[number].tx = tx;
+  sptable[number].ty = ty;
+  sptable[number].tw = tw;
+  sptable[number].th = th;
+}
+
+void
+gSprite_PutSprite(int number, int x, int y)
+{
+    ps2utilSprite *p = &sp[sp_counter];
+
+    ps2util_sprite_Set_basicAttribute(
+	p,
+	(unsigned short)x, (unsigned short)y,
+	(unsigned short)sptable[number].tw*2, (unsigned short)sptable[number].th*2,
+	(unsigned short)sptable[number].tx, (unsigned short)sptable[number].ty,
+	(unsigned short)sptable[number].tw, (unsigned short)sptable[number].th,
+	SPRITE_PRIO_FOREGROUND);
+
+    ps2util_sprite_Request(p);
+    sp_counter++;
+}
+
+void
+gSprite_PutSpriteEx(int number, int x, int y, float w, float h)
+{
+    ps2utilSprite *p = &sp[sp_counter];
+
+    ps2util_sprite_Set_basicAttribute(
+	p,
+	(unsigned short)x, (unsigned short)y,
+	(unsigned short)sptable[number].tw*w, (unsigned short)sptable[number].th*h,
+	(unsigned short)sptable[number].tx, (unsigned short)sptable[number].ty,
+	(unsigned short)sptable[number].tw, (unsigned short)sptable[number].th,
+	SPRITE_PRIO_FOREGROUND);
+
+    ps2util_sprite_Request(p);
+    sp_counter++;
+}
+
+
+static void
+gSprite_Init_Png(char *texname)
+{
+  if (!(sprite_tex = read_png_file(texname))) {
+    fprintf(stderr,
+	    "cannot creat texture - init_png().\n");
+    fflush(stderr);
+    exit(EXIT_FAILURE);
+  }
+
+  if (ps2util_tex_Set(sprite_tex) == -1) {
+    fprintf(stderr,
+	    "cannot set texture - init_png().\n");
+    fflush(stderr);
+    exit(EXIT_FAILURE);
+  }
+
+}
+
+static void
+gSprite_Create()
+{
+  int i;
+
+  for (i=0; i<DEFOBJ; i++) {
+    if (ps2util_sprite_Create(&sp[i], sprite_tex) == -1) {
+      fprintf(stderr,
+	      "cannot create sprite No.%d - create_sprite()\n", i);
+      fflush(stderr);
+      exit(EXIT_FAILURE);
+    }
+    ps2util_sprite_Unuse_alpha(&sp[i]);
+  }
+
+  flag_spriteInited = false;
+}
+
+
+void
+gSprite_Init()
+{
+  ps2util_graphic_Init();
+  gSprite_Init_Png("img/main2.png");
+  gSprite_Create(); // スプライト生成
+
+
+  // スプライトの登録 
+  gSprite_DefSprite(10,   1,   1, 512, 666); // タイトル  
+  gSprite_DefSprite(17,   1,  35,  33,  33); // 選択マーク
+  gSprite_DefSprite(23,   1,   1, 106,  34); // スピードメーター
+  gSprite_DefSprite(24,  51,  40,  18,  20); // 右矢印
+  gSprite_DefSprite(25,  33,  40,  17,  20); // 左矢印
+  gSprite_DefSprite(26,  56,  89,  55,  26); // km/h
+  gSprite_DefSprite(27,  62,  62,  39,  26); // Rap
+  gSprite_DefSprite(28, 430,  62,  53,  46); // 1p
+  gSprite_DefSprite(29, 460,   6,  53,  46); // 2P 
+  gSprite_DefSprite(51, 333, 116, 165,  140); // 選択画面の車 
+  gSprite_DefSprite(52, 181, 116, 165,  140);
+  gSprite_DefSprite(53,  12, 116, 165,  140);
+  gSprite_DefSprite(81, 115,   1, 148, 114); // 選択画面のコース 
+  // 本当は (82, 272,...)です。二つ目のコース絵がないので 
+  gSprite_DefSprite(82, 272,   1, 148, 114);
+
+}
+
+
+static void
+gSprite_Clear()
+{
+  int i;
+
+  for (i=0; i<DEFOBJ; i++) {
+    sprite_disappear(&sp[i].attribute);
+  }
+  sp_counter = 0;
+}
+
+
+
+void
+gSprite_Draw_Reset()
+{
+  if (flag_spriteInited == true) {
+    gSprite_Clear();
+  }
+}
+
+
+
+void
+gSprite_PutSprite_Pause()
+{
+}
--- a/game.c	Thu Jun 02 17:26:21 2011 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,45 +0,0 @@
-/* game.c */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdbool.h>
-#include "libps2.h"
-#include "ps2util.h"
-#include "controler.h"
-//#include "linda/lindaapi.h"
-#include "game.h"
-#include "car.h"
-
-#include "schedule.h"
-
-
-/* linda.c */
-#ifdef LINDA
-//extern int linda_init();
-#else
-#define linda_init 1
-#endif
-
-void game_main()
-{
-  Game game;
-  bool flg = true;
-#ifdef LINDA
-  game->play_id = linda_init();
-#endif
-  
-  while (1) {
-    flg = padCheck();
-    
-    if (flg == false) {
-      break;
-    }
-    schedule(&game);
-    
-#ifdef LINDA
-    psx_sync_n();
-#endif
-  }
-}
-
-//ceriumのmainルーチンに直す。
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/game.cc	Thu Jun 02 17:51:41 2011 +0900
@@ -0,0 +1,45 @@
+/* game.c */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include "libps2.h"
+#include "ps2util.h"
+#include "controler.h"
+//#include "linda/lindaapi.h"
+#include "game.h"
+#include "car.h"
+
+#include "schedule.h"
+
+
+/* linda.c */
+#ifdef LINDA
+//extern int linda_init();
+#else
+#define linda_init 1
+#endif
+
+void game_main()
+{
+  Game game;
+  bool flg = true;
+#ifdef LINDA
+  game->play_id = linda_init();
+#endif
+  
+  while (1) {
+    flg = padCheck();
+    
+    if (flg == false) {
+      break;
+    }
+    schedule(&game);
+    
+#ifdef LINDA
+    psx_sync_n();
+#endif
+  }
+}
+
+//ceriumのmainルーチンに直す。
--- a/game_time.c	Thu Jun 02 17:26:21 2011 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,114 +0,0 @@
-/**
- * 2006/07/31(MON) Nobutaka OSHIRO
- */
-#include "game_time.h"
-
-int game_time_get_msec() {
-	
-  struct timeval now; 	 
-  int time_msec;
-
- /** 
-  *  *** man timeval ***
-  *  struct timeval {
-  *   time_t tv_sec // second
-  *   suseconds_t tv_usec; // micro sec
-  * }; 
-  **/
-
-  // get time micro second ( micro second = 1 / 1000,000 second) 
-  gettimeofday(&now, NULL);
-
-  // evaluation milli second ( milli second = 1 / 1000 second )
-  time_msec = now.tv_sec * 1000 + now.tv_usec / 1000;
- 
-  return time_msec;
-}
-
-
-int game_time_conv_ms2cs (int msec)
-{
-  return msec / 10 % 100;  /** 1/100 sec **/ 
-}
-
-int game_time_conv_ms2sec (int msec)
-{
-  return msec / 1000 % 60;
-}
-
-int game_time_conv_ms2minute (int msec)
-{
-  return msec / 60000 % 60;  
-}
-
-
-/**
- *  NAME:
- *       game_time_set_raptime - Return RAP TIME ("XXX:XX:XX") 
- *
- *  DESCRIPTION:
- *       1. convert (int --> string)
- *             (int) argument2 (milli second)  --> "XXX:XX:XX"
- *  
- *       2. set ( string --> char * ) 
- *             "XXX:XX:XX" --> char *argument1  
- **/
-void game_time_set_raptime (char *s,int msec)  
-{
-  char chminute[3]; 
-  char chsec[2];
-  char chcsec[2];
-  char raptime[10];
-  int minute  = game_time_conv_ms2minute (msec);
-  int sec  = game_time_conv_ms2sec (msec); 
-  int csec = game_time_conv_ms2cs (msec);
-  int i;
-
-
-  if (minute < 10 ){
-    chminute[0] = ' ';
-    chminute[1] = '0';
-    chminute[2] = minute + 48;
-  } else if (minute < 100 ) {
-    chminute[0] = ' ';
-    chminute[1] = (minute / 10) + 48;  
-    chminute[2] = (minute % 10) + 48;
-  } else {
-    chminute[0] = (minute / 100) + 48;
-    chminute[1] = (minute / 10) + 48;  
-    chminute[2] = (minute % 10) + 48;
-  }
-  if (sec < 10 ){  
-    chsec[0] = '0';
-    chsec[1] = sec + 48;
-  } else {
-    chsec[0] = (sec / 10) + 48;  
-    chsec[1] = (sec % 10) + 48;
-  }
-
-  if (csec < 10 ){  
-    chcsec[0] = '0';
-    chcsec[1] = csec + 48;
-  } else {
-    chcsec[0] = (csec / 10) + 48;  
-    chcsec[1] = (csec % 10) + 48;
-  }
-
-
-  /** raptime[0-9] == "XXX:XX:XX\0" **/ 
-  raptime[0] = chminute[0];
-  raptime[1] = chminute[1];
-  raptime[2] = chminute[2];
-  raptime[3] = ':';
-  raptime[4] = chsec[0];
-  raptime[5] = chsec[1];
-  raptime[6] = ':';
-  raptime[7] = chcsec[0];
-  raptime[8] = chcsec[1];
-  raptime[9] = '\0';   // NULL
-
-
-  for (i = 0; raptime[i] != '\0'; i++) {
-    s[i] = raptime[i];    
-  } 
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/game_time.cc	Thu Jun 02 17:51:41 2011 +0900
@@ -0,0 +1,114 @@
+/**
+ * 2006/07/31(MON) Nobutaka OSHIRO
+ */
+#include "game_time.h"
+
+int game_time_get_msec() {
+	
+  struct timeval now; 	 
+  int time_msec;
+
+ /** 
+  *  *** man timeval ***
+  *  struct timeval {
+  *   time_t tv_sec // second
+  *   suseconds_t tv_usec; // micro sec
+  * }; 
+  **/
+
+  // get time micro second ( micro second = 1 / 1000,000 second) 
+  gettimeofday(&now, NULL);
+
+  // evaluation milli second ( milli second = 1 / 1000 second )
+  time_msec = now.tv_sec * 1000 + now.tv_usec / 1000;
+ 
+  return time_msec;
+}
+
+
+int game_time_conv_ms2cs (int msec)
+{
+  return msec / 10 % 100;  /** 1/100 sec **/ 
+}
+
+int game_time_conv_ms2sec (int msec)
+{
+  return msec / 1000 % 60;
+}
+
+int game_time_conv_ms2minute (int msec)
+{
+  return msec / 60000 % 60;  
+}
+
+
+/**
+ *  NAME:
+ *       game_time_set_raptime - Return RAP TIME ("XXX:XX:XX") 
+ *
+ *  DESCRIPTION:
+ *       1. convert (int --> string)
+ *             (int) argument2 (milli second)  --> "XXX:XX:XX"
+ *  
+ *       2. set ( string --> char * ) 
+ *             "XXX:XX:XX" --> char *argument1  
+ **/
+void game_time_set_raptime (char *s,int msec)  
+{
+  char chminute[3]; 
+  char chsec[2];
+  char chcsec[2];
+  char raptime[10];
+  int minute  = game_time_conv_ms2minute (msec);
+  int sec  = game_time_conv_ms2sec (msec); 
+  int csec = game_time_conv_ms2cs (msec);
+  int i;
+
+
+  if (minute < 10 ){
+    chminute[0] = ' ';
+    chminute[1] = '0';
+    chminute[2] = minute + 48;
+  } else if (minute < 100 ) {
+    chminute[0] = ' ';
+    chminute[1] = (minute / 10) + 48;  
+    chminute[2] = (minute % 10) + 48;
+  } else {
+    chminute[0] = (minute / 100) + 48;
+    chminute[1] = (minute / 10) + 48;  
+    chminute[2] = (minute % 10) + 48;
+  }
+  if (sec < 10 ){  
+    chsec[0] = '0';
+    chsec[1] = sec + 48;
+  } else {
+    chsec[0] = (sec / 10) + 48;  
+    chsec[1] = (sec % 10) + 48;
+  }
+
+  if (csec < 10 ){  
+    chcsec[0] = '0';
+    chcsec[1] = csec + 48;
+  } else {
+    chcsec[0] = (csec / 10) + 48;  
+    chcsec[1] = (csec % 10) + 48;
+  }
+
+
+  /** raptime[0-9] == "XXX:XX:XX\0" **/ 
+  raptime[0] = chminute[0];
+  raptime[1] = chminute[1];
+  raptime[2] = chminute[2];
+  raptime[3] = ':';
+  raptime[4] = chsec[0];
+  raptime[5] = chsec[1];
+  raptime[6] = ':';
+  raptime[7] = chcsec[0];
+  raptime[8] = chcsec[1];
+  raptime[9] = '\0';   // NULL
+
+
+  for (i = 0; raptime[i] != '\0'; i++) {
+    s[i] = raptime[i];    
+  } 
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hikae	Thu Jun 02 17:51:41 2011 +0900
@@ -0,0 +1,20 @@
+hg rename camera.c camera.cc
+hg rename car.c car.cc
+hg rename carNode.c carNode.cc
+hg rename col.c col.cc
+hg rename controler.c controler.cc
+hg rename field.c field.cc
+hg rename gFont.c gFont.cc
+hg rename gSprite.c gSprite.cc
+hg rename game.c game.cc
+hg rename game_time.c game_time.cc
+hg rename light.c light.cc
+hg rename linda.c linda.cc
+hg rename main.c main.cc
+hg rename mytype.c mytype.cc
+hg rename ps2util.c ps2util.cc
+hg rename quotanion.c quotanion.cc
+hg rename schedule.c schedule.cc
+hg rename sjoy.c sjoy.cc
+hg rename test_vector.c test_vector.cc
+hg rename title_scene.c title_scene.cc
--- a/light.c	Thu Jun 02 17:26:21 2011 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,77 +0,0 @@
-/* light.c */
-
-#include <stdio.h>
-#include "libps2.h"
-#include "light.h"
-
-#include "sjoy.h" // ps2関連ファイルから
-
-FMATRIX normal_light;
-FMATRIX light_color;
-
-
-void init_light(LIGHT *l)
-{
-  //Three lights in all.
-  //   The color of the light of "light0" is color0.
-  //   The color of the light of "light1" is color1.
-  //   The color of the light of "light2" is color2.
-  
-
-  l->light0[0] = 0.0;
-  l->light0[1] = 0.0;
-  l->light0[2] = 1.0;
-  l->light0[3] = 1.0;
-
-  l->light1[0] = 0.0;
-  l->light1[1] = -1.0;
-  l->light1[2] = 0.0;
-  l->light1[3] = 1.0;
-
-  l->light2[0] = 1.0;
-  l->light2[1] = 1.0;
-  l->light2[2] = 1.0;
-  l->light2[3] = 1.0;
-
-  l->color0[0] = 0.4;
-  l->color0[1] = 0.4;
-  l->color0[2] = 0.4;
-  l->color0[3] = 1.0;
-
-  l->color1[0] = 0.4;
-  l->color1[1] = 0.4;
-  l->color1[2] = 0.4;
-  l->color1[3] = 1.0;
-
-  l->color2[0] = 0.4;
-  l->color2[1] = 0.4;
-  l->color2[2] = 0.4;
-  l->color2[3] = 1.0;
-
-//Reflection degree of light
-  l->ambient[0] = 0.4;
-  l->ambient[1] = 0.4;
-  l->ambient[2] = 0.4;
-  l->ambient[3] = 1.0;
-
-}
-
-// 自作:miya
-void ps2_vu0_normal_light_matrix(FMATRIX light_color, FVECTOR l0, FVECTOR l1, FVECTOR l2)
-{
-  char *miyahira;
-  miyahira = "この関数なに?";
-}
-
-// 自作:miya
-void ps2_vu0_light_color_matrix( FMATRIX light_color, FVECTOR c0, FVECTOR c1, FVECTOR c2, FVECTOR a)
-{
-  char *miyahira;
-  miyahira = "test";
-}
-
-void set_light(LIGHT *l)
-{
-  ps2_vu0_normal_light_matrix(normal_light, l->light0, l->light1, l->light2);
-  ps2_vu0_light_color_matrix(light_color, l->color0, l->color1, l->color2, l->ambient);
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/light.cc	Thu Jun 02 17:51:41 2011 +0900
@@ -0,0 +1,77 @@
+/* light.c */
+
+#include <stdio.h>
+#include "libps2.h"
+#include "light.h"
+
+#include "sjoy.h" // ps2関連ファイルから
+
+FMATRIX normal_light;
+FMATRIX light_color;
+
+
+void init_light(LIGHT *l)
+{
+  //Three lights in all.
+  //   The color of the light of "light0" is color0.
+  //   The color of the light of "light1" is color1.
+  //   The color of the light of "light2" is color2.
+  
+
+  l->light0[0] = 0.0;
+  l->light0[1] = 0.0;
+  l->light0[2] = 1.0;
+  l->light0[3] = 1.0;
+
+  l->light1[0] = 0.0;
+  l->light1[1] = -1.0;
+  l->light1[2] = 0.0;
+  l->light1[3] = 1.0;
+
+  l->light2[0] = 1.0;
+  l->light2[1] = 1.0;
+  l->light2[2] = 1.0;
+  l->light2[3] = 1.0;
+
+  l->color0[0] = 0.4;
+  l->color0[1] = 0.4;
+  l->color0[2] = 0.4;
+  l->color0[3] = 1.0;
+
+  l->color1[0] = 0.4;
+  l->color1[1] = 0.4;
+  l->color1[2] = 0.4;
+  l->color1[3] = 1.0;
+
+  l->color2[0] = 0.4;
+  l->color2[1] = 0.4;
+  l->color2[2] = 0.4;
+  l->color2[3] = 1.0;
+
+//Reflection degree of light
+  l->ambient[0] = 0.4;
+  l->ambient[1] = 0.4;
+  l->ambient[2] = 0.4;
+  l->ambient[3] = 1.0;
+
+}
+
+// 自作:miya
+void ps2_vu0_normal_light_matrix(FMATRIX light_color, FVECTOR l0, FVECTOR l1, FVECTOR l2)
+{
+  char *miyahira;
+  miyahira = "この関数なに?";
+}
+
+// 自作:miya
+void ps2_vu0_light_color_matrix( FMATRIX light_color, FVECTOR c0, FVECTOR c1, FVECTOR c2, FVECTOR a)
+{
+  char *miyahira;
+  miyahira = "test";
+}
+
+void set_light(LIGHT *l)
+{
+  ps2_vu0_normal_light_matrix(normal_light, l->light0, l->light1, l->light2);
+  ps2_vu0_light_color_matrix(light_color, l->color0, l->color1, l->color2, l->ambient);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/linda.cc	Thu Jun 02 17:51:41 2011 +0900
@@ -0,0 +1,729 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <string.h>
+#include <math.h>
+#include <arpa/inet.h>
+#include "libps2.h"
+#include "ps2util.h"
+
+#include "car.h"
+#include "game.h"
+#include "Linda/lindaapi.h"
+#include "linda.h"
+
+extern void psx_free(unsigned char *);
+extern void carNode_append(CarPtr);
+extern FILE *main_fp;
+static int my_id;
+static CarPtr linda_carlist[CLIENT_MAX+1];
+static int linda_seq[CLIENT_MAX+1];
+
+static bool (*sche_func)(int);
+
+static void
+set_header(unsigned int data, char *pkt, int offset)
+{
+    int *ipkt;
+    int ndata = htonl(data);
+
+    ipkt = (int*)pkt;
+    ipkt[offset/4] = ndata;
+}
+
+static unsigned int
+get_header(char *pkt, int offset)
+{
+    int *ipkt;
+    int data;
+    unsigned int header;
+
+    ipkt   = (int *)pkt;
+    data   = ipkt[offset/4];
+    header = (unsigned int)ntohl(data);
+
+    return header;
+}
+
+static char*
+make_packet(unsigned int mode,     unsigned int carid,
+	    unsigned int courseid, char *data)
+{
+    char *packet;
+    unsigned int len = 0;
+
+    if (data) len += sizeof(FMATRIX);
+
+    packet = (char*)malloc(PKT_HEADER_SIZE+len);
+
+    set_header(mode,     packet, PKT_MODE_OFFSET);
+    set_header(carid,    packet, PKT_CARID_OFFSET);
+    set_header(courseid, packet, PKT_COURSEID_OFFSET);
+
+    if (data)
+      	memcpy(packet+PKT_DATA_OFFSET, data, len);
+
+    return packet;
+}
+
+
+static void
+send_packet(unsigned int dest, unsigned int mode, unsigned int car,
+	    unsigned int course,  char *data)
+{
+  char *pkt;
+  char *reply;
+  int len = PKT_HEADER_SIZE;
+
+  if (data) len += sizeof(FMATRIX);
+
+  reply = psx_reply(linda_seq[dest]);
+    
+  if (linda_seq[dest] == 0) {
+    pkt = make_packet(mode, car, course, data);
+    psx_out(dest, pkt, len);
+    free(pkt);
+  } else if (reply = psx_reply(linda_seq[dest])) {
+    pkt = make_packet(mode, car, course, data);
+    psx_out(dest, pkt, len);
+    free(pkt);
+    psx_free(reply);
+  }
+    
+  pkt = make_packet(mode, car, course, data);
+  psx_out(dest, pkt, len);
+  free(pkt);
+}
+
+static void
+get_packet(int id, int *flg, int *mode, int *car, int *course, char *data)
+{
+  char *reply = NULL;
+  char *pkt = NULL;
+
+  reply = psx_reply(linda_seq[id]);
+  if (reply) {
+    pkt    = reply+LINDA_HEADER_SIZE;
+
+    if (flg)    *flg    = 1;
+    if (mode)   *mode   = get_header(pkt, PKT_MODE_OFFSET);
+    if (car)    *car    = get_header(pkt, PKT_CARID_OFFSET);
+    if (course) *course = get_header(pkt, PKT_COURSEID_OFFSET);
+    if (data)   memcpy(data, pkt+PKT_DATA_OFFSET, sizeof(FMATRIX));
+    psx_free(reply);
+    linda_seq[id] = psx_rd(id);
+  }    
+}
+
+static void
+linda_set_schedule(void *func, int mode, Game *game)
+{
+  int id = game->play_id;
+
+  linda_seq[id] = psx_in(id);
+  sche_func = func;
+  send_packet(id, mode, game->car_id, game->course_id, NULL);
+}
+
+static bool linda_sche_wait0(int p, Game *game)
+{
+  int i, flg=0;
+  int mode = 0;
+  int id = game->play_id;
+  int connect = 1; // 接続済みユーザ数
+
+  for (i=1; i<=CLIENT_MAX; i++) {
+    if (i == id) continue;
+    get_packet(i, &flg, &mode, NULL, NULL, NULL);
+    if (flg == 1 && mode == MODE_WAIT) {
+      connect++;
+      flg = 0;
+    }
+  }
+
+  if (p == 1 && connect == CLIENT_MAX) {
+    linda_set_schedule(linda_sche_wait_ready0, MODE_WAIT_READY,game);
+    return true;
+  } else {
+    return false;
+  }
+}
+
+static bool
+linda_sche_wait1(int p, Game *game)
+{
+  int mode;
+
+  get_packet(PLAYER_1P, NULL, &mode, NULL, NULL, NULL);
+
+  if (mode == MODE_WAIT_READY) {
+    linda_set_schedule(linda_sche_wait_ready1, MODE_WAIT_READY, game);
+    return true;
+  } else {
+    return false;
+  }
+}
+
+static bool
+linda_sche_wait_ready0(int p, Game *game)
+{
+  int i, flg, mode;
+  int id = game->play_id;
+  int connect = 1;
+
+  for (i=1; i<=CLIENT_MAX; i++) {
+    if (i == id) continue;
+    get_packet(i, &flg, &mode, NULL, NULL, NULL);
+    if (i == id) {
+      flg = 0;
+      continue;
+    }
+    if (flg == 1 && mode == MODE_WAIT_READY) {
+      connect++;
+      flg = 0;
+    }
+  }
+
+  if (p == 1 && connect == CLIENT_MAX) {
+    linda_set_schedule(linda_sche_opening0, MODE_OPENING,game);
+    return true;
+  } else {
+    return false;
+  }
+
+}
+
+static bool
+linda_sche_wait_ready1(int p, Game *game)
+{
+  int mode;
+
+  get_packet(PLAYER_1P, NULL, &mode, NULL, NULL, NULL);
+
+  if (mode == MODE_OPENING) {
+    linda_set_schedule(linda_sche_opening1, MODE_OPENING,game);
+    return true;
+  } else {
+    return false;
+  }
+}
+
+static bool
+linda_sche_opening0(int p, Game *game)
+{
+  int i, flg, mode;
+  int id = game->play_id;
+  int connect = 1;
+
+  for (i=1; i<=CLIENT_MAX; i++) {
+    if (i == id) continue;
+    get_packet(i, &flg, &mode, NULL, NULL, NULL);
+    if (flg == 1 && mode == MODE_OPENING) {
+      connect++;
+      flg = 0;
+    }
+  }
+
+  if (p == 1 && connect == CLIENT_MAX) {
+    linda_set_schedule(linda_sche_select_car0, MODE_SELECT_CAR, game);
+    return true;
+  } else {
+    return false;
+  }
+}
+
+static bool
+linda_sche_opening1(int p, Game *game)
+{
+  int mode;
+
+  get_packet(PLAYER_1P, NULL, &mode, NULL, NULL, NULL);
+
+  if (mode == MODE_SELECT_CAR) {
+    linda_set_schedule(linda_sche_select_car1, MODE_SELECT_CAR, game);
+    return true;
+  } else {
+    return false;
+  }
+}
+
+static bool 
+linda_sche_select_car0(int p, Game *game)
+{
+  int i, flg, mode;
+  int id = game->play_id;
+  int connect = 1;
+
+  for (i=1; i<=CLIENT_MAX; i++) {
+    if (i == id) continue;
+    get_packet(i, &flg, &mode, NULL, NULL, NULL);
+    if (flg == 1 && mode == MODE_SELECT_CAR) {
+      connect++;
+      flg = 0;
+    }
+  }
+
+  if (p == 1 && connect == CLIENT_MAX) {
+    linda_set_schedule(linda_sche_select_course0, MODE_SELECT_COURSE, game);
+    return true;
+  } else {
+    return false;
+  }
+}
+
+static bool
+linda_sche_select_car1(int p, Game *game)
+{
+  int mode;
+
+  get_packet(PLAYER_1P, NULL, &mode, NULL, NULL, NULL);
+
+  if (mode == MODE_SELECT_COURSE) {
+    linda_set_schedule(linda_sche_select_course1, MODE_SELECT_COURSE, game);
+    return true;
+  } else {
+    return false;
+  }
+}
+
+static bool
+linda_sche_select_course0(int p, Game *game)
+{
+  int i;
+  int flg, mode;
+  int connect = 1;
+  int id = game->play_id;
+  static int course_id = 1;
+
+  if (course_id != game->course_id) {
+    course_id = game->course_id;
+    linda_seq[id] = psx_in(id);
+    send_packet(id, MODE_SELECT_COURSE, 0, course_id, NULL);
+    return false;
+  }
+
+  for (i=1; i<=CLIENT_MAX; i++) {
+    if (i == id) continue; 
+    get_packet(i, &flg, &mode, NULL, NULL, NULL);
+    if (flg == 1 && mode == MODE_SELECT_COURSE) {
+      connect++;
+      flg = 0;
+    }
+
+  }
+
+  if (p == 1 && connect == CLIENT_MAX) {
+    linda_set_schedule(linda_sche_ready0, MODE_READY, game);
+    return true;
+  } else {
+    return false;
+  }
+}
+
+static bool
+linda_sche_select_course1(int p, Game *game)
+{
+  int mode, course_id;
+
+  get_packet(PLAYER_1P, NULL, &mode, NULL, &course_id, NULL);
+
+  if (mode == MODE_SELECT_COURSE) {
+    game->course_id = course_id;
+    return false;
+  } else if (mode == MODE_READY) {
+    linda_set_schedule(linda_sche_ready1, MODE_READY, game);
+    return true;
+  } else {
+    return false;
+  }
+}
+
+
+static bool
+linda_sche_ready0(int p, Game *game)
+{
+  int i, flg, mode;
+  int id = game->play_id;
+  int connect = 1;
+
+  for (i=1; i<=CLIENT_MAX; i++) {
+    if (i == id) continue;
+    get_packet(i, &flg, &mode, NULL, NULL, NULL);
+    if (flg == 1 && mode == MODE_READY) {
+      connect++;
+      flg = 0;
+    }
+  }
+
+  if (p == 1 && connect == CLIENT_MAX) {
+    linda_set_schedule(linda_sche_main_init, MODE_MAIN_INIT, game);
+    return true;
+  } else {
+    return false;
+  }
+}
+
+static bool
+linda_sche_ready1(int p, Game *game)
+{
+  int mode;
+
+  get_packet(PLAYER_1P, NULL, &mode, NULL, NULL, NULL);
+
+  if (mode == MODE_MAIN_INIT) {
+    linda_set_schedule(linda_sche_main_init, MODE_MAIN_INIT, game);
+    return true;
+  } else {
+    return false;
+  }
+}
+
+static bool
+linda_sche_main_init(int p, Game *game)
+{
+  int i, flg, mode, car_id;
+  int id = game->play_id;
+  int connect = 1;
+  CarPtr car = NULL;
+
+  for (i=1; i<=CLIENT_MAX; i++) {
+    if (i == id) continue;
+    get_packet(i, &flg, &mode, &car_id, NULL, NULL);
+
+    if (flg == 1 && mode == MODE_MAIN_INIT) {
+      if (linda_carlist[i] == NULL) {
+	car = car_init(car_id);
+	carNode_append(car);
+	linda_carlist[i] = car;
+      }
+      connect++;
+      flg = 0;
+    }
+  }
+
+  if (p == 1 && connect == CLIENT_MAX) {
+    if (id == PLAYER_1P)
+      linda_set_schedule(linda_sche_main_ready0, MODE_MAIN_READY, game);
+    else
+      linda_set_schedule(linda_sche_main_ready1, MODE_MAIN_READY, game);
+    return true;
+  } else {
+    return false;
+  }
+}
+
+
+static bool
+linda_sche_main_ready0(int p, Game *game)
+{
+  int i, flg, mode;
+  int id = game->play_id;
+  int connect = 1;
+
+  for (i=1; i<=CLIENT_MAX; i++) {
+    if (i == id) continue;
+    get_packet(i, &flg, &mode, NULL, NULL, NULL);
+    if (flg == 1 && mode == MODE_MAIN_READY) {
+      connect++;
+      flg = 0;
+    }
+  }
+
+  if (p == 1 && connect == CLIENT_MAX) {
+    linda_set_schedule(linda_sche_main, MODE_MAIN, game);
+    return true;
+  } else {
+    return false;
+  }
+}
+
+static bool
+linda_sche_main_ready1(int p, Game *game)
+{
+  int mode;
+
+  get_packet(PLAYER_1P, NULL, &mode, NULL, NULL, NULL);
+
+  if (mode == MODE_MAIN) {
+    linda_set_schedule(linda_sche_main, MODE_MAIN, game);
+    return true;
+  } else {
+    return false;
+  }
+}
+
+static bool
+linda_sche_main(int p, Game *game)
+{
+  int i, flg, mode;
+  int id = game->play_id;
+  int connect = 1;
+  FMATRIX po;
+  CarPtr mycar = game->jiki;
+  CarPtr enemy = NULL;
+
+  for (i=1; i<=CLIENT_MAX; i++) {
+    ps2_vu0_unit_matrix(po);
+    get_packet(i, &flg, &mode, NULL, NULL, (char*)po);
+
+    if (i == id) {
+      ps2_vu0_copy_matrix(po, mycar->body->transfer);
+      ps2_vu0_copy_vector(po[3], mycar->location);
+	    
+      linda_seq[i] = psx_in(i);
+      send_packet(i, MODE_MAIN, 0, 0, (char*)po);
+    } else {
+      enemy = linda_carlist[i];
+      if (flg == 1 && mode == MODE_MAIN) {
+	ps2_vu0_copy_matrix(enemy->body->transfer, po);
+	enemy->body->transfer[3][0] -= mycar->location[0];
+	enemy->body->transfer[3][1] -= mycar->location[1];
+	enemy->body->transfer[3][2] -= mycar->location[2];
+	enemy->body->transfer[3][3] = 1;
+      }
+    }
+  }
+
+  if (p == 1 && connect == CLIENT_MAX) {
+    if (id == PLAYER_1P)
+      linda_set_schedule(linda_sche_main_ready0, MODE_MAIN_READY, game);
+    else
+      linda_set_schedule(linda_sche_main_ready1, MODE_MAIN_READY, game);
+    return true;
+  } else {
+    return false;
+  }
+
+
+  return false;
+}
+
+bool
+linda_update(int p, Game *game)
+{
+  return sche_func(p);
+}
+
+#if 0
+
+/*
+ * 位置が同じなら1を返す。
+ * もっと良い比較方法があるんでは...
+ */
+static int
+linda_jiki_compareLocation(Game *game)
+{
+  float x,y,z;
+  double d;
+
+  if (common_state == GAME_MAIN || common_state == GAME_GOAL) {
+    x = jiki.position[3][0] - game.jiki->location[0];
+    y = jiki.position[3][1] - game.jiki->location[1];
+    z = jiki.position[3][2] - game.jiki->location[2];
+    d = sqrt(x*x+y*y+z*z);
+
+    if (d < 1.0) {
+      return 1;
+    } else {
+      return 0;
+    }
+  } else {
+    return 1;
+  }
+}
+
+
+/*
+ * 自機情報が更新されていなければ
+ * 0を返す(psx_outしない)
+ */
+static int
+linda_jiki_compare()
+{
+  if ((jiki.car_id == game.car_id) &&
+      (jiki.course_id == game.course_id) &&
+      (jiki.create_flg == ((game.jiki) ? 1:0)) &&
+      (jiki.state == common_state) &&
+      (linda_jiki_compareLocation())) {
+    return 0;
+  } else {
+    return 1;
+  }
+}
+
+static void
+linda_jiki_update()
+{
+  int i,j;
+    
+
+  jiki.car_id     = game.car_id;
+  jiki.course_id  = game.course_id;
+  jiki.create_flg = (game.jiki) ? 1 : 0;
+  jiki.state      = common_state;
+
+  if (common_state == GAME_MAIN || common_state == GAME_GOAL) {
+    for (i=0; i<3; i++) {
+      for (j=0; j<4; j++) {
+	jiki.position[i][j]
+	  = game.jiki->body->transfer[i][j];
+      }
+    }
+    jiki.position[3][0] = game.jiki->location[0];
+    jiki.position[3][1] = game.jiki->location[1];
+    jiki.position[3][2] = game.jiki->location[2];
+    jiki.position[3][3] = 1;
+  }
+}
+
+void
+linda_update()
+{
+  int i;
+  int barrier = 1; // バリア同期(?)用
+  int connect = 1;
+  int mode, id, flg;
+  char* reply;
+  char* pkt;
+  CarPtr car = NULL;
+
+  for (i=1; i<=CLIENT_MAX; i++) {
+    reply = psx_reply(linda_seq[i]);
+    if (reply) {
+      pkt  = reply+LINDA_HEADER_SIZE;
+      mode = get_header(pkt, PKT_MODE_OFFSET);
+      id   = get_header(pkt, PKT_ID_OFFSET);
+      flg  = get_header(pkt, PKT_FLG_OFFSET);
+	    
+      if (i != game.play_id) {
+	connect++;
+		
+	car = linda_carlist[i];
+	if (common_state == GAME_MAIN && !car && p->create_flg == 1) {
+	  car = car_init(p->car_id);
+	  carNode_append(car);
+	  linda_carlist[i] = car;
+	}
+	linda_enemy_update(i, car, p);
+	if (common_state == p->state) {
+	  barrier++;
+	}
+      }
+      psx_free(reply);
+      linda_seq[i] = psx_rd(i);
+    }
+  }
+
+  if (connect == CLIENT_MAX) {
+    if (game->state == GAME_WAIT) {
+      gFont_SetString("CONNECT OK!!", 170, 300);
+      if (game->play_id == 1)
+	gFont_SetString(" PUSH START ", 170, 400);
+    }
+
+    // ごちゃごちゃしてる...
+    // なんか無駄な処理がありそうだ
+    if (game->play_id == 1) {
+      // 全員のフラグ成立
+      if (common_state == GAME_GOAL) {
+	if (game->state == GAME_FINISH) {
+	  common_state = game->state;
+	} else {
+	  game->state = common_state;
+	}
+      } else if (barrier == CLIENT_MAX) {
+	common_state = game->state;
+      } else {
+	game->state = common_state;
+      }
+    } else {
+      if (game->state == GAME_GOAL) {
+	if (common_state != GAME_FINISH) {
+	  common_state = game->state;
+	} else {
+	  game->state = common_state;
+	}
+      } else {
+	game->state = common_state;
+      }
+    }
+  } else {
+    if (game->state == GAME_WAIT) {
+      gFont_SetString("WAITING...", 200, 100);
+    }
+    game->state = common_state;
+  }
+
+  if (linda_jiki_compare()) {
+#ifdef DEBUG
+    // どのタイミングでoutされてるか見る
+    // 必要なときだけoutしないと重いですね当然だけど
+    fprintf(main_fp, "psx_out() jiki\n");
+#endif
+    linda_jiki_update();
+    // 無理矢理
+    // 古いものを消すだけなんだけど
+    // 正しいやり方が他に有るのかな?
+    // 実行し続けてると最終的に激重になるので
+    // ここら辺に問題が有るのだろうか。
+    psx_free(psx_reply(psx_in(game->play_id)));
+    linda_seq[my_id]=psx_in(game->play_id);
+    psx_out(game->play_id, (char*)&jiki, sizeof(CarInfo));
+  }
+}
+#endif
+
+static int
+get_id()
+{
+  unsigned char * reply;
+  int seq;
+  int id;
+
+  //ユーザIDが格納されているTUPLE SpaceのIDへアクセス
+  seq = psx_in(LINDA_ASK_ID);
+
+  // IDが取得できるまでループ
+  while((reply = psx_reply(seq)) == 0) psx_sync_n();
+
+  id = atoi(reply+LINDA_HEADER_SIZE);
+  psx_free(reply);
+  return id;
+}
+
+void linda_env_init( void )
+{
+  int i;
+  
+  for (i=0; i<CLIENT_MAX+1; i++) {
+    linda_carlist[i] = NULL;
+  }
+}
+
+
+
+int
+linda_init(Game *game)
+{
+  int i;
+
+  start_linda(LINDA_HOST);
+  my_id = get_id();
+
+  for (i=1; i<=CLIENT_MAX; i++) {
+    if (i == my_id) {
+      send_packet(i, MODE_WAIT, i, 0, NULL);
+    }
+    linda_seq[i] = psx_rd(i);
+  }
+  psx_sync_n();
+
+  if (my_id == PLAYER_1P) {
+    sche_func = &linda_sche_wait0;
+  } else {
+    sche_func = &linda_sche_wait1;
+  }
+  send_packet(game->play_id, MODE_WAIT, 1, 1, NULL);
+
+  return my_id;
+}
--- a/main.c	Thu Jun 02 17:26:21 2011 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,19 +0,0 @@
-#include <stdio.h>
-#include "game.h"
-#include "libps2.h"
-#include "ps2util.h"
-
-FILE *main_fp;
-
-int
-main(int argc, char* argv[])
-{
-  main_fp = fopen("/dev/stdout", "w");
-  if (!main_fp) {
-    perror("main");
-  }
-
-  game_main();
-  ps2util_graphic_Finish();
-  return 0;
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cc	Thu Jun 02 17:51:41 2011 +0900
@@ -0,0 +1,19 @@
+#include <stdio.h>
+#include "game.h"
+#include "libps2.h"
+#include "ps2util.h"
+
+FILE *main_fp;
+
+int
+main(int argc, char* argv[])
+{
+  main_fp = fopen("/dev/stdout", "w");
+  if (!main_fp) {
+    perror("main");
+  }
+
+  game_main();
+  ps2util_graphic_Finish();
+  return 0;
+}
--- a/mytype.c	Thu Jun 02 17:26:21 2011 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,54 +0,0 @@
-/*  mytype.c */
-
-#include <time.h>
-#include <stdio.h>
-#include <stdbool.h>
-#include "libps2.h"
-#include "ps2util.h"
-#include "mytype.h"
-
-static clock_t start;
-static clock_t race_start;
-
-void
-wait_init()
-{
-  start = clock();
-}
-
-/*
- * wait_init()から
- * time秒(マイクロ秒?)すぎたらTRUEを返す
- */
-bool
-wait(double time)
-{
-  clock_t t;
-  double a;
-
-  t = clock();
-  a = (t-start)/(double)CLOCKS_PER_SEC;
-  if (a > time) {
-    return true;
-  }
-
-  return false;
-}
-
-void
-time_RaceStart()
-{
-  race_start = clock();
-}
-
-double
-time_RaceTime()
-{
-  clock_t t;
-  double a;
-
-  t = clock();
-  a = (t-race_start)/(double)CLOCKS_PER_SEC;
-
-  return a;
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mytype.cc	Thu Jun 02 17:51:41 2011 +0900
@@ -0,0 +1,54 @@
+/*  mytype.c */
+
+#include <time.h>
+#include <stdio.h>
+#include <stdbool.h>
+#include "libps2.h"
+#include "ps2util.h"
+#include "mytype.h"
+
+static clock_t start;
+static clock_t race_start;
+
+void
+wait_init()
+{
+  start = clock();
+}
+
+/*
+ * wait_init()から
+ * time秒(マイクロ秒?)すぎたらTRUEを返す
+ */
+bool
+wait(double time)
+{
+  clock_t t;
+  double a;
+
+  t = clock();
+  a = (t-start)/(double)CLOCKS_PER_SEC;
+  if (a > time) {
+    return true;
+  }
+
+  return false;
+}
+
+void
+time_RaceStart()
+{
+  race_start = clock();
+}
+
+double
+time_RaceTime()
+{
+  clock_t t;
+  double a;
+
+  t = clock();
+  a = (t-race_start)/(double)CLOCKS_PER_SEC;
+
+  return a;
+}
--- a/ps2util.c	Thu Jun 02 17:26:21 2011 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,384 +0,0 @@
-/* ps2util.c */
-
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <math.h> 
-#include "libps2.h"
-#include "ps2util.h"
-
-/*
-  たぶん、本当は読み込んだ xml file から情報を取得するとかそんなんだと思う
-  どんな処理か分からないので、とりあえず、初期化している。
-*/
-
-OBJECT *ps2util_obj_Create_fromXML(char *filename)
-{
-  OBJECT *body;
-
-  /*
-  body->xyz = {0,0,0,0};
-  body->angle = {0,0,0,0};
-  body->transfer = { {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0} };
-  body->*name = filename;
-  body->*free_me = NULL;
-  */
-  
-  return body;
-}
-
-
-
-void ps2util_obj_Set_effect(OBJECT *body, int def)
-{
-  //none
-}
-
-// ベクトル v1 をベクトル v2 にコピーする
-void ps2_vu0_copy_vector(FVECTOR directionA, FVECTOR directionB)
-{
-  memcpy(directionA, directionB, sizeof(FVECTOR));
-}
-
-
-void ps2util_obj_Renew_transMatrix(OBJECT *car){
-  //none
-}
-
-
-/*
-  ps2 内の texture.c から
-*/
-TEXTURE* read_png_file(char *texname)
-{
-  printf("trace\n");  
-  //とりあえず戻り値を返してエラーをどうにか
-  TEXTURE* tex;
-  
-  return tex;
-}
-
-
-
-int ps2util_tex_Set(TEXTURE* tex)
-{
-  return -1;
-}
-
-int ps2util_sprite_Create(ps2utilSprite *Sp, TEXTURE *sprite_tex)
-{
-  return -1;
-}
-
-
-void ps2util_obj_Set_texture(OBJECT* car_body, TEXTURE *tex)
-{
-  //none
-}
-
-// 与えられた行列を単位行列に変換する
-void ps2_vu0_unit_matrix(FMATRIX m)
-{
-  m[0][1] = m[0][2] = m[0][3] = 0;
-  m[1][0] = m[1][2] = m[1][3] = 0;
-  m[2][0] = m[2][1] = m[2][3] = 0;
-  m[3][0] = m[3][1] = m[3][2] = 0;
-  m[0][0] = m[1][1] = m[2][2] = m[3][3] = 1.0;
-}
-
-/*
-Y軸を中心とした行列の回転 
-回転角 rx より X 軸を中心とした回転マトリックスを求めて、マトリックス m1 に左側から乗算して、その結果をマトリックス m0 に与える。 
-X 軸だけでなく Y 軸、Z 軸を中心とした関数もある。また3ついっんに回転させる関数もある。
-*/
-void ps2_vu0_rot_matrix_y(FMATRIX result, FMATRIX m, float radian)
-{
-  // 回転行列を作ってかけてやれば良い
-
-  m[0][1] = m[0][2] = m[0][3] = 0;
-  m[1][0] = m[1][2] = m[1][3] = 0;
-  m[2][0] = m[2][1] = m[2][3] = 0;
-  m[3][0] = m[3][1] = m[3][2] = 0;
-  m[0][0] = m[1][1] = m[2][2] = m[3][3] = 1.0;
-
-  
-  m[0][0] = sinf(radian);
-  m[2][2] = sinf(radian);
-  m[0][2] = -cosf(radian);
-  m[2][0] = cosf(radian);
-  
-  FMATRIX m1;// = m;
-  memcpy(&m1, m, sizeof(FMATRIX));
-
-  ps2_vu0_mul_matrix(result, m1, m);
-}
-
-// ベクトルの計算
-// マトリックス m にベクトル  を右から乗算して result に与える
-void ps2_vu0_apply_matrix(FVECTOR result, FMATRIX m, FVECTOR v)
-{
-  result[0] = m[0][0] * v[0] + m[0][1] * v[1] + m[0][2] * v[2] + m[0][3] * v[3] ;
-  result[1] = m[1][0] * v[0] + m[1][1] * v[1] + m[1][2] * v[2] + m[1][3] * v[3] ;
-  result[2] = m[2][0] * v[0] + m[2][1] * v[1] + m[2][2] * v[2] + m[2][3] * v[3] ;
-  result[3] = m[3][0] * v[0] + m[3][1] * v[1] + m[3][2] * v[2] + m[3][3] * v[3] ;
-}
-
-
-void ps2_vu0_scale_vector(FVECTOR mov, FVECTOR car_direction, float car_speed)
-{
-  mov[0] = car_direction[0] * car_speed ;
-  mov[1] = car_direction[1] * car_speed ;
-  mov[2] = car_direction[2] * car_speed ;
-  mov[3] = car_direction[3];
-}
-
-// ベクトル v1 の各要素とベクトル v2 の各要素を各々加算してv0に与える
-// v0 = v1+v2
-void ps2_vu0_add_vector(FVECTOR result, FVECTOR v0, FVECTOR v1)
-{
-  result[0] = v0[0] + v1[0];
-  result[1] = v0[1] + v1[1];
-  result[2] = v0[2] + v1[2];
-  //  result[3] = v0[3] + v1[3];
-  result[3] = v0[3];
-}
-
-// 外積
-void ps2_vu0_outer_product(FVECTOR result, FVECTOR v0, FVECTOR v1)
-{
-  result[0] = v0[1] * v1[2] - v0[2] * v1[1] ;
-  result[1] = v0[0] * v1[2] - v0[2] * v1[0] ;
-  result[2] = v0[0] * v1[1] - v0[1] * v1[0] ;
-  result[3] = 1;
-}
-
-// 内積
-float ps2_vu0_inner_product(FVECTOR v0, FVECTOR v1)
-{
-  return v0[0] * v1[0] + v0[1] * v1[1] + v0[2] * v1[2];
-}
-
-
-void ps2_vu0_mul_matrix(FMATRIX result, FMATRIX m0, FMATRIX m1)
-{
-  result[0][0] = m0[0][0] * m1[0][0] + m0[0][1] * m1[1][0] + m0[0][2] * m1[2][0] + m0[0][3] * m1[3][0];
-  result[0][1] = m0[0][0] * m1[0][1] + m0[0][1] * m1[1][1] + m0[0][2] * m1[2][1] + m0[0][3] * m1[3][1];
-  result[0][2] = m0[0][0] * m1[0][2] + m0[0][1] * m1[1][2] + m0[0][2] * m1[2][2] + m0[0][3] * m1[3][2];
-  result[0][3] = m0[0][0] * m1[0][3] + m0[0][1] * m1[1][3] + m0[0][2] * m1[2][3] + m0[0][3] * m1[3][3];
-
-  result[1][0] = m0[1][0] * m1[0][0] + m0[1][1] * m1[1][0] + m0[1][2] * m1[2][0] + m0[1][3] * m1[3][0];
-  result[1][1] = m0[1][0] * m1[0][1] + m0[1][1] * m1[1][1] + m0[1][2] * m1[2][1] + m0[1][3] * m1[3][1];
-  result[1][2] = m0[1][0] * m1[0][2] + m0[1][1] * m1[1][2] + m0[1][2] * m1[2][2] + m0[1][3] * m1[3][2];
-  result[1][3] = m0[1][0] * m1[0][3] + m0[1][1] * m1[1][3] + m0[1][2] * m1[2][3] + m0[1][3] * m1[3][3];
-
-  result[2][0] = m0[2][0] * m1[0][0] + m0[2][1] * m1[1][0] + m0[2][2] * m1[2][0] + m0[2][3] * m1[3][0];
-  result[2][1] = m0[2][0] * m1[0][1] + m0[2][1] * m1[1][1] + m0[2][2] * m1[2][1] + m0[2][3] * m1[3][1];
-  result[2][2] = m0[2][0] * m1[0][2] + m0[2][1] * m1[1][2] + m0[2][2] * m1[2][2] + m0[2][3] * m1[3][2];
-  result[2][3] = m0[2][0] * m1[0][3] + m0[2][1] * m1[1][3] + m0[2][2] * m1[2][3] + m0[2][3] * m1[3][3];
-
-  result[3][0] = m0[3][0] * m1[0][0] + m0[3][1] * m1[1][0] + m0[3][2] * m1[2][0] + m0[3][3] * m1[3][0];
-  result[3][1] = m0[3][0] * m1[0][1] + m0[3][1] * m1[1][1] + m0[3][2] * m1[2][1] + m0[3][3] * m1[3][1];
-  result[3][2] = m0[3][0] * m1[0][2] + m0[3][1] * m1[1][2] + m0[3][2] * m1[2][2] + m0[3][3] * m1[3][2];
-  result[3][3] = m0[3][0] * m1[0][3] + m0[3][1] * m1[1][3] + m0[3][2] * m1[2][3] + m0[3][3] * m1[3][3];
-}
-
-
-void ps2_vu0_copy_matrix(FMATRIX transfer, FMATRIX pose)
-{
-  memcpy(transfer, pose, sizeof(FMATRIX));
-}
-
-void ps2util_obj_Free(OBJECT* obj)
-{
-  free(obj);
-}
-
-
-
-void ps2_vu0_sub_vector(FVECTOR result, FVECTOR v0, FVECTOR v1)
-{
-  result[0] = v0[0] - v1[0];
-  result[1] = v0[1] - v1[1];
-  result[2] = v0[2] - v1[2];
-  result[3] = v0[3];// - v1[3];
-}
-
-
-
-void ps2_vu0_normalize(FVECTOR result, FVECTOR v)
-{
-  // 大きさで割ってるだけって
-  float d = sqrtf(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
-  result[0] = v[0] / d;
-  result[1] = v[1] / d;
-  result[2] = v[2] / d;
-  result[3] = 1;
-}
-
-
-void xml_free(PolygonInfo xml)
-{
-  //none
-}
-
-
-void ps2util_obj_Draw(OBJECT *object)
-{
-  //none
-}
-
-
-void  ps2util_sprite_Destroy(ps2utilSprite *title_sprite )
-{
-  //none
-}
-
-
-
-
-void ps2util_sprite_Set_basicAttribute(ps2utilSprite *p,
-	unsigned short x, unsigned short y,
-	unsigned short sptable_tw1, unsigned short sptable_th1,
-	unsigned short sptable_tx, unsigned short sptable_ty,
-	unsigned short sptable_tw2, unsigned short sptable_th2,
-	int sprite_prio_foreground)
-{
-  //none
-}
-
-void ps2util_sprite_Request(ps2utilSprite *p)
-{
-  //none
-}
-
-
-void ps2util_sprite_Unuse_alpha(ps2utilSprite *sp)
-{
-  //none
-}
-
-void ps2util_graphic_Init()
-{
-  //none
-}
-
-
-/*
-  ps2 依存関係の sprite.c より引用。
-*/
-#define SPRITE_HAS_4VERTEXIS 4
-
-#define PS2_GS_XYZ3 1 // なにかわからん定数だから適当に作りました
-
-void
-sprite_disappear( SPRITE* sprite )
-{
-  int i;
-  GsSpritePacket* packet = sprite->gs_packet;
-  for (i=0; i<SPRITE_HAS_4VERTEXIS; i++)
-    packet->primData[i].xyz_addr = PS2_GS_XYZ3;
-}
-
-
-
-
-/*
-  からの関数
-  ps2 依存関係にあったけど、( name_dictionary.c ) の中のもの
-  だけど、他にも持ってくるものが増えるので、とりあえず、からの関数に
-*/
-void delete_name_dictionary(const char *string)
-{
-  /*
-  int number;
-  NAME_DIC *dic_ptr;
-
-  if (string == NULL) return;
-
-  number = hash_func(string,NAME_HASH_SIZE);
-
-  for (dic_ptr=name_hash+number;dic_ptr->name;dic_ptr=name_hash+number) {
-    if (!strcmp(string,dic_ptr->name)) {
-      dic_ptr->ref_num--;
-      if (dic_ptr->ref_num == 0) {
-	free(dic_ptr->name);
-	dic_ptr->name = NULL;
-      }
-      return;
-    } else {
-      number += REHASH_NUM;
-      if (number > NAME_HASH_SIZE) number -= NAME_HASH_SIZE;
-    }
-  }
-  */
-}
-  
-
-
-/*
-  ps2 依存関係から持ってきた。
-  テクスチャに割り振ったメモリの解放処理?
-  元ファイル:texture.c
-*/
-void free_texture(TEXTURE *tex)
-{
-  if (tex == NULL) return;
-
-  delete_name_dictionary(tex->name);
-  free(tex->free_texenv);
-  free(tex->free_image);
-  free(tex);
-}
-
-
-/*
-  ps2 依存関係内の、texture.c から拝借
-  この malloc によるメモリ取得をあちこちで行っているっぽい
-  cerium にある。
-*/
-int malloc_align16(void *free, void *aligned, int size)
-{
-  char *index;
-  unsigned int *f=(unsigned int *)free,*a=(unsigned int *)aligned;
-
-  if (free == NULL || aligned == NULL || size <= 0) return(-1);
-
-  index = (char *)malloc(size + ALIGN_16BYTE);
-  if (index == NULL) {
-    return(-1);
-  }
-
-  *f = *a = (unsigned long int)index;
-  if (((unsigned long int)index % ALIGN_16BYTE) != 0) {
-    index += ALIGN_16BYTE - ((unsigned long int)index % ALIGN_16BYTE);
-    *a = (unsigned long int)index;
-  }
-
-  return(0);
-}
-
-
-
-// miya
-void ps2util_tex_Exclude( TEXTURE* t )
-{
-  char *miyahira;
-  miyahira = "なにこの関数?";
-}
-
-void ps2util_sprite_Draw()
-{
-  printf("ps2util_sprite_Draw()\n");
-}
-
-void ps2util_graphic_Finish()
-{
-  printf("ps2util_graphic_Finish()\n");
-}
-
-
-// title.cに書いてた
-void ps2util_sprite_Use_alpha( ps2utilSprite *title )
-{
-  printf("ps2util_sprite_Use_alpha()\n");
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ps2util.cc	Thu Jun 02 17:51:41 2011 +0900
@@ -0,0 +1,384 @@
+/* ps2util.c */
+
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h> 
+#include "libps2.h"
+#include "ps2util.h"
+
+/*
+  たぶん、本当は読み込んだ xml file から情報を取得するとかそんなんだと思う
+  どんな処理か分からないので、とりあえず、初期化している。
+*/
+
+OBJECT *ps2util_obj_Create_fromXML(char *filename)
+{
+  OBJECT *body;
+
+  /*
+  body->xyz = {0,0,0,0};
+  body->angle = {0,0,0,0};
+  body->transfer = { {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0} };
+  body->*name = filename;
+  body->*free_me = NULL;
+  */
+  
+  return body;
+}
+
+
+
+void ps2util_obj_Set_effect(OBJECT *body, int def)
+{
+  //none
+}
+
+// ベクトル v1 をベクトル v2 にコピーする
+void ps2_vu0_copy_vector(FVECTOR directionA, FVECTOR directionB)
+{
+  memcpy(directionA, directionB, sizeof(FVECTOR));
+}
+
+
+void ps2util_obj_Renew_transMatrix(OBJECT *car){
+  //none
+}
+
+
+/*
+  ps2 内の texture.c から
+*/
+TEXTURE* read_png_file(char *texname)
+{
+  printf("trace\n");  
+  //とりあえず戻り値を返してエラーをどうにか
+  TEXTURE* tex;
+  
+  return tex;
+}
+
+
+
+int ps2util_tex_Set(TEXTURE* tex)
+{
+  return -1;
+}
+
+int ps2util_sprite_Create(ps2utilSprite *Sp, TEXTURE *sprite_tex)
+{
+  return -1;
+}
+
+
+void ps2util_obj_Set_texture(OBJECT* car_body, TEXTURE *tex)
+{
+  //none
+}
+
+// 与えられた行列を単位行列に変換する
+void ps2_vu0_unit_matrix(FMATRIX m)
+{
+  m[0][1] = m[0][2] = m[0][3] = 0;
+  m[1][0] = m[1][2] = m[1][3] = 0;
+  m[2][0] = m[2][1] = m[2][3] = 0;
+  m[3][0] = m[3][1] = m[3][2] = 0;
+  m[0][0] = m[1][1] = m[2][2] = m[3][3] = 1.0;
+}
+
+/*
+Y軸を中心とした行列の回転 
+回転角 rx より X 軸を中心とした回転マトリックスを求めて、マトリックス m1 に左側から乗算して、その結果をマトリックス m0 に与える。 
+X 軸だけでなく Y 軸、Z 軸を中心とした関数もある。また3ついっんに回転させる関数もある。
+*/
+void ps2_vu0_rot_matrix_y(FMATRIX result, FMATRIX m, float radian)
+{
+  // 回転行列を作ってかけてやれば良い
+
+  m[0][1] = m[0][2] = m[0][3] = 0;
+  m[1][0] = m[1][2] = m[1][3] = 0;
+  m[2][0] = m[2][1] = m[2][3] = 0;
+  m[3][0] = m[3][1] = m[3][2] = 0;
+  m[0][0] = m[1][1] = m[2][2] = m[3][3] = 1.0;
+
+  
+  m[0][0] = sinf(radian);
+  m[2][2] = sinf(radian);
+  m[0][2] = -cosf(radian);
+  m[2][0] = cosf(radian);
+  
+  FMATRIX m1;// = m;
+  memcpy(&m1, m, sizeof(FMATRIX));
+
+  ps2_vu0_mul_matrix(result, m1, m);
+}
+
+// ベクトルの計算
+// マトリックス m にベクトル  を右から乗算して result に与える
+void ps2_vu0_apply_matrix(FVECTOR result, FMATRIX m, FVECTOR v)
+{
+  result[0] = m[0][0] * v[0] + m[0][1] * v[1] + m[0][2] * v[2] + m[0][3] * v[3] ;
+  result[1] = m[1][0] * v[0] + m[1][1] * v[1] + m[1][2] * v[2] + m[1][3] * v[3] ;
+  result[2] = m[2][0] * v[0] + m[2][1] * v[1] + m[2][2] * v[2] + m[2][3] * v[3] ;
+  result[3] = m[3][0] * v[0] + m[3][1] * v[1] + m[3][2] * v[2] + m[3][3] * v[3] ;
+}
+
+
+void ps2_vu0_scale_vector(FVECTOR mov, FVECTOR car_direction, float car_speed)
+{
+  mov[0] = car_direction[0] * car_speed ;
+  mov[1] = car_direction[1] * car_speed ;
+  mov[2] = car_direction[2] * car_speed ;
+  mov[3] = car_direction[3];
+}
+
+// ベクトル v1 の各要素とベクトル v2 の各要素を各々加算してv0に与える
+// v0 = v1+v2
+void ps2_vu0_add_vector(FVECTOR result, FVECTOR v0, FVECTOR v1)
+{
+  result[0] = v0[0] + v1[0];
+  result[1] = v0[1] + v1[1];
+  result[2] = v0[2] + v1[2];
+  //  result[3] = v0[3] + v1[3];
+  result[3] = v0[3];
+}
+
+// 外積
+void ps2_vu0_outer_product(FVECTOR result, FVECTOR v0, FVECTOR v1)
+{
+  result[0] = v0[1] * v1[2] - v0[2] * v1[1] ;
+  result[1] = v0[0] * v1[2] - v0[2] * v1[0] ;
+  result[2] = v0[0] * v1[1] - v0[1] * v1[0] ;
+  result[3] = 1;
+}
+
+// 内積
+float ps2_vu0_inner_product(FVECTOR v0, FVECTOR v1)
+{
+  return v0[0] * v1[0] + v0[1] * v1[1] + v0[2] * v1[2];
+}
+
+
+void ps2_vu0_mul_matrix(FMATRIX result, FMATRIX m0, FMATRIX m1)
+{
+  result[0][0] = m0[0][0] * m1[0][0] + m0[0][1] * m1[1][0] + m0[0][2] * m1[2][0] + m0[0][3] * m1[3][0];
+  result[0][1] = m0[0][0] * m1[0][1] + m0[0][1] * m1[1][1] + m0[0][2] * m1[2][1] + m0[0][3] * m1[3][1];
+  result[0][2] = m0[0][0] * m1[0][2] + m0[0][1] * m1[1][2] + m0[0][2] * m1[2][2] + m0[0][3] * m1[3][2];
+  result[0][3] = m0[0][0] * m1[0][3] + m0[0][1] * m1[1][3] + m0[0][2] * m1[2][3] + m0[0][3] * m1[3][3];
+
+  result[1][0] = m0[1][0] * m1[0][0] + m0[1][1] * m1[1][0] + m0[1][2] * m1[2][0] + m0[1][3] * m1[3][0];
+  result[1][1] = m0[1][0] * m1[0][1] + m0[1][1] * m1[1][1] + m0[1][2] * m1[2][1] + m0[1][3] * m1[3][1];
+  result[1][2] = m0[1][0] * m1[0][2] + m0[1][1] * m1[1][2] + m0[1][2] * m1[2][2] + m0[1][3] * m1[3][2];
+  result[1][3] = m0[1][0] * m1[0][3] + m0[1][1] * m1[1][3] + m0[1][2] * m1[2][3] + m0[1][3] * m1[3][3];
+
+  result[2][0] = m0[2][0] * m1[0][0] + m0[2][1] * m1[1][0] + m0[2][2] * m1[2][0] + m0[2][3] * m1[3][0];
+  result[2][1] = m0[2][0] * m1[0][1] + m0[2][1] * m1[1][1] + m0[2][2] * m1[2][1] + m0[2][3] * m1[3][1];
+  result[2][2] = m0[2][0] * m1[0][2] + m0[2][1] * m1[1][2] + m0[2][2] * m1[2][2] + m0[2][3] * m1[3][2];
+  result[2][3] = m0[2][0] * m1[0][3] + m0[2][1] * m1[1][3] + m0[2][2] * m1[2][3] + m0[2][3] * m1[3][3];
+
+  result[3][0] = m0[3][0] * m1[0][0] + m0[3][1] * m1[1][0] + m0[3][2] * m1[2][0] + m0[3][3] * m1[3][0];
+  result[3][1] = m0[3][0] * m1[0][1] + m0[3][1] * m1[1][1] + m0[3][2] * m1[2][1] + m0[3][3] * m1[3][1];
+  result[3][2] = m0[3][0] * m1[0][2] + m0[3][1] * m1[1][2] + m0[3][2] * m1[2][2] + m0[3][3] * m1[3][2];
+  result[3][3] = m0[3][0] * m1[0][3] + m0[3][1] * m1[1][3] + m0[3][2] * m1[2][3] + m0[3][3] * m1[3][3];
+}
+
+
+void ps2_vu0_copy_matrix(FMATRIX transfer, FMATRIX pose)
+{
+  memcpy(transfer, pose, sizeof(FMATRIX));
+}
+
+void ps2util_obj_Free(OBJECT* obj)
+{
+  free(obj);
+}
+
+
+
+void ps2_vu0_sub_vector(FVECTOR result, FVECTOR v0, FVECTOR v1)
+{
+  result[0] = v0[0] - v1[0];
+  result[1] = v0[1] - v1[1];
+  result[2] = v0[2] - v1[2];
+  result[3] = v0[3];// - v1[3];
+}
+
+
+
+void ps2_vu0_normalize(FVECTOR result, FVECTOR v)
+{
+  // 大きさで割ってるだけって
+  float d = sqrtf(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
+  result[0] = v[0] / d;
+  result[1] = v[1] / d;
+  result[2] = v[2] / d;
+  result[3] = 1;
+}
+
+
+void xml_free(PolygonInfo xml)
+{
+  //none
+}
+
+
+void ps2util_obj_Draw(OBJECT *object)
+{
+  //none
+}
+
+
+void  ps2util_sprite_Destroy(ps2utilSprite *title_sprite )
+{
+  //none
+}
+
+
+
+
+void ps2util_sprite_Set_basicAttribute(ps2utilSprite *p,
+	unsigned short x, unsigned short y,
+	unsigned short sptable_tw1, unsigned short sptable_th1,
+	unsigned short sptable_tx, unsigned short sptable_ty,
+	unsigned short sptable_tw2, unsigned short sptable_th2,
+	int sprite_prio_foreground)
+{
+  //none
+}
+
+void ps2util_sprite_Request(ps2utilSprite *p)
+{
+  //none
+}
+
+
+void ps2util_sprite_Unuse_alpha(ps2utilSprite *sp)
+{
+  //none
+}
+
+void ps2util_graphic_Init()
+{
+  //none
+}
+
+
+/*
+  ps2 依存関係の sprite.c より引用。
+*/
+#define SPRITE_HAS_4VERTEXIS 4
+
+#define PS2_GS_XYZ3 1 // なにかわからん定数だから適当に作りました
+
+void
+sprite_disappear( SPRITE* sprite )
+{
+  int i;
+  GsSpritePacket* packet = sprite->gs_packet;
+  for (i=0; i<SPRITE_HAS_4VERTEXIS; i++)
+    packet->primData[i].xyz_addr = PS2_GS_XYZ3;
+}
+
+
+
+
+/*
+  からの関数
+  ps2 依存関係にあったけど、( name_dictionary.c ) の中のもの
+  だけど、他にも持ってくるものが増えるので、とりあえず、からの関数に
+*/
+void delete_name_dictionary(const char *string)
+{
+  /*
+  int number;
+  NAME_DIC *dic_ptr;
+
+  if (string == NULL) return;
+
+  number = hash_func(string,NAME_HASH_SIZE);
+
+  for (dic_ptr=name_hash+number;dic_ptr->name;dic_ptr=name_hash+number) {
+    if (!strcmp(string,dic_ptr->name)) {
+      dic_ptr->ref_num--;
+      if (dic_ptr->ref_num == 0) {
+	free(dic_ptr->name);
+	dic_ptr->name = NULL;
+      }
+      return;
+    } else {
+      number += REHASH_NUM;
+      if (number > NAME_HASH_SIZE) number -= NAME_HASH_SIZE;
+    }
+  }
+  */
+}
+  
+
+
+/*
+  ps2 依存関係から持ってきた。
+  テクスチャに割り振ったメモリの解放処理?
+  元ファイル:texture.c
+*/
+void free_texture(TEXTURE *tex)
+{
+  if (tex == NULL) return;
+
+  delete_name_dictionary(tex->name);
+  free(tex->free_texenv);
+  free(tex->free_image);
+  free(tex);
+}
+
+
+/*
+  ps2 依存関係内の、texture.c から拝借
+  この malloc によるメモリ取得をあちこちで行っているっぽい
+  cerium にある。
+*/
+int malloc_align16(void *free, void *aligned, int size)
+{
+  char *index;
+  unsigned int *f=(unsigned int *)free,*a=(unsigned int *)aligned;
+
+  if (free == NULL || aligned == NULL || size <= 0) return(-1);
+
+  index = (char *)malloc(size + ALIGN_16BYTE);
+  if (index == NULL) {
+    return(-1);
+  }
+
+  *f = *a = (unsigned long int)index;
+  if (((unsigned long int)index % ALIGN_16BYTE) != 0) {
+    index += ALIGN_16BYTE - ((unsigned long int)index % ALIGN_16BYTE);
+    *a = (unsigned long int)index;
+  }
+
+  return(0);
+}
+
+
+
+// miya
+void ps2util_tex_Exclude( TEXTURE* t )
+{
+  char *miyahira;
+  miyahira = "なにこの関数?";
+}
+
+void ps2util_sprite_Draw()
+{
+  printf("ps2util_sprite_Draw()\n");
+}
+
+void ps2util_graphic_Finish()
+{
+  printf("ps2util_graphic_Finish()\n");
+}
+
+
+// title.cに書いてた
+void ps2util_sprite_Use_alpha( ps2utilSprite *title )
+{
+  printf("ps2util_sprite_Use_alpha()\n");
+}
--- a/quotanion.c	Thu Jun 02 17:26:21 2011 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,53 +0,0 @@
-#include"libps2.h"
-#include<math.h>
-#include"mytype.h"
-
-/*---------------------------
-  クォータニオンを求める
-  axis  : 回転軸方向の単位ベクトル
-  angle : 回転量
-  ---------------------------*/
-void
-quotanion(FVECTOR q, FVECTOR axis, float angle)
-{
-      float s=sin(angle/2);
-      q[0] = axis[0]*s;
-      q[1] = axis[1]*s;
-      q[2] = axis[2]*s;
-      q[3] = cos(angle/2);
-}
-
-/*-----------------------
-  クォータニオンqから
-  変換行列rotを生成する
-  -----------------------*/
-void
-quotanion_rotmatrix(FMATRIX rot, FVECTOR q)
-{
-    rot[0][0] = q[3]*q[3] + q[0]*q[0] - q[1]*q[1] - q[2]*q[2];
-    rot[0][1] = 2*(q[0]*q[1] - q[3]*q[2]);
-    rot[0][2] = 2*(q[0]*q[2] + q[3]*q[1]);
-    rot[0][3] = 0;
-    rot[1][0] = 2*(q[0]*q[1] + q[3]*q[2]);
-    rot[1][1] = q[3]*q[3] - q[0]*q[0] + q[1]*q[1] - q[2]*q[2];
-    rot[1][2] = 2*(q[1]*q[2] - q[3]*q[0]);
-    rot[1][3] = 0;
-    rot[2][0] = 2*(q[0]*q[2] - q[3]*q[1]);
-    rot[2][1] = 2*(q[1]*q[2] + q[3]*q[0]);
-    rot[2][2] = q[3]*q[3] - q[0]*q[0] - q[1]*q[1] + q[2]*q[2];
-    rot[2][3] = 0;
-    rot[3][0] = 0;
-    rot[3][1] = 0;
-    rot[3][2] = 0;
-    rot[3][3] = 1;
-  
-}
-
-float
-degree2radian(float digree)
-{
-    float radian = digree * M_PI/180.0;
-    radian += (radian < -M_PI) ? 2*M_PI : 0;
-    radian += (radian > M_PI) ? -2*M_PI : 0;
-    return radian;
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/quotanion.cc	Thu Jun 02 17:51:41 2011 +0900
@@ -0,0 +1,53 @@
+#include"libps2.h"
+#include<math.h>
+#include"mytype.h"
+
+/*---------------------------
+  クォータニオンを求める
+  axis  : 回転軸方向の単位ベクトル
+  angle : 回転量
+  ---------------------------*/
+void
+quotanion(FVECTOR q, FVECTOR axis, float angle)
+{
+      float s=sin(angle/2);
+      q[0] = axis[0]*s;
+      q[1] = axis[1]*s;
+      q[2] = axis[2]*s;
+      q[3] = cos(angle/2);
+}
+
+/*-----------------------
+  クォータニオンqから
+  変換行列rotを生成する
+  -----------------------*/
+void
+quotanion_rotmatrix(FMATRIX rot, FVECTOR q)
+{
+    rot[0][0] = q[3]*q[3] + q[0]*q[0] - q[1]*q[1] - q[2]*q[2];
+    rot[0][1] = 2*(q[0]*q[1] - q[3]*q[2]);
+    rot[0][2] = 2*(q[0]*q[2] + q[3]*q[1]);
+    rot[0][3] = 0;
+    rot[1][0] = 2*(q[0]*q[1] + q[3]*q[2]);
+    rot[1][1] = q[3]*q[3] - q[0]*q[0] + q[1]*q[1] - q[2]*q[2];
+    rot[1][2] = 2*(q[1]*q[2] - q[3]*q[0]);
+    rot[1][3] = 0;
+    rot[2][0] = 2*(q[0]*q[2] - q[3]*q[1]);
+    rot[2][1] = 2*(q[1]*q[2] + q[3]*q[0]);
+    rot[2][2] = q[3]*q[3] - q[0]*q[0] - q[1]*q[1] + q[2]*q[2];
+    rot[2][3] = 0;
+    rot[3][0] = 0;
+    rot[3][1] = 0;
+    rot[3][2] = 0;
+    rot[3][3] = 1;
+  
+}
+
+float
+degree2radian(float digree)
+{
+    float radian = digree * M_PI/180.0;
+    radian += (radian < -M_PI) ? 2*M_PI : 0;
+    radian += (radian > M_PI) ? -2*M_PI : 0;
+    return radian;
+}
--- a/schedule.c	Thu Jun 02 17:26:21 2011 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,512 +0,0 @@
-/* schedule.c */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdbool.h>
-#include "libps2.h"
-#include "ps2util.h"
-#include "field.h"
-#include "car.h"
-#include "gSprite.h"
-#include "gFont.h"
-#include "game.h"
-#include "controler.h"
-#include "camera.h"
-#include "carNode.h"
-#include "light.h"
-#include "title_scene.h"
-#include "game_time.h"
-#include "schedule.h"
-#include "game.h"
-
-#include "mytype.h"
-#include "linda.h"
-
-#include "sjoy.h"
-
-#ifdef LINDA
-bool linda_update(int p, Game *game);
-#else
-#define linda_update(change_state, game) true
-#endif
-
-#define MAXCAR   3 // 選択可能機体
-#define MAXFIELD 2 // 選択可能コース
-#define MAXRAP   3 // ラップ数
-#define SP_SEL_CAR    50
-#define SP_SEL_COURSE 80
-
-// controler.cより
-extern SGO_PAD pad;
-
-
-static void set_schedule(Game *game);
-static void sche_game_init(Game *game);
-//static void sche_game_wait(Game *game); //プロトタイプも消しといた
-//static void sche_game_wait_ready(Game *game);
-static void sche_game_opening(Game *game);
-static void sche_game_select_car(Game *game);
-static void sche_game_select_course(Game *game);
-static void sche_game_ready(Game *game);
-static void sche_game_main_init(Game *game);
-static void sche_game_main_ready(Game *game);
-static void sche_game_main(Game *game);
-static void sche_game_main_pause(Game *game);
-static void sche_game_main_goal(Game *game);
-static void sche_game_main_finish(Game *game);
-static void sche_game_main_finish2(Game *game);
-
-
-
-/* timer */
-static int start_time,time_count;
-static int RUNNIG=0;
-char raptime[10];
-
-static int ranking = 0;
-static LIGHT l;
-static int i=0;
-
-static void (*sche_func_assumption)();
-static void (*sche_func)() = &sche_game_init;
-static int change_state = 0;
-
-// schedule.cで使用してる
-void linda_env_init( void );
-
-static void
-set_schedule_assumption(void *_func)
-{
-  sche_func_assumption = _func;
-  change_state = 1;
-}
-
-static void
-unset_schedule()
-{
-  change_state = 0;
-}
-
-static void
-set_schedule(Game *game)
-{
-  sche_func = sche_func_assumption;
-  change_state = 0;
-}
-
-static void
-graphic_init()
-{
-  gSprite_Init(); // グラフィック関連の初期化
-  gFont_Init();   // フォント関連の初期化
-}
-
-static void 
-play_init( Game *game )
-{
-  game->jiki = car_init(game->car_id);
-  carNode_append(game->jiki);
-  field_init(game->course_id);
-}
-
-// 適当に自作 :miya
-void linda_env_init( void )
-{
-  printf("linda_env_init\n");
-}
-
-static void game_env_init ( Game *game )
-{
-  game->car_id      = 1;
-  game->course_id   = 1;
-  game->camera_type = 0;
-  game->rap         = 1;
-  game->jiki        = NULL;
-
-  ranking = 0;
-
-  wait_init();
-  linda_env_init();
-}
-
-
-
-void
-sche_game_init(Game *game)
-{
-  game_env_init(game);
-  graphic_init();
-  camera_init();
-
-#ifdef LINDA
-  //sche_func = &sche_game_wait;
-  //set_schedule_assumption(sche_game_wait);
-#else
-  set_schedule_assumption(sche_game_opening);
-#endif
-}
-
-/**
- * 通信対戦専用
- * 全ユーザが接続するまで待つ
- * ・・・だったんだけど、現在 linda を切っているため worning が出る。
- * ので cut する。
- */
-
-/* linda を使用しないのでカットした
-static void
-sche_game_wait(Game *game)
-{
-  gFont_SetString("WAITING...", 200, 100);
-  set_schedule_assumption(sche_game_wait_ready);
-}
-*/
-
-
-/**
- * 通信対戦専用
- * 全ユーザの接続を確認したら呼び出す
- * こいつも、linda がないので cut
-*/ 
- /*
-static void
-sche_game_wait_ready(Game *game)
-{
-  gFont_SetString("CONNECT OK!!", 170, 300);
-  if (game->play_id == 1) {
-    gFont_SetString(" PUSH START ", 170, 400);
-    if (pad.st != 1) { goto WAIT_READY; }
-  }
-
-  set_schedule_assumption(sche_game_opening);
-    
- WAIT_READY:
-  return;
-}
- */
-
-
-void
-sche_game_opening(Game *game)
-{
-  static int blink_count = 0;
-  if (game->play_id==1){
-    if (blink_count < 35) {
-      gFont_SetString("PUSH START !!", 170, 380);
-    }
-    blink_count = (blink_count > 70) ? 0 : blink_count + 1;
-
-    if (pad.st != 1) { goto OPENING; }
-  }
-
-    
-  set_schedule_assumption(sche_game_select_car);
-
- OPENING:
-  return;
-
-
-  if (game->play_id == 1) {
-    if (title_scene() < 0){
-    }
-  } else if (game->play_id == 2) {
-    if (i==0){
-      title_init_call();
-      i=1;
-    }
-  }
-
-
-}
-
-void
-sche_game_select_car(Game *game)
-{
-  if (i==1){
-    title_finish_call();
-    i=2;
-  }
-  gSprite_PutSpriteEx(SP_SEL_CAR+game->car_id, 190, 200, 1.5, 1.5);
-  gSprite_PutSprite(24, 460, 300);
-  gSprite_PutSprite(25, 120, 300);
-  gFont_SetString("SELECT CAR", 180, 50);
- 
-  if (pad.right == 1) {
-    game->car_id =
-      (game->car_id > MAXCAR-1) ? 1 : game->car_id + 1;
-  }
-  if (pad.left == 1) {
-    game->car_id =
-      (game->car_id < 2) ? MAXCAR : game->car_id - 1;
-  }
-
-  if (game->play_id == 1)
-    if (pad.circle != 1) { goto SELECT_CAR; }
- 
-    
-  set_schedule_assumption(sche_game_select_course);
-    
- SELECT_CAR:
-  return;
-}
-
-void
-sche_game_select_course(Game *game)
-{
-  gSprite_PutSpriteEx(SP_SEL_COURSE+game->course_id, 190, 200, 1.7, 1.8);
-  gSprite_PutSprite(24, 460, 300);
-  gSprite_PutSprite(25, 120, 300);
-
-  gFont_SetString("SELECT COURSE", 150, 50);
-
-  if (game->play_id == 1) {
-    if (pad.right == 1) {
-      game->course_id =
-	(game->course_id > MAXFIELD-1) ? 1 : game->course_id + 1;
-      goto SELECT_COURSE;
-    }
-    if (pad.left == 1) {
-      game->course_id =
-	(game->course_id < 2) ? MAXFIELD : game->course_id - 1;
-      goto SELECT_COURSE;
-    }
-
-    if (pad.circle != 1) { goto SELECT_COURSE; }
-  }
-
-  set_schedule_assumption(sche_game_ready);
-
- SELECT_COURSE:
-  return;
-
-}
-
-void
-sche_game_ready(Game *game)
-{
-  static int blink_count = 0;//
-
-  gSprite_PutSprite(27+game->play_id,265,10);
-  gSprite_PutSpriteEx(SP_SEL_CAR+game->car_id, 50, 120, 1.5, 1.5);
-  gSprite_PutSpriteEx(SP_SEL_COURSE+game->course_id, 340, 120, 1.7, 1.8);
-	
-  /* 点滅 */
-  if (blink_count < 35) {
-    gFont_SetString("GAME START !!", 170, 380);
-  }
-  blink_count = (blink_count > 70) ? 0 : blink_count + 1;
-
-  set_schedule_assumption(sche_game_main_init);
-
-
-  if (pad.st == 1) {
-    set_schedule_assumption(sche_game_main_init);
-  }
-  if (pad.cross > 0) {
-    set_schedule_assumption(sche_game_select_car);
-  }
-
-}
-
-void
-sche_game_main_init(Game *game)
-{
-  if (!game->jiki)
-    play_init(game);
-  RUNNIG=0;
-
-  set_schedule_assumption(sche_game_main_ready);
-}
-
-static void
-sche_game_main_ready(Game *game)
-{
-  gFont_SetString("Loading....", 180, 100);
-  set_schedule_assumption(sche_game_main);
-}
-
-static void
-sche_game_main(Game *game)
-{
-  /** begin: dispaly RAP TIME **/
-  if(RUNNIG==0){
-    start_time = game_time_get_msec();
-    RUNNIG=1;
-  }
-
-  time_count = game_time_get_msec() - start_time;
-  game_time_set_raptime(raptime,time_count);
-  gFont_SetString("TIME",300,20);
-  gFont_SetString(raptime,400,20);
-  /** end: dispaly RAP TIME **/
-
-  // light_init と init_lightの書き間違え?
-  init_light(&l);
-  set_light(&l);
-    
-  car_id_update(game, game->jiki);
-
-  field_update(game->jiki);
-  camera_update(game,game->jiki->body->transfer);
-  carNode_draw();
-
-  gFont_SetStringInt(game->rap, 50, 100);
-
-  /* スピードメーター */
-  gSprite_DefSprite(23, 1, 1,(int)(106.0*(game->jiki->speed/game->jiki->speed_max)), 34);
-  gSprite_PutSprite(23, 400, 400);
-  /* km/h */
-  gSprite_PutSprite(26, 470, 350);
-  /* Rap */
-  gSprite_PutSprite(27, 80, 100);
-
-  if (game->rap > MAXRAP) {
-    ranking = 1;
-    set_schedule_assumption(sche_game_main_goal);
-  }
-
-  gFont_SetStringInt((int)(100.0*game->jiki->speed), 380, 350);
-
-  
-  if ((pad.right > 0) && ((game->jiki->speed != 0) || (pad.circle > 0))) {
-    car_swerve(game->jiki, 1);
-  }
-  if ((pad.left > 0) && ((game->jiki->speed != 0) || (pad.circle > 0))) {
-    car_swerve(game->jiki, -1);
-  }
-  if (pad.circle > 0) {
-    car_accelerate(game->jiki, 1);
-  }
-  if (pad.cross > 0) {
-    car_accelerate(game->jiki, -1);
-  }
-
-  if (pad.r1 == 1) {
-    game->camera_type = !game->camera_type;
-  }
-  if (pad.st == 1) {
-    set_schedule_assumption(sche_game_main_pause);
-  }
-
-}
-
-
-void
-sche_game_main_pause(Game *game)
-{
-  static int select = 0;
-
-  field_update(game->jiki);
-  carNode_draw();
-      
-  if (game->play_id == 1) {
-    // 選択マーク 
-    gSprite_PutSprite(17, 100, 190+select*100);
-	
-    gFont_SetString("BACK TO GAME", 200, 200);
-    gFont_SetString("GO TO TITLE",  200, 300);
-  } else {
-    gFont_SetString("Pause ...", 200, 200);
-  }
-
-    
-  if (pad.circle == 1) {
-    if (select == 0) {
-      set_schedule_assumption(sche_game_main);
-    } else {
-      set_schedule_assumption(sche_game_main_finish);
-    }
-  } else if (pad.st == 1) {
-    set_schedule_assumption(sche_game_main);
-  } else if (pad.up == 1 || pad.down == 1) {
-    select = !select;
-  }
-   
-}
-
-
-void
-sche_game_main_goal(Game *game)
-{
-  /** dispaly TOTAL TIME **/ 
-  game_time_set_raptime(raptime,time_count);
-
-  gFont_SetString("TOTAL TIME",150,20);
-  gFont_SetString(raptime,400,20);
-  gFont_SetString("GOAL !!", 220, 150);
-
-#ifdef LINDA
-  if (ranking == 1)
-    gFont_SetString("You WIN!!", 200, 250);
-  else
-    gFont_SetString("You Lose...", 200, 250);
-#endif
-
-
-  // 宣言では引数が二つだったから、第一引数に game を入れてみた
-  car_update(game, game->jiki);
-  field_update(game->jiki);
-  carNode_draw();
-  camera_update(game,game->jiki->body->transfer);
-    
-  if (pad.st == 1) {
-    set_schedule_assumption(sche_game_main_finish);
-  }
-    
-}
-
-void
-sche_game_main_finish(Game *game)
-{
-  field_destroy();
-  carNode_destroy();
-  game_env_init(game);
-
-  set_schedule_assumption(sche_game_main_finish2);
-}
-
-void
-sche_game_main_finish2(Game *game)
-{
-  gFont_SetString("GAME OVER ...", 200, 200);
-
-
-  if (pad.st == 1) {
-    set_schedule_assumption(sche_game_opening);
-  }
-
-}
-
-// 適当に作りました
-void wait_sync(Game *game)
-{
-  printf("wait_sync\n");
-}
-
-// 適当に
-void swap_dbuff()
-{
-  printf("swap_dbuff()\n");
-}
-
-void
-schedule(Game *game)
-{
-  sche_func(game);
-
-  if (linda_update(change_state, game) == true){
-    set_schedule(game);
-  }
-  else{
-    unset_schedule();
-  }
-
-  wait_sync(game);
-  swap_dbuff();
-  sjoy_poll();
-    
-  ps2util_sprite_Draw();
-  gSprite_Draw_Reset();
-  gFont_Draw_Reset();
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/schedule.cc	Thu Jun 02 17:51:41 2011 +0900
@@ -0,0 +1,512 @@
+/* schedule.c */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdbool.h>
+#include "libps2.h"
+#include "ps2util.h"
+#include "field.h"
+#include "car.h"
+#include "gSprite.h"
+#include "gFont.h"
+#include "game.h"
+#include "controler.h"
+#include "camera.h"
+#include "carNode.h"
+#include "light.h"
+#include "title_scene.h"
+#include "game_time.h"
+#include "schedule.h"
+#include "game.h"
+
+#include "mytype.h"
+#include "linda.h"
+
+#include "sjoy.h"
+
+#ifdef LINDA
+bool linda_update(int p, Game *game);
+#else
+#define linda_update(change_state, game) true
+#endif
+
+#define MAXCAR   3 // 選択可能機体
+#define MAXFIELD 2 // 選択可能コース
+#define MAXRAP   3 // ラップ数
+#define SP_SEL_CAR    50
+#define SP_SEL_COURSE 80
+
+// controler.cより
+extern SGO_PAD pad;
+
+
+static void set_schedule(Game *game);
+static void sche_game_init(Game *game);
+//static void sche_game_wait(Game *game); //プロトタイプも消しといた
+//static void sche_game_wait_ready(Game *game);
+static void sche_game_opening(Game *game);
+static void sche_game_select_car(Game *game);
+static void sche_game_select_course(Game *game);
+static void sche_game_ready(Game *game);
+static void sche_game_main_init(Game *game);
+static void sche_game_main_ready(Game *game);
+static void sche_game_main(Game *game);
+static void sche_game_main_pause(Game *game);
+static void sche_game_main_goal(Game *game);
+static void sche_game_main_finish(Game *game);
+static void sche_game_main_finish2(Game *game);
+
+
+
+/* timer */
+static int start_time,time_count;
+static int RUNNIG=0;
+char raptime[10];
+
+static int ranking = 0;
+static LIGHT l;
+static int i=0;
+
+static void (*sche_func_assumption)();
+static void (*sche_func)() = &sche_game_init;
+static int change_state = 0;
+
+// schedule.cで使用してる
+void linda_env_init( void );
+
+static void
+set_schedule_assumption(void *_func)
+{
+  sche_func_assumption = _func;
+  change_state = 1;
+}
+
+static void
+unset_schedule()
+{
+  change_state = 0;
+}
+
+static void
+set_schedule(Game *game)
+{
+  sche_func = sche_func_assumption;
+  change_state = 0;
+}
+
+static void
+graphic_init()
+{
+  gSprite_Init(); // グラフィック関連の初期化
+  gFont_Init();   // フォント関連の初期化
+}
+
+static void 
+play_init( Game *game )
+{
+  game->jiki = car_init(game->car_id);
+  carNode_append(game->jiki);
+  field_init(game->course_id);
+}
+
+// 適当に自作 :miya
+void linda_env_init( void )
+{
+  printf("linda_env_init\n");
+}
+
+static void game_env_init ( Game *game )
+{
+  game->car_id      = 1;
+  game->course_id   = 1;
+  game->camera_type = 0;
+  game->rap         = 1;
+  game->jiki        = NULL;
+
+  ranking = 0;
+
+  wait_init();
+  linda_env_init();
+}
+
+
+
+void
+sche_game_init(Game *game)
+{
+  game_env_init(game);
+  graphic_init();
+  camera_init();
+
+#ifdef LINDA
+  //sche_func = &sche_game_wait;
+  //set_schedule_assumption(sche_game_wait);
+#else
+  set_schedule_assumption(sche_game_opening);
+#endif
+}
+
+/**
+ * 通信対戦専用
+ * 全ユーザが接続するまで待つ
+ * ・・・だったんだけど、現在 linda を切っているため worning が出る。
+ * ので cut する。
+ */
+
+/* linda を使用しないのでカットした
+static void
+sche_game_wait(Game *game)
+{
+  gFont_SetString("WAITING...", 200, 100);
+  set_schedule_assumption(sche_game_wait_ready);
+}
+*/
+
+
+/**
+ * 通信対戦専用
+ * 全ユーザの接続を確認したら呼び出す
+ * こいつも、linda がないので cut
+*/ 
+ /*
+static void
+sche_game_wait_ready(Game *game)
+{
+  gFont_SetString("CONNECT OK!!", 170, 300);
+  if (game->play_id == 1) {
+    gFont_SetString(" PUSH START ", 170, 400);
+    if (pad.st != 1) { goto WAIT_READY; }
+  }
+
+  set_schedule_assumption(sche_game_opening);
+    
+ WAIT_READY:
+  return;
+}
+ */
+
+
+void
+sche_game_opening(Game *game)
+{
+  static int blink_count = 0;
+  if (game->play_id==1){
+    if (blink_count < 35) {
+      gFont_SetString("PUSH START !!", 170, 380);
+    }
+    blink_count = (blink_count > 70) ? 0 : blink_count + 1;
+
+    if (pad.st != 1) { goto OPENING; }
+  }
+
+    
+  set_schedule_assumption(sche_game_select_car);
+
+ OPENING:
+  return;
+
+
+  if (game->play_id == 1) {
+    if (title_scene() < 0){
+    }
+  } else if (game->play_id == 2) {
+    if (i==0){
+      title_init_call();
+      i=1;
+    }
+  }
+
+
+}
+
+void
+sche_game_select_car(Game *game)
+{
+  if (i==1){
+    title_finish_call();
+    i=2;
+  }
+  gSprite_PutSpriteEx(SP_SEL_CAR+game->car_id, 190, 200, 1.5, 1.5);
+  gSprite_PutSprite(24, 460, 300);
+  gSprite_PutSprite(25, 120, 300);
+  gFont_SetString("SELECT CAR", 180, 50);
+ 
+  if (pad.right == 1) {
+    game->car_id =
+      (game->car_id > MAXCAR-1) ? 1 : game->car_id + 1;
+  }
+  if (pad.left == 1) {
+    game->car_id =
+      (game->car_id < 2) ? MAXCAR : game->car_id - 1;
+  }
+
+  if (game->play_id == 1)
+    if (pad.circle != 1) { goto SELECT_CAR; }
+ 
+    
+  set_schedule_assumption(sche_game_select_course);
+    
+ SELECT_CAR:
+  return;
+}
+
+void
+sche_game_select_course(Game *game)
+{
+  gSprite_PutSpriteEx(SP_SEL_COURSE+game->course_id, 190, 200, 1.7, 1.8);
+  gSprite_PutSprite(24, 460, 300);
+  gSprite_PutSprite(25, 120, 300);
+
+  gFont_SetString("SELECT COURSE", 150, 50);
+
+  if (game->play_id == 1) {
+    if (pad.right == 1) {
+      game->course_id =
+	(game->course_id > MAXFIELD-1) ? 1 : game->course_id + 1;
+      goto SELECT_COURSE;
+    }
+    if (pad.left == 1) {
+      game->course_id =
+	(game->course_id < 2) ? MAXFIELD : game->course_id - 1;
+      goto SELECT_COURSE;
+    }
+
+    if (pad.circle != 1) { goto SELECT_COURSE; }
+  }
+
+  set_schedule_assumption(sche_game_ready);
+
+ SELECT_COURSE:
+  return;
+
+}
+
+void
+sche_game_ready(Game *game)
+{
+  static int blink_count = 0;//
+
+  gSprite_PutSprite(27+game->play_id,265,10);
+  gSprite_PutSpriteEx(SP_SEL_CAR+game->car_id, 50, 120, 1.5, 1.5);
+  gSprite_PutSpriteEx(SP_SEL_COURSE+game->course_id, 340, 120, 1.7, 1.8);
+	
+  /* 点滅 */
+  if (blink_count < 35) {
+    gFont_SetString("GAME START !!", 170, 380);
+  }
+  blink_count = (blink_count > 70) ? 0 : blink_count + 1;
+
+  set_schedule_assumption(sche_game_main_init);
+
+
+  if (pad.st == 1) {
+    set_schedule_assumption(sche_game_main_init);
+  }
+  if (pad.cross > 0) {
+    set_schedule_assumption(sche_game_select_car);
+  }
+
+}
+
+void
+sche_game_main_init(Game *game)
+{
+  if (!game->jiki)
+    play_init(game);
+  RUNNIG=0;
+
+  set_schedule_assumption(sche_game_main_ready);
+}
+
+static void
+sche_game_main_ready(Game *game)
+{
+  gFont_SetString("Loading....", 180, 100);
+  set_schedule_assumption(sche_game_main);
+}
+
+static void
+sche_game_main(Game *game)
+{
+  /** begin: dispaly RAP TIME **/
+  if(RUNNIG==0){
+    start_time = game_time_get_msec();
+    RUNNIG=1;
+  }
+
+  time_count = game_time_get_msec() - start_time;
+  game_time_set_raptime(raptime,time_count);
+  gFont_SetString("TIME",300,20);
+  gFont_SetString(raptime,400,20);
+  /** end: dispaly RAP TIME **/
+
+  // light_init と init_lightの書き間違え?
+  init_light(&l);
+  set_light(&l);
+    
+  car_id_update(game, game->jiki);
+
+  field_update(game->jiki);
+  camera_update(game,game->jiki->body->transfer);
+  carNode_draw();
+
+  gFont_SetStringInt(game->rap, 50, 100);
+
+  /* スピードメーター */
+  gSprite_DefSprite(23, 1, 1,(int)(106.0*(game->jiki->speed/game->jiki->speed_max)), 34);
+  gSprite_PutSprite(23, 400, 400);
+  /* km/h */
+  gSprite_PutSprite(26, 470, 350);
+  /* Rap */
+  gSprite_PutSprite(27, 80, 100);
+
+  if (game->rap > MAXRAP) {
+    ranking = 1;
+    set_schedule_assumption(sche_game_main_goal);
+  }
+
+  gFont_SetStringInt((int)(100.0*game->jiki->speed), 380, 350);
+
+  
+  if ((pad.right > 0) && ((game->jiki->speed != 0) || (pad.circle > 0))) {
+    car_swerve(game->jiki, 1);
+  }
+  if ((pad.left > 0) && ((game->jiki->speed != 0) || (pad.circle > 0))) {
+    car_swerve(game->jiki, -1);
+  }
+  if (pad.circle > 0) {
+    car_accelerate(game->jiki, 1);
+  }
+  if (pad.cross > 0) {
+    car_accelerate(game->jiki, -1);
+  }
+
+  if (pad.r1 == 1) {
+    game->camera_type = !game->camera_type;
+  }
+  if (pad.st == 1) {
+    set_schedule_assumption(sche_game_main_pause);
+  }
+
+}
+
+
+void
+sche_game_main_pause(Game *game)
+{
+  static int select = 0;
+
+  field_update(game->jiki);
+  carNode_draw();
+      
+  if (game->play_id == 1) {
+    // 選択マーク 
+    gSprite_PutSprite(17, 100, 190+select*100);
+	
+    gFont_SetString("BACK TO GAME", 200, 200);
+    gFont_SetString("GO TO TITLE",  200, 300);
+  } else {
+    gFont_SetString("Pause ...", 200, 200);
+  }
+
+    
+  if (pad.circle == 1) {
+    if (select == 0) {
+      set_schedule_assumption(sche_game_main);
+    } else {
+      set_schedule_assumption(sche_game_main_finish);
+    }
+  } else if (pad.st == 1) {
+    set_schedule_assumption(sche_game_main);
+  } else if (pad.up == 1 || pad.down == 1) {
+    select = !select;
+  }
+   
+}
+
+
+void
+sche_game_main_goal(Game *game)
+{
+  /** dispaly TOTAL TIME **/ 
+  game_time_set_raptime(raptime,time_count);
+
+  gFont_SetString("TOTAL TIME",150,20);
+  gFont_SetString(raptime,400,20);
+  gFont_SetString("GOAL !!", 220, 150);
+
+#ifdef LINDA
+  if (ranking == 1)
+    gFont_SetString("You WIN!!", 200, 250);
+  else
+    gFont_SetString("You Lose...", 200, 250);
+#endif
+
+
+  // 宣言では引数が二つだったから、第一引数に game を入れてみた
+  car_update(game, game->jiki);
+  field_update(game->jiki);
+  carNode_draw();
+  camera_update(game,game->jiki->body->transfer);
+    
+  if (pad.st == 1) {
+    set_schedule_assumption(sche_game_main_finish);
+  }
+    
+}
+
+void
+sche_game_main_finish(Game *game)
+{
+  field_destroy();
+  carNode_destroy();
+  game_env_init(game);
+
+  set_schedule_assumption(sche_game_main_finish2);
+}
+
+void
+sche_game_main_finish2(Game *game)
+{
+  gFont_SetString("GAME OVER ...", 200, 200);
+
+
+  if (pad.st == 1) {
+    set_schedule_assumption(sche_game_opening);
+  }
+
+}
+
+// 適当に作りました
+void wait_sync(Game *game)
+{
+  printf("wait_sync\n");
+}
+
+// 適当に
+void swap_dbuff()
+{
+  printf("swap_dbuff()\n");
+}
+
+void
+schedule(Game *game)
+{
+  sche_func(game);
+
+  if (linda_update(change_state, game) == true){
+    set_schedule(game);
+  }
+  else{
+    unset_schedule();
+  }
+
+  wait_sync(game);
+  swap_dbuff();
+  sjoy_poll();
+    
+  ps2util_sprite_Draw();
+  gSprite_Draw_Reset();
+  gFont_Draw_Reset();
+}
--- a/schedule.h	Thu Jun 02 17:26:21 2011 +0900
+++ b/schedule.h	Thu Jun 02 17:51:41 2011 +0900
@@ -5,7 +5,7 @@
 #endif
 
 // game.hからここに移動
-void schedule();
+void schedule(Game *game);
 
 // car.hから。 
 void car_update( Game *game, CarPtr car );
--- a/sjoy.c	Thu Jun 02 17:26:21 2011 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,144 +0,0 @@
-// Copyright(C) 2001 Sony Computer Entertainment Inc. All Rights Reserved.
-//
-// "sjoy.c"
-//
-//
-#include <stdio.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <assert.h>
-
-
-#include "sjoy.h"
-
-#define N_JOY   2
-
-static char *g_devName[N_JOY] = {
-  "/dev/js0",
-  "/dev/js1",
-};
-
-static int g_fd[N_JOY] = {
-  -1, -1,
-};
-
-//static __u32 g_button[N_JOY];   // max 32 buttons per joystick
-//static __s16 g_axis[N_JOY][2];  // max 2 axis per joystick
-
-//----------------------------------------------------------------------
-int sjoy_open(void)
-{
-  int joy;
-        
-  sjoy_close();
-        
-  for (joy = 0; joy < N_JOY; joy++) {
-    assert(g_fd[joy] == -1);
-    g_fd[joy] = open(g_devName[joy], O_RDONLY | O_NONBLOCK);
-    if (g_fd[joy] < 0) {
-      fprintf(stderr, "can't open %s\n", g_devName[joy]);
-      fprintf(stderr,
-	      "You don't have permission, or should load module for joysticks.\n"
-	      "How to load joystick module:\n"
-	      "    # modprobe ps2pad\n");
-      return -1;
-    }
-  }
-        
-  return 0;
-}
-
-//----------------------------------------------------------------------
-int sjoy_close(void)
-{
-  int joy;
-  int fail = 0;
-        
-  for (joy = 0; joy < N_JOY; joy++) {
-    if (g_fd[joy] >= 0) {
-      fail |= close(g_fd[joy]);
-    }
-    g_fd[joy] = -1;
-  }
-        
-  return fail ? -1 : 0;
-}
-
-/* 適当に自作:miya */
-struct js_event
-{
-  int type;
-  int number;
-  int value;
-};
-
-int g_button[10];
-int g_axis[10][10];
-
-#define JS_EVENT_INIT 1
-#define JS_EVENT_BUTTON 2
-#define JS_EVENT_AXIS 3
-/* ここまで適当に自作:miya */
-
-
-//----------------------------------------------------------------------
-void sjoy_poll(void)
-{
-  int joy;
-        
-  for (joy = 0; joy < N_JOY; joy++) {
-    if (g_fd[joy] < 0) {
-      continue;
-    }
-    for (; ;) {
-      struct js_event e;
-      int n = read(g_fd[joy], &e, sizeof(e));
-      if (n != sizeof(e)) {
-	break;
-      }
-      switch (e.type & ~JS_EVENT_INIT) {
-      case JS_EVENT_BUTTON:
-	g_button[joy] &= ~(1 << e.number);
-	g_button[joy] |= (e.value << e.number);
-	break;
-                                
-      case JS_EVENT_AXIS:
-	g_axis[joy][e.number] = e.value;
-	break;
-                                
-      default:
-	assert(0);
-	break;
-      }
-    }
-  }
-
-}
-
-//----------------------------------------------------------------------
-int sjoy_get_button(int joy)
-{
-  return g_button[joy];
-}
-
-//----------------------------------------------------------------------
-int sjoy_get_axis(int joy, int axis)
-{
-  return g_axis[joy][axis];
-}
-
-//----------------------------------------------------------------------
-int sjoy_get_ps2_button(int joy)
-{
-  int w = g_button[joy];
-  int a0 = g_axis[joy][0];
-  int a1 = g_axis[joy][1];
-  int th = 0x4000;
-        
-  w |= (a0 < -th) ? SJOY_PS2_L_LEFT : 0;
-  w |= (a1 > th) ? SJOY_PS2_L_DOWN : 0;
-  w |= (a0 > th) ? SJOY_PS2_L_RIGHT : 0;
-  w |= (a1 < -th) ? SJOY_PS2_L_UP : 0;
-        
-  return w;
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sjoy.cc	Thu Jun 02 17:51:41 2011 +0900
@@ -0,0 +1,144 @@
+// Copyright(C) 2001 Sony Computer Entertainment Inc. All Rights Reserved.
+//
+// "sjoy.c"
+//
+//
+#include <stdio.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <assert.h>
+
+
+#include "sjoy.h"
+
+#define N_JOY   2
+
+static char *g_devName[N_JOY] = {
+  "/dev/js0",
+  "/dev/js1",
+};
+
+static int g_fd[N_JOY] = {
+  -1, -1,
+};
+
+//static __u32 g_button[N_JOY];   // max 32 buttons per joystick
+//static __s16 g_axis[N_JOY][2];  // max 2 axis per joystick
+
+//----------------------------------------------------------------------
+int sjoy_open(void)
+{
+  int joy;
+        
+  sjoy_close();
+        
+  for (joy = 0; joy < N_JOY; joy++) {
+    assert(g_fd[joy] == -1);
+    g_fd[joy] = open(g_devName[joy], O_RDONLY | O_NONBLOCK);
+    if (g_fd[joy] < 0) {
+      fprintf(stderr, "can't open %s\n", g_devName[joy]);
+      fprintf(stderr,
+	      "You don't have permission, or should load module for joysticks.\n"
+	      "How to load joystick module:\n"
+	      "    # modprobe ps2pad\n");
+      return -1;
+    }
+  }
+        
+  return 0;
+}
+
+//----------------------------------------------------------------------
+int sjoy_close(void)
+{
+  int joy;
+  int fail = 0;
+        
+  for (joy = 0; joy < N_JOY; joy++) {
+    if (g_fd[joy] >= 0) {
+      fail |= close(g_fd[joy]);
+    }
+    g_fd[joy] = -1;
+  }
+        
+  return fail ? -1 : 0;
+}
+
+/* 適当に自作:miya */
+struct js_event
+{
+  int type;
+  int number;
+  int value;
+};
+
+int g_button[10];
+int g_axis[10][10];
+
+#define JS_EVENT_INIT 1
+#define JS_EVENT_BUTTON 2
+#define JS_EVENT_AXIS 3
+/* ここまで適当に自作:miya */
+
+
+//----------------------------------------------------------------------
+void sjoy_poll(void)
+{
+  int joy;
+        
+  for (joy = 0; joy < N_JOY; joy++) {
+    if (g_fd[joy] < 0) {
+      continue;
+    }
+    for (; ;) {
+      struct js_event e;
+      int n = read(g_fd[joy], &e, sizeof(e));
+      if (n != sizeof(e)) {
+	break;
+      }
+      switch (e.type & ~JS_EVENT_INIT) {
+      case JS_EVENT_BUTTON:
+	g_button[joy] &= ~(1 << e.number);
+	g_button[joy] |= (e.value << e.number);
+	break;
+                                
+      case JS_EVENT_AXIS:
+	g_axis[joy][e.number] = e.value;
+	break;
+                                
+      default:
+	assert(0);
+	break;
+      }
+    }
+  }
+
+}
+
+//----------------------------------------------------------------------
+int sjoy_get_button(int joy)
+{
+  return g_button[joy];
+}
+
+//----------------------------------------------------------------------
+int sjoy_get_axis(int joy, int axis)
+{
+  return g_axis[joy][axis];
+}
+
+//----------------------------------------------------------------------
+int sjoy_get_ps2_button(int joy)
+{
+  int w = g_button[joy];
+  int a0 = g_axis[joy][0];
+  int a1 = g_axis[joy][1];
+  int th = 0x4000;
+        
+  w |= (a0 < -th) ? SJOY_PS2_L_LEFT : 0;
+  w |= (a1 > th) ? SJOY_PS2_L_DOWN : 0;
+  w |= (a0 > th) ? SJOY_PS2_L_RIGHT : 0;
+  w |= (a1 < -th) ? SJOY_PS2_L_UP : 0;
+        
+  return w;
+}
Binary file test_vector has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test_vector.cc	Thu Jun 02 17:51:41 2011 +0900
@@ -0,0 +1,189 @@
+#include <stdio.h>
+#include "ps2util.h"
+#include "libps2.h"
+
+void init_FVECTOR(FVECTOR v, float num);
+void init_FMATRIX(FMATRIX m, float num);
+void output_FVECTOR(FVECTOR v);
+void output_FMATRIX(FMATRIX m);
+void all_init(FVECTOR v0, FVECTOR v1, FMATRIX m0, FMATRIX m1, float num);
+
+
+/*
+  ps2util.c にある、vector 計算のテスト用処理です。
+*/
+
+int main(){
+
+  FVECTOR resultV;
+  FMATRIX resultM;
+  float resultf;
+
+  FVECTOR v0,v1;
+  FMATRIX m0,m1;
+
+  float f0 = 0.5;
+  float num = 0.1;
+  
+  int i,j;
+  int lim1 = 4;
+  
+  //v0,v1,m0,m1 を初期化
+  all_init(v0, v1, m0, m1, num);
+  
+  printf("v0\n");
+  output_FVECTOR(v0);
+
+  printf("v1\n");
+  output_FVECTOR(v1);
+
+  printf("m0\n");
+  output_FMATRIX(m0);
+
+  printf("m1\n");
+  output_FMATRIX(m1);
+
+  printf("\n");
+  printf("\n");
+  
+  
+
+  
+  /*-----------ps2util.c test----------*/
+
+  ps2_vu0_copy_vector(v0, v1);
+  printf("ps2_vu0_copy_vector(v0, v1)\n");
+  output_FVECTOR(v0);
+  output_FVECTOR(v1);
+  printf("\n");
+  all_init(v0, v1, m0, m1, num);
+
+  ps2_vu0_unit_matrix(m0);
+  printf("ps2_vu0_unit_matrix(m0)\n");
+  output_FMATRIX(m0);
+  printf("\n");
+  all_init(v0, v1, m0, m1, num);
+
+  ps2_vu0_rot_matrix_y(resultM, m0, f0);
+  printf("ps2_vu0_rot_matrix_y(resultM, m0, f0)\n");
+  output_FMATRIX(resultM);
+  printf("\n");
+  all_init(v0, v1, m0, m1, num);
+
+  ps2_vu0_apply_matrix(resultV, m0, v0);
+  printf("ps2_vu0_apply_matrix(resultV, m0, v0)\n");
+  output_FVECTOR(resultV);
+  printf("\n");
+  all_init(v0, v1, m0, m1, num);
+
+  ps2_vu0_scale_vector(resultV, v0, f0);
+  printf("ps2_vu0_sacle_vector(resultV, v0, f0)\n");
+  output_FVECTOR(resultV);
+  printf("\n");
+  all_init(v0, v1, m0, m1, num);
+
+  ps2_vu0_add_vector(resultV, v0, v1);
+  printf("ps2_vu0_add_vector(resultV, v0, v1)\n");
+  output_FVECTOR(resultV);
+  printf("\n");
+  all_init(v0, v1, m0, m1, num);
+
+  ps2_vu0_outer_product(resultV, v0, v1);
+  printf("ps2_vu0_outer_product(resultV, v0, v1)\n");
+  output_FVECTOR(resultV);
+  printf("\n");
+  all_init(v0, v1, m0, m1, num);
+
+  resultf = ps2_vu0_inner_product(v0, v1);
+  printf("ps2_vu0_inner_product(v0, v1)\n");
+  printf("resultf = %10f\n",resultf);
+  printf("\n");
+  all_init(v0, v1, m0, m1, num);
+
+  ps2_vu0_mul_matrix(resultM, m0, m1);
+  printf("ps2_vu0_mul_matrix(resultM, m0, m1)\n");
+  output_FMATRIX(resultM);
+  printf("\n");
+  all_init(v0, v1, m0, m1, num);
+
+  ps2_vu0_copy_matrix(m0, m1);
+  printf("ps2_vu0_copy_matrix(m0, m1)\n");
+  output_FMATRIX(m0);
+  output_FMATRIX(m0);
+  printf("\n");
+  all_init(v0, v1, m0, m1, num);
+
+  ps2_vu0_sub_vector(resultV, v0, v1);
+  printf("ps2_vu0_sub_vector(resultV, v0, v1)\n");
+  output_FVECTOR(resultV);
+  printf("\n");
+  all_init(v0, v1, m0, m1, num);
+  
+  ps2_vu0_normalize(resultV, v0);
+  printf("ps2_vu0_normalize(result, v0)\n");
+  output_FVECTOR(resultV);
+  printf("\n");
+  all_init(v0, v1, m0, m1, num);
+
+  
+}
+
+
+
+//使用する値の初期化 FVECTOR
+void init_FVECTOR(FVECTOR v, float num){
+  int i;
+  int lim1=4;
+  for ( i=0; i<lim1; i++ ) {
+    v[i] = num + ( (float)i * num * 0.3 ) ;
+  }
+  v[3] = 1;
+}
+
+//使用する値の初期化 FMATRIX
+void init_FMATRIX(FMATRIX m, float num){
+  int i,j;
+  int lim1=4;
+  for ( i=0; i<lim1; i++ ) {
+    for ( j=0; j<lim1; j++ ) {
+      m[i][j] = ( num * (float)j )  + ( (float)i * num*4.0 ) ;
+    }
+  }
+  m[0][3] = m[1][3] = m[2][3] = 0;
+
+  m[3][0] = m[3][1] = m[3][2] = 0;
+  m[3][3] = 1;
+}
+
+//--------出力---------
+void output_FVECTOR(FVECTOR v){
+  int i;
+  int lim1 = 4;
+  for ( i=0; i<lim1; i++ ) {
+    printf("%10f ",v[i]);
+  }
+  printf("\n\n");
+}
+
+//--------出力---------
+void output_FMATRIX(FMATRIX m){
+  int i,j;
+  int lim1 = 4;
+  for ( i=0; i<lim1; i++ ) {
+    for ( j=0; j<lim1; j++ ) {
+      printf("%10f",m[i][j]);
+    }
+    printf("\n");
+  }
+  printf("\n");
+}
+
+
+
+//全部を初期値に戻す。
+void all_init(FVECTOR v0, FVECTOR v1, FMATRIX m0, FMATRIX m1, float num){
+  init_FVECTOR(v0, num);
+  init_FVECTOR(v1, num*2);
+  init_FMATRIX(m0, num);
+  init_FMATRIX(m1, num*2);
+}
--- a/title_scene.c	Thu Jun 02 17:26:21 2011 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,88 +0,0 @@
-#include "libps2.h"
-#include "ps2util.h"
-#include "title_scene.h"
-#include "gSprite.h"
-
-#include "sjoy.h"
-
-
-typedef enum {
-    TITLE_INIT,
-    TITLE_MAIN,
-    TITLE_FINISH
-} TITLE_STATE;
-
-static ps2utilSprite title_sprite;
-
-static TEXTURE *title_img;
-
-#define TITLE_IMG_FILE "img/title.png"
-
-
-static void
-title_init() 
-{    
-
-  //load texture 
-
-  title_img = read_png_file( TITLE_IMG_FILE );
-  ps2util_tex_Set( title_img );
-
-  /*    
-	create sprite object
-  */
-
-    ps2util_sprite_Create( &title_sprite, title_img );
-    ps2util_sprite_Set_basicAttribute( &title_sprite, 
-    0, 0, 650, 500, 0, 0, 512, 256, SPRITE_PRIO_FOREGROUND );
-
-    ps2util_sprite_Use_alpha( &title_sprite );
-    ps2util_sprite_Request( &title_sprite );
-}
-
-void
-title_init_call()
-{
-  title_init();
-}
-
-static void
-title_finish()
-{
-  ps2util_sprite_Destroy( &title_sprite );
-  ps2util_tex_Exclude( title_img );
-  free_texture( title_img );
-}
-
-void
-title_finish_call()
-{
-  title_finish();
-}
-
-int
-title_scene() 
-{
-  static TITLE_STATE state = TITLE_INIT;
-  int pad;
-
-  switch (state) {
-  case TITLE_INIT:
-    title_init();
-    state = TITLE_MAIN;
-    break;
-
-  case TITLE_MAIN:
-    pad = sjoy_get_ps2_button( JOYPAD_1 );
-    state = (pad & SJOY_PS2_START) ? TITLE_FINISH : TITLE_MAIN;
-    break;
-
-  case TITLE_FINISH:
-    title_finish();
-    return -1;
-
-  default:
-    break;
-  }
-  return 0;
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/title_scene.cc	Thu Jun 02 17:51:41 2011 +0900
@@ -0,0 +1,88 @@
+#include "libps2.h"
+#include "ps2util.h"
+#include "title_scene.h"
+#include "gSprite.h"
+
+#include "sjoy.h"
+
+
+typedef enum {
+    TITLE_INIT,
+    TITLE_MAIN,
+    TITLE_FINISH
+} TITLE_STATE;
+
+static ps2utilSprite title_sprite;
+
+static TEXTURE *title_img;
+
+#define TITLE_IMG_FILE "img/title.png"
+
+
+static void
+title_init() 
+{    
+
+  //load texture 
+
+  title_img = read_png_file( TITLE_IMG_FILE );
+  ps2util_tex_Set( title_img );
+
+  /*    
+	create sprite object
+  */
+
+    ps2util_sprite_Create( &title_sprite, title_img );
+    ps2util_sprite_Set_basicAttribute( &title_sprite, 
+    0, 0, 650, 500, 0, 0, 512, 256, SPRITE_PRIO_FOREGROUND );
+
+    ps2util_sprite_Use_alpha( &title_sprite );
+    ps2util_sprite_Request( &title_sprite );
+}
+
+void
+title_init_call()
+{
+  title_init();
+}
+
+static void
+title_finish()
+{
+  ps2util_sprite_Destroy( &title_sprite );
+  ps2util_tex_Exclude( title_img );
+  free_texture( title_img );
+}
+
+void
+title_finish_call()
+{
+  title_finish();
+}
+
+int
+title_scene() 
+{
+  static TITLE_STATE state = TITLE_INIT;
+  int pad;
+
+  switch (state) {
+  case TITLE_INIT:
+    title_init();
+    state = TITLE_MAIN;
+    break;
+
+  case TITLE_MAIN:
+    pad = sjoy_get_ps2_button( JOYPAD_1 );
+    state = (pad & SJOY_PS2_START) ? TITLE_FINISH : TITLE_MAIN;
+    break;
+
+  case TITLE_FINISH:
+    title_finish();
+    return -1;
+
+  default:
+    break;
+  }
+  return 0;
+}