Browse Source

Improved the display routines in XDisplay.c and rendered somewhat faster.

Changed method of storing WWLCDPanel data.
(I made 1 byte allocated with 1 pixel as 1 byte with 2 pixels)
(For speeding up, thought about future color correspondence (241 colors?))

Added WonxDisplay_Sync ().  Reduced wasteful drawing in functions of get type.

Implement sprite window function.  (Not tested)

Implement time related functions.  (timer.c)

Fix sprite priority.  (I modified "Priority is given to younger one")

Version 0.0.4 alpha - from wonx-a04.tar.gz
Hiroaki Sakai 23 years ago
parent
commit
aa38e7adab
12 changed files with 508 additions and 156 deletions
  1. 23 0
      HISTORY
  2. 2 2
      Makefile
  3. 73 20
      WWDisplay.c
  4. 10 0
      WWDisplay.h
  5. 6 2
      WWDisplayP.h
  6. 4 10
      WWLCDPanel.c
  7. 23 8
      WonxDisplay.c
  8. 1 0
      WonxDisplay.h
  9. 10 0
      XDisplay.c
  10. 171 101
      disp.c
  11. 14 0
      key.c
  12. 171 13
      timer.c

+ 23 - 0
HISTORY

@@ -1,5 +1,28 @@
+2000/9/30(土)
+
+wonx-a04 公開
+
+XDisplay.c 内の表示ルーチンを改良し,描画を多少高速にした.
+
+WWLCDPanel のデータの格納方法を変更した.
+(2ピクセルで1バイトだったのを,1ピクセルで1バイトを割り当てるようにした)
+(高速化のためだが,将来のカラー対応(241色?)のことも考えた)
+
+WonxDisplay_Sync() を追加.get 系の関数内での無駄な描画を減らした.
+
+スプライトウインドウ機能を実装.(未テスト)
+
+時刻関連の関数を実装.(timer.c)
+
+スプライトの優先順位を修正.(「番号が若いもののほうが優先」に修正した)
+
+
+
+
 2000/9/28(木)
 
+wonx-a03 公開
+
 screen2_set_window()の表示範囲を修正.
 マニュアルの screen2_set_window() の説明には「表示領域の横幅と縦幅」と
 書いてあるが,実際には「表示領域の横幅+1と縦幅+1」で動作する

+ 2 - 2
Makefile

@@ -2,8 +2,8 @@ XINCLUDEDIR = /usr/X11R6/include
 INCLUDEDIR = .
 XLIBDIR = /usr/X11R6/lib
 
-VERSION = Wonx-a03
-PKGNAME = wonx-a03
+VERSION = Wonx-a04
+PKGNAME = wonx-a04
 
 OBJS = WWCharacter.o WWColorMap.o WWDisplay.o WWLCDPanel.o WWPalette.o WWScreen.o WWSprite.o WonxDisplay.o XDisplay.o bank.o comm.o disp.o text.o key.o sound.o system.o timer.o etc.o wonx.o
 

+ 73 - 20
WWDisplay.c

@@ -24,6 +24,15 @@ int WWDisplay_GetSpriteEnable(WWDisplay d) { return (d->sprite_enable); }
 int WWDisplay_GetSpriteWindowEnable(WWDisplay d)
 { return (d->sprite_window_enable); }
 
+int WWDisplay_GetSpriteWindowX(WWDisplay d)
+{ return (d->sprite_window_x); }
+int WWDisplay_GetSpriteWindowY(WWDisplay d)
+{ return (d->sprite_window_y); }
+int WWDisplay_GetSpriteWindowWidth(WWDisplay d)
+{ return (d->sprite_window_width); }
+int WWDisplay_GetSpriteWindowHeight(WWDisplay d)
+{ return (d->sprite_window_height); }
+
 int WWDisplay_GetBorder(WWDisplay d) { return (d->border); }
 
 int WWDisplay_GetForegroundColor(WWDisplay d) { return (d->foreground_color); }
@@ -54,6 +63,15 @@ int WWDisplay_SetSpriteEnable(WWDisplay d, int f)
 int WWDisplay_SetSpriteWindowEnable(WWDisplay d, int f)
 { return (d->sprite_window_enable = f); }
 
+int WWDisplay_SetSpriteWindowX(WWDisplay d, int n)
+{ return (d->sprite_window_x = n); }
+int WWDisplay_SetSpriteWindowY(WWDisplay d, int n)
+{ return (d->sprite_window_y = n); }
+int WWDisplay_SetSpriteWindowWidth(WWDisplay d, int n)
+{ return (d->sprite_window_width = n); }
+int WWDisplay_SetSpriteWindowHeight(WWDisplay d, int n)
+{ return (d->sprite_window_height = n); }
+
 int WWDisplay_SetBorder(WWDisplay d, int b) { return (d->border = b); }
 
 int WWDisplay_SetForegroundColor(WWDisplay d, int c)
@@ -112,6 +130,11 @@ WWDisplay WWDisplay_Create(int lcd_panel_width, int lcd_panel_height,
   WWDisplay_SetSpriteEnable(display, 0);
   WWDisplay_SetSpriteWindowEnable(display, 0);
 
+  WWDisplay_SetSpriteWindowX(     display, 0);
+  WWDisplay_SetSpriteWindowY(     display, 0);
+  WWDisplay_SetSpriteWindowWidth( display, lcd_panel_width);
+  WWDisplay_SetSpriteWindowHeight(display, lcd_panel_height);
+
   WWDisplay_SetBorder(display, 0);
 
   WWDisplay_SetForegroundColor(display, 3);
@@ -253,8 +276,21 @@ static int WWDisplay_DrawScreen(WWDisplay display, WWScreen screen)
 
 static int WWDisplay_DrawSprite(WWDisplay display, WWSprite sprite)
 {
-  int x, y;
-  int pixel;
+  int x, y, lcd_x, lcd_y;
+  int sx, sy, ex, ey;
+  int pixel, outside;
+
+  sx = WWDisplay_GetSpriteWindowX(display) - 1;
+  sy = WWDisplay_GetSpriteWindowY(display) - 1;
+
+  /* 以下は WWDisplay_DrawScreen() に合わせた */
+#if 0
+  ex = sx + WWDisplay_GetSpriteWindowWidth(display) - 1;
+  ey = sy + WWDisplay_GetSpriteWindowHeight(display) - 1;
+#else
+  ex = sx + WWDisplay_GetSpriteWindowWidth(display);
+  ey = sy + WWDisplay_GetSpriteWindowHeight(display);
+#endif
 
   for (y = 0; y < 8; y++) {
     for (x = 0; x < 8; x++) {
@@ -263,11 +299,24 @@ static int WWDisplay_DrawSprite(WWDisplay display, WWSprite sprite)
       /* 透明色の場合 */
       if (pixel == -1) continue;
 
+      lcd_x = WWSprite_GetX(sprite) + x;
+      lcd_y = WWSprite_GetY(sprite) + y;
+
+      if (WWDisplay_GetSpriteWindowEnable(display)) {
+	if ( (lcd_x < sx) || (lcd_y < sy) || (lcd_x > ex) || (lcd_y > ey) )
+	  outside = 1;
+	else
+	  outside = 0;
+
+	if (WWSprite_GetClipping(sprite)) { /* ウインドウの外側部分を表示 */
+	  if (!outside) continue;
+	} else {                            /* ウインドウの内側部分を表示 */
+	  if (outside) continue;
+	}
+      }
+
       pixel = WWColorMap_GetLCDColor(WWDisplay_GetColorMap(display), pixel);
-      WWLCDPanel_SetPixel(WWDisplay_GetLCDPanel(display),
-			  WWSprite_GetX(sprite) + x,
-			  WWSprite_GetY(sprite) + y,
-			  pixel);
+      WWLCDPanel_SetPixel(WWDisplay_GetLCDPanel(display), lcd_x, lcd_y, pixel);
     }
   }
 
@@ -300,28 +349,32 @@ int WWDisplay_DrawLCDPanel(WWDisplay display)
   }
 
   /* スクリーン1描画 */
-  if (WWDisplay_GetSpriteEnable(display))
-    WWDisplay_DrawScreen(display, WWDisplay_GetScreen(display, 0));
+  WWDisplay_DrawScreen(display, WWDisplay_GetScreen(display, 0));
 
   /* スプライト描画(スクリーン2より優先でないもの) */
-  for (i = 0; i < WWDisplay_GetSpriteCount(display); i++) {
-    sprite = WWDisplay_GetSprite(display,
-				 i + WWDisplay_GetSpriteStart(display));
-    if (!WWSprite_GetPriority(sprite)) {
-      WWDisplay_DrawSprite(display, sprite);
+  /* 重なった場合は,番号の若いものが手前に表示される */
+  if (WWDisplay_GetSpriteEnable(display)) {
+    for (i = WWDisplay_GetSpriteCount(display) - 1; i >= 0; i--) {
+      sprite = WWDisplay_GetSprite(display,
+				   i + WWDisplay_GetSpriteStart(display));
+      if (!WWSprite_GetPriority(sprite)) {
+	WWDisplay_DrawSprite(display, sprite);
+      }
     }
   }
 
   /* スクリーン2描画 */
-  if (WWDisplay_GetSpriteEnable(display))
-    WWDisplay_DrawScreen(display, WWDisplay_GetScreen(display, 1));
+  WWDisplay_DrawScreen(display, WWDisplay_GetScreen(display, 1));
 
   /* スプライト描画(スクリーン2より優先なもの) */
-  for (i = 0; i < WWDisplay_GetSpriteCount(display); i++) {
-    sprite = WWDisplay_GetSprite(display,
-				 i + WWDisplay_GetSpriteStart(display));
-    if (WWSprite_GetPriority(sprite)) {
-      WWDisplay_DrawSprite(display, sprite);
+  /* 重なった場合は,番号の若いものが手前に表示される */
+  if (WWDisplay_GetSpriteEnable(display)) {
+    for (i = WWDisplay_GetSpriteCount(display) - 1; i >= 0; i--) {
+      sprite = WWDisplay_GetSprite(display,
+				   i + WWDisplay_GetSpriteStart(display));
+      if (WWSprite_GetPriority(sprite)) {
+	WWDisplay_DrawSprite(display, sprite);
+      }
     }
   }
 

+ 10 - 0
WWDisplay.h

@@ -35,6 +35,11 @@ WWLCDPanel WWDisplay_GetLCDPanel(WWDisplay d);
 int WWDisplay_GetSpriteEnable(WWDisplay d);
 int WWDisplay_GetSpriteWindowEnable(WWDisplay d);
 
+int WWDisplay_GetSpriteWindowX(WWDisplay d);
+int WWDisplay_GetSpriteWindowY(WWDisplay d);
+int WWDisplay_GetSpriteWindowWidth(WWDisplay d);
+int WWDisplay_GetSpriteWindowHeight(WWDisplay d);
+
 int WWDisplay_GetBorder(WWDisplay d);
 
 int WWDisplay_GetForegroundColor(WWDisplay d);
@@ -57,6 +62,11 @@ WWLCDPanel WWDisplay_SetLCDPanel(WWDisplay d, WWLCDPanel p);
 int WWDisplay_SetSpriteEnable(WWDisplay d, int f);
 int WWDisplay_SetSpriteWindowEnable(WWDisplay d, int f);
 
+int WWDisplay_SetSpriteWindowX(WWDisplay d, int n);
+int WWDisplay_SetSpriteWindowY(WWDisplay d, int n);
+int WWDisplay_SetSpriteWindowWidth(WWDisplay d, int n);
+int WWDisplay_SetSpriteWindowHeight(WWDisplay d, int n);
+
 int WWDisplay_SetBorder(WWDisplay d, int b);
 
 int WWDisplay_SetForegroundColor(WWDisplay d, int c);

+ 6 - 2
WWDisplayP.h

@@ -21,8 +21,12 @@ typedef struct _WWDisplay {
   WWLCDPanel lcd_panel;
 
   /* ディスプレイの属性情報 */
-  int sprite_enable;  /* スプライト表示イネーブルフラグ */
-  int sprite_window_enable;  /* スプライトウインドウ機能イネーブルフラグ */
+  int sprite_enable; /* スプライト表示イネーブルフラグ */
+  int sprite_window_enable; /* スプライトウインドウ機能イネーブルフラグ */
+  int sprite_window_x;      /* スプライトウインドウ用 */
+  int sprite_window_y;      /* スプライトウインドウ用 */
+  int sprite_window_width;  /* スプライトウインドウ用 */
+  int sprite_window_height; /* スプライトウインドウ用 */
 
   int border; /* ボーダーカラー.0~7のカラーマップ番号 */
 

+ 4 - 10
WWLCDPanel.c

@@ -24,8 +24,7 @@ int WWLCDPanel_GetPixel(WWLCDPanel lcd_panel, int x, int y)
        (y < 0) || (y > WWLCDPanel_GetHeight(lcd_panel) - 1) )
     return (-1);
 
-  pixel = lcd_panel->pixel[y * (WWLCDPanel_GetWidth(lcd_panel) / 2) + x / 2];
-  if (x % 2) pixel = pixel >> 4;
+  pixel = lcd_panel->pixel[y * WWLCDPanel_GetWidth(lcd_panel) + x];
   pixel &= 0x0f;
   return ((int)pixel);
 }
@@ -39,14 +38,9 @@ int WWLCDPanel_SetPixel(WWLCDPanel lcd_panel, int x, int y, int pixel)
        (y < 0) || (y > WWLCDPanel_GetHeight(lcd_panel) - 1) )
     return (-1);
 
-  p = 0x0f;
-  if (x % 2) p = p << 4;
-  n = y * (WWLCDPanel_GetWidth(lcd_panel) / 2) + x / 2;
-  lcd_panel->pixel[n] &= ~p;
-
   p = ((unsigned char)pixel) & 0x0f;
-  if (x % 2) p = p << 4;
-  lcd_panel->pixel[n] |= p;
+  n = y * WWLCDPanel_GetWidth(lcd_panel) + x;
+  lcd_panel->pixel[n] = p;
 
   return (pixel);
 }
@@ -63,7 +57,7 @@ WWLCDPanel WWLCDPanel_Create(int width, int height)
   WWLCDPanel_SetHeight(lcd_panel, height);
   lcd_panel->pixel =
     (unsigned char *)malloc(sizeof(unsigned char) *
-			    (WWLCDPanel_GetWidth(lcd_panel) / 2) *
+			    WWLCDPanel_GetWidth(lcd_panel) *
 			    WWLCDPanel_GetHeight(lcd_panel));
 
   for (y = 0; y < lcd_panel->height; y++) {

+ 23 - 8
WonxDisplay.c

@@ -44,22 +44,15 @@ WonxDisplay WonxDisplay_Create(int x_width, int x_height,
   return (wonx_display);
 }
 
-int WonxDisplay_Flush(WonxDisplay wonx_display)
+int WonxDisplay_Sync(WonxDisplay wonx_display)
 {
   int i;
   XDisplay x_display;
   WWDisplay ww_display;
-  WWLCDPanel ww_lcd_panel;
 
   x_display = WonxDisplay_GetXDisplay(wonx_display);
   ww_display = WonxDisplay_GetWWDisplay(wonx_display);
 
-  if (XDisplay_GetLCDDraw(x_display)) {
-    WWDisplay_DrawLCDPanel(ww_display);
-    ww_lcd_panel = WWDisplay_GetLCDPanel(ww_display);
-    XDisplay_DrawLCDWindow(x_display, ww_lcd_panel);
-  }
-
   if (XDisplay_GetColorMapPrint(x_display)) {
     WWColorMap_PrintData(WWDisplay_GetColorMap(ww_display), stdout);
     XDisplay_SetColorMapPrint(x_display, 0);
@@ -86,6 +79,28 @@ int WonxDisplay_Flush(WonxDisplay wonx_display)
     XDisplay_SetSpritePrint(x_display, 0);
   }
 
+  XDisplay_Sync(x_display);
+
+  return (0);
+}
+
+int WonxDisplay_Flush(WonxDisplay wonx_display)
+{
+  XDisplay x_display;
+  WWDisplay ww_display;
+  WWLCDPanel ww_lcd_panel;
+
+  x_display = WonxDisplay_GetXDisplay(wonx_display);
+  ww_display = WonxDisplay_GetWWDisplay(wonx_display);
+
+  if (XDisplay_GetLCDDraw(x_display)) {
+    WWDisplay_DrawLCDPanel(ww_display);
+    ww_lcd_panel = WWDisplay_GetLCDPanel(ww_display);
+    XDisplay_DrawLCDWindow(x_display, ww_lcd_panel);
+  }
+
+  WonxDisplay_Sync(wonx_display);
+
   return (0);
 }
 

+ 1 - 0
WonxDisplay.h

@@ -19,6 +19,7 @@ WWDisplay WonxDisplay_GetWWDisplay(WonxDisplay wonx_display);
 WonxDisplay WonxDisplay_Create(int x_width, int x_height,
 			       int ww_lcd_panel_width, int ww_lcd_panel_height,
 			       int ww_screen_width, int ww_screen_height);
+int WonxDisplay_Sync(WonxDisplay wonx_display);
 int WonxDisplay_Flush(WonxDisplay wonx_display);
 
 /*****************************************************************************/

+ 10 - 0
XDisplay.c

@@ -387,6 +387,16 @@ int XDisplay_DrawLCDWindow(XDisplay x_display, WWLCDPanel ww_lcd_panel)
 	  rectangles[n].y = py;
 	  rectangles[n].width  = (x+1) * x_display->width  / ww_lcd_width - px;
 	  rectangles[n].height = (y+1) * x_display->height / ww_lcd_height- py;
+
+	  /* 隣接してる同色のピクセルは,極力いっしょに描画する */
+	  x++;
+	  while ( (x < ww_lcd_width) &&
+		  (pixel == WWLCDPanel_GetPixel(ww_lcd_panel, x, y)) ) {
+	    rectangles[n].width = (x+1) * x_display->width / ww_lcd_width - px;
+	    x++;
+	  }
+	  x--;
+
 	  n++;
 	}
       }

+ 171 - 101
disp.c

@@ -19,7 +19,7 @@ void display_control(unsigned int flags)
 {
   WWDisplay ww_display;
 
-  printf("call : display_control() : flags = 0x%04x, ", (int)flags);
+  printf("call : display_control() : flags = 0x%04x\n", (int)flags);
   fflush(stdout);
 
   if (wonx_display == NULL) Wonx_Create();
@@ -47,7 +47,7 @@ void display_control(unsigned int flags)
 
   WonxDisplay_Flush(wonx_display);
 
-  printf("return value = none\n"); fflush(stdout);
+  printf("call : display_control() : return value = none\n"); fflush(stdout);
 
   return;
 }
@@ -57,7 +57,7 @@ unsigned int display_status()
   WWDisplay ww_display;
   unsigned short int ret;
 
-  printf("call : display_status() : "); fflush(stdout);
+  printf("call : display_status() : \n"); fflush(stdout);
 
   if (wonx_display == NULL) Wonx_Create();
 
@@ -89,9 +89,10 @@ unsigned int display_status()
 
   ret |= WWDisplay_GetBorder(WonxDisplay_GetWWDisplay(wonx_display)) << 7;
 
-  WonxDisplay_Flush(wonx_display);
+  WonxDisplay_Sync(wonx_display);
 
-  printf("return value = %u\n", (int)ret); fflush(stdout);
+  printf("call : display_status() : return value = %u\n", (int)ret);
+  fflush(stdout);
 
   return (ret);
 }
@@ -103,7 +104,7 @@ void font_set_monodata(unsigned int number, unsigned int count, void * data)
   int f, b;
   unsigned char * d;
 
-  printf("call : font_set_monodata() : number = %u, count = %u, data = %p, ",
+  printf("call : font_set_monodata() : number = %u, count = %u, data = %p\n",
 	 (int)number, (int)count, data); fflush(stdout);
 
   if (wonx_display == NULL) Wonx_Create();
@@ -127,7 +128,8 @@ void font_set_monodata(unsigned int number, unsigned int count, void * data)
 
   WonxDisplay_Flush(wonx_display);
 
-  printf("return value = none\n"); fflush(stdout);
+  printf("call : font_set_monodata() : return value = none\n");
+  fflush(stdout);
 
   return;
 }
@@ -140,7 +142,7 @@ void font_set_colordata(unsigned int number,
   int f, b;
   unsigned char * d;
 
-  printf("call : font_set_colordata() : number = %u, count = %u, data = %p, ",
+  printf("call : font_set_colordata() : number = %u, count = %u, data = %p\n",
 	 (int)number, (int)count, data); fflush(stdout);
 
   if (wonx_display == NULL) Wonx_Create();
@@ -166,7 +168,8 @@ void font_set_colordata(unsigned int number,
 
   WonxDisplay_Flush(wonx_display);
 
-  printf("return value = none\n"); fflush(stdout);
+  printf("call : font_set_colordata() : return value = none\n");
+  fflush(stdout);
 
   return;
 }
@@ -180,7 +183,7 @@ void font_get_data(unsigned int number,
   int f, b;
   unsigned char * d;
 
-  printf("call : font_get_data() : number = %u, count = %u, data = %p, ",
+  printf("call : font_get_data() : number = %u, count = %u, data = %p\n",
 	 (int)number, (int)count, data); fflush(stdout);
 
   if (wonx_display == NULL) Wonx_Create();
@@ -205,9 +208,9 @@ void font_get_data(unsigned int number,
     }
   }
 
-  WonxDisplay_Flush(wonx_display);
+  WonxDisplay_Sync(wonx_display);
 
-  printf("return value = none\n"); fflush(stdout);
+  printf("call : font_get_data() : return value = none\n"); fflush(stdout);
 
   return;
 }
@@ -216,7 +219,7 @@ void font_set_color(unsigned int colors)
 {
   WWDisplay dis;
 
-  printf("call : font_set_color() : colors = 0x%04x, ", (int)colors);
+  printf("call : font_set_color() : colors = 0x%04x\n", (int)colors);
   fflush(stdout);
 
   if (wonx_display == NULL) Wonx_Create();
@@ -227,7 +230,7 @@ void font_set_color(unsigned int colors)
 
   WonxDisplay_Flush(wonx_display);
 
-  printf("return value = none\n"); fflush(stdout);
+  printf("call : font_set_color() : return value = none\n"); fflush(stdout);
 
   return;
 }
@@ -237,7 +240,7 @@ unsigned int font_get_color(void)
   unsigned short int ret;
   WWDisplay dis;
 
-  printf("call : font_get_color() : "); fflush(stdout);
+  printf("call : font_get_color() : \n"); fflush(stdout);
 
   if (wonx_display == NULL) Wonx_Create();
 
@@ -246,9 +249,10 @@ unsigned int font_get_color(void)
   ret |= WWDisplay_GetForegroundColor(dis);
   ret |= WWDisplay_GetBackgroundColor(dis) << 2;
 
-  WonxDisplay_Flush(wonx_display);
+  WonxDisplay_Sync(wonx_display);
 
-  printf("return value = 0x%04x\n", (int)ret); fflush(stdout);
+  printf("call : font_get_color() : return value = 0x%04x\n", (int)ret);
+  fflush(stdout);
 
   return (ret);
 }
@@ -265,7 +269,7 @@ void screen_set_char(int screen, int x, int y, int w, int h, void * data)
   WWPalette p;
   WWCharacter c;
 
-  printf("call : screen_set_char() : screen = %d, x = %d, y = %d, w = %d, h = %d, data = %p",
+  printf("call : screen_set_char() : screen = %d, x = %d, y = %d, w = %d, h = %d, data = %p\n",
 	 screen, x, y, w, h, data); fflush(stdout);
 
   if (wonx_display == NULL) Wonx_Create();
@@ -294,7 +298,7 @@ void screen_set_char(int screen, int x, int y, int w, int h, void * data)
 
   WonxDisplay_Flush(wonx_display);
 
-  printf("return value = none\n"); fflush(stdout);
+  printf("call : screen_set_char() : return value = none\n"); fflush(stdout);
 
   return;
 }
@@ -311,7 +315,7 @@ void screen_get_char(int screen, int x, int y, int w, int h, void * data)
   WWPalette p;
   WWCharacter c;
 
-  printf("call : screen_get_char() : screen = %d, x = %d, y = %d, w = %d, h = %d, data = %p",
+  printf("call : screen_get_char() : screen = %d, x = %d, y = %d, w = %d, h = %d, data = %p\n",
 	 screen, x, y, w, h, data); fflush(stdout);
 
   if (wonx_display == NULL) Wonx_Create();
@@ -337,28 +341,49 @@ void screen_get_char(int screen, int x, int y, int w, int h, void * data)
     }
   }
 
-  WonxDisplay_Flush(wonx_display);
+  WonxDisplay_Sync(wonx_display);
 
-  printf("return value = none\n"); fflush(stdout);
+  printf("call : screen_get_char() : return value = none\n"); fflush(stdout);
 
   return;
 }
 
 unsigned int screen_get_char1(int screen, int x, int y)
 {
+  int horizontal; /* 横方向反転フラグ */
+  int vertical; /* 縦方向反転フラグ */
+  int palette_num; /* パレット番号 */
+  int character_num; /* 表示キャラクタ */
+  WWScreen s;
+  WWPalette p;
+  WWCharacter c;
   unsigned short int ret;
 
-  printf("call : screen_get_char1() : screen = %d, x = %d, y = %d, ",
+  printf("call : screen_get_char1() : screen = %d, x = %d, y = %d\n",
 	 screen, x, y);
   fflush(stdout);
 
   if (wonx_display == NULL) Wonx_Create();
 
-  screen_get_char(screen, x, y, 1, 1, &ret);
+  s = WWDisplay_GetScreen(WonxDisplay_GetWWDisplay(wonx_display), screen);
+
+  horizontal = WWScreen_GetHorizontal(s, x, y);
+  vertical   = WWScreen_GetVertical(  s, x, y);
+  p          = WWScreen_GetPalette(   s, x, y);
+  c          = WWScreen_GetCharacter( s, x, y);
+  palette_num = WWPalette_GetNumber(p);
+  character_num = WWCharacter_GetNumber(c);
 
-  WonxDisplay_Flush(wonx_display);
+  ret = 0;
+  ret |= horizontal << 15;
+  ret |= vertical << 14;
+  ret |= palette_num << 9;
+  ret |= character_num;
+
+  WonxDisplay_Sync(wonx_display);
 
-  printf("return value = 0x%04x\n", (int)ret); fflush(stdout);
+  printf("call : screen_get_char1() : return value = 0x%04x\n", (int)ret);
+  fflush(stdout);
 
   return (ret);
 }
@@ -375,7 +400,7 @@ void screen_fill_char(int screen, int x, int y, int w, int h,
   WWPalette p;
   WWCharacter c;
 
-  printf("call : screen_fill_char() : screen = %d, x = %d, y = %d, w = %d, h = %d, data = 0x%04x, ",
+  printf("call : screen_fill_char() : screen = %d, x = %d, y = %d, w = %d, h = %d, data = 0x%04x\n",
 	 screen, x, y, w, h, (int)data); fflush(stdout);
 
   if (wonx_display == NULL) Wonx_Create();
@@ -403,7 +428,7 @@ void screen_fill_char(int screen, int x, int y, int w, int h,
 
   WonxDisplay_Flush(wonx_display);
 
-  printf("return value = none\n"); fflush(stdout);
+  printf("call : screen_fill_char() : return value = none\n"); fflush(stdout);
 
   return;
 }
@@ -414,7 +439,7 @@ void screen_fill_attr(int screen, int x, int y, int w, int h,
   int i, j;
   unsigned short int c;
 
-  printf("call : screen_fill_attr() : screen = %d, x = %d, y = %d, w = %d, h = %d, data = 0x%04x, mask = 0x%04x, ",
+  printf("call : screen_fill_attr() : screen = %d, x = %d, y = %d, w = %d, h = %d, data = 0x%04x, mask = 0x%04x\n",
 	 screen, x, y, w, h, (int)data, (int)mask); fflush(stdout);
 
   if (wonx_display == NULL) Wonx_Create();
@@ -430,14 +455,14 @@ void screen_fill_attr(int screen, int x, int y, int w, int h,
 
   WonxDisplay_Flush(wonx_display);
 
-  printf("return value = none\n"); fflush(stdout);
+  printf("call : screen_fill_attr() : return value = none\n"); fflush(stdout);
 
   return;
 }
 
 void sprite_set_range(unsigned int sprite_start, unsigned int sprite_count)
 {
-  printf("call : sprite_set_range() : start = %u, count = %u, ",
+  printf("call : sprite_set_range() : start = %u, count = %u\n",
 	 (int)sprite_start, (int)sprite_count); fflush(stdout);
 
   if (wonx_display == NULL) Wonx_Create();
@@ -449,19 +474,18 @@ void sprite_set_range(unsigned int sprite_start, unsigned int sprite_count)
 
   WonxDisplay_Flush(wonx_display);
 
-  printf("return value = none\n"); fflush(stdout);
+  printf("call : sprite_set_range() : return value = none\n"); fflush(stdout);
 
   return;
 }
 
-void sprite_set_char(unsigned int sprite_num,
-		     unsigned int data)
+void sprite_set_char(unsigned int sprite_num, unsigned int data)
 {
   WWSprite s;
   WWPalette p;
   WWCharacter c;
 
-  printf("call : sprite_set_char() : number = %u, data = 0x%04x, ",
+  printf("call : sprite_set_char() : number = %u, data = 0x%04x\n",
 	 (int)sprite_num, (int)data); fflush(stdout);
 
   if (wonx_display == NULL) Wonx_Create();
@@ -483,7 +507,7 @@ void sprite_set_char(unsigned int sprite_num,
 
   WonxDisplay_Flush(wonx_display);
 
-  printf("return value = none\n"); fflush(stdout);
+  printf("call : sprite_set_char() : return value = none\n"); fflush(stdout);
 
   return;
 }
@@ -495,7 +519,7 @@ unsigned int sprite_get_char(unsigned int sprite_num)
   WWCharacter c;
   unsigned short int ret;
 
-  printf("call : sprite_get_char() : number = %u, ", (int)sprite_num);
+  printf("call : sprite_get_char() : number = %u\n", (int)sprite_num);
   fflush(stdout);
 
   if (wonx_display == NULL) Wonx_Create();
@@ -516,9 +540,10 @@ unsigned int sprite_get_char(unsigned int sprite_num)
   c = WWSprite_GetCharacter(s);
   ret |= WWCharacter_GetNumber(c);
 
-  WonxDisplay_Flush(wonx_display);
+  WonxDisplay_Sync(wonx_display);
 
-  printf("return value = 0x%04x\n", (int)ret); fflush(stdout);
+  printf("call : sprite_get_char() : return value = 0x%04x\n", (int)ret);
+  fflush(stdout);
 
   return (ret);
 }
@@ -527,7 +552,7 @@ void sprite_set_location(unsigned int sprite_num, int x, int y)
 {
   WWSprite s;
 
-  printf("call : sprite_set_location() : number = %u, x = %d, y = %d, ",
+  printf("call : sprite_set_location() : number = %u, x = %d, y = %d\n",
 	 (int)sprite_num, x, y); fflush(stdout);
 
   if (wonx_display == NULL) Wonx_Create();
@@ -537,7 +562,8 @@ void sprite_set_location(unsigned int sprite_num, int x, int y)
 
   WonxDisplay_Flush(wonx_display);
 
-  printf("return value = none\n"); fflush(stdout);
+  printf("call : sprite_set_location() : return value = none\n");
+  fflush(stdout);
 
   return;
 }
@@ -547,21 +573,19 @@ unsigned int sprite_get_location(unsigned int sprite_num)
   WWSprite s;
   unsigned short int ret;
 
-  printf("call : sprite_get_location() : number = %u, ", (int)sprite_num);
+  printf("call : sprite_get_location() : number = %u\n", (int)sprite_num);
   fflush(stdout);
 
   if (wonx_display == NULL) Wonx_Create();
 
   s = WWDisplay_GetSprite(WonxDisplay_GetWWDisplay(wonx_display), sprite_num);
-  ret = 0;
 
-  /* これは本当か? 逆では? */
-  ret |= WWSprite_GetX(s) << 8;
-  ret |= WWSprite_GetY(s);
+  ret = (WWSprite_GetY(s) << 8) | WWSprite_GetX(s);
 
-  WonxDisplay_Flush(wonx_display);
+  WonxDisplay_Sync(wonx_display);
 
-  printf("return value = 0x%04x\n", (int)ret); fflush(stdout);
+  printf("call : sprite_get_location() : return value = 0x%04x\n", (int)ret);
+  fflush(stdout);
 
   return (ret);
 }
@@ -571,7 +595,7 @@ void sprite_set_char_location(unsigned int sprite_num,
 {
   if (wonx_display == NULL) Wonx_Create();
 
-  printf("call : sprite_set_char_location() : number = %u, data = 0x%04x, x = %d, y = %d, ",
+  printf("call : sprite_set_char_location() : number = %u, data = 0x%04x, x = %d, y = %d\n",
 	 (int)sprite_num, (int)data, x, y); fflush(stdout);
 
   sprite_set_char(sprite_num, data);
@@ -579,7 +603,8 @@ void sprite_set_char_location(unsigned int sprite_num,
 
   WonxDisplay_Flush(wonx_display);
 
-  printf("return value = none\n"); fflush(stdout);
+  printf("call : sprite_set_char_location() : return value = none\n");
+  fflush(stdout);
 
   return;
 }
@@ -588,19 +613,20 @@ unsigned long int sprite_get_char_location(unsigned int sprite_num)
 {
   unsigned long int ret;
 
-  printf("call : sprite_get_char_location() : number = %u, ", (int)sprite_num);
+  printf("call : sprite_get_char_location() : number = %u\n", (int)sprite_num);
   fflush(stdout);
 
   if (wonx_display == NULL) Wonx_Create();
 
   ret = 0;
-  /* これは本当か? 逆では? */
-  ret |= sprite_get_char(sprite_num) << 16;
-  ret |= sprite_get_location(sprite_num);
+  ret |= ((unsigned long int)sprite_get_char(sprite_num));
+  ret |= (unsigned long int)sprite_get_location(sprite_num) << 16;
 
-  WonxDisplay_Flush(wonx_display);
+  WonxDisplay_Sync(wonx_display);
 
-  printf("return value = 0x%08x\n", (int)ret); fflush(stdout);
+  printf("call : sprite_get_char_location() : return value = 0x%08x\n",
+	 (int)ret);
+  fflush(stdout);
 
   return (ret);
 }
@@ -611,7 +637,7 @@ void sprite_set_data(unsigned int sprite_num, unsigned int count, void * data)
   char * d;
   unsigned long int * n;
 
-  printf("call : sprite_set_data() : number = %u, count = %u, data = %p",
+  printf("call : sprite_set_data() : number = %u, count = %u, data = %p\n",
 	 (int)sprite_num, (int)count, data); fflush(stdout);
 
   if (wonx_display == NULL) Wonx_Create();
@@ -626,7 +652,7 @@ void sprite_set_data(unsigned int sprite_num, unsigned int count, void * data)
 
   WonxDisplay_Flush(wonx_display);
 
-  printf("return value = none\n"); fflush(stdout);
+  printf("call : sprite_set_data() : return value = none\n"); fflush(stdout);
 
   return;
 }
@@ -635,7 +661,7 @@ void screen_set_scroll(int screen, int x, int y)
 {
   WWScreen s;
 
-  printf("call : screen_set_scroll() : scsreen = %d, x = %d, y = %d, ",
+  printf("call : screen_set_scroll() : screen = %d, x = %d, y = %d\n",
 	 screen, x, y); fflush(stdout);
 
   if (wonx_display == NULL) Wonx_Create();
@@ -646,7 +672,7 @@ void screen_set_scroll(int screen, int x, int y)
 
   WonxDisplay_Flush(wonx_display);
 
-  printf("return value = none\n"); fflush(stdout);
+  printf("call : screen_set_scroll() : return value = none\n"); fflush(stdout);
 
   return;
 }
@@ -656,7 +682,7 @@ unsigned int screen_get_scroll(int screen)
   unsigned short int ret;
   WWScreen s;
 
-  printf("call : screen_get_scroll() : screen = %d, ", screen); fflush(stdout);
+  printf("call : screen_get_scroll() : screen = %d\n", screen); fflush(stdout);
 
   if (wonx_display == NULL) Wonx_Create();
 
@@ -666,9 +692,10 @@ unsigned int screen_get_scroll(int screen)
   ret |= WWScreen_GetRollX(s);
   ret |= WWScreen_GetRollY(s) << 8;
 
-  WonxDisplay_Flush(wonx_display);
+  WonxDisplay_Sync(wonx_display);
 
-  printf("return value = %u\n", (int)ret); fflush(stdout);
+  printf("call : screen_get_scroll() : return value = %u\n", (int)ret);
+  fflush(stdout);
 
   return (ret);
 }
@@ -677,7 +704,7 @@ void screen2_set_window(int x, int y, int w, int h)
 {
   WWScreen s;
 
-  printf("call : screen2_set_window() : x = %d, y = %d, width = %d, height = %d, ",
+  printf("call : screen2_set_window() : x = %d, y = %d, width = %d, height = %d\n",
 	 x, y, w, h); fflush(stdout);
 
   if (wonx_display == NULL) Wonx_Create();
@@ -690,7 +717,8 @@ void screen2_set_window(int x, int y, int w, int h)
 
   WonxDisplay_Flush(wonx_display);
 
-  printf("return value = none\n"); fflush(stdout);
+  printf("call : screen2_set_window() : return value = none\n");
+  fflush(stdout);
 
   return;
 }
@@ -704,39 +732,79 @@ unsigned long int screen2_get_window(void)
 
   if (wonx_display == NULL) Wonx_Create();
 
-  printf("call : screen2_get_window() : "); fflush(stdout);
+  printf("call : screen2_get_window() : \n"); fflush(stdout);
 
   s = WWDisplay_GetScreen(WonxDisplay_GetWWDisplay(wonx_display), SCREEN2);
-  
+
   xy =
-    ((WWScreen_GetDrawY(s) << 8) & 0xff00) |
-    (WWScreen_GetDrawX(s) & 0x00ff);
+    (((unsigned short int)WWScreen_GetDrawY(s) << 8) & 0xff00) |
+    ((unsigned short int)WWScreen_GetDrawX(s) & 0x00ff);
   wh =
-    ((WWScreen_GetDrawHeight(s) << 8) & 0xff00) |
-    (WWScreen_GetDrawWidth(s) & 0x00ff);
+    (((unsigned short int)WWScreen_GetDrawHeight(s) << 8) & 0xff00) |
+    ((unsigned short int)WWScreen_GetDrawWidth(s) & 0x00ff);
   ret = ((unsigned long int)wh) << 16 | xy;
 
-  WonxDisplay_Flush(wonx_display);
+  WonxDisplay_Sync(wonx_display);
 
-  printf("return value = 0x%08x\n", (int)ret); fflush(stdout);
+  printf("call : screen2_get_window() : return value = 0x%08x\n", (int)ret);
+  fflush(stdout);
 
   return (ret);
 }
 
 void sprite_set_window(int x, int y, int w, int h)
 {
+  WWDisplay d;
+
+  printf("call : sprite_set_window() : x = %d, y = %d, w = %d, h = %d\n",
+	 x, y, w, h);
+  fflush(stdout);
+
   if (wonx_display == NULL) Wonx_Create();
-  /* あとで書くこと */
+
+  d = WonxDisplay_GetWWDisplay(wonx_display);
+
+  WWDisplay_SetSpriteWindowX(d, x);
+  WWDisplay_SetSpriteWindowY(d, y);
+  WWDisplay_SetSpriteWindowWidth(d, w);
+  WWDisplay_SetSpriteWindowHeight(d, h);
 
   WonxDisplay_Flush(wonx_display);
+
+  printf("call : sprite_set_window() : return value = none\n");
+  fflush(stdout);
+
+  return;
 }
 
 unsigned long int sprite_get_window(void)
 {
+  WWDisplay d;
+  unsigned short int xy;
+  unsigned short int wh;
+  unsigned long int ret;
+
+  printf("call : sprite_get_window() : \n");
+  fflush(stdout);
+
   if (wonx_display == NULL) Wonx_Create();
-  /* あとで書くこと */
 
-  WonxDisplay_Flush(wonx_display);
+  d = WonxDisplay_GetWWDisplay(wonx_display);
+
+  xy =
+    (((unsigned short int)WWDisplay_GetSpriteWindowY(d) << 8) & 0xff00) |
+    ((unsigned short int)WWDisplay_GetSpriteWindowX(d) & 0x00ff);
+  wh =
+    (((unsigned short int)WWDisplay_GetSpriteWindowHeight(d) << 8) & 0xff00) |
+    ((unsigned short int)WWDisplay_GetSpriteWindowWidth(d) & 0x00ff);
+  ret = ((unsigned long int)wh) << 16 | xy;
+
+  WonxDisplay_Sync(wonx_display);
+
+  printf("call : sprite_get_window() : return value = 0x%08x\n", (int)ret);
+  fflush(stdout);
+
+  return (ret);
 }
 
 void palette_set_color(unsigned int palette_num,
@@ -745,7 +813,7 @@ void palette_set_color(unsigned int palette_num,
   int mapped_colors[4];
   WWPalette palette;
 
-  printf("call : palette_set_color() : number = %u, colors = 0x%04x, ",
+  printf("call : palette_set_color() : number = %u, colors = 0x%04x\n",
 	 (int)palette_num, (int)colors); fflush(stdout);
 
   if (wonx_display == NULL) Wonx_Create();
@@ -761,7 +829,7 @@ void palette_set_color(unsigned int palette_num,
 
   WonxDisplay_Flush(wonx_display);
 
-  printf("return value = none\n"); fflush(stdout);
+  printf("call : palette_set_color() : return value = none\n"); fflush(stdout);
 
   return;
 }
@@ -772,7 +840,7 @@ unsigned int palette_get_color(unsigned int palette_num)
   WWPalette palette;
   unsigned short int ret;
 
-  printf("call : palette_get_color() : number = %u, ", (int)palette_num);
+  printf("call : palette_get_color() : number = %u\n", (int)palette_num);
   fflush(stdout);
 
   if (wonx_display == NULL) Wonx_Create();
@@ -787,9 +855,10 @@ unsigned int palette_get_color(unsigned int palette_num)
   ret |= (mapped_colors[2] & 0x07) <<  8;
   ret |= (mapped_colors[3] & 0x07) << 12;
 
-  WonxDisplay_Flush(wonx_display);
+  WonxDisplay_Sync(wonx_display);
 
-  printf("return value = %u\n", (int)ret); fflush(stdout);
+  printf("call : palette_get_color() : return value = %u\n", (int)ret);
+  fflush(stdout);
 
   return (ret);
 }
@@ -799,7 +868,7 @@ void lcd_set_color(unsigned int colors0, unsigned int colors1)
   WWColorMap color_map;
   int lcd_colors[8];
 
-  printf("call : lcd_set_color() : colors0 = 0x%04x, colors1 = 0x%04x, ",
+  printf("call : lcd_set_color() : colors0 = 0x%04x, colors1 = 0x%04x\n",
 	 (int)colors0, (int)colors1); fflush(stdout);
 
   if (wonx_display == NULL) Wonx_Create();
@@ -818,7 +887,7 @@ void lcd_set_color(unsigned int colors0, unsigned int colors1)
 
   WonxDisplay_Flush(wonx_display);
 
-  printf("return value = none\n"); fflush(stdout);
+  printf("call : lcd_set_color() : return value = none\n"); fflush(stdout);
 
   return;
 }
@@ -829,7 +898,7 @@ unsigned long int lcd_get_color(void)
   int lcd_colors[8];
   unsigned long int ret;
 
-  printf("call : lcd_get_color() : "); fflush(stdout);
+  printf("call : lcd_get_color() : \n"); fflush(stdout);
 
   if (wonx_display == NULL) Wonx_Create();
 
@@ -837,18 +906,19 @@ unsigned long int lcd_get_color(void)
   WWColorMap_GetLCDColors(color_map, lcd_colors);
 
   ret = 0;
-  ret |=  lcd_colors[0] & 0x0f;
-  ret |= (lcd_colors[1] & 0x0f) <<  4;
-  ret |= (lcd_colors[2] & 0x0f) <<  8;
-  ret |= (lcd_colors[3] & 0x0f) << 12;
-  ret |=  lcd_colors[0] & 0x0f;
-  ret |= (lcd_colors[1] & 0x0f) <<  4;
-  ret |= (lcd_colors[2] & 0x0f) <<  8;
-  ret |= (lcd_colors[3] & 0x0f) << 12;
-
-  WonxDisplay_Flush(wonx_display);
-
-  printf("return value = 0x%08x\n", (int)ret); fflush(stdout);
+  ret |=  (unsigned long int)lcd_colors[0] & 0x0f;
+  ret |= ((unsigned long int)lcd_colors[1] & 0x0f) <<  4;
+  ret |= ((unsigned long int)lcd_colors[2] & 0x0f) <<  8;
+  ret |= ((unsigned long int)lcd_colors[3] & 0x0f) << 12;
+  ret |=  (unsigned long int)lcd_colors[0] & 0x0f;
+  ret |= ((unsigned long int)lcd_colors[1] & 0x0f) <<  4;
+  ret |= ((unsigned long int)lcd_colors[2] & 0x0f) <<  8;
+  ret |= ((unsigned long int)lcd_colors[3] & 0x0f) << 12;
+
+  WonxDisplay_Sync(wonx_display);
+
+  printf("call : lcd_get_color() : return value = 0x%08x\n", (int)ret);
+  fflush(stdout);
 
   return (ret);
 }
@@ -866,7 +936,7 @@ unsigned lcd_get_segments(void)
   if (wonx_display == NULL) Wonx_Create();
   /* セグメント表示は未サポートか? */
 
-  WonxDisplay_Flush(wonx_display);
+  WonxDisplay_Sync(wonx_display);
 }
 
 void lcd_set_sleep(unsigned sleep)
@@ -874,7 +944,7 @@ void lcd_set_sleep(unsigned sleep)
   if (wonx_display == NULL) Wonx_Create();
   /* ? */
 
-  WonxDisplay_Flush(wonx_display);
+  WonxDisplay_Sync(wonx_display);
 }
 
 unsigned lcd_get_sleep(void)
@@ -882,21 +952,21 @@ unsigned lcd_get_sleep(void)
   if (wonx_display == NULL) Wonx_Create();
   /* ? */
 
-  WonxDisplay_Flush(wonx_display);
+  WonxDisplay_Sync(wonx_display);
 }
 
 void screen_set_vram(int screen, int locationID)
 {
   if (wonx_display == NULL) Wonx_Create();
 
-  WonxDisplay_Flush(wonx_display);
+  WonxDisplay_Sync(wonx_display);
 }
 
 void sprite_set_vram(int locationID)
 {
   if (wonx_display == NULL) Wonx_Create();
 
-  WonxDisplay_Flush(wonx_display);
+  WonxDisplay_Sync(wonx_display);
 }
 
 /*****************************************************************************/

+ 14 - 0
key.c

@@ -21,6 +21,8 @@ int key_press_check(void)
 
   ret = XDisplay_GetKeyPress(x_display);
 
+  WonxDisplay_Sync(wonx_display);
+
   printf("return value = 0x%04x\n", (int)ret); fflush(stdout);
 
   return (ret);
@@ -40,6 +42,8 @@ int key_hit_check(void)
 
   ret = XDisplay_GetKeyPress(x_display);
 
+  WonxDisplay_Sync(wonx_display);
+
   printf("return value = 0x%04x\n", (int)ret); fflush(stdout);
 
   return (ret);
@@ -62,6 +66,8 @@ int key_wait(void)
     ret = XDisplay_GetKeyPress(x_display);
   } while (ret == 0);
 
+  WonxDisplay_Sync(wonx_display);
+
   printf("return value = 0x%04x\n", (int)ret); fflush(stdout);
 
   return (ret);
@@ -74,7 +80,11 @@ void key_set_repeat(int rate, int delay)
 
   if (wonx_display == NULL) Wonx_Create();
 
+  WonxDisplay_Sync(wonx_display);
+
   printf("return value = none\n"); fflush(stdout);
+
+  return;
 }
 
 int key_get_repeat(void)
@@ -87,6 +97,8 @@ int key_get_repeat(void)
 
   ret = 0;
 
+  WonxDisplay_Sync(wonx_display);
+
   printf("return value = 0x%04x\n", (int)ret); fflush(stdout);
 
   return (ret);
@@ -106,6 +118,8 @@ int key_hit_check_with_repeat(void)
 
   ret = XDisplay_GetKeyPress(x_display);
 
+  WonxDisplay_Sync(wonx_display);
+
   printf("return value = 0x%04x\n", (int)ret); fflush(stdout);
 
   return (ret);

+ 171 - 13
timer.c

@@ -1,4 +1,5 @@
 #include <stdlib.h>
+#include <time.h>
 
 #include <sys/timer.h>
 
@@ -6,28 +7,185 @@
 
 #include "WonxDisplay.h"
 
+typedef struct {
+  unsigned char year;
+  unsigned char month;
+  unsigned char date;
+  unsigned char day_of_week;
+  unsigned char hour;
+  unsigned char minute;
+  unsigned char second;
+} datetime_t;
+
+/* int tm_year; year - 1900 */
+static int get_year(struct tm * tblock) { return (tblock->tm_year - 100); }
+/* int tm_mon; month of year (0-11) */
+static int get_month(struct tm * tblock) { return (tblock->tm_mon + 1); }
+/* int tm_mday; day of month (1-31) */
+static int get_day(struct tm * tblock) { return (tblock->tm_mday); }
+/* int tm_wday; day of week (Sunday = 0) */
+static int get_week(struct tm * tblock) { return (tblock->tm_wday); }
+/* int tm_hour; hours (0 - 23) */
+static int get_hour(struct tm * tblock) { return (tblock->tm_hour); }
+/* int tm_min; minutes (0 - 59) */
+static int get_minute(struct tm * tblock) { return (tblock->tm_min); }
+/* int tm_sec; seconds (0 - 60) */
+static int get_second(struct tm * tblock) { return (tblock->tm_sec); }
+
 void rtc_set_datetime(int field, unsigned int value)
 {
+  printf("call : rtc_set_datetime() : field = %d, value = %d\n",
+	 field, (int)value);
+  fflush(stdout);
+
+  /* 未サポート */
+  printf("call : rtc_set_datetime() : not supported\n");
+
+  printf("call : rtc_set_datetime() : return value = none\n");
+  fflush(stdout);
+
+  return;
 }
 
 unsigned int rtc_get_datetime(int field)
 {
-  unsigned int t;
-  t = (unsigned int)time(NULL); /* ここはてきとうなので,あとで修正すること */
-  return (t);
+  unsigned int ret;
+  time_t timer;
+  struct tm * tblock;
+
+  printf("call : rtc_get_datetime() : field = %d\n", field);
+  fflush(stdout);
+
+  time(&timer);
+  tblock = localtime(&timer);
+
+  switch (field) {
+  case RTC_YEAR        : ret = get_year(  tblock); break;
+  case RTC_MONTH       : ret = get_month( tblock); break;
+  case RTC_DATE        : ret = get_day(   tblock); break;
+  case RTC_DAY_OF_WEEK : ret = get_week(  tblock); break;
+  case RTC_HOUR        : ret = get_hour(  tblock); break;
+  case RTC_MIN         : ret = get_minute(tblock); break;
+  case RTC_SEC         : ret = get_second(tblock); break;
+  }
+
+  printf("call : rtc_get_datetime() : return value = %d\n", (int)ret);
+  fflush(stdout);
+
+  return (ret);
+}
+
+void rtc_set_datetime_struct(void * buffer)
+{
+  printf("call : rtc_set_datetime_struct() : buffer = %p\n", buffer);
+  fflush(stdout);
+
+  /* 未サポート */
+  printf("call : rtc_set_datetime_struct() : not supported\n");
+
+  printf("call : rtc_set_datetime_struct() : return value = none\n");
+  fflush(stdout);
+
+  return;
+}
+
+void rtc_get_datetime_struct(void * buffer)
+{
+  time_t timer;
+  struct tm * tblock;
+  datetime_t * p;
+
+  printf("call : rtc_get_datetime_struct() : buffer = %p\n", buffer);
+  fflush(stdout);
+
+  time(&timer);
+  tblock = localtime(&timer);
+
+  p = (datetime_t *)buffer;
+
+  p->year = get_year(tblock);
+  p->month = get_month(tblock);
+  p->date = get_day(tblock);
+  p->day_of_week = get_week(tblock);
+  p->hour = get_hour(tblock);
+  p->minute = get_minute(tblock);
+  p->second = get_second(tblock);
+
+  printf("call : rtc_get_datetime_struct() : return value = none\n");
+  fflush(stdout);
+
+  return;
+}
+
+void rtc_enable_alarm(int hour, int minute)
+{
+  printf("call : rtc_enable_alarm() : hour = %d, minute = %d\n", hour, minute);
+  fflush(stdout);
+
+  /* 未サポート */
+  printf("call : rtc_enable_alarm() : not supported\n");
+
+  printf("call : rtc_enable_alarm() : return value = none\n");
+  fflush(stdout);
+
+  return;
 }
 
-void rtc_set_datetime_struct(void * buf)
-{}
-void rtc_get_datetime_struct(void * buf)
-{}
-void rtc_enable_alarm(int hour, int min)
-{}
 void rtc_disable_alarm(void)
-{}
+{
+  printf("call : rtc_disable_alarm() : \n");
+  fflush(stdout);
+
+  /* 未サポート */
+  printf("call : rtc_disable_alarm() : not supported\n");
+
+  printf("call : rtc_disable_alarm() : return value = none\n");
+  fflush(stdout);
+
+  return;
+}
+
 void timer_enable(int type, unsigned int auto_preset, unsigned int preset)
-{}
+{
+  printf("call : timer_enable() : type = %d, auto_preset = %u, preset = %u\n",
+	 type, (int)auto_preset, (int)preset);
+  fflush(stdout);
+
+  /* 未サポート */
+  printf("call : timer_enable() : not supported\n");
+
+  printf("call : timer_enable() : return value = none\n");
+  fflush(stdout);
+
+  return;
+}
+
 void timer_disable(int type)
-{}
+{
+  printf("call : timer_disable() : type = %d\n", type);
+  fflush(stdout);
+
+  /* 未サポート */
+  printf("call : timer_disable() : not supported\n");
+
+  printf("call : timer_disable() : return value = none\n");
+  fflush(stdout);
+
+  return;
+}
+
 unsigned int timer_get_count(int type)
-{}
+{
+  unsigned int ret = 0;
+
+  printf("call : timer_get_count() : type = %d\n", type);
+  fflush(stdout);
+
+  /* 未サポート */
+  printf("call : timer_get_count() : not supported\n");
+
+  printf("call : timer_get_count() : return value = %u\n", ret);
+  fflush(stdout);
+
+  return;
+}