From d1cde9116a2f00c1b3de95d55677e7c7d9d7a454 Mon Sep 17 00:00:00 2001 From: Hiroaki Sakai Date: Sat, 13 Jan 2001 12:00:00 +0900 Subject: [PATCH] Added dump of RGB value when dumping palette data. Fixed a part of the data dump part. Changed the line of perl script from / usr / bin / perl to / usr / local / bin / perl. (On FreeBSD, Japanese perl is in / usr / local / bin) For disp.c, libwwc.c, a function for reading and acquiring bitmap data of characters, The type of bitmap data is not unsigned char *, but instead of short int *, long int * It was modified to an appropriate type. Let the bitmap of the WWCharacter class be union of uchar, ushort, ulong, By accessing with an appropriate type in WWCharacter_GetPixel () The endian dependence of bitmap data is eliminated. (i386, confirmed by SPARC) Fixed how to get the value of WWCharacter_GetPixel () in 16 PACKED color mode. (The bug that the character was displayed inverted horizontally was resolved) Stop for 10 seconds at F11, forcibly end with Ctrl-c or F12, Added iconization with Ctrl-i. (It was a function that was originally, but I forgot that, We modified it somewhat to make it formal support) Move display / non-display change key from p to F10. Manual correction. XDisplay.c: generated with XColorGC_CreateFromRGB () with XDisplay_DrawLCDWindow () Since we did not Destroy () the XColorGC object, we made a bug that caused memory flow Fix. (XColorGC_Destroy (x_color_gc) addition) Add wonx_include / fcntl.h. The contents are / usr / include / fcntl.h, Just include /usr/include/sys/fcntl.h. Format change of serial output message (output to serial port:). (I tried to enclose it with "".) etc.c: wonx_print_character () Fixed. (Add \ ", \ \ and others) Fix sout2str.pl. (Add \ ", \ \ etc .... The above message for serial output It was modified according to format change) Added int2sint.pl, filters.pl, challsrc.sh. Change sys2wonx.pl. in wonx_include / types.h typedef unsigned short WORD; typedef unsigned long DWORD; To typedef unsigned short int WORD; typedef unsigned long int DWORD; change to. Fixed README. Version 2.1 - from wonx-2.1.tar.gz --- HISTORY | 57 ++++++ Makefile | 20 ++- README | 305 ++++++++++++++++++++++++--------- WWCharacter.c | 158 ++++++++++++++--- WWCharacter.h | 48 +++++- WWCharacterP.h | 6 +- WWColorMap.c | 2 +- WWPalette.c | 20 ++- WWSprite.c | 18 +- WWText.c | 28 ++- Wonx2WonX.pl | 17 -- XDisplay.c | 54 +++--- challsrc.sh | 4 + comm.c | 12 +- disp.c | 35 ++-- etc.c | 14 ++ etc.h | 6 + filters.pl | 16 ++ int2sint.pl | 19 ++ libwwc.c | 22 ++- readline.pl | 16 -- sout2str.pl | 15 +- sys2wonx.pl | 16 +- wonx_include/disp.h | 4 +- wonx_include/fcntl.h | 32 ++++ wonx_include/fcntl_attention.h | 16 -- wonx_include/libwwc.h | 6 +- wonx_include/types.h | 8 +- 28 files changed, 698 insertions(+), 276 deletions(-) delete mode 100644 Wonx2WonX.pl create mode 100644 challsrc.sh create mode 100644 filters.pl create mode 100644 int2sint.pl delete mode 100644 readline.pl create mode 100644 wonx_include/fcntl.h delete mode 100644 wonx_include/fcntl_attention.h diff --git a/HISTORY b/HISTORY index b4517b4..1637fc7 100644 --- a/HISTORY +++ b/HISTORY @@ -1,5 +1,62 @@ +2001/1/13(土) + +wonx-2.1 公開 + +パレットデータのダンプ時に,RGB値もダンプするようにした. +データのダンプ部分を一部修正. + +perl スクリプトの行頭を,/usr/bin/perl から /usr/local/bin/perl に変更. +(FreeBSD では,日本語 perl は /usr/local/bin に入るので) + +disp.c, libwwc.c の,キャラクタのビットマップデータ読み込み用・取得用関数で, +ビットマップデータの型を unsigned char * でなく short int *, long int * などの +適切な型に修正した. +WWCharacter クラスのビットマップを,uchar, ushort, ulong の union とし, +WWCharacter_GetPixel() では適切な型でアクセスすることにより, +ビットマップデータのエンディアンの依存性を無くした.(i386, SPARC で確認済) + +WWCharacter_GetPixel() の 16PACKED カラーモード時の値の取得方法を修正した. +(キャラクタが左右反転表示されていたバグが解消した) + +F11 で10秒間停止,もしくは Ctrl-c もしくは F12 で強制終了, +Ctrl-i でアイコン化の追加.(もともとあった機能だったが,忘れてたのを, +多少修正して正式サポートにした) + +表示/非表示の切替えキーを p から F10 に移動.マニュアル修正. + +XDisplay.c:XDisplay_DrawLCDWindow() で,XColorGC_CreateFromRGB() で生成した +XColorGC オブジェクトを Destroy() していないので,メモリフローしていたバグを +修正.(XColorGC_Destroy(x_color_gc) 追加) + +wonx_include/fcntl.h 追加.内容は,/usr/include/fcntl.h, +/usr/include/sys/fcntl.h をインクルードするだけ. + +シリアル出力時のメッセージ(output to serial port : )の書式変更. +("" でくくるようにした) +etc.c:wonx_print_character() 修正.(\", \\ などを追加) +sout2str.pl 修正.(\", \\ などを追加.上記のシリアル出力時のメッセージの +書式変更にあわせて修正した) + +int2sint.pl, filters.pl, challsrc.sh 追加. +sys2wonx.pl 変更. + +wonx_include/types.h の +typedef unsigned short WORD; +typedef unsigned long DWORD; +を +typedef unsigned short int WORD; +typedef unsigned long int DWORD; +に変更. + +README 修正. + + + + 2001/1/3(水) +wonx-2.0 公開 + カラー化対応.GCの管理用に,XColorGC クラスを追加.(XFireworks から流用した) カラー化に対応させて,transparent(透過色)の判定処理を WWPalette クラスから diff --git a/Makefile b/Makefile index 766ec54..1a0c0f1 100644 --- a/Makefile +++ b/Makefile @@ -2,8 +2,8 @@ XINCLUDEDIR = /usr/X11R6/include INCLUDEDIR = . XLIBDIR = /usr/X11R6/lib -VERSION = WonX-2.0 -PKGNAME = wonx-2.0 +VERSION = WonX-2.1 +PKGNAME = wonx-2.1 SMAC = smac-b02 WWTERM = wwterm-b05 @@ -41,9 +41,10 @@ smac : libwonx.a cp libwonx.a $(SMAC) mv $(SMAC)/makefile $(SMAC)/makefile.orig cp makefile_for_smac $(SMAC)/makefile - cp sys2wonx.pl $(SMAC) - echo "ここで止まったときは,sys2wonx.pl の1行目に適切なperlを指定してください" - cd $(SMAC) ; ./sys2wonx.pl *.[ch] + cp challsrc.sh filters.pl sys2wonx.pl int2sint.pl $(SMAC) + # ここで止まったときは,filters.pl, sys2wonx.pl, int2sint.pl の + # 1行目に適切なperlを指定してください" + cd $(SMAC) ; ./challsrc.sh *.[ch] makefile cd $(SMAC) ; $(MAKE) wwterm : libwonx.a @@ -52,9 +53,10 @@ wwterm : libwonx.a 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] + cp challsrc.sh filters.pl sys2wonx.pl int2sint.pl $(WWTERM) + # ここで止まったときは,filters.pl, sys2wonx.pl, int2sint.pl の + # 1行目に適切なperlを指定してください" + cd $(WWTERM) ; ./challsrc.sh *.[ch] makefile cd $(WWTERM) ; $(MAKE) package : @@ -62,7 +64,7 @@ package : rm -fR $(PKGNAME)/* mkdir -p $(PKGNAME)/wonx_include cp COPYING COPYRIGHT HISTORY README MANUAL OMAKE.jpn Makefile \ - makefile_for_smac makefile_for_wwterm *.pl \ + makefile_for_smac makefile_for_wwterm *.sh *.pl \ *.h *.c $(SMAC).zip $(WWTERM).zip $(PKGNAME) cp wonx_include/*.h $(PKGNAME)/wonx_include tar cvzf $(PKGNAME).tar.gz $(PKGNAME) diff --git a/README b/README index dbf91a2..c02851f 100644 --- a/README +++ b/README @@ -2,29 +2,18 @@ WonX - WonderWitch on X. ■ 配布に当たって -WonX はまだ不完全です.実装されていない機能や,不完全な機能,おかしな -動作をする部分などがいっぱいあります. +ご意見,ご要望など歓迎します.どしどしお寄せください. バグ情報やアドバイスがあれば,作者の坂井弘亮まで,どんどんメールください. アドレスは, sakai@seki.ee.kagu.sut.ac.jp hsakai@pfu.co.jp です. +(ただし,返事を書くとは限らないし,要望を反映するとも限りませんので + その点はご容赦ください) また,坂井の気が向く限り,アップデートは随時行っていきます. http://www.seki.ee.kagu.sut.ac.jp/~sakai/WonderWitch/index.html で,随時公開していきます. -現在は坂井が一人で製作していますが,ひとりでは細かい点の整合性 -(初期化しなかった場合の動作の違いなど.WonderWitch と WonX では - 微妙に異なっている)を追いきれないのが現状です. -とくにマニュアルに書いてない部分に関しては,WonderWitch ではどのように -動作するのか,ひとりではチェックしきれません.(ていうか面倒) -情報をお待ち(ていうか期待)しています. -いっしょに少しずつ,完全なものに仕上げていきましょう. - -ご意見,ご要望なども歓迎します.どしどしお寄せください. -(ただし,返事を書くとは限らないし,要望を反映するとも限りませんので - その点はご容赦ください) - ■ はじめに WonX は,WonderWitch 用のプログラムを X アプリケーションとしてコンパイルする @@ -51,6 +40,33 @@ WonX 従って,WonderWitch での動作を模倣することよりも,デバッグ情報を 出力することや改造のしやすさを優先したような実装をする場合がある. +■ 必要なもの + +WonX では,以下のものを使用しています. + +・perl + (WonderWitch用ソースコード → WonX用ソースコードの変換用 perl スクリプトを + 添付しているので,WonderWitch用ソースコードの中に漢字が入っているのならば, + 日本語 perl が望ましい) + 添付の perl スクリプトは,すべて #!/usr/local/bin/perl になっているので, + 日本語 perl が別のところにあるばあいには,修正してから使用してください. + 日本語 perl が無ければ,まあ,ふつうの perl でもたぶん大丈夫でしょう. +・qkc + 漢字コード変換,改行コード変換に必要. + (nkf でもべつにいいんだけど,qkc だと改行コードも変換してくれるので, + この文書では qkc を使用しています) + qkc は,以下のサイトから入手できます. + http://hp.vector.co.jp/authors/VA000501/index.html + qkc には,MS-DOS 版,Windows 版,UNIX 版などがありますので, + UNIX 版(qkcc100.zip)を入手してください. + コンパイルは,make するだけなのでとっても簡単です. +・unzip + 添付の smac-b02.zip, wwterm-b05.zip を解凍するのに必要. + +このマニュアルは,以上のものがすべてインストールされていることを前提として +説明を進めます.必要ならばインストールするか,他のアプリケーションで +代用してください. + ■ 3分WonX とりあえず,どんなものか見てみたいことでしょう.そんな人は, @@ -88,16 +104,16 @@ WonX ~/wonx/smac>% ./smac ウインドウが開いて,標準出力にメッセージが出力されます. -いったん p を押して画面描画を OFF にします.しばらくしたら -(メッセージの内容が変わったら) p を押して再び画面表示を ON にすると, +いったん F10 を押して画面描画を OFF にします.しばらくしたら +(メッセージの内容が変わったら) F10 を押して再び画面表示を ON にすると, smac のタイトル画面が表示されます. -ここでスペースを押して,さらにまた p で画面表示を OFF にして, -しばらくしたら(メッセージの内容が変わったら) p で画面表示を ON にします. +ここでスペースを押して,さらにまた F10 で画面表示を OFF にして, +しばらくしたら(メッセージの内容が変わったら) F10 で画面表示を ON にします. どうですか? SpeedMac のゲーム画面が表示されているでしょうか? カーソルキーで移動,スペースキーで射撃です. ただし,キー入力はキー入力用関数が呼ばれたときしか有効ではないので, キーは反応するまで長めに押してください. -p を押して頻繁に描画の ON, OFF を切替えるのは,描画が非常に遅いため, +F10 を押して頻繁に描画の ON, OFF を切替えるのは,描画が非常に遅いため, ONのままだと画面クリアとかに異常に時間がかかるからです. 最後に,WonderWitch 用の端末エミュレータ "WWTerm" をコンパイル・実行 @@ -106,7 +122,7 @@ ON ~/wonx>% make wwterm (中略) ~/wonx>% cd wwterm -~/wonx/smac>% ./terminal +~/wonx/wwterm>% ./terminal ■ 10分WonX @@ -125,29 +141,40 @@ ON libwonx.a ~/wonx>% -次に,libwonx.a と,wonx_include ディレクトリと,sys2wonx.pl を -あなたの作ったプログラムのディレクトリ(ここでは例として,yoursample とします) -にコピーします. +次に,libwonx.a と,wonx_include ディレクトリと, +challsrc.sh, filters.pl, sys2wonx.pl, int2sint.pl をあなたの作ったプログラムの +ディレクトリ(ここでは例として,yoursample とします)にコピーします. -~/wonx>% cp -R libwonx.a wonx_include sys2wonx.pl ../yoursample +~/wonx>% cp -R libwonx.a wonx_include ../yoursample +~/wonx>% cp challsrc.sh filters.pl sys2wonx.pl int2sint.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 +あなたの作ったプログラムのすべてのファイルに対して,以下のことを行います. +・MS-DOS テキスト形式から UNIX のテキスト形式に変換する. + (つまり,改行コードを \r\n から \n に変換して,漢字コードを SJIS から + EUC に変換します) +・プログラム中の #include のようなのを, + #include "wonx_include/disp.h" に変更する.(sys2wonx.pl を通す) +・デフォルトの int を,short int に変換する.(int2sint.pl を通す) +これらのフィルタをまとめて通してくれる filters.pl というスクリプトを +添付してあるので,以下のようにして,すべてのソースファイルに対して, +必要なフィルタを通してください. + +~/yoursample>% ./filters.pl "qkc -e -u" ./sys2wonx.pl ./int2sint.pl -f *.[ch] [Mm]akefile* MAKEFILE* + +もしくは,以下のようにしてもよいです. + +~/yoursample>% ./challsrc.sh *.[ch] [Mm]akefile* MAKEFILE* + +(注意! filters.pl や challsrc.sh は,ファイルの本体を書き換えてしまうので, + 変更されると困るようなファイルは必ずバックアップしてください) + makefile を以下のように修正する. ・コンパイラには gcc を使用する. ・オブジェクトファイルを *.obj から *.o に変更. @@ -161,16 +188,6 @@ makefile 添付の makefile_for_smac や makefile_for_wwterm を参考にして,makefile を 修正してください. -次に,sys2wonx.pl をかけて,プログラム中の #include のようなのを, -#include "wonx_include/disp.h" に変更する. -(注意! sys2wonx.pl は,ファイルの本体を書き換えてしまうので,変更されると - 困るようなファイルは必ずバックアップしてください. - #include のような部分が無いファイルの場合だと,読み込んで - そのまま出力するので,ファイルの内容自体は変わらないと思いますが, - 日付は変わってしまいます) - -~/yoursample>% ./sys2wonx.pl *.[ch] - 最後に,make をします. ~/yoursample>% make @@ -218,8 +235,9 @@ WonderWitch (ただし,コンフリクトしないという絶対の自信があるなら,この限りではありません) WonderWitch のプログラムの,#include は,すべて #include に修正する必要がある,ということです. -(これをまとめて行うための perl スクリプトを添付してあります. - sys2wonx.pl *.[ch] を実行すると,ごっそりと書き換えてくれます) +(これをまとめて行うための sys2wonx.pl という perl スクリプトを添付して + あります../filters.pl ./sys2wonx.pl -f *.[ch] を実行すると,ごっそりと + 書き換えてくれます) また,UNIXシステムによっては,/usr/include/sys/types.h で ushort, ulong を 定義しているものといないものがあります.よって,コンパイル中に @@ -276,12 +294,61 @@ SpeedMac ~/wonx/smac-b02>% cp ../libwonx.a . ~/wonx/smac-b02>% -3. makefile を修正する. +3. ソースを修正する. + +~/wonx/smac-b02>% emacs chara.c +~/wonx/smac-b02>% emacs dsp.c +... (ファイルをひとつひとつ修正する) + +MS-DOS のファイル形式になっているファイルは,UNIXのテキスト形式に +変換します.具体的には,以下の変換をします. +・改行コードを \r\n から \n にする. +・漢字コードを SJIS から EUC にする. +qkc というアプリケーションで,上記のことを一度に行うことができます. +面倒なかたは,以下のようにすれば,まとめて変換されます. +~/wonx/smac-b02>% ./filters.pl "qkc -e -u" -f *.[ch] +qkc が無い人は... nkf とかてきとうに使って変換してください. + +また,ソース中の, +#include +#include +のような部分を, +#include "wonx_include/disp.h" +#include "wonx_include/key.h" +のように修正します. + +これをまとめてやるための perl スクリプト (sys2wonx.pl) を添付してあるので, +面倒なかたは, +~/wonx/smac-b02>% cp ../filters.pl ../sys2wonx.pl . +~/wonx/smac-b02>% ./filters.pl ./sys2wonx.pl -f *.[ch] +のようにしてください. +(filters.pl は,引数で指定したファイル自体を書き換えてしまうので注意) + +さらに,WonderWitch では sizeof(int) == sizeof(short int) ですが, +UNIX ではふつうは sizeof(int) == sizeof(long int) なので, +キャラクタのビットマップなど,int 型のバイトサイズに依存する部分で +int を使用している場合には,short int などと明示します. + +これをまとめてやるための perl スクリプト (int2sint.pl) を添付してあるので, +面倒なかたは, +~/wonx/smac-b02>% cp ../int2sint.pl . +~/wonx/smac-b02>% ./filters.pl ./int2sint.pl -f *.[ch] +のようにしてください. +(filters.pl は,引数で指定したファイル自体を書き換えてしまうので注意) + +日本語 perl は EUC コードでないと正常に動作しないので, +sys2wonx.pl や int2sint.pl を使用する場合には,まず先に qkc で漢字コードを +EUC に変換してから,sys2wonx.pl や int2sint.pl を使用してください. + +4. makefile を修正する. ~/wonx/smac-b02>% emacs makefile 以下のように修正します. +・漢字コードを EUC に,改行コードを \r\n から \n に変換する. + (改行コードを変換しないと make が正常に動作しません.qkc を通すと + いいでしょう) ・gcc でコンパイルをするように修正する.このときに,コンパイルオプションに, -I. -L. -L/usr/X11R6/lib -lwonx -lX11 -lXt を追加する. @@ -295,27 +362,6 @@ SpeedMac のようにしてコピーしてください. -4. ソースを修正する. - -~/wonx/smac-b02>% emacs chara.c -~/wonx/smac-b02>% emacs dsp.c -... (ファイルをひとつひとつ修正する) - -ソース中の, -#include -#include -のような部分を, -#include "wonx_include/disp.h" -#include "wonx_include/key.h" -のように修正します. - -これをまとめてやるための perl スクリプト (sys2wonx.pl) を添付してあるので, -面倒なかたは, -~/wonx/smac-b02>% cp ../sys2wonx.pl . -~/wonx/smac-b02>% ./sys2wonx.pl *.[ch] -のようにしてください. -(sys2wonx.pl は,引数で指定したファイル自体を書き換えてしまうので注意) - 5. make する. ~/wonx/smac-b02>% make @@ -351,12 +397,16 @@ smac ・i,j,k,l キーが,WonderSwan のY1〜Y4ボタンに対応している. ・スペースバーと左シフトキーが,A,Bボタンに対応している. ・sキーが,STARTボタンに対応している. -・p を押すと,表示/非表示モードを切替える. - (非表示だと画面への描画を行わないが高速) ・F1 を押すと,LCDカラーマップのデータをダンプ出力する. ・F2 を押すと,パレットのデータをダンプ出力する. ・F3 を押すと,キャラクターのデータをダンプ出力する. ・F4 を押すと,スプライトのデータをダンプ出力する. +・F10 を押すと,表示/非表示モードを切替える. + (非表示だと画面への描画を行わないが高速) +・F11 で10秒間停止.(画面写真をとるときなどに利用できる) + (F11は短めに押してください.長めに押すと,復帰しなくなるようです) +・q もしくは Ctrl-c もしくは F12 で強制終了. +・Ctrl-i でアイコン化. デフォルトではなにか関数が呼ばれるたびに画面の再描画を行うため, 非常に低速です. @@ -369,8 +419,8 @@ for (y = 0; y < 32; y++) } } -このような場合は,p を押して非表示モードにして,ループ処理が終ったら -再び p を押して表示モードに戻してください. +このような場合は,F10 を押して非表示モードにして,ループ処理が終ったら +再び F10 を押して表示モードに戻してください. F1 や F2 を押すと,データをダンプ出力するのですが,標準ではその他にも メッセージが大量に出力されているので,ふつうに F1 を押しただけでは, @@ -383,7 +433,7 @@ smac もしもキャラクタ番号10番のキャラクタのデータだけが見たい場合には, 以下のように実行してから,F3 キーを押せば良いでしょう. -> smac | grep "character\[10\]" +> smac | grep "character\[010\]" WonX は,メッセージを出力する際に,grep でフィルタリングできるように, かならず出力メッセージの先頭に,統一性のある文字列を追加しています. @@ -450,24 +500,56 @@ UNIX なりませんが,ビットマップの格納場所として使用するようなときには, 問題になります. 一番問題になりやすいのは,キャラクタのビットマップを扱う場合です. +(bmpcnv を使用して,ビットマップデータの出力が unsigned int bitmap = { + のようになっている場合など) font_set_colordata()などは,16*8 バイトのキャラクタデータを short int 型の配列として引数に持ちます.WonderWitch では sizeof(short int) == sizeof(int) なので,WonderWitch 用のプログラム上では, キャラクタデータを short int とせずに,int 型の配列として定義してしまう ことが考えられます.(当然 WonderWitch ならば問題は無いが,UNIX 上で 実行したら,キャラクタに妙な縞々が入るだろうと思われる) -このような場合には,UNIX 上でコンパイルするときには,short int に -修正する必要があります. +このような場合には,UNIX 上でコンパイルするときには,コンパイラオプションで +デフォルトの int は short int になるように指定するか,もしくはソース中の +int を short int にじかに修正する必要があります.i386 上で gcc を使用する +場合には,このようなコンパイラオプションは無いので,じかにソースを修正する +ことになります. +int2sint.pl を通すと,明示されていない int はすべて short int に変換しますが, +もしもあなたが int2sint.pl が信用できなければ,手で修正してください.ふつうは +キャラクタのビットマップデータとそれを扱う部分のみを修正すれば十分でしょう. + +コンパイル時のワーニングもちゃんと確認してください.また,コンパイル時には +-Wall オプションをつけましょう. +wonx-2.1 からは,キャラクタのビットマップ設定関連(font_set_colordata()など) +の関数の引数は,適切な型のポインタに修正したので,コンパイラがワーニングを +出していたら,ビットマップデータの型がおかしいかもしれません. + +単なるカウンタやフラグとして使用しているような int は,多くの場合は +short int でも long int でも動作は変わりませんが,たとえそうだとしても, +WonX を使用して,gcc で -Wall オプションをつけてコンパイルすると, +WonderWitch で動作させるときの潜在的なバグ(short int の上下限にまつわる +バグなど)を発見できることがあるので,なるべくなら int2sint.pl で int を +ごっそり short int にしてしまうことをおすすめします. [エンディアンの問題] WonderWitch の CPU は x86系です.SPARC などで使用する場合には, エンディアンに注意する必要があります. font_set_colordata()などは,short int 型の配列でキャラクタデータを受け取る -ので,char * で定義したキャラクタデータを short int * にキャストして +ので,unsigned char * で定義したキャラクタデータを short int * にキャストして font_set_colordata()に渡すなどのことをしていると,画像がひっくり返る ことが考えられます. i386 系のいわゆる PC-UNIX ならば,おそらく問題は無いでしょう. +WonX-2.1 から,キャラクタデータに関しては,極力エンディアンに依存しないように +修正しました.i386 と SPARC でエンディアンに依存しないことを動作確認 +しています.しかしそれでも,キャラクタデータを unsigned char * で定義して, +ビットマップ読み込み用の関数にキャラクタデータを渡すときに short int * に +キャストして渡すような書き方をしていると,依存してしまいます. + +キャラクタデータのビットマップ読み込み用の関数には,適切な型のデータを +渡すようにしてください.short int * を渡すべきところに,unsigned char * を +渡したりすると,このようなバグの原因になる可能性があります.不適切な +ポインタを渡している場合には,コンパイラがワーニングを出すので, +コンパイラのワーニングに十分に注意してください. [タイマ割り込みの問題] @@ -563,7 +645,7 @@ gcc -g -o smac $(OBJS) -lwonx -lX11 -lXt -L. -L/usr/X11R6/lib make がうまく動作しなかったり,コンパイルできてもプログラム自体が 誤動作してしまい,しかも原因に気づきにくくなってしまう可能性があります. makefile やソースコードは必ず, -> cat makefile | qkc -I -O -e -u > makefile.tmp +> cat makefile | qkc -e -u > makefile.tmp > mv makefile.tmp makefile などを通して,UNIXのテキストファイルに変換しましょう. @@ -703,6 +785,75 @@ WWSprite_PrintData(WWDisplay_GetSprite(ww_display, 0), stdout); のようにして不安なコードの前後でダンプデータを取ると,デバッグに 役立つでしょう. +■ 添付のツールについて + +[sys2wonx.pl] + +#include +を, +#include "wonx_include/disp.h" +のように変換するフィルタです. + +[int2sint.pl] + +short か long か明示されていない int を,short int に変換します. +sizeof(int) や uint* も,sizeof(short int), unsigned short int* に +変換されます. +ただ,ひょっとしたらおかしな変換をしてしまうかも... でもたぶんそのときには +コンパイル時にエラーが出るだろうから,いいか. +そうだ.perl は行単位に処理するので, +long +int a; +とか, +void func(long + int a) +のような変な書き方をしていると, +long +short int a; +とか, +void func(long + short int a) +に変換されてしまって,きっとエラーになることでしょう.気をつけてください. + +[filters.pl] + +複数のフィルタをまとめて通すための perl スクリプトです. +書式は, +filters.pl [filters...] -f [files...] +です.例えば, +> filters.pl sort head -f file1 file2 file3 +は, +> cat file1 | sort | head > file1.tmp +> mv file1.tmp file1 +> cat file2 | sort | head > file2.tmp +> mv file2.tmp file2 +> cat file3 | sort | head > file3.tmp +> mv file3.tmp file3 +をすることと等価です. + +[challsrc.sh] + +WonderWitch用ソース → wonx用ソース への変換をするためのシェルスクリプトです. +内容は,単に, +./filters.pl "qkc -e -u" ./sys2wonx.pl ./int2sint.pl -f [files] +するだけです. +日本語 perl を使用する場合には,漢字コードは EUC でないと正常に動作しないので, +"qkc -e -u" を通してから ./sys2wonx.pl と ./int2sint.pl を +通すような順番になっています. + +[sout2str.pl] + +wonx は,シリアルポートへの出力は, +output to serial port : "A" +とか, +output to serial port : "\n" +のように,標準出力に出力します.sout2str.pl は,この "" でくくられた部分 +のみを抽出して,\n や \t を適切なコードに変換して出力するフィルタです. +シリアルポートを使用するプログラム(例: wwterm)を起動するときには, +> wwterm | ./sout2str.pl +のようにして,sout2str.pl を通して起動することにより,実際のシリアルポート +への出力をモニタすることができます. + ■ 作者 WonX は,坂井弘亮がその大部分を往復3時間の通勤電車の中で Libretto で書いた, diff --git a/WWCharacter.c b/WWCharacter.c index e5860ad..8f66fde 100644 --- a/WWCharacter.c +++ b/WWCharacter.c @@ -6,11 +6,16 @@ #include "WWCharacterP.h" #include "WonX.h" +#include "etc.h" /*****************************************************************************/ /* メンバ関数の定義 */ /*****************************************************************************/ +/*===========================================================================*/ +/* ナンバーの操作 */ +/*===========================================================================*/ + int WWCharacter_GetNumber(WWCharacter c) { if (c == NULL) WonX_Error("WWCharacter_GetNumber", "WWCharacter is NULL."); @@ -28,26 +33,95 @@ int WWCharacter_SetNumber(WWCharacter c, int n) return (c->number = n); } -unsigned char WWCharacter_GetBitmap(WWCharacter c, int n) +/*===========================================================================*/ +/* ビットマップの操作 */ +/*===========================================================================*/ + +/*---------------------------------------------------------------------------*/ +/* char 型として操作するための関数 */ +/*---------------------------------------------------------------------------*/ + +unsigned char WWCharacter_GetBitmapAsChar(WWCharacter c, int n) { - if (c == NULL) WonX_Error("WWCharacter_GetBitmap", "WWCharacter is NULL."); + if (c == NULL) + WonX_Error("WWCharacter_GetBitmapAsChar", "WWCharacter is NULL."); if ((n < 0) || (n > 32 - 1)) - WonX_Error("WWCharacter_GetBitmap", "Invalid range."); + WonX_Error("WWCharacter_GetBitmapAsChar", "Invalid range."); - return (c->bitmap[n]); + return (c->bitmap.bitmap_char[n]); } -unsigned char WWCharacter_SetBitmap(WWCharacter c, int n, unsigned char bitmap) +unsigned char WWCharacter_SetBitmapAsChar(WWCharacter c, int n, + unsigned char bitmap) { - if (c == NULL) WonX_Error("WWCharacter_SetBitmap", "WWCharacter is NULL."); + if (c == NULL) + WonX_Error("WWCharacter_SetBitmapAsChar", "WWCharacter is NULL."); if ((n < 0) || (n > 32 - 1)) - WonX_Error("WWCharacter_SetBitmap", "Invalid range."); + WonX_Error("WWCharacter_SetBitmapAsChar", "Invalid range."); - return (c->bitmap[n] = bitmap); + return (c->bitmap.bitmap_char[n] = bitmap); } +/*---------------------------------------------------------------------------*/ +/* short int 型として操作するための関数 */ +/*---------------------------------------------------------------------------*/ + +unsigned short int WWCharacter_GetBitmapAsShortInt(WWCharacter c, int n) +{ + if (c == NULL) + WonX_Error("WWCharacter_GetBitmapAsShortInt", "WWCharacter is NULL."); + + if ((n < 0) || (n > 16 - 1)) + WonX_Error("WWCharacter_GetBitmapAsShortInt", "Invalid range."); + + return (c->bitmap.bitmap_short_int[n]); +} + +unsigned short int WWCharacter_SetBitmapAsShortInt(WWCharacter c, int n, + unsigned short int bitmap) +{ + if (c == NULL) + WonX_Error("WWCharacter_SetBitmapAsShortInt", "WWCharacter is NULL."); + + if ((n < 0) || (n > 16 - 1)) + WonX_Error("WWCharacter_SetBitmapAsShortInt", "Invalid range."); + + return (c->bitmap.bitmap_short_int[n] = bitmap); +} + +/*---------------------------------------------------------------------------*/ +/* long int 型として操作するための関数 */ +/*---------------------------------------------------------------------------*/ + +unsigned long int WWCharacter_GetBitmapAsLongInt(WWCharacter c, int n) +{ + if (c == NULL) + WonX_Error("WWCharacter_GetBitmapAsLongInt", "WWCharacter is NULL."); + + if ((n < 0) || (n > 8 - 1)) + WonX_Error("WWCharacter_GetBitmapAsLongInt", "Invalid range."); + + return (c->bitmap.bitmap_long_int[n]); +} + +unsigned long int WWCharacter_SetBitmapAsLongInt(WWCharacter c, int n, + unsigned long int bitmap) +{ + if (c == NULL) + WonX_Error("WWCharacter_SetBitmapAsLongInt", "WWCharacter is NULL."); + + if ((n < 0) || (n > 8 - 1)) + WonX_Error("WWCharacter_SetBitmapAsLongInt", "Invalid range."); + + return (c->bitmap.bitmap_long_int[n] = bitmap); +} + +/*===========================================================================*/ +/* オブジェクトの生成と削除 */ +/*===========================================================================*/ + WWCharacter WWCharacter_Create(int number) { WWCharacter character; @@ -70,10 +144,16 @@ WWCharacter WWCharacter_Destroy(WWCharacter character) return (NULL); } +/*===========================================================================*/ +/* ピクセルの操作 */ +/*===========================================================================*/ + int WWCharacter_GetPixel(WWCharacter character, int x, int y, WWDisplay display) { unsigned short int pixel; + unsigned short int spixel; + unsigned long int lpixel; if (character == NULL) WonX_Error("WWCharacter_GetPixel", "WWCharacter is NULL."); @@ -88,18 +168,38 @@ int WWCharacter_GetPixel(WWCharacter character, int x, int y, switch (WWDisplay_GetColorMode(display)) { case COLOR_MODE_GRAYSCALE: case COLOR_MODE_4COLOR: - pixel = ((character->bitmap[y * 2 + 0] >> (7-x)) & 1) << 0; - pixel |= ((character->bitmap[y * 2 + 1] >> (7-x)) & 1) << 1; + spixel = (character->bitmap.bitmap_short_int[y] >> (7-x)) & 0x0101; + pixel = + ((spixel & 0x0001) ? 1 : 0) | + ((spixel & 0x0100) ? 2 : 0); +#if 0 + pixel = ((character->bitmap.bitmap_char[y * 2 + 0] >> (7-x)) & 1) << 0; + pixel |= ((character->bitmap.bitmap_char[y * 2 + 1] >> (7-x)) & 1) << 1; +#endif break; case COLOR_MODE_16COLOR: + lpixel = (character->bitmap.bitmap_long_int[y] >> (7-x)) & 0x01010101; + pixel = + ((lpixel & 0x00000001) ? 1 : 0) | + ((lpixel & 0x00000100) ? 2 : 0) | + ((lpixel & 0x00010000) ? 4 : 0) | + ((lpixel & 0x01000000) ? 8 : 0); +#if 0 pixel = ((character->bitmap[y * 4 + 0] >> (7-x)) & 1) << 0; pixel |= ((character->bitmap[y * 4 + 1] >> (7-x)) & 1) << 1; pixel |= ((character->bitmap[y * 4 + 2] >> (7-x)) & 1) << 2; pixel |= ((character->bitmap[y * 4 + 3] >> (7-x)) & 1) << 3; +#endif break; case COLOR_MODE_16PACKED: - pixel = character->bitmap[y * 4 + (7-x) / 2] >> (((7-x) % 2) * 4); + lpixel = character->bitmap.bitmap_long_int[y]; + lpixel = lpixel >> (3 - (7-x) / 2) * 8; + lpixel = lpixel >> ((7-x) % 2) * 4; + pixel = lpixel & 0x0f; +#if 0 + pixel = character->bitmap[y * 4 + 3 - (7-x) / 2] >> (((7-x) % 2) * 4); pixel &= 0x0f; +#endif break; default: WonX_Error("WWCharacter_GetPixel", "Unknown color mode."); @@ -113,7 +213,7 @@ int WWCharacter_ClearAllPixels(WWCharacter character) if (character == NULL) WonX_Error("WWCharacter_ClearAllPixels", "WWCharacter is NULL."); - memset(character->bitmap, 0, 32); + memset(character->bitmap.bitmap_char, 0, 32); return (0); } @@ -125,14 +225,19 @@ int WWCharacter_CopyAllPixels(WWCharacter dst, WWCharacter src) if (src == NULL) WonX_Error("WWCharacter_CopyAllPixel", "src is NULL."); - memcpy(dst->bitmap, src->bitmap, 32); + memcpy(dst->bitmap.bitmap_char, src->bitmap.bitmap_char, 32); return (0); } +/*===========================================================================*/ +/* 内部データ出力 */ +/*===========================================================================*/ + int WWCharacter_PrintData(WWCharacter character, WWDisplay display, FILE * f) { int i, x, y, n; + int pixel; if (character == NULL) WonX_Error("WWCharacter_PrintData", "WWCharacter is NULL."); @@ -141,27 +246,28 @@ int WWCharacter_PrintData(WWCharacter character, WWDisplay display, FILE * f) fprintf(f, "\n"); - fprintf(f, "character[%d] :\tnumber = %d\n", + fprintf(f, "character[%03d] :\tnumber = %d\n", n, WWCharacter_GetNumber(character)); for (i = 0; i < 32; i += 8) { - fprintf(f, "character[%d] :\tbitmap[%d] =", n, i); - fprintf(f, " %02x", (int)WWCharacter_GetBitmap(character, i )); - fprintf(f, " %02x", (int)WWCharacter_GetBitmap(character, i+1)); - fprintf(f, " %02x", (int)WWCharacter_GetBitmap(character, i+2)); - fprintf(f, " %02x", (int)WWCharacter_GetBitmap(character, i+3)); - fprintf(f, " %02x", (int)WWCharacter_GetBitmap(character, i+4)); - fprintf(f, " %02x", (int)WWCharacter_GetBitmap(character, i+5)); - fprintf(f, " %02x", (int)WWCharacter_GetBitmap(character, i+6)); - fprintf(f, " %02x", (int)WWCharacter_GetBitmap(character, i+7)); + fprintf(f, "character[%03d] :\tbitmap[%02d] =", n, i); + fprintf(f, " %02x", (int)WWCharacter_GetBitmapAsChar(character, i )); + fprintf(f, " %02x", (int)WWCharacter_GetBitmapAsChar(character, i+1)); + fprintf(f, " %02x", (int)WWCharacter_GetBitmapAsChar(character, i+2)); + fprintf(f, " %02x", (int)WWCharacter_GetBitmapAsChar(character, i+3)); + fprintf(f, " %02x", (int)WWCharacter_GetBitmapAsChar(character, i+4)); + fprintf(f, " %02x", (int)WWCharacter_GetBitmapAsChar(character, i+5)); + fprintf(f, " %02x", (int)WWCharacter_GetBitmapAsChar(character, i+6)); + fprintf(f, " %02x", (int)WWCharacter_GetBitmapAsChar(character, i+7)); fprintf(f, "\n"); } - fprintf(f, "character[%d] :\tpixels : 01234567\n", n); + fprintf(f, "character[%03d] :\tpixels : 01234567\n", n); for (y = 0; y < 8; y++) { - fprintf(f, "character[%d] :\tpixels : %d ", n, y); + fprintf(f, "character[%03d] :\tpixels : %01d ", n, y); for (x = 0; x < 8; x++) { - fprintf(f, "%d", WWCharacter_GetPixel(character, x, y, display)); + pixel = WWCharacter_GetPixel(character, x, y, display); + fprintf(f, "%c", wonx_dec_to_hex(pixel)); } fprintf(f, "\n"); } diff --git a/WWCharacter.h b/WWCharacter.h index 3178393..757dede 100644 --- a/WWCharacter.h +++ b/WWCharacter.h @@ -25,19 +25,61 @@ typedef struct _WWCharacter * WWCharacter; /* メンバ関数の宣言 */ /*****************************************************************************/ +/*===========================================================================*/ +/* ナンバーの操作 */ +/*===========================================================================*/ + int WWCharacter_GetNumber(WWCharacter c); int WWCharacter_SetNumber(WWCharacter c, int n); -unsigned char WWCharacter_GetBitmap(WWCharacter c, int n); -unsigned char WWCharacter_SetBitmap(WWCharacter c, int n, unsigned char bitmap); + +/*===========================================================================*/ +/* ビットマップの操作 */ +/*===========================================================================*/ + +/*---------------------------------------------------------------------------*/ +/* char 型として操作するための関数 */ +/*---------------------------------------------------------------------------*/ + +unsigned char WWCharacter_GetBitmapAsChar(WWCharacter c, int n); +unsigned char WWCharacter_SetBitmapAsChar(WWCharacter c, int n, + unsigned char bitmap); + +/*---------------------------------------------------------------------------*/ +/* short int 型として操作するための関数 */ +/*---------------------------------------------------------------------------*/ + +unsigned short int WWCharacter_GetBitmapAsShortInt(WWCharacter c, int n); +unsigned short int WWCharacter_SetBitmapAsShortInt(WWCharacter c, int n, + unsigned short int bitmap); + +/*---------------------------------------------------------------------------*/ +/* long int 型として操作するための関数 */ +/*---------------------------------------------------------------------------*/ + +unsigned long int WWCharacter_GetBitmapAsLongInt(WWCharacter c, int n); +unsigned long int WWCharacter_SetBitmapAsLongInt(WWCharacter c, int n, + unsigned long int bitmap); + +/*===========================================================================*/ +/* オブジェクトの生成と削除 */ +/*===========================================================================*/ WWCharacter WWCharacter_Create(int number); WWCharacter WWCharacter_Destroy(WWCharacter character); +/*===========================================================================*/ +/* ピクセルの操作 */ +/*===========================================================================*/ + int WWCharacter_GetPixel(WWCharacter character, int x, int y, WWDisplay display); - int WWCharacter_ClearAllPixels(WWCharacter character); int WWCharacter_CopyAllPixels(WWCharacter dst, WWCharacter src); + +/*===========================================================================*/ +/* 内部データ出力 */ +/*===========================================================================*/ + int WWCharacter_PrintData(WWCharacter character, WWDisplay display, FILE * f); /*****************************************************************************/ diff --git a/WWCharacterP.h b/WWCharacterP.h index 6b317d1..3691180 100644 --- a/WWCharacterP.h +++ b/WWCharacterP.h @@ -15,7 +15,11 @@ typedef struct _WWCharacter { int number; /* キャラクタのビットマップ */ - unsigned char bitmap[32]; + union { + unsigned char bitmap_char[32]; + unsigned short int bitmap_short_int[16]; + unsigned long int bitmap_long_int[8]; + } bitmap; } _WWCharacter; /*****************************************************************************/ diff --git a/WWColorMap.c b/WWColorMap.c index 4d206ec..ad26684 100644 --- a/WWColorMap.c +++ b/WWColorMap.c @@ -72,7 +72,7 @@ int WWColorMap_PrintData(WWColorMap c, FILE * f) fprintf(f, "\n"); for (i = 0; i < 8; i++) { - fprintf(f, "colormap :\tcolor[%d] = %d\n", + fprintf(f, "colormap :\tcolor[%01d] = %d\n", i, WWColorMap_GetLCDColor(c, i)); } diff --git a/WWPalette.c b/WWPalette.c index 9aa0386..5b28b33 100644 --- a/WWPalette.c +++ b/WWPalette.c @@ -137,12 +137,13 @@ int WWPalette_PrintData(WWPalette p, WWDisplay display, FILE * f) { int i, n; int transparent; + int red, green, blue; n = WWPalette_GetNumber(p); fprintf(f, "\n"); - fprintf(f, "palette[%d] :\tnumber = %d\n", n, WWPalette_GetNumber(p)); + fprintf(f, "palette[%02d] :\tnumber = %d\n", n, WWPalette_GetNumber(p)); /* * WonX-2.0 以降から,透明色の判定は WWDisplay で行うように変更したので, @@ -150,18 +151,29 @@ int WWPalette_PrintData(WWPalette p, WWDisplay display, FILE * f) */ #if 1 transparent = WWDisplay_IsTransparent(display, p, 0); - fprintf(f, "palette[%d] :\ttransparent = %s\n", + fprintf(f, "palette[%02d] :\ttransparent = %s\n", n, wonx_true_false(transparent)); #else - fprintf(f, "palette[%d] :\ttransparent = %s\n", + fprintf(f, "palette[%02d] :\ttransparent = %s\n", n, wonx_true_false(WWPalette_GetTransparent(p))); #endif for (i = 0; i < 4; i++) { - fprintf(f, "palette[%d] :\tcolor[%d] = %d\n", + fprintf(f, "palette[%02d] :\tcolor[%01d] = %d\n", n, i, WWPalette_GetMappedColor(p, i)); } + for (i = 0; i < 16; i++) { + red = WWPalette_GetRed( p, i); + green = WWPalette_GetGreen(p, i); + blue = WWPalette_GetBlue( p, i); + fprintf(f, "palette[%02d] :\tRGB[%02d] = 0x%c%c%c\n", + n, i, + wonx_dec_to_hex(red), + wonx_dec_to_hex(green), + wonx_dec_to_hex(blue)); + } + fflush(f); return (0); diff --git a/WWSprite.c b/WWSprite.c index 63e982f..c4417c9 100644 --- a/WWSprite.c +++ b/WWSprite.c @@ -120,21 +120,21 @@ int WWSprite_PrintData(WWSprite s, FILE * f) fprintf(f, "\n"); - fprintf(f, "sprite[%d] :\tnumber = %d\n", n, WWSprite_GetNumber(s)); - fprintf(f, "sprite[%d] :\thorizontal = %s\n", + fprintf(f, "sprite[%03d] :\tnumber = %d\n", n, WWSprite_GetNumber(s)); + fprintf(f, "sprite[%03d] :\thorizontal = %s\n", n, wonx_true_false(WWSprite_GetHorizontal(s))); - fprintf(f, "sprite[%d] :\tvertical = %s\n", + fprintf(f, "sprite[%03d] :\tvertical = %s\n", n, wonx_true_false(WWSprite_GetVertical( s))); - fprintf(f, "sprite[%d] :\tpriority = %s\n", + fprintf(f, "sprite[%03d] :\tpriority = %s\n", n, wonx_true_false(WWSprite_GetPriority( s))); - fprintf(f, "sprite[%d] :\tclipping = %s\n", + fprintf(f, "sprite[%03d] :\tclipping = %s\n", n, wonx_true_false(WWSprite_GetClipping( s))); - fprintf(f, "sprite[%d] :\tpalette number = %d\n", + fprintf(f, "sprite[%03d] :\tpalette number = %d\n", n, WWPalette_GetNumber(WWSprite_GetPalette(s))); - fprintf(f, "sprite[%d] :\tcharacter number = %d\n", + fprintf(f, "sprite[%03d] :\tcharacter number = %d\n", n, WWCharacter_GetNumber(WWSprite_GetCharacter(s))); - fprintf(f, "sprite[%d] :\tx = %d\n", n, WWSprite_GetX(s)); - fprintf(f, "sprite[%d] :\ty = %d\n", n, WWSprite_GetY(s)); + fprintf(f, "sprite[%03d] :\tx = %d\n", n, WWSprite_GetX(s)); + fprintf(f, "sprite[%03d] :\ty = %d\n", n, WWSprite_GetY(s)); fflush(f); diff --git a/WWText.c b/WWText.c index 04cc157..8cc2276 100644 --- a/WWText.c +++ b/WWText.c @@ -73,9 +73,9 @@ int WWText_PutCharacter(WWText ww_text, int x, int y, int character, { WWCharacter ww_character; int j, k, n; - unsigned char pixel; int f, b; - unsigned char bitmap[2]; + unsigned short int pixel; + unsigned short int bitmap; if ((character < 0) || (character > 127)) { WonX_Warning("WWText_PutCharacter", "Character number is out of range."); @@ -122,15 +122,13 @@ int WWText_PutCharacter(WWText ww_text, int x, int y, int character, n = character * 8; for (j = 0; j < 8; j++) { - bitmap[0] = 0; - bitmap[1] = 0; + bitmap = 0; for (k = 0; k < 8; k++) { pixel = (fonts[n] & (1 << k)) ? f : b; - bitmap[0] |= ( pixel & 1) << k; - bitmap[1] |= ((pixel >> 1) & 1) << k; + bitmap |= ( pixel & 1) << k; + bitmap |= ((pixel >> 1) & 1) << (k + 8); } - WWCharacter_SetBitmap(ww_character, j*2 , bitmap[0]); - WWCharacter_SetBitmap(ww_character, j*2+1, bitmap[1]); + WWCharacter_SetBitmapAsShortInt(ww_character, j, bitmap); n++; } #endif @@ -155,9 +153,9 @@ WWText WWText_Create(WWScreen screen, WWText ww_text; WWCharacter ww_character; int i, j, k, n; - unsigned char pixel; int f, b; - unsigned char bitmap[2]; + unsigned short int pixel; + unsigned short int bitmap; ww_text = (WWText)malloc(sizeof(_WWText)); if (ww_text == NULL) WonX_Error("WWText_Create", "Cannot allocate memory."); @@ -181,15 +179,13 @@ WWText WWText_Create(WWScreen screen, for (i = 0; i < 128; i++) { ww_character = WWCharacter_Create(i); for (j = 0; j < 8; j++) { - bitmap[0] = 0; - bitmap[1] = 0; + bitmap = 0; for (k = 0; k < 8; k++) { pixel = (fonts[n] & (1 << k)) ? f : b; - bitmap[0] |= ( pixel & 1) << k; - bitmap[1] |= ((pixel >> 1) & 1) << k; + bitmap |= ( pixel & 1) << k; + bitmap |= ((pixel >> 1) & 1) << (k + 8); } - WWCharacter_SetBitmap(ww_character, j*2 , bitmap[0]); - WWCharacter_SetBitmap(ww_character, j*2+1, bitmap[1]); + WWCharacter_SetBitmapAsShortInt(ww_character, j, bitmap); n++; } WWText_SetFont(ww_text, i, ww_character); diff --git a/Wonx2WonX.pl b/Wonx2WonX.pl deleted file mode 100644 index 053f9cd..0000000 --- a/Wonx2WonX.pl +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/perl - -while ($filename = shift(@ARGV)) { - open(RFILE, "< $filename"); - open(WFILE, "> $filename.tmp"); - while () { - if (/Wonx/) { - print $_; - s/Wonx/WonX/g; - print $_; - } - print WFILE $_; - } - close(RFILE); - close(WFILE); - system("mv $filename.tmp $filename"); -} diff --git a/XDisplay.c b/XDisplay.c index 439018d..fb8a841 100644 --- a/XDisplay.c +++ b/XDisplay.c @@ -74,16 +74,16 @@ static void iconify(Widget w, XEvent * event, String * params, Cardinal * num) XIconifyWindow(XtDisplay(w), XtWindow(w), DefaultScreen(XtDisplay(w))); } -static void sleep_3(Widget w, XEvent * event, String * params, Cardinal * num) +static void sleep_10(Widget w, XEvent * event, String * params, Cardinal * num) { time_t old_t; time_t t; int i; /* UNIXTimer.c 内部で SIGALRM を使用しているので,sleep() は使用できない */ #if 0 - sleep(3); + sleep(10); #else - for (i = 0; i < 3; i++) { + for (i = 0; i < 10; i++) { time(&t); old_t = t; while (t == old_t) @@ -96,14 +96,15 @@ static XtActionsRec actions[] = { {"quit", quit}, {"wm_protocols_proc", wm_protocols_proc}, {"iconify", iconify}, - {"pause", sleep_3} + {"pause", sleep_10} }; static char * translations = "WM_PROTOCOLS: wm_protocols_proc()\n" -"Nonep: pause()\n" +"NoneF11: pause()\n" "Ctrli: iconify()\n" "Ctrlc: quit()\n" +"NoneF12: quit()\n" "Noneq: quit()"; /*===========================================================================*/ @@ -123,6 +124,21 @@ static unsigned long XDisplay_GetPixelFromColorName(XDisplay x_display, /* イベントハンドラ */ /*===========================================================================*/ +/*---------------------------------------------------------------------------*/ +/* イクスポーズ */ +/*---------------------------------------------------------------------------*/ + +static void ExposeHandler(Widget w, XtPointer p, XEvent * event, + Boolean * dispatch) +{ + XDisplay x_display = (XDisplay)p; + + XCopyArea(x_display->display, x_display->lcd_pixmap, + x_display->lcd_window, x_display->copy_gc, + 0, 0, x_display->width, x_display->height, 0, 0); + return; +} + /*---------------------------------------------------------------------------*/ /* キーの押下 */ /*---------------------------------------------------------------------------*/ @@ -161,10 +177,16 @@ static void KeyHandler(Widget w, XtPointer p, XEvent * event, switch (key_sym) { /* 表示モード変更 */ - case XK_p : + case XK_F10 : x_display->lcd_draw = !(x_display->lcd_draw); - if (x_display->lcd_draw) + + if (x_display->lcd_draw) { +#if 1 WonXDisplay_Flush(WonX_GetWonXDisplay()); +#else + ExposeHandler(w, p, event, dispatch); +#endif + } break; /* データのダンプ操作 */ @@ -184,21 +206,6 @@ static void KeyHandler(Widget w, XtPointer p, XEvent * event, return; } -/*---------------------------------------------------------------------------*/ -/* イクスポーズ */ -/*---------------------------------------------------------------------------*/ - -static void ExposeHandler(Widget w, XtPointer p, XEvent * event, - Boolean * dispatch) -{ - XDisplay x_display = (XDisplay)p; - - XCopyArea(x_display->display, x_display->lcd_pixmap, - x_display->lcd_window, x_display->copy_gc, - 0, 0, x_display->width, x_display->height, 0, 0); - return; -} - /*---------------------------------------------------------------------------*/ /* マウスがウインドウを離れたら,キーを初期化する */ /*---------------------------------------------------------------------------*/ @@ -407,7 +414,7 @@ int XDisplay_DrawLCDWindow(XDisplay x_display, WWDisplay ww_display, int n[16]; XRectangle rectangle; XRectangle * rectangles[16]; - int pixel; + unsigned short int pixel; int ww_lcd_width, ww_lcd_height; int red, green, blue; XColorGCDatabase database; @@ -534,6 +541,7 @@ int XDisplay_DrawLCDWindow(XDisplay x_display, WWDisplay ww_display, rectangle.y, rectangle.width, rectangle.height); + XColorGC_Destroy(x_color_gc); } } diff --git a/challsrc.sh b/challsrc.sh new file mode 100644 index 0000000..cea36e3 --- /dev/null +++ b/challsrc.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +./filters.pl "qkc -e -u" ./sys2wonx.pl ./int2sint.pl -f $* + diff --git a/comm.c b/comm.c index 9a77758..0faf953 100644 --- a/comm.c +++ b/comm.c @@ -165,9 +165,9 @@ int comm_send_char(unsigned char c) if (!UNIXSerialPort_IsOpened(unix_serial_port)) WonX_Error("comm_send_char", "UNIX serial port is not opened."); - printf("output to serial port : "); + printf("output to serial port : \""); comm_output(c); - printf("\n"); + printf("\"\n"); fflush(stdout); ret = 0; @@ -292,11 +292,11 @@ int comm_send_string(char * string) if (!UNIXSerialPort_IsOpened(unix_serial_port)) WonX_Error("comm_send_string", "UNIX serial port is not opened."); - printf("output to serial port : "); + printf("output to serial port : \""); for (i = 0; string[i]; i++) { comm_output(string[i]); } - printf("\n"); + printf("\"\n"); fflush(stdout); ret = 0; @@ -336,11 +336,11 @@ int comm_send_block(void * buffer, int size) if (!UNIXSerialPort_IsOpened(unix_serial_port)) WonX_Error("comm_send_block", "UNIX serial port is not opened."); - printf("output to serial port : "); + printf("output to serial port : \""); for (i = 0; i < size; i++) { comm_output(((char *)buffer)[i]); } - printf("\n"); + printf("\"\n"); fflush(stdout); ret = 0; diff --git a/disp.c b/disp.c index 5905b74..5d8a369 100644 --- a/disp.c +++ b/disp.c @@ -137,8 +137,7 @@ unsigned int display_status(void) } /* - * void * data だと,まちがって int * でデータを指定するようなバグが - * 入る可能性があるので,unsigned char * data にした. + * data は char × 8 で 8 バイト. */ void font_set_monodata(unsigned int number, unsigned int count, unsigned char * data) @@ -146,9 +145,9 @@ void font_set_monodata(unsigned int number, unsigned int count, WWCharacter ww_character; WWDisplay ww_display; int i, j, k, n; - unsigned char pixel; int f, b; - unsigned char bitmap[2]; + unsigned short int pixel; + unsigned short int bitmap; if (!WonX_IsCreated()) WonX_Create(); @@ -168,15 +167,13 @@ void font_set_monodata(unsigned int number, unsigned int count, for (i = 0; i < count; i++) { ww_character = WWDisplay_GetCharacter(ww_display, number + i); for (j = 0; j < 8; j++) { - bitmap[0] = 0; - bitmap[1] = 0; + bitmap = 0; for (k = 0; k < 8; k++) { pixel = (data[n] & (1 << k)) ? f : b; - bitmap[0] |= ( pixel & 1) << k; - bitmap[1] |= ((pixel >> 1) & 1) << k; + bitmap |= ( pixel & 1) << k; + bitmap |= ((pixel >> 1) & 1) << (k + 8); } - WWCharacter_SetBitmap(ww_character, j*2 , bitmap[0]); - WWCharacter_SetBitmap(ww_character, j*2+1, bitmap[1]); + WWCharacter_SetBitmapAsShortInt(ww_character, j, bitmap); n++; } } @@ -193,11 +190,10 @@ void font_set_monodata(unsigned int number, unsigned int count, } /* - * void * data だと,まちがって int * でデータを指定するようなバグが - * 入る可能性があるので,unsigned char * data にした. + * data は short int × 8 で 16 バイト. */ void font_set_colordata(unsigned int number, unsigned int count, - unsigned char * data) + unsigned short int * data) { WWCharacter ww_character; WWDisplay ww_display; @@ -217,8 +213,8 @@ void font_set_colordata(unsigned int number, unsigned int count, n = 0; for (i = 0; i < count; i++) { ww_character = WWDisplay_GetCharacter(ww_display, number + i); - for (j = 0; j < 16; j++) { - WWCharacter_SetBitmap(ww_character, j, data[n]); + for (j = 0; j < 8; j++) { + WWCharacter_SetBitmapAsShortInt(ww_character, j, data[n]); n++; } } @@ -235,11 +231,10 @@ void font_set_colordata(unsigned int number, unsigned int count, } /* - * void * data だと,まちがって int * でデータを指定するようなバグが - * 入る可能性があるので,unsigned char * data にした. + * data は short int × 8 で 16 バイト. */ void font_get_data(unsigned int number, unsigned int count, - unsigned char * data) + unsigned short int * data) { /* 関数の仕様がわからんので適当に書くぞ */ WWCharacter ww_character; @@ -260,8 +255,8 @@ void font_get_data(unsigned int number, unsigned int count, n = 0; for (i = 0; i < count; i++) { ww_character = WWDisplay_GetCharacter(ww_display, number + i); - for (j = 0; j < 16; j++) { - data[n] = WWCharacter_GetBitmap(ww_character, j); + for (j = 0; j < 8; j++) { + data[n] = WWCharacter_GetBitmapAsShortInt(ww_character, j); n++; } } diff --git a/etc.c b/etc.c index c1a83a5..7dd2416 100644 --- a/etc.c +++ b/etc.c @@ -22,9 +22,23 @@ int wonx_print_character(FILE * fp, unsigned char c) 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, "\\\""); + else if (c == '\'') fprintf(fp, "\\\'"); + else if (c == '\\') fprintf(fp, "\\\\"); else if (c == ' ' ) fprintf(fp, "\\s"); else if (isprint(c)) fputc(c, fp); else fprintf(fp, "^%02x", (int)c); fflush(fp); return (0); } + +/*===========================================================================*/ +/* 10進→16進文字への変換 */ +/*===========================================================================*/ + +char wonx_dec_to_hex(int dec) +{ + static char * dec2hex = "0123456789abcdef"; + return (dec2hex[dec]); +} + diff --git a/etc.h b/etc.h index 2ae48fd..8fc353f 100644 --- a/etc.h +++ b/etc.h @@ -16,4 +16,10 @@ char * wonx_true_false(int b); int wonx_print_character(FILE * fp, unsigned char c); +/*===========================================================================*/ +/* 10進→16進文字への変換 */ +/*===========================================================================*/ + +char wonx_dec_to_hex(int dec); + #endif diff --git a/filters.pl b/filters.pl new file mode 100644 index 0000000..cda67d9 --- /dev/null +++ b/filters.pl @@ -0,0 +1,16 @@ +#!/usr/local/bin/perl + +while ($_ = shift(@ARGV)) { + if ($_ eq "-f" ) { last; } + if ($_ eq "-file") { last; } + $filters = "$filters | $_"; +} + +while ($filename = shift(@ARGV)) { + $command = "cat $filename$filters > $filename.tmp"; + print "$command\n"; + system($command); + $command = "mv $filename.tmp $filename"; + print "$command\n"; + system($command); +} diff --git a/int2sint.pl b/int2sint.pl new file mode 100644 index 0000000..e1683d2 --- /dev/null +++ b/int2sint.pl @@ -0,0 +1,19 @@ +#!/usr/local/bin/perl + +while () { + s/([\s;\}\/])uint(\s)/$1unsigned int$2/g; + s/^uint(\s)/unsigned int$1/g; + + s/([\s;\}\/\(\)])long(\s+)int([\s\)\+\-\*\/])/$1_WONX_LONG_$2_WONX_INT_$3/g; + s/([\s;\}\/\(\)])short(\s+)int([\s\)\+\-\*\/])/$1_WONX_SHORT_$2_WONX_INT_$3/g; + s/^long(\s+)int([\s\)\+\-\*\/])/_WONX_LONG_$1_WONX_INT_$2/g; + s/^short(\s+)int([\s\)\+\-\*\/])/_WONX_SHORT_$1_WONX_INT_$2/g; + + s/([\s;\}\/\(\)])int([\s\)\+\-\*\/])/$1_WONX_SHORT_ _WONX_INT_$2/g; + s/^int([\s\)\+\-\*\/])/_WONX_SHORT_ _WONX_INT_$1/g; + + s/_WONX_LONG_/long/g; + s/_WONX_SHORT_/short/g; + s/_WONX_INT_/int/g; + print $_; +} diff --git a/libwwc.c b/libwwc.c index 9ae0169..3c746cf 100644 --- a/libwwc.c +++ b/libwwc.c @@ -175,7 +175,12 @@ unsigned int wwc_palette_get_color(unsigned int palette_num, unsigned int color_ return (ret); } -void wwc_font_set_colordata(unsigned int number, unsigned int count, unsigned char * data) +/* + * data は long int × 8 で 32 バイト. + */ + +void wwc_font_set_colordata(unsigned int number, unsigned int count, + unsigned long int * data) { WWCharacter ww_character; WWDisplay ww_display; @@ -195,8 +200,8 @@ void wwc_font_set_colordata(unsigned int number, unsigned int count, unsigned ch n = 0; for (i = 0; i < count; i++) { ww_character = WWDisplay_GetCharacter(ww_display, number + i); - for (j = 0; j < 32; j++) { - WWCharacter_SetBitmap(ww_character, j, data[n]); + for (j = 0; j < 8; j++) { + WWCharacter_SetBitmapAsLongInt(ww_character, j, data[n]); n++; } } @@ -212,7 +217,12 @@ void wwc_font_set_colordata(unsigned int number, unsigned int count, unsigned ch return; } -void wwc_font_get_colordata(unsigned int number, unsigned int count, unsigned char * data) +/* + * data は long int × 8 で 32 バイト. + */ + +void wwc_font_get_colordata(unsigned int number, unsigned int count, + unsigned long int * data) { WWCharacter ww_character; WWDisplay ww_display; @@ -232,8 +242,8 @@ void wwc_font_get_colordata(unsigned int number, unsigned int count, unsigned ch n = 0; for (i = 0; i < count; i++) { ww_character = WWDisplay_GetCharacter(ww_display, number + i); - for (j = 0; j < 32; j++) { - data[n] = WWCharacter_GetBitmap(ww_character, j); + for (j = 0; j < 8; j++) { + data[n] = WWCharacter_GetBitmapAsLongInt(ww_character, j); n++; } } diff --git a/readline.pl b/readline.pl deleted file mode 100644 index 8f4d994..0000000 --- a/readline.pl +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/perl - -use FileHandle; - -$file = @ARGV[0]; - -open(FILE, "$file"); -FILE->autoflush(); - -while () { - print "$_"; - STDOUT->autoflush(); - FILE->autoflush(); -} - -# End of program diff --git a/sout2str.pl b/sout2str.pl index 44913af..9327619 100644 --- a/sout2str.pl +++ b/sout2str.pl @@ -1,14 +1,17 @@ -#!/usr/bin/perl +#!/usr/local/bin/perl use FileHandle; while () { if (/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/ /; + ($string) = /output to serial port : \"(.*)\"\n$/; + $string =~ s/\\n/\n/g; + $string =~ s/\\r/\n/g; + $string =~ s/\\t/\t/g; + $string =~ s/\\\"/\"/g; + $string =~ s/\\\'/\'/g; + $string =~ s/\\\\/\\/g; + $string =~ s/\\s/ /g; print "$string"; STDOUT->autoflush(); } diff --git a/sys2wonx.pl b/sys2wonx.pl index 0b899d1..846a2bd 100644 --- a/sys2wonx.pl +++ b/sys2wonx.pl @@ -1,14 +1,6 @@ -#!/usr/bin/perl +#!/usr/local/bin/perl -while ($FILENAME = shift(@ARGV)) { - open (RFILE, "< $FILENAME"); - open (WFILE, "> $FILENAME.tmp"); - while () { - s/^(\s*\#\s*include\s*)[\<\"]sys\/(.+\.h)[\>\"]/$1\"wonx_include\/$2\"/i; - print WFILE $_; - } - close (RFILE); - close (WFILE); - - system("mv $FILENAME.tmp $FILENAME"); +while () { + s/^(\s*\#\s*include\s*)[\<\"]sys\/(.+\.h)[\>\"]/$1\"wonx_include\/$2\"/i; + print $_; } diff --git a/wonx_include/disp.h b/wonx_include/disp.h index 4a6191a..c3c2c93 100644 --- a/wonx_include/disp.h +++ b/wonx_include/disp.h @@ -68,9 +68,9 @@ unsigned int display_status(void); void font_set_monodata(unsigned int number, unsigned int count, unsigned char * data); void font_set_colordata(unsigned int number, unsigned int count, - unsigned char * data); + unsigned short int * data); void font_get_data(unsigned int number, unsigned int count, - unsigned char * data); + unsigned short int * data); void font_set_color(unsigned int colors); unsigned int font_get_color(void); void screen_set_char(int screen, int x, int y, int w, int h, diff --git a/wonx_include/fcntl.h b/wonx_include/fcntl.h new file mode 100644 index 0000000..64faa5f --- /dev/null +++ b/wonx_include/fcntl.h @@ -0,0 +1,32 @@ +#ifndef _WONX_SYS_FCNTL_H_ +#define _WONX_SYS_FCNTL_H_ + +#include "filesys.h" + +/* + * fcntl.h は /usr/include/fcntl.h を読み込めばよいので, + * 本当はこのファイルでは, + * #include + * するだけにしたいのだが,これだと -Iwonx_include のようにしてコンパイル + * している場合に,自分自身を読み込んでしまう可能性があるので, + * #include + * として,自分自身を読み込まないように,/usr/include を明示している. + */ + +/* + * NetBSD と FreeBSD では,/usr/include/fcntl.h と + * /usr/include/sys/fcntl.h はまったく同じである. + * + * Solaris では,/usr/include/fcntl.h が /usr/include/sys/fcntl.h を + * インクルードしている. + * + * Linux では,/usr/include/fcntl.h が本体になっていて, + * /usr/include/sys/fcntl.h は /usr/include/fcntl.h をインクルードするだけの + * ファイルになっている. + */ + +/* 一応両方とも include しておく */ +#include +#include + +#endif diff --git a/wonx_include/fcntl_attention.h b/wonx_include/fcntl_attention.h deleted file mode 100644 index 0b82775..0000000 --- a/wonx_include/fcntl_attention.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef _WONX_SYS_FCNTL_H_ -#define _WONX_SYS_FCNTL_H_ - -/* - * fcntl.h は /usr/include/fcntl.h を読み込めばよいので, - * wonx_include/fcntl.h を作らないほうがよい.(wonx_include/fcntl.h を作ると, - * 書き方によってはそっちが読み込まれてしまうかもしれないので) - * もしも作るとすれば,このファイルのようなのを作るか? - */ - -#include "filesys.h" - -/* 自分自身を読み込まないように,/usr/include を明示する */ -#include - -#endif diff --git a/wonx_include/libwwc.h b/wonx_include/libwwc.h index 137603e..308461f 100644 --- a/wonx_include/libwwc.h +++ b/wonx_include/libwwc.h @@ -23,8 +23,10 @@ unsigned int wwc_set_color_mode(unsigned int mode); unsigned int wwc_get_color_mode(void); void wwc_palette_set_color(unsigned int palette_num, unsigned int color_num, unsigned int rgb); unsigned int wwc_palette_get_color(unsigned int palette_num, unsigned int color_num); -void wwc_font_set_colordata(unsigned int number, unsigned int count, unsigned char * data); -void wwc_font_get_colordata(unsigned int number, unsigned int count, unsigned char * data); +void wwc_font_set_colordata(unsigned int number, unsigned int count, + unsigned long int * data); +void wwc_font_get_colordata(unsigned int number, unsigned int count, + unsigned long int * data); unsigned int wwc_get_hardarch(void); void wwc_clear_font(void); diff --git a/wonx_include/types.h b/wonx_include/types.h index ba54aad..9ca8731 100644 --- a/wonx_include/types.h +++ b/wonx_include/types.h @@ -16,10 +16,10 @@ typedef unsigned short int ushort; typedef unsigned long int ulong; #endif -typedef unsigned char BYTE; -typedef unsigned short WORD; -typedef unsigned long DWORD; -typedef int BOOL; +typedef unsigned char BYTE; +typedef unsigned short int WORD; +typedef unsigned long int DWORD; +typedef int BOOL; #ifndef far #define far /* None */