Browse Source

Added dummy function of _asm_*().
Set FP_OFF ​(), FP_SEG() for the callback function at interrupt setting in WonderWitch
Adjust appropriately according to the setting method. (Fit to wwterm)

UNIXTimer.c: UNIXTimer_Unpause()
((unix_timer -> pause == 1) && (unix_timer -> interrupt_in_pause == 0))
Fixed a bug that was not unix_timer-> pause--; when it was.
(It was not unposted when interrupt was not applied during pause)

Serial receive interrupt, keyboard interrupt added. (corresponding to wwterm, operation confirmed)
Added UNIXSerialPort class.

With this, at WonderWitch,
com_intvector.callback = (void (near *) ()) FP_OFF ​​(com_handler);
com_intvector.cs = _ asm_inline ("\tmov \tax, cs");
com_intvector.ds = _ asm_inline ("\tmov \tax, ds");
sys_interrupt_set_hook (SYS_INT_RECEIVEREADY,
& com_intvector, & com_last_intvector);
Interrupt setting like that shown in Fig.

For warning, add WonX_Warning ().
Move WonX_Error () to WonX.c.

comm_send_string (), text_put_string (), text_put_substring () When executed
Fix output message.

Implement cursor display function. (Add WWCursor class) (Do not blink. Display only)
When displaying the cursor, text information inside WWDisplay_DrawLCDPanel ()
Since we need to be able to read it, we will discontinue the WonXText class and add the WWText class
I moved to a member of the WWDisplay class.

In palette_get_color (), transparent color is displayed when executing WWPalette_GetMappedColors ()
Since it was not considered to be returned as -1, palette_get_color ()
Fixed a bug where return value was wrong value.

Character color palette, LCD color palette initial value, with WonderWitch
It was made to coincide with the initial value.

As a sample, add wwterm - b 05. (Add wwterm target to Makefile)

Version 1.1 - from wonx-1.1.tar.gz

Hiroaki Sakai 23 years ago
parent
commit
c0b964b4f4
60 changed files with 1570 additions and 364 deletions
  1. 47 0
      HISTORY
  2. 10 10
      MANUAL
  3. 17 5
      Makefile
  4. 198 11
      README
  5. 180 0
      UNIXSerialPort.c
  6. 82 0
      UNIXSerialPort.h
  7. 6 6
      UNIXSerialPortP.h
  8. 7 1
      UNIXTimer.c
  9. 7 3
      UNIXTimer.h
  10. 1 1
      WWCharacter.c
  11. 7 3
      WWCharacter.h
  12. 1 1
      WWColorMap.c
  13. 7 3
      WWColorMap.h
  14. 67 0
      WWCursor.c
  15. 57 0
      WWCursor.h
  16. 10 12
      WWCursorP.h
  17. 69 8
      WWDisplay.c
  18. 18 7
      WWDisplay.h
  19. 2 0
      WWDisplayP.h
  20. 1 1
      WWInterrupt.c
  21. 9 5
      WWInterrupt.h
  22. 1 1
      WWLCDPanel.c
  23. 6 2
      WWLCDPanel.h
  24. 2 1
      WWPalette.c
  25. 7 3
      WWPalette.h
  26. 14 3
      WWScreen.c
  27. 11 6
      WWScreen.h
  28. 6 6
      WWSerialPort.c
  29. 17 9
      WWSerialPort.h
  30. 1 1
      WWSerialPortP.h
  31. 7 5
      WWSprite.c
  32. 9 5
      WWSprite.h
  33. 3 3
      WWText.c
  34. 8 4
      WWText.h
  35. 1 1
      WWTimer.c
  36. 9 5
      WWTimer.h
  37. 19 22
      WonX.c
  38. 11 6
      WonX.h
  39. 1 1
      WonXDisplay.c
  40. 11 3
      WonXDisplay.h
  41. 0 1
      WonXP.h
  42. 25 6
      WonXSerialPort.c
  43. 14 5
      WonXSerialPort.h
  44. 1 0
      WonXSerialPortP.h
  45. 49 1
      WonXSystem.c
  46. 8 4
      WonXSystem.h
  47. 0 55
      WonXText.c
  48. 9 5
      XDisplay.h
  49. 100 70
      comm.c
  50. 12 6
      disp.c
  51. 16 12
      etc.c
  52. 7 5
      etc.h
  53. 36 0
      makefile_for_wwterm
  54. 52 0
      service.c
  55. 2 1
      sout2str.pl
  56. 0 7
      system.c
  57. 224 20
      text.c
  58. 68 0
      wonx_include/service.h
  59. 0 2
      wonx_include/system.h
  60. BIN
      wwterm-b05.zip

+ 47 - 0
HISTORY

@@ -1,3 +1,50 @@
+2000/12/28(木)
+
+wonx-1.1 公開
+
+_asm_*() のダミー関数を追加.
+FP_OFF(), FP_SEG() を,WonderWitch での割り込み設定時のコールバック関数の
+設定方法にあわせて,適切に変更.(wwterm に合わせた)
+
+UNIXTimer.c:UNIXTimer_Unpause() で,
+((unix_timer->pause == 1) && (unix_timer->interrupt_in_pause == 0))
+だったときに unix_timer->pause--; されないバグを修正.
+(ポーズ中に割り込みがかからなかった場合に,アンポーズされていなかった)
+
+シリアル受信割り込み,キーボード割り込み追加.(wwterm に対応,動作確認済)
+UNIXSerialPort クラス追加.
+
+これにより,WonderWitch での,
+  com_intvector.callback = (void (near *)())FP_OFF(com_handler);
+  com_intvector.cs = _asm_inline("\tmov\tax,cs");
+  com_intvector.ds = _asm_inline("\tmov\tax,ds");
+  sys_interrupt_set_hook(SYS_INT_RECEIVEREADY,
+                         &com_intvector, &com_last_intvector);
+のような割り込みの設定が正しく実行されるようになった.
+
+ワーニング用に,WonX_Warning() 追加.
+WonX_Error() を WonX.c に移動.
+
+comm_send_string(), text_put_string(), text_put_substring() 実行時の
+出力メッセージを修正.
+
+カーソル表示機能を実装.(WWCursor クラス追加)(点滅はしない.表示のみ)
+カーソル表示をする際に,WWDisplay_DrawLCDPanel() 内部でテキスト情報が
+読める必要があるので,WonXText クラスを廃止して,WWText クラスを
+WWDisplay クラスのメンバに移動した.
+
+palette_get_color() 内で,WWPalette_GetMappedColors() の実行時に透明色が
+-1として返されることを考慮していなかったために,palette_get_color() の
+戻り値がおかしな値になっていたバグを修正.
+
+キャラクタカラーパレット,LCDカラーパレットの初期値を,WonderWitch での
+初期値と一致させた.
+
+サンプルとして,wwterm-b05 を追加.(Makefile に wwterm ターゲットを追加)
+
+
+
+
 2000/11/23(木)
 
 wonx-1.0 公開

+ 10 - 10
MANUAL

@@ -29,23 +29,23 @@ WonderWitch 
                                              ├─  WWCharacter[512]
                              ┌─WWDisplay ─┼─  WWSprite[128]
        ┌─ WonXDisplay  ──┤              ├─  WWScreen[2]
-       │                    └─XDisplay    └─  WWLCDPanel
-       │     
+       │                    └─XDisplay    ├─  WWLCDPanel
+       │                                    ├─  WWText
+       │                                    └─  WWCursor
        │                    ┌─  WWInterrupt
-─ WonXSystem ───┼─  WWTimer[3]
+WonX ─┼─ WonXSystem ───┼─  WWTimer[3]
        │                    └─  UNIXTimer
-WonX ─┤
-       │     
-       ├─ WonXText ──────  WWText
-       └─ WonXSerialPort ─── WWSerialPort
+       │                    ┌─ WWSerialPort
+       └─ WonXSerialPort ─┤
+                             └─ UNIXSerialPort
 
 WW という接頭語がつくクラスは WonderWitch 依存のものです.主に
 WonderSwan の状態情報を格納します.
 X という接頭語がつくクラスは X 依存のもの,UNIX という接頭語がつくクラスは
 UNIX 依存のものです.
-Wonx という接頭語がつくクラスはそれらを統括するものです.
+WonX という接頭語がつくクラスはそれらを統括するものです.
 
 ツリー構造を理解したかったら,各クラスの *P.h ファイルのメンバの定義と,
 *.c ファイルの *_Create() 関数を参照してください.
@@ -56,8 +56,8 @@ Wonx 
 関数が用意されています.
 
 WonX_Create() が呼ばれると,内部で WonXDisplay_Create(), WonXSystem_Create(),
-WonXText_Create(), WonXSerialPort_Create() が呼ばれ,子の WonXDisplay,
-WonXSystem, WonXText, WonXSerialPort オブジェクトが生成されます.
+WonXSerialPort_Create() が呼ばれ,子の WonXDisplay, WonXSystem,
+WonXSerialPort オブジェクトが生成されます.
 WonXDisplay_Create() が呼ばれると,内部で WWDisplay_Create(),
 XDisplay_Create() が呼ばれ,... というように続いて,すべてのツリーか
 生成されます.

+ 17 - 5
Makefile

@@ -2,12 +2,13 @@ XINCLUDEDIR = /usr/X11R6/include
 INCLUDEDIR = .
 XLIBDIR = /usr/X11R6/lib
 
-VERSION = WonX-1.0
-PKGNAME = wonx-1.0
+VERSION = WonX-1.1
+PKGNAME = wonx-1.1
 
 SMAC = smac-b02
+WWTERM = wwterm-b05
 
-OBJS = WWCharacter.o WWColorMap.o WWDisplay.o WWLCDPanel.o WWPalette.o WWScreen.o WWSprite.o WWText.o WWInterrupt.o WWTimer.o WWSerialPort.o WonX.o WonXDisplay.o WonXText.o WonXSystem.o WonXSerialPort.o XDisplay.o UNIXTimer.o bank.o comm.o disp.o text.o key.o sound.o system.o timer.o etc.o
+OBJS = WWCharacter.o WWColorMap.o WWDisplay.o WWLCDPanel.o WWPalette.o WWScreen.o WWSprite.o WWCursor.o WWText.o WWInterrupt.o WWTimer.o WWSerialPort.o WonX.o WonXDisplay.o WonXSystem.o WonXSerialPort.o XDisplay.o UNIXTimer.o UNIXSerialPort.o bank.o comm.o disp.o text.o key.o sound.o system.o timer.o service.o etc.o
 
 CC = gcc
 
@@ -44,13 +45,24 @@ smac :		libwonx.a
 		cd $(SMAC) ; ./sys2wonx.pl *.[ch]
 		cd $(SMAC) ; $(MAKE)
 
+wwterm :	libwonx.a
+		unzip $(WWTERM).zip
+		cp -R wonx_include $(WWTERM)
+		cp libwonx.a $(WWTERM)
+		mv $(WWTERM)/makefile $(WWTERM)/makefile.orig
+		cp makefile_for_wwterm $(WWTERM)/makefile
+		cp sys2wonx.pl $(WWTERM)
+		echo "ここで止まったときは,sys2wonx.pl の1行目に適切なperlを指定してください"
+		cd $(WWTERM) ; ./sys2wonx.pl *.[ch]
+		cd $(WWTERM) ; $(MAKE)
+
 package :
 		mkdir -p $(PKGNAME)
 		rm -fR $(PKGNAME)/*
 		mkdir -p $(PKGNAME)/wonx_include
 		cp COPYING COPYRIGHT HISTORY README MANUAL OMAKE.jpn Makefile \
-			makefile_for_smac *.pl \
-			*.h *.c smac*.zip $(PKGNAME)
+			makefile_for_smac makefile_for_wwterm *.pl \
+			*.h *.c $(SMAC).zip $(WWTERM).zip $(PKGNAME)
 		cp wonx_include/*.h $(PKGNAME)/wonx_include
 		tar cvzf $(PKGNAME).tar.gz $(PKGNAME)
 

+ 198 - 11
README

@@ -57,7 +57,7 @@ WonX 
 サンプルプログラムをコンパイル・実行してみましょう.
 以下のようにしてみてください.
 
-~>% tar xvzf wonx.tgz
+~>% tar xvzf wonx-x.x.tar.gz
 (中略)
 ~>% cd wonx
 
@@ -100,6 +100,85 @@ smac 
 p を押して頻繁に描画の ON, OFF を切替えるのは,描画が非常に遅いため,
 ONのままだと画面クリアとかに異常に時間がかかるからです.
 
+最後に,WonderWitch 用の端末エミュレータ "WWTerm" をコンパイル・実行
+してみます.
+
+~/wonx>% make wwterm
+(中略)
+~/wonx>% cd wwterm
+~/wonx/smac>% ./terminal
+
+■ 10分WonX
+
+次に,なにかあなたが作った WonderWitch 用のプログラムを WonX 使って
+コンパイル・リンクして,X Window System 上で動作するような実行形式を
+作ってみましょう.
+
+まず,WonX を展開して,make してください.libwonx.a ができあがります.
+
+~>% tar xvzf wonx-x.x.tar.gz
+(中略)
+~>% cd wonx
+~/wonx>% make
+(中略)
+~/wonx>% ls libwonx.a
+libwonx.a
+~/wonx>% 
+
+次に,libwonx.a と,wonx_include ディレクトリと,sys2wonx.pl を
+あなたの作ったプログラムのディレクトリ(ここでは例として,yoursample とします)
+にコピーします.
+
+~/wonx>% cp -R libwonx.a wonx_include sys2wonx.pl ../yoursample
+~/wonx>% cd ../yoursample
+~/yoursample>% 
+
+あなたの作ったプログラムのすべてのファイルを,MS-DOS テキスト形式から
+UNIX のテキスト形式に変換します.(つまり,改行コードを \r\n から \n に
+変換して,漢字コードを SJIS から EUC に変換します)
+
+~/yoursample>% cat makefile | qkc -I -O -e -u > makefile.new
+~/yoursample>% mv makefile.new makefile
+~/yoursample>% cat sample.c | qkc -I -O -e -u > sample.c.new
+~/yoursample>% mv sample.c.new sample.c
+...(以下すべてのファイルについて,同様に繰り返し.中略)...
+
+*.C というファイル名のファイルがあったら,*.c に変更します.
+(*.C だと C++ のプログラムだと思われてしまうので)
+
+~/yoursample>% mv SAMPLE2.C sample2.c
+
+makefile を以下のように修正する.
+・コンパイラには gcc を使用する.
+・オブジェクトファイルを *.obj から *.o に変更.
+・コンパイルフラグに -I. -L. -L/usr/X11R6/lib -lwonx -lX11 -lXt を追加.
+・mkfent などによる *.fx ファイルの作成などがあったら,コメントアウトする.
+
+~/yoursample>% emacs makefile
+
+おそらく,makefile の修正が2番目に面倒です.(一番面倒なのは,WonX がうまく
+適用できなかったときのソースの修正です)
+添付の makefile_for_smac や makefile_for_wwterm を参考にして,makefile を
+修正してください.
+
+次に,sys2wonx.pl をかけて,プログラム中の #include <sys/disp.h> のようなのを,
+#include "wonx_include/disp.h" に変更する.
+(注意! sys2wonx.pl は,ファイルの本体を書き換えてしまうので,変更されると
+ 困るようなファイルは必ずバックアップしてください.
+ #include <sys/disp.h> のような部分が無いファイルの場合だと,読み込んで
+ そのまま出力するので,ファイルの内容自体は変わらないと思いますが,
+ 日付は変わってしまいます)
+
+~/yoursample>% ./sys2wonx.pl *.[ch]
+
+最後に,make をします.
+
+~/yoursample>% make
+
+うまくいけば,一撃でコンパイルが通って,実行できます.
+
+~/yoursample>% ./sample
+
 ■ WonX 概要
 
 WonX は,WonderWitch の display_control() とか display_status() といった
@@ -156,7 +235,7 @@ WonX 
 
 1. WonX を展開する.
 
-~>% tar xvzf wonx.tar.gz
+~>% tar xvzf wonx-x.x.tar.gz
 ~>% cd wonx
 ~/wonx>% 
 
@@ -286,7 +365,7 @@ smac 
 /* 画面のクリア */
 for (y = 0; y < 32; y++)
   for (x = 0; x < 32; x++) {
-    screen_fill_char(0, x, y, 1, 1, 0x0000); /* ここで毎回再描画される */
+    screen_fill_char(0, x, y, 1, 1, 0); /* ここで毎回再描画される */
   }
 }
 
@@ -329,8 +408,8 @@ WonX 
 関数を呼び出しても,何も起こりません.(空の関数になっている)
 
 ・サウンド
-・カーソル表示
-・その他いっぱい
+・プロセス
+・インダイレクトライブラリ
 
 ■ 注意しなければならないこと
 
@@ -344,8 +423,10 @@ UNIX 
 かなり回避できると思います.(ビットマップ操作などで,short int にすべき
 ところでは,省略せずにちゃんと short int と明示するとか)
 
-まあ,WonX の目的は論理的なバグを早い段階で無くすことにあるので,このへんは
-そういうものだと割り切って使ってください.
+まあ,WonX の目的は論理的なバグを早い段階で無くすことと,
+論理的バグとハードがらみのバグを切り離して原因を狭めることと,
+坂井が電車の中でも WonderWitch のプログラムを書けるようにすることにあるので,
+このへんはそういうものだと割り切って使ってください.
 WonX を使う限り,なるべく機種依存を無くすように心がけましょう.
 (とくに int のサイズにあまり依存しないようにしましょう)
 
@@ -386,9 +467,9 @@ font_set_colordata()
 ので,char * で定義したキャラクタデータを short int * にキャストして
 font_set_colordata()に渡すなどのことをしていると,画像がひっくり返る
 ことが考えられます.
-i386 系の PC-UNIX ならば,おそらく問題は無いでしょう.
+i386 系のいわゆる PC-UNIX ならば,おそらく問題は無いでしょう.
 
-[割り込みの問題]
+[タイマ割り込みの問題]
 
 WonderWitch にはタイマ割り込みがありますが,WonX の動作は非常に遅いため,
 WonderWitch の時間単位をそのまま UNIX に持ってきたら,割り込みが
@@ -400,6 +481,51 @@ WonderWitch 
 戻った瞬間にまたハンドラが呼ばれて,全然実行が先に進まない,ということに
 なり得ます.
 
+[キー入力割り込み,シリアル受信割り込みの問題]
+
+(あまりやることはないと思いますが)キー入力割り込みとキー入力検査用関数を
+同一ループ内で併用すると,割り込みのとりこぼしが起きやすくなる可能性が
+あります.
+つまり,以下のようなプログラムを書くときには注意してください.
+
+void far key_handler()
+{
+  /* キー入力の処理がここに入る */
+}
+
+static intvector_t key_intvector;
+static intvector_t key_last_intvector;
+
+main()
+{
+  key_intvector.callback = (void (near *)())FP_OFF(key_handler);
+  key_intvector.cs = _asm_inline("\tmov\tax,cs");
+  key_intvector.ds = _asm_inline("\tmov\tax,ds");
+
+  sys_interrupt_set_hook(SYS_INT_KEY, &key_intvector, &key_last_intvector);
+
+  while (1) {
+    /*
+     * キー入力割り込み待ちの状態なのに,key_press_check() でキー入力状態の
+     * 検査も行う
+     */
+    key = key_press_check();
+    /* なんか適当な処理をこのへんで行ったりする */
+  }
+}
+
+キー入力割り込みを待ちながら,key_press_check() でキーの入力状態を
+別個に検査する,ということをやると,割り込みのとりこぼしが起きる可能性が
+あります.
+(ただし,キー入力割り込みによって呼び出される割り込みハンドラ内で
+ key_press_check() を使用することは問題ありません.(でないと割り込みの
+ 意味が無くなってしまうしね) あくまで,同じループ内で併用すると問題が
+ 発生する可能性がある,ということです)
+
+でも,こんなへんなプログラムあまり書くこと無いだろうし,いいかなと思ってます.
+(これを直そうとすると,とてもたいへんなので)
+このことは,シリアル受信割り込みに関しても,同様です.
+
 [キー入力について]
 
 キー入力は,キー入力用関数が呼ばれたときのみ感知するので,長めに押してないと
@@ -420,6 +546,8 @@ gcc -g -o smac $(OBJS) -L. -L/usr/X11R6/lib -lwonx -lX11 -lXt
 のような行があったとして,これが MS-DOS のテキスト形式のファイルだと,
 -lXt のあとに余分な改行コード(\r)が付加されてしまうため,UNIX 上で make
 しても,「-lXt に相当するライブラリが無い」と怒られてしまいます.
+(実際にはコンパイラは,-lXt\r だと思ってしまって,libXt\r.a というライブラリを
+ 探してしまうのです)
 (しかも,ファイルを emacs や less などで参照しても,改行コードは表示されない
  ため,原因がわかりにくい)
 また,
@@ -458,7 +586,66 @@ SAMPLE.C 
 添付の sout2str.pl を通すことにより,シリアル通信への出力のみ抽出して,
 端末への出力のイメージで表示させることができます.
 
-[ソース中の WonX 依存部分のくくりかた]
+■ 割り込みについて
+
+キー入力割り込みやシリアル受信割り込みなどは,UNIXのアラームシグナルを
+利用して実装しています.(一定時間おきにポーリングしている)
+したがって,以下のようなプログラムもコンパイルして正常に動作させる
+ことができます.
+
+void far key_handler()
+{
+  int key;
+  key = key_press_check();
+  /* キー入力の処理がここに入る */
+}
+
+/* シリアル受信の割り込みハンドラ */
+void far com_handler()
+{
+  int c;
+  c = comm_receive_char();
+  /* シリアル受信の処理がここに入る */
+}
+
+static intvector_t key_intvector;
+static intvector_t key_last_intvector;
+static intvector_t com_intvector;
+static intvector_t com_last_intvector;
+
+main()
+{
+  key_intvector.callback = (void (near *)())FP_OFF(key_handler);
+  com_intvector.callback = (void (near *)())FP_OFF(com_handler);
+  key_intvector.cs = _asm_inline("\tmov\tax,cs");
+  key_intvector.ds = _asm_inline("\tmov\tax,ds");
+  com_intvector.cs = _asm_inline("\tmov\tax,cs");
+  com_intvector.ds = _asm_inline("\tmov\tax,ds");
+
+  sys_interrupt_set_hook(SYS_INT_KEY,
+                         &key_intvector, &key_last_intvector);
+  sys_interrupt_set_hook(SYS_INT_RECEIVEREADY,
+                         &com_intvector, &com_last_intvector);
+
+  while (1) {
+    /* 無限ループ.割り込みが入ったら,そのハンドラに飛ぶ */
+  }
+}
+
+_asm_inline() は常に0を返すダミー関数として定義されています.
+また,FP_OFF(), FP_SEG() は,
+#define FP_OFF(p) (p)
+#define FP_SEG(p) (0)
+のように定義されています.よって,上記のようなプログラムも WonX で
+コンパイルして実行することができます.
+
+このように,while (1) {} で無限ループを回して,割り込みがあったときだけ
+処理するようなプログラムを書いても,正常に動作します.
+しかし,キー入力はポーリングされているときしか感知されないので,
+キー入力割り込みをかけるには,長めにキーを押してやる必要があります.
+(キーは基本的に鈍いので,反応するまで長めに押してください)
+
+■ ソース中の WonX 依存部分のくくりかた
 
 WonderWitch 用のプログラムを開発していく際に,WonX の場合のみ組み込みたくて,
 WonderSwan 上で実行するときには取り除きたいコードがあったとします.
@@ -467,7 +654,7 @@ WonderSwan 
 #define _WONX_
 してあるので,そのような場所は #ifdef _WONX_ でくくってください.
 
-[ダンプデータの取りかた]
+■ ダンプデータの取りかた
 
 ソース中に,
 

+ 180 - 0
UNIXSerialPort.c

@@ -0,0 +1,180 @@
+/*****************************************************************************/
+/* ここから                                                                  */
+/*****************************************************************************/
+
+#include <string.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/time.h>
+
+#include "UNIXSerialPortP.h"
+#include "WonX.h"
+#include "etc.h"
+
+/*****************************************************************************/
+/* メンバ関数の定義                                                          */
+/*****************************************************************************/
+
+/*---------------------------------------------------------------------------*/
+/* ポートの open/close                                                       */
+/*---------------------------------------------------------------------------*/
+
+int UNIXSerialPort_Open(UNIXSerialPort unix_serial_port)
+{
+  unix_serial_port->opened = 1;
+  return (0);
+}
+int UNIXSerialPort_Close(UNIXSerialPort unix_serial_port)
+{
+  unix_serial_port->opened = 0;
+  return (0);
+}
+
+int UNIXSerialPort_IsOpened(UNIXSerialPort unix_serial_port)
+{ return (unix_serial_port->opened != 0); }
+int UNIXSerialPort_IsClosed(UNIXSerialPort unix_serial_port)
+{ return (unix_serial_port->opened == 0); }
+
+/*---------------------------------------------------------------------------*/
+/* 受信データがあるかどうか                                                  */
+/*---------------------------------------------------------------------------*/
+
+/*
+ * タイムアウト時間をミリ秒単位で指定.
+ * 0 のときは,即時
+ * -1 のときは,無期限待ち
+ */
+
+int UNIXSerialPort_IsDataExisting(UNIXSerialPort unix_serial_port,
+				  int timeout)
+{
+  fd_set bitmap;
+  struct timeval t;
+  struct timeval * t_p;
+#if 0
+  int c;
+#endif
+
+  if (UNIXSerialPort_IsClosed(unix_serial_port)) return (0);
+
+  /*
+   * 0 のときは,即時
+   * -1 のときは,無期限待ち
+   */
+  if (timeout == -1) {
+    t_p = NULL;
+  } else {
+    t.tv_sec  =  timeout / 1000;
+    t.tv_usec = (timeout % 1000) * 1000;
+    t_p = &t;
+  }
+
+  /*
+   * FreeBSD3.4 で実験したところ,
+   * アラームシグナルを使用する場合,select()でのブロック中に
+   * アラームシグナルが発生すると,その直後にselect()もタイムアウト
+   * してしまうので,注意.
+   * (select() がタイムアウトした後にアラームシグナルが発生する場合は,
+   *  正常に動作した)
+   * 論理上は問題が無いが,期待した時間だけ待ってくれないという現象が
+   * 起きる可能性がある.
+   */
+
+#if 0
+  /* 読み飛ばしたい文字があるときは,こっちのコードを使う */
+  do {
+    FD_ZERO(&bitmap);
+    FD_SET(fileno(stdin), &bitmap);
+    select(fileno(stdin) + 1, &bitmap, NULL, NULL, t_p);
+
+    if (!FD_ISSET(fileno(stdin), &bitmap))
+      return (0);
+
+    c = fgetc(stdin);
+  } while (0); /* 読み飛ばしたい文字があるときは,ここでcをチェックする */
+  ungetc(c, stdin);
+#else
+  FD_ZERO(&bitmap);
+  FD_SET(fileno(stdin), &bitmap);
+  select(fileno(stdin) + 1, &bitmap, NULL, NULL, t_p);
+
+  if (!FD_ISSET(fileno(stdin), &bitmap))
+    return (0);
+#endif
+
+  return (1);
+}
+
+/*---------------------------------------------------------------------------*/
+/* 受信                                                                      */
+/*---------------------------------------------------------------------------*/
+
+int UNIXSerialPort_ReceiveCharacter(UNIXSerialPort unix_serial_port,
+				    int timeout)
+{
+  int c;
+
+  if (UNIXSerialPort_IsClosed(unix_serial_port)) return (-1);
+
+  c = UNIXSerialPort_IsDataExisting(unix_serial_port, timeout)
+    ? fgetc(stdin) : -1;
+  c = (c == '\n') ? '\r' : c; /* \r のエミュレーション */
+
+  return (c);
+}
+
+/*---------------------------------------------------------------------------*/
+/* 送信                                                                      */
+/*---------------------------------------------------------------------------*/
+
+int UNIXSerialPort_SendCharacter(UNIXSerialPort unix_serial_port,
+				 unsigned char c)
+{
+  if (UNIXSerialPort_IsClosed(unix_serial_port)) return (0);
+
+  wonx_print_character(stdout, c);
+
+  return (1);
+}
+
+/*---------------------------------------------------------------------------*/
+/* オブジェクトの作成                                                        */
+/*---------------------------------------------------------------------------*/
+
+UNIXSerialPort UNIXSerialPort_Create()
+{
+  UNIXSerialPort unix_serial_port;
+
+  unix_serial_port = (UNIXSerialPort)malloc(sizeof(_UNIXSerialPort));
+  if (unix_serial_port == NULL)
+    WonX_Error("UNIXSerialPort_Create", "Cannot allocate memory.");
+
+  unix_serial_port->opened = 0;
+
+  return (unix_serial_port);
+}
+
+/*---------------------------------------------------------------------------*/
+/* オブジェクトの削除                                                        */
+/*---------------------------------------------------------------------------*/
+
+UNIXSerialPort UNIXSerialPort_Destroy(UNIXSerialPort unix_serial_port)
+{
+  if (unix_serial_port == NULL)
+    WonX_Error("UNIXSerialPort_Destroy", "Object is not created.");
+
+  if (UNIXSerialPort_IsOpened(unix_serial_port))
+    UNIXSerialPort_Close(unix_serial_port);
+
+  free(unix_serial_port);
+
+  return (NULL);
+}
+
+/*****************************************************************************/
+/* ここまで                                                                  */
+/*****************************************************************************/
+
+/*****************************************************************************/
+/* End of File.                                                              */
+/*****************************************************************************/

+ 82 - 0
UNIXSerialPort.h

@@ -0,0 +1,82 @@
+#ifndef _UNIXSerialPort_h_INCLUDED_
+#define _UNIXSerialPort_h_INCLUDED_
+
+/*****************************************************************************/
+/* ここから                                                                  */
+/*****************************************************************************/
+
+/*****************************************************************************/
+/* クラスの定義                                                              */
+/*****************************************************************************/
+
+typedef struct _UNIXSerialPort * UNIXSerialPort;
+
+/*****************************************************************************/
+/* ヘッダファイルのインクルード                                              */
+/*****************************************************************************/
+
+#include <stdio.h>
+#include <stdlib.h>
+
+/*****************************************************************************/
+/* メンバ関数の宣言                                                          */
+/*****************************************************************************/
+
+/*---------------------------------------------------------------------------*/
+/* ポートの open/close                                                       */
+/*---------------------------------------------------------------------------*/
+
+int UNIXSerialPort_Open(UNIXSerialPort unix_serial_port);
+int UNIXSerialPort_Close(UNIXSerialPort unix_serial_port);
+
+int UNIXSerialPort_IsOpened(UNIXSerialPort unix_serial_port);
+int UNIXSerialPort_IsClosed(UNIXSerialPort unix_serial_port);
+
+/*---------------------------------------------------------------------------*/
+/* 受信データがあるかどうか                                                  */
+/*---------------------------------------------------------------------------*/
+
+/*
+ * タイムアウト時間をミリ秒単位で指定.
+ * 0 のときは,即時
+ * -1 のときは,無期限待ち
+ */
+
+int UNIXSerialPort_IsDataExisting(UNIXSerialPort unix_serial_port,
+				  int timeout);
+
+/*---------------------------------------------------------------------------*/
+/* 受信                                                                      */
+/*---------------------------------------------------------------------------*/
+
+int UNIXSerialPort_ReceiveCharacter(UNIXSerialPort unix_serial_port,
+				    int timeout);
+
+/*---------------------------------------------------------------------------*/
+/* 送信                                                                      */
+/*---------------------------------------------------------------------------*/
+
+int UNIXSerialPort_SendCharacter(UNIXSerialPort unix_serial_port,
+				 unsigned char c);
+
+/*---------------------------------------------------------------------------*/
+/* オブジェクトの作成                                                        */
+/*---------------------------------------------------------------------------*/
+
+UNIXSerialPort UNIXSerialPort_Create();
+
+/*---------------------------------------------------------------------------*/
+/* オブジェクトの削除                                                        */
+/*---------------------------------------------------------------------------*/
+
+UNIXSerialPort UNIXSerialPort_Destroy(UNIXSerialPort unix_serial_port);
+
+/*****************************************************************************/
+/* ここまで                                                                  */
+/*****************************************************************************/
+
+#endif
+
+/*****************************************************************************/
+/* End of File.                                                              */
+/*****************************************************************************/

+ 6 - 6
WonXTextP.h → UNIXSerialPortP.h

@@ -1,19 +1,19 @@
-#ifndef _WonXTextP_h_INCLUDED_
-#define _WonXTextP_h_INCLUDED_
+#ifndef _UNIXSerialPortP_h_INCLUDED_
+#define _UNIXSerialPortP_h_INCLUDED_
 
 /*****************************************************************************/
 /* ここから                                                                  */
 /*****************************************************************************/
 
-#include "WonXText.h"
+#include "UNIXSerialPort.h"
 
 /*****************************************************************************/
 /* クラスの定義                                                              */
 /*****************************************************************************/
 
-typedef struct _WonXText {
-  WWText ww_text;
-} _WonXText;
+typedef struct _UNIXSerialPort {
+  int opened; /* open/close */
+} _UNIXSerialPort;
 
 /*****************************************************************************/
 /* ここまで                                                                  */

+ 7 - 1
UNIXTimer.c

@@ -6,7 +6,7 @@
 #include <signal.h>
 
 #include "UNIXTimerP.h"
-#include "etc.h"
+#include "WonX.h"
 
 /*****************************************************************************/
 /* メンバ関数の定義                                                          */
@@ -171,6 +171,8 @@ int UNIXTimer_Unpause(UNIXTimer unix_timer)
 {
   if (unix_timer->pause == 0)
     WonX_Error("UNIXTimer_Unpause", "Duplicated unpause.");
+  if (unix_timer->pause < 0)
+    WonX_Error("UNIXTimer_Unpause", "Invalid pause.");
 
   if (unix_timer->pause == 1) {
     if (unix_timer->interrupt_in_pause > 0) {
@@ -198,6 +200,10 @@ int UNIXTimer_Unpause(UNIXTimer unix_timer)
 
       /* コールバック関数の呼び出し */
       UNIXTimer_CallBackFunction(0);
+    } else {
+      if (unix_timer->interrupt_in_pause < 0)
+	WonX_Error("UNIXTimer_Unpause", "Invalid interrupt_in_pause.");
+      unix_timer->pause--; /* ポーズはネストできる */
     }
   } else {
     unix_timer->pause--; /* ポーズはネストできる */

+ 7 - 3
UNIXTimer.h

@@ -5,9 +5,6 @@
 /* ここから                                                                  */
 /*****************************************************************************/
 
-#include <stdio.h>
-#include <stdlib.h>
-
 /*****************************************************************************/
 /* クラスの定義                                                              */
 /*****************************************************************************/
@@ -15,6 +12,13 @@
 typedef struct _UNIXTimer * UNIXTimer;
 typedef int (*UNIXTimerCallBack)(void *);
 
+/*****************************************************************************/
+/* ヘッダファイルのインクルード                                              */
+/*****************************************************************************/
+
+#include <stdio.h>
+#include <stdlib.h>
+
 /*****************************************************************************/
 /* メンバ関数の宣言                                                          */
 /*****************************************************************************/

+ 1 - 1
WWCharacter.c

@@ -3,7 +3,7 @@
 /*****************************************************************************/
 
 #include "WWCharacterP.h"
-#include "etc.h"
+#include "WonX.h"
 
 /*****************************************************************************/
 /* ¥á¥ó¥Ð´Ø¿ô¤ÎÄêµÁ                                                          */

+ 7 - 3
WWCharacter.h

@@ -5,15 +5,19 @@
 /* ここから                                                                  */
 /*****************************************************************************/
 
-#include <stdio.h>
-#include <stdlib.h>
-
 /*****************************************************************************/
 /* クラスの定義                                                              */
 /*****************************************************************************/
 
 typedef struct _WWCharacter * WWCharacter;
 
+/*****************************************************************************/
+/* ヘッダファイルのインクルード                                              */
+/*****************************************************************************/
+
+#include <stdio.h>
+#include <stdlib.h>
+
 /*****************************************************************************/
 /* メンバ関数の宣言                                                          */
 /*****************************************************************************/

+ 1 - 1
WWColorMap.c

@@ -3,7 +3,7 @@
 /*****************************************************************************/
 
 #include "WWColorMapP.h"
-#include "etc.h"
+#include "WonX.h"
 
 /*****************************************************************************/
 /* ¥á¥ó¥Ð´Ø¿ô¤ÎÄêµÁ                                                          */

+ 7 - 3
WWColorMap.h

@@ -5,15 +5,19 @@
 /* ここから                                                                  */
 /*****************************************************************************/
 
-#include <stdio.h>
-#include <stdlib.h>
-
 /*****************************************************************************/
 /* クラスの定義                                                              */
 /*****************************************************************************/
 
 typedef struct _WWColorMap * WWColorMap;
 
+/*****************************************************************************/
+/* ヘッダファイルのインクルード                                              */
+/*****************************************************************************/
+
+#include <stdio.h>
+#include <stdlib.h>
+
 /*****************************************************************************/
 /* メンバ関数の宣言                                                          */
 /*****************************************************************************/

+ 67 - 0
WWCursor.c

@@ -0,0 +1,67 @@
+/*****************************************************************************/
+/* ここから                                                                  */
+/*****************************************************************************/
+
+#include "WWCursorP.h"
+#include "WonX.h"
+
+/*****************************************************************************/
+/* メンバ関数の定義                                                          */
+/*****************************************************************************/
+
+int WWCursor_ON(   WWCursor p) { return (p->on =  1); }
+int WWCursor_OFF(  WWCursor p) { return (p->on =  0); }
+int WWCursor_IsON( WWCursor p) { return (p->on != 0); }
+int WWCursor_IsOFF(WWCursor p) { return (p->on == 0); }
+
+int WWCursor_GetX(       WWCursor p       ) { return (p->x           ); }
+int WWCursor_SetX(       WWCursor p, int n) { return (p->x        = n); }
+int WWCursor_GetY(       WWCursor p       ) { return (p->y           ); }
+int WWCursor_SetY(       WWCursor p, int n) { return (p->y        = n); }
+int WWCursor_GetWidth(   WWCursor p       ) { return (p->width       ); }
+int WWCursor_SetWidth(   WWCursor p, int n) { return (p->width    = n); }
+int WWCursor_GetHeight(  WWCursor p       ) { return (p->height      ); }
+int WWCursor_SetHeight(  WWCursor p, int n) { return (p->height   = n); }
+int WWCursor_GetInterval(WWCursor p       ) { return (p->interval    ); }
+int WWCursor_SetInterval(WWCursor p, int n) { return (p->interval = n); }
+
+WWPalette WWCursor_GetPalette(WWCursor p)
+{ return (p->palette      ); }
+WWPalette WWCursor_SetPalette(WWCursor p, WWPalette plt)
+{ return (p->palette = plt); }
+
+WWCursor WWCursor_Create(WWPalette palette)
+{
+  WWCursor cursor;
+
+  cursor = (WWCursor)malloc(sizeof(_WWCursor));
+  if (cursor == NULL)
+    WonX_Error("WWCursor_Create", "Cannot allocate memory");
+
+  WWCursor_OFF(cursor);
+
+  WWCursor_SetX(       cursor,  0);
+  WWCursor_SetY(       cursor,  0);
+  WWCursor_SetWidth(   cursor,  1);
+  WWCursor_SetHeight(  cursor,  1);
+  WWCursor_SetInterval(cursor, 30);
+
+  WWCursor_SetPalette(cursor, palette);
+
+  return (cursor);
+}
+
+WWCursor WWCursor_Destroy(WWCursor cursor)
+{
+  if (cursor == NULL) return (NULL);
+  free(cursor);
+  return (NULL);
+}
+
+/*****************************************************************************/
+/* ここまで                                                                  */
+/*****************************************************************************/
+
+/*****************************************************************************/
+/* End of File.                                                              */
+/*****************************************************************************/

+ 57 - 0
WWCursor.h

@@ -0,0 +1,57 @@
+#ifndef _WWCursor_h_INCLUDED_
+#define _WWCursor_h_INCLUDED_
+
+/*****************************************************************************/
+/* ここから                                                                  */
+/*****************************************************************************/
+
+/*****************************************************************************/
+/* クラスの定義                                                              */
+/*****************************************************************************/
+
+typedef struct _WWCursor * WWCursor;
+
+/*****************************************************************************/
+/* ヘッダファイルのインクルード                                              */
+/*****************************************************************************/
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "WWPalette.h"
+
+/*****************************************************************************/
+/* メンバ関数の宣言                                                          */
+/*****************************************************************************/
+
+int WWCursor_ON(   WWCursor p);
+int WWCursor_OFF(  WWCursor p);
+int WWCursor_IsON( WWCursor p);
+int WWCursor_IsOFF(WWCursor p);
+
+int WWCursor_GetX(       WWCursor p       );
+int WWCursor_SetX(       WWCursor p, int n);
+int WWCursor_GetY(       WWCursor p       );
+int WWCursor_SetY(       WWCursor p, int n);
+int WWCursor_GetWidth(   WWCursor p       );
+int WWCursor_SetWidth(   WWCursor p, int n);
+int WWCursor_GetHeight(  WWCursor p       );
+int WWCursor_SetHeight(  WWCursor p, int n);
+int WWCursor_GetInterval(WWCursor p       );
+int WWCursor_SetInterval(WWCursor p, int n);
+
+WWPalette WWCursor_GetPalette(WWCursor p);
+WWPalette WWCursor_SetPalette(WWCursor p, WWPalette plt);
+
+WWCursor WWCursor_Create(WWPalette palette);
+WWCursor WWCursor_Destroy(WWCursor cursor);
+
+/*****************************************************************************/
+/* ここまで                                                                  */
+/*****************************************************************************/
+
+#endif
+
+/*****************************************************************************/
+/* End of File.                                                              */
+/*****************************************************************************/

+ 10 - 12
WonXText.h → WWCursorP.h

@@ -1,25 +1,23 @@
-#ifndef _WonXText_h_INCLUDED_
-#define _WonXText_h_INCLUDED_
+#ifndef _WWCursorP_h_INCLUDED_
+#define _WWCursorP_h_INCLUDED_
 
 /*****************************************************************************/
 /* ここから                                                                  */
 /*****************************************************************************/
 
-#include "WWText.h"
-#include "WWScreen.h"
-#include "WWPalette.h"
+#include "WWCursor.h"
 
 /*****************************************************************************/
 /* クラスの定義                                                              */
 /*****************************************************************************/
 
-typedef struct _WonXText * WonXText;
-
-WWText WonXText_GetWWText(WonXText wonx_text);
-WWText WonXText_SetWWText(WonXText wonx_text, WWText ww_text);
-WonXText WonXText_Create(WWScreen screen, int x, int y, int width, int height,
-			 WWPalette palette);
-WonXText WonXText_Destroy(WonXText wonx_text);
+typedef struct _WWCursor {
+  int on;            /* 表示/非表示のフラグ */
+  int x, y;          /* カーソル座標 */
+  int width, height; /* カーソルのサイズ */
+  int interval;      /* 点滅周期 */
+  WWPalette palette; /* カーソル表示用パレット */
+} _WWCursor;
 
 /*****************************************************************************/
 /* ここまで                                                                  */

+ 69 - 8
WWDisplay.c

@@ -2,8 +2,11 @@
 /* ここから                                                                  */
 /*****************************************************************************/
 
+#include "wonx_include/disp.h"
+#include "wonx_include/text.h"
+
 #include "WWDisplayP.h"
-#include "etc.h"
+#include "WonX.h"
 
 /*****************************************************************************/
 /* メンバ関数の定義                                                          */
@@ -20,6 +23,8 @@ WWCharacter WWDisplay_GetCharacter(WWDisplay d, int n)
 WWSprite WWDisplay_GetSprite(WWDisplay d, int n) { return (d->sprite[n]); }
 WWScreen WWDisplay_GetScreen(WWDisplay d, int n) { return (d->screen[n]); }
 WWLCDPanel WWDisplay_GetLCDPanel(WWDisplay d) { return (d->lcd_panel); }
+WWText WWDisplay_GetText(WWDisplay d) { return (d->text); }
+WWCursor WWDisplay_GetCursor(WWDisplay d) { return (d->cursor); }
 
 int WWDisplay_GetSpriteEnable(WWDisplay d) { return (d->sprite_enable); }
 int WWDisplay_GetSpriteWindowEnable(WWDisplay d)
@@ -58,6 +63,10 @@ WWScreen WWDisplay_SetScreen(WWDisplay d, int n, WWScreen s)
 { return (d->screen[n] = s); }
 WWLCDPanel WWDisplay_SetLCDPanel(WWDisplay d, WWLCDPanel p)
 { return (d->lcd_panel = p); }
+WWText WWDisplay_SetText(WWDisplay d, WWText p)
+{ return (d->text = p); }
+WWCursor WWDisplay_SetCursor(WWDisplay d, WWCursor p)
+{ return (d->cursor = p); }
 
 int WWDisplay_SetSpriteEnable(WWDisplay d, int f)
 { return (d->sprite_enable = f); }
@@ -94,16 +103,29 @@ WWDisplay WWDisplay_Create(int lcd_panel_width, int lcd_panel_height,
 {
   WWDisplay display;
   int i;
+  static int default_lcd_colors[] = {
+    0x00, 0x02, 0x04, 0x06, 0x08, 0x0a, 0x0c, 0x0f
+  };
+  static struct palette_colors {
+    int colors[4];
+  } default_palette_colors[] = {
+    {{0, 3, 5, 7}}, {{2, 3, 5, 7}}, {{0, 0, 0, 7}}, {{2, 0, 0, 7}},
+    {{0, 0, 3, 7}}, {{0, 7, 7, 7}}, {{0, 7, 7, 7}}, {{0, 0, 2, 7}},
+    {{2, 5, 7, 7}}, {{7, 7, 7, 7}}, {{7, 6, 5, 7}}, {{3, 7, 5, 7}},
+    {{0, 0, 4, 7}}, {{0, 0, 0, 7}}, {{0, 7, 7, 5}}, {{0, 7, 3, 7}}
+  };
 
   display = (WWDisplay)malloc(sizeof(_WWDisplay));
   if (display == NULL)
     WonX_Error("WWDisplay_Create", "Cannot allocate memory.");
 
-  WWDisplay_SetColorMap(display, WWColorMap_Create(NULL));
+  WWDisplay_SetColorMap(display, WWColorMap_Create(default_lcd_colors));
 
   for (i = 0; i < 16; i++) {
     WWDisplay_SetPalette(display, i,
-			 WWPalette_Create(i, NULL, ((i / 4) % 2) ? 1 : 0));
+			 WWPalette_Create(i,
+					  default_palette_colors[i].colors,
+					  ((i / 4) % 2) ? 1 : 0));
   }
 
   for (i = 0; i < 512; i++) {
@@ -129,6 +151,23 @@ WWDisplay WWDisplay_Create(int lcd_panel_width, int lcd_panel_height,
   WWDisplay_SetLCDPanel(display, WWLCDPanel_Create(lcd_panel_width,
 						   lcd_panel_height));
 
+
+
+  /* デフォルトのテキスト表示用パレットは0 */
+  WWDisplay_SetText(display,
+		    WWText_Create(WWDisplay_GetScreen(display, SCREEN2),
+				  0, 0,
+				  TEXT_SCREEN_WIDTH, TEXT_SCREEN_HEIGHT,
+				  WWDisplay_GetPalette(display, 0)));
+
+  /*
+   * WWDisplay_GetPalette() を呼び出すので,パレットを設定してから
+   * カーソルの設定を行うこと.
+   * デフォルトのカーソルパレットは1
+   */
+  WWDisplay_SetCursor(display,
+		      WWCursor_Create(WWDisplay_GetPalette(display, 1)));
+
   WWDisplay_SetSpriteEnable(display, 0);
   WWDisplay_SetSpriteWindowEnable(display, 0);
 
@@ -188,6 +227,14 @@ WWDisplay WWDisplay_Destroy(WWDisplay display)
     WWDisplay_SetLCDPanel(display,
 			  WWLCDPanel_Destroy(WWDisplay_GetLCDPanel(display)));
 
+  if (WWDisplay_GetText(display) != NULL)
+    WWDisplay_SetText(display,
+		      WWText_Destroy(WWDisplay_GetText(display)));
+
+  if (WWDisplay_GetCursor(display) != NULL)
+    WWDisplay_SetCursor(display,
+			WWCursor_Destroy(WWDisplay_GetCursor(display)));
+
   free(display);
 
   return (NULL);
@@ -197,7 +244,8 @@ WWDisplay WWDisplay_Destroy(WWDisplay display)
 /* LCDパネルの描画                                                           */
 /*===========================================================================*/
 
-static int WWDisplay_DrawScreen(WWDisplay display, WWScreen screen)
+static int WWDisplay_DrawScreen(WWDisplay display, WWScreen screen,
+				WWCursor cursor)
 {
   WWLCDPanel lcd_panel;
   int lcd_panel_width;
@@ -267,7 +315,8 @@ static int WWDisplay_DrawScreen(WWDisplay display, WWScreen screen)
 
       px = x + WWScreen_GetRollX(screen);
 
-      pixel = WWScreen_GetPixel(screen, px, py);
+      /* 透明色の場合には,-1が返ってくる */
+      pixel = WWScreen_GetPixel(screen, px, py, cursor);
 
       /* 透明色の場合 */
       if (pixel == -1) continue;
@@ -300,7 +349,7 @@ static int WWDisplay_DrawSprite(WWDisplay display, WWSprite sprite)
 
   for (y = 0; y < 8; y++) {
     for (x = 0; x < 8; x++) {
-      pixel = WWSprite_GetPixel(sprite, x, y);
+      pixel = WWSprite_GetPixel(sprite, x, y); /* 透明色は-1が返ってくる */
 
       /* 透明色の場合 */
       if (pixel == -1) continue;
@@ -337,7 +386,9 @@ int WWDisplay_DrawLCDPanel(WWDisplay display)
   int lcd_panel_height;
   WWColorMap color_map;
   int border;
+  WWScreen screen;
   WWSprite sprite;
+  WWCursor cursor;
 
   lcd_panel = WWDisplay_GetLCDPanel(display);
   lcd_panel_width  = WWLCDPanel_GetWidth( lcd_panel);
@@ -354,7 +405,12 @@ int WWDisplay_DrawLCDPanel(WWDisplay display)
   }
 
   /* スクリーン1描画 */
-  WWDisplay_DrawScreen(display, WWDisplay_GetScreen(display, 0));
+  screen = WWDisplay_GetScreen(display, 0);
+  if (WWText_GetScreen(WWDisplay_GetText(display)) == screen)
+    cursor = WWDisplay_GetCursor(display);
+  else
+    cursor = NULL;
+  WWDisplay_DrawScreen(display, screen, cursor);
 
   /* スプライト描画(スクリーン2より優先でないもの) */
   /* 重なった場合は,番号の若いものが手前に表示される */
@@ -369,7 +425,12 @@ int WWDisplay_DrawLCDPanel(WWDisplay display)
   }
 
   /* スクリーン2描画 */
-  WWDisplay_DrawScreen(display, WWDisplay_GetScreen(display, 1));
+  screen = WWDisplay_GetScreen(display, 1);
+  if (WWText_GetScreen(WWDisplay_GetText(display)) == screen)
+    cursor = WWDisplay_GetCursor(display);
+  else
+    cursor = NULL;
+  WWDisplay_DrawScreen(display, screen, cursor);
 
   /* スプライト描画(スクリーン2より優先なもの) */
   /* 重なった場合は,番号の若いものが手前に表示される */

+ 18 - 7
WWDisplay.h

@@ -5,21 +5,27 @@
 /* ここから                                                                  */
 /*****************************************************************************/
 
+/*****************************************************************************/
+/* クラスの定義                                                              */
+/*****************************************************************************/
+
+typedef struct _WWDisplay * WWDisplay;
+
+/*****************************************************************************/
+/* ヘッダファイルのインクルード                                              */
+/*****************************************************************************/
+
 #include "WWColorMap.h"
 #include "WWPalette.h"
 #include "WWCharacter.h"
 #include "WWSprite.h"
 #include "WWScreen.h"
 #include "WWLCDPanel.h"
+#include "WWText.h"
+#include "WWCursor.h"
 
 /*****************************************************************************/
-/* クラスの定義                                                              */
-/*****************************************************************************/
-
-typedef struct _WWDisplay * WWDisplay;
-
-/*****************************************************************************/
-/* メンバ関数の定義                                                          */
+/* メンバ関数の宣言                                                          */
 /*****************************************************************************/
 
 /*===========================================================================*/
@@ -32,6 +38,9 @@ WWCharacter WWDisplay_GetCharacter(WWDisplay d, int n);
 WWSprite WWDisplay_GetSprite(WWDisplay d, int n);
 WWScreen WWDisplay_GetScreen(WWDisplay d, int n);
 WWLCDPanel WWDisplay_GetLCDPanel(WWDisplay d);
+WWText WWDisplay_GetText(WWDisplay d);
+WWCursor WWDisplay_GetCursor(WWDisplay d);
+
 int WWDisplay_GetSpriteEnable(WWDisplay d);
 int WWDisplay_GetSpriteWindowEnable(WWDisplay d);
 
@@ -58,6 +67,8 @@ WWCharacter WWDisplay_SetCharacter(WWDisplay d, int n, WWCharacter c);
 WWSprite WWDisplay_SetSprite(WWDisplay d, int n, WWSprite s);
 WWScreen WWDisplay_SetScreen(WWDisplay d, int n, WWScreen s);
 WWLCDPanel WWDisplay_SetLCDPanel(WWDisplay d, WWLCDPanel p);
+WWText WWDisplay_SetText(WWDisplay d, WWText p);
+WWCursor WWDisplay_SetCursor(WWDisplay d, WWCursor p);
 
 int WWDisplay_SetSpriteEnable(WWDisplay d, int f);
 int WWDisplay_SetSpriteWindowEnable(WWDisplay d, int f);

+ 2 - 0
WWDisplayP.h

@@ -19,6 +19,8 @@ typedef struct _WWDisplay {
   WWSprite sprite[128];
   WWScreen screen[2];
   WWLCDPanel lcd_panel;
+  WWText text;
+  WWCursor cursor;
 
   /* ディスプレイの属性情報 */
   int sprite_enable; /* スプライト表示イネーブルフラグ */

+ 1 - 1
WWInterrupt.c

@@ -3,7 +3,7 @@
 /*****************************************************************************/
 
 #include "WWInterruptP.h"
-#include "etc.h"
+#include "WonX.h"
 
 /*****************************************************************************/
 /* ¥á¥ó¥Ð´Ø¿ô¤ÎÄêµÁ                                                          */

+ 9 - 5
WWInterrupt.h

@@ -5,11 +5,6 @@
 /* ここから                                                                  */
 /*****************************************************************************/
 
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "wonx_include/system.h"
-
 /*****************************************************************************/
 /* クラスの定義                                                              */
 /*****************************************************************************/
@@ -17,6 +12,15 @@
 typedef struct _WWInterrupt * WWInterrupt;
 typedef void (*WWInterruptCallback)();
 
+/*****************************************************************************/
+/* ヘッダファイルのインクルード                                              */
+/*****************************************************************************/
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "wonx_include/system.h"
+
 /*****************************************************************************/
 /* メンバ関数の宣言                                                          */
 /*****************************************************************************/

+ 1 - 1
WWLCDPanel.c

@@ -3,7 +3,7 @@
 /*****************************************************************************/
 
 #include "WWLCDPanelP.h"
-#include "etc.h"
+#include "WonX.h"
 
 /*****************************************************************************/
 /* ¥á¥ó¥Ð´Ø¿ô¤ÎÄêµÁ                                                          */

+ 6 - 2
WWLCDPanel.h

@@ -5,14 +5,18 @@
 /* ここから                                                                  */
 /*****************************************************************************/
 
-#include <stdlib.h>
-
 /*****************************************************************************/
 /* クラスの定義                                                              */
 /*****************************************************************************/
 
 typedef struct _WWLCDPanel * WWLCDPanel;
 
+/*****************************************************************************/
+/* ヘッダファイルのインクルード                                              */
+/*****************************************************************************/
+
+#include <stdlib.h>
+
 /*****************************************************************************/
 /* メンバ関数の宣言                                                          */
 /*****************************************************************************/

+ 2 - 1
WWPalette.c

@@ -3,6 +3,7 @@
 /*****************************************************************************/
 
 #include "WWPaletteP.h"
+#include "WonX.h"
 #include "etc.h"
 
 /*****************************************************************************/
@@ -91,7 +92,7 @@ int WWPalette_PrintData(WWPalette p, FILE * f)
 
   fprintf(f, "palette[%d] :\tnumber = %d\n", n, WWPalette_GetNumber(p));
   fprintf(f, "palette[%d] :\ttransparent = %s\n",
-	  n, true_false(WWPalette_GetTransparent(p)));
+	  n, wonx_true_false(WWPalette_GetTransparent(p)));
 
   for (i = 0; i < 4; i++) {
     fprintf(f, "palette[%d] :\tcolor[%d] = %d\n",

+ 7 - 3
WWPalette.h

@@ -5,15 +5,19 @@
 /* ここから                                                                  */
 /*****************************************************************************/
 
-#include <stdio.h>
-#include <stdlib.h>
-
 /*****************************************************************************/
 /* クラスの定義                                                              */
 /*****************************************************************************/
 
 typedef struct _WWPalette * WWPalette;
 
+/*****************************************************************************/
+/* ヘッダファイルのインクルード                                              */
+/*****************************************************************************/
+
+#include <stdio.h>
+#include <stdlib.h>
+
 /*****************************************************************************/
 /* メンバ関数の宣言                                                          */
 /*****************************************************************************/

+ 14 - 3
WWScreen.c

@@ -3,7 +3,7 @@
 /*****************************************************************************/
 
 #include "WWScreenP.h"
-#include "etc.h"
+#include "WonX.h"
 
 /*****************************************************************************/
 /* メンバ関数の定義                                                          */
@@ -159,7 +159,7 @@ int WWScreen_SetDrawWidth( WWScreen s, int n) { return (s->draw_width  = n); }
 int WWScreen_SetDrawHeight(WWScreen s, int n) { return (s->draw_height = n); }
 
 /* カラーマップの色(0~7)を返す(透明色は-1を返す) */
-int WWScreen_GetPixel(WWScreen screen, int x, int y)
+int WWScreen_GetPixel(WWScreen screen, int x, int y, WWCursor cursor)
 {
   int cx, cy, px, py;
   int pixel;
@@ -180,10 +180,21 @@ int WWScreen_GetPixel(WWScreen screen, int x, int y)
   if (WWScreen_GetVertical(  screen, cx, cy)) py = 7 - py;
 
   character = WWScreen_GetCharacter(screen, cx, cy);
+
+  /* カーソル表示の処理 */
   palette = WWScreen_GetPalette(screen, cx, cy);
+  if (cursor != NULL) {
+    if ( WWCursor_IsON(cursor) &&
+	 (cx >= WWCursor_GetX(cursor)) &&
+	 (cx <= WWCursor_GetX(cursor) + WWCursor_GetWidth( cursor) - 1) &&
+	 (cy >= WWCursor_GetY(cursor)) &&
+	 (cy <= WWCursor_GetY(cursor) + WWCursor_GetHeight(cursor) - 1) ) {
+      palette = WWCursor_GetPalette(cursor);
+    }
+  }
 
   pixel = WWCharacter_GetPixel(character, px, py);
-  pixel = WWPalette_GetMappedColor(palette, pixel);
+  pixel = WWPalette_GetMappedColor(palette, pixel); /*透明色は-1が返ってくる*/
 
   return (pixel);
 }

+ 11 - 6
WWScreen.h

@@ -5,17 +5,22 @@
 /* ここから                                                                  */
 /*****************************************************************************/
 
-#include <stdlib.h>
-
-#include "WWPalette.h"
-#include "WWCharacter.h"
-
 /*****************************************************************************/
 /* クラスの定義                                                              */
 /*****************************************************************************/
 
 typedef struct _WWScreen * WWScreen;
 
+/*****************************************************************************/
+/* ヘッダファイルのインクルード                                              */
+/*****************************************************************************/
+
+#include <stdlib.h>
+
+#include "WWPalette.h"
+#include "WWCharacter.h"
+#include "WWCursor.h"
+
 /*****************************************************************************/
 /* 定数の定義                                                                */
 /*****************************************************************************/
@@ -66,7 +71,7 @@ int WWScreen_SetDrawY(     WWScreen s, int n);
 int WWScreen_SetDrawWidth( WWScreen s, int n);
 int WWScreen_SetDrawHeight(WWScreen s, int n);
 
-int WWScreen_GetPixel(WWScreen screen, int x, int y);
+int WWScreen_GetPixel(WWScreen screen, int x, int y, WWCursor cursor);
 
 WWScreen WWScreen_Create(int number,
 			 int width, int height,

+ 6 - 6
WWSerialPort.c

@@ -3,16 +3,16 @@
 /*****************************************************************************/
 
 #include "WWSerialPortP.h"
-#include "etc.h"
+#include "WonX.h"
 
 /*****************************************************************************/
 /* ¥á¥ó¥Ð´Ø¿ô¤ÎÄêµÁ                                                          */
 /*****************************************************************************/
 
-int WWSerialPort_ON(   WWSerialPort s) { return (s->port_on =  1); }
-int WWSerialPort_OFF(  WWSerialPort s) { return (s->port_on =  0); }
-int WWSerialPort_IsON( WWSerialPort s) { return (s->port_on != 0); }
-int WWSerialPort_IsOFF(WWSerialPort s) { return (s->port_on == 0); }
+int WWSerialPort_Open(    WWSerialPort s) { return (s->opened =  1); }
+int WWSerialPort_Close(   WWSerialPort s) { return (s->opened =  0); }
+int WWSerialPort_IsOpened(WWSerialPort s) { return (s->opened != 0); }
+int WWSerialPort_IsClosed(WWSerialPort s) { return (s->opened == 0); }
 
 int WWSerialPort_GetBaudrate(WWSerialPort s) { return (s->baudrate); }
 int WWSerialPort_SetBaudrate(WWSerialPort s, int baudrate)
@@ -53,7 +53,7 @@ WWSerialPort WWSerialPort_Create()
   if (ww_serial_port == NULL)
     WonX_Error("WWSerialPort_Create", "Cannot allocate memory.");
 
-  WWSerialPort_OFF(ww_serial_port);
+  WWSerialPort_Close(ww_serial_port);
   WWSerialPort_SetBaudrate38400(ww_serial_port);
   WWSerialPort_SetSendTimeout(ww_serial_port, 100);
   WWSerialPort_SetReceiveTimeout(ww_serial_port, 100);

+ 17 - 9
WWSerialPort.h

@@ -5,28 +5,36 @@
 /* ここから                                                                  */
 /*****************************************************************************/
 
+/*****************************************************************************/
+/* クラスの定義                                                              */
+/*****************************************************************************/
+
+typedef struct _WWSerialPort * WWSerialPort;
+
+/*****************************************************************************/
+/* ヘッダファイルのインクルード                                              */
+/*****************************************************************************/
+
 #include <stdio.h>
 #include <stdlib.h>
 
 #include "wonx_include/comm.h"
 
-#define WW_SERIAL_PORT_BAUDRATE_9600  0
-#define WW_SERIAL_PORT_BAUDRATE_38400 1
-
 /*****************************************************************************/
-/* クラスの定義                                                              */
+/* 定数の定義                                                                */
 /*****************************************************************************/
 
-typedef struct _WWSerialPort * WWSerialPort;
+#define WW_SERIAL_PORT_BAUDRATE_9600  0
+#define WW_SERIAL_PORT_BAUDRATE_38400 1
 
 /*****************************************************************************/
 /* メンバ関数の宣言                                                          */
 /*****************************************************************************/
 
-int WWSerialPort_ON(   WWSerialPort s);
-int WWSerialPort_OFF(  WWSerialPort s);
-int WWSerialPort_IsON( WWSerialPort s);
-int WWSerialPort_IsOFF(WWSerialPort s);
+int WWSerialPort_Open(    WWSerialPort s);
+int WWSerialPort_Close(   WWSerialPort s);
+int WWSerialPort_IsOpened(WWSerialPort s);
+int WWSerialPort_IsClosed(WWSerialPort s);
 
 int WWSerialPort_GetBaudrate(WWSerialPort s);
 int WWSerialPort_SetBaudrate(WWSerialPort s, int baudrate);

+ 1 - 1
WWSerialPortP.h

@@ -13,7 +13,7 @@
 
 typedef struct _WWSerialPort {
 
-  int port_on; /* ポートの状態 */
+  int opened;   /* ポートの状態(open/close) */
   int baudrate; /* ボーレート */
 
   /*

+ 7 - 5
WWSprite.c

@@ -3,6 +3,7 @@
 /*****************************************************************************/
 
 #include "WWSpriteP.h"
+#include "WonX.h"
 #include "etc.h"
 
 /*****************************************************************************/
@@ -37,6 +38,7 @@ int WWSprite_SetPosition(WWSprite sprite, int x, int y)
   return (0);
 }
 
+/* スプライトのピクセル値を返す.(透明色は-1を返す) */
 int WWSprite_GetPixel(WWSprite sprite, int x, int y)
 {
   WWPalette p;
@@ -50,7 +52,7 @@ int WWSprite_GetPixel(WWSprite sprite, int x, int y)
   if (WWSprite_GetVertical(  sprite)) y = 7 - y;
 
   pixel = WWCharacter_GetPixel(c, x, y);
-  pixel = WWPalette_GetMappedColor(p, pixel);
+  pixel = WWPalette_GetMappedColor(p, pixel); /* 透明色は -1 を返す */
 
   return (pixel);
 }
@@ -96,13 +98,13 @@ int WWSprite_PrintData(WWSprite s, FILE * f)
 
   fprintf(f, "sprite[%d] :\tnumber     = %d\n", n, WWSprite_GetNumber(s));
   fprintf(f, "sprite[%d] :\thorizontal = %s\n",
-	  n, true_false(WWSprite_GetHorizontal(s)));
+	  n, wonx_true_false(WWSprite_GetHorizontal(s)));
   fprintf(f, "sprite[%d] :\tvertical   = %s\n",
-	  n, true_false(WWSprite_GetVertical(  s)));
+	  n, wonx_true_false(WWSprite_GetVertical(  s)));
   fprintf(f, "sprite[%d] :\tpriority   = %s\n",
-	  n, true_false(WWSprite_GetPriority(   s)));
+	  n, wonx_true_false(WWSprite_GetPriority(   s)));
   fprintf(f, "sprite[%d] :\tclipping   = %s\n",
-	  n, true_false(WWSprite_GetClipping(  s)));
+	  n, wonx_true_false(WWSprite_GetClipping(  s)));
   fprintf(f, "sprite[%d] :\tpalette number   = %d\n",
 	  n, WWPalette_GetNumber(WWSprite_GetPalette(s)));
   fprintf(f, "sprite[%d] :\tcharacter number = %d\n",

+ 9 - 5
WWSprite.h

@@ -5,17 +5,21 @@
 /* ここから                                                                  */
 /*****************************************************************************/
 
-#include <stdlib.h>
-
-#include "WWPalette.h"
-#include "WWCharacter.h"
-
 /*****************************************************************************/
 /* クラスの定義                                                              */
 /*****************************************************************************/
 
 typedef struct _WWSprite * WWSprite;
 
+/*****************************************************************************/
+/* ヘッダファイルのインクルード                                              */
+/*****************************************************************************/
+
+#include <stdlib.h>
+
+#include "WWPalette.h"
+#include "WWCharacter.h"
+
 /*****************************************************************************/
 /* メンバ関数の宣言                                                          */
 /*****************************************************************************/

+ 3 - 3
WWText.c

@@ -3,7 +3,7 @@
 /*****************************************************************************/
 
 #include "WWTextP.h"
-#include "etc.h"
+#include "WonX.h"
 
 /* フォントのビットマップデータ */
 #include "WWTextFonts.c"
@@ -74,7 +74,7 @@ int WWText_PutCharacter(WWText ww_text, int x, int y, int character,
   WWCharacter ww_character;
 
   if ((character < 0) || (character > 127)) {
-    printf("warning : WWText_PutCharacter() : Character number is out of range.\n");
+    WonX_Warning("WWText_PutCharacter", "Character number is out of range.");
     fflush(stdout);
     return (-1);
   }
@@ -86,7 +86,7 @@ int WWText_PutCharacter(WWText ww_text, int x, int y, int character,
 
   if ( (x < 0) || (x > WWText_GetWidth( ww_text) - 1) ||
        (y < 0) || (y > WWText_GetHeight(ww_text) - 1) ) {
-    printf("warning : WWText_PutCharacter() : Position is out of range.\n");
+    WonX_Warning("WWText_PutCharacter", "Position is out of range.");
     fflush(stdout);
     return (-1);
   }

+ 8 - 4
WWText.h

@@ -5,16 +5,20 @@
 /* ここから                                                                  */
 /*****************************************************************************/
 
-#include "WWDisplay.h"
-#include "WWScreen.h"
-#include "WWPalette.h"
-
 /*****************************************************************************/
 /* クラスの定義                                                              */
 /*****************************************************************************/
 
 typedef struct _WWText * WWText;
 
+/*****************************************************************************/
+/* ヘッダファイルのインクルード                                              */
+/*****************************************************************************/
+
+#include "WWDisplay.h"
+#include "WWScreen.h"
+#include "WWPalette.h"
+
 /*===========================================================================*/
 /* メンバの取得                                                              */
 /*===========================================================================*/

+ 1 - 1
WWTimer.c

@@ -3,7 +3,7 @@
 /*****************************************************************************/
 
 #include "WWTimerP.h"
-#include "etc.h"
+#include "WonX.h"
 
 /*****************************************************************************/
 /* ¥á¥ó¥Ð´Ø¿ô¤ÎÄêµÁ                                                          */

+ 9 - 5
WWTimer.h

@@ -5,17 +5,21 @@
 /* ここから                                                                  */
 /*****************************************************************************/
 
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "wonx_include/timer.h"
-
 /*****************************************************************************/
 /* クラスの定義                                                              */
 /*****************************************************************************/
 
 typedef struct _WWTimer * WWTimer;
 
+/*****************************************************************************/
+/* ヘッダファイルのインクルード                                              */
+/*****************************************************************************/
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "wonx_include/timer.h"
+
 /*****************************************************************************/
 /* メンバ関数の宣言                                                          */
 /*****************************************************************************/

+ 19 - 22
WonX.c

@@ -2,14 +2,9 @@
 #include "etc.h"
 
 #include "wonx_include/disp.h"
-#include "wonx_include/text.h"
 #include "wonx_include/system.h"
 #include "wonx_include/comm.h"
 
-/*****************************************************************************/
-/* ディスプレイの確保                                                        */
-/*****************************************************************************/
-
 static WonX wonx = NULL;
 
 int WonX_IsCreated(void)
@@ -19,9 +14,6 @@ int WonX_IsCreated(void)
 
 void WonX_Create(void)
 {
-  WWScreen screen;
-  WWPalette palette;
-
   wonx = (WonX)malloc(sizeof(_WonX));
   if (wonx == NULL) WonX_Error("WonX_Create", "Cannot allocate memory.");
 
@@ -29,15 +21,6 @@ void WonX_Create(void)
     WonXDisplay_Create(LCD_PIXEL_WIDTH * 2, LCD_PIXEL_HEIGHT * 2,
                        LCD_PIXEL_WIDTH, LCD_PIXEL_HEIGHT,
 		       SCREEN_CHAR_WIDTH, SCREEN_CHAR_HEIGHT);
-  screen =
-    WWDisplay_GetScreen(WonXDisplay_GetWWDisplay(wonx->wonx_display), SCREEN2);
-  /* デフォルトのテキスト表示用パレットは0 */
-  palette =
-    WWDisplay_GetPalette(WonXDisplay_GetWWDisplay(wonx->wonx_display), 0);
-
-  wonx->wonx_text =
-    WonXText_Create(screen, 0, 0, TEXT_SCREEN_WIDTH, TEXT_SCREEN_HEIGHT,
-		    palette);
 
   wonx->wonx_system = WonXSystem_Create();
 
@@ -51,11 +34,6 @@ WonXDisplay WonX_GetWonXDisplay(void)
   return (wonx->wonx_display);
 }
 
-WonXText WonX_GetWonXText(void)
-{
-  return (wonx->wonx_text);
-}
-
 WonXSystem WonX_GetWonXSystem(void)
 {
   return (wonx->wonx_system);
@@ -66,3 +44,22 @@ WonXSerialPort WonX_GetWonXSerialPort(void)
   return (wonx->wonx_serial_port);
 }
 
+/*===========================================================================*/
+/* エラー処理                                                                */
+/*===========================================================================*/
+
+int WonX_Error(char * funcname, char * message)
+{
+  fprintf(stderr, "error : %s(): %s\n", funcname, message);
+  exit (1);
+}
+
+int WonX_Warning(char * funcname, char * message)
+{
+  fprintf(stderr, "warning : %s(): %s\n", funcname, message);
+  return (0);
+}
+
+/*****************************************************************************/
+/* End of File.                                                              */
+/*****************************************************************************/

+ 11 - 6
WonX.h

@@ -2,19 +2,24 @@
 #define _wonx_h_INCLUDED_
 
 #include "WonXDisplay.h"
-#include "WonXText.h"
 #include "WonXSystem.h"
 #include "WonXSerialPort.h"
 
-/*****************************************************************************/
-/* ディスプレイの確保                                                        */
-/*****************************************************************************/
-
 int WonX_IsCreated(void);
 void WonX_Create(void);
 WonXDisplay WonX_GetWonXDisplay(void);
-WonXText WonX_GetWonXText(void);
 WonXSystem WonX_GetWonXSystem(void);
 WonXSerialPort WonX_GetWonXSerialPort(void);
 
+/*===========================================================================*/
+/* エラー処理                                                                */
+/*===========================================================================*/
+
+int WonX_Error(char * funcname, char * message);
+int WonX_Warning(char * funcname, char * message);
+
 #endif
+
+/*****************************************************************************/
+/* End of File.                                                              */
+/*****************************************************************************/

+ 1 - 1
WonXDisplay.c

@@ -3,7 +3,7 @@
 /*****************************************************************************/
 
 #include "WonXDisplayP.h"
-#include "etc.h"
+#include "WonX.h"
 
 /*****************************************************************************/
 /* ¥á¥ó¥Ð´Ø¿ô¤ÎÄêµÁ                                                          */

+ 11 - 3
WonXDisplay.h

@@ -5,15 +5,23 @@
 /* ここから                                                                  */
 /*****************************************************************************/
 
-#include "XDisplay.h"
-#include "WWDisplay.h"
-
 /*****************************************************************************/
 /* クラスの定義                                                              */
 /*****************************************************************************/
 
 typedef struct _WonXDisplay * WonXDisplay;
 
+/*****************************************************************************/
+/* ヘッダファイルのインクルード                                              */
+/*****************************************************************************/
+
+#include "XDisplay.h"
+#include "WWDisplay.h"
+
+/*****************************************************************************/
+/* メンバ関数の宣言                                                          */
+/*****************************************************************************/
+
 XDisplay WonXDisplay_GetXDisplay(WonXDisplay wonx_display);
 WWDisplay WonXDisplay_GetWWDisplay(WonXDisplay wonx_display);
 WonXDisplay WonXDisplay_Create(int x_width, int x_height,

+ 0 - 1
WonXP.h

@@ -13,7 +13,6 @@
 
 typedef struct _WonX {
   WonXDisplay wonx_display;
-  WonXText wonx_text;
   WonXSystem wonx_system;
   WonXSerialPort wonx_serial_port;
 } _WonX;

+ 25 - 6
WonXSerialPort.c

@@ -3,22 +3,29 @@
 /*****************************************************************************/
 
 #include "WonXSerialPortP.h"
-#include "etc.h"
+#include "WonX.h"
 
 /*****************************************************************************/
 /* ¥á¥ó¥Ð´Ø¿ô¤ÎÄêµÁ                                                          */
 /*****************************************************************************/
 
-WWSerialPort WonXSerialPort_GetWWSerialPort(WonXSerialPort wonx_serial_port)
-{ return (wonx_serial_port->ww_serial_port); }
-WWSerialPort WonXSerialPort_SetWWSerialPort(WonXSerialPort wonx_serial_port,
-					    WWSerialPort ww_serial_port)
-{ return (wonx_serial_port->ww_serial_port = ww_serial_port); }
+WWSerialPort WonXSerialPort_GetWWSerialPort(WonXSerialPort wonx_sp)
+{ return (wonx_sp->ww_serial_port); }
+WWSerialPort WonXSerialPort_SetWWSerialPort(WonXSerialPort wonx_sp,
+					    WWSerialPort ww_sp)
+{ return (wonx_sp->ww_serial_port = ww_sp); }
+
+UNIXSerialPort WonXSerialPort_GetUNIXSerialPort(WonXSerialPort wonx_sp)
+{ return (wonx_sp->unix_serial_port); }
+UNIXSerialPort WonXSerialPort_SetUNIXSerialPort(WonXSerialPort wonx_sp,
+						UNIXSerialPort unix_sp)
+{ return (wonx_sp->unix_serial_port = unix_sp); }
 
 WonXSerialPort WonXSerialPort_Create()
 {
   WonXSerialPort wonx_serial_port;
   WWSerialPort ww_serial_port;
+  UNIXSerialPort unix_serial_port;
 
   wonx_serial_port = (WonXSerialPort)malloc(sizeof(_WonXSerialPort));
   if (wonx_serial_port == NULL)
@@ -30,12 +37,19 @@ WonXSerialPort WonXSerialPort_Create()
 	       "Cannot create WonderWitch serial port.");
   WonXSerialPort_SetWWSerialPort(wonx_serial_port, ww_serial_port);
 
+  unix_serial_port = UNIXSerialPort_Create();
+  if (unix_serial_port == NULL)
+    WonX_Error("WonXSerialPort_Create",
+	       "Cannot create UNIX serial port.");
+  WonXSerialPort_SetUNIXSerialPort(wonx_serial_port, unix_serial_port);
+
   return (wonx_serial_port);
 }
 
 WonXSerialPort WonXSerialPort_Destroy(WonXSerialPort wonx_serial_port)
 {
   WWSerialPort ww_serial_port;
+  UNIXSerialPort unix_serial_port;
 
   if (wonx_serial_port == NULL)
     WonX_Error("WonXSerialPort_Destroy", "Object is not created.");
@@ -45,6 +59,11 @@ WonXSerialPort WonXSerialPort_Destroy(WonXSerialPort wonx_serial_port)
     WonXSerialPort_SetWWSerialPort(wonx_serial_port,
 				   WWSerialPort_Destroy(ww_serial_port));
 
+  unix_serial_port = WonXSerialPort_GetUNIXSerialPort(wonx_serial_port);
+  if (unix_serial_port)
+    WonXSerialPort_SetUNIXSerialPort(wonx_serial_port,
+				     UNIXSerialPort_Destroy(unix_serial_port));
+
   free(wonx_serial_port);
 
   return (NULL);

+ 14 - 5
WonXSerialPort.h

@@ -5,21 +5,30 @@
 /* ここから                                                                  */
 /*****************************************************************************/
 
-#include "WWSerialPort.h"
-
 /*****************************************************************************/
 /* クラスの定義                                                              */
 /*****************************************************************************/
 
 typedef struct _WonXSerialPort * WonXSerialPort;
 
+/*****************************************************************************/
+/* ヘッダファイルのインクルード                                              */
+/*****************************************************************************/
+
+#include "WWSerialPort.h"
+#include "UNIXSerialPort.h"
+
 /*****************************************************************************/
 /* メンバ関数の定義                                                          */
 /*****************************************************************************/
 
-WWSerialPort WonXSerialPort_GetWWSerialPort(WonXSerialPort wonx_serial_port);
-WWSerialPort WonXSerialPort_SetWWSerialPort(WonXSerialPort wonx_serial_port,
-					    WWSerialPort ww_serial_port);
+WWSerialPort WonXSerialPort_GetWWSerialPort(WonXSerialPort wonx_sp);
+WWSerialPort WonXSerialPort_SetWWSerialPort(WonXSerialPort wonx_sp,
+					    WWSerialPort ww_sp);
+
+UNIXSerialPort WonXSerialPort_GetUNIXSerialPort(WonXSerialPort wonx_sp);
+UNIXSerialPort WonXSerialPort_SetUNIXSerialPort(WonXSerialPort wonx_sp,
+						UNIXSerialPort unix_sp);
 
 WonXSerialPort WonXSerialPort_Create();
 WonXSerialPort WonXSerialPort_Destroy(WonXSerialPort wonx_serial_port);

+ 1 - 0
WonXSerialPortP.h

@@ -13,6 +13,7 @@
 
 typedef struct _WonXSerialPort {
   WWSerialPort ww_serial_port;
+  UNIXSerialPort unix_serial_port;
 } _WonXSerialPort;
 
 /*****************************************************************************/

+ 49 - 1
WonXSystem.c

@@ -5,7 +5,7 @@
 #include "wonx_configure.h"
 
 #include "WonXSystemP.h"
-#include "etc.h"
+#include "WonX.h"
 
 /*****************************************************************************/
 /* メンバ関数の定義                                                          */
@@ -47,9 +47,24 @@ static int WonXTimer_Callback(WonXSystem wonx_system)
 {
   WWTimer ww_timer;
   WWInterrupt ww_interrupt;
+  WonXDisplay wonx_display;
+  XDisplay x_display;
+  WonXSerialPort wonx_serial_port;
+  WWSerialPort ww_serial_port;
+  UNIXSerialPort unix_serial_port;
+
+  unsigned int old_key;
+  unsigned int new_key;
 
   ww_interrupt = WonXSystem_GetWWInterrupt(wonx_system);
 
+  wonx_display = WonX_GetWonXDisplay();
+  x_display = WonXDisplay_GetXDisplay(wonx_display);
+
+  wonx_serial_port = WonX_GetWonXSerialPort();
+  ww_serial_port = WonXSerialPort_GetWWSerialPort(wonx_serial_port);
+  unix_serial_port = WonXSerialPort_GetUNIXSerialPort(wonx_serial_port);
+
   ww_timer = WonXSystem_GetWWVBlankTimer(wonx_system);
   if (WWTimer_IsON(ww_timer)) {
     if (WWTimer_Count(ww_timer))
@@ -68,6 +83,39 @@ static int WonXTimer_Callback(WonXSystem wonx_system)
       WWInterrupt_ExecuteHBlankCountUpCallback(ww_interrupt);
   }
 
+  /* キー入力割り込み */
+  /*
+   * XDisplay_Sync() が他のところから呼ばれた場合に割り込みをとり
+   * こぼしてしまうので,XDisplay クラスのほうで割り込みの処理をするか,
+   * フラグを立てるように改良する必要が有るかも.
+   * (別の場所で頻繁に XDisplay_Sync() が呼ばれていると,キー割り込みが
+   *  発生しなくなってしまう)
+   * とりあえずは簡易的にこのような実装にしておいて問題無いだろう.
+   */
+  old_key = XDisplay_GetKeyPress(x_display);
+  XDisplay_Sync(x_display);
+  new_key = XDisplay_GetKeyPress(x_display);
+  /* 新しいキーが押された場合 */
+  /*
+   * WonderWitch で実験したところ,キーを離した場合には割り込みは
+   * かからないようだったので,押されたときのみコールバック関数を呼び出す.
+   */
+  if (new_key & (~old_key)) {
+    WWInterrupt_ExecuteKeyCallback(ww_interrupt);
+  }
+
+  /* シリアル受信割り込み */
+  /*
+   * 上と同じ理由で割り込みをとりこぼす可能性が有るので,UNIXSerialPort の
+   * ほうで割り込みの処理をするか,フラグを立てるように改良する必要が有るかも.
+   * とりあえずは簡易的にこのような実装にしておいて問題無いだろう.
+   */
+  if (WWSerialPort_IsOpened(ww_serial_port) &&
+      UNIXSerialPort_IsOpened(unix_serial_port)) {
+    if (UNIXSerialPort_IsDataExisting(unix_serial_port, 0))
+      WWInterrupt_ExecuteReceiveReadyCallback(ww_interrupt);
+  }
+
   return (0);
 }
 

+ 8 - 4
WonXSystem.h

@@ -5,16 +5,20 @@
 /* ここから                                                                  */
 /*****************************************************************************/
 
-#include "WWInterrupt.h"
-#include "WWTimer.h"
-#include "UNIXTimer.h"
-
 /*****************************************************************************/
 /* クラスの定義                                                              */
 /*****************************************************************************/
 
 typedef struct _WonXSystem * WonXSystem;
 
+/*****************************************************************************/
+/* ヘッダファイルのインクルード                                              */
+/*****************************************************************************/
+
+#include "WWInterrupt.h"
+#include "WWTimer.h"
+#include "UNIXTimer.h"
+
 /*****************************************************************************/
 /* メンバ関数の定義                                                          */
 /*****************************************************************************/

+ 0 - 55
WonXText.c

@@ -1,55 +0,0 @@
-/*****************************************************************************/
-/* ここから                                                                  */
-/*****************************************************************************/
-
-#include "WonXTextP.h"
-#include "etc.h"
-
-/*****************************************************************************/
-/* メンバ関数の定義                                                          */
-/*****************************************************************************/
-
-WWText WonXText_GetWWText(WonXText wonx_text)
-{ return (wonx_text->ww_text); }
-WWText WonXText_SetWWText(WonXText wonx_text, WWText ww_text)
-{ return (wonx_text->ww_text = ww_text); }
-
-WonXText WonXText_Create(WWScreen screen, int x, int y, int width, int height,
-			 WWPalette palette)
-{
-  WonXText wonx_text;
-  WWText ww_text;
-
-  wonx_text = (WonXText)malloc(sizeof(_WonXText));
-  if (wonx_text == NULL)
-    WonX_Error("WonXText_Create", "Cannot allocate memory.");
-
-  ww_text = WWText_Create(screen, x, y, width, height, palette);
-  if (ww_text == NULL)
-    WonX_Error("WonXText_Create", "Cannot create WonderWitch text.");
-  WonXText_SetWWText(wonx_text, ww_text);
-
-  return (wonx_text);
-}
-
-WonXText WonXText_Destroy(WonXText wonx_text)
-{
-  if (wonx_text == NULL)
-    WonX_Error("WonXText_Destroy", "Object is not created.");
-
-  if (WonXText_GetWWText(wonx_text))
-    WonXText_SetWWText(wonx_text,
-		       WWText_Destroy(WonXText_GetWWText(wonx_text)));
-
-  free(wonx_text);
-
-  return (NULL);
-}
-
-/*****************************************************************************/
-/* ここまで                                                                  */
-/*****************************************************************************/
-
-/*****************************************************************************/
-/* End of File.                                                              */
-/*****************************************************************************/

+ 9 - 5
XDisplay.h

@@ -5,10 +5,6 @@
 /* ここから                                                                  */
 /*****************************************************************************/
 
-#include "wonx_include/key.h"
-
-#include "WWLCDPanel.h"
-
 /*****************************************************************************/
 /* クラスの定義                                                              */
 /*****************************************************************************/
@@ -16,7 +12,15 @@
 typedef struct _XDisplay * XDisplay;
 
 /*****************************************************************************/
-/* メンバ関数の定義                                                          */
+/* ヘッダファイルのインクルード                                              */
+/*****************************************************************************/
+
+#include "wonx_include/key.h"
+
+#include "WWLCDPanel.h"
+
+/*****************************************************************************/
+/* メンバ関数の宣言                                                          */
 /*****************************************************************************/
 
 unsigned int XDisplay_GetKeyPress(XDisplay x_display);

+ 100 - 70
comm.c

@@ -14,6 +14,9 @@
 
 #include "wonx_configure.h"
 #include "WonX.h"
+#include "WonXSerialPort.h"
+#include "WWSerialPort.h"
+#include "UNIXSerialPort.h"
 #include "etc.h"
 
 /*****************************************************************************/
@@ -38,7 +41,9 @@
 
 void comm_open(void)
 {
+  WonXSerialPort wonx_serial_port;
   WWSerialPort ww_serial_port;
+  UNIXSerialPort unix_serial_port;
 
   if (!WonX_IsCreated()) WonX_Create();
 
@@ -48,12 +53,17 @@ void comm_open(void)
   printf("call : comm_open() : \n");
   fflush(stdout);
 
-  ww_serial_port = WonXSerialPort_GetWWSerialPort(WonX_GetWonXSerialPort());
+  wonx_serial_port = WonX_GetWonXSerialPort();
+  ww_serial_port = WonXSerialPort_GetWWSerialPort(wonx_serial_port);
+  unix_serial_port = WonXSerialPort_GetUNIXSerialPort(wonx_serial_port);
 
-  if (WWSerialPort_IsON(ww_serial_port))
-    WonX_Error("comm_open", "Serial port has already opened.");
+  if (WWSerialPort_IsOpened(ww_serial_port))
+    WonX_Warning("comm_open", "WW serial port has already opened.");
+  WWSerialPort_Open(ww_serial_port);
 
-  WWSerialPort_ON(ww_serial_port);
+  if (UNIXSerialPort_IsOpened(unix_serial_port))
+    WonX_Warning("comm_open", "UNIX serial port has already opened.");
+  UNIXSerialPort_Open(unix_serial_port);
 
   WonXDisplay_Sync(WonX_GetWonXDisplay());
 
@@ -68,7 +78,9 @@ void comm_open(void)
 
 void comm_close(void)
 {
+  WonXSerialPort wonx_serial_port;
   WWSerialPort ww_serial_port;
+  UNIXSerialPort unix_serial_port;
 
   if (!WonX_IsCreated()) WonX_Create();
 
@@ -78,12 +90,17 @@ void comm_close(void)
   printf("call : comm_close() : \n");
   fflush(stdout);
 
-  ww_serial_port = WonXSerialPort_GetWWSerialPort(WonX_GetWonXSerialPort());
+  wonx_serial_port = WonX_GetWonXSerialPort();
+  ww_serial_port = WonXSerialPort_GetWWSerialPort(wonx_serial_port);
+  unix_serial_port = WonXSerialPort_GetUNIXSerialPort(wonx_serial_port);
 
-  if (!WWSerialPort_IsON(ww_serial_port))
-    WonX_Error("comm_close", "Serial port is not opened.");
+  if (!WWSerialPort_IsClosed(ww_serial_port))
+    WonX_Warning("comm_close", "WW serial port is not opened.");
+  WWSerialPort_Close(ww_serial_port);
 
-  WWSerialPort_OFF(ww_serial_port);
+  if (!UNIXSerialPort_IsClosed(unix_serial_port))
+    WonX_Warning("comm_close", "UNIX serial port is not opened.");
+  UNIXSerialPort_Close(unix_serial_port);
 
   WonXDisplay_Sync(WonX_GetWonXDisplay());
 
@@ -98,75 +115,55 @@ void comm_close(void)
 
 static void comm_output(unsigned char c)
 {
-  if      (c == '\n') printf("\\n");
-  else if (c == '\r') printf("\\r");
-  else if (c == '\t') printf("\\t");
-  else if (isprint(c)) fputc(c, stdout);
-  else printf("^%02x", (int)c);
-  fflush(stdout);
+  WonXSerialPort wonx_serial_port;
+  UNIXSerialPort unix_serial_port;
+
+  wonx_serial_port = WonX_GetWonXSerialPort();
+  unix_serial_port = WonXSerialPort_GetUNIXSerialPort(wonx_serial_port);
+  UNIXSerialPort_SendCharacter(unix_serial_port, c);
+
   return;
 }
 
 static int comm_input(int timeout)
 {
-  int tmp;
+  WonXSerialPort wonx_serial_port;
+  UNIXSerialPort unix_serial_port;
   int c;
-  fd_set bitmap;
-  struct timeval t;
-  struct timeval * t_p;
-
-  /*
-   * 0 のときは,即時
-   * -1 のときは,無期限待ち
-   */
-  if (timeout == -1) {
-    t_p = NULL;
-  } else {
-    tmp = WONX_SERIAL_PORT_TIMETICKS * timeout;
-    t.tv_sec  =  tmp / 1000;
-    t.tv_usec = (tmp % 1000) * 1000;
-    t_p = &t;
-  }
-
-  FD_ZERO(&bitmap);
-  FD_SET(fileno(stdin), &bitmap);
 
-  /*
-   * FreeBSD3.4 で実験したところ,
-   * アラームシグナルを使用する場合,select()でのブロック中に
-   * アラームシグナルが発生すると,その直後にselect()もタイムアウト
-   * してしまうので,注意.
-   * (select() がタイムアウトした後にアラームシグナルが発生する場合は,
-   *  正常に動作した)
-   * 論理上は問題が無いが,期待した時間だけ待ってくれないという現象が
-   * 起きる可能性がある.
-   */
-  select(fileno(stdin) + 1, &bitmap, NULL, NULL, t_p);
-
-  c = FD_ISSET(fileno(stdin), &bitmap) ? fgetc(stdin) : -1;
-  c = (c == '\n') ? '\r' : c;
+  wonx_serial_port = WonX_GetWonXSerialPort();
+  unix_serial_port = WonXSerialPort_GetUNIXSerialPort(wonx_serial_port);
+  c = UNIXSerialPort_ReceiveCharacter(unix_serial_port,
+				      WONX_SERIAL_PORT_TIMETICKS * timeout);
 
   return (c);
 }
 
 int comm_send_char(unsigned char c)
 {
-  int ret;
-
+  WonXSerialPort wonx_serial_port;
   WWSerialPort ww_serial_port;
+  UNIXSerialPort unix_serial_port;
+  int ret;
 
   if (!WonX_IsCreated()) WonX_Create();
 
   /* タイマを一時停止する */
   UNIXTimer_Pause(WonXSystem_GetUNIXTimer(WonX_GetWonXSystem()));
 
-  printf("call : comm_send_char() : character = 0x%02x\n", (int)c);
+  printf("call : comm_send_char() : character = \'");
+  wonx_print_character(stdout, c);
+  printf("\'\n");
   fflush(stdout);
 
-  ww_serial_port = WonXSerialPort_GetWWSerialPort(WonX_GetWonXSerialPort());
+  wonx_serial_port = WonX_GetWonXSerialPort();
+  ww_serial_port = WonXSerialPort_GetWWSerialPort(wonx_serial_port);
+  unix_serial_port = WonXSerialPort_GetUNIXSerialPort(wonx_serial_port);
 
-  if (!WWSerialPort_IsON(ww_serial_port))
-    WonX_Error("comm_send_char", "Serial port is not opened.");
+  if (!WWSerialPort_IsOpened(ww_serial_port))
+    WonX_Error("comm_send_char", "WW serial port is not opened.");
+  if (!UNIXSerialPort_IsOpened(unix_serial_port))
+    WonX_Error("comm_send_char", "UNIX serial port is not opened.");
 
   printf("output to serial port : ");
   comm_output(c);
@@ -187,7 +184,9 @@ int comm_send_char(unsigned char c)
 
 int comm_receive_char(void)
 {
+  WonXSerialPort wonx_serial_port;
   WWSerialPort ww_serial_port;
+  UNIXSerialPort unix_serial_port;
   int c;
   int ret;
 
@@ -199,10 +198,14 @@ int comm_receive_char(void)
   printf("call : comm_receive_char() : \n");
   fflush(stdout);
 
-  ww_serial_port = WonXSerialPort_GetWWSerialPort(WonX_GetWonXSerialPort());
+  wonx_serial_port = WonX_GetWonXSerialPort();
+  ww_serial_port = WonXSerialPort_GetWWSerialPort(wonx_serial_port);
+  unix_serial_port = WonXSerialPort_GetUNIXSerialPort(wonx_serial_port);
 
-  if (!WWSerialPort_IsON(ww_serial_port))
-    WonX_Error("comm_receive_char", "Serial port is not opened.");
+  if (!WWSerialPort_IsOpened(ww_serial_port))
+    WonX_Error("comm_receive_char", "WW serial port is not opened.");
+  if (!UNIXSerialPort_IsOpened(unix_serial_port))
+    WonX_Error("comm_receive_char", "UNIX serial port is not opened.");
 
   c = comm_input(WWSerialPort_GetReceiveTimeout(ww_serial_port));
 
@@ -222,7 +225,9 @@ int comm_receive_char(void)
 
 int comm_receive_with_timeout(int timeout)
 {
+  WonXSerialPort wonx_serial_port;
   WWSerialPort ww_serial_port;
+  UNIXSerialPort unix_serial_port;
   int c;
   int ret;
 
@@ -234,10 +239,14 @@ int comm_receive_with_timeout(int timeout)
   printf("call : comm_receive_with_timeout() : timeout = %d\n", timeout);
   fflush(stdout);
 
-  ww_serial_port = WonXSerialPort_GetWWSerialPort(WonX_GetWonXSerialPort());
+  wonx_serial_port = WonX_GetWonXSerialPort();
+  ww_serial_port = WonXSerialPort_GetWWSerialPort(wonx_serial_port);
+  unix_serial_port = WonXSerialPort_GetUNIXSerialPort(wonx_serial_port);
 
-  if (!WWSerialPort_IsON(ww_serial_port))
-    WonX_Error("comm_receive_with_timeout", "Serial port is not opened.");
+  if (!WWSerialPort_IsOpened(ww_serial_port))
+    WonX_Error("comm_receive_with_timeout", "WW serial port is not opened.");
+  if (!UNIXSerialPort_IsOpened(unix_serial_port))
+    WonX_Error("comm_receive_with_timeout", "UNIX serial port is not opened.");
 
   c = comm_input(timeout);
 
@@ -257,8 +266,11 @@ int comm_receive_with_timeout(int timeout)
 
 int comm_send_string(char * string)
 {
+  WonXSerialPort wonx_serial_port;
   WWSerialPort ww_serial_port;
+  UNIXSerialPort unix_serial_port;
   int ret;
+  char * p;
   int i;
 
   if (!WonX_IsCreated()) WonX_Create();
@@ -266,13 +278,19 @@ int comm_send_string(char * string)
   /* タイマを一時停止する */
   UNIXTimer_Pause(WonXSystem_GetUNIXTimer(WonX_GetWonXSystem()));
 
-  printf("call : comm_send_string() : string = %s\n", string);
+  printf("call : comm_send_string() : string = \"");
+  for (p = string; *p != '\0'; p++) wonx_print_character(stdout, *p);
+  printf("\"\n");
   fflush(stdout);
 
-  ww_serial_port = WonXSerialPort_GetWWSerialPort(WonX_GetWonXSerialPort());
+  wonx_serial_port = WonX_GetWonXSerialPort();
+  ww_serial_port = WonXSerialPort_GetWWSerialPort(wonx_serial_port);
+  unix_serial_port = WonXSerialPort_GetUNIXSerialPort(wonx_serial_port);
 
-  if (!WWSerialPort_IsON(ww_serial_port))
-    WonX_Error("comm_send_string", "Serial port is not opened.");
+  if (!WWSerialPort_IsOpened(ww_serial_port))
+    WonX_Error("comm_send_string", "WW serial port is not opened.");
+  if (!UNIXSerialPort_IsOpened(unix_serial_port))
+    WonX_Error("comm_send_string", "UNIX serial port is not opened.");
 
   printf("output to serial port : ");
   for (i = 0; string[i]; i++) {
@@ -295,7 +313,9 @@ int comm_send_string(char * string)
 
 int comm_send_block(void * buffer, int size)
 {
+  WonXSerialPort wonx_serial_port;
   WWSerialPort ww_serial_port;
+  UNIXSerialPort unix_serial_port;
   int ret;
   int i;
 
@@ -307,10 +327,14 @@ int comm_send_block(void * buffer, int size)
   printf("call : comm_send_block() : buffer = %p, size = %d\n", buffer, size);
   fflush(stdout);
 
-  ww_serial_port = WonXSerialPort_GetWWSerialPort(WonX_GetWonXSerialPort());
+  wonx_serial_port = WonX_GetWonXSerialPort();
+  ww_serial_port = WonXSerialPort_GetWWSerialPort(wonx_serial_port);
+  unix_serial_port = WonXSerialPort_GetUNIXSerialPort(wonx_serial_port);
 
-  if (!WWSerialPort_IsON(ww_serial_port))
-    WonX_Error("comm_send_block", "Serial port is not opened.");
+  if (!WWSerialPort_IsOpened(ww_serial_port))
+    WonX_Error("comm_send_block", "WW serial port is not opened.");
+  if (!UNIXSerialPort_IsOpened(unix_serial_port))
+    WonX_Error("comm_send_block", "UNIX serial port is not opened.");
 
   printf("output to serial port : ");
   for (i = 0; i < size; i++) {
@@ -333,7 +357,9 @@ int comm_send_block(void * buffer, int size)
 
 int comm_receive_block(void * buffer, int size)
 {
+  WonXSerialPort wonx_serial_port;
   WWSerialPort ww_serial_port;
+  UNIXSerialPort unix_serial_port;
   int ret;
   int c;
   int i;
@@ -347,10 +373,14 @@ int comm_receive_block(void * buffer, int size)
 	 buffer, size);
   fflush(stdout);
 
-  ww_serial_port = WonXSerialPort_GetWWSerialPort(WonX_GetWonXSerialPort());
+  wonx_serial_port = WonX_GetWonXSerialPort();
+  ww_serial_port = WonXSerialPort_GetWWSerialPort(wonx_serial_port);
+  unix_serial_port = WonXSerialPort_GetUNIXSerialPort(wonx_serial_port);
 
-  if (!WWSerialPort_IsON(ww_serial_port))
-    WonX_Error("comm_receive_block", "Serial port is not opened.");
+  if (!WWSerialPort_IsOpened(ww_serial_port))
+    WonX_Error("comm_receive_block", "WW serial port is not opened.");
+  if (!UNIXSerialPort_IsOpened(unix_serial_port))
+    WonX_Error("comm_receive_block", "UNIX serial port is not opened.");
 
   ret = 0;
   for (i = 0; i < size; i++) {

+ 12 - 6
disp.c

@@ -1082,6 +1082,7 @@ unsigned int palette_get_color(unsigned int palette_num)
   int mapped_colors[4];
   WWPalette palette;
   unsigned short int ret;
+  int i;
 
   if (!WonX_IsCreated()) WonX_Create();
 
@@ -1094,17 +1095,22 @@ unsigned int palette_get_color(unsigned int palette_num)
   palette =
     WWDisplay_GetPalette(WonXDisplay_GetWWDisplay(WonX_GetWonXDisplay()),
 			 palette_num);
+  /* 透明色は -1 で返されるので注意すること */
   WWPalette_GetMappedColors(palette, mapped_colors);
 
+  /* 透明色は -1 で表されるので,0にする */
+  for (i = 0; i < 4; i++)
+    if (mapped_colors[i] == -1) mapped_colors[i] = 0;
+
   ret = 0;
-  ret |= mapped_colors[0] & 0x07;
+  ret |=  mapped_colors[0] & 0x07;
   ret |= (mapped_colors[1] & 0x07) <<  4;
   ret |= (mapped_colors[2] & 0x07) <<  8;
   ret |= (mapped_colors[3] & 0x07) << 12;
 
   WonXDisplay_Sync(WonX_GetWonXDisplay());
 
-  printf("call : palette_get_color() : return value = %u\n", (int)ret);
+  printf("call : palette_get_color() : return value = 0x%04x\n", (int)ret);
   fflush(stdout);
 
   /* タイマをもとに戻す */
@@ -1172,10 +1178,10 @@ unsigned long int lcd_get_color(void)
   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;
+  ret |= ((unsigned long int)lcd_colors[4] & 0x0f) << 16;
+  ret |= ((unsigned long int)lcd_colors[5] & 0x0f) << 20;
+  ret |= ((unsigned long int)lcd_colors[6] & 0x0f) << 24;
+  ret |= ((unsigned long int)lcd_colors[7] & 0x0f) << 28;
 
   WonXDisplay_Sync(WonX_GetWonXDisplay());
 

+ 16 - 12
etc.c

@@ -1,26 +1,30 @@
 #include "etc.h"
 
-#include <stdio.h>
-#include <stdlib.h>
+#include <ctype.h>
 
 /*===========================================================================*/
-/* エラー処理                                                                */
+/* "true", "false" の文字列を返す                                            */
 /*===========================================================================*/
 
-int WonX_Error(char * funcname, char * message)
+char * wonx_true_false(int b)
 {
-  fprintf(stderr, "%s(): %s\n", funcname, message);
-  exit (1);
+  char * s[] = {"false", "true"};
+  b = b ? 1 : 0;
+  return (s[b]);
 }
 
 /*===========================================================================*/
-/* "true", "false" の文字列を返す                                            */
+/* 文字の出力                                                                */
 /*===========================================================================*/
 
-char * true_false(int b)
+int wonx_print_character(FILE * fp, unsigned char c)
 {
-  char * s[] = {"false", "true"};
-  b = b ? 1 : 0;
-  return (s[b]);
+  if      (c == '\n') fprintf(fp, "\\n");
+  else if (c == '\r') fprintf(fp, "\\r");
+  else if (c == '\t') fprintf(fp, "\\t");
+  else if (c == ' ' ) fprintf(fp, "\\s");
+  else if (isprint(c)) fputc(c, fp);
+  else fprintf(fp, "^%02x", (int)c);
+  fflush(fp);
+  return (0);
 }
-

+ 7 - 5
etc.h

@@ -1,17 +1,19 @@
 #ifndef _etc_h_INCLUDED_
 #define _etc_h_INCLUDED_
 
+#include <stdio.h>
+#include <stdlib.h>
+
 /*===========================================================================*/
-/* エラ〖借妄                                                                */
+/* "true", "false" の矢机误を手す                                            */
 /*===========================================================================*/
 
-int WonX_Error(char * funcname, char * message);
+char * wonx_true_false(int b);
 
 /*===========================================================================*/
-/* "true", "false" の矢机误を手す                                            */
+/* 矢机の叫蜗                                                                */
 /*===========================================================================*/
 
-char * true_false(int b);
+int wonx_print_character(FILE * fp, unsigned char c);
 
 #endif
-

+ 36 - 0
makefile_for_wwterm

@@ -0,0 +1,36 @@
+VERSION = WWTerm-b05
+PKGNAME = wwterm-b05
+
+#OBJS = terminal.obj termlib.obj lib.obj keyboard.obj keymap.obj com.obj screen.obj escape.obj esclib.obj
+#OBJS_FULL = D:\\terminal.obj D:\\termlib.obj D:\\lib.obj D:\\keyboard.obj D:\\keymap.obj D:\\com.obj D:\\screen.obj D:\\escape.obj D:\\esclib.obj
+OBJS = terminal.o termlib.o lib.o keyboard.o keymap.o com.o screen.o escape.o esclib.o
+
+#.SUFFIXES: .c .obj
+.SUFFIXES: .c .o
+
+#terminal.fx :	terminal.bin
+#	doscmd mkfent16 D:\\terminal.cf
+
+#terminal.bin :	$(OBJS)
+#	echo $(OBJS_FULL) > objs
+#	doscmd lcc86 -O -o D:\\terminal.bin @D:\\objs
+
+terminal :	$(OBJS)
+	$(CC) -O -o terminal $(OBJS) -L. -L/usr/X11R6/lib -lwonx -lX11 -lXt
+
+#.c.obj :        $*.c
+#	doscmd lcc86 -c D:\\$*.c -O -I.
+
+.c.o :        $*.c
+	$(CC) -c $*.c -O -I.
+
+clean :
+#	rm -f terminal.fx terminal.bin *.obj $(PKGNAME).zip
+	rm -f terminal *.o $(PKGNAME).zip
+
+package :	terminal.bin terminal.fx
+	mkdir -p $(PKGNAME)
+	rm -fR $(PKGNAME)/*
+	cp COPYING COPYRIGHT OMAKE.jpn makefile \
+		*.h *.c *.bin *.cf *.fx $(PKGNAME)
+	zip -r $(PKGNAME) $(PKGNAME)

+ 52 - 0
service.c

@@ -0,0 +1,52 @@
+/*****************************************************************************/
+/* ここから                                                                  */
+/*****************************************************************************/
+
+#include <stdio.h>
+
+#include "wonx_include/service.h"
+
+#include "WonX.h"
+
+/*****************************************************************************/
+/* ダミー関数の定義                                                          */
+/*****************************************************************************/
+
+int _asm_inline(char * code) { return (0); }
+int _asm_int(char * code, int ax) { return (0); }
+int _asm_intb(char * code, int ax, unsigned char bl) { return (0); }
+int _asm_intbb(char * code, int ax, unsigned char bl, unsigned char cl) { return (0); }
+int _asm_intw(char * code, int ax, int bx) { return (0); }
+int _asm_intww(char * code, int ax, int bx, int cx) { return (0); }
+int _asm_intwww(char * code, int ax, int bx, int cx, int dx) { return (0); }
+int _asm_intwwww(char * code, int ax, int bx, int cx, int dx, int si) { return (0); }
+int _asm_intwp(char * code, int ax, int bx, int (*dummy)(void), void * dx) { return (0); }
+int _asm_intwwp(char * code, int ax, int bx, int cx, void * dx) { return (0); }
+int _asm_intwwwp(char * code, int ax, int bx, int cx, int dx, void * si) { return (0); }
+int _asm_intwfp(char * code, int ax, int bx, void * dsdx) { return (0); }
+int _asm_intfp(char * code, int ax, void * bxdx) { return (0); }
+
+long int _asm_intl(char * code, int ax) { return (0); }
+long int _asm_intlw(char * code, int ax, int bx) { return (0); }
+long int _asm_intlww(char * code, int ax, int bx, int cx) { return (0); }
+long int _asm_intlwww(char * code, int ax, int bx, int cx, int dx) { return (0); }
+long int _asm_intlwwww(char * code, int ax, int bx, int cx, int dx, int si) { return (0); }
+long int _asm_intlwp(char * code, int ax, int bx, int (*dummy)(void), void * dx) { return (0); }
+long int _asm_intlwwp(char * code, int ax, int bx, int cx, void * dx) { return (0); }
+long int _asm_intlwwwp(char * code, int ax, int bx, int cx, int dx, void * si) { return (0); }
+long int _asm_intlwfp(char * code, int ax, int bx, void * dsdx) { return (0); }
+
+void bios_exit()
+{
+  printf("call : bios_exit() : \n");
+  fflush(stdout);
+  exit (0);
+}
+
+/*****************************************************************************/
+/* ここまで                                                                  */
+/*****************************************************************************/
+
+/*****************************************************************************/
+/* End of File.                                                              */
+/*****************************************************************************/

+ 2 - 1
sout2str.pl

@@ -4,10 +4,11 @@ use FileHandle;
 
 while (<STDIN>) {
 	if (/output to serial port : /) {
-		($string) = /output to serial port : (.*)/;
+		($string) = /output to serial port : \"(.*)\"\n/;
 		$string =~ s/\\n/\n/;
 		$string =~ s/\\r/\n/;
 		$string =~ s/\\t/\t/;
+		$string =~ s/\\s/ /;
 		print "$string";
 		STDOUT->autoflush();
 	}

+ 0 - 7
system.c

@@ -177,13 +177,6 @@ unsigned int sys_get_resume(void)
   return (0);
 }
 
-void bios_exit()
-{
-  printf("call : bios_exit() : \n");
-  fflush(stdout);
-  exit (0);
-}
-
 /*****************************************************************************/
 /* ¤³¤³¤Þ¤Ç                                                                  */
 /*****************************************************************************/

+ 224 - 20
text.c

@@ -10,6 +10,9 @@
 
 #include "WonX.h"
 #include "WWText.h"
+#include "WWDisplay.h"
+#include "WWCursor.h"
+#include "etc.h"
 
 /*****************************************************************************/
 /* 互換関数の定義                                                            */
@@ -33,11 +36,11 @@
 
 static void _text_window_init(int x, int y, int w, int h, unsigned int base)
 {
-  WWText ww_text;
   WWDisplay ww_display;
+  WWText ww_text;
 
-  ww_text = WonXText_GetWWText(WonX_GetWonXText());
   ww_display = WonXDisplay_GetWWDisplay(WonX_GetWonXDisplay());
+  ww_text = WWDisplay_GetText(ww_display);
 
   WWText_SetTextWindow(ww_text, x, y, w, h, base, ww_display);
 
@@ -112,11 +115,11 @@ int text_get_mode(void)
 
 static void _text_put_char(int x, int y, unsigned int c)
 {
-  WWText ww_text;
   WWDisplay ww_display;
+  WWText ww_text;
 
-  ww_text = WonXText_GetWWText(WonX_GetWonXText());
   ww_display = WonXDisplay_GetWWDisplay(WonX_GetWonXDisplay());
+  ww_text = WWDisplay_GetText(ww_display);
 
   WWText_PutCharacter(ww_text, x, y, c, ww_display);
 
@@ -130,7 +133,9 @@ void text_put_char(int x, int y, unsigned int c)
   /* タイマを一時停止する */
   UNIXTimer_Pause(WonXSystem_GetUNIXTimer(WonX_GetWonXSystem()));
 
-  printf("call : text_put_char() : x = %d, y = %d, character = %u\n", x, y, (int)c);
+  printf("call : text_put_char() : x = %d, y = %d, character = \'", x, y);
+  wonx_print_character(stdout, c);
+  printf("\'\n");
   fflush(stdout);
 
   _text_put_char(x, y, c);
@@ -148,11 +153,11 @@ void text_put_char(int x, int y, unsigned int c)
 static int _text_put_string(int x, int y, char * string)
 {
   int i, len, ret;
-  WWText ww_text;
   WWDisplay ww_display;
+  WWText ww_text;
 
-  ww_text = WonXText_GetWWText(WonX_GetWonXText());
   ww_display = WonXDisplay_GetWWDisplay(WonX_GetWonXDisplay());
+  ww_text = WWDisplay_GetText(ww_display);
 
   len = strlen(string);
   ret = 0;
@@ -167,13 +172,16 @@ static int _text_put_string(int x, int y, char * string)
 int text_put_string(int x, int y, char * string)
 {
   int ret;
+  char * p;
 
   if (!WonX_IsCreated()) WonX_Create();
 
   /* タイマを一時停止する */
   UNIXTimer_Pause(WonXSystem_GetUNIXTimer(WonX_GetWonXSystem()));
 
-  printf("call : text_put_string() : x = %d, y = %d, string = %s\n", x, y, string);
+  printf("call : text_put_string() : x = %d, y = %d, string = \"", x, y);
+  for (p = string; *p != '\0'; p++) wonx_print_character(stdout, *p);
+  printf("\"\n");
   fflush(stdout);
 
   ret = _text_put_string(x, y, string);
@@ -192,19 +200,21 @@ int text_put_string(int x, int y, char * string)
 int text_put_substring(int x, int y, char * s, int length)
 {
   int i, ret;
-  WWText ww_text;
   WWDisplay ww_display;
+  WWText ww_text;
 
   if (!WonX_IsCreated()) WonX_Create();
 
   /* タイマを一時停止する */
   UNIXTimer_Pause(WonXSystem_GetUNIXTimer(WonX_GetWonXSystem()));
 
-  printf("call : text_put_substring() : x = %d, y = %d, string = %s, length = %d\n", x, y, s, length);
+  printf("call : text_put_substring() : x = %d, y = %d, length = %d, string = \"", x, y, length);
+  for (i = 0; i < length; i++) wonx_print_character(stdout, s[i]);
+  printf("\"\n");
   fflush(stdout);
 
-  ww_text = WonXText_GetWWText(WonX_GetWonXText());
   ww_display = WonXDisplay_GetWWDisplay(WonX_GetWonXDisplay());
+  ww_text = WWDisplay_GetText(ww_display);
 
   ret = 0;
   for (i = 0; i < length; i++) {
@@ -292,8 +302,8 @@ void text_fill_char(int x, int y, int length, int c)
 
 void text_set_palette(int palette_num)
 {
-  WWText ww_text;
   WWDisplay ww_display;
+  WWText ww_text;
 
   if (!WonX_IsCreated()) WonX_Create();
 
@@ -303,8 +313,8 @@ void text_set_palette(int palette_num)
   printf("call : text_set_palette() : palette = %d\n", palette_num);
   fflush(stdout);
 
-  ww_text = WonXText_GetWWText(WonX_GetWonXText());
   ww_display = WonXDisplay_GetWWDisplay(WonX_GetWonXDisplay());
+  ww_text = WWDisplay_GetText(ww_display);
 
   WWText_SetPalette(ww_text, WWDisplay_GetPalette(ww_display, palette_num));
 
@@ -321,6 +331,7 @@ void text_set_palette(int palette_num)
 
 int text_get_palette(void)
 {
+  WWDisplay ww_display;
   WWText ww_text;
   int num;
 
@@ -332,7 +343,8 @@ int text_get_palette(void)
   printf("call : text_get_palette() : \n");
   fflush(stdout);
 
-  ww_text = WonXText_GetWWText(WonX_GetWonXText());
+  ww_display = WonXDisplay_GetWWDisplay(WonX_GetWonXDisplay());
+  ww_text = WWDisplay_GetText(ww_display);
 
   num = WWPalette_GetNumber(WWText_GetPalette(ww_text));
 
@@ -361,8 +373,8 @@ void text_get_fontdata(int c, void * buffer)
 
 void text_set_screen(int screen)
 {
-  WWText ww_text;
   WWDisplay ww_display;
+  WWText ww_text;
 
   if (!WonX_IsCreated()) WonX_Create();
 
@@ -372,8 +384,8 @@ void text_set_screen(int screen)
   printf("call : text_set_screen() : screen = %d\n", screen);
   fflush(stdout);
 
-  ww_text = WonXText_GetWWText(WonX_GetWonXText());
   ww_display = WonXDisplay_GetWWDisplay(WonX_GetWonXDisplay());
+  ww_text = WWDisplay_GetText(ww_display);
 
   WWText_SetScreen(ww_text, WWDisplay_GetScreen(ww_display, screen));
 
@@ -390,6 +402,7 @@ void text_set_screen(int screen)
 
 int text_get_screen(void)
 {
+  WWDisplay ww_display;
   WWText ww_text;
   int n;
 
@@ -401,7 +414,8 @@ int text_get_screen(void)
   printf("call : text_get_screen() : \n");
   fflush(stdout);
 
-  ww_text = WonXText_GetWWText(WonX_GetWonXText());
+  ww_display = WonXDisplay_GetWWDisplay(WonX_GetWonXDisplay());
+  ww_text = WWDisplay_GetText(ww_display);
 
   n = WWScreen_GetNumber(WWText_GetScreen(ww_text));
 
@@ -418,29 +432,219 @@ int text_get_screen(void)
 
 void cursor_display(int flag)
 {
+  WWDisplay ww_display;
+  WWCursor ww_cursor;
+
+  if (!WonX_IsCreated()) WonX_Create();
+
+  /* タイマを一時停止する */
+  UNIXTimer_Pause(WonXSystem_GetUNIXTimer(WonX_GetWonXSystem()));
+
+  printf("call : cursor_display() : flag = %d\n", flag);
+  fflush(stdout);
+
+  ww_display = WonXDisplay_GetWWDisplay(WonX_GetWonXDisplay());
+  ww_cursor = WWDisplay_GetCursor(ww_display);
+
+  switch (flag) {
+  case 0: WWCursor_OFF(ww_cursor); break;
+  case 1: WWCursor_ON( ww_cursor); break;
+  default:
+    WonX_Warning("cursor_display", "Cursor flag is 0 or 1.");
+    WWCursor_ON(ww_cursor); /* 一応 ON にしとく */
+  }
+
+  WonXDisplay_Flush(WonX_GetWonXDisplay());
+
+  printf("call : cursor_display() : return value = none\n");
+  fflush(stdout);
+
+  /* タイマをもとに戻す */
+  UNIXTimer_Unpause(WonXSystem_GetUNIXTimer(WonX_GetWonXSystem()));
+
+  return;
 }
 
 int cursor_status(void)
 {
-  return (0);
+  WWDisplay ww_display;
+  WWCursor ww_cursor;
+  int ret;
+
+  if (!WonX_IsCreated()) WonX_Create();
+
+  /* タイマを一時停止する */
+  UNIXTimer_Pause(WonXSystem_GetUNIXTimer(WonX_GetWonXSystem()));
+
+  printf("call : cursor_status() : \n");
+  fflush(stdout);
+
+  ww_display = WonXDisplay_GetWWDisplay(WonX_GetWonXDisplay());
+  ww_cursor = WWDisplay_GetCursor(ww_display);
+
+  ret = WWCursor_IsON(ww_cursor) ? 1 : 0;
+
+  WonXDisplay_Sync(WonX_GetWonXDisplay());
+
+  printf("call : cursor_status() : return value = %d\n", ret);
+  fflush(stdout);
+
+  /* タイマをもとに戻す */
+  UNIXTimer_Unpause(WonXSystem_GetUNIXTimer(WonX_GetWonXSystem()));
+
+  return (ret);
 }
 
 void cursor_set_location(int x, int y, int w, int h)
 {
+  WWDisplay ww_display;
+  WWCursor ww_cursor;
+
+  if (!WonX_IsCreated()) WonX_Create();
+
+  /* タイマを一時停止する */
+  UNIXTimer_Pause(WonXSystem_GetUNIXTimer(WonX_GetWonXSystem()));
+
+  printf("call : cursor_set_location() : x = %d, y = %d, w = %d, h = %d",
+	 x, y, w, h);
+  fflush(stdout);
+
+  ww_display = WonXDisplay_GetWWDisplay(WonX_GetWonXDisplay());
+  ww_cursor = WWDisplay_GetCursor(ww_display);
+
+  if (x < 0)
+    WonX_Warning("cursor_set_location", "Value of x is too small.");
+  if (x > TEXT_SCREEN_WIDTH - 1)
+    WonX_Warning("cursor_set_location", "Value of x is too large.");
+  if (y < 0)
+    WonX_Warning("cursor_set_location", "Value of y is too small.");
+  if (y > TEXT_SCREEN_HEIGHT - 1)
+    WonX_Warning("cursor_set_location", "Value of y is too large.");
+  if (w <= 0)
+    WonX_Warning("cursor_set_location", "Value of w is too small.");
+  if (h <= 0)
+    WonX_Warning("cursor_set_location", "Value of h is too small.");
+
+  WWCursor_SetX(ww_cursor, x);
+  WWCursor_SetY(ww_cursor, y);
+  WWCursor_SetWidth( ww_cursor, w);
+  WWCursor_SetHeight(ww_cursor, h);
+
+  WonXDisplay_Flush(WonX_GetWonXDisplay());
+
+  printf("call : cursor_set_location() : return value = none\n");
+  fflush(stdout);
+
+  /* タイマをもとに戻す */
+  UNIXTimer_Unpause(WonXSystem_GetUNIXTimer(WonX_GetWonXSystem()));
+
+  return;
 }
 
 unsigned long int cursor_get_location(void)
 {
-  return (0);
+  WWDisplay ww_display;
+  WWCursor ww_cursor;
+  unsigned long int ret;
+
+  if (!WonX_IsCreated()) WonX_Create();
+
+  /* タイマを一時停止する */
+  UNIXTimer_Pause(WonXSystem_GetUNIXTimer(WonX_GetWonXSystem()));
+
+  printf("call : cursor_get_location() : \n");
+  fflush(stdout);
+
+  ww_display = WonXDisplay_GetWWDisplay(WonX_GetWonXDisplay());
+  ww_cursor = WWDisplay_GetCursor(ww_display);
+
+  ret = 0;
+  ret |= (((unsigned long int)WWCursor_GetX(     ww_cursor) & 0xff) <<  0);
+  ret |= (((unsigned long int)WWCursor_GetY(     ww_cursor) & 0xff) <<  8);
+  ret |= (((unsigned long int)WWCursor_GetWidth( ww_cursor) & 0xff) << 16);
+  ret |= (((unsigned long int)WWCursor_GetHeight(ww_cursor) & 0xff) << 24);
+
+  WonXDisplay_Sync(WonX_GetWonXDisplay());
+
+  printf("call : cursor_get_location() : return value = 0x%08x\n", (int)ret);
+  fflush(stdout);
+
+  /* タイマをもとに戻す */
+  UNIXTimer_Unpause(WonXSystem_GetUNIXTimer(WonX_GetWonXSystem()));
+
+  return (ret);
 }
 
 void cursor_set_type(int palette_num, int interval)
 {
+  WWDisplay ww_display;
+  WWCursor ww_cursor;
+
+  if (!WonX_IsCreated()) WonX_Create();
+
+  /* タイマを一時停止する */
+  UNIXTimer_Pause(WonXSystem_GetUNIXTimer(WonX_GetWonXSystem()));
+
+  printf("call : cursor_set_type() : palette = %d, interval = %d",
+	 palette_num, interval);
+  fflush(stdout);
+
+  ww_display = WonXDisplay_GetWWDisplay(WonX_GetWonXDisplay());
+  ww_cursor = WWDisplay_GetCursor(ww_display);
+
+  if (palette_num < 0)
+    WonX_Error("cursor_set_type", "Palette number is too small.");
+  if (palette_num > 15)
+    WonX_Error("cursor_set_type", "Palette number is too large.");
+  if (interval < 0)
+    WonX_Warning("cursor_set_type", "Value of interval is too small.");
+  if (interval > 255)
+    WonX_Warning("cursor_set_type", "Value of interval is too small.");
+
+  WWCursor_SetPalette(ww_cursor,
+		      WWDisplay_GetPalette(ww_display, palette_num));
+  WWCursor_SetInterval(ww_cursor, interval);
+
+  WonXDisplay_Flush(WonX_GetWonXDisplay());
+
+  printf("call : cursor_set_type() : return value = none\n");
+  fflush(stdout);
+
+  /* タイマをもとに戻す */
+  UNIXTimer_Unpause(WonXSystem_GetUNIXTimer(WonX_GetWonXSystem()));
+
+  return;
 }
 
 unsigned long int cursor_get_type(void)
 {
-  return (0);
+  WWDisplay ww_display;
+  WWCursor ww_cursor;
+  unsigned long int ret;
+
+  if (!WonX_IsCreated()) WonX_Create();
+
+  /* タイマを一時停止する */
+  UNIXTimer_Pause(WonXSystem_GetUNIXTimer(WonX_GetWonXSystem()));
+
+  printf("call : cursor_get_type() : \n");
+  fflush(stdout);
+
+  ww_display = WonXDisplay_GetWWDisplay(WonX_GetWonXDisplay());
+  ww_cursor = WWDisplay_GetCursor(ww_display);
+
+  ret = WWPalette_GetNumber(WWCursor_GetPalette(ww_cursor));
+  ret |= (((unsigned long int)WWCursor_GetInterval(ww_cursor) & 0xff) << 8);
+
+  WonXDisplay_Sync(WonX_GetWonXDisplay());
+
+  printf("call : cursor_get_type() : return value = 0x%08x\n", (int)ret);
+  fflush(stdout);
+
+  /* タイマをもとに戻す */
+  UNIXTimer_Unpause(WonXSystem_GetUNIXTimer(WonX_GetWonXSystem()));
+
+  return (ret);
 }
 
 int text_printf(int x, int y, const char *format, ...)

+ 68 - 0
wonx_include/service.h

@@ -6,8 +6,76 @@
 #define MK_WORD(high,low)  (((unsigned short int)(high) <<  8) | ((unsigned short int)(low)))
 #define MK_DWORD(high,low) (((unsigned long  int)(high) << 16) | ((unsigned long  int)(low)))
 #define MK_FP(seg,off) ((void *)MK_DWORD(seg,off))
+
+#if 0
 #define FP_OFF(p) ((unsigned short int)((unsigned long int)(p) & 0xffff))
 #define FP_SEG(p) ((unsigned short int)((unsigned long int)(p) >> 16))
+#else
+#define FP_OFF(p) (p)
+#define FP_SEG(p) (0)
+#endif
+
+int _asm_inline(char * code);
+int _asm_int(char * code, int ax);
+int _asm_intb(char * code, int ax, unsigned char bl);
+int _asm_intbb(char * code, int ax, unsigned char bl, unsigned char cl);
+int _asm_intw(char * code, int ax, int bx);
+int _asm_intww(char * code, int ax, int bx, int cx);
+int _asm_intwww(char * code, int ax, int bx, int cx, int dx);
+int _asm_intwwww(char * code, int ax, int bx, int cx, int dx, int si);
+int _asm_intwp(char * code, int ax, int bx, int (*dummy)(void), void * dx);
+int _asm_intwwp(char * code, int ax, int bx, int cx, void * dx);
+int _asm_intwwwp(char * code, int ax, int bx, int cx, int dx, void * si);
+int _asm_intwfp(char * code, int ax, int bx, void * dsdx);
+int _asm_intfp(char * code, int ax, void * bxdx);
+
+long int _asm_intl(char * code, int ax);
+long int _asm_intlw(char * code, int ax, int bx);
+long int _asm_intlww(char * code, int ax, int bx, int cx);
+long int _asm_intlwww(char * code, int ax, int bx, int cx, int dx);
+long int _asm_intlwwww(char * code, int ax, int bx, int cx, int dx, int si);
+long int _asm_intlwp(char * code, int ax, int bx, int (*dummy)(void), void * dx);
+long int _asm_intlwwp(char * code, int ax, int bx, int cx, void * dx);
+long int _asm_intlwwwp(char * code, int ax, int bx, int cx, int dx, void * si);
+long int _asm_intlwfp(char * code, int ax, int bx, void * dsdx);
+
+#define service(vec, ah)                          _asm_int(NULL,0)
+#define serviceb(vec, ah, bl)                     _asm_intb(NULL,0,0)
+#define servicebb(vec, ah, bl, cl)                _asm_intbb(NULL,0,0,0)
+#define servicew(vec, ah, bx)                     _asm_intw(NULL,0,0)
+#define serviceww(vec, ah, bx, cx)                _asm_intww(NULL,0,0,0)
+#define servicewww(vec, ah, bx, cx, dx)           _asm_intwww(NULL,0,0,0,0)
+#define servicew_w(vec, ah, bx, dx)               _asm_intwww(NULL,0,0,0,0)
+#define servicewwww(vec, ah, bx, cx, dx, si)      _asm_intwwww(NULL,0,0,0,0,0)
+#define servicewp(vec, ah, bx, dx)                _asm_intwp(NULL,0,0,0,0)
+#define servicewwp(vec, ah, bx, cx, dx)           _asm_intwwp(NULL,0,0,0,0)
+#define servicewwwp(vec, ah, bx, cx, dx, si)      _asm_intwwwp(NULL,0,0,0,0,0)
+#define servicewfp(vec, ah, bx, dsdx)             _asm_intwfp(NULL,0,0,0)
+#define servicewwfp(vec, ah, bx, cx, dsdx)        _asm_intwfp(NULL,0,0,0)
+#define servicefp(vec, ah, bxdx)                  _asm_intwfp(NULL,0,0,0)
+
+#define servicex(vec, ah, al)                     _asm_int(NULL,0)
+#define servicexw(vec, ah, al, bx)                _asm_intw(NULL,0,0)
+#define servicexww(vec, ah, al, bx, cx)           _asm_intww(NULL,0,0,0)
+#define servicexwww(vec, ah, al, bx, cx, dx)      _asm_intwww(NULL,0,0,0,0)
+#define servicexwwww(vec, ah, al, bx, cx, dx, si) _asm_intwwww(NULL,0,0,0,0,0)
+#define servicexwp(vec, ah, al, bx, dx)           _asm_intwp(NULL,0,0,0,0)
+#define servicexwwp(vec, ah, al, bx, cx, dx)      _asm_intwwp(NULL,0,0,0,0)
+#define servicexwfp(vec, ah, al, bx, dsdx)        _asm_intwfp(NULL,0,0,0)
+
+#define servicel(vec, ah)                         _asm_intl(NULL,0)
+#define servicelw(vec, ah, bx)                    _asm_intlw(NULL,0,0)
+#define servicelww(vec, ah, bx, cx)               _asm_intlww(NULL,0,0,0)
+#define servicelwww(vec, ah, bx, cx, dx)          _asm_intlwww(NULL,0,0,0,0)
+#define servicelwp(vec, ah, bx, dx)               _asm_intlwp(NULL,0,0,0,0)
+#define servicelwfp(vec, ah, bx, dsdx)            _asm_intlwfp(NULL,0,0,0)
+
+#define servicelx(vec, ah, al)                    _asm_intl(NULL ,0)
+#define servicelxw(vec, ah, al, bx)               _asm_intlw(NULL,0,0)
+#define servicelxww(vec, ah, al, bx, cx)          _asm_intlww(NULL,0,0,0)
+#define servicelxwww(vec, ah, al, bx, cx, dx)     _asm_intlwww(NULL,0,0,0,0)
+#define servicelxwp(vec, ah, al, bx, dx)          _asm_intlwp(NULL,0,0,0,0)
+#define servicelxwfp(vec, ah, al, bx, dsdx)       _asm_intlwfp(NULL,0,0,0)
 
 void bios_exit();
 

+ 0 - 2
wonx_include/system.h

@@ -53,6 +53,4 @@ int sys_swap(int core);
 void sys_set_resume(unsigned int flags);
 unsigned int sys_get_resume(void);
 
-void bios_exit();
-
 #endif

BIN
wwterm-b05.zip