Initial version

Version 0.0.1 alpha - from wonx-a01.tar.gz
This commit is contained in:
Hiroaki Sakai 2000-09-26 12:00:00 +09:00 committed by Godzil
commit 3c624a304e
45 changed files with 5329 additions and 0 deletions

340
COPYING Normal file
View File

@ -0,0 +1,340 @@
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Library General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Library General
Public License instead of this License.

46
COPYRIGHT Normal file
View File

@ -0,0 +1,46 @@
/*****************************************************************************/
/* Wonx - WonderWitch on X. */
/* */
/* Wonx Copyright (c) 2000 Sakai Hiroaki. */
/* All Rights Reserved. */
/*===========================================================================*/
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 2, or (at your option) */
/* any later version. */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program; see the file COPYING. If not, write to */
/* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
/*****************************************************************************/
/*****************************************************************************/
/* 本ソフトウエアの著作権は全て「坂井弘亮」が有します. */
/* 本ソフトウエアは,フリーソフトです. */
/* 本ソフトウエアのライセンスにはGNU General Public License を適用します. */
/* 本ソフトウエアはGNU General Public License の下での */
/* コピー/修正/改良/再配布が可能です. */
/* GPL については詳しくはCOPYING を参照してください. */
/*===========================================================================*/
/* 本ソフトウェアを使用することによって発生したあらゆる損害の責任は */
/* 使用者にあり,著作権者はその責任を一切負いません. */
/* 本ソフトウエアの改良やバージョンアップや移植などの義務は, */
/* 著作権者には一切ありません. */
/*===========================================================================*/
/* 日本語のドキュメントの文章の内容と,英語のドキュメントの文章の内容の間に */
/* 差異が生じた場合には,日本語のドキュメントの文章の内容が,正しい意志で */
/* あるものとします. */
/*===========================================================================*/
/* 坂井弘亮の連絡先のメールアドレスは, */
/* sakai@seki.ee.kagu.sut.ac.jp */
/* hsakai@pfu.co.jp */
/* です.また,本ソフトウエアの最新版を, */
/* http://www.seki.ee.kagu.sut.ac.jp/~sakai/WonderWitch/index.html */
/* で配布しています. */
/* ご意見,ご感想がありましたら,ぜひ連絡ください. */
/*****************************************************************************/

0
HISTORY Normal file
View File

31
Makefile Normal file
View File

@ -0,0 +1,31 @@
XINCLUDEDIR = /usr/X11R6/include
INCLUDEDIR = .
XLIBDIR = /usr/X11R6/lib
VERSION = Wonx-a01
PKGNAME = wonx-a01
OBJS = WWCharacter.o WWColorMap.o WWDisplay.o WWLCDPanel.o WWPalette.o WWScreen.o WWSprite.o WonxDisplay.o XDisplay.o bank.o comm.o disp.o text.o key.o sound.o system.o timer.o etc.o wonx.o
.SUFFIXES: .c .o
all : libwonx.a
libwonx.a : $(OBJS)
ar ruc libwonx.a $(OBJS)
# ranlib libwonx.a
.c.o : $*.c
gcc -c $*.c -O -I$(INCLUDEDIR) -I$(XINCLUDEDIR)
clean :
rm -f libwonx.a *.o
package :
mkdir -p $(PKGNAME)
rm -fR $(PKGNAME)/*
cp COPYING COPYRIGHT HISTORY README OMAKE.jpn Makefile \
*.h *.c $(PKGNAME)
tar cvzf $(PKGNAME).tar.gz $(PKGNAME)
# End of Makefile.

925
OMAKE.jpn Normal file
View File

@ -0,0 +1,925 @@
この文書は,おまけ,ていうか,暇なときに気が向いたまま書き貯めたものです.
■■ N.A.D.A.R. 開発秘話
N.A.D.A.R. はそもそもは中学生のときに「TANK」という名前で作った
人対戦のゲームだったもう10年以上前の話だ
もともとぼくは戦車ゲームが好きなのだが,まわりにはあまり満足のいく
戦車ゲームが無かった.そこで昔のプログラマの鉄則,
ほしければ作る
にしたがって,自宅の PC-9801VX で作ったのがはじまりだった.
このころ学校の理科室に PC-9801M2 があって,それでプレイしてたりしてた.
しかし当時の PC-9801M2 はすでにひと昔前の機種であり8086 の 5MHz では
名機 PC-9801VX の 80286 8MHz にはかなうはずもなく,
おそすぎてゲームにならん
とフトドキなことを考えていた.とくに接近戦になって,2人が同時に
砲弾とミサイルを撃つと,目に見えて速度が低下してしまう.しかしこれも,
クライマックスでスローモーションになる,映画のワンシーンみたい
とあるていど納得していたわけであるから,
遅延まで考慮に入れて逆に利用したゲーム
という,今思うとカッコイイ仕様ではあったと思う.(本当か!?)
TANK は一人プレイ用の TANK2人プレイ用になってTANK3A
改良を加えてTANK3B, TANK3C, ... と製作していき,最終的には,
TANK3E まで製作した.
その後,兄の「戦車をもっと大きくしたほうがよい」という意見を採り入れて,
戦車を拡大した TANK3F再びもとに戻した TANK3G というように,
暇をみてはバージョンアップしていく
という,まさに趣味で作ってるプログラムであった.
大学3年生から4年生にかけて,
マイコン BASIC MAGAZINE
によく投稿していて,一時期,常連になっていたのだが,
大学4年のときに,マイコン BASIC MAGAZINE の投稿用に,プログラムを
全体的に見直してTANK3I を作った.が,これは,
あえなくボツ
マイコン BASIC MAGAZINE の掲載基準は「アイディア重視」であって,
やはりこういうありがちなゲームは載りにくい.しかも2人でないと
プレイできないとなると,なおさら載りにくい.
ピーピング形式にしてTANK3J を作ったが,
これもボツ
PC-9801 用の TANK は,ここまでである.
しかし研究室に入ってX を使うようになってからは,いつか TANK を
X に移植したいと思っていた.そして,
フリーソフトとして公開する
というTank 復活の方法を考えていた.
実際に Tank を書きはじめたのは就職した1999年の4月からである
4月に就職し5月くらいからTank で使用するためのネットワーク通信用
ライブラリを書き出した.
このころ,ちょうど,
オブジェクト指向
にはまってて,頭の中ではすっかりオブジェクト指向至上主義.
オブジェクト指向で書いておけば,
その向こうにはバラ色の世界が待っている
という考えだった.
しかし,通信には文字列処理がつきものなので,そのまえに文字列処理用の
String クラスを作ろう,と思った.
また,通信するには select() で調べることが必要になるからselect() 用の
クラスも欲しい.ソケットの接続までの部分は接続部分として,別クラスにしたい.
通信は文字列の通信を行う部分と,じっさいにデータ通信を行う部分は別クラスに
したい,などという感じで,オブジェクト指向をやりたてのときにありがちな,
なんでもかんでもクラスにしよう
というようにはまってしまい,あげくのはてには,
整数までもInteger クラスで管理しそうな勢い
になって,収拾がつかなくなってしまう.
また,クライアントが複数になったときには,サーバ側では fork() して通信の
接続要求だけを処理するようなプロセスを作って,クライアントごとには
通信だけを処理するプロセスを作り,サーバプロセスとはパイプで通信する...
というような実装も見越した上で書きたい,などと,
はてしない深みにはまっていってしまった
そのうち EyeClock-2.0 の開発を始めることになってしまい,こっちに
どっぷりつかってしまった.
1999年の月から12月にかけてはEyeClock-2.0 にかかりっきりで,
Tank は先送り(ていうか,ほとんど忘れ去られた状態)になってしまった.
EyeClock-2.0 は1999年の年末ぎりぎり(クリスマスイブだった.
とくに意味はないのだが)に公開した.しかし今思えば,
クリスマスイブに,世のため人のために
フリーソフトを公開しているなんて,
聖人のような生活
だと思ってしまう.
しかし,ただの時計なので,
たいして世のためになっていない
というのが悲しいところである.
EyeClock-2.0 がひと段落してからは,あそびで XKeyWrap とかを書いていたのだが,
2000年の月中旬くらいにようやく Tank を書き出した.
以前の教訓があったので,今回はあまり細部にこだわらずに,
とりあえず動くもんをつくって公開しちまえ
という方針で開発を進めた.
以前のネットワーク用ライブラリとかEyeClock-2.0 での経験とかが
あったので,開発はトントン拍子に進んで,わずか1ヵ月足らずで
ふつうにプレイできるプロトタイプが仕上がった.
よく「N.A.D.A.R.って,なんの略なの?」と聞かれる.
N.A.D.A.R. の命名には,ずいぶん悩んだ.ここで,命名の由来を書こう.
もともと橋本も僕も,
グロブダー
というゲームが好きだった.ナムコのずいぶん古いアーケードゲームなのだが,
ちょっとでも気を抜いたら(ていうか,気を抜いていなくても),あっと言うまに
やられてしまうという,スリルとスピード感のあるゲームだった.
やはりスリルと緊張感,一瞬の判断こそが
アクションゲームの醍醐味
だとぼくは思っているので,そんなゲームを作りたいと常々思っていた.
N.A.D.A.R. のプロトタイプが完成して,そろそろ名前を決めてしまいたいと
いうとき,橋本と焼肉屋に行った.で,焼肉屋でいろいろ話したのだが,とりあえず,
「TANK」はやめよう
ということになった.
戦車の重みを表現したいので,「グロブダー」のように,濁音のある名前にしたい.
そう考えると「グロブダー」はG,B,D と,濁音のある文字が3つも入っている.
そこで考えたのが,
GNOMEDAR
でもGNOME は直接的にとくに関係は無いのでこれは却下.
いっそのこと,日本的な名前はどうだろう?
「風林火山」
なんて冗談半分でいろいろ考えていたのだが,そこでそのとき,
「灘の生一本」
という日本酒のポスターが目に入った.
「灘」ってのはどうだ?
このときは,あまり深く考えてなくって,けっきょくこの日には決まらなかった
のだが,このときにしっかり決めなかったのがよくなかった.
そのうち開発を進めるうちに,ファイル名とかも整理しだして,
ほんとにもういいかげん名前を決めたい
と思い,けっきょく,「灘」にアクセントで r をつけて「NADAR」にしてしまった
というようにあまり意味なく決まってしまった「NADAR」なのだが
作者としては,いちおう,
アルファベットになにか意味を持たせたい
うーん,
N.A.D.A.R. - Network Action ...
だめだDのあたりでなんにもおもいつかん
■■ EyeClock 開発秘話
そもそもなんで EyeClock を作り出したかってはなし.
大学の卒業研究のために研究室に配属されたのは1996年の月だった
この研究室では数値計算を行うため,メインの OS として UNIX が使われていた
のだが,僕にとっては,これが,よかった.
研究室では主に FreeBSD を使って作業していたんだけれど,
「好きな画像を時計にしたい!」
と,常々思っていた.
今思えば,よく探せばそういう時計アプリケーションもなにかしらあるんじゃ
ないかと思うんだけどそのときはよく探しもせずにman xclock をてきとーに
読んだくらいであきらめていた.
これが後々 EyeClock の開発につながったわけだ.
EyeClock の開発に着手したのはたしか1998 年の6月ごろだったと思う.
1998年の月というと自分は大学院の修士年で就職活動のあいまを
見つけては,本業の研究をそっちのけにして,
XMangekyou
を書いていた.
なにせこのころは,毎日毎日,一日中 X のプログラミングをしてたのだ.
毎週火曜と水曜には研究室に泊まって,大学の近くの
三河屋という酒屋(理科大の人はよく知っているハズだ)
に行って,ビールとワインを買って,夜になると,
飲んで歌いながら
プログラミングをしていたもんだ.(今考えると,不気味だ)
研究室にはスパゲッティとミートソースの缶詰を買い置き(これも三河屋で買ったもの)
してあってだいたい夜の12時を過ぎたころに夜食を食べて
明け方の4時頃までがんばって眠くてどうしようもなくなったら寝袋で寝る
朝は10時頃に起きて大学のトレーニングルームでシャワーを浴びて
シャンプーして,ヒゲをそって,で,またプログラミングを始める,
といった生活だった.
このため,研究室には,
着替えも常備してあった
このころまでは,だれも使っていなかった Sun SPARC Station 5 をよく
使っていたんだけれどXMangekyou の動作を XFree86 上でテストする
必要性が出てきたので,これまたあまりだれも使っていなかった,ロースペックの
オーダーメイド AT 互換機(FreeBSD + XFree86) を使うようになった.
このロースペックマシンは,研究室に数少ない,
音の出るマシン
のうちのひとつだったので,けっこうお気に入りだった.ロースペックなので,
だれも使わないし,計算を走らせたりもしないから,気軽に使えるということもあり,
けっきょく,卒業するまで,ずっとこのマシンを使っていた.
EyeClock や XStarRoll や修士論文は,すべてこのマシンを使って書いた.
5月の中旬に就職が決まって,そのあとには,たまに研究もしつつ,
でも本業はプログラミングというくらいのいきおいで,プログラミングをしていた.
当時の後輩曰く,
「坂井さんはいっつも研究室にいるけど,
なにをやっているのかわからんです」
研究してるわけでもないし,遊んでいるようにも見えないし,ということだった
らしい.とはいっても,
じつは遊んでいたんだけどね
月の終り頃XMangekyou をひととおり作り終えたあとは,いよいよ EyeClock の
開発にとりかかる.
まず時計「MyClock」を作ったこれは時計とはいっても
白黒のビットマップを張りつけられるだけ
という,非常におそまつなものだった.当時はまだピックスマップファイルの
読み込みかたをしらなかったので,しかたなくビットマップで作ったのだ.
このあたりの作業の順番はじつはうろおぼえなので,たしかなことはよく
覚えていないのだが,次にやったのは,
「ピックスマップファイルを読み込んで,カラーで表示したい!」
ということだったとおもう.
しかしX の標準では,ピックスマップファイルを読み込んでピックスマップを
作成するような関数は,提供されていない.
X や Motif の書籍をいろいろ調べたのだが,ピックスマップファイルの
読み込みかたは,書いていなかった.そこで,かの有名な,
EmiClock
のソースを参考にすることにした.
EmiClock のソースを読んで,はじめて Xpm ライブラリの存在を知り,
ピックスマップファイルを読み込むことができるようになった.
ちなみに EmiClock はすばらしく優れたプログラムで,ソースを見ると
わかるのだが,ほんとにいたれりつくせりで,
X のプログラミングをしようとしてるひとは,ぜひ読んだほうがいい
という,おすすめの1本である.
これで MyClock は,カラーの画像が扱えるようになった.自分としては
それなりに満足して,タレントの画像を張り付けたりして使っていた.
そんなある日,忘れもしない,帰宅中の
三田線水道橋~白山
あたりで,ふと思った.
「あれで目を動かしたら,面白いんじゃないか?」
ここから EyeClock の開発が始まったわけだ.
(次回作の OMAKE.jpn に続く)
■■ 趣味のプログラム
ぼくは子供のころから,なにかものを作ることが趣味だったんだけど,
ある日,ぼくの兄上(こいつもなにかものを作ることが趣味なのだが)と,
ぼくと,父親で,
よくわからない展示会
のようなところに行った.(なんの展示会だったのか,会場はどこだったのかなどは,
まったく覚えていない)
この展示会場には,当時はやりだった LED のゲームとかがいろいろあったように
記憶しているのだが,この会場のある一角に,
マイコン
が置いてあるコーナーがあった.(もともとは兄がそっちが目的だったらしいのだが)
このマイコンはRETURN キーが緑色と赤色だったので,いま思えばおそらく,
東芝のパソピア7だったのだろうとおもう.
このマイコンでは,実際に BASIC のプログラムをいろいろいじる,というような
デモが行われていたらしく,
BASIC のプログラムリストが画面上にダンプされていて,
カーソルが左上で点滅しているだけ
だった.ちなみに,この「マイコン」を初めて見て,ぼくが最初に口にした言葉は,
「ねえねえ,これってどんなゲームなの?」
だった.うーん,はずかしい.
しばらくして,近所のひとがパソコンを持っているというので,
兄といっしょに触らせてもらいに行くことになった.
このときあったのは,いま思えばたしか Sharp の MZ 系のマシンだったと思う.
当時はぼくはパソコンというものをまったく知らなかったので,ただ単に
兄についていって,兄がいじるのをとなりで見ていただけだったのだ.
兄がプログラムを打ち込み終って run すると,画面上に,
2
とかの数字が出てきた.
もういちど run すると,今度は,
6
とかの数字が出てきた.
兄「これ,見てみ」
僕「なに,これ?」
そう,このとき兄が書いていたプログラムは,忘れもしない,
サイコロ
であったのである.
いま思えば,
10 A=INT(RND(1)*6)+1
20 PRINT A
30 END
のようなプログラムを打ち込むのに10数分かかっていたのだろう
そんな兄の要望で,ついに我が家もパソコンを買うことになった.
当時兄は小学6年生で,毎週秋葉原に行っては抵抗やコンデンサを買いこんできて,
ラジオとかを作っていた(気違い小学生だ)のだが,そんなある日の日曜に,
父親,兄,僕で,いよいよ秋葉原に買いに行った.
秋葉原駅前のサトームセン(エスカレーターから外が見える建物)で選んだ
パソコンは,忘れもしない,
PC-8001mkII
であったたしか当時で本体価格が127,000円(だと思った)で,さらに当時はまだ
高価だったカラーディスプレイ(当時はまだ,グリーンディスプレイが主流だった)
とデータレコーダーも買ったわけだから,当時の小学生にしては,
けっこう高い買物だったとおもう.
これのおかげで今があるわけだから,親には感謝感謝である.
このときついでに,
2001年宇宙の旅
というゲームと,あと,
ファイヤーレスキュー
というゲームも買った.このファイヤーレスキューというのは,当時,
マイコンショップの店頭で,デモなどによく使われていた記憶があるのだが,
内容はというと,
消防車を左右に操作して,スペースを押すとハシゴが伸びて,
ビルの火事から人を救助する
という,非常に単純なゲームだった.しかも,画面構成は,
キャラクタベース
だったのである.
____
| |
/\__/
/\/
/\/
/\/
/\/
_/\/__________
| | | | \
| | | |__\
| | | |
|__/ \____/ \___|
\_/ \_/
というような消防車を動かすわけである.
どちらも BASIC で書いてあって,ゲーム中に Stop を押すと,
^C
Break in 1130
とかいって止まってしまって,なんと,
プログラムリストを見ることができる
という,いまから考えると信じられないようなものだった.
ぼくが小4の6月に,ついに我が家にもパソコンが来た.このころは,
パソコンが使える BASIC でプログラムが書ける
という時代だったので,ぼくもプログラムを書きはじめることになるのだが,
はじめて買ったパソコンの本は,
BASICプログラミング
という本だった.(漫画である)
どういう内容の本かというと,
ロムさんとラムさん
という兄弟が,
マイコさんやアイコさん
のために,家計簿だとか,社員の定期券の期限の計算用プログラムとかの
プログラミングをしていく,という内容だった.
ちなみにアイコさんはマイコさんの妹で,アイコさんはショートカットの OL で,
ロムさんはマイコさんが好きで,ラムさんはアイコさんが好き,という設定だった.
しかし,
今思うと,すごい名前だ
ちなみにぼくは,長女系のマイコさんより,次女系のアイコさんのほうが好きだった.
この本は BASIC をあるていど知っていることを前提にしていて,
実際にプログラムを書いていく,という内容だったので,まったくの初心者の
ぼくには,よくわからなかった.
そこで次に買った本が,
まんがパソコンゼミナール(きぎようへい・さとう光)
この本は,なんと,いまだに自宅に保存してある.
どういう本かというと,
マイちゃんとコンちゃん
が,名機 PC-8001 を使って,「先生」と「ネコちゃん」といっしょに,
コンピュータの仕組みや,プログラムの書き方を勉強していく,という内容だった.
この本はとてもわかりやすくて,
データバスやアドレスバスやコントロールバスや ROM や RAM や
モニタプログラムや BASIC インタプリタや入力装置や出力装置や
入出力装置や機械語
といった,ハードのこともちゃんと解説されていて,とってもためになった.
この本はボロボロになるまで100回以上繰り返し読んでいると思う
この本の最後を飾っていたプログラムは,「センスイカンノエ」というものである.
どういうものかというと,たしか,
10 REM センスイカンノエ
20 PRINT CHR$(12)
30 LOCATE 20,10
40 PRINT "センスイカンノエ"
50 FOR I=0 TO 1000
60 NEXT
70 PRINT CHR$(12)
80 LOCATE 0,10
90 PRINT " ■ "
100 PRINT "/~~~~~~~~~~~~\"
110 PRINT "\____________/"
120 END
というようなものだったと思う.
FOR I=0 TO 1000
NEXT
で,十分なウエイトになってしまうあたりが,すごいとこだ.
そーいえば,このころってまだ,
マイコン
って言葉が使われていた時代だったなあ.
ぼくがプログラミングをはじめたころはBASIC が全盛の時期だった.
当時は BASIC のプログラムが載っている本が多くあって,
なにをかくそうぼく自身,本に載っているプログラムを
ゲームやりたさで
ひたすら打ち込んで,プログラムをおぼえた,というクチである.
プログラムを打ち込み終って,どきどきしながら run させると,
必ずといっていいほど,
Syntax Error in 30 (いきなり3行目だったりする)
などと言われてしまって,それから本とディスプレイを照らしあわせるという
あまりやりたくない作業になるわけである.
Syntax Error なら,まだいい.たいていはそこの行にミスがあるからである.
やっかいなのは,
Illegal function call (関数やステートメントに渡す値がおかしい)
とかである.これだと,たいていは,その行ではなく,別の行に間違いがある.
いちばんイヤだったのは,
Subscript out of range (配列の範囲をこえたアクセス)
だ.これだと,まず間違いなく,別の行にミスがあって,変数の値が
おかしくなっているのである.
しかしそれも,
(タダで)ゲームがやりたくてたまらない小学生
にとっては,それほど苦ではなかったようである.
この苦労(?)のおかげで,いま思えば,フリーソフトウエアプログラマにとって
もっとも重要な力である,
どんなエラーが出ても,自力でなんとかする気力
が身についたと思う.
どんな本を参考にしていたかというと,一番さいしょに読んで打ち込みはじめたのは,
いまでも覚えている,知る人ぞ知る,ナツメ社の,
はるみのゲームライブラリII
という本だった.この本は残念ながら,どこかへいってしまった.
うーん,もう一度,読んでみたいものである.
「あるけあるけゲーム」(tron のようなゲーム)とか,
「スクロールジャンプ」とか,
「ビルディングクラッシュ」とか,
「地底探検ゲーム」とか,
ペンゴもどきとか,
月面着陸とかを打ち込んでは遊んでた.
この本は当時はやりの,
1画面プログラム
を集めた本(しかも40x25)で,わりと手軽に打ち込めるプログラムが
多かったのだが,それでもパソコンを覚えたての小学生ではキーを探すのも
ままならず,1本を入力するのに2時間とか3時間とかかかっていた.
しかしそれでも,
(タダで)ゲームをやりたいという熱意
は強く,学校が終ったら急いで帰って,きのうの続きを打ち込みはじめる,
という日も多かったように思う.
当然,学校でもゲームのことばかり考えているわけであるから,困ったものだ.
はるみのゲームライブラリ
という本のプログラムも,よく打ち込んだ.
そのうち打ち込んだゲームを適当に改良したりするようになる.
やがて,自分でもゲームを作り出すようになる.
はじめて作ったゲームは,いまでも覚えているが,
「レーザーパックマン」
というタイトルだった.
どういうゲームかというと,
・まず,敵がいる.(ランダムで動いている)
・自分がいる.(テンキーの '1', '2', '3', '5' で移動できる)
・自分と敵の X 座標が一致すると,「ピッ」と音がして,レーザーが発射される.
(IF X=EX THEN LINE(X,Y)-(EX,EY),"■",2 のようなことをやっているわけである)
・自分と敵の Y 座標が一致したときも,おんなじ.
・レーザーを撃つと,スコアが増える.
パッと見てまず思うだろう.そう,このゲームには,
ゲームオーバーがない
のである.
いま思えば,こんなしょーもないゲームでよく遊んでいたものだと思う.
今,思いだせる限りで,レーザーパックマンを再現してみよう.
10 X=20:Y=12:TX=10:TY=10:S=0
20 LOCATE X,Y:PRINT " "
30 LOCATE TX,TY:PRINT " "
40 I$=INKEY$
50 IF I$="1" AND X>0 THEN X=X-1
60 IF I$="3" AND X<39 THEN X=X+1
70 IF I$="5" AND Y>0 THEN Y=Y-1
80 IF I$="2" AND Y<23 THEN Y=Y+1
90 IF INT(RND(1)*2)+1=1 THEN TX=TX-1:GOTO 130
100 IF INT(RND(1)*2)+1=1 THEN TY=TY-1:GOTO 130
110 IF INT(RND(1)*2)+1=1 THEN TX=TX+1:GOTO 130
120 TY=TY+1
130 LOCATE X,Y:PRINT "○"
140 LOCATE TX,TY:PRINT "●"
150 IF X=TX AND Y=TY THEN LINE(X,Y)-(TX,TY),"■",2:S=S+100:BEEP1:BEEP0:GOTO 170
160 IF X=TX OR Y=TY THEN LINE(X,Y)-(TX,TY),"■",2:S=S+10:BEEP1:BEEP0
170 LOCATE 10,0:PRINT S
180 GOTO 20
たしか,こんなんだったとおもう.(なにしろ,はじめて書いたプログラムですから)
確率的に,敵が左上のほうに行きやすくなってしまったというのをおぼえている.
こんなんおもしろいのか?
とも思ってしまうが,自分で作ったゲームというのは,
それなりにおもしろいものである.(本当かなあ...)
ほかにも,インベーダーゲームを作ったことがある.
これは,大量のインベーダーをひとつひとつ処理することに無理があったので,
GET(X,Y)-(X+9,Y+4),G% してから, PUT(X+VX,Y+VY)-(X+VX+9,Y+VY+4),G%
で,インベーダーをまとめて動かしていた.
このころの雑誌で忘れられないのが,
マイコン BASIC マガジン
である.
(次回作の OMAKE.jpn に続く)
■■ 参考文献
ぼくは,本が好きだ.
本棚の専門書を分類したり,整頓したりするのが,とても好きである.
というわけで,参考文献紹介も兼ねて,ちょっと書評(ていうか,個人的な思い出話)
でも書こうかと思う.
■ C言語関係
「はじめての C 改訂第3版 [ANSI C 対応]」
ぼくが大学3年のとき,この本で C 言語に入門したので,
けっこう思い入れがある本である.
あとで知ったのだが,入門書としては,わりと名著で有名らしい.
これを参考にして,大学の授業で,
円周率を(double 型の範囲で)計算するプログラムを作る
という課題があったときに,調子にのって,
円周率を10万桁まで計算するプログラム
を作った記憶がある.しかも,
計算の途中経過をセーブすることができる
という,なかなか気のきいたプログラムだった.
「C プログラミング診断室」
衝動買いした本.いちおうひととおり読んだ...と思う.
たしか大学4年のとき,池袋のビックカメラにまだパソコン館が無いころ,
ビックカメラの1階の書籍コーナーで買った.
内容はちょっと古めなので,オブジェクト指向が流行りの今としては,ちょっと
古いかもしれない,と思う.
「C プログラミング専門課程」
研究室に入ってから UNIX 上で C 言語でプログラミングをするようになって,
「C 言語をもっと勉強したい!」と思って買った本.
これはためになった.この本のおかげで,コンパイラの動作とか,メモリとかが
わかってきた.
こんな疑問を持ったことを覚えている.
「char * s = "ABC"; などの文字列リテラルは,メモリ上に静的に確保される.
ということは,
while (1) {
printf("ABC\n");
}
を実行するとprintf(); が実行されるたびに "ABC" がメモリ上に
配置されるわけだから,そのうちメモリがなくなってしまうのではないだろうか?
しかも,これに対する自分の解答が,
char * a = "ABC";
char * b = "ABC";
のように,文字列がダブっている場合には,コンパイラが判断して,
同じ領域に割り付けたりするらしい.
たぶんwhile () で printf() を繰り返したときにも,
これと同様にprintf() の実行時には,文字列は同じ領域に
割り付けられるのだろう.
うーん,すばらしくとんちんかんというか,さすが BASIC 出身者,というか,
こうして書くこともはずかしいような疑問である.
(インタプリタとコンパイラの動作を誤解しているわけだ)
「プログラミング言語 C」(いわゆる "K&R" である)
有名な本なので,研究室に入ってからとりあえず買ってみた.ざっと読んだだけ.
「fgetc() の戻り値が,なぜ int 型なのか?」という疑問を持ったときに,
この本に解説してあったので,
「なんていい本なんだ!」
と思って買ったんだけど,あんまりちゃんと読んでない.
「C プログラミング FAQ」
これは,いい.最高にためになる.
とりあえず1度通して読んだが,またそのうちもう一度通して読みたいと思っている.
中級者くらいになって,たいてい疑問に思うようなことは,必ず書いてあるのが
すごい.
この本に書いてあることが全般的に理解できてればC 言語はほぼ完璧なのでは,
と思う.
■ X 関係
「X-Window Ver.11 プログラミング[第2版]」
X のプログラムをはじめたころに,これの第1版が研究室にあったので,
よく参考にしてた.
そのうち,家で使う分と学校で使う分の2冊が欲しくなってきて,けっきょく,
第2版を自分で買った.
X のプログラミングをする人って,この本を参考にしている人がけっこう多い
みたいだね.フリーソフトのドキュメントを読んでると,参考文献とかで
よく見かけたりする.
「X-Window OSF/Motif プログラミング」
X のプログラムをはじめたころに,これを参考にしてプログラミングしてた.
はじめのうちはMotif (正確にはLesstif) を使っていたのだが,
やはり Motif は商品である,というのと,
「BSD を 256 倍使うための本」(いわゆる,「黒いニゴロの本」である)
EmiClock 開発秘話で,
X のプログラミングはX ツールキットを使うのがオシャレ
というふうに書いてあった,というのがあって,だんだん Motif は使わなくなった.
でも X ツールキット専門の本ってなぜかすっごく少なくて,たいていは
X ツールキットのプログラミングをするときでもMotif の本を参考にしたりしてる.
ちなみにEyeClock は,
「BSD を 256 倍使うための本」
に,すっごく影響を受けている.
■ そのほか
「スーパーユーザの日々」
「UNIX ネットワークの日々」
「Mail & News の日々」
研究室のシステム管理者をやるようになって,この本でいろいろ勉強した.
帰宅中の有楽町線のなかでよく読んだ.
内容はちょっと古めだが,基礎的なことがしっかりと書かれているので,
基礎勉強にとてもいい本だと思う.書いてある内容も,とてもしっかりしている.
「UNIX のシステムの勉強がしたいんだけど,なにかいい本はないか?」
「ネットワークの勉強がしたいんだけど,なにかいい本はないか?」
とか聞かれたときには,この本を推薦するようにしている.
「UNIX ネットワークの日々」「Mail & News の日々」は,研究室内の
システム管理者育成の勉強会で教材にしていた.この勉強会では,毎回,
「K君」や「中村さん」の役を決めて読む
しかも当然,
セリフ付
ということをしていて,朝,研究室に入ってくる卒研生とかが,
スーパーユーザーが,学芸会のセリフの練習でもしているかのような姿
をまのあたりにして,ギョッとしていた.
「セキュリティの日々」とかも,出してほしいもんだ.
「GNU ソフトウエアプログラミング」
プログラミングに emacs, gcc, make, gdb を使うときの一連の流れが
わかるので,とってもいい本だと思う.
個々のアプリケーションをひとつひとつ詳しく解説してある本はたくさん
あるのだが,開発の一連の流れとして解説してある本は,なかなか少ない.
「よしだともこのルート訪問記」
最近買ったのだが,なんていうか,ここまで,
システム管理者の実際
が書かれているという本は,他にないのでは? とおもう.
(そりゃそうだ,現役の管理者へのインタビューなのだから)
ほかの大学や研究室とかではどういうふうに管理されているか,というのが,
非常に幅広く紹介されていて,とてもためになる.
というのは,コンピュータやネットワークのシステムの構成など
(こういったことも非常にためになるが)が書いてあるだけでなく,
「管理者の人材確保」や「管理者の育成・教育態勢」がどのようになって
いるかなどが書かれているからだ.
やはり,「人材の確保」と「教育」がいちばん大変で重要なことであって,
こういったことが,システム管理の実態だと思う.
しかし,読んでいると,他の大学や研究室などの管理態勢や教育態勢が,
うらやましくなってしまう
ということもある.
(次回作の OMAKE.jpn に続く)
■■ うまいもの
寿司がすきである.
おごってもらうとしたら,
1.寿司
2.焼肉
3.なんかめずらしいたべもの
の順に嬉しい.なにしろ小学生のころは,
寿司屋になりたかった
というくらいである.
とはいっても,寿司などそうそういっつも食べにいけるものではないから,
ふだんは回転寿司にいったり,たまに寿司屋で食べるくらいである.
とはいっても,魚の名前をよく知らない.寿司屋でネタを見ても,
なんの魚だかわからなかったりする.
そのうち,ちゃんとネタの名前をおぼえて,
「なんにいたしますか?」
「そうだなあ.白身のいいとこを握ってくれ」
「へい,おまち」
「お,これはヒラメだね」
なーんて言ってみたいのだが.
ちなみに好きなネタベスト10は
1. 中トロ
2. ビントロ
3. サーモン,ハマチ,マグロ赤身
6. 鯛,メカジキ,サンマ
9. カニ味噌,ウニ
てなかんじだろうか.適当に考えただけなのだが.
うーん,こうしてみると,まだまだ子供の味覚である.
池袋は,やたらと回転寿司が多いので,嬉しい.
(次回作の OMAKE.jpn に続く)
■■ 携帯端末
わずか 800g 程度の Libretto SS1000 に FreeBSD と X を入れて,
電車の中だろうが,待ち合わせの「いけふくろう」の前だろうが,
ところかまわずプログラミングをしている.
・携帯端末(いわゆるWindowsCEマシン)
・携帯Java端末
・携帯電話
ちょっと前までは,携帯端末が今後の主流になると思っていた.
しかし今では,これからは,携帯端末でなく,携帯電話が主流になって,
携帯電話でなんでもできる,というような方向に進んで行くのだろうとおもう.
というのは,携帯電話はやはり「電話」という,実用的で馴染みやすい機能が
メインであるからだ.
「GPS標準搭載の携帯端末」があったとしてもGPSをやるためにわざわざ
携帯端末を買って,操作をおぼえようとする人は少ないだろう.
しかし「GPSつき携帯電話」ならば携帯電話が欲しい人で物珍しさで
買ってしまいそうな人が出てくるような気はする.
きっとそのうち,携帯電話に Java や Linux が搭載され,美術館に行ったら
自分の携帯電話に案内が自動的にインストールされて,自分の携帯電話が
案内してくれる,というようになるのだろう.
携帯電話のメモリサイズや処理能力はどんどん進化しているから,いまパソコンで
できるようなことは,ぜんぶ携帯電話でできるようになってしまう.
そのうち映画とかも見れるようになって電車の中の10分くらいの中途半端な
自由時間に,ちょっと映画をみたり,ロールプレイングゲームの続きをしたり,
電子ペットにえさをあげたりするようになるのだろう.
携帯電話のいいところは,小さくて電車の中とかでいじっていても違和感は無いが,
多彩の機能を盛り込める程度には大きい,というところだ.
たとえばGPSつきのごつくてでかい腕時計が出てもそれをいつもつけようとする
人はいないだろう.
また,「違和感が無い」というのはとても重要だ.
ぼくのようにところかまわず人目も気にせず,いつどんなところでもプログラムを
書き出してしまうような人間はともかく,普通の人は,やはり人目は気になる
(のだと思う)からだ.
このファイルはここまで.

225
README Normal file
View File

@ -0,0 +1,225 @@
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 アプリケーションとしてコンパイルする
ための,ライブラリです.以下の特徴があります.
・C言語レベルで互換機能を持っているのでWonderWitch 用のプログラムを
UNIX上でそのままコンパイルできる(-lwonx でコンパイルする)
・UNIX上でデバッガを使用してデバッグできるようになる(強力!)
・キャラクタデータやパレットデータのダンプ機能をつける予定.
・不正な引数の値や,パレットやキャラクタを初期化しないで使用するなどを
厳しくチェックし,エラーを出力する(ようにする).厳しくエラーチェックする.
・使用できない機能(関数は用意してあるが,まだ実装してなかったり,
実装が困難だったりして,中身が空のもの)はたくさんある.
徐々に追加していくつもり.
・ゲームの画面写真が簡単に撮れる.(デジカメで撮ったり,画像取り込み用の
プログラムを使ったりする必要が無くなる) これはわりとべんり.
・エミュレータでなくライブラリであり,ソースコード公開しているので,
自由にカスタマイズが可能.
・描画速度は遅いが,デバッグ目的のためなので,速度を速くすることは
あまり考えていない.(それよりも上記のデバッグ性を優先する)
・WonderWitch 用のプログラムをX上で楽しむためのものではない
あくまでデバッグ目的のもの.(そういうポリシーで開発を進める)
■ 足りないもの
以下のものにはまだ対応してません.したがって,例えばサウンド関連の
関数を呼び出しても,何も起こりません.(空の関数になっている)
・文字表示関連 (ターミナルにそのまま出力する)
とくに,文字だけでタイトル画面を書いてるゲームの場合などは,
なにも表示されないことになってしまうので注意してください.
(正常に動作していても,画面が真っ白で固まっているように見えてしまう)
・画面周りの細かいところ(ウインドウ機能など)
・サウンド
・シリアルポート
・割り込み処理関連
割り込みを使用している場合は注意してください.そのままではまともに
動かないでしょう.
そのうちシグナル使ってなんとかサポートしたいと思います.
■ Wonx概要
Wonx はWonderWitch の display_control() とか display_status() といった
関数(システムコール)と互換の関数を持っています.
これらの関数はX上にウインドウを開いてそこで WonderWitch と互換の動作を
するように書いてあります.
Wonx を make するとlibwonx.a というライブラリができます.
WonderWitch 用のプログラムをUNIX 上で -lwonx してコンパイルしてやれば,
WonderWitch の display_control() とかのかわりにWonx の display_control() が
リンクされX 上で動作するようになる,という仕組みです.
■ インストール
インストールするには,以下のことを行う必要があります.
・Wonx のコンパイルにはWonderWitch 付属のヘッダファイル(sys/disp.h とか)が
必要なので,それらをコピーします.
・Wonx をコンパイルします.→ libwonx.a ができあがります.
・ヘッダファイル(sys/disp.h とか)と libwonx.a を,適切なディレクトリに
置きます.
(アプリケーションのコンパイルにはWonderWitch 付属のヘッダファイルが必要)
インストールは,以下の手順で行います.
1. Wonx を展開する.
~>% tar xvzf wonx.tar.gz
~>% cd wonx
~/wonx>%
2. WonderWitch 付属のヘッダファイルをコピーする.
~/wonx>% mkdir sys
~/wonx>% cp ~/WWitch/include/bank.h sys
~/wonx>% cp ~/WWitch/include/comm.h sys
~/wonx>% cp ~/WWitch/include/disp.h sys
~/wonx>% cp ~/WWitch/include/key.h sys
~/wonx>% cp ~/WWitch/include/sound.h sys
~/wonx>% cp ~/WWitch/include/system.h sys
~/wonx>% cp ~/WWitch/include/text.h sys
~/wonx>% cp ~/WWitch/include/timer.h sys
~/wonx>% cp ~/WWitch/include/types.h sys
3. 以下の内容のファイル(sys/service.h)を作成する.
~/wonx>% emacs sys/service.h
==== ここから ====
#ifndef _service_h_INCLUDED_
#define _service_h_INCLUDED_
#define far /* None */
#define near /* None */
#endif
==== ここまで ====
sys/service.h はdisp.h などの中から,
#include <sys/service.h>
のようにしてインクルードされますが,コンパイル時には -I. でコンパイル
されるのでばあいによってはsys/sys/service.h にする必要があるかも
しれません.(未確認)
4. Wonx を make する.
~/wonx>% make
gcc -c WWCharacter.c -O -I. -I/usr/X11R6/include
gcc -c WWColorMap.c -O -I. -I/usr/X11R6/include
...(中略)...
gcc -c wonx.c -O -I. -I/usr/X11R6/include
ar ruc libwonx.a WWCharacter.o WWColorMap.o WWDisplay.o WWLCDPanel.o WWPalette.o WWScreen.o WWSprite.o WonxDisplay.o XDisplay.o disp.o text.o key.o system.o timer.o etc.o wonx.o
~/wonx>% ls lib*
libwonx.a
~/wonx>%
ここまでで,ライブラリとヘッダファイルの作成は終りです.
■ WonderWitch 用アプリケーションのコンパイル
拙作の SpeedMac をコンパイルしてみます.
1. 展開する.
~/wonx>% cd
~>% unzip xvzf smac-b02.zip
...(中略)...
~>% cd smac-b02
~/smac-b02>%
2. ヘッダファイルと libwonx.a をコピーする.
~/smac-b02>% mkdir sys
~/smac-b02>% cp ~/wonx/sys/* ./sys
~/smac-b02>% cp ~/wonx/libwonx.a .
~/smac-b02>%
3. Makefile を修正する.
~/smac-b02>% emacs Makefile
以下のように修正します.
・gcc でコンパイルをするように修正する.このときに,コンパイルオプションに,
-I. -I/usr/X11R6/include -L. -L/usr/X11R6/lib -lwonx -lX11 -lXt
を追加する.
(必要なら,-g も追加する)
・mkfent によるファイルのコンバートなどがあったら,削除する.
4. make する.
~/smac-b02>% make
gcc -c chara.c -g -I.
gcc -c game.c -g -I.
...(中略)...
gcc -c main.c -g -I.
gcc -g -o smac chara.o game.o man.o mansub.o mansub2.o map.o mapsub.o menu.o monster.o picture.o player.o smac.o stage.o dsp.o etc.o main.o -lwonx -lX11 -lXt -L. -L/usr/X11R6/lib
~/smac-b02>% ls smac
smac
~/smac-b02>%
5. smac を起動する.
~/smac-b02>% ./smac
■ 操作
smac を起動すると,ウインドウが開きます.また,ターミナルには,
以下のデバッグ用の情報が表示されます.
・WonderWitch の互換関数が呼ばれると,引数と戻り値を表示します.
またここでは,以下の操作が行えます.
・カーソルキーがWonderSwan のX1X4ボタンに対応している
・i,j,k,l キーがWonderSwan のY1Y4ボタンに対応している
・スペースバーと左シフトキーがA,Bボタンに対応している
・sキーがSTARTボタンに対応している
・p を押すと,表示/非表示モードを切替える.
(非表示だと画面への描画を行わないが高速)
標準ではなにか関数が呼ばれるたびに画面の再描画を行うため,非常に低速です.
このような場合は,非表示モードにしてください.
■ 作者
Wonx は,坂井弘亮が通勤電車の中で Libretto で書いた作品です.
GPLで配布します
坂井弘亮の連絡先のメールアドレスは,
sakai@seki.ee.kagu.sut.ac.jp
hsakai@pfu.co.jp
です.また,本ソフトウエアの最新版を,
http://www.seki.ee.kagu.sut.ac.jp/~sakai/WonderWitch/index.html
で配布しています.
■ このファイルはここまで

114
WWCharacter.c Normal file
View File

@ -0,0 +1,114 @@
/*****************************************************************************/
/* ここから */
/*****************************************************************************/
#include "WWCharacterP.h"
/*****************************************************************************/
/* メンバ関数の定義 */
/*****************************************************************************/
int WWCharacter_GetNumber(WWCharacter c)
{
if (c == NULL) Error("WWCharacter_GetNumber()", "WWCharacter is NULL.");
return (c->number);
}
int WWCharacter_SetNumber(WWCharacter c, int n)
{
if ((n < 0) || (n >= 512))
Error("WWCharacter_SetNumber()", "Invalid range.");
return (c->number = n);
}
WWCharacter WWCharacter_Create(int number, unsigned char * bitmap)
{
WWCharacter character;
character = (WWCharacter)malloc(sizeof(_WWCharacter));
if (character == NULL)
Error("WWCharacter_Create", "Cannot allocate memory.");
WWCharacter_SetNumber(character, number);
WWCharacter_SetBitmap(character, bitmap);
return (character);
}
WWCharacter WWCharacter_Destroy(WWCharacter character)
{
if (character == NULL)
Error("WWCharacter_Destroy()", "WWCharacter is NULL.");
free(character);
return (NULL);
}
int WWCharacter_SetBitmap(WWCharacter character, unsigned char * bitmap)
{
int i;
if (character == NULL)
Error("WWCharacter_SetBitmap()", "WWCharacter is NULL.");
for (i = 0; i < 16; i++) {
if (bitmap == NULL) {
character->bitmap[i] = 0x00;
} else {
character->bitmap[i] = bitmap[i];
}
}
return (0);
}
#include <stdio.h>
int WWCharacter_GetPixel(WWCharacter character, int x, int y)
{
if (character == NULL)
Error("WWCharacter_GetPixel()", "WWCharacter is NULL.");
if ((x < 0) || (x > 7))
Error("WWCharacter_GetPixel()", "x is invalid value.");
if ((y < 0) || (y > 7))
Error("WWCharacter_GetPixel()", "y is invalid value.");
/* ビットマップは2ビットでぴとつのピクセルに対応する */
/* 2ビットの値がpalette の色に対応する. */
/* bitmap は unsigned char bitmap[16]; に定義してある. */
/* パレット色(03)を返す */
return ( (character->bitmap[y * 2 + x / 4] >> ((x % 4) * 2)) & 0x03 );
}
int WWCharacter_SetPixel(WWCharacter character, int x, int y, int pixel)
{
unsigned char p;
if (character == NULL)
Error("WWCharacter_SetPixel()", "WWCharacter is NULL.");
if ((x < 0) || (x > 7))
Error("WWCharacter_SetPixel()", "x is invalid value.");
if ((y < 0) || (y > 7))
Error("WWCharacter_SetPixel()", "y is invalid value.");
if ((pixel < 0) || (pixel > 3))
Error("WWCharacter_SetPixel()", "Invalid pixel.");
p = ((unsigned char)pixel) & 0x03;
p = p << ((x % 4) * 2);
character->bitmap[y * 2 + x / 4] &= ~(0x03 << ((x % 4) * 2));
character->bitmap[y * 2 + x / 4] |= p;
return (pixel);
}
/*****************************************************************************/
/* ここまで */
/*****************************************************************************/
/*****************************************************************************/
/* End of File. */
/*****************************************************************************/

36
WWCharacter.h Normal file
View File

@ -0,0 +1,36 @@
#ifndef _WWCharacter_h_INCLUDED_
#define _WWCharacter_h_INCLUDED_
/*****************************************************************************/
/* ここから */
/*****************************************************************************/
#include <stdlib.h>
/*****************************************************************************/
/* クラスの定義 */
/*****************************************************************************/
typedef struct _WWCharacter * WWCharacter;
/*****************************************************************************/
/* メンバ関数の宣言 */
/*****************************************************************************/
int WWCharacter_GetNumber(WWCharacter c);
int WWCharacter_SetNumber(WWCharacter c, int n);
WWCharacter WWCharacter_Create(int number, unsigned char * bitmap);
WWCharacter WWCharacter_Destroy(WWCharacter character);
int WWCharacter_SetBitmap(WWCharacter character, unsigned char * bitmap);
int WWCharacter_GetPixel(WWCharacter character, int x, int y);
int WWCharacter_SetPixel(WWCharacter character, int x, int y, int pixel);
/*****************************************************************************/
/* ここまで */
/*****************************************************************************/
#endif
/*****************************************************************************/
/* End of File. */
/*****************************************************************************/

30
WWCharacterP.h Normal file
View File

@ -0,0 +1,30 @@
#ifndef _WWCharacterP_h_INCLUDED_
#define _WWCharacterP_h_INCLUDED_
/*****************************************************************************/
/* ここから */
/*****************************************************************************/
#include "WWCharacter.h"
/*****************************************************************************/
/* クラスの定義 */
/*****************************************************************************/
typedef struct _WWCharacter {
int number;
/* ビットマップは2ビットでぴとつのピクセルに対応する */
/* 2ビットの値がpalette の色に対応する. */
unsigned char bitmap[16];
} _WWCharacter;
/*****************************************************************************/
/* ここまで */
/*****************************************************************************/
#endif
/*****************************************************************************/
/* End of File. */
/*****************************************************************************/

72
WWColorMap.c Normal file
View File

@ -0,0 +1,72 @@
/*****************************************************************************/
/* ここから */
/*****************************************************************************/
#include "WWColorMapP.h"
/*****************************************************************************/
/* メンバ関数の定義 */
/*****************************************************************************/
WWColorMap WWColorMap_Create(int * lcd_colors)
{
WWColorMap color_map;
color_map = (WWColorMap)malloc(sizeof(_WWColorMap));
if (color_map == NULL) Error("WWColorMap_Create", "Cannot allocate memory");
WWColorMap_SetLCDColors(color_map, lcd_colors);
return (color_map);
}
WWColorMap WWColorMap_Destroy(WWColorMap color_map)
{
if (color_map == NULL) return (NULL);
free(color_map);
return (NULL);
}
int * WWColorMap_GetLCDColors(WWColorMap color_map, int * lcd_colors)
{
int i;
for (i = 0; i < 8; i++) {
lcd_colors[i] = WWColorMap_GetLCDColor(color_map, i);
}
return (lcd_colors);
}
int WWColorMap_SetLCDColors(WWColorMap color_map, int * lcd_colors)
{
int i;
for (i = 0; i < 8; i++) {
if (lcd_colors == NULL) {
WWColorMap_SetLCDColor(color_map, i, (i * 2) + ((i == 7) ? 1 : 0));
} else {
WWColorMap_SetLCDColor(color_map, i, lcd_colors[i]);
}
}
return (0);
}
int WWColorMap_GetLCDColor(WWColorMap color_map, int color)
{
return (color_map->lcd_color[color]);
}
int WWColorMap_SetLCDColor(WWColorMap color_map, int color, int lcd_color)
{
return (color_map->lcd_color[color] = lcd_color);
}
/*****************************************************************************/
/* ここまで */
/*****************************************************************************/
/*****************************************************************************/
/* End of File. */
/*****************************************************************************/

35
WWColorMap.h Normal file
View File

@ -0,0 +1,35 @@
#ifndef _WWColorMap_h_INCLUDED_
#define _WWColorMap_h_INCLUDED_
/*****************************************************************************/
/* ここから */
/*****************************************************************************/
#include <stdlib.h>
/*****************************************************************************/
/* クラスの定義 */
/*****************************************************************************/
typedef struct _WWColorMap * WWColorMap;
/*****************************************************************************/
/* メンバ関数の宣言 */
/*****************************************************************************/
WWColorMap WWColorMap_Create(int * lcd_colors);
WWColorMap WWColorMap_Destroy(WWColorMap color_map);
int * WWColorMap_GetLCDColors(WWColorMap color_map, int * lcd_colors);
int WWColorMap_SetLCDColors(WWColorMap color_map, int * lcd_colors);
int WWColorMap_GetLCDColor(WWColorMap color_map, int color);
int WWColorMap_SetLCDColor(WWColorMap color_map, int color, int lcd_color);
/*****************************************************************************/
/* ここまで */
/*****************************************************************************/
#endif
/*****************************************************************************/
/* End of File. */
/*****************************************************************************/

26
WWColorMapP.h Normal file
View File

@ -0,0 +1,26 @@
#ifndef _WWColorMapP_h_INCLUDED_
#define _WWColorMapP_h_INCLUDED_
/*****************************************************************************/
/* ここから */
/*****************************************************************************/
#include "WWColorMap.h"
/*****************************************************************************/
/* クラスの定義 */
/*****************************************************************************/
typedef struct _WWColorMap {
int lcd_color[8]; /* 16色中8色を選択 */
} _WWColorMap;
/*****************************************************************************/
/* ここまで */
/*****************************************************************************/
#endif
/*****************************************************************************/
/* End of File. */
/*****************************************************************************/

304
WWDisplay.c Normal file
View File

@ -0,0 +1,304 @@
/*****************************************************************************/
/* ここから */
/*****************************************************************************/
#include "WWDisplayP.h"
/*****************************************************************************/
/* メンバ関数の定義 */
/*****************************************************************************/
/*===========================================================================*/
/* メンバの取得 */
/*===========================================================================*/
WWColorMap WWDisplay_GetColorMap(WWDisplay d) { return (d->color_map); }
WWPalette WWDisplay_GetPalette(WWDisplay d, int n) { return (d->palette[n]); }
WWCharacter WWDisplay_GetCharacter(WWDisplay d, int n)
{ return (d->character[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); }
int WWDisplay_GetScreenEnable(WWDisplay d, int n)
{ return (d->screen_enable[n]); }
int WWDisplay_GetSpriteEnable(WWDisplay d) { return (d->sprite_enable); }
int WWDisplay_GetSpriteWindowEnable(WWDisplay d)
{ return (d->sprite_window_enable); }
int WWDisplay_GetScreen2WindowMode(WWDisplay d)
{ return (d->screen2_window_mode); }
int WWDisplay_GetBorder(WWDisplay d) { return (d->border); }
int WWDisplay_GetForegroundColor(WWDisplay d) { return (d->foreground_color); }
int WWDisplay_GetBackgroundColor(WWDisplay d) { return (d->background_color); }
int WWDisplay_GetSpriteStart(WWDisplay d) { return (d->sprite_start); }
int WWDisplay_GetSpriteCount(WWDisplay d) { return (d->sprite_count); }
/*===========================================================================*/
/* メンバの設定 */
/*===========================================================================*/
WWColorMap WWDisplay_SetColorMap(WWDisplay d, WWColorMap cm)
{ return (d->color_map = cm); }
WWPalette WWDisplay_SetPalette(WWDisplay d, int n, WWPalette p)
{ return (d->palette[n] = p); }
WWCharacter WWDisplay_SetCharacter(WWDisplay d, int n, WWCharacter c)
{ return (d->character[n] = c); }
WWSprite WWDisplay_SetSprite(WWDisplay d, int n, WWSprite s)
{ return (d->sprite[n] = s); }
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); }
int WWDisplay_SetScreenEnable(WWDisplay d, int n, int f)
{ return (d->screen_enable[n] = f); }
int WWDisplay_SetSpriteEnable(WWDisplay d, int f)
{ return (d->sprite_enable = f); }
int WWDisplay_SetSpriteWindowEnable(WWDisplay d, int f)
{ return (d->sprite_window_enable = f); }
int WWDisplay_SetScreen2WindowMode(WWDisplay d, int mode)
{ return (d->screen2_window_mode = mode); }
int WWDisplay_SetBorder(WWDisplay d, int b) { return (d->border = b); }
int WWDisplay_SetForegroundColor(WWDisplay d, int c)
{ return (d->foreground_color = c); }
int WWDisplay_SetBackgroundColor(WWDisplay d, int c)
{ return (d->background_color = c); }
int WWDisplay_SetSpriteStart(WWDisplay d, int n)
{ return (d->sprite_start = n); }
int WWDisplay_SetSpriteCount(WWDisplay d, int n)
{ return (d->sprite_count = n); }
/*===========================================================================*/
/* オブジェクトの生成と消去 */
/*===========================================================================*/
WWDisplay WWDisplay_Create(int lcd_panel_width, int lcd_panel_height,
int screen_width, int screen_height)
{
WWDisplay display;
int i;
display = (WWDisplay)malloc(sizeof(_WWDisplay));
if (display == NULL) Error("WWDisplay_Create", "Cannot allocate memory.");
WWDisplay_SetColorMap(display, WWColorMap_Create(NULL));
for (i = 0; i < 16; i++) {
WWDisplay_SetPalette(display, i,
WWPalette_Create(i, NULL, ((i / 4) % 2) ? 1 : 0));
}
for (i = 0; i < 512; i++) {
WWDisplay_SetCharacter(display, i, WWCharacter_Create(i, NULL));
}
for (i = 0; i < 128; i++) {
WWDisplay_SetSprite(display, i,
WWSprite_Create(i, 0, 0, 0, 0, 0, 0,
WWDisplay_GetPalette(display, 0),
WWDisplay_GetCharacter(display, 0)));
}
for (i = 0; i < 2; i++) {
WWDisplay_SetScreen(display, i,
WWScreen_Create(i, screen_width, screen_height,
WWDisplay_GetPalette(display, 0),
WWDisplay_GetCharacter(display, 0)));
}
WWDisplay_SetLCDPanel(display, WWLCDPanel_Create(lcd_panel_width,
lcd_panel_height));
WWDisplay_SetScreenEnable(display, 0, 0);
WWDisplay_SetScreenEnable(display, 1, 0);
WWDisplay_SetSpriteEnable(display, 0);
WWDisplay_SetSpriteWindowEnable(display, 0);
WWDisplay_SetScreen2WindowMode(display, 0);
WWDisplay_SetBorder(display, 0);
WWDisplay_SetForegroundColor(display, 3);
WWDisplay_SetBackgroundColor(display, 0);
WWDisplay_SetSpriteStart(display, 0);
WWDisplay_SetSpriteCount(display, 0);
return (display);
}
WWDisplay WWDisplay_Destroy(WWDisplay display)
{
int i;
if (display == NULL) return (NULL);
if (WWDisplay_GetColorMap(display) != NULL)
WWDisplay_SetColorMap(display,
WWColorMap_Destroy(WWDisplay_GetColorMap(display)));
for (i = 0; i < 16; i++) {
if (WWDisplay_GetPalette(display, i) != NULL)
WWDisplay_SetPalette(display, i,
WWPalette_Destroy(WWDisplay_GetPalette(display, i))
);
}
for (i = 0; i < 512; i++) {
if (WWDisplay_GetCharacter(display, i) != NULL)
WWDisplay_SetCharacter(display, i,
WWCharacter_Destroy(WWDisplay_GetCharacter(display
, i)));
}
for (i = 0; i < 128; i++) {
if (WWDisplay_GetSprite(display, i) != NULL)
WWDisplay_SetSprite(display, i,
WWSprite_Destroy(WWDisplay_GetSprite(display, i)));
}
for (i = 0; i < 2; i++) {
if (WWDisplay_GetScreen(display, i) != NULL)
WWDisplay_SetScreen(display, i,
WWScreen_Destroy(WWDisplay_GetScreen(display, i)));
}
if (WWDisplay_GetLCDPanel(display) != NULL)
WWDisplay_SetLCDPanel(display,
WWLCDPanel_Destroy(WWDisplay_GetLCDPanel(display)));
free(display);
return (NULL);
}
/*===========================================================================*/
/* LCDパネルの描画 */
/*===========================================================================*/
static int WWDisplay_DrawScreen(WWDisplay display, WWScreen screen)
{
WWLCDPanel lcd_panel;
int lcd_panel_width;
int lcd_panel_height;
int pixel;
int x, y, px, py;
lcd_panel = WWDisplay_GetLCDPanel(display);
lcd_panel_width = WWLCDPanel_GetWidth( lcd_panel);
lcd_panel_height = WWLCDPanel_GetHeight(lcd_panel);
for (y = 0; y < lcd_panel_height; y++) {
for (x = 0; x < lcd_panel_width; x++) {
px = x + WWScreen_GetRollX(screen);
py = y + WWScreen_GetRollY(screen);
pixel = WWScreen_GetPixel(screen, px, py);
/* 透明色の場合 */
if (pixel == -1) continue;
pixel = WWColorMap_GetLCDColor(WWDisplay_GetColorMap(display), pixel);
WWLCDPanel_SetPixel(lcd_panel, x, y, pixel);
}
}
return (0);
}
static int WWDisplay_DrawSprite(WWDisplay display, WWSprite sprite)
{
int x, y;
int pixel;
for (y = 0; y < 8; y++) {
for (x = 0; x < 8; x++) {
pixel = WWSprite_GetPixel(sprite, x, y);
/* 透明色の場合 */
if (pixel == -1) continue;
pixel = WWColorMap_GetLCDColor(WWDisplay_GetColorMap(display), pixel);
WWLCDPanel_SetPixel(WWDisplay_GetLCDPanel(display),
WWSprite_GetX(sprite) + x,
WWSprite_GetY(sprite) + y,
pixel);
}
}
return (0);
}
int WWDisplay_DrawLCDPanel(WWDisplay display)
{
WWLCDPanel lcd_panel;
WWScreen screen;
int x, y, i;
int lcd_panel_width;
int lcd_panel_height;
WWColorMap color_map;
int border;
WWSprite sprite;
lcd_panel = WWDisplay_GetLCDPanel(display);
lcd_panel_width = WWLCDPanel_GetWidth(lcd_panel);
lcd_panel_height = WWLCDPanel_GetHeight(lcd_panel);
color_map = WWDisplay_GetColorMap(display);
border = WWDisplay_GetBorder(display);
/* ボーダーカラーで埋める */
for (x = 0; x < lcd_panel_width; x++) {
for (y = 0; y < lcd_panel_height; y++) {
WWLCDPanel_SetPixel(lcd_panel, x, y,
WWColorMap_GetLCDColor(color_map, border));
}
}
/* スクリーン1描画 */
WWDisplay_DrawScreen(display, WWDisplay_GetScreen(display, 0));
/* スプライト描画(スクリーン2より優先でないもの) */
for (i = 0; i < WWDisplay_GetSpriteCount(display); i++) {
sprite = WWDisplay_GetSprite(display,
i + WWDisplay_GetSpriteStart(display));
if (!WWSprite_GetPriority(sprite)) {
WWDisplay_DrawSprite(display, sprite);
}
}
/* スクリーン2描画 */
WWDisplay_DrawScreen(display, WWDisplay_GetScreen(display, 1));
/* スプライト描画(スクリーン2より優先なもの) */
for (i = 0; i < WWDisplay_GetSpriteCount(display); i++) {
sprite = WWDisplay_GetSprite(display,
i + WWDisplay_GetSpriteStart(display));
if (WWSprite_GetPriority(sprite)) {
WWDisplay_DrawSprite(display, sprite);
}
}
/*
for (x = 0; x < lcd_panel_width; x++) {
for (y = 0; y < lcd_panel_height; y++) {
printf("%d", WWLCDPanel_GetPixel(lcd_panel, x, y));
}
}
*/
return (0);
}
/*****************************************************************************/
/* ここまで */
/*****************************************************************************/
/*****************************************************************************/
/* End of File. */
/*****************************************************************************/

94
WWDisplay.h Normal file
View File

@ -0,0 +1,94 @@
#ifndef _WWDisplay_h_INCLUDED_
#define _WWDisplay_h_INCLUDED_
/*****************************************************************************/
/* ここから */
/*****************************************************************************/
#include "WWColorMap.h"
#include "WWPalette.h"
#include "WWCharacter.h"
#include "WWSprite.h"
#include "WWScreen.h"
#include "WWLCDPanel.h"
/*****************************************************************************/
/* クラスの定義 */
/*****************************************************************************/
typedef struct _WWDisplay * WWDisplay;
/*****************************************************************************/
/* メンバ関数の定義 */
/*****************************************************************************/
/*===========================================================================*/
/* メンバの取得 */
/*===========================================================================*/
WWColorMap WWDisplay_GetColorMap(WWDisplay d);
WWPalette WWDisplay_GetPalette(WWDisplay d, int n);
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);
int WWDisplay_GetScreenEnable(WWDisplay d, int n);
int WWDisplay_GetSpriteEnable(WWDisplay d);
int WWDisplay_GetSpriteWindowEnable(WWDisplay d);
int WWDisplay_GetScreen2WindowMode(WWDisplay d);
int WWDisplay_GetBorder(WWDisplay d);
int WWDisplay_GetForegroundColor(WWDisplay d);
int WWDisplay_GetBackgroundColor(WWDisplay d);
int WWDisplay_GetSpriteStart(WWDisplay d);
int WWDisplay_GetSpriteCount(WWDisplay d);
/*===========================================================================*/
/* メンバの設定 */
/*===========================================================================*/
WWColorMap WWDisplay_SetColorMap(WWDisplay d, WWColorMap cm);
WWPalette WWDisplay_SetPalette(WWDisplay d, int n, WWPalette p);
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);
int WWDisplay_SetScreenEnable(WWDisplay d, int n, int f);
int WWDisplay_SetSpriteEnable(WWDisplay d, int f);
int WWDisplay_SetSpriteWindowEnable(WWDisplay d, int f);
int WWDisplay_SetScreen2WindowMode(WWDisplay d, int mode);
int WWDisplay_SetBorder(WWDisplay d, int b);
int WWDisplay_SetForegroundColor(WWDisplay d, int c);
int WWDisplay_SetBackgroundColor(WWDisplay d, int c);
int WWDisplay_SetSpriteStart(WWDisplay d, int n);
int WWDisplay_SetSpriteCount(WWDisplay d, int n);
/*===========================================================================*/
/* オブジェクトの生成と消去 */
/*===========================================================================*/
WWDisplay WWDisplay_Create(int lcd_panel_width, int lcd_panel_height,
int screen_width, int screen_height);
WWDisplay WWDisplay_Destroy(WWDisplay display);
/*===========================================================================*/
/* LCDパネルの描画 */
/*===========================================================================*/
int WWDisplay_DrawLCDPanel(WWDisplay display);
/*****************************************************************************/
/* ここまで */
/*****************************************************************************/
#endif
/*****************************************************************************/
/* End of File. */
/*****************************************************************************/

50
WWDisplayP.h Normal file
View File

@ -0,0 +1,50 @@
#ifndef _WWDisplayP_h_INCLUDED_
#define _WWDisplayP_h_INCLUDED_
/*****************************************************************************/
/* ここから */
/*****************************************************************************/
#include "WWDisplay.h"
/*****************************************************************************/
/* クラスの定義 */
/*****************************************************************************/
typedef struct _WWDisplay {
WWColorMap color_map;
WWPalette palette[16];
WWCharacter character[512];
WWSprite sprite[128];
WWScreen screen[2];
WWLCDPanel lcd_panel;
/* ディスプレイの属性情報 */
int screen_enable[2]; /* スクリーン表示イネーブルフラグ */
int sprite_enable; /* スプライト表示イネーブルフラグ */
int sprite_window_enable; /* スプライトウインドウ機能イネーブルフラグ */
/* スクリーン2ウインドウモード */
/* 0,1... 無効 2...ウインドウの内側を表示 3...ウインドウの外側を表示 */
int screen2_window_mode;
int border; /* ボーダーカラー07のカラーマップ番号 */
int foreground_color; /* モノクロフォント展開時の色 */
int background_color; /* モノクロフォント展開時の色 */
int sprite_start; /* スプライトの描画の指定 */
int sprite_count; /* スプライトの描画の指定 */
} _WWDisplay;
/*****************************************************************************/
/* ここまで */
/*****************************************************************************/
#endif
/*****************************************************************************/
/* End of File. */
/*****************************************************************************/

92
WWLCDPanel.c Normal file
View File

@ -0,0 +1,92 @@
/*****************************************************************************/
/* ここから */
/*****************************************************************************/
#include "WWLCDPanelP.h"
/*****************************************************************************/
/* メンバ関数の定義 */
/*****************************************************************************/
int WWLCDPanel_GetWidth( WWLCDPanel p) { return (p->width ); }
int WWLCDPanel_GetHeight(WWLCDPanel p) { return (p->height); }
int WWLCDPanel_SetWidth( WWLCDPanel p, int n) { return (p->width = n); }
int WWLCDPanel_SetHeight(WWLCDPanel p, int n) { return (p->height = n); }
unsigned char * WWLCDPanel_GetPixelMap(WWLCDPanel p) { return (p->pixel); }
/* LCDはピクセル16色(4ビット必要) */
int WWLCDPanel_GetPixel(WWLCDPanel lcd_panel, int x, int y)
{
unsigned char pixel;
if ( (x < 0) || (x > WWLCDPanel_GetWidth(lcd_panel) - 1) ||
(y < 0) || (y > WWLCDPanel_GetHeight(lcd_panel) - 1) )
return (-1);
pixel = lcd_panel->pixel[y * (WWLCDPanel_GetWidth(lcd_panel) / 2) + x / 2];
if (x % 2) pixel = pixel >> 4;
pixel &= 0x0f;
return ((int)pixel);
}
int WWLCDPanel_SetPixel(WWLCDPanel lcd_panel, int x, int y, int pixel)
{
unsigned char p;
int n;
if ( (x < 0) || (x > WWLCDPanel_GetWidth(lcd_panel) - 1) ||
(y < 0) || (y > WWLCDPanel_GetHeight(lcd_panel) - 1) )
return (-1);
p = 0x0f;
if (x % 2) p = p << 4;
n = y * (WWLCDPanel_GetWidth(lcd_panel) / 2) + x / 2;
lcd_panel->pixel[n] &= ~p;
p = ((unsigned char)pixel) & 0x0f;
if (x % 2) p = p << 4;
lcd_panel->pixel[n] |= p;
return (pixel);
}
WWLCDPanel WWLCDPanel_Create(int width, int height)
{
WWLCDPanel lcd_panel;
int x, y;
lcd_panel = (WWLCDPanel)malloc(sizeof(_WWLCDPanel));
if (lcd_panel == NULL) Error("WWLCDPanel_Create", "Cannot allocate memory.");
WWLCDPanel_SetWidth( lcd_panel, width);
WWLCDPanel_SetHeight(lcd_panel, height);
lcd_panel->pixel =
(unsigned char *)malloc(sizeof(unsigned char) *
(WWLCDPanel_GetWidth(lcd_panel) / 2) *
WWLCDPanel_GetHeight(lcd_panel));
for (y = 0; y < lcd_panel->height; y++) {
for (x = 0; x < lcd_panel->width / 2; x++) {
WWLCDPanel_SetPixel(lcd_panel, x, y, 0x00);
}
}
return (lcd_panel);
}
WWLCDPanel WWLCDPanel_Destroy(WWLCDPanel lcd_panel)
{
if (lcd_panel == NULL) return (NULL);
if (lcd_panel->pixel) free(lcd_panel->pixel);
free(lcd_panel);
return (NULL);
}
/*****************************************************************************/
/* ここまで */
/*****************************************************************************/
/*****************************************************************************/
/* End of File. */
/*****************************************************************************/

38
WWLCDPanel.h Normal file
View File

@ -0,0 +1,38 @@
#ifndef _WWLCDPanel_h_INCLUDED_
#define _WWLCDPanel_h_INCLUDED_
/*****************************************************************************/
/* ここから */
/*****************************************************************************/
#include <stdlib.h>
/*****************************************************************************/
/* クラスの定義 */
/*****************************************************************************/
typedef struct _WWLCDPanel * WWLCDPanel;
/*****************************************************************************/
/* メンバ関数の宣言 */
/*****************************************************************************/
int WWLCDPanel_GetWidth( WWLCDPanel p);
int WWLCDPanel_GetHeight(WWLCDPanel p);
int WWLCDPanel_SetWidth( WWLCDPanel p, int n);
int WWLCDPanel_SetHeight(WWLCDPanel p, int n);
unsigned char * WWLCDPanel_GetPixelMap(WWLCDPanel p);
int WWLCDPanel_GetPixel(WWLCDPanel lcd_panel, int x, int y);
int WWLCDPanel_SetPixel(WWLCDPanel lcd_panel, int x, int y, int pixel);
WWLCDPanel WWLCDPanel_Create(int width, int height);
WWLCDPanel WWLCDPanel_Destroy(WWLCDPanel lcd_panel);
/*****************************************************************************/
/* ここまで */
/*****************************************************************************/
#endif
/*****************************************************************************/
/* End of File. */
/*****************************************************************************/

29
WWLCDPanelP.h Normal file
View File

@ -0,0 +1,29 @@
#ifndef _WWLCDPanelP_h_INCLUDED_
#define _WWLCDPanelP_h_INCLUDED_
/*****************************************************************************/
/* ここから */
/*****************************************************************************/
#include "WWLCDPanel.h"
/*****************************************************************************/
/* クラスの定義 */
/*****************************************************************************/
typedef struct _WWLCDPanel {
int width;
int height;
/* 16色のカラー情報バイトでピクセル分の情報を持つ */
unsigned char * pixel;
} _WWLCDPanel;
/*****************************************************************************/
/* ここまで */
/*****************************************************************************/
#endif
/*****************************************************************************/
/* End of File. */
/*****************************************************************************/

88
WWPalette.c Normal file
View File

@ -0,0 +1,88 @@
/*****************************************************************************/
/* ここから */
/*****************************************************************************/
#include "WWPaletteP.h"
/*****************************************************************************/
/* メンバ関数の定義 */
/*****************************************************************************/
int WWPalette_GetNumber(WWPalette p) { return (p->number); }
int WWPalette_SetNumber(WWPalette p, int n) { return (p->number = n); }
int WWPalette_GetTransparent(WWPalette p) { return (p->transparent); }
int WWPalette_SetTransparent(WWPalette p, int f)
{ return (p->transparent = f); }
WWPalette WWPalette_Create(int number, int * mapped_colors, int transparent)
{
WWPalette palette;
palette = (WWPalette)malloc(sizeof(_WWPalette));
if (palette == NULL) Error("WWPalette_Create", "Cannot allocate memory");
WWPalette_SetNumber(palette, number);
WWPalette_SetTransparent(palette, transparent);
WWPalette_SetMappedColors(palette, mapped_colors);
return (palette);
}
WWPalette WWPalette_Destroy(WWPalette palette)
{
if (palette == NULL) return (NULL);
free(palette);
return (NULL);
}
int * WWPalette_GetMappedColors(WWPalette palette, int * mapped_colors)
{
int i;
for (i = 0; i < 4; i++) {
mapped_colors[i] = WWPalette_GetMappedColor(palette, i);
}
return (mapped_colors);
}
int WWPalette_SetMappedColors(WWPalette palette, int * mapped_colors)
{
int i;
for (i = 0; i < 4; i++) {
if (mapped_colors == NULL) {
WWPalette_SetMappedColor(palette, i, (i * 2) + ((i == 3) ? 1 : 0));
} else {
WWPalette_SetMappedColor(palette, i, mapped_colors[i]);
}
}
return (0);
}
int WWPalette_GetMappedColor(WWPalette palette, int color)
{
int pixel;
pixel = palette->mapped_color[color];
if (WWPalette_GetTransparent(palette) && (pixel == 0)) {
pixel = -1;
}
return (pixel);
}
int WWPalette_SetMappedColor(WWPalette palette, int color, int mapped_color)
{
if (mapped_color == -1) mapped_color = 0;
return (palette->mapped_color[color] = mapped_color);
}
/*****************************************************************************/
/* ここまで */
/*****************************************************************************/
/*****************************************************************************/
/* End of File. */
/*****************************************************************************/

39
WWPalette.h Normal file
View File

@ -0,0 +1,39 @@
#ifndef _WWPalette_h_INCLUDED_
#define _WWPalette_h_INCLUDED_
/*****************************************************************************/
/* ここから */
/*****************************************************************************/
#include <stdlib.h>
/*****************************************************************************/
/* クラスの定義 */
/*****************************************************************************/
typedef struct _WWPalette * WWPalette;
/*****************************************************************************/
/* メンバ関数の宣言 */
/*****************************************************************************/
int WWPalette_GetNumber(WWPalette p);
int WWPalette_SetNumber(WWPalette p, int n);
int WWPalette_GetTransparent(WWPalette palette);
int WWPalette_SetTransparent(WWPalette palette, int f);
WWPalette WWPalette_Create(int number, int * mapped_colors, int transparent);
WWPalette WWPalette_Destroy(WWPalette palette);
int * WWPalette_GetMappedColors(WWPalette palette, int * mapped_colors);
int WWPalette_SetMappedColors(WWPalette palette, int * mapped_colors);
int WWPalette_GetMappedColor(WWPalette palette, int color);
int WWPalette_SetMappedColor(WWPalette palette, int color, int mapped_color);
/*****************************************************************************/
/* ここまで */
/*****************************************************************************/
#endif
/*****************************************************************************/
/* End of File. */
/*****************************************************************************/

32
WWPaletteP.h Normal file
View File

@ -0,0 +1,32 @@
#ifndef _WWPaletteP_h_INCLUDED_
#define _WWPaletteP_h_INCLUDED_
/*****************************************************************************/
/* ここから */
/*****************************************************************************/
#include "WWPalette.h"
/*****************************************************************************/
/* クラスの定義 */
/*****************************************************************************/
typedef struct _WWPalette {
int number;
int transparent; /* 0 は透明色になるかどうかのフラグ */
/* カラーマップの8色中から4色を選択 */
int mapped_color[4]; /* カラーマップの番号(07)を持つ */
} _WWPalette;
/*****************************************************************************/
/* ここまで */
/*****************************************************************************/
#endif
/*****************************************************************************/
/* End of File. */
/*****************************************************************************/

194
WWScreen.c Normal file
View File

@ -0,0 +1,194 @@
/*****************************************************************************/
/* ここから */
/*****************************************************************************/
#include "WWScreenP.h"
/*****************************************************************************/
/* メンバ関数の定義 */
/*****************************************************************************/
/*===========================================================================*/
/* プライベートなもの */
/*===========================================================================*/
static int WWScreenCharacter_GetHorizontal(WWScreenCharacter sc)
{ return (sc->horizontal); }
static int WWScreenCharacter_GetVertical(WWScreenCharacter sc)
{ return (sc->vertical); }
static WWPalette WWScreenCharacter_GetPalette(WWScreenCharacter sc)
{ return (sc->palette); }
static WWCharacter WWScreenCharacter_GetCharacter(WWScreenCharacter sc)
{ return (sc->character); }
static int WWScreenCharacter_SetHorizontal(WWScreenCharacter sc, int f)
{ return (sc->horizontal = f); }
static int WWScreenCharacter_SetVertical(WWScreenCharacter sc, int f)
{ return (sc->vertical = f); }
static WWPalette WWScreenCharacter_SetPalette(WWScreenCharacter sc,
WWPalette palette)
{ return (sc->palette = palette); }
static WWCharacter WWScreenCharacter_SetCharacter(WWScreenCharacter sc,
WWCharacter c)
{ return (sc->character = c); }
static WWScreenCharacter WWScreenCharacter_Create(int horizontal, int vertical,
WWPalette palette,
WWCharacter character)
{
WWScreenCharacter screen_character;
screen_character = (WWScreenCharacter)malloc(sizeof(_WWScreenCharacter));
if (screen_character == NULL)
Error("WWScreenCharacter", "Cannot allocate memory.");
WWScreenCharacter_SetHorizontal(screen_character, horizontal);
WWScreenCharacter_SetVertical(screen_character, vertical);
WWScreenCharacter_SetPalette(screen_character, palette);
WWScreenCharacter_SetCharacter(screen_character, character);
return (screen_character);
}
static WWScreenCharacter WWScreenCharacter_Destroy(WWScreenCharacter
screen_character)
{
if (screen_character == NULL) return (NULL);
free(screen_character);
return (NULL);
}
static WWScreenCharacter WWScreen_GetScreenCharacter(WWScreen s, int x, int y)
{
return (s->screen_characters[y * WWScreen_GetWidth(s) + x]);
}
static WWScreenCharacter WWScreen_SetScreenCharacter(WWScreen s, int x, int y,
WWScreenCharacter sc)
{
return (s->screen_characters[y * WWScreen_GetWidth(s) + x] = sc);
}
/*===========================================================================*/
/* パブリックなもの */
/*===========================================================================*/
int WWScreen_GetNumber(WWScreen s) { return (s->number); }
int WWScreen_GetHorizontal(WWScreen s, int x, int y)
{ return (WWScreen_GetScreenCharacter(s, x, y)->horizontal); }
int WWScreen_GetVertical(WWScreen s, int x, int y)
{ return (WWScreen_GetScreenCharacter(s, x, y)->vertical); }
WWPalette WWScreen_GetPalette(WWScreen s, int x, int y)
{ return (WWScreen_GetScreenCharacter(s, x, y)->palette); }
WWCharacter WWScreen_GetCharacter(WWScreen s, int x, int y)
{ return (WWScreen_GetScreenCharacter(s, x, y)->character); }
int WWScreen_SetNumber(WWScreen s, int n) { return (s->number = n); }
int WWScreen_SetHorizontal(WWScreen s, int x, int y, int f)
{ return (WWScreen_GetScreenCharacter(s, x, y)->horizontal = f); }
int WWScreen_SetVertical(WWScreen s, int x, int y, int f)
{ return (WWScreen_GetScreenCharacter(s, x, y)->vertical = f); }
WWPalette WWScreen_SetPalette(WWScreen s, int x, int y, WWPalette palette)
{ return (WWScreen_GetScreenCharacter(s, x, y)->palette = palette); }
WWCharacter WWScreen_SetCharacter(WWScreen s, int x, int y, WWCharacter c)
{ return (WWScreen_GetScreenCharacter(s, x, y)->character = c); }
int WWScreen_GetWidth( WWScreen s) { return (s->width ); }
int WWScreen_GetHeight(WWScreen s) { return (s->height); }
int WWScreen_GetRollX( WWScreen s) { return (s->roll_x); }
int WWScreen_GetRollY( WWScreen s) { return (s->roll_y); }
int WWScreen_SetWidth( WWScreen s, int n) { return (s->width = n); }
int WWScreen_SetHeight(WWScreen s, int n) { return (s->height = n); }
int WWScreen_SetRollX( WWScreen s, int r) { return (s->roll_x = r); }
int WWScreen_SetRollY( WWScreen s, int r) { return (s->roll_y = r); }
/* カラーマップの色(07)を返す(透明色は-1を返す) */
int WWScreen_GetPixel(WWScreen screen, int x, int y)
{
int cx, cy, px, py;
int pixel;
WWCharacter character;
WWPalette palette;
/* x,y 座標が範囲外のときは,ロールオーバーする */
/* (スクリーンの端と端は,つながっている) */
while (x < 0) x += WWScreen_GetWidth( screen) * 8;
while (y < 0) y += WWScreen_GetHeight(screen) * 8;
x = x % (WWScreen_GetWidth( screen) * 8);
y = y % (WWScreen_GetHeight(screen) * 8);
cx = x / 8; cy = y / 8;
px = x % 8; py = y % 8;
if (WWScreen_GetHorizontal(screen, cx, cy)) px = 7 - px;
if (WWScreen_GetVertical( screen, cx, cy)) py = 7 - py;
character = WWScreen_GetCharacter(screen, cx, cy);
palette = WWScreen_GetPalette(screen, cx, cy);
pixel = WWCharacter_GetPixel(character, px, py);
pixel = WWPalette_GetMappedColor(palette, pixel);
return (pixel);
}
WWScreen WWScreen_Create(int number, int width, int height,
WWPalette initial_palette,
WWCharacter initial_character)
{
WWScreen screen;
WWScreenCharacter sc;
int x, y;
screen = (WWScreen)malloc(sizeof(_WWScreen));
if (screen == NULL) Error("WWScreen_Create", "Cannot allocate memory.");
WWScreen_SetNumber(screen, number);
WWScreen_SetWidth( screen, width);
WWScreen_SetHeight(screen, height);
WWScreen_SetRollX( screen, 0);
WWScreen_SetRollY( screen, 0);
screen->screen_characters =
(WWScreenCharacter *)malloc(sizeof(WWScreenCharacter) *
screen->width * screen->height);
for (y = 0; y < screen->height; y++) {
for (x = 0; x < screen->width; x++) {
sc = WWScreenCharacter_Create(0, 0, initial_palette, initial_character);
WWScreen_SetScreenCharacter(screen, x, y, sc);
}
}
return (screen);
}
WWScreen WWScreen_Destroy(WWScreen screen)
{
int x, y;
WWScreenCharacter sc;
if (screen == NULL) return (NULL);
for (y = 0; y < screen->height; y++) {
for (x = 0; x < screen->width; x++) {
sc = WWScreen_GetScreenCharacter(screen, x, y);
WWScreen_SetScreenCharacter(screen, x, y, WWScreenCharacter_Destroy(sc));
}
}
if (screen->screen_characters) free(screen->screen_characters);
free(screen);
return (NULL);
}
/*****************************************************************************/
/* ここまで */
/*****************************************************************************/
/*****************************************************************************/
/* End of File. */
/*****************************************************************************/

60
WWScreen.h Normal file
View File

@ -0,0 +1,60 @@
#ifndef _WWScreen_h_INCLUDED_
#define _WWScreen_h_INCLUDED_
/*****************************************************************************/
/* ここから */
/*****************************************************************************/
#include <stdlib.h>
#include "WWPalette.h"
#include "WWCharacter.h"
/*****************************************************************************/
/* クラスの定義 */
/*****************************************************************************/
typedef struct _WWScreen * WWScreen;
/*****************************************************************************/
/* メンバ関数の宣言 */
/*****************************************************************************/
int WWScreen_GetNumber(WWScreen s);
int WWScreen_GetHorizontal(WWScreen s, int x, int y);
int WWScreen_GetVertical(WWScreen s, int x, int y);
WWPalette WWScreen_GetPalette(WWScreen s, int x, int y);
WWCharacter WWScreen_GetCharacter(WWScreen s, int x, int y);
int WWScreen_SetNumber(WWScreen s, int n);
int WWScreen_SetHorizontal(WWScreen s, int x, int y, int f);
int WWScreen_SetVertical(WWScreen s, int x, int y, int f);
WWPalette WWScreen_SetPalette(WWScreen s, int x, int y, WWPalette palette);
WWCharacter WWScreen_SetCharacter(WWScreen s, int x, int y, WWCharacter c);
int WWScreen_GetWidth( WWScreen s);
int WWScreen_GetHeight(WWScreen s);
int WWScreen_GetRollX( WWScreen s);
int WWScreen_GetRollY( WWScreen s);
int WWScreen_SetWidth( WWScreen s, int n);
int WWScreen_SetHeight(WWScreen s, int n);
int WWScreen_SetRollX( WWScreen s, int r);
int WWScreen_SetRollY( WWScreen s, int r);
int WWScreen_GetPixel(WWScreen screen, int x, int y);
WWScreen WWScreen_Create(int number, int width, int height,
WWPalette initial_palette,
WWCharacter initial_character);
WWScreen WWScreen_Destroy(WWScreen screen);
/*****************************************************************************/
/* ここまで */
/*****************************************************************************/
#endif
/*****************************************************************************/
/* End of File. */
/*****************************************************************************/

41
WWScreenP.h Normal file
View File

@ -0,0 +1,41 @@
#ifndef _WWScreenP_h_INCLUDED_
#define _WWScreenP_h_INCLUDED_
/*****************************************************************************/
/* ここから */
/*****************************************************************************/
#include "WWScreen.h"
/*****************************************************************************/
/* クラスの定義 */
/*****************************************************************************/
/* スクリーンのマス目ごとに決まる,表示情報 */
typedef struct _WWScreenCharacter {
int horizontal; /* 横方向反転フラグ */
int vertical; /* 縦方向反転フラグ */
WWPalette palette; /* パレット番号015 のパレット番号 */
WWCharacter character; /* 表示キャラクタ */
} _WWScreenCharacter;
typedef struct _WWScreenCharacter * WWScreenCharacter;
typedef struct _WWScreen {
int number;
int width;
int height;
int roll_x;
int roll_y;
WWScreenCharacter * screen_characters;
} _WWScreen;
/*****************************************************************************/
/* ここまで */
/*****************************************************************************/
#endif
/*****************************************************************************/
/* End of File. */
/*****************************************************************************/

93
WWSprite.c Normal file
View File

@ -0,0 +1,93 @@
/*****************************************************************************/
/* ここから */
/*****************************************************************************/
#include "WWSpriteP.h"
/*****************************************************************************/
/* メンバ関数の定義 */
/*****************************************************************************/
int WWSprite_GetNumber( WWSprite s) { return (s->number); }
int WWSprite_GetHorizontal(WWSprite s) { return (s->horizontal); }
int WWSprite_GetVertical( WWSprite s) { return (s->vertical); }
int WWSprite_GetPriority( WWSprite s) { return (s->priority); }
int WWSprite_GetClipping( WWSprite s) { return (s->clipping); }
WWPalette WWSprite_GetPalette( WWSprite s) { return (s->palette); }
WWCharacter WWSprite_GetCharacter( WWSprite s) { return (s->character); }
int WWSprite_SetNumber( WWSprite s, int n) { return (s->number = n); }
int WWSprite_SetHorizontal(WWSprite s, int f) { return (s->horizontal = f); }
int WWSprite_SetVertical( WWSprite s, int f) { return (s->vertical = f); }
int WWSprite_SetPriority( WWSprite s, int f) { return (s->priority = f); }
int WWSprite_SetClipping( WWSprite s, int f) { return (s->clipping = f); }
WWPalette WWSprite_SetPalette(WWSprite s, WWPalette p)
{ return (s->palette = p); }
WWCharacter WWSprite_SetCharacter(WWSprite s, WWCharacter c)
{ return (s->character = c); }
int WWSprite_GetX(WWSprite sprite) { return (sprite->x); }
int WWSprite_GetY(WWSprite sprite) { return (sprite->y); }
int WWSprite_SetPosition(WWSprite sprite, int x, int y)
{
sprite->x = x;
sprite->y = y;
return (0);
}
int WWSprite_GetPixel(WWSprite sprite, int x, int y)
{
WWPalette p;
WWCharacter c;
int pixel;
p = WWSprite_GetPalette(sprite);
c = WWSprite_GetCharacter(sprite);
if (WWSprite_GetHorizontal(sprite)) x = 7 - x;
if (WWSprite_GetVertical( sprite)) y = 7 - y;
pixel = WWCharacter_GetPixel(c, x, y);
pixel = WWPalette_GetMappedColor(p, pixel);
return (pixel);
}
WWSprite WWSprite_Create(int number, int x, int y,
int horizontal, int vertical,
int priority, int clipping,
WWPalette palette, WWCharacter character)
{
WWSprite sprite;
sprite = (WWSprite)malloc(sizeof(_WWSprite));
if (sprite == NULL) Error("WWSprite_Create", "Cannot allocate memory.");
WWSprite_SetNumber(sprite, number);
WWSprite_SetHorizontal(sprite, horizontal);
WWSprite_SetVertical(sprite, vertical);
WWSprite_SetPriority(sprite, priority);
WWSprite_SetClipping(sprite, clipping);
WWSprite_SetPalette(sprite, palette);
WWSprite_SetCharacter(sprite, character);
WWSprite_SetPosition(sprite, x, y);
return (sprite);
}
WWSprite WWSprite_Destroy(WWSprite sprite)
{
if (sprite == NULL) return (NULL);
free(sprite);
return (NULL);
}
/*****************************************************************************/
/* ここまで */
/*****************************************************************************/
/*****************************************************************************/
/* End of File. */
/*****************************************************************************/

57
WWSprite.h Normal file
View File

@ -0,0 +1,57 @@
#ifndef _WWSprite_h_INCLUDED_
#define _WWSprite_h_INCLUDED_
/*****************************************************************************/
/* ここから */
/*****************************************************************************/
#include <stdlib.h>
#include "WWPalette.h"
#include "WWCharacter.h"
/*****************************************************************************/
/* クラスの定義 */
/*****************************************************************************/
typedef struct _WWSprite * WWSprite;
/*****************************************************************************/
/* メンバ関数の宣言 */
/*****************************************************************************/
int WWSprite_GetNumber(WWSprite s);
int WWSprite_GetHorizontal(WWSprite s);
int WWSprite_GetVertical(WWSprite s);
int WWSprite_GetPriority(WWSprite s);
int WWSprite_GetClipping(WWSprite s);
WWPalette WWSprite_GetPalette(WWSprite s);
WWCharacter WWSprite_GetCharacter(WWSprite s);
int WWSprite_SetNumber(WWSprite s, int n);
int WWSprite_SetHorizontal(WWSprite s, int f);
int WWSprite_SetVertical(WWSprite s, int f);
int WWSprite_SetPriority(WWSprite s, int f);
int WWSprite_SetClipping(WWSprite s, int f);
WWPalette WWSprite_SetPalette(WWSprite s, WWPalette p);
WWCharacter WWSprite_SetCharacter(WWSprite s, WWCharacter c);
int WWSprite_GetX(WWSprite sprite);
int WWSprite_GetY(WWSprite sprite);
int WWSprite_SetPosition(WWSprite sprite, int x, int y);
WWSprite WWSprite_Create(int number, int x, int y,
int horizontal, int vertical,
int priority, int clipping,
WWPalette palette, WWCharacter character);
WWSprite WWSprite_Destroy(WWSprite sprite);
/*****************************************************************************/
/* ここまで */
/*****************************************************************************/
#endif
/*****************************************************************************/
/* End of File. */
/*****************************************************************************/

33
WWSpriteP.h Normal file
View File

@ -0,0 +1,33 @@
#ifndef _WWSpriteP_h_INCLUDED_
#define _WWSpriteP_h_INCLUDED_
/*****************************************************************************/
/* ここから */
/*****************************************************************************/
#include "WWSprite.h"
/*****************************************************************************/
/* クラスの定義 */
/*****************************************************************************/
typedef struct _WWSprite {
int number;
int horizontal; /* 横方向反転フラグ */
int vertical; /* 縦方向反転フラグ */
int priority; /* スクリーン2に対する優先度 */
int clipping; /* クリッピングタイプ */
WWPalette palette; /* パレット番号815 のパレット番号から8を引いた値 */
WWCharacter character; /* 表示キャラクタ */
int x, y; /* 座標(LCD上での絶対座標) */
} _WWSprite;
/*****************************************************************************/
/* ここまで */
/*****************************************************************************/
#endif
/*****************************************************************************/
/* End of File. */
/*****************************************************************************/

71
WonxDisplay.c Normal file
View File

@ -0,0 +1,71 @@
/*****************************************************************************/
/* ここから */
/*****************************************************************************/
#include "WonxDisplayP.h"
/*****************************************************************************/
/* メンバ関数の定義 */
/*****************************************************************************/
XDisplay WonxDisplay_GetXDisplay(WonxDisplay wonx_display)
{ return (wonx_display->x_display); }
WWDisplay WonxDisplay_GetWWDisplay(WonxDisplay wonx_display)
{ return (wonx_display->ww_display); }
static XDisplay WonxDisplay_SetXDisplay(WonxDisplay wonx_d, XDisplay xd)
{ return (wonx_d->x_display = xd); }
static WWDisplay WonxDisplay_SetWWDisplay(WonxDisplay wonx_d, WWDisplay wd)
{ return (wonx_d->ww_display = wd); }
WonxDisplay WonxDisplay_Create(int x_width, int x_height,
int ww_lcd_panel_width, int ww_lcd_panel_height,
int ww_screen_width, int ww_screen_height)
{
WonxDisplay wonx_display;
WWDisplay ww_display;
XDisplay x_display;
wonx_display = (WonxDisplay)malloc(sizeof(_WonxDisplay));
if (wonx_display == NULL)
Error("WonxDisplay_Create", "Cannot allocate memory.");
ww_display = WWDisplay_Create(ww_lcd_panel_width, ww_lcd_panel_height,
ww_screen_width, ww_screen_height);
if (ww_display == NULL)
Error("WonxDisplay_Create", "Cannot create WonderWitch display.");
WonxDisplay_SetWWDisplay(wonx_display, ww_display);
x_display = XDisplay_Create(x_width, x_height);
if (x_display == NULL)
Error("WonxDisplay_Create", "Cannot create X display.");
WonxDisplay_SetXDisplay(wonx_display, x_display);
return (wonx_display);
}
int WonxDisplay_Flush(WonxDisplay wonx_display)
{
XDisplay x_display;
WWDisplay ww_display;
WWLCDPanel ww_lcd_panel;
x_display = WonxDisplay_GetXDisplay(wonx_display);
ww_display = WonxDisplay_GetWWDisplay(wonx_display);
if (XDisplay_GetLCDDraw(x_display)) {
WWDisplay_DrawLCDPanel(ww_display);
ww_lcd_panel = WWDisplay_GetLCDPanel(ww_display);
XDisplay_DrawLCDWindow(x_display, ww_lcd_panel);
}
return (0);
}
/*****************************************************************************/
/* ここまで */
/*****************************************************************************/
/*****************************************************************************/
/* End of File. */
/*****************************************************************************/

32
WonxDisplay.h Normal file
View File

@ -0,0 +1,32 @@
#ifndef _WonxDisplay_h_INCLUDED_
#define _WonxDisplay_h_INCLUDED_
/*****************************************************************************/
/* ここから */
/*****************************************************************************/
#include "XDisplay.h"
#include "WWDisplay.h"
/*****************************************************************************/
/* クラスの定義 */
/*****************************************************************************/
typedef struct _WonxDisplay * WonxDisplay;
XDisplay WonxDisplay_GetXDisplay(WonxDisplay wonx_display);
WWDisplay WonxDisplay_GetWWDisplay(WonxDisplay wonx_display);
WonxDisplay WonxDisplay_Create(int x_width, int x_height,
int ww_lcd_panel_width, int ww_lcd_panel_height,
int ww_screen_width, int ww_screen_height);
int WonxDisplay_Flush(WonxDisplay wonx_display);
/*****************************************************************************/
/* ここまで */
/*****************************************************************************/
#endif
/*****************************************************************************/
/* End of File. */
/*****************************************************************************/

27
WonxDisplayP.h Normal file
View File

@ -0,0 +1,27 @@
#ifndef _WonxDisplayP_h_INCLUDED_
#define _WonxDisplayP_h_INCLUDED_
/*****************************************************************************/
/* ここから */
/*****************************************************************************/
#include "WonxDisplay.h"
/*****************************************************************************/
/* クラスの定義 */
/*****************************************************************************/
typedef struct _WonxDisplay {
XDisplay x_display;
WWDisplay ww_display;
} _WonxDisplay;
/*****************************************************************************/
/* ここまで */
/*****************************************************************************/
#endif
/*****************************************************************************/
/* End of File. */
/*****************************************************************************/

402
XDisplay.c Normal file
View File

@ -0,0 +1,402 @@
#include <stdio.h>
/*****************************************************************************/
/* ここから */
/*****************************************************************************/
#include "XDisplayP.h"
/*****************************************************************************/
/* メンバ関数の定義 */
/*****************************************************************************/
unsigned int XDisplay_GetKeyPress(XDisplay x_display)
{ return (x_display->key_press); }
int XDisplay_GetLCDDraw(XDisplay x_display)
{ return (x_display->lcd_draw); }
/*****************************************************************************/
/* 内部で使用する関数などの定義 */
/*****************************************************************************/
static XrmOptionDescRec options[] = {};
static Atom wm_delete_window;
static void die(Widget w)
{
kill(getpid(), SIGINT);
}
static void quit(Widget w, XEvent * event, String * params, Cardinal * num)
{
die(w);
}
static void wm_protocols_proc(Widget w, XEvent * event, String * params,
Cardinal * num)
{
if ((event->type == ClientMessage) &&
(event->xclient.data.l[0] != wm_delete_window)) {
XBell(XtDisplay(w), 0);
} else {
die(w);
}
}
static void iconify(Widget w, XEvent * event, String * params, Cardinal * num)
{
XIconifyWindow(XtDisplay(w), XtWindow(w), DefaultScreen(XtDisplay(w)));
}
static void pause(Widget w, XEvent * event, String * params, Cardinal * num)
{
sleep(3);
}
static XtActionsRec actions[] = {
{"quit", quit},
{"wm_protocols_proc", wm_protocols_proc},
{"iconify", iconify},
{"pause", pause}
};
static char * translations =
"<Message>WM_PROTOCOLS: wm_protocols_proc()\n"
"None<Key>p: pause()\n"
"Ctrl<Key>i: iconify()\n"
"Ctrl<Key>c: quit()\n"
"None<Key>q: quit()";
/*===========================================================================*/
/* 色名からピクセル値を取得する */
/*===========================================================================*/
static unsigned long XDisplay_GetPixelFromColorName(XDisplay x_display,
char * color_name)
{
XColor c0, c1;
XAllocNamedColor(x_display->display, x_display->colormap, color_name,
&c0, &c1);
return (c0.pixel);
}
/*===========================================================================*/
/* イベントハンドラ */
/*===========================================================================*/
/*---------------------------------------------------------------------------*/
/* キーの押下 */
/*---------------------------------------------------------------------------*/
static void KeyHandler(Widget w, XtPointer p, XEvent * event,
Boolean * dispatch)
{
XDisplay x_display = (XDisplay)p;
KeySym key_sym;
int press = 0;
if ((event->type == KeyPress) || (event->type == KeyRelease)) {
key_sym = XKeycodeToKeysym(x_display->display, event->xkey.keycode, 0);
switch (key_sym) {
/* WonderSwan用 */
case XK_Up : press = KEY_UP1; break;
case XK_Right : press = KEY_RIGHT1; break;
case XK_Down : press = KEY_DOWN1; break;
case XK_Left : press = KEY_LEFT1; break;
case XK_i : press = KEY_UP2; break;
case XK_l : press = KEY_RIGHT2; break;
case XK_k : press = KEY_DOWN2; break;
case XK_j : press = KEY_LEFT2; break;
case XK_s : press = KEY_START; break;
case XK_space : press = KEY_A; break;
case XK_Shift_L : press = KEY_B; break;
/* Wonx 操作用 */
/* 表示モード変更 */
case XK_p :
press = 0;
if (event->type == KeyPress)
x_display->lcd_draw = !(x_display->lcd_draw);
break;
default : press = 0; break;
}
if (press) {
if (event->type == KeyPress) x_display->key_press |= press;
else x_display->key_press &= ~press;
}
}
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;
}
/*---------------------------------------------------------------------------*/
/* マウスがウインドウを離れたら,キーを初期化する */
/*---------------------------------------------------------------------------*/
static void LeaveWindowHandler(Widget w, XtPointer p, XEvent * event,
Boolean * dispatch)
{
XDisplay x_display = (XDisplay)p;
x_display->key_press = 0;
return;
}
/*===========================================================================*/
/* オブジェクトの生成と消去 */
/*===========================================================================*/
/*---------------------------------------------------------------------------*/
/* オブジェクトの生成 */
/*---------------------------------------------------------------------------*/
XDisplay XDisplay_Create(int width, int height)
{
XDisplay x_display;
int argc = 0;
char ** argv = NULL;
XColor color;
char * color_name[] = {"white", "gray84", "gray78", "gray72",
"gray66", "gray60", "gray54", "gray48",
"gray42", "gray36", "gray30", "gray24",
"gray18", "gray12", "gray6", "black"};
int i;
x_display = (XDisplay)malloc(sizeof(_XDisplay));
if (x_display == NULL) Error("XDisplay_Create", "Cannot allocate memory.");
x_display->width = width;
x_display->height = height;
x_display->toplevel = XtAppInitialize(&(x_display->app_context),
"Wonx",
NULL, 0, &argc, argv, NULL, NULL, 0);
XtVaSetValues(x_display->toplevel, XtNinput, True, NULL);
XtVaSetValues(x_display->toplevel, XtNtitle, "Wonx", NULL);
XtVaSetValues(x_display->toplevel, XtNwidth , x_display->width , NULL);
XtVaSetValues(x_display->toplevel, XtNminWidth , x_display->width , NULL);
XtVaSetValues(x_display->toplevel, XtNmaxWidth , x_display->width , NULL);
XtVaSetValues(x_display->toplevel, XtNheight , x_display->height, NULL);
XtVaSetValues(x_display->toplevel, XtNminHeight, x_display->height, NULL);
XtVaSetValues(x_display->toplevel, XtNmaxHeight, x_display->height, NULL);
x_display->key_press = 0;
x_display->lcd_draw = 1;
XtRealizeWidget(x_display->toplevel);
while (!XtIsRealized(x_display->toplevel)) { /* None */ }
x_display->display = XtDisplay(x_display->toplevel);
x_display->root_window = DefaultRootWindow(x_display->display);
x_display->lcd_window = XtWindow(x_display->toplevel);
x_display->colormap = DefaultColormap(x_display->display,
DefaultScreen(x_display->display));
x_display->depth = DefaultDepth(x_display->display,
DefaultScreen(x_display->display));
x_display->lcd_pixmap = XCreatePixmap(x_display->display,
x_display->lcd_window,
x_display->width,
x_display->height,
x_display->depth);
x_display->copy_gc = XCreateGC(x_display->display, x_display->lcd_window,
0, 0);
XSetFunction(x_display->display, x_display->copy_gc, GXcopy);
for (i = 0; i < 16; i++) {
XParseColor(x_display->display, x_display->colormap,
color_name[i], &color); /* 色の名前 → RGB値*/
XAllocColor(x_display->display, x_display->colormap,
&color); /* 色を確保し,ピクセル値を得る */
x_display->color_gc[i] = XCreateGC(x_display->display,
x_display->lcd_window, 0, 0);
XSetForeground(x_display->display, x_display->color_gc[i], color.pixel);
XSetFunction(x_display->display, x_display->color_gc[i], GXcopy);
}
/* フォントの確保 */
x_display->font = XLoadFont(x_display->display, "8x16");
x_display->font_gc = XCreateGC(x_display->display,
x_display->lcd_window, 0, 0);
XSetFont(x_display->display, x_display->font_gc, x_display->font);
XSetFunction(x_display->display, x_display->font_gc, GXcopy);
XSetForeground(x_display->display, x_display->font_gc,
XDisplay_GetPixelFromColorName(x_display, "white"));
XSetBackground(x_display->display, x_display->font_gc,
XDisplay_GetPixelFromColorName(x_display, "black"));
XFillRectangle(x_display->display, x_display->lcd_window,
x_display->color_gc[0],
0, 0, x_display->width, x_display->height);
/* イベントハンドラの登録 */
XtAddEventHandler(x_display->toplevel, KeyPressMask | KeyReleaseMask,
False, KeyHandler, x_display);
XtAddEventHandler(x_display->toplevel, ExposureMask,
False, ExposeHandler, x_display);
XtAddEventHandler(x_display->toplevel, LeaveWindowMask | FocusChangeMask,
False, LeaveWindowHandler, x_display);
/* アイコンの設定 */
#if 0
XtVaSetValues(x_display->toplevel, XtNiconPixmap,
x_display->icon_pixmap, NULL);
XtVaSetValues(x_display->toplevel, XtNiconMask ,
x_display->icon_mask , NULL);
#endif
/* アクションの設定 */
XtAppAddActions(x_display->app_context, actions, XtNumber(actions));
/* トランスレーションの設定 */
XtOverrideTranslations(x_display->toplevel,
XtParseTranslationTable(translations));
/* ウィンドウマネージャからの f.delete への対応 */
wm_delete_window = XInternAtom(x_display->display,
"WM_DELETE_WINDOW", False);
XSetWMProtocols(x_display->display, x_display->lcd_window,
&wm_delete_window, 1);
/* Xサーバと同期をとる */
/* True だと,イベントキュー内のイベントを廃棄する */
XSync(x_display->display, True);
return (x_display);
}
/*---------------------------------------------------------------------------*/
/* オブジェクトの消去 */
/*---------------------------------------------------------------------------*/
XDisplay XDisplay_Destroy(XDisplay x_display)
{
int i;
if (x_display == NULL) return (NULL);
/* あとでリソースの解放を追加すること */
if (x_display->color_gc != NULL) {
for (i = 0; i < 16; i++) {
if (x_display->color_gc[i])
XFreeGC(x_display->display, x_display->color_gc[i]);
x_display->color_gc[i] = 0;
}
}
free(x_display);
return (NULL);
}
/*---------------------------------------------------------------------------*/
/* Xサーバとの同期 */
/*---------------------------------------------------------------------------*/
int XDisplay_Sync(XDisplay x_display)
{
XEvent event;
XFlush(x_display->display);
/* Xサーバと同期をとる */
/* False だと,イベントキュー内のイベントを廃棄しない */
XSync(x_display->display, False);
/* イベントの処理 */
while (XtAppPending(x_display->app_context)) {
XtAppNextEvent(x_display->app_context, &event);
XtDispatchEvent(&event);
}
return (0);
}
/*---------------------------------------------------------------------------*/
/* 描画 */
/*---------------------------------------------------------------------------*/
int XDisplay_DrawLCDWindow(XDisplay x_display, WWLCDPanel ww_lcd_panel)
{
int x, y, n;
int px, py;
int num;
XRectangle * rectangles;
int pixel;
int ww_lcd_width, ww_lcd_height;
num =
WWLCDPanel_GetHeight(ww_lcd_panel) * WWLCDPanel_GetWidth(ww_lcd_panel);
rectangles = (XRectangle *)malloc(sizeof(XRectangle) * num);
if (rectangles == NULL)
Error("XDisplay_DrawLCDWindow", "Cannot allocate memory.");
ww_lcd_width = WWLCDPanel_GetWidth( ww_lcd_panel);
ww_lcd_height = WWLCDPanel_GetHeight(ww_lcd_panel);
/* ここの処理はホットスポットになるので,のちのちにチューニングすること */
for (pixel = 0; pixel < 16; pixel++) {
n = 0;
for (y = 0; y < ww_lcd_height; y++) {
for (x = 0; x < ww_lcd_width; x++) {
if (pixel == WWLCDPanel_GetPixel(ww_lcd_panel, x, y)) {
px = (x * x_display->width ) / ww_lcd_width;
py = (y * x_display->height) / ww_lcd_height;
rectangles[n].x = px;
rectangles[n].y = py;
rectangles[n].width = (x+1) * x_display->width / ww_lcd_width - px;
rectangles[n].height = (y+1) * x_display->height / ww_lcd_height- py;
n++;
}
}
}
if (n > 0) {
XFillRectangles(x_display->display,
x_display->lcd_pixmap,
x_display->color_gc[pixel],
rectangles, n);
}
}
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);
XDisplay_Sync(x_display);
free(rectangles);
return (0);
}
/*****************************************************************************/
/* ここまで */
/*****************************************************************************/
/*****************************************************************************/
/* End of File. */
/*****************************************************************************/

61
XDisplay.h Normal file
View File

@ -0,0 +1,61 @@
#ifndef _XDisplay_h_INCLUDED_
#define _XDisplay_h_INCLUDED_
/*****************************************************************************/
/* ここから */
/*****************************************************************************/
#include "sys/key.h"
#include "WWLCDPanel.h"
/*****************************************************************************/
/* クラスの定義 */
/*****************************************************************************/
typedef struct _XDisplay * XDisplay;
/*****************************************************************************/
/* メンバ関数の定義 */
/*****************************************************************************/
unsigned int XDisplay_GetKeyPress(XDisplay x_display);
int XDisplay_GetLCDDraw(XDisplay x_display);
/*===========================================================================*/
/* オブジェクトの生成と消去 */
/*===========================================================================*/
/*---------------------------------------------------------------------------*/
/* オブジェクトの生成 */
/*---------------------------------------------------------------------------*/
XDisplay XDisplay_Create(int width, int height);
/*---------------------------------------------------------------------------*/
/* オブジェクトの消去 */
/*---------------------------------------------------------------------------*/
XDisplay XDisplay_Destroy(XDisplay x_display);
/*---------------------------------------------------------------------------*/
/* Xサーバとの同期 */
/*---------------------------------------------------------------------------*/
int XDisplay_Sync(XDisplay x_display);
/*---------------------------------------------------------------------------*/
/* 描画 */
/*---------------------------------------------------------------------------*/
int XDisplay_DrawLCDWindow(XDisplay x_display, WWLCDPanel ww_lcd_panel);
/*****************************************************************************/
/* ここまで */
/*****************************************************************************/
#endif
/*****************************************************************************/
/* End of File. */
/*****************************************************************************/

62
XDisplayP.h Normal file
View File

@ -0,0 +1,62 @@
#ifndef _XDisplayP_h_INCLUDED_
#define _XDisplayP_h_INCLUDED_
/*****************************************************************************/
/* ここから */
/*****************************************************************************/
#include "XDisplay.h"
#include <signal.h>
#include <X11/Xlib.h>
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#include <X11/Shell.h>
#include <X11/Xatom.h>
#include <X11/keysym.h>
/*****************************************************************************/
/* クラスの定義 */
/*****************************************************************************/
typedef struct _XDisplay {
XtAppContext app_context;
Widget toplevel;
Display * display;
Window root_window;
Colormap colormap;
Cardinal depth;
Dimension width, height;
int size;
Window lcd_window;
Pixmap lcd_pixmap;
GC copy_gc;
GC color_gc[16];
/* テキストスクリーンへの文字表示用のフォント */
Font font;
GC font_gc;
/* キーの状態 */
unsigned int key_press;
/* LCD描画のフラグ */
int lcd_draw;
} _XDisplay;
/*****************************************************************************/
/* ここまで */
/*****************************************************************************/
#endif
/*****************************************************************************/
/* End of File. */
/*****************************************************************************/

67
bank.c Normal file
View File

@ -0,0 +1,67 @@
/*****************************************************************************/
/* ここから */
/*****************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <sys/bank.h>
#include "wonx.h"
/*****************************************************************************/
/* メンバ関数の定義 */
/*****************************************************************************/
void bank_set_map(int bank, int bank_num)
{
return;
}
int bank_get_map(int bank)
{
return (0);
}
unsigned char bank_read_byte(int bank, unsigned int offset)
{
return (0);
}
void bank_write_byte(int bank, unsigned int offset, unsigned int data)
{
return;
}
unsigned int bank_read_word(int bank, unsigned int offset)
{
return (0);
}
void bank_write_word(int bank, unsigned int offset, unsigned int data)
{
return;
}
void bank_read_block(int bank, unsigned int offset,
void * buffer, unsigned int size)
{
return;
}
void bank_write_block(int bank, unsigned int offset,
void * buffer, unsigned int size)
{
return;
}
void bank_fill_block(int bank, unsigned int offset,
unsigned int size, unsigned int data)
{
return;
}
void bank_erase_flash(int bank)
{
return;
}

79
comm.c Normal file
View File

@ -0,0 +1,79 @@
/*****************************************************************************/
/* ここから */
/*****************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <sys/comm.h>
#include "wonx.h"
/*****************************************************************************/
/* メンバ関数の定義 */
/*****************************************************************************/
void comm_open(void)
{}
void comm_close(void)
{}
int comm_send_char(unsigned char byte)
{
return (0);
}
int comm_receive_char(void)
{
return (0);
}
int comm_receive_with_timeout(int timeout)
{
return (0);
}
int comm_send_string(char * string)
{
return (0);
}
int comm_send_block(void * buffer, int size)
{
return (0);
}
int comm_receive_block(void * buffer, int size)
{
return (0);
}
void comm_set_timeout(int receive_timeout, int send_timeout)
{
}
void comm_set_baudrate(int speed)
{
}
int comm_get_baudrate(void)
{
return (0);
}
void comm_set_cancel_key(unsigned int pattern)
{
}
unsigned int comm_get_cancel_key(void)
{
return (0);
}
/*
int comm_xmodem(void * xmodem)
{
return (0);
}
*/

865
disp.c Normal file
View File

@ -0,0 +1,865 @@
/*****************************************************************************/
/* ここから */
/*****************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <sys/disp.h>
#include "wonx.h"
#include "WonxDisplay.h"
/*****************************************************************************/
/* メンバ関数の定義 */
/*****************************************************************************/
void display_control(unsigned int flags)
{
printf("display_control(): flags = %ud, ", flags); fflush(stdout);
if (wonx_display == NULL) Wonx_Create();
WWDisplay_SetScreenEnable(WonxDisplay_GetWWDisplay(wonx_display),
SCREEN1,
(flags & DCM_SCR1) ? 1 : 0);
WWDisplay_SetScreenEnable(WonxDisplay_GetWWDisplay(wonx_display),
SCREEN2,
(flags & DCM_SCR2) ? 1 : 0);
WWDisplay_SetSpriteEnable(WonxDisplay_GetWWDisplay(wonx_display),
(flags & DCM_SPR) ? 1 : 0);
WWDisplay_SetSpriteWindowEnable(WonxDisplay_GetWWDisplay(wonx_display),
(flags & DCM_SPR_WIN) ? 1 : 0);
if ((flags & 0x0030) == DCM_SCR2_WIN_INSIDE)
WWDisplay_SetScreen2WindowMode(WonxDisplay_GetWWDisplay(wonx_display), 2);
else if ((flags & 0x0030) == DCM_SCR2_WIN_OUTSIDE)
WWDisplay_SetScreen2WindowMode(WonxDisplay_GetWWDisplay(wonx_display), 3);
WWDisplay_SetBorder(WonxDisplay_GetWWDisplay(wonx_display),
(flags & DCM_BORDER_COLOR) >> 7);
WonxDisplay_Flush(wonx_display);
printf("return value = none\n"); fflush(stdout);
return;
}
unsigned int display_status()
{
unsigned short int ret;
printf("display_status(): "); fflush(stdout);
if (wonx_display == NULL) Wonx_Create();
ret = 0;
if (WWDisplay_GetScreenEnable(WonxDisplay_GetWWDisplay(wonx_display),
SCREEN1))
ret |= DCM_SCR1;
if (WWDisplay_GetScreenEnable(WonxDisplay_GetWWDisplay(wonx_display),
SCREEN2))
ret |= DCM_SCR2;
if (WWDisplay_GetSpriteEnable(WonxDisplay_GetWWDisplay(wonx_display)))
ret |= DCM_SPR;
if (WWDisplay_GetSpriteWindowEnable(WonxDisplay_GetWWDisplay(wonx_display)))
ret |= DCM_SPR_WIN;
switch
(WWDisplay_GetScreen2WindowMode(WonxDisplay_GetWWDisplay(wonx_display))) {
case 2:
ret |= DCM_SCR2_WIN_INSIDE;
break;
case 3:
ret |= DCM_SCR2_WIN_OUTSIDE;
break;
default:
}
ret |= WWDisplay_GetBorder(WonxDisplay_GetWWDisplay(wonx_display)) << 7;
WonxDisplay_Flush(wonx_display);
printf("return value = %ul\n", (unsigned int)ret); fflush(stdout);
return (ret);
}
void font_set_monodata(unsigned int number,
unsigned int count, void * data)
{
WWCharacter c;
int i, x, y, n, p;
int f, b;
unsigned char * d;
printf("font_set_monodata(): number = %ud, count = %ud, data = %p, ",
number, count, data); fflush(stdout);
if (wonx_display == NULL) Wonx_Create();
n = 0;
d = (unsigned char *)data; /* ひとつのキャラクタデータは8バイト */
f = WWDisplay_GetForegroundColor(WonxDisplay_GetWWDisplay(wonx_display));
b = WWDisplay_GetBackgroundColor(WonxDisplay_GetWWDisplay(wonx_display));
for (i = 0; i < count; i++) {
c = WWDisplay_GetCharacter(WonxDisplay_GetWWDisplay(wonx_display),
number + i);
for (y = 0; y < 8; y++) {
for (x = 0; x < 8; x++) {
p = (d[n] & (1 << (7 - x))) ? f : b; /*これでよいのか?*/
WWCharacter_SetPixel(c, x, y, p);
}
n++;
}
}
WonxDisplay_Flush(wonx_display);
printf("return value = none\n"); fflush(stdout);
return;
}
void font_set_colordata(unsigned int number,
unsigned int count, void * data)
{
WWCharacter c;
int i, x, y, n, p;
int f, b;
unsigned char * d;
printf("font_set_colordata(): number = %ud, count = %ud, data = %p, ",
number, count, data); fflush(stdout);
if (wonx_display == NULL) Wonx_Create();
n = 0;
d = (unsigned char *)data; /* ひとつのキャラクタデータは16バイト */
for (i = 0; i < count; i++) {
c = WWDisplay_GetCharacter(WonxDisplay_GetWWDisplay(wonx_display),
number + i);
for (y = 0; y < 8; y++) {
for (x = 0; x < 8; x++) {
/*これでよいのか?*/
p = ((d[n] & (1 << (7-x))) ? 2 : 0) + ((d[n + 1] & (1 << (7-x))) ? 1 : 0);
WWCharacter_SetPixel(c, x, y, p);
}
n++;
n++;
}
}
WonxDisplay_Flush(wonx_display);
printf("return value = none\n"); fflush(stdout);
return;
}
void font_get_data(unsigned int number,
unsigned int count, void * data)
{
/* 関数の仕様がわからんので適当に書くぞ */
WWCharacter c;
int i, x, y, n, p;
int f, b;
unsigned char * d;
printf("font_get_data(): number = %ud, count = %ud, data = %p, ",
number, count, data); fflush(stdout);
if (wonx_display == NULL) Wonx_Create();
n = 0;
d = (unsigned char *)data; /* ひとつのキャラクタデータは16バイト */
for (i = 0; i < count; i++) {
c = WWDisplay_GetCharacter(WonxDisplay_GetWWDisplay(wonx_display),
number + i);
for (y = 0; y < 8; y++) {
d[n ] = 0;
d[n+1] = 0;
for (x = 0; x < 8; x++) {
p = WWCharacter_GetPixel(c, x, y);
/* これでよいのか? */
d[n ] |= (((unsigned char)p & 0x02) ? 1 : 0) << (7-x);
d[n+1] |= (((unsigned char)p & 0x01) ? 1 : 0) << (7-x);
}
n++;
n++;
}
}
WonxDisplay_Flush(wonx_display);
printf("return value = none\n"); fflush(stdout);
return;
}
void font_set_color(unsigned int colors)
{
WWDisplay dis;
printf("font_set_color(): colors = %ud, ", colors); fflush(stdout);
if (wonx_display == NULL) Wonx_Create();
dis = WonxDisplay_GetWWDisplay(wonx_display);
WWDisplay_SetForegroundColor(dis, colors & 0x03);
WWDisplay_SetBackgroundColor(dis, (colors >> 2) & 0x03);
WonxDisplay_Flush(wonx_display);
printf("return value = none\n"); fflush(stdout);
return;
}
unsigned int font_get_color(void)
{
unsigned short int ret;
WWDisplay dis;
printf("font_get_color(): "); fflush(stdout);
if (wonx_display == NULL) Wonx_Create();
dis = WonxDisplay_GetWWDisplay(wonx_display);
ret = 0;
ret |= WWDisplay_GetForegroundColor(dis);
ret |= WWDisplay_GetBackgroundColor(dis) << 2;
WonxDisplay_Flush(wonx_display);
printf("return value = %ud\n", ret); fflush(stdout);
return (ret);
}
void screen_set_char(int screen, int x, int y, int w, int h, void * data)
{
int i, j;
int horizontal; /* 横方向反転フラグ */
int vertical; /* 縦方向反転フラグ */
int palette_num; /* パレット番号 */
int character_num; /* 表示キャラクタ */
unsigned short int * d;
WWScreen s;
WWPalette p;
WWCharacter c;
printf("font_set_char(): screen = %d, x = %d, y = %d, w = %d, h = %d, data = %p",
screen, x, y, w, h, data); fflush(stdout);
if (wonx_display == NULL) Wonx_Create();
d = (unsigned short int *)data;
s = WWDisplay_GetScreen(WonxDisplay_GetWWDisplay(wonx_display), screen);
for (j = 0; j < h; j++) {
for (i = 0; i < w; i++) {
horizontal = (*d & (1 << 15)) ? 1 : 0;
vertical = (*d & (1 << 14)) ? 1 : 0;
palette_num = (*d >> 9) & 0x0f;
character_num = *d & 0x1ff;
p = WWDisplay_GetPalette(WonxDisplay_GetWWDisplay(wonx_display),
palette_num);
c = WWDisplay_GetCharacter(WonxDisplay_GetWWDisplay(wonx_display),
character_num);
WWScreen_SetHorizontal(s, x + i, y + j, horizontal);
WWScreen_SetVertical( s, x + i, y + j, vertical);
WWScreen_SetPalette( s, x + i, y + j, p);
WWScreen_SetCharacter( s, x + i, y + j, c);
d++;
}
}
WonxDisplay_Flush(wonx_display);
printf("return value = none\n"); fflush(stdout);
return;
}
void screen_get_char(int screen, int x, int y, int w, int h, void * data)
{
int i, j;
int horizontal; /* 横方向反転フラグ */
int vertical; /* 縦方向反転フラグ */
int palette_num; /* パレット番号 */
int character_num; /* 表示キャラクタ */
unsigned short int * d;
WWScreen s;
WWPalette p;
WWCharacter c;
printf("font_get_char(): screen = %d, x = %d, y = %d, w = %d, h = %d, data = %p",
screen, x, y, w, h, data); fflush(stdout);
if (wonx_display == NULL) Wonx_Create();
d = (unsigned short int *)data;
s = WWDisplay_GetScreen(WonxDisplay_GetWWDisplay(wonx_display), screen);
for (j = 0; j < h; j++) {
for (i = 0; i < w; i++) {
horizontal = WWScreen_GetHorizontal(s, x + i, y + j);
vertical = WWScreen_GetVertical( s, x + i, y + j);
p = WWScreen_GetPalette( s, x + i, y + j);
c = WWScreen_GetCharacter( s, x + i, y + j);
palette_num = WWPalette_GetNumber(p);
character_num = WWCharacter_GetNumber(c);
*d = 0;
*d |= horizontal << 15;
*d |= vertical << 14;
*d |= palette_num << 9;
*d |= character_num;
d++;
}
}
WonxDisplay_Flush(wonx_display);
printf("return value = none\n"); fflush(stdout);
return;
}
unsigned int screen_get_char1(int screen, int x, int y)
{
unsigned short int ret;
printf("screen_get_char1(): screen = %d, x = %d, y = %d, ",
screen, x, y); fflush(stdout);
if (wonx_display == NULL) Wonx_Create();
screen_get_char(screen, x, y, 1, 1, &ret);
WonxDisplay_Flush(wonx_display);
printf("return value = %ud\n", ret); fflush(stdout);
return (ret);
}
void screen_fill_char(int screen, int x, int y, int w, int h,
unsigned int data)
{
int i, j;
int horizontal; /* 横方向反転フラグ */
int vertical; /* 縦方向反転フラグ */
int palette_num; /* パレット番号 */
int character_num; /* 表示キャラクタ */
WWScreen s;
WWPalette p;
WWCharacter c;
printf("screen_fill_char(): screen = %d, x = %d, y = %d, w = %d, h = %d, data = %ud",
screen, x, y, w, h, data); fflush(stdout);
if (wonx_display == NULL) Wonx_Create();
s = WWDisplay_GetScreen(WonxDisplay_GetWWDisplay(wonx_display), screen);
horizontal = (data & (1 << 15)) ? 1 : 0;
vertical = (data & (1 << 14)) ? 1 : 0;
palette_num = (data >> 9) & 0x0f;
character_num = data & 0x1ff;
p = WWDisplay_GetPalette(WonxDisplay_GetWWDisplay(wonx_display),
palette_num);
c = WWDisplay_GetCharacter(WonxDisplay_GetWWDisplay(wonx_display),
character_num);
for (j = 0; j < h; j++) {
for (i = 0; i < w; i++) {
WWScreen_SetHorizontal(s, x + i, y + j, horizontal);
WWScreen_SetVertical( s, x + i, y + j, vertical);
WWScreen_SetPalette( s, x + i, y + j, p);
WWScreen_SetCharacter( s, x + i, y + j, c);
}
}
WonxDisplay_Flush(wonx_display);
printf("return value = none\n"); fflush(stdout);
return;
}
void screen_fill_attr(int screen, int x, int y, int w, int h,
unsigned int data, unsigned int mask)
{
int i, j;
unsigned short int c;
printf("screen_fill_attr(): screen = %d, x = %d, y = %d, w = %d, h = %d, data = %ud, mask = %ud, ",
screen, x, y, w, h, data, mask); fflush(stdout);
if (wonx_display == NULL) Wonx_Create();
for (j = 0; j < h; j++) {
for (i = 0; i < w; i++) {
c = screen_get_char1(screen, x + i, y + j);
c &= mask;
c |= data;
screen_fill_char(screen, x + i, y + j, 1, 1, c);
}
}
WonxDisplay_Flush(wonx_display);
printf("return value = none\n"); fflush(stdout);
return;
}
void sprite_set_range(unsigned int sprite_start, unsigned int sprite_count)
{
printf("sprite_set_range(): start = %ud, count = %ud, ",
sprite_start, sprite_count); fflush(stdout);
if (wonx_display == NULL) Wonx_Create();
WWDisplay_SetSpriteStart(WonxDisplay_GetWWDisplay(wonx_display),
sprite_start);
WWDisplay_SetSpriteCount(WonxDisplay_GetWWDisplay(wonx_display),
sprite_count);
WonxDisplay_Flush(wonx_display);
printf("return value = none\n"); fflush(stdout);
return;
}
void sprite_set_char(unsigned int sprite_num,
unsigned int data)
{
WWSprite s;
WWPalette p;
WWCharacter c;
printf("sprite_set_char(): number = %ud, data = %ud, ",
sprite_num, data); fflush(stdout);
if (wonx_display == NULL) Wonx_Create();
s = WWDisplay_GetSprite(WonxDisplay_GetWWDisplay(wonx_display), sprite_num);
WWSprite_SetHorizontal(s, (data >> 15) ? 1 : 0);
WWSprite_SetVertical( s, (data >> 14) ? 1 : 0);
WWSprite_SetPriority( s, (data >> 13) ? 1 : 0);
WWSprite_SetClipping( s, (data >> 12) ? 1 : 0);
p = WWDisplay_GetPalette(WonxDisplay_GetWWDisplay(wonx_display),
(data >> 9) & 0x07);
c = WWDisplay_GetCharacter(WonxDisplay_GetWWDisplay(wonx_display), data & 0x1ff);
WWSprite_SetPalette(s, p);
WWSprite_SetCharacter(s, c);
WonxDisplay_Flush(wonx_display);
printf("return value = none\n"); fflush(stdout);
return;
}
unsigned int sprite_get_char(unsigned int sprite_num)
{
WWSprite s;
WWPalette p;
WWCharacter c;
unsigned short int ret;
printf("sprite_get_char(): number = %ud, ", sprite_num); fflush(stdout);
if (wonx_display == NULL) Wonx_Create();
s = WWDisplay_GetSprite(WonxDisplay_GetWWDisplay(wonx_display), sprite_num);
ret = 0;
ret |= (WWSprite_GetHorizontal(s) ? 1 : 0) << 15;
ret |= (WWSprite_GetVertical( s) ? 1 : 0) << 14;
ret |= (WWSprite_GetPriority( s) ? 1 : 0) << 13;
ret |= (WWSprite_GetClipping( s) ? 1 : 0) << 12;
p = WWSprite_GetPalette(s);
ret |= (WWPalette_GetNumber(p) & 0x07) << 9;
c = WWSprite_GetCharacter(s);
ret |= WWCharacter_GetNumber(c);
WonxDisplay_Flush(wonx_display);
printf("return value = %ud\n", ret); fflush(stdout);
return (ret);
}
void sprite_set_location(unsigned int sprite_num, int x, int y)
{
WWSprite s;
printf("sprite_set_location(): number = %ud, x = %d, y = %d, ",
sprite_num, x, y); fflush(stdout);
if (wonx_display == NULL) Wonx_Create();
s = WWDisplay_GetSprite(WonxDisplay_GetWWDisplay(wonx_display), sprite_num);
WWSprite_SetPosition(s, x, y);
WonxDisplay_Flush(wonx_display);
printf("return value = none\n"); fflush(stdout);
return;
}
unsigned int sprite_get_location(unsigned int sprite_num)
{
WWSprite s;
unsigned short int ret;
printf("sprite_get_location(): number = %ud, ", sprite_num); fflush(stdout);
if (wonx_display == NULL) Wonx_Create();
s = WWDisplay_GetSprite(WonxDisplay_GetWWDisplay(wonx_display), sprite_num);
ret = 0;
/* これは本当か? 逆では? */
ret |= WWSprite_GetX(s) << 8;
ret |= WWSprite_GetY(s);
WonxDisplay_Flush(wonx_display);
printf("return value = %ud\n", ret); fflush(stdout);
return (ret);
}
void sprite_set_char_location(unsigned int sprite_num,
unsigned int data, int x, int y)
{
if (wonx_display == NULL) Wonx_Create();
printf("sprite_set_char_location(): number = %ud, data = %ud, x = %d, y = %d, ",
sprite_num, data, x, y); fflush(stdout);
sprite_set_char(sprite_num, data);
sprite_set_location(sprite_num, x, y);
WonxDisplay_Flush(wonx_display);
printf("return value = none\n"); fflush(stdout);
return;
}
unsigned long int sprite_get_char_location(unsigned int sprite_num)
{
unsigned long int ret;
printf("sprite_get_char_location(): number = %ud, ",
sprite_num); fflush(stdout);
if (wonx_display == NULL) Wonx_Create();
ret = 0;
/* これは本当か? 逆では? */
ret |= sprite_get_char(sprite_num) << 16;
ret |= sprite_get_location(sprite_num);
WonxDisplay_Flush(wonx_display);
printf("return value = %ul\n", ret); fflush(stdout);
return (ret);
}
void sprite_set_data(unsigned sprite_num, unsigned int count, void * data)
{
int i;
char * d;
unsigned long int * n;
printf("sprite_set_data(): number = %ud, count = %ud, data = %p",
sprite_num, count, data); fflush(stdout);
if (wonx_display == NULL) Wonx_Create();
n = (unsigned long int *)data;
for (i = 0; i < count; i++) {
sprite_set_char_location(sprite_num + i,
n[i] >> 16,
(n[i] >> 8) & 0xff,
n[i] & 0xff);
}
WonxDisplay_Flush(wonx_display);
printf("return value = none\n"); fflush(stdout);
return;
}
void screen_set_scroll(int screen, int x, int y)
{
WWScreen s;
printf("screen_set_scroll(): scsreen = %d, x = %d, y = %d, ",
screen, x, y); fflush(stdout);
if (wonx_display == NULL) Wonx_Create();
s = WWDisplay_GetScreen(WonxDisplay_GetWWDisplay(wonx_display), screen);
WWScreen_SetRollX(s, x);
WWScreen_SetRollY(s, y);
WonxDisplay_Flush(wonx_display);
printf("return value = none\n"); fflush(stdout);
return;
}
unsigned int screen_get_scroll(int screen)
{
unsigned short int ret;
WWScreen s;
printf("screen_get_scroll(): scsreen = %d, ", screen); fflush(stdout);
if (wonx_display == NULL) Wonx_Create();
s = WWDisplay_GetScreen(WonxDisplay_GetWWDisplay(wonx_display), screen);
ret = 0;
ret |= WWScreen_GetRollX(s);
ret |= WWScreen_GetRollY(s) << 8;
WonxDisplay_Flush(wonx_display);
printf("return value = %ud\n", ret); fflush(stdout);
return (ret);
}
void screen2_set_window(int x, int y, int w, int h)
{
if (wonx_display == NULL) Wonx_Create();
/* あとで書くこと */
WonxDisplay_Flush(wonx_display);
}
unsigned long int screen2_get_window(void)
{
if (wonx_display == NULL) Wonx_Create();
/* あとで書くこと */
WonxDisplay_Flush(wonx_display);
}
void sprite_set_window(int x, int y, int w, int h)
{
if (wonx_display == NULL) Wonx_Create();
/* あとで書くこと */
WonxDisplay_Flush(wonx_display);
}
unsigned long int sprite_get_window(void)
{
if (wonx_display == NULL) Wonx_Create();
/* あとで書くこと */
WonxDisplay_Flush(wonx_display);
}
void palette_set_color(unsigned int palette_num,
unsigned int colors)
{
int mapped_colors[4];
WWPalette palette;
printf("palette_set_color(): number = %ud, colors = %ud", palette_num,
colors); fflush(stdout);
if (wonx_display == NULL) Wonx_Create();
mapped_colors[0] = colors & 0x07;
mapped_colors[1] = (colors >> 4) & 0x07;
mapped_colors[2] = (colors >> 8) & 0x07;
mapped_colors[3] = (colors >> 12) & 0x07;
palette = WWDisplay_GetPalette(WonxDisplay_GetWWDisplay(wonx_display), palette_num);
WWPalette_SetMappedColors(palette, mapped_colors);
WonxDisplay_Flush(wonx_display);
printf("return value = none\n"); fflush(stdout);
return;
}
unsigned int palette_get_color(unsigned int palette_num)
{
int mapped_colors[4];
WWPalette palette;
unsigned short int ret;
printf("palette_get_color(): number = %ud, ", palette_num); fflush(stdout);
if (wonx_display == NULL) Wonx_Create();
palette = WWDisplay_GetPalette(WonxDisplay_GetWWDisplay(wonx_display), palette_num);
WWPalette_GetMappedColors(palette, mapped_colors);
ret = 0;
ret |= mapped_colors[0] & 0x07;
ret |= (mapped_colors[1] & 0x07) << 4;
ret |= (mapped_colors[2] & 0x07) << 8;
ret |= (mapped_colors[3] & 0x07) << 12;
WonxDisplay_Flush(wonx_display);
printf("return value = %ud\n", ret); fflush(stdout);
return (ret);
}
void lcd_set_color(unsigned int colors0, unsigned int colors1)
{
WWColorMap color_map;
int lcd_colors[8];
printf("lcd_set_color(): colors0 = %ud, colors1 = %ud, ", colors0, colors1); fflush(stdout);
if (wonx_display == NULL) Wonx_Create();
lcd_colors[0] = colors0 & 0x0f;
lcd_colors[1] = (colors0 >> 4) & 0x0f;
lcd_colors[2] = (colors0 >> 8) & 0x0f;
lcd_colors[3] = (colors0 >> 12) & 0x0f;
lcd_colors[4] = colors1 & 0x0f;
lcd_colors[5] = (colors1 >> 4) & 0x0f;
lcd_colors[6] = (colors1 >> 8) & 0x0f;
lcd_colors[7] = (colors1 >> 12) & 0x0f;
color_map = WWDisplay_GetColorMap(WonxDisplay_GetWWDisplay(wonx_display));
WWColorMap_SetLCDColors(color_map, lcd_colors);
WonxDisplay_Flush(wonx_display);
printf("return value = none\n"); fflush(stdout);
return;
}
unsigned long int lcd_get_color(void)
{
WWColorMap color_map;
int lcd_colors[8];
unsigned long int ret;
printf("lcd_get_color(): "); fflush(stdout);
if (wonx_display == NULL) Wonx_Create();
color_map = WWDisplay_GetColorMap(WonxDisplay_GetWWDisplay(wonx_display));
WWColorMap_GetLCDColors(color_map, lcd_colors);
ret = 0;
ret |= lcd_colors[0] & 0x0f;
ret |= (lcd_colors[1] & 0x0f) << 4;
ret |= (lcd_colors[2] & 0x0f) << 8;
ret |= (lcd_colors[3] & 0x0f) << 12;
ret |= lcd_colors[0] & 0x0f;
ret |= (lcd_colors[1] & 0x0f) << 4;
ret |= (lcd_colors[2] & 0x0f) << 8;
ret |= (lcd_colors[3] & 0x0f) << 12;
WonxDisplay_Flush(wonx_display);
printf("return value = %ul\n", ret); fflush(stdout);
return (ret);
}
void lcd_set_segments(unsigned segments)
{
if (wonx_display == NULL) Wonx_Create();
/* セグメント表示は未サポートか? */
WonxDisplay_Flush(wonx_display);
}
unsigned lcd_get_segments(void)
{
if (wonx_display == NULL) Wonx_Create();
/* セグメント表示は未サポートか? */
WonxDisplay_Flush(wonx_display);
}
void lcd_set_sleep(unsigned sleep)
{
if (wonx_display == NULL) Wonx_Create();
/* ? */
WonxDisplay_Flush(wonx_display);
}
unsigned lcd_get_sleep(void)
{
if (wonx_display == NULL) Wonx_Create();
/* ? */
WonxDisplay_Flush(wonx_display);
}
void screen_set_vram(int screen, int locationID)
{
if (wonx_display == NULL) Wonx_Create();
WonxDisplay_Flush(wonx_display);
}
void sprite_set_vram(int locationID)
{
if (wonx_display == NULL) Wonx_Create();
WonxDisplay_Flush(wonx_display);
}
/*****************************************************************************/
/* ここまで */
/*****************************************************************************/
/*****************************************************************************/
/* End of File. */
/*****************************************************************************/

14
etc.c Normal file
View File

@ -0,0 +1,14 @@
#include "etc.h"
#include <stdio.h>
#include <stdlib.h>
/*===========================================================================*/
/* ¥¨¥é¡¼½èÍý */
/*===========================================================================*/
int Error(char * funcname, char * message)
{
fprintf(stderr, "%s(): %s\n", funcname, message);
exit (1);
}

11
etc.h Normal file
View File

@ -0,0 +1,11 @@
#ifndef _etc_h_INCLUDED_
#define _etc_h_INCLUDED_
/*===========================================================================*/
/* ¥¨¥é¡¼½èÍý */
/*===========================================================================*/
int Error(char * funcname, char * message);
#endif

113
key.c Normal file
View File

@ -0,0 +1,113 @@
#include <stdio.h>
#include <stdlib.h>
#include <sys/key.h>
#include "wonx.h"
#include "WonxDisplay.h"
int key_press_check(void)
{
XDisplay x_display;
int ret;
printf("key_press_check(): "); fflush(stdout);
if (wonx_display == NULL) Wonx_Create();
x_display = WonxDisplay_GetXDisplay(wonx_display);
XDisplay_Sync(x_display);
ret = XDisplay_GetKeyPress(x_display);
printf("return value = %d\n", ret); fflush(stdout);
return (ret);
}
int key_hit_check(void)
{
XDisplay x_display;
int ret;
printf("key_hit_check(): "); fflush(stdout);
if (wonx_display == NULL) Wonx_Create();
x_display = WonxDisplay_GetXDisplay(wonx_display);
XDisplay_Sync(x_display);
ret = XDisplay_GetKeyPress(x_display);
printf("return value = %d\n", ret); fflush(stdout);
return (ret);
}
int key_wait(void)
{
XDisplay x_display;
int ret;
printf("key_wait(): "); fflush(stdout);
if (wonx_display == NULL) Wonx_Create();
x_display = WonxDisplay_GetXDisplay(wonx_display);
ret = 0;
do {
XDisplay_Sync(x_display);
ret = XDisplay_GetKeyPress(x_display);
} while (ret == 0);
printf("return value = %d\n", ret); fflush(stdout);
return (ret);
}
void key_set_repeat(int rate, int delay)
{
printf("key_set_repeat(): rate = %d, delay = %d, ", rate, delay);
fflush(stdout);
if (wonx_display == NULL) Wonx_Create();
printf("return value = none\n"); fflush(stdout);
}
int key_get_repeat(void)
{
int ret;
printf("key_get_repeat(): "); fflush(stdout);
if (wonx_display == NULL) Wonx_Create();
ret = 0;
printf("return value = %d\n", ret); fflush(stdout);
return (ret);
}
int key_hit_check_with_repeat(void)
{
XDisplay x_display;
int ret;
printf("key_hit_check_with_repeat(): "); fflush(stdout);
if (wonx_display == NULL) Wonx_Create();
x_display = WonxDisplay_GetXDisplay(wonx_display);
XDisplay_Sync(x_display);
ret = XDisplay_GetKeyPress(x_display);
printf("return value = %d\n", ret); fflush(stdout);
return (ret);
}

89
sound.c Normal file
View File

@ -0,0 +1,89 @@
/*****************************************************************************/
/* ここから */
/*****************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <sys/sound.h>
#include "wonx.h"
/*****************************************************************************/
/* メンバ関数の定義 */
/*****************************************************************************/
void sound_init(void)
{
return;
}
void sound_set_channel(unsigned int flags)
{
return;
}
unsigned int sound_get_channel(void)
{
return (0);
}
void sound_set_output(unsigned int flags)
{
return;
}
unsigned int sound_get_output(void)
{
return (0);
}
void sound_set_wave(int channel, unsigned char * wave)
{
return;
}
void sound_set_pitch(int channel, unsigned int frequency)
{
return;
}
unsigned int sound_get_pitch(int channel)
{
return (0);
}
void sound_set_volume(int channel, unsigned int volume)
{
return;
}
unsigned int sound_get_volume(int channel)
{
return (0);
}
void sound_set_sweep(int sweep, int step)
{
return;
}
unsigned int sound_get_sweep(void)
{
return (0);
}
void sound_set_noise(unsigned int flags)
{
return;
}
unsigned int sound_get_noise(void)
{
return (0);
}
unsigned int sound_get_random(void)
{
return (0);
}

100
system.c Normal file
View File

@ -0,0 +1,100 @@
#include <stdlib.h>
#include <sys/system.h>
#include "wonx.h"
#include "WonxDisplay.h"
void sys_interrupt_set_hook(int type, intvector_t * intvector,
intvector_t * last_intvector)
{}
void sys_interrupt_reset_hook(int type, intvector_t * last_intvector)
{}
void sys_wait(unsigned int time)
{
}
unsigned long int sys_get_tick_count(void)
{
return (0);
}
void sys_sleep(void)
{
}
void sys_set_sleep_time(int sleep_time)
{
}
int sys_get_sleep_time(void)
{
return (0);
}
void sys_set_awake_key(int awake_key_pattern)
{
}
int sys_get_awake_key(void)
{
return (0);
}
void sys_set_keepalive_int(int keepalive_pattern)
{
}
void sys_get_ownerinfo(int size, char *buffer)
{
}
int sys_suspend(int core)
{
return (0);
}
void sys_resume(int core)
{
}
void sys_set_remote(int remote_enable)
{
}
unsigned int sys_get_remote(void)
{
return (0);
}
void * sys_alloc_iram(void *pointer, unsigned size)
{}
void sys_free_iram(void * p)
{}
void * sys_get_my_iram(void)
{
}
unsigned int sys_get_version(void)
{
return (0);
}
int sys_swap(int core)
{
return (0);
}
void sys_set_resume(unsigned int flags)
{
}
unsigned int sys_get_resume(void)
{
return (0);
}

147
text.c Normal file
View File

@ -0,0 +1,147 @@
#include <stdlib.h>
#include <sys/text.h>
#include "wonx.h"
#include "WonxDisplay.h"
void text_screen_init(void)
{
if (wonx_display == NULL) Wonx_Create();
}
void text_window_init(int x, int y, int w, int h, unsigned font_base)
{
if (wonx_display == NULL) Wonx_Create();
}
void text_set_mode(int mode)
{
if (wonx_display == NULL) Wonx_Create();
}
int text_get_mode(void)
{
if (wonx_display == NULL) Wonx_Create();
return (0);
}
void text_put_char(int x, int y, unsigned int c)
{
if (wonx_display == NULL) Wonx_Create();
printf("%c", (unsigned char)c);
}
int text_put_string(int x, int y, char * s)
{
if (wonx_display == NULL) Wonx_Create();
printf("%s\n", s);
return (0);
}
int text_put_substring(int x, int y, char * s, int len)
{
int i;
if (wonx_display == NULL) Wonx_Create();
for (i = 0; i < len; i++)
printf("%c", s[i]);
printf("\n");
return (0);
}
void text_put_numeric(int x, int y, int len, int format, int number)
{
if (wonx_display == NULL) Wonx_Create();
printf("%d\n", number);
}
void text_store_numeric(char * buffer, int len, int format, int number)
{
if (wonx_display == NULL) Wonx_Create();
sprintf(buffer, "%d", number);
}
void text_fill_char(int x, int y, int len, int code)
{
if (wonx_display == NULL) Wonx_Create();
printf("%c\n", (unsigned char)code);
}
void text_set_palette(int palette_num)
{
if (wonx_display == NULL) Wonx_Create();
}
int text_get_palette(void)
{
if (wonx_display == NULL) Wonx_Create();
return (0);
}
void text_set_ank_font(int font_base_num, int is_color, int font_count,
void * font)
{
if (wonx_display == NULL) Wonx_Create();
}
void text_set_sjis_font(void * font_address)
{
if (wonx_display == NULL) Wonx_Create();
}
void text_get_fontdata(int char_code, void * fontdata_buffer)
{
if (wonx_display == NULL) Wonx_Create();
}
void text_set_screen(int screen)
{
if (wonx_display == NULL) Wonx_Create();
}
int text_get_screen(void)
{
if (wonx_display == NULL) Wonx_Create();
return (0);
}
void cursor_display(int cursor_enable)
{
if (wonx_display == NULL) Wonx_Create();
}
int cursor_status(void)
{
if (wonx_display == NULL) Wonx_Create();
return (0);
}
void cursor_set_location(int x, int y, int w, int h)
{
if (wonx_display == NULL) Wonx_Create();
}
unsigned long cursor_get_location(void)
{
if (wonx_display == NULL) Wonx_Create();
return (0);
}
void cursor_set_type(int palette_num, int blink_interval)
{
if (wonx_display == NULL) Wonx_Create();
}
unsigned long cursor_get_type(void)
{
if (wonx_display == NULL) Wonx_Create();
return (0);
}
int text_printf(int x, int y, const char *format, ...)
{
if (wonx_display == NULL) Wonx_Create();
return (0);
}

33
timer.c Normal file
View File

@ -0,0 +1,33 @@
#include <stdlib.h>
#include <sys/timer.h>
#include "wonx.h"
#include "WonxDisplay.h"
void rtc_set_datetime(int field, unsigned int value)
{
}
unsigned int rtc_get_datetime(int field)
{
unsigned int t;
t = (unsigned int)time(NULL); /* ここはてきとうなので,あとで修正すること */
return (t);
}
void rtc_set_datetime_struct(void * buf)
{}
void rtc_get_datetime_struct(void * buf)
{}
void rtc_enable_alarm(int hour, int min)
{}
void rtc_disable_alarm(void)
{}
void timer_enable(int type, unsigned int auto_preset, unsigned int preset)
{}
void timer_disable(int type)
{}
unsigned int timer_get_count(int type)
{}

16
wonx.c Normal file
View File

@ -0,0 +1,16 @@
#include "wonx.h"
/*****************************************************************************/
/* ¥Ç¥£¥¹¥×¥ì¥¤¤Î³ÎÊÝ */
/*****************************************************************************/
WonxDisplay wonx_display = NULL;
void Wonx_Create(void)
{
wonx_display =
WonxDisplay_Create(LCD_PIXEL_WIDTH * 2, LCD_PIXEL_HEIGHT * 2,
LCD_PIXEL_WIDTH, LCD_PIXEL_HEIGHT,
SCREEN_CHAR_WIDTH, SCREEN_CHAR_HEIGHT);
return;
}

16
wonx.h Normal file
View File

@ -0,0 +1,16 @@
#ifndef _wonx_h_INCLUDED_
#define _wonx_h_INCLUDED_
#include <sys/disp.h>
#include "WonxDisplay.h"
/*****************************************************************************/
/* ディスプレイの確保 */
/*****************************************************************************/
extern WonxDisplay wonx_display;
void Wonx_Create(void);
#endif