summaryrefslogtreecommitdiffstats
path: root/loader/kon2
diff options
context:
space:
mode:
authorMatt Wilson <msw@redhat.com>1999-09-11 16:17:23 +0000
committerMatt Wilson <msw@redhat.com>1999-09-11 16:17:23 +0000
commitec0a82a9f0ebfbfa97df65b9637f1e32068b1dd0 (patch)
tree42861a8021cde06c3b5a0f89b584870c762138f2 /loader/kon2
parent67b133020bb2a5ba90005ac6da55a0d5d1424799 (diff)
downloadanaconda-ec0a82a9f0ebfbfa97df65b9637f1e32068b1dd0.tar.gz
anaconda-ec0a82a9f0ebfbfa97df65b9637f1e32068b1dd0.tar.xz
anaconda-ec0a82a9f0ebfbfa97df65b9637f1e32068b1dd0.zip
Initial revision
Diffstat (limited to 'loader/kon2')
-rw-r--r--loader/kon2/.config20
-rw-r--r--loader/kon2/Makefile63
-rw-r--r--loader/kon2/Makefile.FreeBSD30
-rw-r--r--loader/kon2/Makefile.linux58
-rw-r--r--loader/kon2/config.in.FreeBSD8
-rw-r--r--loader/kon2/config.in.linux18
-rw-r--r--loader/kon2/doc/AUTHOR27
-rw-r--r--loader/kon2/doc/CHANGES158
-rw-r--r--loader/kon2/doc/INSTALL.ENG315
-rw-r--r--loader/kon2/doc/MODULE39
-rw-r--r--loader/kon2/doc/QINSTALL.ENG26
-rw-r--r--loader/kon2/doc/README65
-rw-r--r--loader/kon2/doc/README.FreeBSD89
-rw-r--r--loader/kon2/doc/THANKS29
-rw-r--r--loader/kon2/doc/TODO3
-rw-r--r--loader/kon2/doc/conf.doc70
-rw-r--r--loader/kon2/doc/fld.j3100.doc33
-rw-r--r--loader/kon2/doc/kon.1292
-rw-r--r--loader/kon2/doc/kon.doc393
-rw-r--r--loader/kon2/font/Makefile31
-rw-r--r--loader/kon2/font/Makefile.FreeBSD23
-rw-r--r--loader/kon2/font/Makefile.linux31
-rw-r--r--loader/kon2/font/bdf.c162
-rw-r--r--loader/kon2/font/fld.c258
-rw-r--r--loader/kon2/font/fontx2.c213
-rw-r--r--loader/kon2/font/j3100.c297
-rw-r--r--loader/kon2/font/minix.c194
-rw-r--r--loader/kon2/include/child.h37
-rw-r--r--loader/kon2/include/config.h71
-rw-r--r--loader/kon2/include/defs.h40
-rw-r--r--loader/kon2/include/errors.h41
-rw-r--r--loader/kon2/include/fnld.h65
-rw-r--r--loader/kon2/include/getcap.h59
-rw-r--r--loader/kon2/include/interface.h94
-rw-r--r--loader/kon2/include/mem.h103
-rw-r--r--loader/kon2/include/mouse.h58
-rw-r--r--loader/kon2/include/setutmp.h36
-rw-r--r--loader/kon2/include/sock.h37
-rw-r--r--loader/kon2/include/term.h40
-rw-r--r--loader/kon2/include/vc.h124
-rw-r--r--loader/kon2/include/version.h1
-rw-r--r--loader/kon2/include/vga.h147
-rw-r--r--loader/kon2/include/vt.h128
-rw-r--r--loader/kon2/kbiff/Makefile11
-rw-r--r--loader/kon2/kbiff/kbiff.c68
-rw-r--r--loader/kon2/kon.cfg.FreeBSD216
-rw-r--r--loader/kon2/kon.cfg.linux213
-rw-r--r--loader/kon2/lib/Makefile23
-rw-r--r--loader/kon2/lib/Makefile.FreeBSD9
-rw-r--r--loader/kon2/lib/Makefile.linux23
-rw-r--r--loader/kon2/lib/coding.c184
-rw-r--r--loader/kon2/lib/font.c77
-rw-r--r--loader/kon2/lib/getcap.c248
-rw-r--r--loader/kon2/lib/load.c48
-rw-r--r--loader/kon2/lib/mem.c86
-rw-r--r--loader/kon2/lib/sockface.c133
-rw-r--r--loader/kon2/src/Makefile40
-rw-r--r--loader/kon2/src/Makefile.FreeBSD31
-rw-r--r--loader/kon2/src/Makefile.linux40
-rw-r--r--loader/kon2/src/child.c148
-rw-r--r--loader/kon2/src/display/Makefile34
-rw-r--r--loader/kon2/src/display/Makefile.FreeBSD20
-rw-r--r--loader/kon2/src/display/Makefile.linux34
-rw-r--r--loader/kon2/src/display/j31sx.c453
-rw-r--r--loader/kon2/src/display/s3.c264
-rw-r--r--loader/kon2/src/display/svga.c110
-rw-r--r--loader/kon2/src/display/vga.c797
-rw-r--r--loader/kon2/src/errors.c116
-rw-r--r--loader/kon2/src/fnld.c238
-rw-r--r--loader/kon2/src/main.c60
-rw-r--r--loader/kon2/src/mouse.c408
-rw-r--r--loader/kon2/src/sock.c148
-rw-r--r--loader/kon2/src/term.c579
-rw-r--r--loader/kon2/src/utmp.c104
-rw-r--r--loader/kon2/src/vc.c926
-rw-r--r--loader/kon2/src/vt.c744
-rw-r--r--loader/kon2/termcap.kon19
-rw-r--r--loader/kon2/terminfo.kon32
-rwxr-xr-xloader/kon2/tools/Configure.FreeBSD108
-rwxr-xr-xloader/kon2/tools/Configure.linux119
-rw-r--r--loader/kon2/tools/Makefile37
-rw-r--r--loader/kon2/tools/logto.c40
-rwxr-xr-xloader/kon2/tools/makedir11
-rw-r--r--loader/kon2/tools/minifont.list2526
-rwxr-xr-xloader/kon2/tools/mkminifontbin0 -> 942059 bytes
-rw-r--r--loader/kon2/tools/mkminifont.c40
-rwxr-xr-xloader/kon2/tools/newvcbin0 -> 1102069 bytes
-rw-r--r--loader/kon2/tools/newvc.c167
-rwxr-xr-xloader/kon2/tools/relbin0 -> 923323 bytes
-rw-r--r--loader/kon2/tools/rel.c18
-rw-r--r--loader/kon2/tools/swkon.c88
91 files changed, 13864 insertions, 0 deletions
diff --git a/loader/kon2/.config b/loader/kon2/.config
new file mode 100644
index 000000000..be693892f
--- /dev/null
+++ b/loader/kon2/.config
@@ -0,0 +1,20 @@
+TOPDIR =
+BINDIR = $(TOPDIR)/usr/bin
+LIBDIR = $(TOPDIR)/etc
+MANDIR = $(TOPDIR)/usr/man/ja_JP.ujis/man1
+CONFIG_NAME = kon.cfg
+OPTS = -DCONFIG_NAME=\"$(LIBDIR)/$(CONFIG_NAME)\" -I$(INCDIR)
+CFLAGS = -O2 -Wall $(OPTS)
+LD = gcc $(CFLAGS)
+RM = rm -f
+INSTALL = install -c -s
+
+MINI_KON = MINI_KON
+HAS_VGA = HAS_VGA
+HAS_J31SX = HAS_J31SX
+HAS_MOUSE = HAS_MOUSE
+FLD_MINIX = FLD_MINIX
+FLD_BDF = FLD_BDF
+FLD_FONTX2 = FLD_FONTX2
+FLD_J31ROM = FLD_J31ROM
+USE_ROMFONT = USE_ROMFONT
diff --git a/loader/kon2/Makefile b/loader/kon2/Makefile
new file mode 100644
index 000000000..f295779d4
--- /dev/null
+++ b/loader/kon2/Makefile
@@ -0,0 +1,63 @@
+VERSION = 0.3
+
+ifeq (.config,$(wildcard .config))
+include .config
+endif
+
+INCDIR = $(shell pwd)/include
+LIB = $(shell pwd)/lib/libgon.a
+
+MAKEFLAGS = INCDIR=$(INCDIR) LIB=$(LIB)
+
+ifdef MINI_KON
+SUBDIRS = lib src
+else
+SUBDIRS = lib src font tools
+endif
+
+all: subdirs
+
+version:
+ @expr `cat .VERSION` + 1 > .VERSION
+ @echo \#define VERSION \"ver.$(VERSION).`cat .VERSION` \(`date +%m/%d`\)\" > include/version.h
+
+config:
+ @sh tools/Configure.linux < config.in.linux
+ -for i in $(SUBDIRS) src/display; do \
+ (cd $$i && test -f Makefile.linux && cp Makefile.linux Makefile) ; \
+ done
+ cp Makefile.linux Makefile
+
+subdirs:
+ @for i in $(SUBDIRS);\
+ do (cd $$i && echo making all in $$i && $(MAKE) $(MAKEFLAGS)) || exit;\
+ done
+
+depend:
+ @for i in $(SUBDIRS);\
+ do (cd $$i && echo building dependencies in $$i && $(MAKE) depend) || exit;\
+ done
+
+clean:
+ $(RM) -f *~ include/*~ doc/*~ .depend .config include/config.h config.out
+ @for i in $(SUBDIRS);\
+ do (cd $$i && echo cleaning all in $$i && $(MAKE) clean);\
+ done
+
+install: makedir instbin
+ @if [ -f $(LIBDIR)/$(CONFIG_NAME) ]; then\
+ mv $(LIBDIR)/$(CONFIG_NAME) $(LIBDIR)/$(CONFIG_NAME)'.org';\
+ echo $(LIBDIR)/$(CONFIG_NAME)': file exists ... renamed !!';\
+ fi
+ @install -c $(CONFIG_NAME).linux $(LIBDIR)/${CONFIG_NAME}
+ install -c doc/kon.1 $(MANDIR)
+
+makedir:
+ @sh tools/makedir $(BINDIR)
+ @sh tools/makedir $(LIBDIR)
+ @sh tools/makedir $(MANDIR)
+
+instbin:
+ @for i in $(SUBDIRS);\
+ do (cd $$i && echo installing all in $$i && $(MAKE) install);\
+ done
diff --git a/loader/kon2/Makefile.FreeBSD b/loader/kon2/Makefile.FreeBSD
new file mode 100644
index 000000000..01dfdb885
--- /dev/null
+++ b/loader/kon2/Makefile.FreeBSD
@@ -0,0 +1,30 @@
+# project makefile for kon for FreeBSD
+# Tatsumi Hosokawa <hosokawa@jp.FreeBSD.org>
+
+VERSION= 0.3
+
+SUBDIR= lib src/display src font
+
+.if exists(${.CURDIR}/.config)
+.include "${.CURDIR}/.config"
+.endif
+
+CLEANFILES= Makefile config.out .config .VERSION
+
+version:
+ @expr `cat .VERSION` + 1 > .VERSION
+ @echo \#define VERSION \"ver.$(VERSION).`cat .VERSION` \(`date +%m/%d`\)\" > include/version.h
+
+config:
+ @sh tools/Configure.FreeBSD < config.in.FreeBSD
+ -for i in $(SUBDIR); do \
+ (cd ${.CURDIR}/$$i && test -f Makefile.FreeBSD && cp Makefile.FreeBSD Makefile) ; \
+ done
+ cp Makefile.FreeBSD Makefile
+
+install:
+ (cd ${.CURDIR}/src ; make install)
+ (cd ${.CURDIR}/font ; make install)
+ install -g wheel -o root -m 0644 -c kon.cfg.FreeBSD /usr/local/etc/kon.cfg
+
+.include <bsd.prog.mk>
diff --git a/loader/kon2/Makefile.linux b/loader/kon2/Makefile.linux
new file mode 100644
index 000000000..77eb0aa4f
--- /dev/null
+++ b/loader/kon2/Makefile.linux
@@ -0,0 +1,58 @@
+VERSION = 0.3
+
+ifeq (.config,$(wildcard .config))
+include .config
+endif
+
+ifdef MINI_KON
+SUBDIRS = lib src
+else
+SUBDIRS = lib src font tools
+endif
+
+all: subdirs
+
+version:
+ @expr `cat .VERSION` + 1 > .VERSION
+ @echo \#define VERSION \"ver.$(VERSION).`cat .VERSION` \(`date +%m/%d`\)\" > include/version.h
+
+config:
+ @sh tools/Configure.linux < config.in.linux
+ -for i in $(SUBDIRS) src/display; do \
+ (cd $$i && test -f Makefile.linux && cp Makefile.linux Makefile) ; \
+ done
+ cp Makefile.linux Makefile
+
+subdirs:
+ @for i in $(SUBDIRS);\
+ do (cd $$i && echo making all in $$i && $(MAKE)) || exit;\
+ done
+
+depend:
+ @for i in $(SUBDIRS);\
+ do (cd $$i && echo building dependencies in $$i && $(MAKE) depend) || exit;\
+ done
+
+clean:
+ $(RM) -f *~ include/*~ doc/*~ .depend .config include/config.h config.out
+ @for i in $(SUBDIRS);\
+ do (cd $$i && echo cleaning all in $$i && $(MAKE) clean);\
+ done
+
+install: makedir instbin
+ @if [ -f $(LIBDIR)/$(CONFIG_NAME) ]; then\
+ mv $(LIBDIR)/$(CONFIG_NAME) $(LIBDIR)/$(CONFIG_NAME)'.org';\
+ echo $(LIBDIR)/$(CONFIG_NAME)': file exists ... renamed !!';\
+ fi
+ @install -c $(CONFIG_NAME).linux $(LIBDIR)/${CONFIG_NAME}
+ install -c doc/kon.1 $(MANDIR)
+
+makedir:
+ @sh tools/makedir $(BINDIR)
+ @sh tools/makedir $(LIBDIR)
+ @sh tools/makedir $(MANDIR)
+
+instbin:
+ @for i in $(SUBDIRS);\
+ do (cd $$i && echo installing all in $$i && $(MAKE) install);\
+ done
diff --git a/loader/kon2/config.in.FreeBSD b/loader/kon2/config.in.FreeBSD
new file mode 100644
index 000000000..9fdcdbbcc
--- /dev/null
+++ b/loader/kon2/config.in.FreeBSD
@@ -0,0 +1,8 @@
+Support VGA driver
+HAS_VGA y
+Install Minix/V font loader
+FLD_MINIX y
+Install .bdf font loader
+FLD_BDF y
+Support MOUSE driver
+HAS_MOUSE y
diff --git a/loader/kon2/config.in.linux b/loader/kon2/config.in.linux
new file mode 100644
index 000000000..830cde46b
--- /dev/null
+++ b/loader/kon2/config.in.linux
@@ -0,0 +1,18 @@
+build MINI KON
+MINI_KON y
+Support VGA driver
+HAS_VGA y
+Support J31SX driver
+HAS_J31SX y
+Support MOUSE driver
+HAS_MOUSE y
+Install Minix/V font loader
+FLD_MINIX y
+Install $fontx2 font loader
+FLD_BDF y
+Install .bdf font loader
+FLD_FONTX2 y
+Install J3100ROM font loader
+FLD_J31ROM y
+Use ROM font
+USE_ROMFONT y
diff --git a/loader/kon2/doc/AUTHOR b/loader/kon2/doc/AUTHOR
new file mode 100644
index 000000000..ce5bef66d
--- /dev/null
+++ b/loader/kon2/doc/AUTHOR
@@ -0,0 +1,27 @@
+frandsen@diku.dk (Tommy Frandsen)
+ VGA グラフィックライブラリ (vgalib)
+nemossan@uitec.ac.jp == nemossan@mix
+takamiti@mix
+ MINIX-V フォントおよびそのローダ
+maebashi@mcs.meitetsu.co.jp
+yamamoto@sws.cpd.mei.co.jp
+ MINIX-V フォントローダ
+kensyu@rabbit.is.s.u-tokyo.ac.jp
+ FONTX version 2 のフォントファイルローダ (fontx2.c)
+komeda@ics.es.osaka-u.ac.jp
+ オートラップ等に関するパッチ
+mad@nak.math.keio.ac.jp
+ バーチャルコンソール対応 (vc.c の EnterVC,LeavVC,InitVC)
+ カーネルメッセージの表示 (syslogk.c)
+obuk@MIX
+ J3100sx 対応
+kazu@jl1keo.tama.prug.or.jp
+ J3100 BOLD 対応 ROM フォントローダ
+miura@is.aist-nara.ac.jp(三浦欽也)
+ PS/2 マウス対応
+hibara@psrc.isac.co.jp
+ MONO モード対応
+----------------------------------------------------------- 敬称略・作成時期順
+mad@nak.math.keio.ac.jp
+manabe@papilio.tutics.tut.ac.jp
+ その他のプログラム、全体の取りまとめ
diff --git a/loader/kon2/doc/CHANGES b/loader/kon2/doc/CHANGES
new file mode 100644
index 000000000..012d10abe
--- /dev/null
+++ b/loader/kon2/doc/CHANGES
@@ -0,0 +1,158 @@
+92/10/13 0.90
+ 第1回テスト公開
+92/10/14 0.90.1
+ スクロールタイミングの調整−>失敗
+92/10/15 0.90.2
+ NEmacs に対応するために ESC シーケンスを拡張
+92/10/16 0.91
+ コンソール以外からの起動を禁止
+ 標準色として低輝度と高輝度をコンパイルオプションで選択可能
+ 表示されないものを出力しないようにして1割以上高速化
+ 終了メッセージを表示
+ フォントファイルをソケットを使って読み込む方式に変更
+92/10/18 0.92
+ KI コードとして、^[$@ に加えて ^[$B が使えるように変更
+ uum に対応するために ESC シーケンスを拡張
+0.92.10.24
+ バージョンのつけかたを変更(version.h)
+0.92.11.01
+ 文字の挿入・削除での不具合を修正
+0.92.11.06
+ 実効グループ ID の変更
+0.93.11.08
+ linux/types.h を直接 include するのを止めた
+ 行末に改行コードが来た場合に勝手に次の行に移らない
+0.95.11.20
+ fontx の 16 ドットフォントのローダを追加
+0.96.11.21
+ 通信方式の整理
+ ソースプログラムの整理
+ Makefile でオプションを指定 (config.h の削除)
+ make install でインストール可能
+0.97.11.23
+ Stealth 版 Wide Text モードサポート(他のボードの対応は未確認)
+ kon.pal から kon.cfg に変更、パレット情報の他に VGA の
+ CRT 制御レジスタ、misc レジスタおよび表示サイズの情報を
+ ここから得る
+ con80x30 のエントリを使わずに、環境変数 TERMCAP にサイズ
+ を設定する
+0.97.11.27
+ kensyu@rabbit.is.s.u-tokyo.ac.jp さんにより fontx
+ version 2.X のフォントに対応
+ ET4000 のボードでもハードウェアスクロールが正常に動作する
+ ことが判明
+ Linux-0.98PL5 では bzero(memset) が正常に動作しないので、
+ オリジナルの bzero2 を使用
+0.97.11.29
+ ソースファイルの整理
+ mem.c をライブラリに移動
+0.97.12.05
+ komeda@ics.osaka-u.ac.jp さんパッチによる修正版
+ ・オートラップの完全化
+ ・ESC[M ESC[L に対する修正
+ ・JIS シフトアウトとして ESC(B も認識
+ −install 時に set-gid しないようにした
+ kensyu@rabbit.is.s.u-tokyo.ac.jp さんから ProDesignerIIs
+ 用レジスタ設定値をいただいた
+0.97.4 (12/09) 公開
+ バージョンの付け方を更に変更
+ フォントローダ、フォントの指定を kon.cfg からできるように変更
+ カーソルサイズをコンパイル時に指定
+0.98.0 (12/27)
+ mad@nak.math.keio.ac.jp さんパッチにより VC に対応
+ KON 毎にソケットを作成
+ コンフィグスクリプトによる環境設定
+0.98.1 (01/02)
+ 仮想テキスト VRAM を用いることにより VC 対応を完全化
+ 色数を 8 色に制限
+0.98.2 (01/04)
+ 全角カーソルに対応
+ コンフィグスクリプトの変更
+0.98.3 (01/07)
+ マウスによるカット&ペーストをサポート
+ mad@math.keio.ac.jp さんのノーブランド ET4000 カード用レジスタ設定
+0.98.4 (01/11) 公開
+ スクリーンセイバー
+ 必要な時以外はマウスカーソルを表示しない
+ EUC/S-JIS が利用可能
+0.98.5 (01/22)
+ ハードウェアスクロールしていてもカットできるように修正
+ 下線が引けるように修正
+ グラフィックドライバを入れ替えれるように disp.c -> vga.c
+ font の再ロード時にはメモリを realloc する
+ komeda@ics.osaka-u.ac.jp さんパッチ2
+ ・点滅しないカーソル
+ ・リバースモード
+ −ump の更新
+ kon.cfg でのパレット指定の復活
+ スタートアップ処理を指定し、フォントロードもそこで行う
+0.98+ (03/02)
+ select での signal 対策
+ J3100sx 対応(obuk@MIX さん)
+ syslogd + syslogk によりカーネルからのメッセージを表示
+ 圧縮フォント対応
+0.99 alpha (?????)
+ 前田@慶応さんによるソースの書き換えなど、とにかく大改造
+0.99.1 alpha (8/18)
+ シェアードフォントの採用
+0.99.1.beta (8/29)
+ 仮想テキストの漢字依存を排除
+ いわゆる半角カタカナもサポート
+ シェアードフォントの再ロードが可能
+0.99.2 (1/24)
+ kon.cfg でのビデオモードの設定を Xconfig ライクに
+ VT エミュレータの case 文を関数に置き換え
+0.99.3 (1/30)
+ KON から起動した KON を VC 上で動かす
+0.99.4a (94/5/9)
+ 多言語対応版
+0.99.4b (94/5/12)
+ Mule の "ESC $(0" (Big5) に対応
+0.99.4c (94/5/15)
+ ???
+0.99.4d (94/7/4)
+ MONO モードへの対応
+0.99.4f (95/11/28)
+ 曽根さんによる resize 等のパッチ
+ wrap まわり
+0.99.4g (96/04/17)
+ 藤枝(fujieda@jaist.ac.jp)さんのパッチ
+ MAP_FIXED 修正
+KON2 0.2(96/11/09)
+ 吉山さんによる、レジスタのバグフィックス
+KON2 0.3(97/1/25) hosokawa@jp.FreeBSD.org
+ 待望の FreeBSD 版との統合!!
+KON2 0.3(97/1/27) manabe@dsl.ics.tut.ac.jp
+ FreeBSD 版でもマウス対応
+KON2 0.3(97/1/28) hosokawa@jp.FreeBSD.org
+ FreeBSD での kon.cfg, kon のインストール時のパーミッション修正
+KON2 0.3(97/2/06) manabe@dsl.ics.tut.ac.jp
+ FreeBSD 版 kon.cfg での VGA レジスタ値を Linux でも利用
+KON2 0.3.1(97/4/7) t93141tk@sfc.keio.ac.jp
+ VgaFm ドライバで SegV 起こすバグの修正
+KON2 0.3.2(97/6/15)
+ 1. コンパイルオプションUSE_ROMFONTの追加
+ 2. 漢字ミニフォントを作成する機能の追加(mkminifont)
+ 3. コンパイルオプションMINI_KONの追加〜fldを使わずにフォントをロード
+ - USE_ROMFONTを強制設定
+ - 漢字ミニフォント
+ 4. 8ビットコードの罫線が使えるように修正
+ 5. Mule上での挿入/削除にともなう字化けの修正
+KON2 0.3.3(97/6/16)
+ 1. MINI_KONではソケットもSysV IPCも利用しない
+ 2. ステータスラインの実装(region設定による暫定実装)
+ 3. TERM=konになる:termcap/terminfoファイルを用意(Linux用)
+KON2 0.3.4(97/6/19) yosshy@jedi.seg.kobe-u.ac.jp
+ コンパイル時のwarning抑制
+KON2 0.3.5(97/6/25) akira@isq.rim.or.jp
+ カーソルのゴミが残るバグ
+KON2 0.3.6(97/8/7)
+ 1. MINI_KONではutmpを削除(thank you yosshy@jedi.seg.kobe-u.ac.jp)
+ 2. MINI_KONではTERM=linuxに
+ 3. termio->termios への変更
+KON2 0.3.7(97/8/18)
+ 1. ESC[10mでCS_LEFTに移るのはCS_GRAPHの時だけ
+ (thank you kikutani@jdc.ericsson.se)
+KON2 0.3.8(98/3/9)
+ 1. single user modeでも正常に動作するように
+
diff --git a/loader/kon2/doc/INSTALL.ENG b/loader/kon2/doc/INSTALL.ENG
new file mode 100644
index 000000000..282d4148d
--- /dev/null
+++ b/loader/kon2/doc/INSTALL.ENG
@@ -0,0 +1,315 @@
+1. Setting your environment by "make config"
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+"make config" is necessary to let the Makefile know your environment.
+Type in "make config" at a prompt and you will be asked as follows:
+
+ $ make config
+ KON Kanji ON Linux console
+ Binary Directory [/usr/local/bin]?
+
+The characters between the brackets are the default settings. If you
+hit ENTER key without typing in anything, you are accepting the
+setting. When you execute "make config" for the first time or after
+"make clean", authors' specifications will be shown between the
+brackets. Otherwise, you will see the settings you specified last
+time.
+
+The followings are the questions asked in the "make config" routine.
+If you do not like the default settings, you must input your
+specifications.
+
+ Binary Directory
+ Specify a directory for installing "kon" and other tools.
+
+ Library Directory
+ Specify a directory for installing "kon.cfg" file.
+
+ Support VGA driver
+ Use VGA screen mode to display Japanese characters.
+
+ Support J31SX driver
+ Use J3100SX (DCGA?) screen to display Japanese characters.
+
+ Support MOUSE driver
+ Link the mouse driver with the "kon" program and use mouse under
+ Japanese screen mode.
+
+ Support Minix/V font loader
+ Install the Minix/V font loader (fld.minix) to "Binary Directory"
+ you specified in the second question.
+
+ Install $fontx1 font loader
+ Install the $fontx1 font loader (fld.fontx) to "Binary Directory"
+ you specified in the second question. You can not answer "y" here
+ if you want to install $fontx2 font loader.
+
+ Install $fontx2 font loader
+ Install the $fontx2 font loader (fld.fontx) to "Binary Directory"
+ you specified in the second question. You can not answer "y" here
+ if you want to install $fontx1 font loader.
+
+ Install J3100ROM font loader
+ Install the font loader for J3100SX ROM fonts (fld.j31rom).
+
+ Install new "syslogk"
+ Install "syslogk" into /etc directory.
+
+
+2. Running "make" to compile kon for your system
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+After finishing the "make config" procedure, you can start compiling
+the program by running "make". If the program is generated without
+any trouble, try to install the program by running "make install" with
+the root privilege.
+
+In the "make install" procedure, the install program tries to copy the
+"kon.cfg" file to the directory you designated in the "make config"
+questions. If your old "kon.cfg" is already in the directory, the
+install program renames the old one into "kon.cfg.org" and copies the
+new "kon.cfg" file to the directory.
+
+"make instbin" installs binary files only and does not install the
+"kon.cfg" file. Please make sure to install the new "kon.cfg" file by
+running "make install" because the content of the "kon.cfg" file has
+been changed since the last version.
+
+
+3. Configuring the "kon.cfg" file
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+"KON" reads the "kon.cfg" file at the time of execution.
+The rule of writing entries in the "kon.cfg" file is:
+
+ entry:[alias 1:alias 2:...]
+ the items for the entry
+
+KON is not case-sensitive about the entry names. Each line that
+contains the items must begin with a TAB character. If a line begins
+with a '#' sign, the line is considered as a comment and KON ignores it.
+
+You can specify the following types of items under a entry:
+
+ boolean - on/off
+ choice - choose one from the lists
+ numeric - write decimal values
+ string - type in characters in special formats
+
+** ATTENTION **
+You must write the first two items (i.e., NORMAL and STARTUP) in your
+"kon.cfg" file.
+
+==============================================================================
+NORMAL (string type)
+
+Choose one of the video drivers (such as Stealth, ProIIs, VGA9), whose
+first items are as follows:
+
+ VGA - VGA, SVGA, EGA video driver
+ VGAFM - VGA, SVGA, EGA video driver with the font modification
+ feature (see below)
+ J3100SX - TOSHIBA J3100SX video driver
+
+Then write "Normal" as the alias of the name of your video driver.
+
+Numbers that follow the first item are the value of VGA registers, the
+screen size (dots), the number of columns, and the number of lines.
+You can modify the number of characters displayed on screen by
+changing these values. However, except the standard VGA resolution
+(640x480), the relations between the values of VGA registers and the
+number of characters displayed on screen vary depending on each video
+card. The standard VGA entry is defined as NORMAL in the original
+"kon.cfg".
+
+If you are fortunate enough, your video card's configuration is
+already in the "kon.cfg" file; just type in "NORMAL" following the
+entry and you may be able to use high-resolution Japanese screen. In
+that case, don't forget to delete "NORMAL" from "VGA" entry.
+
+When you create entries, whose type is either "VGA" or "VGAFM", for your
+video card, you must also write:
+
+ the values of VGA registers
+ the numbers of horizontal and vertical dots
+ the numbers of columns and lines
+
+The values of VGA registers can be retrieved from your video card by
+using "vacuum.exe" in the "tools" directory; the program is for DOS.
+See "tools/README" for details.
+
+==============================================================================
+STARTUP (string type)
+
+The commands you want to run in the startup process are specified
+here. The number of commands written in this section is arbitrary.
+
+It is necessary to write a command that loads ZENKAKU fonts. Loading
+HANKAKU fonts is optional. Examples follow:
+
+to use fontx's fonts:
+ /usr/local/bin/fld.fontx /dos/lib/font/jpnhn16x.fnt
+ /usr/local/bin/fld.fontx /dos/lib/font/jpnzn16x.fnt
+
+to use MINIX's fonts:
+ /usr/local/bin/fld.minix /usr/lib/fonts/publicfont.ank
+ /usr/local/bin/fld.minix /usr/lib/fonts/publicfont.k14
+
+
+to use compressed font files:
+ zcat /dos/lib/font/jpnhn16x.fnt.Z | /usr/local/bin/fld.fontx
+ zcat /dos/lib/font/jpnzn16x.fnt.Z | /usr/local/bin/fld.fontx
+
+or
+ zcat /usr/lib/fonts/publicfont.ank.Z | /usr/local/bin/fld.minix
+ zcat /usr/lib/fonts/publicfont.k14.Z | /usr/local/bin/fld.minix
+
+==============================================================================
+PELS (string type)
+
+"PELS" defines color palettes. This entry is necessary when you
+choose one of VGA or VGAFM video drivers. There must be 16 lines
+under this entry, and each line contains 3 decimal values for Red,
+Green, and Blue.
+
+There are "STDPEL" and "REVPEL" entries in the standard "kon.cfg"
+file. STDPEL stands for standard palette, and REVPEL stands for
+reverse palette. Define PELS as an alias for either STDPEL or
+REVPEL.
+==============================================================================
+MOUSE (choice type)
+
+Select one of the mouse drivers from the following:
+
+ Microsoft, MouseSystems, BusMouse,
+ MMSeries, Logitech, None
+
+If the Logitech driver does not work with your Logitech mouse, please
+try Microsoft.
+==============================================================================
+MouseBaud (choice type)
+
+Specify the baud rate for your serial mouse. Choose one of the following:
+
+ 1200, 2400, 4800, 9600
+
+1200 is the default setting. This is effective when your mouse driver is
+one of the following:
+
+ Microsoft, MouseSystems, MMSeries, Logitech
+
+==============================================================================
+MouseDev (string type)
+
+Specify the device name of your mouse. This entry is effective when
+you choose an item other than NONE for the MOUSE entry.
+==============================================================================
+HardScroll (boolean type)
+
+Specify whethter to use hardware scroll. The default is ON.
+This is effective on VGA, VGAFM, and J31SX.
+==============================================================================
+VgaFontOffset (numeric type)
+
+Specify the offset address when loading VGA fonts. If '1' is given here
+the fonts will appear one dot higher than usual. The default is 0.
+==============================================================================
+BeepCounter (numeric type)
+
+Specify the length of beep by 1/100 seconds. The default is 5.
+==============================================================================
+CursorInterval (numeric type)
+
+Specify the interval time of cursor blinking by 1/10 second.
+the default is 5. If you do not want the cursor to blink,
+choose 0 (zero).
+==============================================================================
+SaveTime (numeric type)
+
+Specify the length of time before the screen saver start working.
+The default is 4.
+
+** ATTENTION **
+The screen saver does not work if you choose not to blink the cursor,
+because KON times the length by counting the number of blinking.
+==============================================================================
+KanjiCursor (boolean type)
+
+When KanjiCursor is ON, the width of the cursor becomes ZENKAKU size.
+The default is ON.
+==============================================================================
+CursorTop, CursorBottom
+(numeric type : for VGA and VGAFM drivers.)
+
+Specify the size of the cursor.
+
+ 0 +--------+
+ | |
+ |--------| <-- CursorTop
+ |********|
+ |********|
+ |********|
+ |********|
+ |********|
+ 15 +--------+ <-- CursorBottom
+
+==============================================================================
+BoxCursor (boolean type : for the J3100SX driver)
+
+When BoxCursor is ON, the cursor's shape is a box.
+==============================================================================
+SavePlane3 (boolean type : for VGA and VGAFM drivers)
+
+When SavePlane3 is ON, KON saves the font data that are in
+the third page of VGA. The default is OFF. This item is
+not necessary if you do not use Trident video cards.
+==============================================================================
+SjisKanji (boolean type)
+
+When SjisKanji is on, KON uses Shift-JIS code instead of EUC for its
+second kanji code. The default is OFF (using EUC for the second kanji
+code.)
+==============================================================================
+StartupMessage (boolean type)
+
+When StartupMessage is ON, KON displays the greeting messages
+in the startup procedure. The default is ON.
+==============================================================================
+
+
+4. The Font Modification Function
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+The hight of KON's fonts are 16 dots by default, but the VGAFM driver
+can make the fonts smaller by reducing the hight of a character to
+less than 16 dots. (The original idea is credited to Mr. Matsui Takao
+: mat@tansei.cc.u-tokyo.ac.jp)
+
+The VGAFM driver calculates the hight (lines) of a character from the
+number of dots in the NORMAL entry and the number of lines. Then the
+driver displays characters by reducing the hight of a character if
+necessary.
+
+By using MINIX's public fonts, the VGAFM driver can create fonts that
+are fairly readable. In this case, the number of lines on a screen
+increases by 30 percent. 480-dot screen can have 40 lines, and
+600-dot screen can have 50 lines. This function may be particularly
+useful for notebook computers.
+
+
+5. Other information about the "kon.cfg" file
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+If there are several entries that have the same name, the first
+entry will be effective.
+
+If an entry has an illegal name, the entry will be ignored.
+
+The maximum number of characters in a line is 255.
+
+An entry can have a maximum of 1023 bytes of characters.
+_____________________
+
+If there are any questions regarding this translation, please send
+messages to:
+
+ NBB02702 (NIFTY-Serve)
+ 72111,2702 (CompuServe)
+
+or respective Internet addresses.
+ Nakagome Tomoyuki
diff --git a/loader/kon2/doc/MODULE b/loader/kon2/doc/MODULE
new file mode 100644
index 000000000..973c0c64d
--- /dev/null
+++ b/loader/kon2/doc/MODULE
@@ -0,0 +1,39 @@
+各モジュールの関係
+
+ただし、完全に階層に分かれているわけではなく、階層を飛ばして呼び出すこ
+ともあります。
+
+main - メイン
+ term - マルチプレクサ
+ utmp - utmp 設定
+ sock - socket 通信
+ fnld - フォントローダ
+ child - スタートアップコマンド実行、シェル起動
+ mouse - マウスドライバ
+ vt - vt エミュレータ
+ vc - コンソールドライバ
+ vga
+ cga
+ j31sx
+ errors - エラーメッセージ表示ユーティリティ
+
+
+初期化のステップについて。
+
+各モジュールの初期化は一般に次の3つのステップで行なわれます。
+
+1. Init 設定ファイルを読む準備
+ kon.cfg のエントリを解析する call back 関数を設定します。
+
+2. Config 設定ファイルの読み込み
+ kon.cfg を読み込み中に、1 で設定した call back 関数が呼び出されます。
+ kon.cfg の内容によって変数の設定を行ない、必要ならば追加の call
+ back 関数を設定します。
+
+3. Start 初期化
+ 設定し終った変数の値に応じて初期化を行ないます。
+
+4. Cleanup 解放
+ 再初期化の前に、Cleanup ルーチンが呼ばれます。 ここでは、確保した資
+ 源 (メモリ, ファイル, IO permission, capability 表のエントリ) を解
+ 放します。
diff --git a/loader/kon2/doc/QINSTALL.ENG b/loader/kon2/doc/QINSTALL.ENG
new file mode 100644
index 000000000..9442cb8e3
--- /dev/null
+++ b/loader/kon2/doc/QINSTALL.ENG
@@ -0,0 +1,26 @@
+For those of you who do not have patience to read through the
+instructions in the "install.eng" file, here is the brief installing
+procedure.
+
+1. "make clean"
+ deletes backup files. This is not necessary for the first install.
+
+2. "make config"
+ determines your environment and prepares for compiling KON.
+
+3. "make depend"
+ creates the dependency files for compiling KON.
+
+4. "make"
+ creates KON.
+
+5. "make install"
+ installs several files including the KON program.
+ Do this with the root privilege.
+
+6. "kon"
+ runs the program.
+
+And you should be able to display Japanese characters on screen. I
+recommend that, at first, you use standard VGA screen (640x480 dots)
+to run KON. Good luck!
diff --git a/loader/kon2/doc/README b/loader/kon2/doc/README
new file mode 100644
index 000000000..bf846838c
--- /dev/null
+++ b/loader/kon2/doc/README
@@ -0,0 +1,65 @@
+ KON ----- Kanji ON Linux console -----
+
+
+ KON は Linux のコンソール画面上で漢字を表示するためのプログラムです。
+表示方式は DOS/V, minix-V, 386BSD KanjiHand と(恐らく)同じですが、
+minix-V や KanjiHand と異なる点が一つあります。KON では疑似端末を使っ
+てコンソール出力をフックし、VGA に展開しています。したがってカーネル
+ソースにパッチを当てる必要はありませんが、minix-V や KanjiHand のよう
+な拡張機能は期待できません。
+
+● 機能と制限
+
+・ フォントファイルとして minix-V の publicfont および fontx1 の 16 ド
+ ットフォントを使わせていただいてます。publicfont は X11R5 で使われ
+ ている k14.bdf などを minix-V のフォーマットにしたものですので
+ minix-V のフォントパッケージから入手して下さい。fontx1 フォントの場
+ 合も内部的には、minix-V のフォント構造で扱っています。
+
+・ fontx1 に続いて、fontx2 のフォントファイルにも対応しました。
+ kensyu@rabbit.is.s.u-tokyo.ac.jp さん作です。
+
+・ pty を使って出力をフックし、VGA でテキスト画面をエミュレートして
+ います。
+
+・ obuk@MIX さんにより、J3100sx でも利用できるようになりました。
+
+・ JIS/{EUC|SJIS} に対応しております。
+
+・ フォアグランド、バックグランドそれぞれ8色カラーで反転、下線の属性
+ 表示ができます。
+
+・ ソケットを通してクライアントプログラムと通信することができます。
+ (現状ではフォントロードのみサポート)
+
+・ カーネルバージョン 0.99PL1 以降で利用することにより、バーチャルコン
+ ソールに対応します。
+
+・ マウスによるカット&ペースト機能をサポートしました。マウスカーソルは
+ マウスを動かすと表示されます。一旦表示されてカーソルが10回点滅すると
+ 消えます。
+
+・ カーネルからコンソールへのメッセージを KON で表示できるように
+ なりました。
+
+− more などのツールは8ビットクリーンな設計になってますが、JIS のエス
+ ケープシーケンスを理解することはできません。したがって、JIS コードの
+ テキストを more したりすると字が化けます。
+
+● プログラム、バグについて
+
+ KON のソースプログラムに関して私個人としてはいかなる部分にもどんな権利も
+主張するつもりはありません(放棄することはできないそうですが)。したがって、
+変更・配布は自由に行っていただいて結構です。ただ、バグフィックス等の改善は
+取りまとめたいので作者まで送っていただければ幸いです。
+ また、KON を使ってハードウェアや他のソフトウェアに問題が発生しても責任を
+とることはできません。
+ バグや意見などがありましたら以下のアドレスにメイルを下さい。
+
+ E-Mail: manabe@papilio.tutics.tut.ac.jp.
+ PC-VAN: FFE91293
+
+ 現在わかっているバグは、
+・ Xを利用できない。
+・ KON 終了時にテキストが戻らない時がある。
+です。
diff --git a/loader/kon2/doc/README.FreeBSD b/loader/kon2/doc/README.FreeBSD
new file mode 100644
index 000000000..2cbbcecb5
--- /dev/null
+++ b/loader/kon2/doc/README.FreeBSD
@@ -0,0 +1,89 @@
+KON2 for Linux/FreeBSD は、ほそかわたつみ <hosokawa@jp.FreeBSD.org> が
+FreeBSD 対応作業を行ないました。作業は主に、従来の kon-0.99.4e (下のド
+キュメントを参照) のパッチの取り込み、GNU make から FreeBSD make への
+Makefile の修正、FreeBSD 用パッチを当てた後で Linux でコンパイルがうま
+くいかない部分の修正などを行ないました。
+
+make するには、
+
+# tar xvfz kon2-0.1.tar.gz
+# cd kon2-0.1
+# make -f Makefile.FreeBSD
+ (質問にはすべて [Enter] で大丈夫です)
+# make
+# make install
+
+の手順で行なって下さい。
+
+ほそかわ たつみ <hosokawa@jp.FreeBSD.org>
+
+
+
+kon-0.99.4 に対する FreeBSD 用移植については以下の文章を参照して下さい。
+
+----------------------------------------------------------------------------
+
+ KON for FreeBSD ver 0.1
+
+ 1995-06-04
+ 小倉 貴
+ <ogura@st.rim.or.jp>
+
+ はじめに kon for FreeBSD は、linux の日本語コンソールである kon-0.99.4e
+と kon for NetBSD(NetBSD-0.9 がリリースされた当時に移植されたもの)をベース
+に移植したものです。
+
+ 特徴として、シェアードメモリにフォントの情報を置くので多くの仮想コンソー
+ル上で kon を起動してもメモリを多く使用しないことがあります。また、作者の
+手抜き、技術力の低さからオリジナルの kon-0.99.4e より多くの機能が削除され
+ています。対応していない機能については選択できない用にしています。
+
+
+インストールの仕方
+
+ 1.1 カーネルにシェアードメモリを設定する。/usr/src/sys/i386/conf/GENERIC
+ ファイルに"options SYSVSHM"の行を追加後、
+ config GENERIC;cd ../../compile/GENERIC
+ make depend;make all;cp kernel /
+ などを実行してリブートしてください。
+
+ 1.2 このディレクトリで make config を実行してください。VGA は必ず[y]に
+ してください。フォントの選択はどれか一つは必ず[y]にしてください。
+
+ 1.3 .config ファイルを実行モジュールをインストールするディレクトリや、
+ kon.cfg / man ファイルの格納先などを変更してください。デフォルトで
+ は以下の用になっています。
+ /usr/local/bin 実行モジュール格納先
+ /usr/local/etc kon.cfg ファイル格納先
+ /usr/local/man/ja_JP.EUC/man1 man ファイル格納先
+
+ 1.4 kon.cfg ファイルをフォントにあわせて変更してください。記述方法な
+ どは doc 以下のファイルを参考にしてください。使用するフォントは
+ デフォルトでは linux の日本語パッケージである JE の publicfont
+ の k14 と ank フォントを gzip 形式で /usr/share/fonts 以下に格納
+ するようになっています。
+
+ 1.5 make;make install を実行してください。
+
+
+トラブルシューティング
+
+ kon がうまく起動しない時には、シェアードメモリが利用できるか確
+ 認してください。 また、画面が真っ暗でもほとんどの場合ハングはし
+ ていませんから"exit" や "CTRL+D"、"CTRL+C" などで kon を終了させ
+ "vidcontrol VGA_80x30"を実行して見てください。また、XFree86-3.1
+ とほぼ同じ方法でコンソール上に文字を表示しているのでXが利用でき
+ ることを確認してみてください。
+
+
+ 本ソフトウェア(kon for FreeBSD)はフリーソフトウェアであり、変更・配布は
+自由に行っていただいて結構です。ただ、バグや感想などを私宛にメールでもし
+ていただければ幸いです。
+ また、kon for FreeBSD を使ってハードウェアや他のソフトウェアに問題が発生
+しても責任をとることはできません。
+
+ 最後に、kon の作者である真鍋さん<manabe@papilio.tutics.tut.ac.jp>と
+kon for NetBSD の作者である鵜飼さん<ukai@hplj.hpl.hp.com>、テストに協力し
+てくださった皆様、ありがとうございました。
+
+ 小倉 貴<ogura@st.rim.or.jp>
diff --git a/loader/kon2/doc/THANKS b/loader/kon2/doc/THANKS
new file mode 100644
index 000000000..6cda91a9f
--- /dev/null
+++ b/loader/kon2/doc/THANKS
@@ -0,0 +1,29 @@
+ KON は他のプログラムのコードをかなり含んでいます。この事に関して何名か
+の方にお世話になりました。
+ minix-V の作者である
+ nemossan@uitec.ac.jp == nemossan@mix さん
+ takamiti@mix さん
+ そして KanjiHand の作者である
+ maebashi@mcs.meitetsu.co.jp さん
+ yamamoto@sws.cpd.mei.co.jp さん
+フォントおよびそのローダ部分の転用を快諾していただいて真にありがとうござい
+ました。フォントだけでなく VGA 関係もかなり参考にさせていただきました。
+ KON のテスト公開に関しては Azuma Okamoto <lfo@ecei.tohoku.ac.jp> さんの
+迅速な対応に感謝しています。
+ テストに協力してくださった
+ Takahiro.Noguchi@Japan.Sun.COM さん
+ありがとうございました。
+ NEmacs + SKK が既にあることを教えてくださった
+ nakamura@arl.mech.tohoku.ac.jp さん
+おかげさまで、環境が随分改善されました。
+ 私が Linux を始めた頃にいろいろと教えてくださった
+ kawamoto@chuo-computer.co.jp さん
+ nick@nsis.cl.nec.co.jp さん
+は私にとって大変心強い存在です。
+ KON の開発にあたっては、screen, pty, kterm など様々な公開ソフトを参考に
+させていただきました。publicfont の基となっている X11R5 のフォントファイル
+も含めて、このような貴重かつ膨大な情報を手にすることができるこの世界に感謝
+し、できることならば貢献していきたいと思います。
+ 最後に、Linux を開発し公開された
+ torvalds@klaava.Helsinki.FI (Linus Benedict Torvalds) 氏
+そしてこの Linux を育ててきた多くの方々に深く感謝します。
diff --git a/loader/kon2/doc/TODO b/loader/kon2/doc/TODO
new file mode 100644
index 000000000..b21544371
--- /dev/null
+++ b/loader/kon2/doc/TODO
@@ -0,0 +1,3 @@
+$B!&6&M-%a%b%jHs;HMQHG(B
+$B!&(BISO-2022 $BBP1~(B
+$B!&4J0W%0%i%U%#%C%/5!G=$NAuHw(B
diff --git a/loader/kon2/doc/conf.doc b/loader/kon2/doc/conf.doc
new file mode 100644
index 000000000..71aa63fae
--- /dev/null
+++ b/loader/kon2/doc/conf.doc
@@ -0,0 +1,70 @@
+A. kon.cfg の処理
+
+■void ReadConfig(void)
+
+kon.cfg の内容は関数 ReadConfig() によって処理されます。 ReadConfig()
+はエントリ名と初期化関数の対応表をサーチして、読み込んだエントリ1つ1
+つについて対応する初期化関数を呼び出します。 対応表は以下の構造体を並
+べたものです。
+
+ static struct capability {
+ const char *name; エントリ名
+ void (*func)(const char*); 初期化関数
+ int initialized; 初期化が終れば 1
+ const char *def_value; デフォルト値。 NULLなら必須エントリ
+ };
+
+処理関数はエントリ値の文字列を受けとり初期化処理を行ないます。
+
+kon.cfg を読み終ると、初期化関数を呼び出さなかったエントリについてデフォ
+ルト値が設定されているかどうか調べ、設定されていればそのデフォルト値で
+初期化関数を呼び出します。 設定されていなければエラーとなります。
+
+
+■void DefineCap(const char *name, initializer *func, const char *def_value)
+
+新たなエントリを初期化テーブルに加えます。 VGA ドライバだけは PELS エ
+ントリを必要とするので、この関数を使って必須エントリを追加しています。
+
+■void DelCap(const char* name)
+
+対応表の中のエントリ名 name の初期化関数を削除します。 再初期化の際に
+使っています。
+
+
+B. ビデオドライバのインターフェース
+
+●構造体 vInfo
+
+ビデオドライバに対する操作はすべて構造体 vInfo を通して行なわれます。
+
+struct videoInfo {
+ bool has_hard_scroll; ハードスクロールが使えるかどうか
+ void (*init)(void), 初期化
+ (*text_mode)(void), テキストモードに切替え
+ (*graph_mode)(void), グラフィックモードに切替え
+ (*wput)(u_char *code, u_char fc, u_char bc),
+ 漢字出力
+ (*sput)(u_char *code, u_char fc, u_char bc),
+ ANK出力
+ (*set_cursor_address)(struct cursorInfo *c, u_int x, u_int y),
+ カーソル c のアドレスを (x, y) に設定
+ (*set_address)(u_int i),次に書く文字のアドレスを i 文字目に設定
+ (*cursor)(bool), カーソルon/off
+ (*clear_all)(void), 画面クリア
+ (*screen_saver)(bool), スクリーンセーバ(TRUEでセーブ、FALSEで復帰)
+
+ /* ハードスクロールが使えなければ以下はNULL */
+ (*set_start_address)(), 表示開始アドレス設定
+ (*hard_scroll_up)(int lines), ハードスクロールアップ
+ (*hard_scroll_down)(int lines); ハードスクロールダウン
+} vInfo;
+
+
+■void ConfigDisplay(const char *config)
+
+ビデオドライバエントリの初期化関数 ConfigDisplay() は、エントリ値文字
+列 config の最初の行をキーとしてビデオドライバ設定関数を選択します。
+ビデオドライバ設定関数は dInfo と vInfo にそのドライバを使うための値を
+設定します。また、VGA, VGAFM ドライバの場合はレジスタ値を config 文字
+列より得てドライバ内部の変数に記憶します。
diff --git a/loader/kon2/doc/fld.j3100.doc b/loader/kon2/doc/fld.j3100.doc
new file mode 100644
index 000000000..c3d06b87f
--- /dev/null
+++ b/loader/kon2/doc/fld.j3100.doc
@@ -0,0 +1,33 @@
+J-3100 $B4A;z(B ROM $B@lMQ%U%)%s%H%m!<%@!<(B
+
+ $B8B$i$l$?(B disk $B;q8;$rM-8z$K;H$&$?$a!"$^$?!"(Bk14 $B$J$I$h$j$O!"8+$J$l$?%U%)%s%H(B
+$B$G!"(BKON $B$r;H$&$?$a$K!"(BJ-3100 $B$NFbB"4A;z(B ROM $B$rMxMQ$7$?!"%U%)%s%H%m!<%@!<$G$9!#(B
+
+$B#1!%%$%s%9%H!<%k(B
+ * make [install|instbin] $B$G!"(B/usr/local/bin $B$K%$%s%9%H!<%k$5$l$^$9!#(B
+ * /usr/local/lib/kon.cfg $B$N:G8e$K!"(B
+ /usr/local/bin/fld.j3100 ank standard
+ /usr/local/bin/fld.j3100 kanji standard
+ $B$H!";XDj$7$^$9!#$^$?!"%\!<%k%I%U%)%s%H$K$7$?$$>l9g$O!"(B
+ /usr/local/bin/fld.j3100 ank bold
+ /usr/local/bin/fld.j3100 kanji bold
+ $B$NMM$K!";XDj$7$^$9!#$5$i$K!"H>3Q%U%)%s%H$O%G%U%)%k%H$G4A;z(B ROM $B$+$i(B
+ $BFI$_9~$_$^$9$,!"0J2<$N$h$&$K;XDj$9$l$P!"(BBIOS ROM $B$+$iFI$_9~$`$3$H$,(B
+ $B$G$-$^$9!#(B
+ /usr/local/bin/fld.j3100 ank [standard|bold] bios
+ $B>e5-;XDj$G!"@5$7$/I=<($5$l$J$$>l9g$O!"0J2<$N$h$&$K;XDj$7$F2<$5$$!#(B
+ /usr/local/bin/fld.j3100 ank [standard|bold] bios2
+ $B!v4A;z(B ROM $B$r;XDj$9$k$H!"H>3Q$N(B'$B!o(B'$B$,I=<($5$l!"(BBIOS ROM $B$r;XDj$9$k(B
+ $B$H!"H>3Q$N(B'$B!@(B'$B$,I=<($5$l$^$9!#(BBIOS ROM $B$O!"5!<o$K$h$j%U%)%s%H$N(B
+ $B%"%I%l%9$,0[$J$k$N$G!"(B[bios|bios1] $B$H(B bios2 $B$r;n$7$F!"@5$7$/I=<((B
+ $B$5$l$kJ}$r8fMxMQ2<$5$$!#(B
+
+$B#2!%F0:n3NG'(B
+ * J-3100SX001 + 80Mhdd + 8Mram
+ SLS1.03(93/08/18)
+ linux-0.99.12+
+ KON-0.99.1
+
+$B#3!%O"Mm@h(B
+ * kazu@jl1keo.tama.prug.or.jp
+
diff --git a/loader/kon2/doc/kon.1 b/loader/kon2/doc/kon.1
new file mode 100644
index 000000000..55183284d
--- /dev/null
+++ b/loader/kon2/doc/kon.1
@@ -0,0 +1,292 @@
+.TH KON 1 "Sep 5, 1996"
+.UC 4
+.SH 【名前】
+KON \- 漢字コンソールエミュレータ
+.SH 【書式】
+.B kon
+[
+.B video
+]
+[
+.B -capability
+value ...
+]
+.SH 【概要】
+\fIKON\fP は \fILinux\fP, \fIFreeBSD\fP のコンソール画面上で漢字を表示
+するためのプログラムです。\fIKON\fP では、
+.B pty(4)
+を使ってコンソール入出力をフックし、\fIVGA\fP あるいは \fIDCGA\fP
+に展開する事によって漢字表示を実現しています。また、\fIKON\fP が動作
+しているコンソールから起動された \fIKON\fP は新しい仮想コンソール上で
+動作します。
+.SH 【オプション】
+.PP
+\fIKON\fP はオプションでビデオドライバやいくつかの環境を指定することが
+できます。
+.B video
+には \fIkon.cfg\fP に記述されているビデオドライバエントリ
+の一つを指定します。何も指定しなければ、ビデオドライバとして \fINORMAL\fP
+が指定されたことになります。 \fICursorInterval\fP などの設定はオプション
+.B -capability
+でオーバライトすることができます。例えば、
+
+.br
+ % kon -CursorInterval 10
+.br
+
+とすれば \fICursorInterval\fP の値を 10 にして起動します。
+
+.PP
+.SH 【環境設定】
+表示するビデオドライバやパレットなどの環境は \fIkon.cfg\fP ファイルで設定する
+ことができます。このファイルの文法は以下のようになっています:
+.TP 8
+ \fIエントリ名\fP:[\fI別名1\fP:\fI別名2\fP:...]
+ \fIエントリの値\fP
+.PP
+\fIエントリ名\fPの大文字/小文字は区別しません。ある\fIエントリの値\fPを
+指示する行は必ず \fITAB\fP キャラクタで始めなければなりません。また、
+\fI#\fP から行末まではコメントとして扱われます。
+.PP
+\fIエントリの値\fPの種類には次のようなものがあります:
+.TP 10
+\fIboolean\fP
+On または Off を指定(大文字/小文字の区別なし)
+.TP 10
+\fIchoice\fP
+いくつかの選択肢から一つを指定(大文字/小文字の区別なし)
+.TP 10
+\fInumeric\fP
+10進数値を指定
+.TP 10
+\fIstring\fP
+そのエントリ特有のフォーマットで値を指定
+.PP
+また、以下の2つのエントリは必須です:
+.TP 4
+\fINORMAL\fP(string)
+ビデオドライバを選択します。値の意味は以下の通りです:
+
+.nf
+\fIVGA\fP VGA, SVGA, EGA用ドライバ
+\fIVGAFM\fP VGA, SVGA, EGA用ドライバ(フォント変形機能つき)
+\fIJ3100SX\fP 東芝 J3100SX 用ドライバ(DCGA ドライバ)
+.fi
+
+\fIVGA\fP, \fIVGAFM\fP の場合はさらに\fIVGAレジスタ値\fPと画面サイズ
+(ドット数)、行幅(文字数)、行数を指定します。このエントリによって
+表示文字数を変えることができますが、 VGA の解像度(640x480)を除いて
+\fIVGAレジスタ値\fPと表示文字数の関係はビデオカードに依存します。
+付属の \fIkon.cfg\fP では、 \fINORMAL\fP が標準 VGA の別名となっており、
+その他にいくつかのエントリが用意されています。まずこの状況で試して、
+その後お使いのビデオカードにあったものを選んで下さい。
+
+.\" お使いのビデオカード用に新たなエントリを書き加えるには、tools
+.\" ディレクトリにある \fIvacuum.exe\fP を用いて DOS 上で\fIVGAレジスタ値\fP
+.\" を調べる必要があります。
+
+\fIKON\fP は 16 ドットフォントのみを扱いますが、 \fIVGAFM\fP ドライバは、
+ラインを間引いて 16 ラインより少ない幅で 1 行を指定する機能を持っています
+(原案は松井孝雄さん mat@tanasei.cc.u-tokyo.ac.jpによる)。 \fIVGAFM\fP
+ドライバは、 \fINORMAL\fP エントリの縦ドット数と行数から 1 行のライン数を求め、
+必要ならばラインを間引いて通常より多くの行を表示できます。フォントと
+ライン数の組合せにより読みやすさは異なりますが、 MINIX のパブリックフォント
+を用いた場合、 12 ドットでも結構読める表示ができます。その場合、行数
+が3割以上増えるので(480ラインで 40 行、 600 ラインで 50 行)、特にノートパソコン
+などでは便利な時があるでしょう。
+.TP 4
+\fISTARTUP\fP(string)
+スタートアップ時に起動するコマンド文字列を指定します。 1 行 1 コマン
+ドで何行でも記述できます。フォントをロードするコマンドをここで指定
+してやらなければなりません。また、VGA において半角フォントをロード
+しなかった時は \fIVGAフォント\fPが使われます。
+
+.nf
+.I 非圧縮フォント
+ <フォントローダ> <半角フォントファイル>
+ <フォントローダ> <全角フォントファイル>
+.I 圧縮フォント
+ zcat <半角フォントファイル> | <フォントローダ>
+ zcat <全角フォントファイル> | <フォントローダ>
+.fi
+.PP
+次のエントリはビデオドライバに VGA, VGAFM を指定した時に必要になります:
+.TP
+\fIPELS\fP(string)
+パレットの指定を行ないます。フォーマットは、R,G,B のパレット値(10
+進)を 1 行に書き、それを 16 行並べたものです。
+パッケージ付属の \fIkon.cfg\fP では、 \fISTDPEL\fP と \fIREVPEL\fP の
+エントリがあります。 \fISTDPEL\fP は標準パレットで、 \fIREVPEL\fP
+はリバースです。希望するエントリの別名として \fIPELS\fP を指定して下さい。
+.PP
+その他には以下のようなエントリがあります:
+.TP 4
+\fIMOUSE\fP(choice)
+Microsoft, MouseSystems, BusMouse, MMSeries, Logitech, None
+より 1 つ選択。デフォルトは None。
+マウスドライバの種類を選択します。Logitech Mouse Man シリーズが動作
+しない場合は Microsoft を指定してみて下さい。
+.TP 4
+\fIMouseBaud\fP(choice)
+1200, 2400, 4800, 9600より選択。デフォルトは 1200。
+シリアルマウスのボーレートを選択します。 MOUSE に None, BusMouse 以
+外の値を指定した時に有効となります。
+.TP 4
+\fIMouseDev\fP(string)
+マウスのデバイス名を指定します。デフォルトは /dev/mouse です。
+\fIMOUSE\fP に None 以外のエントリを与えた時に有効です。
+.TP 4
+\fIMouse3Buttons\fP(boolean)
+3 ボタンマウスの場合にペーストボタンを中央に設定します。
+デフォルトは Off です。
+.TP 4
+\fIHardScroll\fP(boolean)
+ハードウエアスクロールを使うかどうかを指定します。 デフォルトは
+On です。 VGA, VGAFM, J31SX ドライバで有効です。
+.TP 4
+\fIBeepCounter\fP(numeric)
+ビープ音の長さを 1/100 秒単位で指定します。デフォルトは 5 です。
+.TP 4
+\fICursorInterval\fP(numeric)
+カーソル点滅間隔を 1/10 秒単位で指定します。デフォルトは 4 です。
+カーソルの点滅を止めるには 0 を指定します。
+.TP 4
+\fISaveTime\fP(numeric)
+スクリーンセイバが働くまでの時間を分単位で指定します。
+デフォルトは 4 です。
+.TP 4
+\fIKanjiCursor\fP(boolean)
+漢字の上にカーソルがある時、カーソルを全角幅にするかどうかを
+指定します。デフォルトは On です。
+.TP 4
+\fICursorTop\fP(numeric),\fICursorBottom\fP(numeric)
+この 2 つでカーソルボックスのサイズを指定します。
+.nf
+ 0 +--------+
+ | |
+ |--------| <-- CursorTop
+ |********|
+ |********|
+ |********|
+ |********|
+ |********|
+ 15 +--------+ <-- CursorBottom
+.fi
+VGA, VGAFM, CGA ドライバで有効です。
+.TP 4
+\fIBoxCursor\fP(boolean)
+カーソルの形状を下線のみでなく箱型にするかどうかを指定します。
+デフォルトは Off です。 J3100SX ドライバで有効です。
+.TP 4
+\fISavePlane3\fP(boolean)
+VGA メモリ第 3 ページのフォントデータを保存します。Trident 系以外で
+は不要です。デフォルトは Off です。 VGA, VGAFM ドライバで有効です。
+.TP 4
+\fIVgaFontOffset\fP(numeric)
+\fIVGAフォント\fPのオフセット値を指定します。デフォルトは 0 です。
+\fIVGAフォント\fPを半角フォントとして利用する場合、メーカによっては文字の
+下部が欠けることがあります。そのような時にこの値を指定することによって
+文字の位置を調整することができます。
+.TP 4
+\fICoding\fP(string)
+デフォルトで利用するフォントおよび 16bit でのコーディングを指定します。
+記述方法は、
+
+.br
+ <SB font> <DB font> [EUC|SJIS]
+
+となり、それぞれ以下のような指定をすることができます。
+.PP
+.TP 4
+ SB font: Single Byte フォント
+ ISO8859-1,ISO8859-2,ISO8859-3,ISO8859-4,ISO8859-5,
+ ISO8859-6,ISO8859-7,ISO8859-8,ISO8859-9,
+ JISX0201.1976-0
+.PP
+.TP 4
+ DB font: Double Byte フォント
+ GB2312.1980-1,JISX0208.1983-0,KSC5601,BIG5
+.PP
+.TP 4
+\fIStartupMessage\fP(boolean)
+起動時の greeting メッセージを出すかどうかを指定します。デフォルト
+は On です。
+.PP
+.SH 【高解像度モードの設定】
+\fIkon\fP では、ビデオドライバとして VGA, VGAFM を指定した場合に
+\fIkon.cfg\fP の設定によりテキストの広さを変更することができます。
+.TP 4
+\fIエントリ名\fP:
+.br
+ <\fIVGA\fP あるいは \fIVGAFM\fP>
+.br
+ [\fIVGAFM\fP の場合の間引き係数]
+.br
+ <HR> <HS> <HE> <HFL> <VR> <VS> <VE> <VFL>
+.br
+ <\fIクロック番号\fP>
+.br
+ <\fI行幅 - 1\fP> <\fI行数 - 1\fP>
+.PP
+3 行目(VGAドライバでは 2 行目)の画面制御パラメータは
+8 個の 10 進数の数値からなります。これは、Xconfig(4/5)
+におけるビデオモードデータベースとほぼ同じ内容です。
+ただし、\fIKON\fP では 800x600 までの解像度でテキストを
+エミュレートすることができます。
+.TP 4
+画面制御パラメータ
+.br
+.B HR
+水平ドット数
+.br
+.B HS
+水平同期始点
+.br
+.B HE
+水平同期終点
+.br
+.B HFL
+水平総フレーム数
+.br
+.B VR
+垂直ライン数
+.br
+.B VS
+垂直同期始点
+.br
+.B VE
+垂直同期終点
+.br
+.B VFL
+垂直総フレーム数
+.PP
+\fIクロック番号\fP にはそのエントリの画面モードが何番目のクロックを
+使用するかを指定します。実質有効なのは値の下位 2 ビットです。
+したがって、0 〜 3 の値のいずれかです。
+最後の行はエミュレートするテキスト画面の広さの指定です。
+.SH 【ファイル】
+.if n .ta 2.5i
+.if t .ta 1.8i
+/usr/local/lib/kon.cfg 環境設定ファイル
+.br
+/usr/lib/font/* フォントファイル
+.SH 【関連項目】
+swkon(1), fld(1)
+.SH 【注意事項】
+- テキストを高解像度モードにして \fILinux\fP を起動すると \fIVGAフォント\fP
+のサイズが異なりますので、正常に表示されなくなります。
+.br
+- \fIkon.cfg\fP において同じエントリ名が複数ある場合、最初のものが有効
+となります。また、1 行の長さの最大値は 255 バイトです。
+.br
+- \fIX Window System\fP との相性が良くない場合は \fIswkon(1)\fP で
+テキストモードに移り、マウスを切り離して \fIX Window System\fP をご利用
+下さい。
+.SH 【作者】
+.nf
+MANABE Takashi <manabe@papilio.tutics.tut.ac.jp>
+MAEDA Atusi <mad@nak.math.keio.ac.jp>
+KOMEDA Shinji <komeda@ics.es.osaka-u.ac.jp>
+YOSHIDA Kensyu <kensyu@rabbit.is.s.u-tokyo.ac.jp>
+obuk@MIX
+.fi
diff --git a/loader/kon2/doc/kon.doc b/loader/kon2/doc/kon.doc
new file mode 100644
index 000000000..0ae60c93f
--- /dev/null
+++ b/loader/kon2/doc/kon.doc
@@ -0,0 +1,393 @@
+ KON ----- Kanji ON Linux console -----
+
+ このファイルは KON の内部構造をドキュメント化したものです。まだ未完成ですが、
+バグ取りや改造の際の参考にして下さい。
+
+1.文字出力の流れ
+
+ KON では仮想テキスト VRAM を通して画面出力を行っています。PTY からの出力は
+BUFSIZ 単位でフラグメント化されて VT エミュレータに引き渡されます。VT エミュ
+レータは1文字ずつ解析して仮想テキストに出力します。1つのフラグメントが処理さ
+れた時点でコンソールがアクティブならば仮想テキストの内容をそのまま VGA 画面に書
+き込みます。
+
+1.1.疑似端末
+
+1.2.VT エミュレータ
+
+●構造体 con
+
+ VT エミュレータに於けるテキスト状態情報は con 構造体に記憶されています。
+VT エミュレータではテキスト座標系は左端を原点[0, 0]として計算しています。
+
+struct _con_info {
+ char x, 現在の X 座標
+ y, 現在の Y 座標
+ xmax, X 座標最大値
+ ymin, Y 座標最小値
+ ymax, Y 座標最大値
+ tab; TAB 個数
+ u_char fcol, フォアグランドカラー
+ bcol, バックグランドカラー
+ attr, 文字属性フラグ
+ sfonth, 半角フォントの高さ
+ wfonth, 全角フォントの高さ
+ knj1; 漢字コード第1バイト
+ enum {
+ ESC_NEUTRAL, ESC 外
+ ESC_START, '\x1B' 受信
+ ESC_BRA, '[' 受信
+ ESC_SI, '$' 受信
+ ESC_SO, '(' 受信
+ ESC_QUESTION, '?' 受信
+ } esc; エスケープシーケンスの状態変数
+ bool knj, JIS 漢字モードフラグ
+ soft, ソフトウェアスクロールフラグ
+ ins, 挿入モードフラグ
+ active, アクティブコンソールフラグ
+ saved, 焼き付け防止状態
+ wrap; wrap 状態フラグ
+};
+
+●変数 scrollLine
+
+ con.y がリージョン(con.ymin〜con.ymax の範囲)外になればスクロールする必要が
+有ります。しかし、uum などの FEP ではシステムラインに文字出力する際に必ずリー
+ジョン外になります。そこで、\Ey:xH によるカーソル移動に対してはスクロールしない
+ようにしました。これ以外の方法で con.y がリージョン外に出た場合は、変数
+scrollLine に適当なスクロール行数が加算されます。con.ymin より小さい場合は負
+数、con.ymax より大きい場合は正数がそれぞれ加算されます。制御コード(表示不可能
+文字)が入力された時点で変数 scrollLine を実際のスクロールに反映します。
+
+1.3.仮想テキスト
+
+ 仮想テキストは3つのバッファからなります。
+
+●テキストバッファ
+
+ テキストのキャラクタコードが格納されます。半角文字はその ASCII コードがそのま
+ま格納されます。漢字の場合は EUC/SJIS ともに JIS コードに変換されて格納されます。
+また、BIG5 では Mule 拡張の "ESC$(0" が来れば BIG5 の 16bit コードに変換されて
+格納されます。また、EUC の場合はどの言語でも漢字同様に 8bit が落されて格納され
+ますので、BIG5 で EUC にすると情報が落ちます。
+
+●色・属性バッファ
+
+ 色と属性の情報が格納されます。ただし、全角文字の場合は若いアドレスにしか格納
+されません。各ビットの意味は以下の様なものになっています。
+
+ MSB LSB
+ |b7|b6|b5|b4|b3|b2|b1|b0|
+
+ b2〜b0: フォアグランド色
+ b3: 未使用
+ b6〜b4: バックグランド色
+ b7: 下線属性
+
+●フラグバッファ
+
+ フラグバッファは該当テキストの変更情報と言語情報を持っています。MSBは変更情
+報で、テキストへの書き込みが起こると 0 になり、それが実画面へ反映されると 1 と
+なります。次の 2bit は Double Byte コードを意味しており、第 1 バイトならば b5
+が、第 2 バイトなら b6 が 1 となります。第 1 バイトの b3-b0 には言語情報が入り
+ます。今後、対応言語が増えれば b4 あるいは 第 2 バイトの空きビットを言語情報に
+割り当てる予定である。言語情報は、
+
+ enum {
+ DF_GB2312,
+ DF_JISX0208,
+ DF_KSC5601,
+ DF_JISX0212,
+ DF_BIG5_0,
+ DF_BIG5_1
+ };
+
+と定義しています。
+
+ MSB LSB
+ | b7| b6| b5|b4||b3|b2|b1|b0|
+ |CLEAN_S|LATCH_2|LATCH_1| ||<--------->|
+ |0=latch| byte2| byte1| || LANG|
+
+ 80x30 の 標準 VGA 画面でテキスト座標[5, 3](左隅は[0, 0])に「1あ」を白色背景色
+無しで表示すると、
+
+ 相対アドレス: 80 x 3 + 5 = 245
+ 「1」の ASCII コード: 0x31
+ 「あ」の JIS コード: 0x2422
+ 白色背景色なし: 00000111(B) = 0x07
+
+ textBuff[245] = 0x31
+ attrBuff[245] = 0x07
+ flagBuff[245] = 0x00
+
+ textBuff[246] = 0xA2
+ textBuff[247] = 0x24
+ attrBuff[246] = 0x07
+ attrBuff[247] = 0x07
+ flagBuff[246] = 0x22
+ flagBuff[247] = 0x40
+
+となります。
+
+2.VGA
+
+ 仮想テキストを採用することにより VGA 操作部分を小さくすることができました。
+EGA などへの移植も楽になったと思います。
+
+2.1.レジスタ
+
+2.2.基本操作
+
+●構造体 dInfo
+
+ 表示能力を示す情報を保存しています。各値は kon.cfg から読み込まれたもの、
+あるいはそれらにより算出されたものです。
+
+struct dispInfo {
+ int gsize; グラフィックメモリサイズ
+ = glineByte * gydim
+ short gxdim, グラフィック X ドット数
+ glineChar の整数倍になるように正規化された値
+ gydim, グラフィック Y ライン数
+ txmax, テキスト X 最大値(con.xmax の初期値)
+ tymax, テキスト Y 最大値(con.ymax の初期値)
+ glineChar, テキスト1行分のグラフィックライン数
+ = gydim / (tymax + 1)
+ glineByte, グラフィック1行分のバイト数
+ = gxdim / 8
+ tlineByte; テキスト1行分のグラフィックバイト数
+ = glineChar * glineByte
+};
+
+●構造体 cInfo
+
+ カーソルに関する情報です。点滅回数は偶数なら表示中を意味しており、スクリーン
+セイバーのカウンターにも使われています。addr は VgaSetCursorAddress によって
+計算されます。kanji はカーソル位置が全角なら非0値となります。表示スイッチは
+ESC シーケンスによって操作されます。
+
+struct cursorInfo {
+ short kanji; 漢字の上にあれば TRUE
+ u_int addr; VRAM アドレス
+ bool sw; FALSE なら表示禁止
+ int interval; 点滅間隔
+ int count; 点滅用カウント
+ bool shown; 表示中フラグ
+};
+
+2.3.WideText
+
+ KON では VGA を高解像度モードに移行するために VGA の CRT 制御レジスタと MISC
+レジスタを kon.cfg ファイルで指定できる様にしています。VGA 本来の規格からすれば
+800x600 までの解像度であれば CRT 制御レジスタと MISC レジスタのみによって VGA
+の解像度を変更できるように思えるのですが、SVGA カードが持つ複数のモードの殆んど
+は他のレジスタに依存しているようです。
+
+●構造体 regText, regGraph
+
+ VGA のレジスタ情報です。regGraph の場合は CRT 制御レジスタ、misc レジスタは
+kon.cfg から読み込まれます。CRT 制御レジスタは更に計算が施されます。dInfo.gydim
+は kon.cfg から読み込まれる時に表示有効な値に変換されます。この値を基に VGA 側
+の表示ライン数を変更する必要があります。表示ライン数は CRT 制御レジスタにあり、
+ 0x12 の全ビット : 下位16ビット
+ 0x07 の第2ビット: 第9ビット
+ 0x07 の第7ビット: 第10ビット
+となっていますので、
+ regGraph.crt[0x12] = (dInfo.gydim - 1) & 0xFF;
+ regGraph.crt[7] &= 0xBD;
+ regGraph.crt[7] |= ((dInfo.gydim - 1) & 0x100) >> 7;
+ regGraph.crt[7] |= ((dInfo.gydim - 1) & 0x200) >> 3;
+という操作を施しています。
+
+struct vgaRegs {
+ u_char crt[VGACRT_CNT], CRT 制御レジスタ
+ att[VGAATTR_CNT], 属性レジスタ
+ gra[VGAGRP_CNT], グラフィックス制御レジスタ
+ seq[VGASEQ_CNT], シーケンサ
+ mis; misc レジスタ
+};
+
+●変数 LineComp8, LineComp9
+
+ ライン比較レジスタは 0x18 にありますが、その第9ビットと第10ビットはそれぞれ
+0x07 および 0x09 にあります。これらのビット以外の値とレジスタ番号をまとめた物が
+LineComp8 と LineComp9 です。
+
+3.ソケットによる通信
+
+ 様々な拡張性を考えてソケットを用意したのですが、まだフォントロードにしか使わ
+れていません。まともなプロトコルを作成・実装する知識も時間もないので通信方式が
+いい加減なものになっています。
+
+3.1.ソケット名
+
+ KON のソケットは /tmp に作成されます。その名前は .kon の後に数文字1文字をと
+もなっています。この数字は KON が利用している疑似端末名の末尾の数文字と等しくな
+ります。また、GON ライブラリの SocketClientOpen 関数を利用すれば自動的に適当な
+ソケット名を使うので、名前を意識すること無くソケットをオープンすることができま
+す。
+
+3.2.基本的な通信方式
+
+ 通信は messageHeader 構造体を用いて行われます。
+
+ struct messageHeader {
+ u_char cno, クライアント番号(未使用)
+ cmd; 機能コード
+ };
+
+ クライアントが機能コードを指定することによって通信が開始されます。機能コード
+は半角文字1文字です。
+
+ S: 半角文字フォントロード
+ W: 全角文字フォントロード
+
+機能コードを認識した KON は ACK を機能コードとしいて送り返します。認識でき
+なかった場合は NAK を返します。以後、データを受信するごとに KON は ACK あるい
+は NAK を送信します。クライアント側は NAK を受け取れば直ちに送信を中止なけれ
+ばなりません。
+
+3.3.フォントロードの方式
+
+ フォントローダが KON にフォントデータを送信する際の手順について説明します。
+
+ フォントローダ (fld.*) <-- /usr/tmp/.kon? --> KON
+
+ Function: S|W -------------------->
+ S = 半角フォント
+ W = 漢字フォント
+ <-------------------- 肯定応答 (ACK)
+ fontInfo 構造体 -------------------->
+ <-------------------- 肯定応答 (ACK)
+ フォントデータを BUFSIZ でフラグメント化して以下を繰り返す:
+ データグラム -------------------->
+ <-------------------- 肯定応答 (ACK)
+
+4.マウスドライバ
+
+ マウスドライバは selection-1.4 を参考に書きました。したがって5機種対応となっ
+ていますが、こちらでテストしているのは MircoSoft と Mouse Systems のみです。
+
+●構造体 mInfo
+
+ マウスに関する情報を管理しています。座標情報は全てテキスト座標系で表現されて
+います。カーソル表示寿命はカーソルが点滅するごとにデクリメントされ、0になった
+時点でマウスカーソルが表示されなくなります。マウスの状態が変化した時は常にこの
+値を MOUSE_LIFETIME(デフォルト 22) で初期化するようになっています。
+
+struct mouseInfo {
+ char x, y, マウスカーソル位置
+ dx, dy, マウスカーソル移動値
+ sx, sy, 左ボタンクリック位置
+ sw, カーソル表示寿命
+ stat; ボタン状態
+};
+
+●変数 dx, dy
+
+ 関数 MouseAnalyzePacket で使われている static 変数 dx, dy はグラフィックス
+座標系のマウス移動値です。マウスをゆっくりと動かした場合でもちゃんと反映される
+様にするために用意しました。
+
+●変数 oldstat
+
+ 関数 MouseAnalyzePacket で使われている static 変数 oldstat は mInfo.stat の
+前回の状態です。
+
+●ファイル /tmp/.kontmp
+
+ マウスでカットしたバッファを格納するファイルです。
+
+5.多言語に関する扱い
+
+ フォントは lib/coding.c に登録されているものが利用できます。新たなフォント
+の登録は Single Byte の場合は coding.c:fSRegs, coding.c:fldSRegs に、
+Double Byte の場合は coding.c:fDRegs, coding.c:fldDRegs, そして vt.h の
+DF_?????? に記述して下さい。それぞれの情報は 1 対 1 になっていますので、
+順序を守って下さい。
+
+6.GON ライブラリ
+
+ KON との通信を容易に行うために用意したライブラリです。
+
+6.1.メモリ操作関数
+
+■void PortOutw(u_short value, u_short port)
+
+ I/O ポートへ2バイト単位の出力を行います。
+
+■void PortOutb(char value, u_short port)
+
+ I/O ポートへ1バイト単位の出力を行います。
+
+■u_char PortInb(unsigned short port)
+
+ I/O ポートから1バイト単位の入力を行います。
+
+■void bzero2(void *buff, int n)
+
+ stosb を使った高速なゼロ埋め関数です。結果は bzero と同じです。
+
+■void wzero(void *buff, int n)
+
+ stosw を使った高速なゼロ埋め関数です。n バイトをゼロ埋めすることに注意して
+下さい。
+
+■void lzero(void *buff, int n)
+
+ stosl を使った高速なゼロ埋め関数です。n バイトをゼロ埋めすることに注意して
+下さい。
+
+■void bmove(void *dst, void *src, int n)
+
+ movsb を使った高速なバッファ転送関数です。
+
+■void brmove(void *dst, void *src, int n)
+
+ movsb を使った高速な逆方向バッファ転送関数です。src, dst から逆方向に n
+バイトの転送を行います。
+
+■void wmove(void *dst, void *src, int n)
+
+ movsw を使った高速なバッファ転送関数です。n バイト転送することに注意して下
+さい。
+
+■void lmove(void *dst, void *src, int n)
+
+ movsl を使った高速なバッファ転送関数です。n バイト転送することに注意して下
+さい。
+
+6.2.ソケット操作関数
+
+■void SocketKill(int fd)
+
+ ファイルディスクプリタで指定されたソケットをクローズし、KON のソケットを
+削除する。
+
+■int SocketRecCommand(int fd, struct messageHeader *mh)
+
+ ソケットから、messageHeader 構造体を読み込む
+
+■int SocketSendCommand(int fd, char *cmd)
+
+ クライアントから、KON に機能コードを送ります。
+
+■int SocketClientOpen()
+
+ KON のソケットをオープンします。
+
+■int SocketSendData(u_char *buff, int size, int fd)
+
+ データバッファを BUFSIZ でフラグメント化しながらソケットへ送り出します。
+
+■char socketName[MAX_SOCKET_NAME+1]
+
+ 関数 SocketClientOpen で作成されたソケット名が記憶されるバッファです。
+
+6.3.その他
+
+■FILE *CapSearchLabel(char *label)
+
+ kon.cfg から指定されたラベルを検索する関数。ラベルの別名も調べる。一致する
+ラベルを見つけた場合は FILE 構造体へのポインタを返す。
diff --git a/loader/kon2/font/Makefile b/loader/kon2/font/Makefile
new file mode 100644
index 000000000..be3a81541
--- /dev/null
+++ b/loader/kon2/font/Makefile
@@ -0,0 +1,31 @@
+OBJ = fld.o minix.o fontx2.o bdf.o j3100.o
+
+ifeq (../.config,$(wildcard ../.config))
+include ../.config
+endif
+
+#CC = cc -g
+#LD = cc -g
+
+LOADLIBES = $(LIB)
+
+all: fld
+
+fld: $(OBJ) $(LIB)
+ $(LD) -o fld $(OBJ) $(LIB)
+
+bdfcat: bdf.c $(LIB)
+ $(CC) $(CFLAGS) -DBDFCAT -o bdfcat bdf.c $(LIB)
+
+depend .depend:
+ $(CC) $(CFLAGS) -M *.c > .depend
+
+clean:
+ $(RM) *.o fld fontx.c *~ .depend
+
+install: fld
+ $(INSTALL) -m 4755 fld $(BINDIR)
+
+ifeq (.depend,$(wildcard .depend))
+include .depend
+endif
diff --git a/loader/kon2/font/Makefile.FreeBSD b/loader/kon2/font/Makefile.FreeBSD
new file mode 100644
index 000000000..84a2317fd
--- /dev/null
+++ b/loader/kon2/font/Makefile.FreeBSD
@@ -0,0 +1,23 @@
+# Tatsumi Hosokawa <hosokawa@jp.FreeBSD.org>
+
+SRCS= fld.c minix.c fontx2.c bdf.c # j3100.c
+CFLAGS+= -I${.CURDIR}/../include
+CLEANFILES= Makefile
+
+NOMAN= YES
+
+.if exists(${.CURDIR}/../.config)
+.include "${.CURDIR}/../.config"
+.endif
+
+PROG= fld
+
+.if exists(${.OBJDIR}/../lib)
+LIBOBJ= -L${.OBJDIR}/../lib
+.else
+LIBOBJ= -L${.CURDIR}/../lib
+.endif
+
+LDADD= ${LIBOBJ} -lgon
+
+.include <bsd.prog.mk>
diff --git a/loader/kon2/font/Makefile.linux b/loader/kon2/font/Makefile.linux
new file mode 100644
index 000000000..be3a81541
--- /dev/null
+++ b/loader/kon2/font/Makefile.linux
@@ -0,0 +1,31 @@
+OBJ = fld.o minix.o fontx2.o bdf.o j3100.o
+
+ifeq (../.config,$(wildcard ../.config))
+include ../.config
+endif
+
+#CC = cc -g
+#LD = cc -g
+
+LOADLIBES = $(LIB)
+
+all: fld
+
+fld: $(OBJ) $(LIB)
+ $(LD) -o fld $(OBJ) $(LIB)
+
+bdfcat: bdf.c $(LIB)
+ $(CC) $(CFLAGS) -DBDFCAT -o bdfcat bdf.c $(LIB)
+
+depend .depend:
+ $(CC) $(CFLAGS) -M *.c > .depend
+
+clean:
+ $(RM) *.o fld fontx.c *~ .depend
+
+install: fld
+ $(INSTALL) -m 4755 fld $(BINDIR)
+
+ifeq (.depend,$(wildcard .depend))
+include .depend
+endif
diff --git a/loader/kon2/font/bdf.c b/loader/kon2/font/bdf.c
new file mode 100644
index 000000000..05225958a
--- /dev/null
+++ b/loader/kon2/font/bdf.c
@@ -0,0 +1,162 @@
+/*
+ * KON2 - Kanji ON Console -
+ * Copyright (C) 1992-1996 Takashi MANABE (manabe@papilio.tutics.tut.ac.jp)
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY TAKASHI MANABE ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE TERRENCE R. LAMBERT BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/ioctl.h>
+#include <sys/file.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <errno.h>
+
+#include <interface.h>
+#include <fnld.h>
+
+extern struct fontInfo fi;
+extern forceLoad;
+
+u_char *FontLoadBdf(fp)
+FILE *fp;
+{
+ char *fdata = NULL, line[256], *p, *w, reg[256];
+ u_char ch, ch2;
+ int num, width, high, i, code, data, k, n;
+ struct fontRegs *fReg;
+ struct fontLoaderRegs *fldReg;
+
+ fReg = &fSRegs[0];
+ fldReg = &fldSRegs[0];
+ fi.type = CodingByRegistry("ISO8859-1");
+ num = width = high = 0;
+ while(fgets(line, 256, fp)) {
+ if (!width && !high &&
+ !strncmp("FONTBOUNDINGBOX", line,
+ strlen("FONTBOUNDINGBOX"))) {
+ p = line + sizeof("FONTBOUNDINGBOX");
+ sscanf(p, "%d %d", &width, &high);
+ } else if (!strncmp("CHARSET_REGISTRY", line, 16)) {
+ p = line + sizeof("CHARSET_REGISTRY");
+ while(*p != '"') p ++;
+ w = ++p;
+ while(*p != '"') p ++;
+ *p = '\0';
+ strcpy(reg, w);
+ } else if (!strncmp("CHARSET_ENCODING", line, 16)) {
+ p = line + sizeof("CHARSET_ENCODING");
+ while(*p != '"') p ++;
+ w = ++p;
+ while(*p != '"') p ++;
+ *p = '\0';
+ strcat(reg, "-");
+ strcat(reg, w);
+ fi.type = CodingByRegistry(reg);
+ } else if (!num && !strncmp("CHARS ", line, 6)) {
+ p = line + sizeof("CHARS");
+ sscanf(p, "%d", &num);
+ break;
+ }
+ }
+ fi.width = width;
+ fi.high = high;
+ if (fi.type & CHR_DBC) {
+ fldReg = &fldDRegs[fi.type&~CHR_DFLD];
+ fReg = &fDRegs[fi.type&~CHR_DFLD];
+ if (fldReg->max)
+ fi.size = fldReg->addr(fldReg->max >> 8, fldReg->max & 0xFF)
+ + 16;
+ else
+ fi.size = (width / 8 + ((width % 8 > 0) ? 1: 0)) * num * 16;
+ width = 0;
+ } else {
+ fldReg = &fldSRegs[fi.type&~CHR_SFLD];
+ fReg = &fSRegs[fi.type&~CHR_SFLD];
+ if (fldReg->max)
+ fi.size = fldReg->max * 16;
+ else
+ fi.size = num * 16;
+ }
+ if ((fdata = (u_char *)malloc(fi.size)) == NULL) return(NULL);
+ k = 0;
+ while(fgets(line, 256, fp)) {
+ if (!strncmp("ENCODING", line, strlen("ENCODING"))) {
+ p = line + sizeof("ENCODING");
+ code = atoi(p);
+ } else if (!strncmp("BITMAP", line, strlen("BITMAP"))) {
+ p = fdata + code * 16;
+ k ++;
+#ifdef BDFCAT
+ printf("----- %X -----\n", code);
+#endif
+ if (!(fi.type & CHR_DBC)) {
+ for (i = 0; i < fi.high; i ++, p ++) {
+ fscanf(fp, "%2X", &data);
+#ifdef BDFCAT
+ for (n = 0; n < 7; n ++)
+ printf("%c", ((data << n) & 0x80) ? '#':' ');
+ printf("\n");
+#else
+ *p = data;
+#endif
+ }
+ } else {
+ ch = (code >> 8) & 0xFF;
+ ch2 = code & 0xFF;
+ num = fldReg->addr(ch, ch2);
+ if (num > width) width = num;
+ p = fdata + num;
+ for (i = 0; i < fi.high; i ++, p ++) {
+ fscanf(fp, "%4X", &data);
+#ifdef BDFCAT
+ for (n = 0; n < 15; n ++)
+ printf("%c", ((data << n) & 0x80) ? '#':' ');
+ printf("\n");
+#else
+ *p = (data >> 8) & 0xFF;
+ p ++;
+ *p = data & 0xFF;
+#endif
+ }
+ }
+ }
+ }
+ return(fdata);
+}
+
+#ifdef BDFCAT
+struct fontInfo fi;
+forceLoad;
+
+void main(int argc, char *argv[])
+{
+ FILE *fp;
+
+ fp = fopen(argv[1], "r");
+ FontLoadBdf(fp);
+}
+#endif
diff --git a/loader/kon2/font/fld.c b/loader/kon2/font/fld.c
new file mode 100644
index 000000000..d27a7ab35
--- /dev/null
+++ b/loader/kon2/font/fld.c
@@ -0,0 +1,258 @@
+/*
+ KON - Kanji ON Linux Console -
+ Copyright (C) 1992, 1993 Takashi MANABE (manabe@tut.ac.jp)
+
+ KON 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.
+
+ KON 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/file.h>
+#include <string.h>
+#include <ctype.h>
+#include <sys/ipc.h>
+#include <sys/shm.h>
+#include <sys/socket.h>
+#include <errno.h>
+
+#include <interface.h>
+#include <fnld.h>
+
+int forceLoad=1;
+struct fontInfo fi;
+
+u_char *FontLoadMinix();
+u_char *FontLoadFontx();
+u_char *FontLoadBdf();
+#if defined(linux)
+u_char *FontLoadJ3100();
+#endif
+
+static struct {
+ char *type;
+ u_char* (*loader)(FILE *fp);
+} fontLoaders[] = {
+ {"minix", FontLoadMinix},
+ {"fontx", FontLoadFontx},
+ {"bdf", FontLoadBdf},
+ {"j3100", NULL},
+ {NULL, NULL}
+};
+
+void UnloadShmem(char fnum)
+{
+ key_t shmkey;
+ int shmid;
+ struct shmid_ds shmseg;
+
+#if defined(linux)
+ shmkey = ftok(CONFIG_NAME, fnum);
+#elif defined(__FreeBSD__)
+ shmkey = 5000 + (fnum & 0x7F);
+#endif
+ if ((shmid = shmget(shmkey, sizeof(struct fontInfo), 0444)) < 0)
+ return;
+ shmctl(shmid, IPC_STAT, &shmseg);
+ if (shmseg.shm_nattch < 1) {
+ shmctl(shmid, IPC_RMID, 0);
+ }
+}
+
+int CheckLoadedFont(char fnum)
+{
+ key_t shmkey;
+ extern int forceLoad;
+
+ if (forceLoad) return(EOF);
+#if defined(linux)
+ shmkey = ftok(SHMEM_NAME, fnum);
+#elif defined(__FreeBSD__)
+ shmkey = 5000 + (fnum & 0x7F);
+#endif
+ if (shmget(shmkey, 1, 0444) == EOF) return(EOF);
+ return(0);
+}
+
+static
+ void ShmFont(char *prog, u_char *font, struct fontInfo *fi)
+{
+ key_t shmkey;
+ int shmid;
+ u_char *shmbuff;
+
+#if defined(linux)
+ shmkey = ftok(SHMEM_NAME, fi->type);
+#elif defined(__FreeBSD__)
+ shmkey = 5000 + (fi->type & 0x0000007F);
+#endif
+ shmid = shmget(shmkey, fi->size+sizeof(struct fontInfo),
+ IPC_CREAT|0666);
+ shmbuff = shmat(shmid, 0, 0);
+ memcpy(shmbuff, fi, sizeof(struct fontInfo));
+ memcpy(shmbuff + sizeof(struct fontInfo), font, fi->size);
+ shmdt(shmbuff);
+ fprintf(stderr, "%s> load %s in shmem(%d): %d Bytes\n",
+ prog,
+ (fi->type & CHR_DBC) ?
+ fDRegs[fi->type&~CHR_DFLD].registry:
+ fSRegs[fi->type&~CHR_SFLD].registry,
+ shmid, fi->size);
+}
+
+int SetFont(char *prog, u_char *font, struct fontInfo *fi)
+{
+ int s;
+
+ if ((s = SocketClientOpen()) > 0) {
+ SocketSendCommand(s, CHR_UNLOAD);
+ close(s);
+ }
+ ShmFont(prog, font, fi);
+ if ((s = SocketClientOpen()) > 0) {
+ SocketSendCommand(s, CHR_LOAD);
+ close(s);
+ }
+ return(0);
+}
+
+void
+ShowShmem(u_char fnum)
+{
+ key_t shmkey;
+ int shmid;
+ struct fontInfo *fi;
+
+#if defined(linux)
+ shmkey = ftok(CONFIG_NAME, fnum);
+#elif defined(__FreeBSD__)
+ shmkey = 5000 + (fnum & 0x7F);
+#endif
+ if ((shmid = shmget(shmkey, sizeof(struct fontInfo), 0444)) < 0)
+ return;
+ fi = (struct fontInfo*)shmat(shmid, 0, SHM_RDONLY);
+ if (fi) {
+ printf("%3X %6d %-15s %2dx%2d %7d\n",
+ fnum&~CHR_SFLD,
+ shmid,
+ (fnum & CHR_DBC) ?
+ fDRegs[fnum&~CHR_DFLD].registry:
+ fSRegs[fnum&~CHR_SFLD].registry,
+ fi->width,
+ fi->high,
+ fi->size);
+ }
+}
+
+void ShowFont()
+{
+ int i;
+
+ i = 0;
+ printf(" No. ShmId Font Name Size MemSize\n"
+ "+---+-----+---------------+-----+-------+\n");
+ while (fSRegs[i].registry) {
+ ShowShmem(i|CHR_SFLD);
+ i ++;
+ }
+ i = 0;
+ while (fDRegs[i].registry) {
+ ShowShmem(i|CHR_DFLD);
+ i ++;
+ }
+}
+
+void main(argc, argv)
+int argc;
+char *argv[];
+{
+ int i, n;
+ FILE *fp = stdin;
+ enum {ST_ARG, ST_UNLOAD, ST_TYPE} st=ST_ARG;
+ char file[256], *type, *p;
+ u_char *font;
+
+ if ((p = index(argv[0], '.')) != NULL) type = p + 1;
+ for (i = 1; i < argc; i ++) {
+ p = argv[i];
+ switch(st) {
+ case ST_UNLOAD:
+ if (isxdigit(*p)) {
+ sscanf(p, "%X", &n);
+ fprintf(stderr, "%s> unload %X(%s)\n", argv[0], n,
+ (n & CHR_DBC) ?
+ fDRegs[n&~CHR_DFLD].registry:
+ fSRegs[n&~CHR_SFLD].registry);
+ UnloadShmem(n | CHR_SFLD);
+ break;
+ }
+ st = ST_ARG;
+ case ST_ARG:
+ if (*p == '-') {
+ ++p;
+ switch(*p) {
+ case 'n':
+ forceLoad = 0;
+ break;
+ case 'u':
+ st = ST_UNLOAD;
+ break;
+ case 't':
+ st = ST_TYPE;
+ break;
+ case 'i':
+ ShowFont();
+ exit(0);
+ break;
+ }
+ } else {
+ if(!(fp = fopen(argv[i], "r"))) {
+ fprintf(stderr, "%s> Can not open font file.\n", argv[0]);
+ exit(EOF);
+ }
+ }
+ break;
+ case ST_TYPE:
+ type = p;
+ st = ST_ARG;
+ break;
+ }
+ }
+ if (st == ST_UNLOAD) exit(0);
+ i = 0;
+ while (fontLoaders[i].type) {
+ if (!strcasecmp(fontLoaders[i].type, type))
+ break;
+ i ++;
+ }
+ if (!fontLoaders[i].type) {
+ fprintf(stderr, "%s> type %s is not supported.\n",
+ argv[0], type);
+ exit(EOF);
+ }
+#if defined(linux)
+ if (!fontLoaders[i].loader)
+ font = FontLoadJ3100(argc, argv);
+ else
+#endif
+ font = fontLoaders[i].loader(fp);
+ if (font == NULL) {
+ fprintf(stderr, "%s> Can not load font.\n", argv[0]);
+ exit(EOF);
+ }
+ if (fp != stdin) fclose(fp);
+ exit(SetFont(argv[0], font, &fi));
+}
diff --git a/loader/kon2/font/fontx2.c b/loader/kon2/font/fontx2.c
new file mode 100644
index 000000000..ead054c1b
--- /dev/null
+++ b/loader/kon2/font/fontx2.c
@@ -0,0 +1,213 @@
+/*
+ * KON2 - Kanji ON Console -
+ * Copyright (C) 1992, 1993
+ * kensyu@rabbit.is.s.u-tokyo.ac.jp
+ * nozomi@yucca.cc.tsukuba.ac.jp
+ * Copyright (C) 1992-1996 Takashi MANABE (manabe@papilio.tutics.tut.ac.jp)
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY TAKASHI MANABE ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE TERRENCE R. LAMBERT BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#define FXLD_C
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/ioctl.h>
+#include <sys/file.h>
+#include <string.h>
+#include <sys/socket.h>
+
+#include <interface.h>
+#include <fnld.h>
+
+extern struct fontInfo fi;
+extern forceLoad;
+
+struct fontx {
+ char title[6];
+ char name[8];
+ unsigned char xsize;
+ unsigned char ysize;
+ unsigned char type;
+
+ unsigned char ntable;
+ struct tn { unsigned short top, tail; } table[1 /* = ntable */];
+};
+
+#define FontxhTop 17
+#define MSDOS 1
+#define nSFontx 256
+
+static struct fontx* LoadFontxHeader(FILE *fp){
+ struct fontx head;
+ struct fontx* ans;
+#if !MSDOS
+ fread(&head.title, 6, 1, fp);
+ fread(&head.name, 8, 1, fp);
+ fread(&head.xsize, 1, 1, fp);
+ fread(&head.ysize, 1, 1, fp);
+ fread(&head.type, 1, 1, fp);
+ fread(&head.ntable, 1, 1, fp);
+#else
+ fread(&head, sizeof(struct fontx) - sizeof(struct tn), 1, fp);
+#endif
+ if(head.type & 1){
+ ans = malloc(sizeof(struct fontx) + sizeof(struct tn)*(head.ntable-1));
+ *ans = head;
+#if !MSDOS
+ for(i=1;i<head.ntable;i++)fread(ans->table + i,sizeof(struct tn),1,fp);
+#else
+ fread(ans->table, sizeof(struct tn), head.ntable, fp);
+#endif
+ fseek(fp, FontxhTop + 1 + ans->ntable * 4, SEEK_SET);
+ }else{
+ ans = malloc(sizeof(struct fontx));
+ *ans = head;
+ fseek(fp, FontxhTop, SEEK_SET);
+ };
+ return ans;
+};
+
+u_char *FontLoadSFontx(fp, header)
+FILE *fp;
+struct fontx *header;
+{
+ u_char *fontbuff;
+
+ fi.width = header->xsize;
+ fi.high = header->ysize;
+ fi.size = ((header->xsize - 1)/8 + 1) * header->ysize * nSFontx;
+ fontbuff = (u_char *)calloc(fi.size, nSFontx);
+ fread(fontbuff, fi.size, nSFontx, fp);
+ return(fontbuff);
+}
+static unsigned int sjis2num(unsigned int code){
+ unsigned int cl, ch;
+ /* to jis */
+ ch = (code >> 8) & 0xFF;
+ cl = code & 0xFF;
+
+ ch -= (ch > 0x9F) ? 0xC1: 0x81;
+ if (cl >= 0x9F) {
+ ch = (ch << 1) + 0x22;
+ cl -= 0x7E;
+ } else {
+ ch = (ch << 1) + 0x21;
+ cl -= ((cl <= 0x7E) ? 0x1F: 0x20);
+ }
+ /* to num */
+ if (ch > 0x2A){
+ return (cl - 0x41 + (ch - 0x26) * 96);
+ }else{
+ return (cl - 0x21 + (ch - 0x21) * 96);
+ }
+}
+
+u_char *FontLoadDFontx(fp, header)
+FILE *fp;
+struct fontx *header;
+{
+ u_char *fontbuff;
+ unsigned i, code, nchar;
+ int char_byte;
+
+ for(i = 0, nchar = 0; i < header->ntable; i++){
+ nchar += header->table[i].tail - header->table[i].top + 1;
+ }
+ fi.width = header->xsize;
+ fi.high = header->ysize;
+ char_byte = ((header->xsize - 1)/8 + 1) * header->ysize;
+ fi.size = char_byte * (sjis2num(header->table[header->ntable-1].tail) + 1);
+
+ fontbuff = (u_char *)malloc(fi.size);
+
+ for(i = 0; i < header->ntable; i++){
+ for(code = header->table[i].top; code <= header->table[i].tail; code ++){
+ if ((code & 0xFF) == 0x7F){ /* for buggy font (0x7E == 0x7F) */
+ fseek(fp, char_byte, SEEK_CUR);
+ continue;
+ }
+ fread(fontbuff + sjis2num(code) * char_byte, char_byte, 1, fp);
+ }
+ }
+ return(fontbuff);
+}
+
+u_char *FontLoadFontx(FILE *fp)
+{
+ u_char *font;
+ struct fontx *header;
+
+ header = LoadFontxHeader(fp);
+ if (header->type & 1) {
+ fi.type = CodingByRegistry("JISX0208.1983-0");
+ if (forceLoad || CheckLoadedFont(fi.type))
+ font = FontLoadDFontx(fp, header);
+ else exit(0);
+ } else {
+ fi.type = CodingByRegistry("JISX0201.1976-0");
+ if (CheckLoadedFont(fi.type))
+ font = FontLoadSFontx(fp, header);
+ else exit(0);
+ }
+ free(header);
+ return(font);
+}
+
+#if 0
+void main(argc, argv)
+int argc;
+char *argv[];
+{
+ FILE *fp;
+ u_char *font;
+ int i, loaded=0;
+ char *p;
+
+ for (i = 1; i < argc; i ++) {
+ p = argv[i];
+ if (*p == '-') {
+ ++p;
+ switch(*p) {
+ case 'n':
+ forceLoad = 0;
+ break;
+ }
+ } else {
+ if(!(fp = fopen(argv[i], "r"))) {
+ fprintf(stderr, "%s> Can not open font file.\n", argv[0]);
+ exit(EOF);
+ }
+ loaded = 1;
+ }
+ }
+ if (!loaded) fp = stdin;
+ if ((font = FontLoadFontx(fp))== NULL) {
+ fprintf(stderr, "%s> Can not load font file.\n", argv[0]);
+ exit(EOF);
+ }
+ fclose(fp);
+
+ exit(SetFont(argv[0], font, &fi));
+}
+#endif
diff --git a/loader/kon2/font/j3100.c b/loader/kon2/font/j3100.c
new file mode 100644
index 000000000..d19a03baa
--- /dev/null
+++ b/loader/kon2/font/j3100.c
@@ -0,0 +1,297 @@
+/*
+ KON Font Loader for J-3100 (TOSHIBA), Version 0.3(1993/ 9/ 3)
+ Copyright (C) 1993, Kazumasa KAWAI (kazu@jl1keo.tama.prug.or.jp)
+ Copyright (C) 1992, 1993 MAEDA Atusi (mad@math.keio.ac.jp)
+*/
+/*
+ * KON2 - Kanji ON Console 2 -
+ * Copyright (C) 1992-1996 Takashi MANABE (manabe@papilio.tutics.tut.ac.jp)
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY TAKASHI MANABE ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE TERRENCE R. LAMBERT BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#define FXLD_C
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/ioctl.h>
+#include <sys/file.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/mman.h>
+/* #include <linux/mm.h> */
+#include <asm/page.h>
+#include <mem.h>
+
+#include <fnld.h>
+#include <interface.h>
+
+#define ANK_BASE 0xFC000
+#define ANK_SIZE 0x4000
+#define SCHAR_SIZE (16*1) /* Size of one hankaku char (bytes) */
+#define HANKAKU_OFFSET 32 /* No font for first 32 chars */
+#define SFONT_SIZE (256*SCHAR_SIZE) /* Font for 32(10)...128(10) */
+#define KANJI_BASE 0xE0000
+#define KANJI_SIZE 0x10000
+#define MINKANJI 0x2121
+#define MAXKANJI 0x7424
+
+static char *fontrom;
+
+extern struct fontInfo fi;
+
+#define get_kfontoft(k1,k2) (((k1) > 0x29) ? \
+ ((((k2) - 0x40) + ((k1) - 0x25) * 96) << 5) : \
+ ((((k2) - 0x20) + ((k1) - 0x20) * 96) << 5))
+
+#define get_afontoft(c) (c << 4)
+
+static u_char *FontLoads(boldMode, Source)
+int boldMode, Source;
+{
+ int devMem, i;
+ u_short word;
+ u_char *fontbuf, bankNum;
+ u_int offset;
+
+ if (Source) { /* from BIOS ROM */
+ if ((devMem = open("/dev/mem", O_RDWR) ) < 0) {
+ fprintf(stderr, "Can not open /dev/mem.\n");
+ exit(EOF);
+ }
+ if ((fontrom = malloc(ANK_SIZE + (PAGE_SIZE-1))) == NULL) {
+ fprintf(stderr, "Memory allocation error.\n");
+ exit (EOF);
+ }
+ if ((unsigned long)fontrom % PAGE_SIZE)
+ fontrom += PAGE_SIZE - ((unsigned long)fontrom % PAGE_SIZE);
+ fontrom = (unsigned char *)mmap(
+ (caddr_t)fontrom,
+ ANK_SIZE,
+ PROT_READ,
+ MAP_SHARED|MAP_FIXED,
+ devMem,
+ ANK_BASE
+ );
+ if ((long)fontrom < 0) {
+ fprintf(stderr, "Can not map memory.\n");
+ exit(EOF);
+ }
+
+ if ((fontbuf = (u_char *)malloc(get_afontoft(256))) == NULL)
+ return(NULL);
+ fi.size = get_afontoft(128);
+ if (Source == 1)
+ offset = 0xA00;
+ else
+ offset = 0xC00;
+ bmove(fontbuf, fontrom + offset, fi.size);
+ } else { /* from KANJI ROM */
+ if ((devMem = open("/dev/mem", O_RDWR) ) < 0) {
+ fprintf(stderr, "Can not open /dev/mem.\n");
+ exit(EOF);
+ }
+ if ((fontrom = valloc(KANJI_SIZE)) == NULL ||
+ (fontbuf = calloc(1, SFONT_SIZE)) == NULL) {
+ fprintf(stderr, "Memory allocation error.\n");
+ exit (EOF);
+ }
+ fontrom = (u_char *)mmap(
+ (caddr_t)fontrom,
+ KANJI_SIZE,
+ PROT_READ|PROT_WRITE,
+ MAP_SHARED|MAP_FIXED,
+ devMem,
+ KANJI_BASE
+ );
+ bankNum = 0x80;
+ *fontrom = bankNum;
+ for (i = HANKAKU_OFFSET*SCHAR_SIZE, offset = 0; i < (SFONT_SIZE/2); i ++) {
+ word = *(u_short *) (fontrom + offset);
+ fontbuf[i] = (word & 0xff);
+ offset += 2;
+ }
+ }
+ /* kana */
+/*
+ if ((devMem = open("/dev/mem", O_RDWR) ) < 0) {
+ fprintf(stderr, "Can not open /dev/mem.\n");
+ exit(EOF);
+ }
+*/
+ if ((fontrom = valloc(KANJI_SIZE)) == NULL) {
+ fprintf(stderr, "Memory allocation error.\n");
+ exit (EOF);
+ }
+ fontrom = (u_char *)mmap(
+ (caddr_t)fontrom,
+ KANJI_SIZE,
+ PROT_READ|PROT_WRITE,
+ MAP_SHARED|MAP_FIXED,
+ devMem,
+ KANJI_BASE
+ );
+ bankNum = 0x80;
+ *fontrom = bankNum;
+ for (i = 0xa00, offset = get_kfontoft(0x29, 0x20); i < 0xe00; i ++) {
+ word = *(u_short *) (fontrom + offset);
+ fontbuf[i] = (word & 0xff);
+ offset += 2;
+ }
+ fi.size = SFONT_SIZE;
+ if (boldMode) {
+ for (i = 0; i < fi.size; i++) {
+ *(fontbuf + i) |= *(fontbuf + i) >> 1;
+ }
+ }
+ return(fontbuf);
+}
+
+static u_char *FontLoadw(boldMode)
+int boldMode;
+{
+ size_t start;
+ int devMem, i; /* , l; JL1KEO */
+ u_char *fontbuf;
+
+ if ((devMem = open("/dev/mem", O_RDWR) ) < 0) {
+ fprintf(stderr, "Can not open /dev/mem.\n");
+ exit(EOF);
+ }
+ if ((fontrom = malloc(KANJI_SIZE + (PAGE_SIZE-1))) == NULL) {
+ fprintf(stderr, "Memory allocation error.\n");
+ exit (EOF);
+ }
+ if ((unsigned long)fontrom % PAGE_SIZE)
+ fontrom += PAGE_SIZE - ((unsigned long)fontrom % PAGE_SIZE);
+ fontrom = (unsigned char *)mmap(
+ (caddr_t)fontrom,
+ KANJI_SIZE,
+ PROT_READ|PROT_WRITE,
+ MAP_SHARED|MAP_FIXED,
+ devMem,
+ KANJI_BASE
+ );
+ if ((long)fontrom < 0) {
+ fprintf(stderr, "Can not map memory.\n");
+ exit(EOF);
+ }
+
+ fi.size = get_kfontoft((MAXKANJI+1)>>8, (MAXKANJI+1) & 0xFF);
+ start = get_kfontoft((MINKANJI)>>8, (MINKANJI) & 0xFF);
+ if ((fontbuf = (u_char *)malloc(fi.size)) == NULL) return(NULL);
+
+ *fontrom = 0x80; bmove(fontbuf , fontrom, 0x10000);
+ *fontrom = 0x81; bmove(fontbuf + 0x10000, fontrom, 0x10000);
+ *fontrom = 0x82; bmove(fontbuf + 0x20000, fontrom, 0x10000);
+ *fontrom = 0x83; bmove(fontbuf + 0x30000, fontrom, 0x0b0a0);
+
+ if (boldMode) {
+ for (i = 0; i < fi.size; ) {
+ if(*(fontbuf + i) & 0x01) {
+ *(fontbuf + i + 1) |= (*(fontbuf + i + 1) >> 1) | 0x80;
+ } else {
+ *(fontbuf + i + 1) |= *(fontbuf + i + 1) >> 1;
+ }
+ *(fontbuf + i) |= *(fontbuf + i) >> 1;
+ i += 2;
+ }
+ }
+
+ return(fontbuf + start);
+}
+
+u_char *FontLoadJ3100(int argc, char **argv)
+{
+ int boldMode = 0, Source = 0;
+ u_char *font = NULL;
+
+ if (argc < 2) exit(EOF);
+ if (argc > 2) /* Bold mode */
+ if (*argv[2] == 'b' || *argv[2] == 'B')
+ boldMode = 1;
+ if (argc > 3) /* ASCII source */
+ if (*argv[3] == 'b' || *argv[3] == 'B') /* from BIOS ROM */
+ if (*(argv[3]+4) == '2')
+ Source = 2;
+ else
+ Source = 1;
+ if (*argv[1] == 'a' || *argv[1] == 'A') { /* ASCII mode */
+ fi.width = 8;
+ fi.high = 16;
+ fi.type = CHR_SFONT; /* single byte char */
+ if (CheckLoadedFont(CHR_SFONT))
+ font = FontLoads(boldMode, Source);
+ else exit(0);
+ } else { /* KANJI mode */
+ fi.width = 16;
+ fi.high = 16;
+ fi.type = CHR_WFONT; /* double byte char */
+ if (CheckLoadedFont(CHR_WFONT))
+ font = FontLoadw(boldMode);
+ else exit(0);
+ }
+}
+
+#if 0
+void main(argc, argv)
+int argc;
+char *argv[];
+{
+ int boldMode = 0, Source = 0;
+ u_char *font = NULL;
+
+ if (argc < 2) exit(EOF);
+ if (argc > 2) /* Bold mode */
+ if (*argv[2] == 'b' || *argv[2] == 'B')
+ boldMode = 1;
+ if (argc > 3) /* ASCII source */
+ if (*argv[3] == 'b' || *argv[3] == 'B') /* from BIOS ROM */
+ if (*(argv[3]+4) == '2')
+ Source = 2;
+ else
+ Source = 1;
+ if (*argv[1] == 'a' || *argv[1] == 'A') { /* ASCII mode */
+ fi.width = 8;
+ fi.high = 16;
+ fi.type = CHR_SFONT; /* single byte char */
+ if (CheckLoadedFont(CHR_SFONT))
+ font = FontLoads(boldMode, Source);
+ else exit(0);
+ } else { /* KANJI mode */
+ fi.width = 16;
+ fi.high = 16;
+ fi.type = CHR_WFONT; /* double byte char */
+ if (CheckLoadedFont(CHR_WFONT))
+ font = FontLoadw(boldMode);
+ else exit(0);
+ }
+ if (font == NULL) {
+ fprintf(stderr, "%s> Can not load font file.\n", argv[0]);
+ exit(EOF);
+ }
+
+ exit(SetFont(argv[0], font, &fi));
+}
+#endif
diff --git a/loader/kon2/font/minix.c b/loader/kon2/font/minix.c
new file mode 100644
index 000000000..85bba8b4f
--- /dev/null
+++ b/loader/kon2/font/minix.c
@@ -0,0 +1,194 @@
+/*
+ * KON2 - Kanji ON Console -
+ * Copyright (C) 1992-1996 Takashi MANABE (manabe@papilio.tutics.tut.ac.jp)
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY TAKASHI MANABE ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE TERRENCE R. LAMBERT BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+/*
+ This code is based on KanjiHand.
+
+ Thanks to
+ nemossan@uitec.ac.jp == nemossan@mix
+ takamiti@mix
+ maebashi@mcs.meitetsu.co.jp
+ yamamoto@sws.cpd.mei.co.jp
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/ioctl.h>
+#include <sys/file.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <errno.h>
+
+#include <fnld.h>
+#include <interface.h>
+
+#define SFONT_SIZE 256
+#define FH_MEMO_SIZE 508
+
+extern struct fontInfo fi;
+extern forceLoad;
+
+struct font_header {
+ short fnt_size; /* bytes per one character bit patern */
+ short fnt_high; /* font height */
+ short fnt_width; /* font width */
+ unsigned short top_code;
+ unsigned short end_code;
+ char _unused[502]; /* empty */
+ char memo[FH_MEMO_SIZE];
+ long sum;
+};
+
+#define FONT_HEAD_SIZE sizeof(struct font_header)
+#define MINKANJI 0x2121
+#define MAXKANJI 0x7424
+
+#define get_kfontoft(k1,k2) (((k1) > 0x29) ? \
+ ((((k2) - 0x40) + ((k1) - 0x25) * 96) << 5) : \
+ ((((k2) - 0x20) + ((k1) - 0x20) * 96) << 5))
+
+#define get_afontoft(c) (c << 4)
+
+static u_char *FontLoads(fp, fsize)
+FILE *fp;
+size_t fsize;
+{
+ int addr, i;
+ u_char *fontbuf;
+
+ if ((fontbuf = (u_char *)malloc(get_afontoft(SFONT_SIZE))) == NULL)
+ return(NULL);
+ fi.size = get_afontoft(SFONT_SIZE);
+ for (i = 0; i < SFONT_SIZE; i ++) {
+ addr = get_afontoft(i);
+ if (fread(fontbuf + addr, fsize, 1, fp) != 1) return(NULL);
+ }
+ return(fontbuf);
+}
+
+static u_char *FontLoadw(fp, fsize)
+FILE *fp;
+size_t fsize;
+{
+ size_t start;
+ int addr, k1, k2, i;
+ u_char *fontbuf;
+
+ fi.size = get_kfontoft((MAXKANJI+1)>>8, (MAXKANJI+1) & 0xFF);
+ start = get_kfontoft((MINKANJI)>>8, (MINKANJI) & 0xFF);
+ if ((fontbuf = (u_char *)malloc(fi.size)) == NULL) return(NULL);
+ for (k1 = 0x21; k1 <= 0x74; k1 ++) {
+ for (k2 = 0x21; k2 < 0x7f; k2 ++) {
+ if (k1 > 0x29 && k1 < 0x30) {
+ for (i = 0; i < fsize; i ++) fgetc(fp);
+ /* fseek(fp, fsize, SEEK_CUR);*/
+ continue;
+ }
+ addr = get_kfontoft(k1, k2);
+ if (fread(fontbuf + addr, fsize, 1, fp) != 1)
+ return(NULL);
+ if(k1 == 0x74 && k2 == 0x24) break;
+ }
+ }
+ return(fontbuf + start);
+}
+
+u_char *FontLoadMinix(fp)
+FILE *fp;
+{
+ char *fdata = NULL;
+ struct font_header hd;
+
+ if(fread(&hd, sizeof(struct font_header), 1, fp) != 1) return(NULL);
+ if (memcmp("k14;", hd.memo, 4)) {
+ if (hd.fnt_width > 0 && hd.fnt_width <= 8
+ && hd.fnt_high > 8 && hd.fnt_high <= 16
+ && hd.fnt_size == 16 ) {
+ fi.high = hd.fnt_high;
+ fi.width = hd.fnt_width;
+ fi.type = CodingByRegistry("JISX0201.1976-0");
+ if (CheckLoadedFont(fi.type))
+ fdata = FontLoads(fp, hd.fnt_size);
+ else exit(0);
+ }
+ } else {
+ if(hd.fnt_width > 8 && hd.fnt_width <= 16
+ && hd.fnt_high > 8
+ && hd.fnt_high <= 16
+ && hd.fnt_size > 16 && hd.fnt_size <= 32) {
+ fi.high = hd.fnt_high;
+ fi.width = hd.fnt_width;
+ fi.type = CodingByRegistry("JISX0208.1983-0");
+ if (CheckLoadedFont(fi.type))
+ fdata = FontLoadw(fp, hd.fnt_size);
+ else exit(0);
+ }
+ }
+ return(fdata);
+}
+
+#if 0
+void main(argc, argv)
+int argc;
+char *argv[];
+{
+ FILE *fp;
+ u_char *font;
+ int loaded=0;
+ int i;
+ char *p;
+
+ for (i = 1; i < argc; i ++) {
+ p = argv[i];
+ if (*p == '-') {
+ ++p;
+ switch(*p) {
+ case 'n':
+ forceLoad = 0;
+ break;
+ }
+ } else {
+ if(!(fp = fopen(argv[i], "r"))) {
+ fprintf(stderr, "%s> Can not open font file.\n", argv[0]);
+ exit(EOF);
+ }
+ loaded = 1;
+ }
+ }
+ if (!loaded) fp = stdin;
+
+ if ((font = FontLoadMinix(fp)) == NULL) {
+ fprintf(stderr, "%s> Can not load font file.\n", argv[0]);
+ exit(EOF);
+ }
+ if (fp != stdin) fclose(fp);
+
+ exit(SetFont(argv[0], font, &fi));
+}
+#endif
diff --git a/loader/kon2/include/child.h b/loader/kon2/include/child.h
new file mode 100644
index 000000000..7a760c875
--- /dev/null
+++ b/loader/kon2/include/child.h
@@ -0,0 +1,37 @@
+ /*
+ * KON2 - Kanji ON Console -
+ * Copyright (C) 1992-1996 Takashi MANABE (manabe@papilio.tutics.tut.ac.jp)
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY TAKASHI MANABE ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE TERRENCE R. LAMBERT BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+/* child -- child process (run startup command and execute shell) */
+
+#ifndef CHILD_H
+#define CHILD_H
+
+extern void ChildInit(void);
+extern void ChildStart(FILE *errfp);
+extern void ChildCleanup(void);
+
+#endif
diff --git a/loader/kon2/include/config.h b/loader/kon2/include/config.h
new file mode 100644
index 000000000..9a8f7143d
--- /dev/null
+++ b/loader/kon2/include/config.h
@@ -0,0 +1,71 @@
+
+/*
+ * KON2 - Kanji ON Console -
+ * Copyright (C) 1992, 1993 MAEDA Atusi (mad@math.keio.ac.jp)
+ * Copyright (C) 1992-1996 Takashi MANABE (manabe@papilio.tutics.tut.ac.jp)
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY TAKASHI MANABE ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE TERRENCE R. LAMBERT BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+/*
+ NOTE: This is automatically generated config.
+ >>>>>>>>>>>>>> DO NOT EDIT !! <<<<<<<<<<<<<<
+*/
+
+#ifndef CONFIG_H
+#define CONFIG_H
+
+
+/* build MINI KON */
+#define MINI_KON
+
+/* Support VGA driver */
+#define HAS_VGA
+
+/* Support J31SX driver */
+#define HAS_J31SX
+
+/* Support MOUSE driver */
+#undef HAS_MOUSE
+
+/* Install Minix/V font loader */
+#define FLD_MINIX
+
+/* Install $fontx2 font loader */
+#define FLD_BDF
+
+/* Install .bdf font loader */
+#define FLD_FONTX2
+
+/* Install J3100ROM font loader */
+#define FLD_J31ROM
+
+/* Use ROM font */
+#define USE_ROMFONT
+#endif
+
+#ifdef MINI_KON
+#undef USE_ROMFONT
+#define USE_ROMFONT
+#endif
+
diff --git a/loader/kon2/include/defs.h b/loader/kon2/include/defs.h
new file mode 100644
index 000000000..6cd90187e
--- /dev/null
+++ b/loader/kon2/include/defs.h
@@ -0,0 +1,40 @@
+/*
+ * KON2 - Kanji ON Console -
+ * Copyright (C) 1992-1996 Takashi MANABE (manabe@papilio.tutics.tut.ac.jp)
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY TAKASHI MANABE ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE TERRENCE R. LAMBERT BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+/* defs.h -- global definition */
+
+#ifndef DEFS_H
+#define DEFS_H
+
+#undef FALSE
+#undef TRUE
+typedef enum {FALSE, TRUE} bool;
+
+#define FAILURE (-1)
+#define SUCCESS (0)
+
+#endif
diff --git a/loader/kon2/include/errors.h b/loader/kon2/include/errors.h
new file mode 100644
index 000000000..f4bfc1e18
--- /dev/null
+++ b/loader/kon2/include/errors.h
@@ -0,0 +1,41 @@
+/*
+ * KON2 - Kanji ON Console -
+ * Copyright (C) 1993 by MAEDA Atusi (mad@math.keio.ac.jp)
+ * Copyright (C) 1992-1996 Takashi MANABE (manabe@papilio.tutics.tut.ac.jp)
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY TAKASHI MANABE ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE TERRENCE R. LAMBERT BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#ifndef ERRORS_H
+#define ERRORS_H
+
+#define error kon_error
+
+extern void Perror(const char *message); /* perror(message) */
+extern void PerrorExit(const char *message); /* perror(message) and die */
+extern void fatal(const char *format, ...); /* print error message and die */
+extern void error(const char *format, ...); /* print error message */
+extern void warn(const char *format, ...); /* print warning message */
+extern void message(const char *format, ...); /* print message */
+
+#endif
diff --git a/loader/kon2/include/fnld.h b/loader/kon2/include/fnld.h
new file mode 100644
index 000000000..cdf94181d
--- /dev/null
+++ b/loader/kon2/include/fnld.h
@@ -0,0 +1,65 @@
+/*
+ * KON2 - Kanji ON Console -
+ * Copyright (C) 1992-1996 Takashi MANABE (manabe@papilio.tutics.tut.ac.jp)
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY TAKASHI MANABE ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE TERRENCE R. LAMBERT BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+/* fnld.h -- font information */
+
+#ifndef FNLD_H
+#define FNLD_H
+
+#include <interface.h>
+#include <defs.h>
+
+struct fontRegs {
+ u_int (*addr)(u_char ch1, u_char ch2);
+ u_int size;
+ char *registry, *bitmap;
+ u_char high, width, sign0, sign1, stat;
+};
+
+struct langInfo {
+ u_char
+ sb,
+ db,
+ sc;
+};
+
+extern struct langInfo lInfo;
+
+#define FR_ATTACH 1
+#define FR_PROXY 2
+
+extern struct fontRegs fSRegs[], fDRegs[];
+extern struct fontRegs *sbFReg, *dbFReg;
+
+extern u_char *FontLoad(u_char *fbuff, int fd, struct fontInfo *fi);
+extern u_char *GetShmem(char type);
+extern void DownShmem(char type);
+extern void FontAttach(void);
+extern void FontDetach(bool);
+extern int CodingByRegistry(char *);
+
+#endif
diff --git a/loader/kon2/include/getcap.h b/loader/kon2/include/getcap.h
new file mode 100644
index 000000000..41e380482
--- /dev/null
+++ b/loader/kon2/include/getcap.h
@@ -0,0 +1,59 @@
+/*
+ * KON2 - Kanji ON Console -
+ * Copyright (C) 1992-1996 Takashi MANABE (manabe@papilio.tutics.tut.ac.jp)
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY TAKASHI MANABE ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE TERRENCE R. LAMBERT BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+/* getcap library - read configuration file and invoke initializer function */
+
+#ifndef GETCAP_H
+#define GETCAP_H
+
+#include <defs.h>
+
+/* Initializer function should return 0 on success, -1 on failure. */
+typedef int (initializer)(const char *);
+
+/* Define initializer function func for capability name. If def_value is nil,
+ then the entry of the name must exist in configuration file. An error is
+ flagged if no entry is found. If def_value is non-nil and no entry is found
+ in configuration file, then func is invoked with def_value. */
+extern void DefineCap(const char *name, initializer *func, const char *def_value);
+
+/* Delete all initializer functions. */
+extern void CapInit(void);
+
+/* Read configuration file named filename and invoke initializer function for each entry.
+ Return 0 on success, -1 on failure. */
+extern int ReadConfig(const char *filename);
+
+/* Set value for capability capName. Return 0 on success, -1 if capName not defined. */
+extern int SetCapArg(const char *capName, const char *value);
+
+#define MAX_COLS 256 /* maximum line length of config file */
+
+/* Utility function that return 1 if confstr is "On" and 0 if "OFF". */
+extern bool BoolConf(const char *confstr);
+
+#endif
diff --git a/loader/kon2/include/interface.h b/loader/kon2/include/interface.h
new file mode 100644
index 000000000..46d8aad29
--- /dev/null
+++ b/loader/kon2/include/interface.h
@@ -0,0 +1,94 @@
+/*
+ * KON2 - Kanji ON Console -
+ * Copyright (C) 1992-1996 Takashi MANABE (manabe@papilio.tutics.tut.ac.jp)
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY TAKASHI MANABE ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE TERRENCE R. LAMBERT BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+/* interface.h -- communication protocol definition */
+
+#ifndef INTERFACE_H
+#define INTERFACE_H
+
+#include <sys/types.h>
+
+/* 通信制御キャラクタ */
+#define STR_NAK "\x15"
+#define CHR_NAK 0x15
+#define STR_ACK "\x06"
+#define CHR_ACK 0x06
+
+/* 通信内容の識別子 */
+#define CHR_SFONT 0x81
+#define CHR_WFONT 0x89
+
+#define CHR_SFLD 0x80
+#define CHR_DBC 0x20
+#define CHR_DFLD (CHR_SFLD|CHR_DBC)
+
+#define CHR_LOAD 'L'
+#define CHR_UNLOAD 'U'
+#define CHR_STAT 'S'
+#define CHR_DISCONNECT 'D'
+#define CHR_TEXTMODE 'T'
+#define CHR_GRAPHMODE 'G'
+#define CHR_RESTART 'R'
+
+#define MAX_SOCKET_NAME 14
+#define SOCKET_BASENAME "/tmp/.kon"
+
+#define SHMEM_NAME CONFIG_NAME
+
+/* 制御キャラクタの最大長 */
+#define MAX_CTRLCHAR 80
+
+/*
+extern char socketName[MAX_SOCKET_NAME+1];
+*/
+
+struct messageHeader {
+ u_char cno, /* client number */
+ cmd; /* command */
+};
+
+struct fontInfo {
+ u_int size;
+ u_char high, width, type;
+};
+
+struct fontLoaderRegs {
+ u_int (*addr)(u_char ch1, u_char ch2);
+ u_int max;
+};
+
+extern struct fontLoaderRegs fldSRegs[], fldDRegs[];
+
+extern void SocketKill(int);
+extern int SocketRecCommand(int, struct messageHeader *);
+extern int SocketSendCommand(int, char);
+extern int SocketClientOpen(void);
+extern int SocketSendData(u_char *buff, int size, int fd);
+extern int CheckLoadedFont(char type);
+extern int SetFont(char *prog, u_char *font, struct fontInfo *fi);
+
+#endif
diff --git a/loader/kon2/include/mem.h b/loader/kon2/include/mem.h
new file mode 100644
index 000000000..4294c1656
--- /dev/null
+++ b/loader/kon2/include/mem.h
@@ -0,0 +1,103 @@
+/*
+ * KON2 - Kanji ON Console -
+ * Copyright (C) 1992-1996 Takashi MANABE (manabe@papilio.tutics.tut.ac.jp)
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY TAKASHI MANABE ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE TERRENCE R. LAMBERT BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+/* mem -- memory handling libraries */
+
+#ifndef MEM_H
+#define MEM_H
+
+static inline
+ void PortOutw(u_short value, u_short port)
+{
+ __asm__ ("outw %0,%1"
+ ::"a" ((u_short) value),
+ "d" ((u_short) port));
+}
+
+static inline
+ void PortOutb(char value, u_short port)
+{
+ __asm__ ("outb %0,%1"
+ ::"a" ((char) value),
+ "d" ((u_short) port));
+}
+
+static inline
+ void lzero(void *head, int n)
+{
+ __asm__ ("cld\n\t"
+ "rep\n\t"
+ "stosl"
+ ::"a" (0),
+ "c" (n>>2),
+ "D" ((long)head)
+ :"cx","di");
+}
+
+static inline
+ void bmove(void *dst, void *src, int n)
+{
+ __asm__ ("cld\n\t"
+ "rep\n\t"
+ "movsb\n\t"
+ ::"c" (n),
+ "D" ((long)dst),
+ "S" ((long)src)
+ :"cx","di","si");
+}
+
+static inline
+ void brmove(void *dst, void *src, int n)
+{
+ __asm__ ("std\n\t"
+ "rep\n\t"
+ "movsb\n\t"
+ ::"c" (n),
+ "D" ((long)dst),
+ "S" ((long)src)
+ :"cx","di","si");
+}
+
+static inline
+ void bzero2(void *head, int n)
+{
+ __asm__ ("cld\n\t"
+ "rep\n\t"
+ "stosb"
+ ::"a" (0),
+ "c" (n),
+ "D" ((long)head)
+ :"cx","di");
+}
+
+extern u_char PortInb(u_short);
+extern void wzero(void *, int);
+extern void wmove(void *, void *, int);
+extern void lmove(void *, void *, int);
+extern void SafeFree(void **);
+
+#endif
diff --git a/loader/kon2/include/mouse.h b/loader/kon2/include/mouse.h
new file mode 100644
index 000000000..6c01006ca
--- /dev/null
+++ b/loader/kon2/include/mouse.h
@@ -0,0 +1,58 @@
+/*
+ * KON2 - Kanji ON Console -
+ * Copyright (C) 1992-1996 Takashi MANABE (manabe@papilio.tutics.tut.ac.jp)
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY TAKASHI MANABE ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE TERRENCE R. LAMBERT BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+/* mouse.h -- mouse driver interface */
+#ifndef MOUSE_H
+#define MOUSE_H
+
+#include <defs.h>
+
+#define MOUSE_LFT 4
+#define MOUSE_MID 2
+#define MOUSE_RGT 1
+#define MOUSE_LIFETIME 55 /* 5.5 seconds */
+
+struct mouseInfo {
+ bool has_mouse;
+ char x, y,
+ dx, dy,
+ sx, sy,
+ sw,
+ stat;
+};
+
+extern struct mouseInfo mInfo;
+extern int mouseFd;
+
+extern void MouseInit(void);
+extern int MouseStart(void);
+extern void MouseGetPacket(u_char *, int);
+extern void MouseCleanup(void);
+extern void MouseSetRfd(int);
+extern void MouseResetRfd(int);
+
+#endif
diff --git a/loader/kon2/include/setutmp.h b/loader/kon2/include/setutmp.h
new file mode 100644
index 000000000..1b1f1eb66
--- /dev/null
+++ b/loader/kon2/include/setutmp.h
@@ -0,0 +1,36 @@
+/*
+ * KON2 - Kanji ON Console -
+ * Copyright (C) 1992-1996 Takashi MANABE (manabe@papilio.tutics.tut.ac.jp)
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY TAKASHI MANABE ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE TERRENCE R. LAMBERT BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+/* setutmp -- set/reset utmp entry */
+
+#ifndef SETUTMP_H
+#define SETUTMP_H
+
+extern void SetUtmp(char *tty);
+extern void ResetUtmp(char *tty);
+
+#endif
diff --git a/loader/kon2/include/sock.h b/loader/kon2/include/sock.h
new file mode 100644
index 000000000..fe5248e41
--- /dev/null
+++ b/loader/kon2/include/sock.h
@@ -0,0 +1,37 @@
+/*
+ * KON2 - Kanji ON Console -
+ * Copyright (C) 1992-1996 Takashi MANABE (manabe@papilio.tutics.tut.ac.jp)
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY TAKASHI MANABE ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE TERRENCE R. LAMBERT BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+/* sock -- socket interface module */
+
+#ifndef SOCK_H
+#define SOCK_H
+
+extern int SocketInit(char*);
+extern void SocketInterface(int);
+extern void FontShmGet(u_char);
+
+#endif
diff --git a/loader/kon2/include/term.h b/loader/kon2/include/term.h
new file mode 100644
index 000000000..3890ad8c8
--- /dev/null
+++ b/loader/kon2/include/term.h
@@ -0,0 +1,40 @@
+/*
+ * KON2 - Kanji ON Console -
+ * Copyright (C) 1992-1996 Takashi MANABE (manabe@papilio.tutics.tut.ac.jp)
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY TAKASHI MANABE ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE TERRENCE R. LAMBERT BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+/* term -- multiplexer main module */
+
+#ifndef TERM_H
+#define TERM_H
+
+/* Do initialization before reading config file */
+extern void TermInit(int argc, const char *argv[]);
+
+extern void TermStart(void); /* start procesing */
+extern void TermRestart(int fd); /* restart kon (args are read from fd) */
+extern int masterPty; /* master pseudo-tty file descriptor */
+
+#endif
diff --git a/loader/kon2/include/vc.h b/loader/kon2/include/vc.h
new file mode 100644
index 000000000..601155307
--- /dev/null
+++ b/loader/kon2/include/vc.h
@@ -0,0 +1,124 @@
+/*
+ * KON2 - Kanji ON Console -
+ * Copyright (C) 1992-1996 Takashi MANABE (manabe@papilio.tutics.tut.ac.jp)
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY TAKASHI MANABE ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE TERRENCE R. LAMBERT BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+/* vc -- high-level console driver */
+
+#ifndef VC_H
+#define VC_H
+
+#define ATTR_ULINE 0x80 /* under line */
+#define ATTR_REVERSE 0x40 /* reverse */
+#define ATTR_HIGH 0x20 /* high */
+
+#define LATCH_S 0x0 /* single byte char */
+#define LATCH_1 0x20 /* double byte char 1st byte */
+#define LATCH_2 0x40 /* double byte char 2nd byte */
+
+#define CLEAN_S 0x80
+#define CODEIS_1 LATCH_1
+#define CODEIS_2 LATCH_2
+#define LANG_CODE 0x0F
+/*
+#define LANG_DCODE LANG_CODE|CODEIS_1
+#define LANG_SCODE LANG_CODE
+*/
+
+extern void ConsoleInit(const char *video_type);
+extern void ConsoleStart(void);
+extern void ConsoleCleanup(void);
+extern void TextClearAll(void);
+extern void TextClearEol(u_char);
+extern void TextClearEos(u_char);
+extern void TextDeleteChar(int);
+extern void TextInsertChar(int);
+extern void TextMoveDown(int top, int btm, int line);
+extern void TextMoveUp(int top, int btm, int line);
+extern void TextMode(void);
+extern void GraphMode(void);
+extern void ScrollUp(int);
+extern void ScrollDown(int);
+extern void TextWput(u_char ch1, u_char ch2);
+extern void TextSput(u_char ch);
+extern void TextReverse(int fx, int fy, int tx, int ty);
+extern void TextRefresh(void);
+extern void TextInvalidate(void);
+extern void TextCopy(int fx, int fy, int tx, int ty);
+extern void TextPaste(void);
+extern void PollCursor(bool wakeup); /* Called to wakeup, or every 0.1 sec when idle */
+extern void Beep(void);
+
+struct cursorInfo {
+ short kanji; /* 漢字の上にあれば TRUE */
+ u_int addr; /* VRAM アドレス */
+ bool sw; /* FALSE なら表示禁止 */
+ int interval; /* 点滅間隔 */
+ int count; /* 点滅用カウント */
+ bool shown; /* 表示中フラグ */
+};
+
+/* video driver interface */
+struct videoInfo {
+ bool
+ has_hard_scroll; /* ハードスクロールが使えるかどうか */
+ void
+ (*init)(void), /* 初期化 */
+ (*text_mode)(void), /* テキストモードに切替え */
+ (*graph_mode)(void), /* グラフィックモードに切替え */
+ (*wput)(u_char *code, u_char fc, u_char bc), /* 漢字出力 */
+ (*sput)(u_char *code, u_char fc, u_char bc), /* ANK出力 */
+ (*set_cursor_address)(struct cursorInfo *c, u_int x, u_int y),
+ /* カーソル c のアドレスを (x,y) に設定 */
+ (*set_address)(u_int i),
+ /* 文字書き込みアドレスを i 文字目に設定 */
+ (*cursor)(struct cursorInfo *), /* カーソルをトグル */
+ (*clear_all)(void), /* 画面クリア */
+ (*screen_saver)(bool), /* スクリーンブランク/アンブランク */
+ (*detatch)(void), /* ドライバ解放 */
+ /* ハードスクロールが使えなければ以下はNULL */
+ (*set_start_address)(void), /* 表示開始アドレス設定 */
+ (*hard_scroll_up)(int lines), /* ハードスクロールアップ */
+ (*hard_scroll_down)(int lines); /* ハードスクロールダウン */
+};
+
+struct dispInfo {
+ int
+ gsize;
+ short
+ gxdim,
+ gydim,
+ txmax,
+ tymax,
+ glineChar, /* text 1行分の graph 行数 */
+ glineByte, /* graph 1行分のバイト数 */
+ tlineByte; /* text 1行分のバイト数 */
+};
+
+extern struct dispInfo dInfo;
+extern struct cursorInfo cInfo;
+extern struct videoInfo vInfo;
+
+#endif
diff --git a/loader/kon2/include/version.h b/loader/kon2/include/version.h
new file mode 100644
index 000000000..e50b625c6
--- /dev/null
+++ b/loader/kon2/include/version.h
@@ -0,0 +1 @@
+#define VERSION "ver.0.3.8 (98/03/09)"
diff --git a/loader/kon2/include/vga.h b/loader/kon2/include/vga.h
new file mode 100644
index 000000000..734c5a700
--- /dev/null
+++ b/loader/kon2/include/vga.h
@@ -0,0 +1,147 @@
+/*
+ * KON2 - Kanji ON Console -
+ * Copyright (C) 1992-1996 Takashi MANABE (manabe@papilio.tutics.tut.ac.jp)
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY TAKASHI MANABE ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE TERRENCE R. LAMBERT BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+/* vga.h -- definitions used in video drivers */
+
+#ifndef VGA_H
+#define VGA_H
+
+/* Sequencer */
+#define VGASEQ_ADDR 0x3C4
+#define VGASEQ_DATA 0x3C5
+#define VGASEQ_CNT 5
+
+/* CRT controller */
+/*
+#define VGACRT_ADDR 0x3D4
+#define VGACRT_DATA 0x3D5
+*/
+#define CGACRT_ADDR 0x3D4
+#define CGACRT_DATA 0x3D5
+#define VGACRT_CNT 25
+#define CGACRT_CNT 25
+
+/* Graphics controller */
+#define VGAGRP_ADDR 0x3CE
+#define VGAGRP_DATA 0x3CF
+#define VGAGRP_CNT 9
+
+/* Attribute controller */
+#define VGAATTR_A_O 0x3C0
+#define VGAATTR_DATA 0x3C1
+#define VGAATTR_CNT 21
+#define EGAATTR_CNT 20
+
+#if defined(linux)
+#define GRAPH_BASE 0xA0000
+#elif defined(__FreeBSD__)
+#define GRAPH_BASE 0x0
+#endif
+#define FONT_SIZE 0x2000
+
+#define VGA_FONT_SIZE 128
+#define VGA_FONT_HEIGHT 16
+
+#define NUM_VIDEOH_INFO 4
+#define NUM_VIDEOV_INFO 4
+
+/* DAC Palette */
+#define VGAPAL_OADR 0x3C8
+#define VGAPAL_IADR 0x3C7
+#define VGAPAL_DATA 0x3C9
+
+/* Misc */
+#define VGAMISC_IN 0x3CC
+#define VGAMISC_OUT 0x3C2
+
+/* Input Stat 1 */
+/*#define VGAST1_ADDR 0x3DA*/
+
+#define MAX_PELS 16
+
+struct vgaRegs {
+ u_char crt[VGACRT_CNT],
+ att[VGAATTR_CNT],
+ gra[VGAGRP_CNT],
+ seq[VGASEQ_CNT],
+ mis;
+};
+
+struct pelRegs {
+ u_char red[MAX_PELS],
+ grn[MAX_PELS],
+ blu[MAX_PELS];
+};
+
+union videoTimings {
+ struct {
+ int hDot, hStart, hEnd, hTotal;
+ int vLine, vStart, vEnd, vTotal;
+ int txmax, tymax, i;
+ } m;
+ int v[NUM_VIDEOH_INFO+NUM_VIDEOV_INFO+1];
+};
+
+static inline
+ void VgaOutByte(u_char value)
+{
+ __asm__ ("movb %%al, %%ah\n\t"
+ "movb $8, %%al\n\t"
+ "outw %%ax, %w1"
+ :/* no outputs */
+ :"a" ((u_char) value),
+ "d" ((u_short)VGAGRP_ADDR));
+}
+
+extern u_int vgaCrtAddr, vgaCrtData, vgaSt1Addr;
+
+extern int LineComp9, LineComp8, gramHead;
+extern struct vgaRegs regText, regGraph;
+extern struct videoInfo SvgaInfo;
+
+void VgaSetRegisters(struct vgaRegs *regs);
+void VgaInit(void);
+void VgaTextMode(void);
+void VgaGraphMode(void);
+void VgaWput(u_char *code, u_char fc, u_char bc);
+void VgaSput(u_char *code, u_char fc, u_char bc);
+void VgaWputFm(u_char *code, u_char fc, u_char bc);
+void VgaSputFm(u_char *code, u_char fc, u_char bc);
+void VgaHardScrollUp(int line);
+void VgaHardScrollDown(int line);
+void VgaSetCursorAddress(struct cursorInfo *ci, u_int x, u_int y);
+void VgaSetAddress(u_int p);
+void VgaCursor(struct cursorInfo *ci);
+void VgaClearAll(void);
+void VgaScreenSaver(bool blank);
+int VgaReadPels(const char *str);
+int VgaReadNewRegs(const char *str, union videoTimings *);
+int VgaAttach(void);
+void VgaDetach(void);
+void VgaDefaultCaps();
+void VgaLoadRomFont(char *);
+#endif
diff --git a/loader/kon2/include/vt.h b/loader/kon2/include/vt.h
new file mode 100644
index 000000000..e019568a3
--- /dev/null
+++ b/loader/kon2/include/vt.h
@@ -0,0 +1,128 @@
+/*
+ * KON2 - Kanji ON Console -
+ * Copyright (C) 1992-1996 Takashi MANABE (manabe@papilio.tutics.tut.ac.jp)
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY TAKASHI MANABE ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE TERRENCE R. LAMBERT BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+/* vt -- VT emulator */
+
+#ifndef VT_H
+#define VT_H
+
+#include <defs.h>
+#include <fnld.h>
+
+struct _con_info {
+ short
+ x,
+ y,
+ xmax, /* 79 */
+ ymin, /* 0:スクロール開始行 */
+ ymax, /* 29 */
+ tab; /* 8 */
+ u_char
+ fcol, /* フォアグランド */
+ bcol, /* バックグランド */
+ attr, /* 文字属性 */
+ sb, /* 1 byte code フォント番号 */
+ db, /* 2 byte code フォント番号 */
+ knj1; /* 漢字キャラクタ第 1 byte */
+ void (*esc)(u_char);
+ enum {
+ CS_LEFT,
+ CS_RIGHT,
+ CS_GRAPH,
+ CS_DBCS} trans, g[2];
+ enum {
+ SL_NONE,
+ SL_ENTER,
+ SL_LEAVE} sl;
+ bool
+ soft,
+ ins,
+ active,
+ wrap,
+ text_mode;
+};
+
+extern struct _con_info con;
+
+#define CODE_2022 0 /* 2022 のみに従う*/
+#define CODE_EUC 1 /* EUC にも従う */
+#define CODE_SJIS 2 /* SJIS にも従う */
+
+#define G0_SET 0
+#define G1_SET 0x80
+
+extern void VtInit(void);
+extern void VtStart(void);
+extern void VtEmu(const char*, int nchars);
+extern void VtCleanup(void);
+
+#define sjistojis(ch, cl)\
+{\
+ ch -= (ch > 0x9F) ? 0xB1: 0x71;\
+ ch = ch * 2 + 1;\
+ if (cl > 0x9E) {\
+ cl = cl - 0x7E;\
+ ch ++;\
+ } else {\
+ if (cl > 0x7E) cl --;\
+ cl -= 0x1F;\
+ }\
+}
+
+#define jistosjis(ch, cl)\
+{\
+ if (ch & 1) cl = cl + (cl > 0x5F ? 0x20:0x1F);\
+ else cl += 0x7E;\
+ ch = ((ch - 0x21) >> 1) + 0x81;\
+ if (ch > 0x9F) ch += 0x40;\
+}
+
+/*
+ derived from Mule:codeconv.c to support "ESC $(0" sequence
+ thanks to K.Handa <handa@etl.go.jp>
+ */
+
+#define muletobig5(type, m1, m2)\
+{\
+ unsigned code = (m1 - 0x21) * 94 + (m2 - 0x21);\
+\
+ if (type == DF_BIG5_1) code += 0x16F0;\
+ m1 = code / 157 + 0xA1;\
+ m2 = code % 157;\
+ m2 += m2 < 0x3F ? 64 : 98;\
+}
+
+enum {
+ DF_GB2312,
+ DF_JISX0208,
+ DF_KSC5601,
+ DF_JISX0212,
+ DF_BIG5_0,
+ DF_BIG5_1
+ };
+
+#endif
diff --git a/loader/kon2/kbiff/Makefile b/loader/kon2/kbiff/Makefile
new file mode 100644
index 000000000..a319f5dd5
--- /dev/null
+++ b/loader/kon2/kbiff/Makefile
@@ -0,0 +1,11 @@
+CFLAGS=-O3 -g
+OBJS= kbiff.o
+
+kbiff: $(OBJS)
+ $(CC) -o $@ $< -lncurses
+
+install:
+ install -cs kbiff /usr/bin
+
+clean:
+ rm -f $(OBJS) kbiff
diff --git a/loader/kon2/kbiff/kbiff.c b/loader/kon2/kbiff/kbiff.c
new file mode 100644
index 000000000..d1c8ea1b7
--- /dev/null
+++ b/loader/kon2/kbiff/kbiff.c
@@ -0,0 +1,68 @@
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include <stdlib.h>
+#include <curses.h>
+#include <term.h>
+#include <signal.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+
+void
+cleanup()
+{
+ putp(from_status_line);
+ putp(dis_status_line);
+ exit(0);
+}
+
+void
+main(int argc, char *argv[])
+{
+ char *term, *mail, *p, *buff;
+ time_t interval=10000000;
+ time_t old_mtime=0;
+ int n, update=1;
+ struct stat st;
+
+ if ((term = getenv("TERM")) == NULL
+ || (mail = getenv("MAIL")) == NULL) exit(1);
+ setupterm(term, 1, &n);
+ if (n != 1) exit(1);
+ if (!has_status_line) exit(1);
+ if ((buff = calloc(columns + 1, 1)) == NULL) exit(1);
+ putp(tparm(to_status_line, 0, 0));
+ putp(from_status_line);
+ fflush(stdout);
+ signal(SIGINT, cleanup);
+ signal(SIGKILL, cleanup);
+ while (1) {
+ if (!stat(mail, &st) && st.st_size) {
+ if (st.st_mtime > old_mtime) {
+ sprintf(buff, "New mail received %s",
+ ctime(&st.st_mtime));
+ update = 1;
+ old_mtime = st.st_mtime;
+ }
+ } else {
+ if (st.st_mtime > old_mtime) {
+ sprintf(buff, "No mail");
+ update = 1;
+ old_mtime = st.st_mtime;
+ }
+ }
+ if (update) {
+ if ((p = strchr(buff, '\n')) != NULL) *p = 0;
+ printf("%s%s\n%*s%s%s",
+ tparm(to_status_line, 0, 0),
+ enter_standout_mode,
+ columns, buff,
+ exit_standout_mode,
+ from_status_line);
+ fflush(stdout);
+ update = 0;
+ }
+ usleep(interval);
+ }
+ cleanup();
+}
diff --git a/loader/kon2/kon.cfg.FreeBSD b/loader/kon2/kon.cfg.FreeBSD
new file mode 100644
index 000000000..764df6f9b
--- /dev/null
+++ b/loader/kon2/kon.cfg.FreeBSD
@@ -0,0 +1,216 @@
+##################################################
+#
+# Configuration file for KON
+#
+##################################################
+
+##################################################
+# REQUIRED ENTRIES
+#
+# 1) Normal and Startup entries must be present.
+# 2) For VGA and VGAFM type displays, Pels entry
+# must be defined *after* Normal entry.
+#
+##################################################
+
+# Display definition
+# Entry named `Normal' is used as default.
+J3100SX:J31:J3100
+ J3100SX
+Stealth:
+ VGA
+ 800 864 1016 1064 600 606 608 632
+ 2
+ 99 36
+PCI805:
+ VGA
+ 800 864 1016 1064 600 606 608 632
+ 2
+ 99 36
+VGA11:
+ VGAFM
+ 3777
+ 640 680 776 808 480 491 493 524
+ 1
+ 79 42
+VGA12:
+ VGAFM
+ 3BF7
+ 640 680 776 808 480 491 493 524
+ 1
+ 79 39
+VGA13:
+ VGAFM
+ 3FF7
+ 640 680 776 808 480 491 493 524
+ 1
+ 79 35
+VGA14:
+ VGAFM
+ 7FF7
+ 640 680 776 808 480 491 493 524
+ 1
+ 79 33
+VGA:Normal
+ VGA
+ 640 680 768 800 480 491 493 525
+ 1
+ 79 23
+
+# Pels: Pallette value definition for VGA, VGAFM drivers
+
+REVPEL: # Values for reverse color
+ 63 63 63
+ 63 63 21
+ 63 21 63
+ 63 21 21
+ 21 63 63
+ 21 63 21
+ 21 21 63
+ 21 21 21
+ 42 42 42
+ 42 21 0
+ 42 0 42
+ 42 0 0
+ 0 42 42
+ 0 42 0
+ 0 0 42
+ 0 0 0
+
+STDPEL: # Standard color
+ 0 0 0
+ 0 0 42
+ 0 42 0
+ 0 42 42
+ 42 0 0
+ 42 0 42
+ 42 21 0
+ 42 42 42
+ 21 21 21
+ 21 21 63
+ 21 63 21
+ 21 63 63
+ 63 21 21
+ 63 21 63
+ 63 63 21
+ 63 63 63
+
+HIPEL: Pels # Hi color
+ 0 0 0
+ 0 0 52
+ 0 52 0
+ 0 52 52
+ 52 0 0
+ 52 0 52
+ 52 31 0
+ 52 52 52
+ 31 31 31
+ 31 31 63
+ 31 63 31
+ 31 63 63
+ 63 31 31
+ 63 31 63
+ 63 63 31
+ 63 63 63
+
+# Startup command definition (usually font loading commands are specified)
+bdf-zcat:Startup
+ gzip -cd /usr/local/lib/fonts/k14.bdf.gz | /usr/local/bin/fld -t bdf -n
+ gzip -cd /usr/local/lib/fonts/7x14rk.bdf.gz | /usr/local/bin/fld -t bdf -n
+minix:
+ /usr/bin/fld.minix -n /usr/share/fonts/publicfont.ank
+ /usr/bin/fld.minix -n /usr/share/fonts/publicfont.k14
+fontx:
+ /usr/bin/fld.fontx -n /dos/lib/font/new/jpnhn16x.fnt
+ /usr/bin/fld.fontx -n /dos/lib/font/new/jpnzn16x.fnt
+minix-zcat:
+ zcat /usr/share/fonts/publicfont.a.Z | /usr/bin/fld.minix -n
+ zcat /usr/share/fonts/publicfont.k.Z | /usr/bin/fld.minix -n
+fontx-zcat:
+ zcat /dos/lib/font/jpnhn16x.Z | /usr/bin/fld.fontx -n
+ zcat /dos/lib/font/jpnzn16x.Z | /usr/bin/fld.fontx -n
+minix-gzip:
+ gzip -cd /usr/share/fonts/publicfont.k14.gz | /usr/local/bin/fld -t minix -n
+ gzip -cd /usr/share/fonts/publicfont.ank.gz | /usr/local/bin/fld -t minix -n
+fontx-gzip:
+ gzip -d < /dos/lib/font/jpnhn16x.z | /usr/bin/fld.fontx -n
+ gzip -d < /dos/lib/font/jpnzn16x.z | /usr/bin/fld.fontx -n
+
+#################################
+# OPTIONAL SETUP ENTRIES
+#################################
+
+# Mouse type definition. Choose one of: Microsoft,
+# MouseSystems, BusMouse, MMSeries, Logitech, or None.
+Mouse:
+ None
+# Mouse baud rate
+MouseBaud:
+ 1200
+# Mouse device file name
+MouseDev:
+ /dev/mouse
+
+# Use hard scroll
+HardScroll:
+ On
+
+# Length of beep sound (1/100 sec).
+BeepCounter:
+ 5
+
+# Cursor blink interval (1/10 sec).
+CursorInterval:
+ 4
+
+# Screen blank time (minutes).
+SaveTime:
+ 5
+
+# Use double width cursor on kanji character
+KanjiCursor:
+ On
+
+# Cursor top raster line (0..15)
+CursorTop:
+ 14
+
+# Cursor bottom raster line (CursorTop..15)
+CursorBottom:
+ 15
+
+# Vga Font Offset
+VgaFontOffset:
+ 0
+
+# Save font data in plane 3 (required for Trident TVGA series)
+SavePlane3:
+ Off
+
+Mouse3Buttons:
+ On
+
+# Coding
+# SingleByte DoubleByte 8bitCode
+# ISO8895-[123456789], JISX0201.1976-0
+# BIG5.HKU-0, GB2312.1980-1, JISX0208.1983-0, KSC5601.1987-0
+# EUC, SJIS
+
+ja_JP.ujis:Coding
+ JISX0201.1976-0 JISX0208.1983-0 EUC
+
+ja_JP.sjis:
+ JISX0201.1976-0 JISX0208.1983-0 SJIS
+
+zh_TW.big5:
+ ISO8859-1 BIG5.HKU-0
+
+zh_CN.ugb:
+ ISO8859-1 GB2312.1980-0
+
+ko_KR.euc:
+ ISO8859-1 KSC5601.1987-0
+
+# Show `No warranty' message
+StartupMessage:
+ On
diff --git a/loader/kon2/kon.cfg.linux b/loader/kon2/kon.cfg.linux
new file mode 100644
index 000000000..a68583cdb
--- /dev/null
+++ b/loader/kon2/kon.cfg.linux
@@ -0,0 +1,213 @@
+##################################################
+#
+# Configuration file for KON
+#
+##################################################
+
+##################################################
+# REQUIRED ENTRIES
+#
+# 1) Normal and Startup entries must be present.
+# 2) For VGA and VGAFM type displays, Pels entry
+# must be defined *after* Normal entry.
+#
+##################################################
+
+# Display definition
+# Entry named `Normal' is used as default.
+J3100SX:J31:J3100
+ J3100SX
+Stealth:
+ VGA
+ 800 864 1016 1064 600 606 608 632
+ 2
+ 99 36
+PCI805:
+ VGA
+ 800 864 1016 1064 600 606 608 632
+ 2
+ 99 36
+VGA11:
+ VGAFM
+ 3777
+ 640 680 768 800 480 491 493 525
+ 1
+ 79 42
+VGA12:
+ VGAFM
+ 3BF7
+ 640 680 768 800 480 491 493 525
+ 1
+ 79 39
+VGA13:
+ VGAFM
+ 3FF7
+ 640 680 768 800 480 491 493 525
+ 1
+ 79 35
+VGA14:
+ VGAFM
+ 7FF7
+ 640 680 768 800 480 491 493 525
+ 1
+ 79 33
+VGA:Normal
+ VGA
+ 640 680 768 800 480 491 493 525
+ 1
+ 79 29
+
+# Pels: Pallette value definition for VGA, VGAFM drivers
+
+REVPEL: # Values for reverse color
+ 63 63 63
+ 63 63 21
+ 63 21 63
+ 63 21 21
+ 21 63 63
+ 21 63 21
+ 21 21 63
+ 21 21 21
+ 42 42 42
+ 42 21 0
+ 42 0 42
+ 42 0 0
+ 0 42 42
+ 0 42 0
+ 0 0 42
+ 0 0 0
+
+STDPEL: # Standard color
+ 0 0 0
+ 0 0 42
+ 0 42 0
+ 0 42 42
+ 42 0 0
+ 42 0 42
+ 42 21 0
+ 42 42 42
+ 21 21 21
+ 21 21 63
+ 21 63 21
+ 21 63 63
+ 63 21 21
+ 63 21 63
+ 63 63 21
+ 63 63 63
+
+HIPEL: Pels # Hi color
+ 0 0 0
+ 0 0 52
+ 0 52 0
+ 0 52 52
+ 52 0 0
+ 52 0 52
+ 52 31 0
+ 52 52 52
+ 31 31 31
+ 31 31 63
+ 31 63 31
+ 31 63 63
+ 63 31 31
+ 63 31 63
+ 63 63 31
+ 63 63 63
+
+# Startup command definition (usually font loading commands are specified)
+minix:
+ /usr/bin/fld.minix -n /usr/share/fonts/publicfont.ank
+ /usr/bin/fld.minix -n /usr/share/fonts/publicfont.k14
+fontx:
+ /usr/bin/fld.fontx -n /dos/lib/font/new/jpnhn16x.fnt
+ /usr/bin/fld.fontx -n /dos/lib/font/new/jpnzn16x.fnt
+minix-zcat:
+ zcat /usr/share/fonts/publicfont.a.Z | /usr/bin/fld.minix -n
+ zcat /usr/share/fonts/publicfont.k.Z | /usr/bin/fld.minix -n
+fontx-zcat:
+ zcat /dos/lib/font/jpnhn16x.Z | /usr/bin/fld.fontx -n
+ zcat /dos/lib/font/jpnzn16x.Z | /usr/bin/fld.fontx -n
+minix-gzip:Startup
+ gzip -d < /usr/share/fonts/pubfont.k.gz | /usr/bin/fld -t minix -n
+ gzip -d < /usr/share/fonts/pubfont.a.gz | /usr/bin/fld -t minix -n
+fontx-gzip:
+ gzip -d < /dos/lib/font/jpnhn16x.z | /usr/bin/fld.fontx -n
+ gzip -d < /dos/lib/font/jpnzn16x.z | /usr/bin/fld.fontx -n
+
+#################################
+# OPTIONAL SETUP ENTRIES
+#################################
+
+# Mouse type definition. Choose one of: Microsoft,
+# MouseSystems, BusMouse, MMSeries, Logitech, or None.
+Mouse:
+ None
+# Mouse baud rate
+MouseBaud:
+ 1200
+# Mouse device file name
+MouseDev:
+ /dev/mouse
+
+# Use hard scroll
+HardScroll:
+ Off
+
+# Length of beep sound (1/100 sec).
+BeepCounter:
+ 5
+
+# Cursor blink interval (1/10 sec).
+CursorInterval:
+ 4
+
+# Screen blank time (minutes).
+SaveTime:
+ 5
+
+# Use double width cursor on kanji character
+KanjiCursor:
+ On
+
+# Cursor top raster line (0..15)
+CursorTop:
+ 14
+
+# Cursor bottom raster line (CursorTop..15)
+CursorBottom:
+ 15
+
+# Vga Font Offset
+VgaFontOffset:
+ 0
+
+# Save font data in plane 3 (required for Trident TVGA series)
+SavePlane3:
+ Off
+
+Mouse3Buttons:
+ On
+
+# Coding
+# SingleByte DoubleByte 8bitCode
+# ISO8895-[123456789], JISX0201.1976-0
+# BIG5.HKU-0, GB2312.1980-1, JISX0208.1983-0, KSC5601.1987-0
+# EUC, SJIS
+
+ja_JP.ujis:Coding
+ JISX0201.1976-0 JISX0208.1983-0 EUC
+
+ja_JP.sjis:
+ JISX0201.1976-0 JISX0208.1983-0 SJIS
+
+zh_TW.big5:
+ ISO8859-1 BIG5.HKU-0
+
+zh_CN.ugb:
+ ISO8859-1 GB2312.1980-0
+
+ko_KR.euc:
+ ISO8859-1 KSC5601.1987-0
+
+# Show `No warranty' message
+StartupMessage:
+ On
diff --git a/loader/kon2/lib/Makefile b/loader/kon2/lib/Makefile
new file mode 100644
index 000000000..a17a97a0f
--- /dev/null
+++ b/loader/kon2/lib/Makefile
@@ -0,0 +1,23 @@
+OBJ = sockface.o getcap.o mem.o font.o coding.o
+LIB = libgon.a
+
+ifeq (../.config,$(wildcard ../.config))
+include ../.config
+endif
+
+all: $(LIB)
+
+$(LIB): $(OBJ)
+ $(AR) rcs $(LIB) $(OBJ)
+
+depend .depend:
+ $(CC) $(CFLAGS) -M *.c > .depend
+
+clean:
+ $(RM) -f $(OBJ) $(LIB) *~ .depend
+
+install: all
+
+ifeq (.depend,$(wildcard .depend))
+include .depend
+endif
diff --git a/loader/kon2/lib/Makefile.FreeBSD b/loader/kon2/lib/Makefile.FreeBSD
new file mode 100644
index 000000000..5764b8a60
--- /dev/null
+++ b/loader/kon2/lib/Makefile.FreeBSD
@@ -0,0 +1,9 @@
+# kon libraly makefile for FreeBSD
+# Tatsumi Hosokawa <hosokawa@jp.FreeBSD.org>
+
+SRCS= sockface.c getcap.c mem.c font.c coding.c
+CFLAGS= -I${.CURDIR}/../include
+CLEANFILES= Makefile
+LIB= gon
+
+.include <bsd.lib.mk>
diff --git a/loader/kon2/lib/Makefile.linux b/loader/kon2/lib/Makefile.linux
new file mode 100644
index 000000000..a17a97a0f
--- /dev/null
+++ b/loader/kon2/lib/Makefile.linux
@@ -0,0 +1,23 @@
+OBJ = sockface.o getcap.o mem.o font.o coding.o
+LIB = libgon.a
+
+ifeq (../.config,$(wildcard ../.config))
+include ../.config
+endif
+
+all: $(LIB)
+
+$(LIB): $(OBJ)
+ $(AR) rcs $(LIB) $(OBJ)
+
+depend .depend:
+ $(CC) $(CFLAGS) -M *.c > .depend
+
+clean:
+ $(RM) -f $(OBJ) $(LIB) *~ .depend
+
+install: all
+
+ifeq (.depend,$(wildcard .depend))
+include .depend
+endif
diff --git a/loader/kon2/lib/coding.c b/loader/kon2/lib/coding.c
new file mode 100644
index 000000000..ae1a1c5a8
--- /dev/null
+++ b/loader/kon2/lib/coding.c
@@ -0,0 +1,184 @@
+/*
+ * KON2 - Kanji ON Console -
+ * Copyright (C) 1992-1996 Takashi MANABE (manabe@papilio.tutics.tut.ac.jp)
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY TAKASHI MANABE ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE TERRENCE R. LAMBERT BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#include <config.h>
+
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+
+#include <interface.h>
+#include <fnld.h>
+
+static u_int JISX0208(u_char ch1, u_char ch2)
+{
+ if (ch1 > 0x2A)
+ return((ch2 - 0x41 + (ch1 - 0x26) * 96) << 5);
+ else
+ return((ch2 - 0x21 + (ch1 - 0x21) * 96) << 5);
+}
+
+#ifdef MINI_KON
+
+#define GB2312 NULL
+#define BIG5 NULL
+#define KSC5601 NULL
+
+#else
+
+static u_int GB2312(u_char ch1, u_char ch2)
+{
+ if (ch1 > 0x29)
+ return(((ch1 - 0x27) * 94 + ch2 - 0x21) << 5);
+ else
+ return(((ch1 - 0x21) * 94 + ch2 - 0x21) << 5);
+}
+
+static u_int BIG5(u_char ch1, u_char ch2)
+{
+ if (ch2 < 0xA1)
+ return(((ch1 - 0xA1) * 157 + ch2 - 0x40) << 5);
+ else
+ return(((ch1 - 0xA1) * 157 + 63 + ch2 - 0xA1) << 5);
+}
+
+static u_int KSC5601(u_char ch1, u_char ch2)
+{
+ if (ch1 > 0x2D)
+ return((ch2 - 0x21 + (ch1 - 0x24) * 96) << 5);
+ else
+ return((ch2 - 0x21 + (ch1 - 0x21) * 96) << 5);
+}
+
+#endif
+
+static u_int FldJISX0208(u_char ch1, u_char ch2)
+{
+ return(JISX0208(ch1&0x7F, ch2&0x7F));
+}
+
+#ifdef MINI_KON
+
+#define FldGB2312 NULL
+#define FldKSC5601 NULL
+
+#else
+
+static u_int FldKSC5601(u_char ch1, u_char ch2)
+{
+ return(KSC5601(ch1&0x7F, ch2&0x7F));
+}
+
+static u_int FldGB2312(u_char ch1, u_char ch2)
+{
+ return(GB2312(ch1&0x7F, ch2&0x7F));
+}
+
+#endif
+
+struct fontRegs fSRegs[] = {
+ /* latin1(French, Spanish, ...) */
+ { NULL, 0, "ISO8859-1", NULL, 0, 0, 'B', 'A', 0},
+ /* latin2 */
+ { NULL, 0, "ISO8859-2", NULL, 0, 0, 'B', 'B', 0},
+ /* latin3 */
+ { NULL, 0, "ISO8859-3", NULL, 0, 0, 'B', 'C', 0},
+ /* latin4 */
+ { NULL, 0, "ISO8859-4", NULL, 0, 0, 'B', 'D', 0},
+ /* Russian */
+ { NULL, 0, "ISO8859-5", NULL, 0, 0, 'B', 'L', 0},
+ /* Arabic */
+ { NULL, 0, "ISO8859-6", NULL, 0, 0, 'B', 'G', 0},
+ /* Greek */
+ { NULL, 0, "ISO8859-7", NULL, 0, 0, 'B', 'F', 0},
+ /* Hebrew */
+ { NULL, 0, "ISO8859-8", NULL, 0, 0, 'B', 'H', 0},
+ /* latin5 */
+ { NULL, 0, "ISO8859-9", NULL, 0, 0, 'B', 'M', 0},
+ /* Japanese */
+ { NULL, 0,"JISX0201.1976-0", NULL, 0, 0, 'J', 'I', 0},
+ { NULL, 0, NULL, NULL, 0, 0, 0, 0, 0}
+};
+
+struct fontLoaderRegs fldSRegs[] = {
+ { NULL, 0xFF},
+ { NULL, 0xFF},
+ { NULL, 0xFF},
+ { NULL, 0xFF},
+ { NULL, 0xFF},
+ { NULL, 0xFF},
+ { NULL, 0xFF},
+ { NULL, 0xFF},
+ { NULL, 0xFF},
+ { NULL, 0xFF},
+ { NULL, 0},
+};
+
+struct fontRegs fDRegs[] = {
+ /* DF_GB2312 */
+ { GB2312, 0, "GB2312.1980-0", NULL, 0, 0, 'A', 0, 0},
+ /* DF_JISX0208 */
+ {JISX0208, 0,"JISX0208.1983-0", NULL, 0, 0, 'B', 0, 0},
+ /* DF_KSC5601 */
+ { KSC5601, 0, "KSC5601.1987-0", NULL, 0, 0, 'C', 0, 0},
+ /* DF_JISX0212 */
+ {JISX0208, 0, "JISX0212", NULL, 0, 0, 'D', 0, 0},
+ /* DF_BIG5_0 */
+ { BIG5, 0, "BIG5.HKU-0", NULL, 0, 0, '0', 0, 0},
+ /* DF_BIG5_1 */
+ { BIG5, 0, "BIG5.HKU-0", NULL, 0, 0, '1', 0, 0},
+ { NULL, 0, NULL, NULL, 0, 0, 0, 0, 0}
+};
+
+struct fontLoaderRegs fldDRegs[] = {
+ { FldGB2312, 0},
+ {FldJISX0208, 0x7424},
+ { FldKSC5601, 0x7D7E},
+ {FldJISX0208, 0x7424},
+ { BIG5, 0},
+ { BIG5, 0},
+ { NULL, 0}
+};
+
+int CodingByRegistry(char *reg)
+{
+ int i;
+
+ i = 0;
+ while (fSRegs[i].registry) {
+ if (!strncasecmp(fSRegs[i].registry, reg, strlen(reg)))
+ return(i|CHR_SFLD);
+ i ++;
+ }
+ i = 0;
+ while (fDRegs[i].registry) {
+ if (!strncasecmp(fDRegs[i].registry, reg, strlen(reg)))
+ return(i|CHR_DFLD);
+ i ++;
+ }
+ return(-1);
+}
diff --git a/loader/kon2/lib/font.c b/loader/kon2/lib/font.c
new file mode 100644
index 000000000..2ada5c5b1
--- /dev/null
+++ b/loader/kon2/lib/font.c
@@ -0,0 +1,77 @@
+/*
+ * KON2 - Kanji ON Console -
+ * Copyright (C) 1992-1996 Takashi MANABE (manabe@papilio.tutics.tut.ac.jp)
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY TAKASHI MANABE ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE TERRENCE R. LAMBERT BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#include <config.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include <sys/shm.h>
+#include <sys/socket.h>
+#include <errno.h>
+
+#include <fnld.h>
+#include <interface.h>
+
+#ifndef MINI_KON
+
+void DownShmem(char fnum)
+{
+ key_t shmkey;
+ int shmid;
+ struct shmid_ds shmseg;
+
+#if defined(linux)
+ shmkey = ftok(CONFIG_NAME, fnum);
+#elif defined(__FreeBSD__)
+ shmkey = 5000 + (fnum & 0x7F);
+#endif
+ if ((shmid = shmget(shmkey, sizeof(struct fontInfo), 0444)) < 0)
+ return;
+ shmctl(shmid, IPC_STAT, &shmseg);
+ if (shmseg.shm_nattch < 1) {
+ shmctl(shmid, IPC_RMID, 0);
+ }
+}
+
+u_char *GetShmem(fnum)
+char fnum;
+{
+ key_t shmkey;
+ int shmid;
+
+#if defined(linux)
+ shmkey = ftok(CONFIG_NAME, fnum);
+#elif defined(__FreeBSD__)
+ shmkey = 5000 + (fnum & 0x7F);
+#endif
+ if ((shmid = shmget(shmkey, sizeof(struct fontInfo), 0444)) < 0) return(0);
+ return((u_char*)shmat(shmid, 0, SHM_RDONLY));
+}
+
+#endif
diff --git a/loader/kon2/lib/getcap.c b/loader/kon2/lib/getcap.c
new file mode 100644
index 000000000..017373647
--- /dev/null
+++ b/loader/kon2/lib/getcap.c
@@ -0,0 +1,248 @@
+/*
+ * KON2 - Kanji ON Console -
+ * Copyright (C) 1992-1996 Takashi MANABE (manabe@papilio.tutics.tut.ac.jp)
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY TAKASHI MANABE ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE TERRENCE R. LAMBERT BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <stdlib.h>
+
+#include <getcap.h>
+
+#define BUF_SIZE 1024
+
+#define MAX_CAPS 20
+
+static struct capability {
+ char *name; /* Name of capability label */
+ initializer *func; /* Function to perform configuration */
+ int initialized; /* 1 if initialized */
+ char *arg; /* Command line argument for this capability. */
+ char *def_value; /* Default value. NULL means required entry. */
+} cap[MAX_CAPS];
+
+static struct capability *FindCap(const char *name)
+{
+ int i;
+ struct capability *cp;
+
+ for (i = 0, cp = cap; i < MAX_CAPS; i++, cp++) {
+ if ((cp->name != NULL) && (strcasecmp(name, cp->name) == 0)) {
+ return cp;
+ }
+ }
+ return NULL;
+}
+
+/* Define initializer function func for capability name. If def_value is nil,
+ then the entry of the name must exist in configuration file. An error is
+ flagged if no entry is found. If def_value is non-nil and no entry is found
+ in configuration file, then func is invoked with def_value. */
+
+void DefineCap(const char *name, initializer *func, const char *def_value)
+{
+ int i;
+ struct capability *cp;
+
+ /* Pass 1 -- try to replace same name entry if exists. */
+ if ((cp = FindCap(name)) != NULL) {
+#ifdef DEBUG
+ fprintf(stderr, "cap %s redefined (default %s)\r\n", name,
+ def_value ? def_value : "None");
+#endif
+ cp->name = strdup(name);
+ cp->func = func;
+ if (def_value)
+ cp->def_value = strdup(def_value);
+ return;
+ }
+ /* Pass 2 -- fine empty slot and insert new entry. */
+ for (i = 0, cp = cap; i < MAX_CAPS; i++, cp++) {
+ if (cp->name == NULL) {
+#ifdef DEBUG
+ fprintf(stderr, "cap %s defined (default %s)\r\n", name,
+ def_value ? def_value : "None");
+#endif
+ cp->name = strdup(name);
+ cp->func = func;
+ if (def_value)
+ cp->def_value = strdup(def_value);
+ return;
+ }
+ }
+ fprintf(stderr, "Fatal: internal error - can't find room for capability `%s'\r\r\n", name);
+ abort();
+}
+
+/* Delete all initializer functions. */
+
+void CapInit(void)
+{
+ struct capability *cp;
+ int i;
+
+ for (i = 0, cp = cap; i < MAX_CAPS; i++, cp++) {
+#ifdef DEBUG
+ if (cp->name)
+ fprintf(stderr, "cap %s deleted\r\n", cp->name);
+#endif
+ cp->initialized = 0;
+ if (cp->name)
+ free(cp->name);
+ if (cp->arg)
+ free(cp->arg);
+ if (cp->def_value)
+ free(cp->def_value);
+ cp->name = cp->arg = cp->def_value = NULL;
+ }
+}
+
+static const char label_delim[] = ":,; \t\n";
+
+/* Read configuration file named filename and invoke initializer function for each entry. */
+
+int ReadConfig(const char *filename)
+{
+ FILE *capFp;
+ char line[MAX_COLS], *p;
+ char buf[BUF_SIZE];
+ struct capability *c;
+ int i;
+ int errors = 0; /* number of errors during configuration */
+
+ if ((capFp = fopen(filename, "r")) == NULL) {
+ fprintf(stderr, "Error: can't open config file\r\r\n");
+ perror(filename);
+ return FAILURE;
+ }
+
+ while(fgets(line, MAX_COLS, capFp) != NULL) {
+ nextLabel:
+ if ((p = strchr(line, '#')) != NULL)
+ *p = '\0';
+ if (strchr(line, ':') == NULL) continue; /* not a lebel */
+ for (p = strtok(line, label_delim); p != NULL; p = strtok(NULL, label_delim)) {
+ /* Process one label line. */
+ if ((c = FindCap(p)) != NULL) {
+ /* Found matching capability. Get body from file. */
+ char *l = buf;
+ while (fgets(line, MAX_COLS, capFp) != NULL
+ && line[0] == '\t') {
+ char *l2 = line;
+ while (*l2 != '\n' && *l2 != '#') {
+ *l++ = *l2++;
+ }
+ *l++ = '\n';
+ }
+ *l = '\0';
+ if (! c->initialized) {
+ /* do initialize */
+ if (c->arg) {
+#ifdef DEBUG
+ fprintf(stderr, "Capability %s set to arg %s\r\n",
+ c->name, c->arg);
+#endif
+ if (c->func(c->arg) < 0)
+ errors++;
+ } else {
+#ifdef DEBUG
+ fprintf(stderr, "Capability %s set to %s",
+ c->name, buf);
+#endif
+ if (c->func(buf) < 0)
+ errors++;
+ }
+ c->initialized = 1;
+ }
+ goto nextLabel; /* next line already read */
+ }
+ }
+ }
+ /* Default initialization for unspecified capability. */
+ for (i = 0, c = cap; i < MAX_CAPS; i++, c++) {
+ if ((c->name != NULL) && !c->initialized) {
+ if (c->arg) {
+#ifdef DEBUG
+ fprintf(stderr, "Capability %s defaults to arg %s\r\n", c->name, c->arg);
+#endif
+ if (c->func(c->arg) < 0)
+ errors++;
+ } else if (c->def_value) {
+#ifdef DEBUG
+ fprintf(stderr, "Capability %s defaults to %s\r\n", c->name, c->def_value);
+#endif
+ if (c->func(c->def_value) < 0)
+ errors++;
+ } else {
+ fprintf(stderr, "Error: entry for capability `%s' not found\r\r\n", c->name);
+ errors++;
+ }
+ }
+ }
+ fclose(capFp);
+#ifdef DEBUG
+ fprintf(stderr, "Finished reading config file\r\n");
+#endif
+ if (errors)
+ return FAILURE;
+ else
+ return SUCCESS;
+}
+
+/* Set value for capability capName. */
+int SetCapArg(const char *capName, const char *value)
+{
+ struct capability *cp;
+ if ((cp = FindCap(capName)) == NULL) {
+ return FAILURE;
+ }
+ if (cp->def_value == NULL) {
+ /* Protected capability. */
+ return FAILURE;
+ }
+ cp->arg = strdup(value);
+#ifdef DEBUG
+ fprintf(stderr, "Setting arg for %s to %s\r\n", capName, value);
+#endif
+ return SUCCESS;
+}
+
+/* Utility function that return 1 if confstr is "On" and 0 if "OFF". */
+
+bool BoolConf(const char *confstr)
+{
+ char name[MAX_COLS];
+ sscanf(confstr, "%s", name);
+ if (strcasecmp(name, "On") == 0 ||
+ strcasecmp(name, "True") == 0) {
+ return TRUE;
+ } else if (strcasecmp(name, "Off") != 0 &&
+ strcasecmp(name, "False") != 0) {
+ fprintf(stderr, "Warning: value `%s' unrecognized as boolean; assuming `Off'\r\r\n",
+ name);
+ }
+ return FALSE;
+}
diff --git a/loader/kon2/lib/load.c b/loader/kon2/lib/load.c
new file mode 100644
index 000000000..68aca8704
--- /dev/null
+++ b/loader/kon2/lib/load.c
@@ -0,0 +1,48 @@
+/*
+ * KON2 - Kanji ON Console -
+ * Copyright (C) 1992-1996 Takashi MANABE (manabe@papilio.tutics.tut.ac.jp)
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY TAKASHI MANABE ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE TERRENCE R. LAMBERT BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+u_char *LoadFromShm(u_char *fbuff, int fd, struct fontInfo *fi)
+{
+ int shmid;
+ u_char *addr;
+
+ read(fd, &shmid, sizeof(shmid));
+ read(fd, fi, sizeof(struct fontInfo));
+ addr = memalign(fi->size, PAGE_SIZE);
+ if (addr < 0) {
+ Perror("memalign");
+ return NULL;
+ }
+ if ((addr = shmat(shmid, addr, 0)) == (char *) -1) {
+ Perror("shmat");
+ free(addr);
+ return NULL;
+ }
+ if (fbuff)
+ free(fbuff);
+ return addr;
+}
diff --git a/loader/kon2/lib/mem.c b/loader/kon2/lib/mem.c
new file mode 100644
index 000000000..978d938f0
--- /dev/null
+++ b/loader/kon2/lib/mem.c
@@ -0,0 +1,86 @@
+/*
+ * KON2 - Kanji ON Console -
+ * Copyright (C) 1992-1996 Takashi MANABE (manabe@papilio.tutics.tut.ac.jp)
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY TAKASHI MANABE ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE TERRENCE R. LAMBERT BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#include <sys/types.h>
+#include <mem.h>
+#if defined(linux)
+#include <malloc.h>
+#else
+#include <stdlib.h>
+#endif
+
+u_char PortInb(unsigned short port)
+{
+ u_char _rval;
+
+ __asm__ volatile ("inb %1,%0"
+ :"=a" (_rval)
+ :"d" ((u_short) port));
+
+ return(_rval);
+}
+
+void wzero(void *head, int n)
+{
+ __asm__ ("cld\n\t"
+ "rep\n\t"
+ "stosw"
+ ::"a" (0),
+ "c" (n>>1),
+ "D" ((long)head)
+ :"cx","di");
+}
+
+void wmove(void *dst, void *src, int n)
+{
+ __asm__ ("cld\n\t"
+ "rep\n\t"
+ "movsw\n\t"
+ ::"c" (n>>1),
+ "D" ((long)dst),
+ "S" ((long)src)
+ :"cx","di","si");
+}
+
+void lmove(void *dst, void *src, int n)
+{
+ __asm__ ("cld\n\t"
+ "rep\n\t"
+ "movsl\n\t"
+ ::"c" (n>>2),
+ "D" ((long)dst),
+ "S" ((long)src)
+ :"cx","di","si");
+}
+
+void SafeFree(void **p)
+{
+ if (*p) {
+ free(*p);
+ *p = NULL;
+ }
+}
diff --git a/loader/kon2/lib/sockface.c b/loader/kon2/lib/sockface.c
new file mode 100644
index 000000000..bef533713
--- /dev/null
+++ b/loader/kon2/lib/sockface.c
@@ -0,0 +1,133 @@
+/*
+ * KON2 - Kanji ON Console -
+ * Copyright (C) 1992-1996 Takashi MANABE (manabe@papilio.tutics.tut.ac.jp)
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY TAKASHI MANABE ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE TERRENCE R. LAMBERT BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#include <config.h>
+
+#ifndef MINI_KON
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/time.h>
+#include <sys/file.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#ifdef linux
+#include <sys/vt.h>
+#endif
+#include <sys/ioctl.h>
+
+#include <interface.h>
+
+u_int wfontSize, sfontSize;
+u_char *sbFontBuff, *dbFontBuff;
+
+/*
+char socketName[MAX_SOCKET_NAME+1];
+*/
+
+static u_char clientNumber;
+
+void SocketKill(int sfd)
+{
+ close(sfd);
+ unlink("/tmp/.kon");
+}
+
+int SocketRecCommand(int fd, struct messageHeader *mh)
+{
+ return(read(fd, mh, sizeof(struct messageHeader)));
+}
+
+int SocketSendCommand(int fd, char cmd)
+{
+ struct messageHeader mh;
+
+ mh.cmd = cmd;
+ mh.cno = clientNumber;
+ return(write(fd, &mh, sizeof(struct messageHeader)));
+}
+
+int SocketSearchName(struct sockaddr *sa, int fd)
+{
+#ifdef linux
+ struct vt_stat vs;
+#endif
+
+ bzero(sa, sizeof(struct sockaddr));
+ sa->sa_family = AF_UNIX;
+#if defined(linux)
+ if (ioctl(fd, VT_GETSTATE, &vs) < 0) {
+ return EOF;
+ }
+ sprintf(sa->sa_data, "%s%d", SOCKET_BASENAME, vs.v_active);
+#elif defined(__FreeBSD__)
+ sprintf(sa->sa_data, "%s", SOCKET_BASENAME);
+#endif
+ return(0);
+}
+
+int SocketClientOpen(void)
+{
+ int s, len;
+ struct sockaddr sa;
+ int fd;
+
+ if ((fd = open("/dev/console", O_WRONLY)) < 0)
+ fd = open("/dev/console", O_RDONLY);
+ SocketSearchName(&sa, fd);
+ s = socket(AF_UNIX, SOCK_STREAM, 0);
+
+#if defined(linux)
+ len = sizeof(sa.sa_family) + strlen(sa.sa_data);
+#elif defined(__FreeBSD__)
+ len = sizeof(sa.sa_family) + strlen(sa.sa_data) + 1;
+#endif
+ if (connect(s, &sa, len) == -1) s = EOF;
+ return(s);
+}
+
+int SocketSendData(u_char *buff, int size, int fd)
+{
+ int i;
+ struct messageHeader mh;
+
+ for (i = 0; i < size; i += BUFSIZ) {
+ if ((size - i) < BUFSIZ)
+ write(fd, (void *)buff, size - i);
+ else
+ write(fd, (void *)buff, BUFSIZ);
+ SocketRecCommand(fd, &mh);
+ if (mh.cmd != CHR_ACK) return(EOF);
+ buff += BUFSIZ;
+ }
+ return(0);
+}
+
+#endif
diff --git a/loader/kon2/src/Makefile b/loader/kon2/src/Makefile
new file mode 100644
index 000000000..c8fd42933
--- /dev/null
+++ b/loader/kon2/src/Makefile
@@ -0,0 +1,40 @@
+DISP = display.a
+OBJS = vt.o sock.o fnld.o vc.o mouse.o term.o main.o utmp.o errors.o child.o
+KON = libkon.a(vt.o sock.o fnld.o vc.o mouse.o term.o main.o utmp.o errors.o child.o)
+
+ifeq (../.config,$(wildcard ../.config))
+include ../.config
+endif
+
+#CC := $(CC) -g
+#LD := $(CC) -lgmon
+SUBDIRS = display
+
+all: subdirs $(KON)
+
+#$(KON): $(OBJS) $(DISP) $(LIB)
+# $(LD) -o $(KON) $(OBJS) $(DISP) $(LIB)
+
+depend .depend:
+ $(CC) $(CFLAGS) -M *.c > .depend
+ @for i in $(SUBDIRS);\
+ do (cd $$i && echo building dependencies in $$i && $(MAKE) depend) || exit;\
+ done
+
+subdirs:
+ @for i in $(SUBDIRS);\
+ do (cd $$i && echo making all in $$i && $(MAKE)) || exit;\
+ done
+
+clean:
+ $(RM) -f *.o $(KON) *~ .depend
+ @for i in $(SUBDIRS);\
+ do (cd $$i && echo cleaning all in $$i && $(MAKE) clean) || exit;\
+ done
+
+install: $(KON)
+ $(INSTALL) -m 4755 $(KON) $(BINDIR)
+
+ifeq (.depend,$(wildcard .depend))
+include .depend
+endif
diff --git a/loader/kon2/src/Makefile.FreeBSD b/loader/kon2/src/Makefile.FreeBSD
new file mode 100644
index 000000000..d45b8f613
--- /dev/null
+++ b/loader/kon2/src/Makefile.FreeBSD
@@ -0,0 +1,31 @@
+# FreeBSD makefile for kon
+# Tatsumi Hosokawa <hosokawa@jp.FreeBSD.org>
+
+PROG= kon
+BINOWN= root
+BINMODE= 4555
+SRCS= vt.c sock.c fnld.c vc.c mouse.c term.c main.c utmp.c errors.c child.c
+LIBS+= -L${.CURDIR}/display -L${.CURDIR}/../lib -ldisplay -lgon
+NOMAN= YES
+CFLAGS+= -I${.CURDIR}/../include
+CLEANFILES= Makefile
+
+.if exists(${.OBJDIR}/../lib)
+LIBOBJ= -L${.OBJDIR}/../lib
+.else
+LIBOBJ= -L${.CURDIR}/../lib
+.endif
+
+.if exists(${.OBJDIR}/display)
+LIBOBJ+= -L${.OBJDIR}/display
+.else
+LIBOBJ+= -L${.CURDIR}/display
+.endif
+
+LDADD= ${LIBOBJ} -ldisplay -lgon
+
+.if exists(${.CURDIR}/../.config)
+.include "${.CURDIR}/../.config"
+.endif
+
+.include <bsd.prog.mk>
diff --git a/loader/kon2/src/Makefile.linux b/loader/kon2/src/Makefile.linux
new file mode 100644
index 000000000..a8f046575
--- /dev/null
+++ b/loader/kon2/src/Makefile.linux
@@ -0,0 +1,40 @@
+DISP = display.a
+OBJS = vt.o sock.o fnld.o vc.o mouse.o term.o main.o utmp.o errors.o child.o
+KON = kon
+
+ifeq (../.config,$(wildcard ../.config))
+include ../.config
+endif
+
+#CC := $(CC) -g
+#LD := $(CC) -lgmon
+SUBDIRS = display
+
+all: subdirs $(KON)
+
+$(KON): $(OBJS) $(DISP) $(LIB)
+ $(LD) -o $(KON) $(OBJS) $(DISP) $(LIB)
+
+depend .depend:
+ $(CC) $(CFLAGS) -M *.c > .depend
+ @for i in $(SUBDIRS);\
+ do (cd $$i && echo building dependencies in $$i && $(MAKE) depend) || exit;\
+ done
+
+subdirs:
+ @for i in $(SUBDIRS);\
+ do (cd $$i && echo making all in $$i && $(MAKE)) || exit;\
+ done
+
+clean:
+ $(RM) -f *.o $(KON) *~ .depend
+ @for i in $(SUBDIRS);\
+ do (cd $$i && echo cleaning all in $$i && $(MAKE) clean) || exit;\
+ done
+
+install: $(KON)
+ $(INSTALL) -m 4755 $(KON) $(BINDIR)
+
+ifeq (.depend,$(wildcard .depend))
+include .depend
+endif
diff --git a/loader/kon2/src/child.c b/loader/kon2/src/child.c
new file mode 100644
index 000000000..b6900e68e
--- /dev/null
+++ b/loader/kon2/src/child.c
@@ -0,0 +1,148 @@
+/*
+ * KON2 - Kanji ON Console -
+ * Copyright (C) 1992-1996 Takashi MANABE (manabe@papilio.tutics.tut.ac.jp)
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY TAKASHI MANABE ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE TERRENCE R. LAMBERT BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#include <config.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+
+#include <getcap.h>
+
+#include <defs.h>
+#include <version.h>
+#include <vc.h>
+
+static char *startupStr, *execProg;
+
+int ConfigExecProg(const char *string)
+{
+ execProg = strdup(string);
+ return SUCCESS;
+}
+
+#ifndef MINI_KON
+
+static int ConfigStartup(const char *string)
+{
+ startupStr = strdup(string);
+ return SUCCESS;
+}
+
+static void RunStartupCmd(void)
+{
+ char *p;
+
+ p = strtok(startupStr, "\n");
+ while(p) {
+ system(p);
+ p = strtok(NULL, "\n");
+ }
+}
+
+static bool startupMessage;
+
+static int ConfigMessage(const char *confstr)
+{
+ startupMessage = BoolConf(confstr);
+ return SUCCESS;
+}
+
+void ChildInit(void)
+{
+ DefineCap("StartupMessage", ConfigMessage, "On");
+ DefineCap("StartUp", ConfigStartup, NULL);
+}
+
+#endif
+
+void ChildCleanup(void)
+{
+ free(startupStr);
+}
+
+void ChildStart(FILE *errfp)
+{
+ char *tail, *tcap;
+ char buff[256];
+ extern char *TermName();
+
+#ifndef MINI_KON
+ char *shell;
+ setgid(getgid());
+ setuid(getuid());
+
+ RunStartupCmd();
+#endif
+
+#if defined(linux)
+#ifdef MINI_KON
+ strcpy(buff, "TERM=linux");
+#else
+ strcpy(buff, "TERM=kon");
+#endif
+#elif defined(__FreeBSD__)
+ sprintf(buff,"TERM=vt100");
+#endif
+
+ tcap = strdup(buff);
+ putenv(tcap);
+
+#ifndef MINI_KON
+ if (startupMessage)
+ printf("\rKON2 Kanji On Console " VERSION
+ " using VT number %c\r\n"
+ "%*s\r\n"
+ "%*s\r\n", *(TermName()+8),
+ dInfo.txmax,
+ "Copyright (C) "
+ "1993-1996 Takashi MANABE",
+ dInfo.txmax,
+ "1993, 1994 MAEDA Atusi ");
+#if defined(__FreeBSD__)
+ printf("\rKON for FreeBSD-2.x ver0.01 Takashi OGURA\r\n");
+#endif
+
+ fflush(stdout);
+#endif
+
+ if (execProg)
+ execlp(execProg, execProg, 0);
+ else {
+ if ((execProg = getenv("SHELL")) == NULL)
+ execProg = "/bin/sh";
+ if ((tail = rindex(execProg, '/')) == NULL)
+ tail = " sh";
+ sprintf(buff, "-%s", tail + 1);
+ execl(execProg, buff, 0);
+ }
+ fprintf(errfp, "KON> couldn't exec shell\r\n");
+ fprintf(errfp, "%s: %s\r\n", execProg, strerror(errno));
+ exit(EXIT_FAILURE);
+}
diff --git a/loader/kon2/src/display/Makefile b/loader/kon2/src/display/Makefile
new file mode 100644
index 000000000..57ec7be20
--- /dev/null
+++ b/loader/kon2/src/display/Makefile
@@ -0,0 +1,34 @@
+OBJS =
+DISP = ../display.a
+
+ifeq (../../.config,$(wildcard ../../.config))
+include ../../.config
+endif
+
+ifdef HAS_S3
+OBJS := $(OBJS) s3.o
+endif
+ifdef HAS_J31SX
+OBJS := $(OBJS) j31sx.o
+endif
+OBJS := $(OBJS) svga.o vga.o
+
+#CC := $(CC) -g
+#LD := $(CC) -g
+
+all: $(DISP)
+
+$(DISP): $(OBJS)
+ $(AR) rcs $(DISP) $(OBJS)
+
+depend .depend:
+ $(CC) $(CFLAGS) -M *.c > .depend
+
+clean:
+ $(RM) -f *.o $(DISP) *~ .depend
+
+install: all
+
+ifeq (.depend,$(wildcard .depend))
+include .depend
+endif
diff --git a/loader/kon2/src/display/Makefile.FreeBSD b/loader/kon2/src/display/Makefile.FreeBSD
new file mode 100644
index 000000000..dfcac4433
--- /dev/null
+++ b/loader/kon2/src/display/Makefile.FreeBSD
@@ -0,0 +1,20 @@
+# Tatsumi Hosokawa <hosokawa@jp.FreeBSD.org>
+
+.if exists(${.CURDIR}/../../.config)
+.include "${.CURDIR}/../../.config"
+.endif
+
+SRCS= svga.c vga.c
+
+.ifdef HAS_S3
+SRCS+= s3.c
+.endif
+
+.ifdef HAS_J31SX
+SRCS+= j31sx.c
+.endif
+
+CFLAGS+= -I${.CURDIR}/../../include
+LIB=display
+
+.include <bsd.lib.mk>
diff --git a/loader/kon2/src/display/Makefile.linux b/loader/kon2/src/display/Makefile.linux
new file mode 100644
index 000000000..57ec7be20
--- /dev/null
+++ b/loader/kon2/src/display/Makefile.linux
@@ -0,0 +1,34 @@
+OBJS =
+DISP = ../display.a
+
+ifeq (../../.config,$(wildcard ../../.config))
+include ../../.config
+endif
+
+ifdef HAS_S3
+OBJS := $(OBJS) s3.o
+endif
+ifdef HAS_J31SX
+OBJS := $(OBJS) j31sx.o
+endif
+OBJS := $(OBJS) svga.o vga.o
+
+#CC := $(CC) -g
+#LD := $(CC) -g
+
+all: $(DISP)
+
+$(DISP): $(OBJS)
+ $(AR) rcs $(DISP) $(OBJS)
+
+depend .depend:
+ $(CC) $(CFLAGS) -M *.c > .depend
+
+clean:
+ $(RM) -f *.o $(DISP) *~ .depend
+
+install: all
+
+ifeq (.depend,$(wildcard .depend))
+include .depend
+endif
diff --git a/loader/kon2/src/display/j31sx.c b/loader/kon2/src/display/j31sx.c
new file mode 100644
index 000000000..380c040a7
--- /dev/null
+++ b/loader/kon2/src/display/j31sx.c
@@ -0,0 +1,453 @@
+/*
+ * KON2 - Kanji ON Console -
+ * Copyright (C) 1992-1996 Takashi MANABE (manabe@papilio.tutics.tut.ac.jp)
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY TAKASHI MANABE ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE TERRENCE R. LAMBERT BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+/*
+ This code is based on vgalib.
+
+ Thanks to frandsen@diku.dk (Tommy Frandsen).
+*/
+
+/*
+ This code is modified for DCGA by obuk@MIX.
+
+ Thanks to obuk@MIX.
+*/
+
+#include <config.h>
+
+#ifdef HAS_J31SX
+
+#include <stdio.h>
+#include <fcntl.h>
+#include <termios.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/mman.h>
+/* #include <linux/mm.h> */
+#include <sys/kd.h>
+#undef free
+#include <stdlib.h>
+
+#include <mem.h>
+#include <getcap.h>
+#include <defs.h>
+#include <errors.h>
+#include <vc.h>
+
+#define COLUMNS 80
+#define ROWS 25
+
+#define GRAPH_BASE 0xB8000
+#define GRAPH_SIZE (LSIZE*NLINES)
+
+#define LSIZE (0x800*4)
+#define NLINES 4
+
+#define LINE0 (0*LSIZE)
+#define LINE1 (1*LSIZE)
+#define LINE2 (2*LSIZE)
+#define LINE3 (3*LSIZE)
+
+#define CGA_DATA 0x3d4
+#define CGA_MODE 0x3d8
+#define CGA_COLOR 0x3d9
+#define CGA_STATUS 0x3da
+
+struct cgaRegs {
+ u_char mode;
+ u_char data[16];
+ u_char color;
+};
+
+static struct cgaRegs
+ regText = {
+ 0x2d & ~8, /* mode */
+ {
+ 0x71, 0x50, 0x5a, 0x0a, 0x1f, 0x06, 0x19, 0x1c, /* data */
+ 0x02, 0x07, 0x06, 0x07, 0x00, 0x00, 0x00, 0x00,
+ },
+ 0x30, /* color */
+ },
+ regGraph = {
+ 0x1e & ~8, /* mode */
+ {
+ 0x38, 0x28, 0x2d, 0x0a, 0x7f, 0x06, 0x64, 0x7d, /* data */
+ 0x02, 0x03, 0x06, 0x07, 0x00, 0x00, 0x00, 0x00,
+ },
+ 0x3f, /* color */
+ };
+
+
+static char *gram; /* dummy buffer for mmapping grahics memory */
+static int origin = 0;
+static int scroll = 0;
+static int mode;
+static u_int writeAddr; /* address to write next character */
+
+static bool boxCursor;
+static bool kanjiCursor;
+
+#define DIM(x) (sizeof(x)/sizeof((x)[0]))
+#define min(a,b) ((a)<(b)?(a):(b))
+
+static void ClearLines(int top, int bottom);
+static void SetOrigin(int pos);
+static void DisableVideo(void);
+static void EnableVideo(void);
+static void SetRegisters(struct cgaRegs *regs);
+
+static u_char wspace[] = {
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+};
+
+static inline
+void VgaSetAddress(u_int p)
+{
+ int row = (p / COLUMNS + scroll) % ROWS;
+ int column = p % COLUMNS;
+ writeAddr = row*COLUMNS*4 + column;
+}
+
+
+static
+void VgaSput(u_char *code, u_char fc, u_char bc)
+{
+ int pos, i; char x;
+ int underline;
+
+ underline = fc & ATTR_ULINE;
+ fc &= 7; bc &= 7;
+ if (!code || fc == bc) code = wspace;
+ x = (fc < bc)? 0xff: 0x00;
+
+ pos = origin + writeAddr - COLUMNS;
+ for (i = 0; i < NLINES; i++) {
+ pos = (pos+COLUMNS) & (LSIZE-1);
+ gram[pos+LINE0] = x ^ *code++;
+ gram[pos+LINE1] = x ^ *code++;
+ gram[pos+LINE2] = x ^ *code++;
+ gram[pos+LINE3] = x ^ *code++;
+ }
+ if (underline) {
+ gram[pos+LINE3] = 0xff;
+ }
+}
+
+
+static
+void VgaWput(u_char *code, u_char fc, u_char bc)
+{
+ int pos1, pos2, i; char x;
+ int underline;
+
+ underline = fc & ATTR_ULINE;
+ fc &= 7; bc &= 7;
+ if (!code || fc == bc) code = wspace;
+ x = (fc < bc)? 0xff: 0x00;
+
+ pos1 = origin + writeAddr - COLUMNS;
+ for (i = 0; i < NLINES; i++) {
+ pos1 = (pos1+COLUMNS) & (LSIZE-1);
+ pos2 = (pos1+1) & (LSIZE-1);
+ gram[pos1+LINE0] = x ^ *code++; gram[pos2+LINE0] = x ^ *code++;
+ gram[pos1+LINE1] = x ^ *code++; gram[pos2+LINE1] = x ^ *code++;
+ gram[pos1+LINE2] = x ^ *code++; gram[pos2+LINE2] = x ^ *code++;
+ gram[pos1+LINE3] = x ^ *code++; gram[pos2+LINE3] = x ^ *code++;
+ }
+ if (underline) {
+ gram[pos1+LINE3] = 0xff; gram[pos2+LINE3] = 0xff;
+ }
+}
+
+
+static inline
+void VgaSetCursorAddress(struct cursorInfo *ci, u_int x, u_int y)
+{
+ ci->addr = y*COLUMNS*4 + x;
+}
+
+static inline
+void VgaCursor(struct cursorInfo *ci)
+{
+ int pos, i;
+
+ pos = origin + ci->addr;
+ i = 0;
+ if (! boxCursor)
+ pos += COLUMNS*3; i += 3;
+
+ for (; i < NLINES; i++) {
+ pos &= LSIZE-1;
+ gram[pos+LINE0] ^= 0xff;
+ gram[pos+LINE1] ^= 0xff;
+ gram[pos+LINE2] ^= 0xff;
+ gram[pos+LINE3] ^= 0xff;
+ if (kanjiCursor && ci->kanji) {
+ int pos2 = (pos+1) & (LSIZE-1);
+ gram[pos2+LINE0] ^= 0xff;
+ gram[pos2+LINE1] ^= 0xff;
+ gram[pos2+LINE2] ^= 0xff;
+ gram[pos2+LINE3] ^= 0xff;
+ }
+ pos += COLUMNS;
+ }
+}
+
+
+
+static
+void VgaSetStartAddress(void)
+{
+ SetOrigin(origin);
+}
+
+static
+void VgaHardScrollUp(int line)
+{
+ if (line > ROWS-1) {
+ line %= ROWS;
+ ClearLines(0, ROWS-1);
+ }
+ SetOrigin(origin + line*COLUMNS*4);
+ ClearLines(ROWS-line, ROWS-1);
+ scroll = (scroll-line+ROWS) % ROWS;
+}
+
+static
+void VgaHardScrollDown(int line)
+{
+ if (line > ROWS-1) {
+ line %= ROWS;
+ ClearLines(0, ROWS-1);
+ }
+ SetOrigin(origin - line*COLUMNS*4);
+ ClearLines(0, line-1);
+ scroll = (scroll+line+ROWS) % ROWS;
+}
+
+
+static void ClearLines(int top, int bottom)
+{
+ int pos, bytes, n;
+ if (top > bottom) return;
+ pos = origin + top*COLUMNS*4;
+ bytes = (bottom+1-top)*COLUMNS*4;
+ while (bytes > 0) {
+ pos &= (LSIZE-1);
+ n = min(bytes, LSIZE-pos);
+ bzero2(&gram[pos+LINE0], n);
+ bzero2(&gram[pos+LINE1], n);
+ bzero2(&gram[pos+LINE2], n);
+ bzero2(&gram[pos+LINE3], n);
+ pos += n;
+ bytes -= n;
+ }
+}
+
+static
+void VgaClearAll(void)
+{
+ ClearLines(0, ROWS-1);
+}
+
+static
+void VgaScreenSaver(bool blank)
+{
+ if (blank) {
+ DisableVideo();
+ } else {
+ EnableVideo();
+ }
+}
+
+
+static
+void VgaTextMode(void)
+{
+ SetRegisters(&regText);
+ EnableVideo();
+}
+
+static
+void VgaGraphMode(void)
+{
+ SetRegisters(&regGraph);
+ EnableVideo();
+}
+
+static
+void VgaInit(void)
+{
+ SetRegisters(&regGraph); /* enter graphics mode */
+ lzero(gram, GRAPH_SIZE);
+ EnableVideo();
+}
+
+
+static void DisableVideo(void)
+{
+ PortOutb(mode &= ~8, CGA_MODE);
+}
+
+
+static void EnableVideo(void)
+{
+ PortOutb(mode |= 8, CGA_MODE);
+}
+
+
+static void SetOrigin(int pos)
+{
+ int word_address = (origin = pos & (LSIZE-1)) >> 1;
+ int hi = word_address >> 8;
+ int lo = word_address & 0x00FF;
+#ifdef wordport_magic
+ PortOutw(12 | (hi << 8), CGA_DATA);
+ PortOutw(13 | (lo << 8), CGA_DATA);
+#else
+ PortOutb(12, CGA_DATA);
+ PortOutb(hi, CGA_DATA+1);
+ PortOutb(13, CGA_DATA);
+ PortOutb(lo, CGA_DATA+1);
+#endif
+}
+
+
+static void SetRegisters(struct cgaRegs *regs)
+{
+ int i;
+
+ PortOutb(0, CGA_MODE); /* disable video */
+ for (i = 0; i < DIM(regs->data); ++i) {
+#ifdef wordport_magic
+ PortOutw((regs->data[i] << 8) | i, CGA_DATA);
+#else
+ PortOutb(i, CGA_DATA);
+ PortOutb(regs->data[i], CGA_DATA+1);
+#endif
+ }
+ PortOutb(regs->color, CGA_COLOR);
+ PortOutb(mode = regs->mode, CGA_MODE);
+}
+
+static void VgaDetach(void)
+{
+ origin = scroll = 0;
+ ioperm(CGA_MODE, 1, 0);
+ ioperm(CGA_DATA, 2, 0);
+ ioperm(CGA_COLOR, 1, 0);
+
+ munmap(gram, GRAPH_SIZE);
+
+ SafeFree((void **)&gram);
+}
+
+static struct videoInfo J31SXInfo =
+{
+ TRUE,
+ VgaInit,
+ VgaTextMode,
+ VgaGraphMode,
+ VgaWput,
+ VgaSput,
+ VgaSetCursorAddress,
+ VgaSetAddress,
+ VgaCursor,
+ VgaClearAll,
+ VgaScreenSaver,
+ VgaDetach,
+ VgaSetStartAddress,
+ VgaHardScrollUp,
+ VgaHardScrollDown
+};
+
+static int ConfigKanjiCursor(const char *confstr)
+{
+ kanjiCursor = BoolConf(confstr);
+ return SUCCESS;
+}
+
+static int ConfigBoxCursor(const char *confstr)
+{
+ boxCursor = BoolConf(confstr);
+ return SUCCESS;
+}
+
+int J31SXSetVideoType(struct videoInfo *info, const char *regs)
+{
+ int devMem;
+
+ /* Calculate display info */
+ dInfo.gxdim = 640;
+ dInfo.gydim = 400;
+ dInfo.txmax = COLUMNS-1;
+ dInfo.tymax = ROWS-1;
+
+ dInfo.glineChar = dInfo.gydim / (dInfo.tymax + 1);
+ dInfo.glineByte = dInfo.gxdim >> 3;
+ dInfo.gydim = dInfo.glineChar * (dInfo.tymax + 1);
+ dInfo.gsize = dInfo.glineByte * dInfo.gydim;
+ dInfo.tlineByte = dInfo.glineChar * dInfo.glineByte;
+
+ /* get I/O permissions for VGA registers */
+ ioperm(CGA_MODE, 1, 1);
+ ioperm(CGA_DATA, 2, 1);
+ ioperm(CGA_COLOR, 1, 1);
+
+ if ((devMem = open("/dev/mem", O_RDWR) ) < 0) {
+ Perror("/dev/mem");
+ return FAILURE;
+ }
+ gram = (unsigned char *)mmap(
+ (__ptr_t)0,
+ GRAPH_SIZE,
+ PROT_READ|PROT_WRITE,
+#if 0
+ MAP_SHARED|MAP_FIXED,
+#else
+ MAP_SHARED,
+#endif
+ devMem,
+ GRAPH_BASE
+ );
+ close(devMem);
+ if ((long)gram < 0) {
+ Perror("mmap");
+ return FAILURE;
+ }
+
+ *info = J31SXInfo;
+ DefineCap("KanjiCursor", ConfigKanjiCursor, "On");
+ DefineCap("BoxCursor", ConfigBoxCursor, "Off");
+
+ return SUCCESS;
+}
+
+#endif
diff --git a/loader/kon2/src/display/s3.c b/loader/kon2/src/display/s3.c
new file mode 100644
index 000000000..e90c7c5f6
--- /dev/null
+++ b/loader/kon2/src/display/s3.c
@@ -0,0 +1,264 @@
+/*
+ * KON2 - Kanji ON Console -
+ * Copyright (C) 1992-1996 Takashi MANABE (manabe@papilio.tutics.tut.ac.jp)
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY TAKASHI MANABE ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE TERRENCE R. LAMBERT BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+/*
+ This code is based on vgalib.
+
+ Thanks to frandsen@diku.dk (Tommy Frandsen).
+ */
+
+#include <config.h>
+
+#ifndef MINI_KON
+
+#ifdef HAS_VGA
+
+#include <stdio.h>
+#include <fcntl.h>
+#include <termios.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/mman.h>
+#include <linux/mm.h>
+#include <sys/kd.h>
+#undef free
+#include <stdlib.h>
+
+#include <mem.h>
+#include <getcap.h>
+#include <defs.h>
+#include <errors.h>
+#include <vc.h>
+#include <vt.h>
+#include <vga.h>
+#include <fnld.h>
+
+#define R5x_MASK 0x7737
+
+union s3Regs {
+ struct {
+ u_char r3[10];/* Video Atribute (CR30-34, CR38-3C) */
+ u_char rx[33];/* Video Atribute (CR40-65) */
+ } x;
+ struct {
+ u_char
+ x30, x31, x32, x33, x34,
+ x38, x39, x3a, x3b, x3c;
+ u_char
+ x40, x41, x42, x43, x44, x45, x46, x47,
+ x48, x49, x4a, x4b, x4c, x4d, x4e, x4f,
+ x50, x51, x53, x54, x55, x58, x59, x5a, x5c, x5d, x5e,
+ x60, x61, x62, x63, x64, x65;
+ } r;
+} s3Text, s3Graph;
+
+static
+ void S3SetRegisters(union s3Regs *regs)
+{
+ int i, n;
+
+ PortOutw(0xa539, vgaCrtAddr); /* unlock system control regs */
+ for (i = 0; i < 5; i ++) {
+ PortOutb(0x30 + i, vgaCrtAddr);
+ PortOutb(regs->x.r3[i], vgaCrtData);
+ PortOutb(0x38 + i, vgaCrtAddr);
+ PortOutb(regs->x.r3[5+i], vgaCrtData);
+ }
+ for (i = 0; i < 16; i ++) {
+ PortOutb(0x40 + i, vgaCrtAddr);
+ PortOutb(regs->x.rx[i], vgaCrtData);
+ }
+ for (n = 16, i = 0; i < 16; i ++) {
+ if ((1 << i) & R5x_MASK) {
+ PortOutb(0x50 + i, vgaCrtAddr);
+ PortOutb(regs->x.rx[n], vgaCrtData);
+ n ++;
+ }
+ }
+ for (i = 0; i < 6; i ++, n ++) {
+ PortOutb(0x60 + i, vgaCrtAddr);
+ PortOutb(s3Text.x.rx[n], vgaCrtData);
+ }
+}
+
+static
+ void S3SetStartAddress(void)
+{
+ u_int til;
+
+ PortOutb(0x31, vgaCrtAddr);
+ PortOutb(((gramHead & 0x030000) >> 12) | s3Graph.r.x31, vgaCrtData);
+ s3Graph.r.x51 &= ~0x03;
+ s3Graph.r.x51 |= ((gramHead & 0x040000) >> 18);
+ PortOutb(0x51, vgaCrtAddr);
+ /* Don't override current bank selection */
+ PortOutb((PortInb(vgaCrtData) & ~0x03)
+ | ((gramHead & 0x40000) >> 18), vgaCrtData);
+
+ PortOutw((gramHead & 0xFF00) | 0x0c, vgaCrtAddr);
+ PortOutw(((gramHead & 0x00FF) << 8) | 0x0d, vgaCrtAddr);
+
+ til = dInfo.gydim - 1 - (gramHead / dInfo.glineByte);
+ PortOutw((til << 8) | 0x18, vgaCrtAddr);
+ PortOutw(((til & 0x100) << 4) | LineComp8, vgaCrtAddr);
+ PortOutw(((til & 0x200) << 5) | LineComp9, vgaCrtAddr);
+ PortOutw(0x8d31, vgaCrtAddr); /* unlock system control regs */
+}
+
+static
+ void S3TextMode(void)
+{
+ VgaTextMode();
+ S3SetRegisters(&s3Text);
+}
+
+static
+ void S3CalcNewRegs(union videoTimings *video)
+{
+ regGraph.mis |= 0x0D;
+/* regGraph.crt[19] = 0xA0;*/
+/* regGraph.crt[20] = 0xA0;*/
+ regGraph.crt[23] = 0xE3;
+/* regGraph.crt[24] = 0;*/
+ s3Graph.r.x5e = (((video->m.vTotal - 2) & 0x400) >> 10)
+ | (((video->m.vLine - 1) & 0x400) >> 9)
+ | ((video->m.vStart & 0x400) >> 8)
+ | ((video->m.vStart & 0x400) >> 6) | 0x40;
+ s3Graph.r.x5d = ((video->m.hTotal & 0x800) >> 11)
+ | ((video->m.hDot & 0x800) >> 10)
+ | ((video->m.hStart & 0x800) >> 9)
+ | ((video->m.hStart & 0x800) >> 7);
+}
+
+static
+ void S3GraphMode(void)
+{
+/* s3Graph.r.x35 = s3Text.r.x35 & 0xF0;*/
+#if 1
+ s3Graph.r.x5c = 0x20;
+ s3Graph.r.x31 = 0x8D;
+ s3Graph.r.x32 = 0;
+ s3Graph.r.x33 = 0x20;
+ s3Graph.r.x34 = 0x10;
+/* s3Graph.r.x35 = 0;*/
+/* s3Graph.r.x3a = 0x95;*/
+ s3Graph.r.x3b = (regGraph.crt[0] + regGraph.crt[4] + 1) / 2;
+ s3Graph.r.x3c = regGraph.crt[0] / 2;
+ s3Graph.r.x40 = (s3Text.r.x40 & 0xF6) | 1;
+ s3Graph.r.x43 = s3Text.r.x44 = 0;
+ s3Graph.r.x45 = s3Text.r.x45 & 1;
+
+ s3Graph.r.x50 = s3Text.r.x50 & ~0xC1;
+ s3Graph.r.x51 = (s3Text.r.x51 & 0xC0) | ((dInfo.gxdim >> 7) & 0x30);
+ s3Graph.r.x53 = s3Text.r.x53 & ~0x30;
+ s3Graph.r.x54 = 0xA0;
+ s3Graph.r.x55 = (s3Text.r.x55 & 8) | 0x40;
+ s3Graph.r.x58 = 0;
+ s3Graph.r.x5d |= s3Graph.r.x5d & ~0x17;
+ s3Graph.r.x60 = 0x3F;
+ s3Graph.r.x61 = 0x81;
+ s3Graph.r.x62 = 0;
+ if (dInfo.gxdim < 800) {
+ s3Graph.r.x50 |= 0x40;
+ s3Graph.r.x42 = 0xb;
+ } else if (dInfo.gxdim < 1024) {
+ s3Graph.r.x50 |= 0x80;
+ s3Graph.r.x42 = 2;
+ } else {
+ s3Graph.r.x42 = 0xE;
+ }
+ VgaGraphMode();
+#endif
+ S3SetRegisters(&s3Graph);
+}
+
+static
+ void S3Init()
+{
+ int i, n;
+
+ PortOutw(0xa539, vgaCrtAddr); /* unlock system control regs */
+/* PortOutw(0x483b, vgaCrtAddr); /* unlock system control regs */
+ for (i = 0; i < 5; i ++) {
+ PortOutb(0x30 + i, vgaCrtAddr);
+ s3Text.x.r3[i] = PortInb(vgaCrtData);
+ PortOutb(0x38 + i, vgaCrtAddr);
+ s3Text.x.r3[i+5] = PortInb(vgaCrtData);
+ }
+ for (i = 0; i < 16; i ++) {
+ PortOutb(0x40 + i, vgaCrtAddr);
+ s3Text.x.rx[i] = PortInb(vgaCrtData);
+ }
+ for (n = 16, i = 0; i < 16; i ++) {
+ if ((1 << i) & R5x_MASK) {
+ PortOutb(0x50 + i, vgaCrtAddr);
+ s3Text.x.rx[n] = PortInb(vgaCrtData);
+ n ++;
+ }
+ }
+ for (i = 0; i < 6; i ++, n ++) {
+ PortOutb(0x60 + i, vgaCrtAddr);
+ s3Text.x.rx[n] = PortInb(vgaCrtData);
+ }
+ s3Graph = s3Text;
+ s3Graph.r.x39 = 0xA5;
+ VgaInit();
+}
+
+static struct videoInfo S3Info =
+{
+ TRUE,
+ S3Init,
+ S3TextMode,
+ S3GraphMode,
+ VgaWput,
+ VgaSput,
+ VgaSetCursorAddress,
+ VgaSetAddress,
+ VgaCursor,
+ VgaClearAll,
+ VgaScreenSaver,
+ VgaDetach,
+ S3SetStartAddress,
+ VgaHardScrollUp,
+ VgaHardScrollDown
+ };
+
+int S3SetVideoType(struct videoInfo *info, const char *regs)
+{
+ union videoTimings video;
+
+ *info = S3Info;
+ VgaReadNewRegs(regs, &video);
+ S3CalcNewRegs(&video);
+ if (VgaAttach() < 0) return FAILURE;
+ VgaDefaultCaps();
+ return SUCCESS;
+}
+
+#endif
+#endif
diff --git a/loader/kon2/src/display/svga.c b/loader/kon2/src/display/svga.c
new file mode 100644
index 000000000..d2d9dffde
--- /dev/null
+++ b/loader/kon2/src/display/svga.c
@@ -0,0 +1,110 @@
+/*
+ * KON2 - Kanji ON Console -
+ * Copyright (C) 1992-1996 Takashi MANABE (manabe@papilio.tutics.tut.ac.jp)
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY TAKASHI MANABE ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE TERRENCE R. LAMBERT BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+/*
+ This code is based on vgalib.
+
+ Thanks to frandsen@diku.dk (Tommy Frandsen).
+ */
+
+#include <config.h>
+
+#ifdef HAS_VGA
+
+#include <stdio.h>
+#include <fcntl.h>
+#include <termios.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/mman.h>
+#if defined(linux)
+/* #include <linux/mm.h> */
+#include <sys/kd.h>
+#endif
+#undef free
+#include <stdlib.h>
+
+#include <mem.h>
+#include <getcap.h>
+#include <defs.h>
+#include <errors.h>
+#include <vc.h>
+#include <vt.h>
+#include <vga.h>
+#include <fnld.h>
+
+#ifdef MINI_KON
+#define vgaCrtAddr 0x3D4
+#define vgaCrtData 0x3D5
+#define vgaSt1Addr 0x3DA
+#endif
+
+static
+ void SvgaSetStartAddress(void)
+{
+ int til;
+
+ til = (dInfo.gydim - 1 - (gramHead / dInfo.glineByte)) << 4;
+
+ PortOutw((gramHead & 0xff00) | 0x0c, vgaCrtAddr);
+ PortOutw((gramHead << 8) | 0x0d, vgaCrtAddr);
+ PortOutw((til << 4) | 0x18, vgaCrtAddr);
+ PortOutw((til & 0x1000) | LineComp8, vgaCrtAddr);
+ PortOutw(((til & 0x2000) << 1) | LineComp9, vgaCrtAddr);
+}
+
+struct videoInfo SvgaInfo =
+{
+ TRUE,
+ VgaInit,
+ VgaTextMode,
+ VgaGraphMode,
+ VgaWput,
+ VgaSput,
+ VgaSetCursorAddress,
+ VgaSetAddress,
+ VgaCursor,
+ VgaClearAll,
+ VgaScreenSaver,
+ VgaDetach,
+ SvgaSetStartAddress,
+ VgaHardScrollUp,
+ VgaHardScrollDown
+ };
+
+int SvgaSetVideoType(struct videoInfo *info, const char *regs)
+{
+ union videoTimings video;
+
+ *info = SvgaInfo;
+ VgaReadNewRegs(regs, &video);
+ if (VgaAttach() < 0) return FAILURE;
+ VgaDefaultCaps();
+ return SUCCESS;
+}
+
+#endif
diff --git a/loader/kon2/src/display/vga.c b/loader/kon2/src/display/vga.c
new file mode 100644
index 000000000..f5bb3e176
--- /dev/null
+++ b/loader/kon2/src/display/vga.c
@@ -0,0 +1,797 @@
+/*
+ * KON2 - Kanji ON Console -
+ * Copyright (C) 1992-1996 Takashi MANABE (manabe@papilio.tutics.tut.ac.jp)
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY TAKASHI MANABE ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE TERRENCE R. LAMBERT BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+/*
+ This code is based on vgalib.
+
+ Thanks to frandsen@diku.dk (Tommy Frandsen).
+ */
+
+#include <config.h>
+
+#ifdef HAS_VGA
+
+#include <stdio.h>
+#include <fcntl.h>
+#include <termios.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/mman.h>
+#if defined(linux)
+/* #include <linux/mm.h> */
+#include <sys/kd.h>
+#elif defined(__FreeBSD__)
+#include <vm/vm_param.h>
+#include <sys/ioctl.h>
+#include <machine/console.h>
+vm_size_t page_size;
+#endif
+#undef free
+#include <stdlib.h>
+
+#include <mem.h>
+#include <getcap.h>
+#include <defs.h>
+#include <errors.h>
+#include <vc.h>
+#include <vt.h>
+#include <vga.h>
+#include <fnld.h>
+
+static struct pelRegs grapPels, textPels;
+
+struct vgaRegs
+ regText,
+ regGraph = {
+ { /* CRT */
+ 0x5F,0x4F,0x50,0x82,0x54,0x80,0x0B,0x3E,
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+ 0xEA,0x0C,0xDF,0x28,0x00,0xE7,0x04,0xE3,
+ 0xFF
+ }, { /* ATT */
+ 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
+ 0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F,
+ 0x01,0x00,0x0F,0x00,0x00
+ }, { /* GRA */
+ 0x00,0x0F,0x00,0x20,0x03,0x00,0x05,0x00,
+ 0xFF
+ }, { /*SEQ */
+ 0x03,0x01,0x0F,0x00,0x06
+ }, /* MIS */
+ 0xE3
+ };
+
+int LineComp9, LineComp8, gramHead;
+#ifdef MINI_KON
+#define vgaCrtAddr 0x3D4
+#define vgaCrtData 0x3D5
+#define vgaSt1Addr 0x3DA
+#else
+u_int vgaCrtAddr = 0x3D4;
+u_int vgaCrtData = 0x3D5;
+u_int vgaSt1Addr = 0x3DA;
+#endif
+
+static char *gramMem; /* dummy buffer for mmapping grahics memory */
+static char *fontBuff1; /* saved font data - plane 2 */
+
+#ifndef MINI_KON
+static bool savePlane3;
+static char *fontBuff2; /* saved font data - plane 3 */
+#endif
+
+static u_int writeAddr; /* address to write next character */
+
+static bool kanjiCursor;
+static u_char cursorTop, cursorBtm;
+
+#ifndef MINI_KON
+static u_short fmPattern; /* bit pattern to modify font; skip line if bit clear */
+#endif
+
+void VgaSetRegisters(struct vgaRegs *regs)
+{
+ int i;
+
+ /* disable video */
+ PortInb(vgaSt1Addr);
+ PortOutb(0x00, VGAATTR_A_O);
+
+ /* update misc output register */
+ PortOutb((regs->mis&~0x1)|(PortInb(VGAMISC_IN)&0x01), VGAMISC_OUT);
+
+ /* synchronous reset on */
+ PortOutb(0x00,VGASEQ_ADDR);
+ PortOutb(0x01,VGASEQ_DATA);
+
+ /* write sequencer registers */
+ for (i = 1; i < VGASEQ_CNT; i++) {
+ PortOutb(i, VGASEQ_ADDR);
+ PortOutb(regs->seq[i], VGASEQ_DATA);
+ }
+
+ /* synchronous reset off */
+ PortOutb(0x00, VGASEQ_ADDR);
+ PortOutb(0x03, VGASEQ_DATA);
+
+ /* deprotect CRT registers 0-7 */
+ PortOutb(0x11, vgaCrtAddr);
+ PortOutb(PortInb(vgaCrtData)&0x7F, vgaCrtData);
+
+ /* write CRT registers */
+ for (i = 0; i < VGACRT_CNT; i++) {
+ PortOutb(i, vgaCrtAddr);
+ PortOutb(regs->crt[i], vgaCrtData);
+ }
+
+ /* write graphics controller registers */
+ for (i = 0; i < VGAGRP_CNT; i++) {
+ PortOutb(i, VGAGRP_ADDR);
+ PortOutb(regs->gra[i], VGAGRP_DATA);
+ }
+
+ /* write attribute controller registers */
+ for (i = 0; i < VGAATTR_CNT; i++) {
+ /* reset flip-flop */
+ PortInb(vgaSt1Addr);
+ PortOutb(i, VGAATTR_A_O);
+ PortOutb(regs->att[i],VGAATTR_A_O);
+ }
+}
+
+static
+void VgaSetPELS(struct pelRegs *pels)
+{
+ int i;
+
+ for(i = 0; i < MAX_PELS; i++) {
+ PortOutb(i, VGAPAL_OADR);
+ PortOutb(pels->red[i], VGAPAL_DATA);
+ PortOutb(pels->grn[i], VGAPAL_DATA);
+ PortOutb(pels->blu[i], VGAPAL_DATA);
+ }
+}
+
+static
+void VgaGetPELS(struct pelRegs *pels)
+{
+ int i;
+
+ PortOutb(0, VGAPAL_IADR);
+ for(i = 0; i < MAX_PELS; i++) {
+ pels->red[i] = PortInb(VGAPAL_DATA);
+ pels->grn[i] = PortInb(VGAPAL_DATA);
+ pels->blu[i] = PortInb(VGAPAL_DATA);
+ }
+}
+
+static inline
+void VgaSetColor(u_char col)
+{
+ static old;
+
+ if (old == col) return;
+ PortOutw(col << 8, VGAGRP_ADDR);
+ old = col;
+}
+
+void VgaInit(void)
+{
+ int i;
+
+ VgaGetPELS(&textPels);
+
+ /* disable video */
+ PortInb(vgaSt1Addr);
+ PortOutb(0x00, VGAATTR_A_O);
+ /* save text mode VGA registers */
+ for (i = 0; i < VGACRT_CNT; i++) {
+ PortOutb(i, vgaCrtAddr);
+ regText.crt[i] = PortInb(vgaCrtData);
+ }
+ for (i = 0; i < VGAATTR_CNT; i++) {
+ PortInb(vgaSt1Addr);
+ PortOutb(i, VGAATTR_A_O);
+ regText.att[i] = PortInb(VGAATTR_DATA);
+ }
+ for (i = 0; i < VGAGRP_CNT; i++) {
+ PortOutb(i, VGAGRP_ADDR);
+ regText.gra[i] = PortInb(VGAGRP_DATA);
+ }
+ for (i = 0; i < VGASEQ_CNT; i++) {
+ PortOutb(i, VGASEQ_ADDR);
+ regText.seq[i] = PortInb(VGASEQ_DATA);
+ }
+ regText.mis = PortInb(VGAMISC_IN);
+
+ PortOutb(PortInb(VGAMISC_IN)|0x01, VGAMISC_OUT);
+ VgaSetRegisters(&regGraph);
+
+ /* save font data in plane 2 */
+ PortOutw(0x0204, VGAGRP_ADDR);
+ memcpy(fontBuff1, gramMem, FONT_SIZE);
+#ifdef USE_ROMFONT
+ VgaLoadRomFont(fontBuff1);
+#endif
+#ifndef MINI_KON
+ if (savePlane3) {
+ /* save font data in plane 3 */
+ PortOutw(0x0304, VGAGRP_ADDR);
+ memcpy(fontBuff2, gramMem, FONT_SIZE);
+ }
+#endif
+}
+
+void VgaTextMode(void)
+{
+ /* disable video */
+ PortInb(vgaSt1Addr);
+ PortOutb(0x00, VGAATTR_A_O);
+
+ /* restore font data - first select a 16 color graphics mode */
+ VgaSetRegisters(&regGraph);
+
+ /* disable Set/Reset Register */
+ PortOutb(0x01, VGAGRP_ADDR );
+ PortOutb(0x00, VGAGRP_DATA );
+
+ /* restore font data in plane 2 - necessary for all VGA's */
+ PortOutb(0x02, VGASEQ_ADDR );
+ PortOutb(0x04, VGASEQ_DATA );
+ memcpy(gramMem, fontBuff1, FONT_SIZE);
+
+#ifndef MINI_KON
+ if (savePlane3) {
+ /* restore font data in plane 3 - necessary for Trident VGA's */
+ PortOutb(0x02, VGASEQ_ADDR );
+ PortOutb(0x08, VGASEQ_DATA );
+ memcpy(gramMem, fontBuff2, FONT_SIZE);
+ }
+#endif
+
+ /* restore text mode VGA registers */
+ VgaSetRegisters(&regText);
+
+ /* set text palette */
+
+ VgaSetPELS(&textPels);
+
+ /* enable video */
+ PortInb(vgaSt1Addr);
+ PortOutb(0x20, VGAATTR_A_O);
+}
+
+void VgaGraphMode(void)
+{
+ /* disable video */
+ PortInb(vgaSt1Addr);
+ PortOutb(0x00, VGAATTR_A_O);
+
+ VgaSetRegisters(&regGraph);
+
+ /* set default palette */
+
+ VgaSetPELS(&grapPels);
+
+ /* enable video */
+ PortInb(vgaSt1Addr);
+ PortOutb(0x20, VGAATTR_A_O);
+}
+
+#ifdef MINI_KON
+void VgaChangeClock()
+{
+ static int clock=-1;
+
+ if (clock < 0) clock = (regGraph.mis >> 2) & 3;
+ clock = (clock + 1) & 3;
+ regGraph.mis &= ~(3 << 2);
+ regGraph.mis |= clock << 2;
+printf("%d\r\n", clock);
+ VgaGraphMode();
+}
+#endif
+
+void VgaWput(u_char *code, u_char fc, u_char bc)
+{
+ volatile char *gram, *vcls;
+ u_char *til;
+ u_char x;
+
+ VgaSetColor(bc&7);
+ vcls = gram = gramMem + writeAddr;
+ for (x = 0;x < dInfo.glineChar;x ++, vcls += dInfo.glineByte)
+ *vcls = *(vcls + 1) = 0;
+ VgaSetColor(fc);
+ if (bc & 0x8) {
+ vcls -= dInfo.glineByte;
+ *vcls = *(vcls + 1) = 0;
+ }
+ til = code + (dbFReg->high << 1);
+ for (;code < til; code ++, gram += dInfo.glineByte) {
+ if (*code) {
+ VgaOutByte(*code);
+ *gram = *gram;
+ }
+ code ++;
+ if (*code) {
+ VgaOutByte(*code);
+ *(gram + 1) = *(gram + 1);
+ }
+ }
+ VgaOutByte(0xFF);
+}
+
+void VgaSput(u_char *code, u_char fc, u_char bc)
+{
+ volatile char *gram, *vcls;
+ u_char *til;
+ u_char x;
+
+ vcls = gram = gramMem + writeAddr;
+ VgaSetColor(bc&7);
+ for (x = 0;x < dInfo.glineChar;x ++, vcls += dInfo.glineByte)
+ *vcls = 0;
+ if (!code) return;
+ VgaSetColor(fc);
+ if (bc & 0x8) *(vcls - dInfo.glineByte) = 0;
+ til = code + sbFReg->high;
+ for (;code < til;code ++, gram += dInfo.glineByte) {
+ if (*code) {
+ VgaOutByte(*code);
+ *gram = *gram;
+ }
+ }
+ VgaOutByte(0xFF);
+}
+
+#ifndef MINI_KON
+
+void VgaWputFm(u_char *code, u_char fc, u_char bc)
+{
+ volatile char *gram, *vcls;
+ u_char x;
+ u_short fm = (1 << (dbFReg->high - 1));
+
+ VgaSetColor(bc&7);
+ vcls = gram = gramMem + writeAddr;
+ for (x = 0;x < dInfo.glineChar;x ++, vcls += dInfo.glineByte)
+ *vcls = *(vcls + 1) = 0;
+ VgaSetColor(fc);
+ if (bc & 0x8) {
+ vcls -= dInfo.glineByte;
+ *vcls = *(vcls + 1) = 0;
+ }
+ for (x = 0;x < dbFReg->high;x ++, code ++, fm >>= 1) {
+ if (*code) {
+ VgaOutByte(*code);
+ *gram = *gram;
+ }
+ code ++;
+ if (*code) {
+ VgaOutByte(*code);
+ *(gram + 1) = *(gram + 1);
+ }
+ if (fm & fmPattern)
+ gram += dInfo.glineByte;
+ }
+ VgaOutByte(0xFF);
+}
+
+void VgaSputFm(u_char *code, u_char fc, u_char bc)
+{
+ volatile char *gram, *vcls;
+ u_char x;
+ u_short fm = (1 << (sbFReg->high - 1));
+
+ vcls = gram = gramMem + writeAddr;
+ VgaSetColor(bc&7);
+ for (x = 0;x < dInfo.glineChar;x ++, vcls += dInfo.glineByte)
+ *vcls = 0;
+/* if (!code) return;*/
+ VgaSetColor(fc);
+ if (bc & 0x8) *(vcls - dInfo.glineByte) = 0;
+ if (code) for (x = 0;x < sbFReg->high;x ++, code ++, fm >>= 1) {
+ if (*code) {
+ VgaOutByte(*code);
+ *gram = *gram;
+ }
+ if (fm & fmPattern)
+ gram += dInfo.glineByte;
+ }
+ VgaOutByte(0xFF);
+}
+#endif
+
+void VgaHardScrollUp(int line)
+{
+ int oldhead;
+
+ VgaSetColor((con.attr & ATTR_REVERSE ? con.fcol:con.bcol)&7);
+
+ if (line > dInfo.tymax) {
+ line %= dInfo.tymax + 1;
+ lzero(gramMem, dInfo.gsize);
+ }
+
+ oldhead = gramHead;
+ gramHead += line * dInfo.tlineByte;
+ if (gramHead >= dInfo.gsize) {
+ gramHead -= dInfo.gsize;
+ lzero(gramMem + oldhead, dInfo.gsize - oldhead);
+/* if (gramHead) lzero(gramMem, gramHead);*/
+ lzero(gramMem, gramHead);
+ } else lzero(gramMem + oldhead, gramHead - oldhead);
+ vInfo.set_start_address();
+}
+
+void VgaHardScrollDown(int line)
+{
+ int oldhead;
+
+ VgaSetColor((con.attr & ATTR_REVERSE ? con.fcol:con.bcol)&7);
+
+ if (line > dInfo.tymax) {
+ line %= dInfo.tymax + 1;
+ lzero(gramMem, dInfo.gsize);
+ }
+
+ oldhead = gramHead;
+ gramHead -= line * dInfo.tlineByte;
+ if (gramHead < 0) {
+ gramHead += dInfo.gsize;
+/* if (oldhead) lzero(gramMem, oldhead);*/
+ lzero(gramMem, oldhead);
+ lzero(gramMem + gramHead, dInfo.gsize - gramHead);
+ } else lzero(gramMem + gramHead, oldhead - gramHead);
+ vInfo.set_start_address();
+}
+
+void VgaSetCursorAddress(struct cursorInfo *ci, u_int x, u_int y)
+{
+#if 0
+ if (x > dInfo.txmax) {
+ y ++;
+ x -= dInfo.txmax + 1;
+ }
+#endif
+ ci->addr = (y * dInfo.tlineByte + cursorTop
+ * dInfo.glineByte + x + gramHead) % dInfo.gsize;
+}
+
+void VgaSetAddress(u_int p)
+{
+ writeAddr = (p%dInfo.glineByte) + (p/dInfo.glineByte) * dInfo.tlineByte;
+}
+
+void VgaCursor(struct cursorInfo *ci)
+{
+ volatile char *gram;
+ u_char x;
+ int bottom = cursorBtm + 1 <= dInfo.glineChar ?
+ cursorBtm + 1 : dInfo.glineChar;
+
+ VgaSetColor(15);
+ gram = gramMem + ci->addr;
+
+ PortOutw(0x0F00, VGAGRP_ADDR); /* color white */
+ PortOutw(0x1803, VGAGRP_ADDR); /* XOR mode */
+ x = cursorTop;
+ if (kanjiCursor && ci->kanji) {
+ for (;x < bottom;x ++, gram += dInfo.glineByte) {
+ *gram = *gram;
+ *(gram + 1)= *(gram + 1);
+ }
+ } else
+ for (;x < bottom;x ++, gram += dInfo.glineByte)
+ *gram = *gram;
+ PortOutw(0x0003, VGAGRP_ADDR); /* unmodify mode */
+}
+
+void VgaClearAll(void)
+{
+ VgaSetColor((con.attr & ATTR_REVERSE ? con.fcol:con.bcol)&7);
+ lzero(gramMem, dInfo.gsize);
+}
+
+void VgaScreenSaver(bool blank)
+{
+ if (blank) {
+ PortOutb(0x01, VGASEQ_ADDR);
+ PortOutb(PortInb(VGASEQ_DATA) | 0x20, VGASEQ_DATA);
+ } else {
+ PortOutb(0x01, VGASEQ_ADDR);
+ PortOutb(PortInb(VGASEQ_DATA) & 0xDF, VGASEQ_DATA);
+ }
+}
+
+int VgaReadPels(const char *str)
+{
+ int i, red, grn, blu;
+
+ for (i = 0; i < MAX_PELS; i ++) {
+ sscanf(str, "%d %d %d", &red, &grn, &blu);
+ if ((str = strchr(str, '\n')) == NULL) {
+ error("PELS entry too short\r\n");
+ return FAILURE;
+ }
+ str++; /* skip '\n' */
+ grapPels.red[i] = red;
+ grapPels.grn[i] = grn;
+ grapPels.blu[i] = blu;
+ }
+ return SUCCESS;
+}
+
+int VgaReadNewRegs(const char *str, union videoTimings *video)
+{
+ int i, clock, txmax, tymax;
+ char *line2;
+
+ for (i = 0; i < NUM_VIDEOH_INFO+NUM_VIDEOV_INFO; i ++) {
+ if (! *str) {
+ error("%d values required for vga registers, "
+ "but only supplied %d\r\n", VGACRT_CNT, i);
+ return FAILURE;
+ }
+ video->v[i] = strtoul(str, (char **) &str, 10);
+ }
+ line2 = strpbrk(str, "\r\n");
+ *line2 = '\0';line2 ++;
+ if (*str) video->m.i = atoi(str);
+ if (sscanf(line2, "%x \n %d %d", &clock, &txmax, &tymax) == EOF) {
+ error("missing arg for vga driver\r\n");
+ return FAILURE;
+ }
+ dInfo.gxdim = video->m.hDot;
+ dInfo.gydim = video->m.vLine;
+ dInfo.txmax = txmax;
+ dInfo.tymax = tymax;
+ dInfo.glineChar = dInfo.gydim / (dInfo.tymax + 1);
+ dInfo.glineByte = dInfo.gxdim >> 3;
+ dInfo.gydim = dInfo.glineChar * (dInfo.tymax + 1);
+ dInfo.gsize = dInfo.glineByte * dInfo.gydim;
+/*printf("%ld\r\n", dInfo.gsize);*/
+ dInfo.tlineByte = dInfo.glineChar * dInfo.glineByte;
+
+ if (video->m.vLine < 480) {
+ regGraph.crt[23] = 0xE3;
+ regGraph.mis = 0xE3;
+ } else {
+ if (video->m.vLine < 768) regGraph.mis = 0xE3;
+ else regGraph.mis = 0x23;
+ regGraph.crt[23] = 0xC3;
+ }
+ regGraph.mis |= (clock & 3) << 2;
+ regGraph.crt[0] = (video->m.hTotal>>3) - 5;
+ regGraph.crt[1] = (video->m.hDot>>3) - 1;
+ regGraph.crt[2] = (video->m.hStart>>3) - 1;
+ regGraph.crt[3] = ((video->m.hEnd>>3) & 0x1F) | 0x80;
+ regGraph.crt[4] = video->m.hStart>>3;
+ regGraph.crt[5] = (((video->m.hEnd>>3) & 0x20) << 2)
+ | ((video->m.hEnd>>3) & 0x1F);
+ regGraph.crt[6] = (video->m.vTotal - 2) & 0xFF;
+ regGraph.crt[7] = 0x10;
+ regGraph.crt[7] |= (((dInfo.gydim - 1) & 0x100) >> 7)
+ | (((dInfo.gydim - 1) & 0x200) >> 3);
+ regGraph.crt[7] |= ((video->m.vStart & 0x100) >> 6)
+ | ((video->m.vStart & 0x100) >> 5);
+ regGraph.crt[7] |= (((video->m.vTotal - 2) & 0x100) >> 8)
+ | (((video->m.vTotal - 2) & 0x200) >> 4);
+ regGraph.crt[7] |= ((video->m.vStart & 0x200) >> 2);
+ regGraph.crt[9] = ((video->m.vStart & 0x200) >>4) | 0x40;
+ regGraph.crt[16] = video->m.vStart & 0xFF;
+ regGraph.crt[17] = (video->m.vEnd & 0x0F) | 0x20;
+ regGraph.crt[18] = (dInfo.gydim - 1) & 0xFF;
+ regGraph.crt[19] = video->m.hDot >> 4;
+ regGraph.crt[21] = video->m.vStart & 0xFF;
+ regGraph.crt[22] = (video->m.vStart + 1) & 0xFF;
+
+ LineComp8 = ((regGraph.crt[7] & 0xEF) << 8) + 0x07;
+ LineComp9 = ((regGraph.crt[9] & 0xBF) << 8) + 0x09;
+
+ return SUCCESS;
+}
+
+/* VGA initialize & uninitialize */
+
+int VgaAttach(void)
+{
+ int devMem;
+
+#if defined(linux)
+ ioperm(VGAMISC_IN, 1, 1);
+#ifndef MINI_KON
+ if (!(PortInb(VGAMISC_IN)&0x01)) { /* monochrome VGA */
+ vgaCrtAddr = 0x3B4;
+ vgaCrtData = 0x3B5;
+ vgaSt1Addr = 0x3BA;
+ }
+#endif
+
+ /* get I/O permissions for VGA registers */
+ ioperm(vgaCrtAddr, 1, 1);
+ ioperm(VGAATTR_A_O, 1, 1);
+ ioperm(VGAGRP_ADDR, 1, 1);
+ ioperm(VGASEQ_ADDR, 1, 1);
+ ioperm(VGAPAL_OADR, 1, 1);
+ ioperm(VGAPAL_IADR, 1, 1);
+ ioperm(vgaCrtData, 1, 1);
+ ioperm(VGAATTR_DATA, 1, 1);
+ ioperm(VGAGRP_DATA, 1, 1);
+ ioperm(VGASEQ_DATA, 1, 1);
+ ioperm(VGAMISC_IN, 1, 1);
+ ioperm(VGAMISC_OUT, 1, 1);
+ ioperm(vgaSt1Addr, 1, 1);
+ ioperm(VGAPAL_DATA, 1, 1);
+
+ if ((devMem = open("/dev/mem", O_RDWR) ) < 0) {
+ Perror("/dev/mem");
+ return FAILURE;
+ }
+#elif defined(__FreeBSD__)
+ if (ioctl(0, KDENABIO,0) < 0) {
+ Perror("ioctl CONSOLE_IO_ENABLE");
+ return FAILURE;
+ }
+ if (ioctl(0, KDSETMODE,KD_GRAPHICS) < 0) {
+ Perror("ioctl CONSOLE_IO_ENABLE");
+ return FAILURE;
+ }
+ if ((devMem = open("/dev/vga", O_RDWR|O_NDELAY) ) < 0) {
+ Perror("/dev/mem");
+ return FAILURE;
+ }
+#endif
+ if ((fontBuff1 = malloc(FONT_SIZE)) == NULL
+#ifndef MINI_KON
+ || (savePlane3 && (fontBuff2 = malloc(FONT_SIZE)) == NULL)
+#endif
+ ) {
+ Perror("malloc ");
+ return FAILURE;
+ }
+ gramMem = (unsigned char *)mmap(
+#if defined(linux)
+ (__ptr_t)0,
+#else
+ 0,
+#endif
+ dInfo.gsize,
+ PROT_READ|PROT_WRITE,
+#if 0
+ MAP_SHARED|MAP_FIXED,
+#else
+#if defined(linux)
+ MAP_SHARED,
+#elif defined(__FreeBSD__)
+ MAP_FILE|MAP_SHARED,
+#endif
+#endif
+ devMem,
+ GRAPH_BASE
+ );
+ close(devMem);
+ if ((long)gramMem < 0) {
+ Perror("mmap");
+ return FAILURE;
+ }
+
+ return SUCCESS;
+}
+
+void VgaDetach(void)
+{
+ gramHead = 0;
+#if defined(linux)
+ ioperm(vgaCrtAddr, 1, 0);
+ ioperm(VGAATTR_A_O, 1, 0);
+ ioperm(VGAGRP_ADDR, 1, 0);
+ ioperm(VGASEQ_ADDR, 1, 0);
+ ioperm(VGAPAL_OADR, 1, 0);
+ ioperm(VGAPAL_IADR, 1, 0);
+ ioperm(vgaCrtData, 1, 0);
+ ioperm(VGAATTR_DATA, 1, 0);
+ ioperm(VGAGRP_DATA, 1, 0);
+ ioperm(VGASEQ_DATA, 1, 0);
+ ioperm(VGAMISC_IN, 1, 0);
+ ioperm(VGAMISC_OUT, 1, 0);
+ ioperm(vgaSt1Addr, 1, 0);
+ ioperm(VGAPAL_DATA, 1, 0);
+#endif
+
+ munmap(gramMem, dInfo.gsize);
+
+ SafeFree((void **)&gramMem);
+ SafeFree((void **)&fontBuff1);
+#ifndef MINI_KON
+ if (savePlane3)
+ SafeFree((void **)&fontBuff2);
+#endif
+}
+
+/* Configure */
+
+#ifndef MINI_KON
+static
+ int ConfigPlane3(const char *confstr)
+{
+ savePlane3 = BoolConf(confstr);
+ return SUCCESS;
+}
+#endif
+
+static
+ int ConfigKanjiCursor(const char *confstr)
+{
+ kanjiCursor = BoolConf(confstr);
+ return SUCCESS;
+}
+
+static
+ int ConfigCursorTop(const char *confstr)
+{
+ cursorTop = atoi(confstr);
+ return SUCCESS;
+}
+
+static
+ int ConfigCursorBottom(const char *confstr)
+{
+ cursorBtm = atoi(confstr);
+ return SUCCESS;
+}
+
+void VgaDefaultCaps()
+{
+ DefineCap("Pels", VgaReadPels, NULL);
+#ifndef MINI_KON
+ DefineCap("SavePlane3", ConfigPlane3, "Off");
+#endif
+ DefineCap("KanjiCursor", ConfigKanjiCursor, "On");
+ DefineCap("CursorTop", ConfigCursorTop, "14");
+ DefineCap("CursorBottom", ConfigCursorBottom, "15");
+}
+
+#ifndef MINI_KON
+
+int VgaFmSetVideoType(struct videoInfo *info, const char *regs)
+{
+ union videoTimings video;
+
+ *info = SvgaInfo;
+ info->sput = VgaSputFm;
+ info->wput = VgaWputFm;
+ fmPattern = (u_short) strtoul(regs, (char **) &regs, 16);
+ if (VgaReadNewRegs(regs, &video) == FAILURE) return FAILURE;
+ if (VgaAttach() < 0) return FAILURE;
+ VgaDefaultCaps();
+ return SUCCESS;
+}
+#endif
+
+#endif
diff --git a/loader/kon2/src/errors.c b/loader/kon2/src/errors.c
new file mode 100644
index 000000000..a1a584726
--- /dev/null
+++ b/loader/kon2/src/errors.c
@@ -0,0 +1,116 @@
+/*
+ * KON2 - Kanji ON Console -
+ * Copyright (C) 1993 by MAEDA Atusi (mad@math.keio.ac.jp)
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY MAEDA ATUSI ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE TERRENCE R. LAMBERT BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+#include <config.h>
+
+#include <stdio.h>
+#include <errno.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+
+#include <defs.h>
+#include <errors.h>
+#include <vc.h>
+#include <vt.h>
+
+#define MAX_MSGLEN 1024
+
+static void KonPrintf(const char *head, const char *format, va_list args)
+{
+#ifndef MINI_KON
+ char buf[MAX_MSGLEN];
+
+ if (con.text_mode) {
+ fprintf(stderr, "%s", head);
+ vfprintf(stderr, format, args);
+ } else {
+ VtEmu(head, strlen(head));
+ vsprintf(buf, format, args);
+ VtEmu(buf, strlen(buf));
+ }
+#endif
+}
+
+void fatal(const char *format, ...)
+{
+#ifndef MINI_KON
+ va_list args;
+
+ va_start(args, format);
+ fprintf(stderr, "KON> fatal error: ");
+ vfprintf(stderr, format, args);
+ va_end(args);
+#endif
+ exit(EXIT_FAILURE);
+}
+
+void warn(const char *format, ...)
+{
+ va_list args;
+
+ va_start(args, format);
+ KonPrintf("KON> warning: ", format, args);
+ va_end(args);
+}
+
+void kon_error(const char *format, ...)
+{
+#ifndef MINI_KON
+ va_list args;
+
+ va_start(args, format);
+ KonPrintf("KON> error: ", format, args);
+ va_end(args);
+#endif
+}
+
+void message(const char *format, ...)
+{
+#ifndef MINI_KON
+ va_list args;
+
+ va_start(args, format);
+ KonPrintf("KON> ", format, args);
+ va_end(args);
+#endif
+}
+
+void Perror(const char *msg)
+{
+#ifndef MINI_KON
+ message("system error - %s: %s\r\n", msg, strerror(errno));
+#endif
+}
+
+void PerrorExit(const char *message)
+{
+#ifndef MINI_KON
+ fprintf(stderr, "%s: %s\r\n", message, strerror(errno));
+#endif
+ exit(EXIT_FAILURE);
+}
diff --git a/loader/kon2/src/fnld.c b/loader/kon2/src/fnld.c
new file mode 100644
index 000000000..e8e8826a8
--- /dev/null
+++ b/loader/kon2/src/fnld.c
@@ -0,0 +1,238 @@
+/*
+ * KON2 - Kanji ON Console -
+ * Copyright (C) 1992-1996 Takashi MANABE (manabe@papilio.tutics.tut.ac.jp)
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY TAKASHI MANABE ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE TERRENCE R. LAMBERT BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#include <config.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/file.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/ipc.h>
+#include <sys/shm.h>
+
+#include <interface.h>
+#include <vt.h>
+#include <fnld.h>
+
+struct fontRegs *dbFReg, *sbFReg;
+
+#ifdef MINI_KON
+
+/*#define USE_GZFONT 1*/
+
+#ifdef USE_GZFONT
+#define PATH_MINIFONT "/usr/lib/minikon.fnt.gz"
+#define CMD_MINIFONT "/bin/gzip -dc "PATH_MINIFONT
+#else
+#define PATH_MINIFONT "/usr/lib/minikon.fnt"
+#endif
+
+void
+LoadMiniFont()
+{
+ int addr, bytes;
+ u_char type, high;
+ u_short max;
+ FILE *fp;
+ struct fontRegs *freg;
+ struct {
+ u_short code;
+ u_char bitmap[32];
+ } fent;
+ char dummy[]={
+ 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
+ 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01,
+ 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
+ 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01,
+ };
+
+ type = CodingByRegistry("JISX0208.1983-0");
+ freg = &fDRegs[type & ~CHR_DFLD];
+#ifdef USE_GZFONT
+ if ((fp = popen(CMD_MINIFONT, "r")) == NULL) {
+#else
+ if ((fp = fopen(PATH_MINIFONT, "r")) == NULL) {
+#endif
+ perror(PATH_MINIFONT);
+ return;
+ }
+ fread(&high, sizeof(high), 1, fp);
+ fread(&max, sizeof(max), 1, fp);
+ max ++;
+ freg->size = freg->addr(max>>8, max & 0xFF);
+ freg->high = high;
+ freg->stat = FR_ATTACH;
+ freg->bitmap = malloc(freg->size);
+ for (addr = 0; addr < freg->size; addr += 32) {
+ memcpy(freg->bitmap + addr, dummy, 32);
+ }
+ bytes = high * 2;
+
+ while (fread(&fent, sizeof(fent.code) + bytes, 1, fp) > 0) {
+ addr = freg->addr(fent.code >> 8, fent.code & 0xFF);
+ memcpy(freg->bitmap + addr, fent.bitmap, bytes);
+ }
+
+#ifdef USE_GZFONT
+ pclose(fp);
+#else
+ fclose(fp);
+#endif
+}
+
+void
+VgaLoadRomFont(char *fontbuff)
+{
+ static int loaded=0;
+ int i;
+
+ if (loaded) return;
+ i = 1;
+ sbFReg = &fSRegs[0];
+ sbFReg->size = 256 * 16;
+ sbFReg->high = 16;
+ sbFReg->stat = FR_ATTACH;
+ sbFReg->bitmap = calloc(sbFReg->size, 1);
+ while (fSRegs[i].registry) {
+ fSRegs[i].high = sbFReg->high;
+ fSRegs[i].stat = FR_PROXY;
+ fSRegs[i].size = sbFReg->size;
+ fSRegs[i].bitmap = sbFReg->bitmap;
+ i ++;
+ }
+
+ for (i = 0; i < sbFReg->size; i += sbFReg->high) {
+ memcpy(&(sbFReg->bitmap[i]), &(fontbuff[i*2]), sbFReg->high);
+ }
+ loaded = 1;
+}
+
+#else
+
+#ifdef USE_ROMFONT
+
+void
+VgaLoadRomFont(char *fontbuff)
+{
+ static int loaded=0;
+ key_t shmkey;
+ int shmid, i;
+ u_char *shmbuff, *buff;
+ struct fontInfo fi;
+
+ if (loaded) return;
+ shmkey = ftok(CONFIG_NAME, CHR_SFLD);
+ fi.size = 256 * 16;
+ fi.high = 16;
+ fi.width = 8;
+ fi.type = CHR_SFLD;
+ shmid = shmget(shmkey, fi.size+sizeof(struct fontInfo),
+ IPC_CREAT|0666);
+ shmbuff = shmat(shmid, 0, 0);
+ memcpy(shmbuff, &fi, sizeof(struct fontInfo));
+ buff = shmbuff + sizeof(struct fontInfo);
+
+ for (i = 0; i < fi.size; i += fi.high) {
+ memcpy(&(buff[i]), &(fontbuff[i*2]), fi.high);
+ }
+ shmdt(shmbuff);
+ loaded = 1;
+}
+
+#endif
+
+void FontDetach(bool down)
+{
+ int i;
+
+ i = 0;
+ while (fSRegs[i].registry) {
+ if (fSRegs[i].stat & FR_ATTACH)
+ shmdt(fSRegs[i].bitmap - sizeof(struct fontInfo));
+ if (down) DownShmem(i|CHR_SFLD);
+ fSRegs[i].width = fSRegs[i].high =
+ fSRegs[i].size = fSRegs[i].stat = 0;
+ i ++;
+ }
+ i = 0;
+ while (fDRegs[i].registry) {
+ if (fDRegs[i].stat & FR_ATTACH)
+ shmdt(fDRegs[i].bitmap - sizeof(struct fontInfo));
+ if (down) DownShmem(i|CHR_DFLD);
+ fDRegs[i].width = fDRegs[i].high =
+ fDRegs[i].size = fDRegs[i].stat = 0;
+ i ++;
+ }
+}
+
+void FontAttach()
+{
+ int i;
+ u_char *font;
+ struct fontInfo *fi;
+
+ i = 0;
+ while (fSRegs[i].registry) {
+ if ((font = GetShmem(i|CHR_SFLD)) != NULL) {
+ fi = (struct fontInfo*)font;
+ fSRegs[i].high = fi->high;
+ fSRegs[i].stat = FR_ATTACH;
+ fSRegs[i].size = fi->size;
+ fSRegs[i].bitmap = font + sizeof(struct fontInfo);
+ sbFReg = &fSRegs[i];
+ } else fSRegs[i].stat = 0;
+ i ++;
+ }
+ if (fSRegs[lInfo.sb].stat) sbFReg = &fSRegs[lInfo.sb];
+#if 1
+ i = 0;
+ while (fSRegs[i].registry) {
+ if (!fSRegs[i].stat) {
+ fSRegs[i].high = sbFReg->high;
+ fSRegs[i].size = sbFReg->size;
+ fSRegs[i].bitmap = sbFReg->bitmap;
+ fSRegs[i].stat = FR_PROXY;
+ }
+ i ++;
+ }
+#endif
+ i = 0;
+ while (fDRegs[i].registry) {
+ if ((font = GetShmem(i|CHR_DFLD)) != NULL) {
+ fi = (struct fontInfo*)font;
+ fDRegs[i].high = fi->high;
+ fDRegs[i].stat = FR_ATTACH;
+ fDRegs[i].size = fi->size;
+ fDRegs[i].bitmap = font + sizeof(struct fontInfo);
+ }
+ i ++;
+ }
+ dbFReg = &fDRegs[lInfo.db];
+}
+#endif
diff --git a/loader/kon2/src/main.c b/loader/kon2/src/main.c
new file mode 100644
index 000000000..1598d64a0
--- /dev/null
+++ b/loader/kon2/src/main.c
@@ -0,0 +1,60 @@
+/*
+ * KON2 - Kanji ON Console -
+ * Copyright (C) 1992-1996 Takashi MANABE (manabe@papilio.tutics.tut.ac.jp)
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY TAKASHI MANABE ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE TERRENCE R. LAMBERT BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#include <config.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <getcap.h>
+
+#include <version.h>
+#include <term.h>
+
+void
+kon_main(int argc, const char *argv[])
+{
+ extern void ChangeNewConsole();
+
+#ifdef MINI_KON
+ fprintf(stderr, "Kanji ON Console MINI " VERSION "\n\n");
+#else
+ fprintf(stderr, "Kanji ON Console " VERSION "\n\n");
+#endif
+ if (geteuid() != 0) {
+ fprintf(stderr, "can not get I/O permissions.\n");
+ exit(EXIT_FAILURE);
+ }
+ ChangeNewConsole();
+ TermInit(argc - 1, argv + 1);
+ if (ReadConfig(CONFIG_NAME) < 0) {
+ fprintf(stderr, "KON> error reading %s\n", CONFIG_NAME);
+ exit(EXIT_FAILURE);
+ }
+ TermStart();
+}
diff --git a/loader/kon2/src/mouse.c b/loader/kon2/src/mouse.c
new file mode 100644
index 000000000..47834f38e
--- /dev/null
+++ b/loader/kon2/src/mouse.c
@@ -0,0 +1,408 @@
+/*
+ * KON2 - Kanji ON Console -
+ * Copyright (C) 1992-1996 Takashi MANABE (manabe@papilio.tutics.tut.ac.jp)
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY TAKASHI MANABE ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE TERRENCE R. LAMBERT BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+/*
+ This code is based on selection.
+*/
+
+#include <config.h>
+
+#ifndef MINI_KON
+
+#include <unistd.h>
+#include <sys/types.h>
+#include <defs.h>
+#include <mouse.h>
+
+struct mouseInfo mInfo;
+
+int mouseFd = -1;
+
+#ifdef HAS_MOUSE
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <termios.h>
+#include <fcntl.h>
+#include <string.h>
+#include <getcap.h>
+
+#include <errors.h>
+#include <vc.h>
+
+static int cFlag;
+static int headMask;
+static int headId;
+static int dataMask;
+static int pkMax;
+
+typedef enum {
+ MOUSE_MICROSOFT,
+ MOUSE_MOUSESYSTEMS,
+ MOUSE_BUSMOUSE,
+ MOUSE_MMSERIES,
+ MOUSE_LOGITECH,
+ MOUSE_PS2,
+ MOUSE_NONE
+} mtype;
+
+static mtype mouseType = MOUSE_NONE;
+
+#define MAX_PK_SIZE 5
+
+struct mouseconf {
+ const char *name;
+ mtype type;
+ int cFlag;
+ int headMask;
+ int headId;
+ int dataMask;
+ int pkMax;
+} mice[] = {
+ {
+ "Microsoft", MOUSE_MICROSOFT,
+ (CS7|CREAD|CLOCAL|HUPCL),
+ 0x40, 0x40, 0x40, 3
+ },
+ {
+ "MouseSystems", MOUSE_MOUSESYSTEMS,
+ (CS8|CSTOPB|CREAD|CLOCAL|HUPCL),
+ 0xf8, 0x80, 0x00, 5
+ },
+ {
+ "BusMouse", MOUSE_BUSMOUSE,
+ 0,
+ 0xf8, 0x80, 0x00, 5
+ },
+ {
+ "MmSeries", MOUSE_MMSERIES,
+ (CS8|PARENB|PARODD|CREAD|CLOCAL|HUPCL),
+ 0xe0, 0x80, 0x80, 3
+ },
+ {
+ "Logitech", MOUSE_LOGITECH,
+ (CS8|CSTOPB|CREAD|CLOCAL|HUPCL),
+ 0xe0, 0x80, 0x80, 3
+ },
+ {
+ "PS2", MOUSE_PS2,
+ (CS8|CREAD|CLOCAL|HUPCL),
+ 0xcc, 0x08, 0x00, 3
+ },
+ {
+ "None", MOUSE_NONE,
+ 0,
+ 0, 0, 0, 0
+ },
+ {
+ NULL, MOUSE_NONE,
+ 0,
+ 0, 0, 0, 0
+ }
+};
+
+static int mouseBaud;
+
+static int ConfigMouseBaud(const char *config)
+{
+ int baud;
+
+ sscanf(config, "%d", &baud);
+
+ switch (baud) {
+ case 9600:
+ mouseBaud = B9600;
+ break;
+ case 4800:
+ mouseBaud = B4800;
+ break;
+ case 2400:
+ mouseBaud = B2400;
+ break;
+ default:
+ warn("invalid mouse baud rate %d; set to default (1200)\r\n", baud);
+ case 1200:
+ mouseBaud = B1200;
+ break;
+ }
+ return SUCCESS;
+}
+
+static char *mouseDev;
+
+static int ConfigMouseDev(const char *config)
+{
+ char name[MAX_COLS];
+ sscanf(config, "%s", name);
+
+ if (mouseDev) free(mouseDev);
+ mouseDev = strdup(name);
+ return SUCCESS;
+}
+
+static int pasteButton;
+
+static int Config3Buttons(const char *config)
+{
+ pasteButton = BoolConf(config) ? MOUSE_MID: MOUSE_RGT;
+ return SUCCESS;
+}
+
+static int ConfigMouse(const char *config)
+{
+ struct mouseconf *p;
+ char name[MAX_COLS];
+
+ mouseType = MOUSE_NONE;
+ mInfo.has_mouse = FALSE;
+ sscanf(config, "%s", name);
+ for (p = mice; p->name != NULL; p++) {
+ if (strcasecmp(name, p->name) == 0) {
+ mouseType = p->type;
+ if (mouseType == MOUSE_NONE)
+ return SUCCESS;
+ message("mouse type `%s'\r\n", name);
+ mInfo.has_mouse = TRUE;
+ cFlag = p->cFlag;
+ headMask = p->headMask;
+ headId = p->headId;
+ dataMask = p->dataMask;
+ pkMax = p->pkMax;
+
+ if (mouseType != MOUSE_BUSMOUSE) {
+ DefineCap("MouseBaud", ConfigMouseBaud, "1200");
+ }
+ DefineCap("Mouse3Buttons", Config3Buttons, "Off");
+ DefineCap("MouseDev", ConfigMouseDev, "/dev/mouse");
+ return SUCCESS;
+ }
+ }
+ warn("unknown mouse type `%s' ignored; assuming no mouse\r\n", name);
+ return SUCCESS;
+}
+
+static
+void MouseSetBaud(int mfd, u_short baud, u_short cflag)
+{
+ struct termios mio;
+ char *cf;
+
+ tcgetattr(mfd, &mio);
+
+ mio.c_iflag = IGNBRK | IGNPAR;
+ mio.c_oflag = 0;
+ mio.c_lflag = 0;
+#ifdef linux
+ mio.c_line = 0;
+#endif
+ mio.c_cc[VTIME] = 0;
+ mio.c_cc[VMIN] = 1;
+
+ mio.c_cflag = cflag;
+ cfsetispeed(&mio, baud);
+ cfsetospeed(&mio, baud);
+
+ tcsetattr(mfd, TCSAFLUSH, &mio);
+
+ switch(mouseBaud) {
+ case B9600: cf = "*q"; break;
+ case B4800: cf = "*p"; break;
+ case B2400: cf = "*o"; break;
+ case B1200: cf = "*n"; break;
+ }
+
+ mio.c_cflag = cflag;
+ cfsetispeed(&mio, mouseBaud);
+ cfsetospeed(&mio, mouseBaud);
+ write(mfd, cf, 2);
+ usleep(100000);
+ tcsetattr(mfd, TCSAFLUSH, &mio);
+}
+
+void MouseInit(void)
+{
+ mInfo.has_mouse = TRUE;
+ DefineCap("Mouse", ConfigMouse, "NONE");
+}
+
+int MouseStart(void)
+{
+ int mfd;
+
+ if ((mfd = open(mouseDev, O_RDWR|O_NONBLOCK)) < 0) {
+ warn("couldn't open mouse device; mouse disabled\n");
+ Perror(mouseDev);
+ free(mouseDev);
+ mouseDev = NULL;
+ mInfo.has_mouse = FALSE;
+ return -1;
+ }
+
+ if (mouseType != MOUSE_BUSMOUSE) {
+ MouseSetBaud(mfd, B9600, cFlag);
+ MouseSetBaud(mfd, B4800, cFlag);
+ MouseSetBaud(mfd, B2400, cFlag);
+ MouseSetBaud(mfd, B1200, cFlag);
+
+ if (mouseType == MOUSE_LOGITECH) {
+ write(mfd, "S", 1);
+ MouseSetBaud(mfd, mouseBaud, CS8 | PARENB | PARODD | CREAD |
+ CLOCAL | HUPCL);
+ }
+
+ write(mfd, "Q", 1);
+ }
+
+ mouseFd = mfd;
+ return(mfd);
+}
+
+void MouseCleanup(void)
+{
+ close(mouseFd);
+ mouseFd = -1;
+}
+
+static
+void MouseAnalyzePacket(u_char *packet)
+{
+ static char oldstat;
+ static int dx, dy;
+
+ switch (mouseType) {
+ case MOUSE_NONE:
+ return;
+ case MOUSE_MICROSOFT:
+ mInfo.stat = ((packet[0] & 0x20) >> 3) | ((packet[0] & 0x10) >> 4);
+ dx += (char)(((packet[0] & 0x03) << 6) | (packet[1] & 0x3F));
+ dy += (char)(((packet[0] & 0x0C) << 4) | (packet[2] & 0x3F));
+ break;
+ case MOUSE_MOUSESYSTEMS:
+ mInfo.stat = (~packet[0]) & 0x07;
+ dx += (char)(packet[1]) + (char)(packet[3]);
+ dy += - ((char)(packet[2]) + (char)(packet[4]));
+ break;
+ case MOUSE_MMSERIES:
+ case MOUSE_LOGITECH:
+ mInfo.stat = packet[0] & 0x07;
+ dx += (packet[0] & 0x10) ? packet[1]: - packet[1];
+ dy += (packet[0] & 0x08) ? - packet[2]: packet[2];
+ break;
+ case MOUSE_PS2:
+ mInfo.stat = ((packet[0] & 0x01) << 2) | ((packet[0] & 0x02) >> 1);
+ dx += (char)(packet[1]);
+ dy -= (char)(packet[2]);
+ break;
+ case MOUSE_BUSMOUSE:
+ mInfo.stat = (~packet[0]) & 0x07;
+ dx += (char)packet[1];
+ dy += - (char)packet[2];
+ break;
+ }
+ mInfo.dx = dx >> 3;
+ dx -= mInfo.dx << 3;
+ mInfo.dy = dy / dInfo.glineChar;
+ dy -= mInfo.dy * dInfo.glineChar;
+
+ mInfo.sw = MOUSE_LIFETIME;
+ if (mInfo.dx || mInfo.dy) {
+ mInfo.x += mInfo.dx;
+ mInfo.y += mInfo.dy;
+
+ if (mInfo.x < 0) mInfo.x = 0;
+ else if (mInfo.x > dInfo.txmax) mInfo.x = dInfo.txmax;
+ if (mInfo.y < 0) mInfo.y = 0;
+ else if (mInfo.y > dInfo.tymax) mInfo.y = dInfo.tymax;
+ }
+ if (mInfo.stat & MOUSE_LFT) {
+ if (!(oldstat & MOUSE_LFT)) {
+ mInfo.sx = mInfo.x;
+ mInfo.sy = mInfo.y;
+ } else if (mInfo.dx || mInfo.dy) {
+ TextReverse(mInfo.sx, mInfo.sy, mInfo.x, mInfo.y);
+ TextRefresh();
+ TextReverse(mInfo.sx, mInfo.sy, mInfo.x, mInfo.y);
+ }
+ } else if (oldstat & MOUSE_LFT)
+ TextCopy(mInfo.sx, mInfo.sy, mInfo.x, mInfo.y);
+
+ if (mInfo.stat & pasteButton && !(oldstat & pasteButton)) TextPaste();
+ oldstat = mInfo.stat;
+}
+
+void MouseGetPacket(u_char *buff, int size)
+{
+ static u_char packet[MAX_PK_SIZE];
+ static stat = 0;
+ int n;
+
+ for (n = 0; n < size; n ++, buff ++) {
+ if (!stat) {
+ if ((*buff & headMask) == headId) {
+ packet[0] = *buff;
+ stat = 1;
+ }
+ continue;
+ }
+ if (mouseType != MOUSE_PS2
+ && ((*buff & dataMask) || *buff == 0x80)) {
+ stat = 0;
+ continue;
+ }
+ packet[stat] = *buff;
+ stat ++;
+ if (stat == pkMax) {
+ MouseAnalyzePacket(packet);
+ stat = 0;
+ }
+ }
+}
+
+#else /* HAS_MOUSE */
+
+/* Dummy routines. */
+
+void MouseInit(void)
+{
+ mInfo.has_mouse = FALSE;
+}
+
+void MouseGetPacket(u_char *buff, int size)
+{
+}
+
+int MouseStart(void)
+{
+ return -1;
+}
+
+void MouseCleanup(void)
+{
+}
+
+#endif
+#endif
diff --git a/loader/kon2/src/sock.c b/loader/kon2/src/sock.c
new file mode 100644
index 000000000..00a18136f
--- /dev/null
+++ b/loader/kon2/src/sock.c
@@ -0,0 +1,148 @@
+/*
+ * KON2 - Kanji ON Console -
+ * Copyright (C) 1992-1996 Takashi MANABE (manabe@papilio.tutics.tut.ac.jp)
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Terrence R. Lambert.
+ * 4. The name Terrence R. Lambert may not be used to endorse or promote
+ * products derived from this software without specific prior written
+ * permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY TAKASHI MANABE ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE TERRENCE R. LAMBERT BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#include <config.h>
+
+#ifndef MINI_KON
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/time.h>
+#include <sys/file.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+
+#include <defs.h>
+#include <errors.h>
+#include <interface.h>
+#include <sock.h>
+#include <fnld.h>
+#include <vc.h>
+#include <vt.h>
+#include <term.h>
+
+void StatReport()
+{
+ int i;
+
+ i = 0;
+ while (fSRegs[i].registry) {
+ message("%2X %-15s %c%c\r\n",
+ i, fSRegs[i].registry,
+ (i == lInfo.sb) ? '*':' ',
+ (fSRegs[i].stat & FR_ATTACH) ? 'A':
+ ((fSRegs[i].stat & FR_PROXY) ? 'P':' '));
+ i ++;
+ }
+ i = 0;
+ while (fDRegs[i].registry) {
+ message("%2X %-15s %c%c\r\n",
+ i|CHR_DBC, fDRegs[i].registry,
+ (i == lInfo.db) ?
+ ((lInfo.sc == CODE_EUC) ? 'E':
+ ((lInfo.sc == CODE_SJIS) ? 'S':' ')): ' ',
+ (fDRegs[i].stat & FR_ATTACH) ? 'A':
+ ((fDRegs[i].stat & FR_PROXY) ? 'P':' '));
+ i ++;
+ }
+}
+
+int SocketInit(char *tty)
+{
+ int len, sfd;
+ struct sockaddr sinfo;
+
+#if defined(linux)
+ sprintf(sinfo.sa_data, "/tmp/.kon%s", tty);
+#elif defined(__FreeBSD__)
+ sprintf(sinfo.sa_data, "/tmp/.kon");
+#endif
+ unlink(sinfo.sa_data);
+ if ((sfd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
+ PerrorExit(sinfo.sa_data);
+ }
+ sinfo.sa_family = AF_UNIX;
+ len = sizeof(sinfo.sa_family) + strlen(sinfo.sa_data) + 1;
+ if (bind(sfd, &sinfo, len) < 0) {
+ message("can't bind socket");
+ PerrorExit(sinfo.sa_data);
+ }
+ listen(sfd, 1);
+ chown(sinfo.sa_data, getuid(), getgid());
+ return(sfd);
+}
+
+void SocketInterface(int sfd)
+{
+ int fd, len;
+ struct sockaddr clt;
+ struct messageHeader mh;
+
+ len = sizeof(struct sockaddr);
+ if ((fd = accept(sfd, &clt, &len)) < 0) PerrorExit("accept");
+ SocketRecCommand(fd, &mh);
+ switch(mh.cmd) {
+ case CHR_LOAD:
+ FontAttach();
+ break;
+ case CHR_UNLOAD:
+ FontDetach(FALSE);
+ break;
+ case CHR_TEXTMODE:
+ TextMode();
+ message("switched to text mode.\r\n");
+ SocketSendCommand(fd, CHR_ACK);
+ break;
+ case CHR_GRAPHMODE:
+ GraphMode();
+ message("switched to graphics mode.\r\n");
+ SocketSendCommand(fd, CHR_ACK);
+ break;
+ case CHR_RESTART:
+ SocketSendCommand(fd, CHR_ACK);
+ TermRestart(fd);
+ break;
+ case CHR_STAT:
+ SocketSendCommand(fd, CHR_ACK);
+ StatReport();
+ break;
+ default:
+ message("unknown request.\r\n");
+ SocketSendCommand(fd, CHR_NAK);
+ }
+ close(fd);
+}
+#endif
diff --git a/loader/kon2/src/term.c b/loader/kon2/src/term.c
new file mode 100644
index 000000000..dccf4addb
--- /dev/null
+++ b/loader/kon2/src/term.c
@@ -0,0 +1,579 @@
+/*
+ * KON2 - Kanji ON Console -
+ * Copyright (C) 1992-1996 Takashi MANABE (manabe@papilio.tutics.tut.ac.jp)
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY TAKASHI MANABE ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE TERRENCE R. LAMBERT BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <termios.h>
+#if defined(__FreeBSD__)
+#include <machine/console.h>
+#endif
+#include <signal.h>
+#include <errno.h>
+#if defined(linux)
+#include <sys/vt.h>
+#include <sys/kd.h>
+#endif
+#include <sys/time.h>
+#include <sys/ioctl.h>
+#include <sys/file.h>
+#include <sys/wait.h>
+
+#include <config.h>
+#include <getcap.h>
+
+#include <defs.h>
+#include <errors.h>
+#ifndef MINI_KON
+#include <setutmp.h>
+#endif
+#include <version.h>
+#include <vc.h>
+#include <vt.h>
+#include <child.h>
+#include <interface.h>
+#include <sock.h>
+#ifdef MINI_KON
+static int mouseFd=-1;
+#else
+static int sockFd;
+#include <mouse.h>
+#endif
+
+#ifdef __FreeBSD__
+#define TCSETA TIOCSETA
+#define TCGETA TIOCGETA
+#define SIGCLD SIGCHLD
+#define XCASE 0
+#endif
+
+int masterPty; /* master pseudo-tty file descriptor */
+
+#define MAX_TTYNAME 10
+
+static int childPid, slavePty;
+static struct termios oldTio;
+static char ptyName[MAX_TTYNAME + 1];
+static int orgVtNum = -1;
+
+struct initInfo {
+ bool display; /* display initialized */
+ bool utmp; /* utmp set */
+ bool socket; /* socket opened */
+ bool termios; /* termios saved */
+};
+
+static struct initInfo init;
+
+static void CleanUp(void)
+{
+ if (init.display && con.active) {
+ TextMode();
+ }
+#ifndef MINI_KON
+ if (init.utmp)
+ ResetUtmp(ptyName);
+ if (init.socket)
+ SocketKill(sockFd);
+#endif
+ if (init.termios)
+ tcsetattr(0, TCSAFLUSH, &oldTio);
+ signal(SIGCHLD, SIG_DFL);
+ signal(SIGHUP, SIG_DFL);
+ signal(SIGTERM, SIG_DFL);
+ signal(SIGSEGV, SIG_DFL);
+ signal(SIGUSR1, SIG_DFL);
+ signal(SIGUSR2, SIG_DFL);
+#ifndef MINI_KON
+ FontDetach(TRUE);
+#endif
+}
+
+static void ExitTerm(int signum)
+{
+ fatal(sys_siglist[signum]);
+}
+
+static void ExitPty(int signum)
+{
+ int stat;
+
+#if defined(__FreeBSD__)
+ signal(SIGCLD, SIG_DFL);
+#endif
+ if (wait3(&stat, WNOHANG, 0) != childPid) {
+ TextMode();
+ kill(0, SIGTSTP);
+ GraphMode();
+ kill(childPid, SIGCONT);
+ signal(SIGCLD, ExitPty);
+ return;
+ }
+ if (WEXITSTATUS(stat) & 0x7f)
+ if (WIFSIGNALED(stat))
+ fatal("child died with signal -- %s\r\n", sys_siglist[WTERMSIG(stat)]);
+ else
+ fatal("child exited with status %d\r\n", WEXITSTATUS(stat) & 0x7f);
+ else if (signum == SIGHUP) {
+ fprintf(stderr, "\r\nKON> switched to new VC\r\n");
+ exit(EXIT_SUCCESS);
+ } else {
+ fprintf(stderr, "\r\nKON> finished\r\n");
+ exit(EXIT_SUCCESS);
+ }
+}
+
+static fd_set orgReadFds;
+static int numFds;
+
+#ifndef MINI_KON
+void MouseSetRfd(int mfd)
+{
+ if (mfd > 0) FD_SET(mfd, &orgReadFds);
+ if (mfd > sockFd) numFds = mfd + 1;
+ else numFds = sockFd + 1;
+}
+
+void MouseResetRfd(int mfd)
+{
+ if (mfd > 0) FD_CLR(mfd, &orgReadFds);
+ numFds = sockFd + 1;
+}
+#endif
+
+static void ConsoleHandler(void)
+{
+ static u_char buff[BUFSIZ + 1];
+ fd_set readFds;
+ int i = 0;
+ struct timeval tv;
+
+ FD_ZERO(&orgReadFds);
+ FD_SET(0, &orgReadFds);
+ FD_SET(masterPty, &orgReadFds);
+#ifdef MINI_KON
+ numFds = masterPty + 1;
+#else
+ FD_SET(sockFd, &orgReadFds);
+ if (mInfo.has_mouse && mouseFd > 0)
+ MouseSetRfd(mouseFd);
+ else
+ MouseResetRfd(mouseFd);
+#endif
+ /* Note: we use timeout on select call even if cursor blink is off
+ because of screen saver and mouse cursor timeout. */
+ while (1) {
+ int v;
+
+ do {
+ /* Idle loop. */
+ PollCursor(FALSE);
+ readFds = orgReadFds;
+ tv.tv_sec = 0;
+ tv.tv_usec = 100000; /* 0.1 sec */
+ v = select(numFds, &readFds, NULL, NULL, &tv);
+ } while (v == 0 || (v < 0 && (errno == EINTR || mouseFd < 0)));
+ if (v < 0) {
+ PerrorExit("select");
+ }
+ if (FD_ISSET(masterPty, &readFds)) {
+ i = read(masterPty, buff, BUFSIZ);
+ if (i > 0) {
+ if (con.text_mode) {
+ write(1, buff, i);
+ } else {
+/* buff[i] = 0;*/
+ VtEmu(buff, i);
+ TextRefresh();
+ }
+ }
+ }
+ if (FD_ISSET(0, &readFds)) {
+ i = read(0, buff, BUFSIZ);
+#ifdef MINI_KON
+ if (i == 3 && !strncmp("\x1b\x5b\x50", buff, 3)) {
+ VgaChangeClock();
+ } else
+#endif
+ if (i > 0) write(masterPty, buff, i);
+#if 0
+ {
+ FILE *fff;
+ fff = fopen("in.log", "a");
+ fwrite(buff, i, 1, fff);
+ fclose(fff);
+ }
+#endif
+ PollCursor(TRUE);
+ }
+#ifndef MINI_KON
+ if (FD_ISSET(sockFd, &readFds)) SocketInterface(sockFd);
+ if (mInfo.has_mouse) {
+ if (FD_ISSET(mouseFd, &readFds) && con.active) {
+ i = read(mouseFd, buff, BUFSIZ);
+ if (i > 0) MouseGetPacket(buff, i);
+ PollCursor(TRUE);
+ }
+ }
+#endif
+ }
+}
+
+static void ProcessArgs(int argc, const char *argv[])
+{
+ int i = 0;
+ const char *video = "NORMAL";
+ extern int ConfigExecProg(const char *);
+
+ if (argc > 0 && argv[0][0] != '-') {
+ video = argv[0];
+ i++;
+ }
+ ConsoleInit(video);
+ while (i < argc) {
+ const char *arg;
+
+ if (argv[i][0] != '-') {
+ warn("bad arg `%s'; assumed `-%s'\r\n", argv[i]);
+ arg = (char *) argv[i];
+ } else
+ arg = (char *) argv[i] + 1;
+ i++;
+ if (i >= argc) {
+ error("no value for `%s'\r\n", arg);
+ break;
+ }
+ if (!strcasecmp(arg, "e"))
+ ConfigExecProg(argv[i]);
+ else if (SetCapArg(arg, argv[i]) < 0)
+ warn("invalid capability `%s' ignored\r\n", arg);
+ i++;
+ }
+}
+
+static int savedArgc; /* argc of startup time */
+static const char **savedArgv; /* argv of startup time */
+
+/* Do initialization before reading config file */
+void TermInit(int argc, const char *argv[])
+{
+ int i;
+
+ init.display = init.utmp = init.socket = init.termios = FALSE;
+ /* Initialize subsystems. */
+
+ CapInit();
+
+#ifndef MINI_KON
+ ChildInit();
+ MouseInit();
+#endif
+
+ VtInit();
+ ProcessArgs(argc, argv);
+ savedArgc = argc;
+ savedArgv = malloc(argc * sizeof(const char *));
+ for (i = 0; i < argc; i++) {
+ savedArgv[i] = strdup(argv[i]);
+ }
+}
+
+static int TryTermReset(int argc, const char *argv[])
+{
+ int i;
+
+ fprintf(stderr, "KON> resetting kon for args [");
+ for (i = 0; i < argc; i++) {
+ fprintf(stderr, " %s", argv[i]);
+ }
+ fprintf(stderr, " ]...\r\n");
+ CapInit();
+ ConsoleCleanup();
+#ifndef MINI_KON
+ if (mInfo.has_mouse)
+ MouseCleanup();
+ MouseInit();
+#endif
+#if 0
+ VtCleanup();
+#endif
+ init.display = FALSE;
+ VtInit();
+ ProcessArgs(argc, argv);
+ return ReadConfig(CONFIG_NAME);
+}
+
+/* Called from SocketInterface with stream fd. */
+void TermRestart(int fd)
+{
+ int i;
+ int argc;
+ char **argv;
+
+ read(fd, &argc, sizeof(argc));
+ argv = alloca(argc * sizeof(char *));
+ for (i = 0; i < argc; i++) {
+ int len;
+
+ read(fd, &len, sizeof(len));
+ argv[i] = alloca(len + 1); /* +1 for '\0' */
+ read(fd, argv[i], (size_t) len);
+ argv[i][len] = '\0';
+ }
+ TextMode();
+ if (TryTermReset(argc, (const char **)argv) < 0 &&
+ TryTermReset(savedArgc, savedArgv) < 0 &&
+ TryTermReset(0, (const char **)NULL) < 0)
+ fatal("giving up\r\n");
+#ifndef MINI_KON
+ if (mInfo.has_mouse)
+ mouseFd = MouseStart();
+#endif
+ VtStart();
+ ConsoleStart();
+ init.display = TRUE;
+ message("reset done\r\n");
+}
+
+char *
+TermName()
+{
+ static char *tty;
+
+ if (!tty) {
+ char *tmp;
+
+ tmp = ttyname(0);
+ tty = strdup(strcmp(tmp, "/dev/console") ? tmp: "/dev/tty1");
+ }
+ return(tty);
+}
+
+/* Start processing */
+void TermStart(void)
+{
+ struct termios newTio;
+ char ls, ln;
+#ifdef MINI_KON
+ extern void LoadMiniFont();
+#endif
+
+ /* Open PTY(master) */
+ for (ls = 'p'; ls <= 's'; ls ++) {
+ for (ln = 0; ln <= 0xF; ln ++) {
+ sprintf(ptyName, "/dev/pty%1c%1x", ls, ln);
+ if ((masterPty = open(ptyName, O_RDWR)) >= 0) break;
+ }
+ if (masterPty >= 0) break;
+ }
+ if (masterPty < 0) {
+ message("can not get master pty\r\n");
+ PerrorExit(ptyName);
+ }
+ ptyName[5] = 't';
+
+#ifndef MINI_KON
+ if (mInfo.has_mouse) {
+ mouseFd = MouseStart();
+ }
+#endif
+
+#ifndef MINI_KON
+ chown("/dev/tty0", getuid(), getgid());
+#if defined(linux)
+ sockFd = SocketInit(TermName() + 8);
+#elif defined(__FreeBSD__)
+ sockFd = SocketInit(ttyname(0) + 9);
+#endif
+#endif
+ init.socket = TRUE;
+
+ /* Get old tio of 0 */
+ tcgetattr(0, &oldTio);
+ init.termios = TRUE;
+
+#ifndef MINI_KON
+ SetUtmp(ptyName);
+#endif
+ init.utmp = TRUE;
+
+ /* fork handler */
+ if ((childPid = fork()) < 0) {
+ PerrorExit("fork");
+ }
+ if (childPid != 0) {
+ /* I'm parent. */
+ atexit(CleanUp);
+ ChildCleanup();
+
+#ifdef MINI_KON
+ LoadMiniFont();
+#endif
+ /* Signal Setting */
+ signal(SIGCHLD, ExitPty);
+ signal(SIGHUP, ExitTerm);
+ signal(SIGTERM, ExitTerm);
+ signal(SIGSEGV, ExitTerm);
+ /* Set new tio of 0 */
+ newTio = oldTio;
+ newTio.c_lflag &= ~(ECHO|ISIG|ICANON|XCASE);
+ newTio.c_iflag = 0;
+ newTio.c_oflag &= ~OPOST;
+ newTio.c_cc[VMIN] = 1;
+ newTio.c_cc[VTIME] = 0;
+#if defined(__FreeBSD__)
+ newTio.c_cc[VDISCARD] = _POSIX_VDISABLE;
+ newTio.c_cc[VLNEXT] = _POSIX_VDISABLE;
+ newTio.c_cc[VSTART] = _POSIX_VDISABLE;
+ newTio.c_cc[VSTOP] = _POSIX_VDISABLE;
+ newTio.c_cc[VINTR] = _POSIX_VDISABLE;
+ newTio.c_cc[VSUSP] = _POSIX_VDISABLE;
+ newTio.c_cc[VDSUSP] = _POSIX_VDISABLE;
+ newTio.c_cc[VQUIT] = _POSIX_VDISABLE;
+#endif
+ newTio.c_cflag |= CS8;
+#ifdef linux
+ newTio.c_line = 0;
+#endif
+ tcsetattr(0, TCSAFLUSH, &newTio);
+ /* VGA initialize */
+ VtStart();
+ ConsoleStart();
+ init.display = TRUE;
+#ifndef MINI_KON
+ FontAttach();
+#endif
+ ConsoleHandler();
+ } else {
+ int efd;
+ FILE *errfp;
+
+ efd = dup(2);
+ errfp = fdopen(efd, "w");
+ /* I'm child */
+ /* Make me process leader */
+ setsid();
+#if defined(__FreeBSD__)
+ {
+ int devtty;
+ if ((devtty = open("/dev/tty",O_RDWR|O_NDELAY)) >= 0) {
+ ioctl(devtty, TIOCNOTTY, (char *)0);
+ close(devtty);
+ }
+ }
+#endif
+ /* Open TTY(slave) */
+ if ((slavePty = open(ptyName, O_RDWR)) < 0) {
+ PerrorExit(ptyName);
+ }
+ close(masterPty);
+ /* Set old tio to TTY */
+ tcsetattr(slavePty, TCSAFLUSH, &oldTio);
+#ifdef __FreeBSD__
+ ioctl(slavePty, TIOCSCTTY, (char *)0);
+#endif
+ /* Set std??? to pty */
+ dup2(slavePty, 0);
+ dup2(slavePty, 1);
+ dup2(slavePty, 2);
+ ChildStart(errfp);
+ }
+}
+
+void ChangeOrgConsole()
+{
+ int cfd;
+
+#if defined(linux)
+ cfd = open("/dev/console", O_WRONLY);
+ if (cfd < 0 && (cfd = open("/dev/console", O_RDONLY)) < 0) {
+ PerrorExit("/dev/console");
+ }
+#elif defined(__FreeBSD__)
+ cfd = open("/dev/vga", O_WRONLY);
+ if (cfd < 0 && (cfd = open("/dev/vga", O_RDONLY)) < 0) {
+ PerrorExit("/dev/vga");
+ }
+#endif
+ ioctl(cfd, VT_ACTIVATE, orgVtNum);
+ close(cfd);
+}
+
+void ChangeNewConsole()
+{
+#if defined(linux)
+ struct vt_stat vts;
+#endif
+ int cfd, vfd, vtNum, child, parent, mode;
+ char vtty[MAX_TTYNAME + 1];
+
+#if defined(linux)
+ cfd = open("/dev/console", O_WRONLY);
+ if (cfd < 0 && (cfd = open("/dev/console", O_RDONLY)) < 0)
+ fatal("can't open /dev/console");
+#elif defined(__FreeBSD__)
+ cfd = open("/dev/vga", O_WRONLY);
+ if (cfd < 0 && (cfd = open("/dev/vga", O_RDONLY)) < 0)
+ fatal("can't open /dev/vga");
+#endif
+ ioctl(cfd, KDGETMODE, &mode);
+ if (mode == KD_TEXT) {
+ close(cfd);
+ return;
+ }
+#if defined(linux)
+ ioctl(cfd, VT_GETSTATE, &vts);
+ orgVtNum = vts.v_active;
+#endif
+ ioctl(cfd, VT_OPENQRY, &vtNum);
+ if (vtNum < 0)
+ fatal("can't get free VC");
+ parent = getpid();
+ if ((child = fork()) == -1)
+ PerrorExit("fork");
+ if (child) {
+ signal(SIGHUP, ExitPty);
+ pause();
+ }
+ setsid();
+#if defined(linux)
+ sprintf(vtty, "/dev/tty%d", vtNum);
+#elif defined(__FreeBSD__)
+ sprintf(vtty, "/dev/ttyv%d", vtNum);
+#endif
+ if ((vfd = open(vtty, O_RDWR)) < 0)
+ fatal("can't open %s", vtty);
+ if (ioctl(cfd, VT_ACTIVATE, vtNum) != 0)
+ fatal("can't activate VC(%d)", vtNum);
+ atexit(ChangeOrgConsole);
+ close(cfd);
+ dup2(vfd, 0);
+ dup2(vfd, 1);
+ dup2(vfd, 2);
+ kill(parent, SIGHUP);
+}
diff --git a/loader/kon2/src/utmp.c b/loader/kon2/src/utmp.c
new file mode 100644
index 000000000..e795b5b09
--- /dev/null
+++ b/loader/kon2/src/utmp.c
@@ -0,0 +1,104 @@
+/*
+ * KON2 - Kanji ON Console -
+ * Copyright (C) 1992-1996 Takashi MANABE (manabe@papilio.tutics.tut.ac.jp)
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY TAKASHI MANABE ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE TERRENCE R. LAMBERT BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+/*
+ Original utmp.c was ported from Wnn by komeda@ics.osaka-u.ac.jp.
+ This code is written by manabe@papilio.tutics.tut.ac.jp,
+ and this does not contain old code (Wnn's setutmp.c).
+
+ Thanks to komeda@ics.osaka-u.ac.jp.
+*/
+
+#include <config.h>
+
+#ifndef MINI_KON
+
+#include <stdio.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <string.h>
+#include <pwd.h>
+#include <utmp.h>
+#include <grp.h>
+#include <sys/stat.h>
+
+static int ttyGid;
+
+void SetUtmp(char *tty)
+{
+#ifdef linux
+ struct utmp utmp;
+ struct passwd *pw;
+ struct group *ttygrp;
+ char *tn;
+
+ pw = getpwuid(getuid());
+ tn = rindex(tty, '/') + 1;
+ memset((char *)&utmp, 0, sizeof(utmp));
+ strncpy(utmp.ut_id, tn + 3, sizeof(utmp.ut_id));
+ utmp.ut_type = DEAD_PROCESS;
+ setutent();
+ getutid(&utmp);
+ utmp.ut_type = USER_PROCESS;
+ utmp.ut_pid = getpid();
+ strncpy(utmp.ut_line, tn, sizeof(utmp.ut_line));
+ strncpy(utmp.ut_user, pw->pw_name, sizeof(utmp.ut_user));
+ time(&(utmp.ut_time));
+ pututline(&utmp);
+ endutent();
+ if ((ttygrp = getgrnam("tty")) != NULL)
+ ttyGid = ttygrp->gr_gid;
+ else
+ ttyGid = -1;
+ chmod(tty, 0622);
+ chown(tty, getuid(), ttyGid);
+#endif
+}
+
+void ResetUtmp(char *tty)
+{
+#ifdef linux
+ struct utmp utmp, *utp;
+ char *tn;
+
+ tn = rindex(tty, '/') + 4;
+ memset((char *)&utmp, 0, sizeof(utmp));
+ strncpy(utmp.ut_id, tn, sizeof(utmp.ut_id));
+ utmp.ut_type = USER_PROCESS;
+ setutent();
+ utp = getutid(&utmp);
+ utp->ut_type = DEAD_PROCESS;
+ memset(utp->ut_user, 0, sizeof(utmp.ut_user));
+ utp->ut_type = DEAD_PROCESS;
+ time(&(utp->ut_time));
+ pututline(utp);
+ endutent();
+ chmod(tty, 0600);
+ chown(tty, 0, ttyGid);
+#endif
+}
+#endif /* MINI_KON */
diff --git a/loader/kon2/src/vc.c b/loader/kon2/src/vc.c
new file mode 100644
index 000000000..387cdefae
--- /dev/null
+++ b/loader/kon2/src/vc.c
@@ -0,0 +1,926 @@
+/*
+ * KON2 - Kanji ON Console -
+ * Copyright (C) 1992, 1993 MAEDA Atusi (mad@math.keio.ac.jp)
+ * Copyright (C) 1992-1996 Takashi MANABE (manabe@papilio.tutics.tut.ac.jp)
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY MAEDA ATUSI AND TAKASHI MANABE ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE TERRENCE R. LAMBERT BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#include <config.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#if defined(linux)
+#include <sys/vt.h>
+#endif
+#include <fcntl.h>
+#include <signal.h>
+#include <termios.h>
+#if defined(__FreeBSD__)
+#include <machine/console.h>
+#endif
+#include <sys/ioctl.h>
+#ifdef linux
+#include <sys/kd.h>
+#endif
+
+#include <mem.h>
+#include <getcap.h>
+
+#include <defs.h>
+#include <errors.h>
+#include <fnld.h>
+#ifndef MINI_KON
+#include <mouse.h>
+#endif
+#include <vc.h>
+#include <vt.h>
+#include <term.h>
+
+struct dispInfo dInfo;
+struct cursorInfo cInfo;
+struct videoInfo vInfo;
+#ifndef MINI_KON
+static struct cursorInfo mouseCursor;
+#endif
+
+static bool textClear;
+
+static int textHead, scrollLine;
+static u_int textSize;
+static u_char *textBuff, *attrBuff, *flagBuff;
+
+static int saveTime, saverCount;
+static bool saved;
+static bool useHardScroll;
+static volatile bool busy; /* TRUE iff updating screen */
+static volatile bool release; /* delayed VC switch flag */
+
+static void ShowCursor(struct cursorInfo *, bool);
+
+static void LeaveVC(int);
+static void EnterVC(int);
+
+/*
+
+ flagBuff:
+ | 7| 6| 5|4||3|2|1|0|
+ |CLEAN_S|LATCH_2|LATCH_1| ||<----->|
+ |0=latch| byte2| byte1| || LANG|
+
+ */
+
+#define KON_TMP_FILE "/tmp/.kontmp"
+
+static
+inline void blatch(void *head, int n)
+{
+
+ __asm__("\t clc\n"
+ "1:\n"
+ "\t andb %%bl, (%%eax)\n"
+ "\t incl %%eax\n"
+ "\t loop 1b\n"
+ :
+ : "eax" ((long)head), "bl" (0x7F), "c" (n)
+ : "bl", "cx" );
+}
+
+static
+inline void llatch(void *head, int n)
+{
+
+ __asm__("\t clc\n"
+ "1:\n"
+ "\t andl %%ebx, (%%eax)\n"
+ "\t addl $4, %%eax\n"
+ "\t loop 1b\n"
+ :
+ : "eax" ((long)head), "ebx" (0x7F7F7F7F), "c" (n>>2)
+ : "ebx", "cx" );
+}
+
+static inline u_int TextAddress(u_int x, u_int y)
+{
+ return (textHead + x + y * dInfo.glineByte) % textSize;
+}
+
+static inline bool IsKanji(u_int x, u_int y)
+{
+ return(*(flagBuff + TextAddress(x, y)) & CODEIS_1);
+}
+
+static inline bool IsKanji2(u_int x, u_int y)
+{
+ return(*(flagBuff + TextAddress(x, y)) & CODEIS_2);
+}
+
+void euctosjis(ch, cl)
+u_char *ch, *cl;
+{
+ u_char nh, nl;
+
+ nh = ((*ch - 0x21) >> 1) + 0x81;
+ if (nh > 0x9F) nh += 0x40;
+ if (*ch & 1) {
+ nl = *cl + 0x1F;
+ if (*cl > 0x5F)
+ nl ++;
+ } else nl = *cl + 0x7E;
+ *cl = nl;
+ *ch = nh;
+}
+
+void TextDeleteChar(int n)
+{
+ u_int addr, dx;
+
+ addr = TextAddress(con.x, con.y);
+ dx = dInfo.glineByte - con.x - n;
+
+ bmove(textBuff + addr, textBuff + addr + n, dx);
+ bmove(attrBuff + addr, attrBuff + addr + n, dx);
+ bmove(flagBuff + addr, flagBuff + addr + n, dx);
+ blatch(flagBuff + addr, dx);
+
+ addr = TextAddress(dInfo.glineByte - n, con.y);
+ bzero2(textBuff + addr, n);
+ bzero2(attrBuff + addr, n);
+ bzero2(flagBuff + addr, n);
+}
+
+void TextInsertChar(int n)
+{
+ u_int addr, dx;
+
+ addr = TextAddress(dInfo.txmax, con.y);
+ dx = dInfo.glineByte - con.x - n;
+ brmove(textBuff + addr, textBuff + addr - n, dx);
+ brmove(attrBuff + addr, attrBuff + addr - n, dx);
+ brmove(flagBuff + addr, flagBuff + addr - n, dx);
+
+ addr = TextAddress(con.x, con.y);
+
+ blatch(flagBuff + addr + n, dx);
+ bzero2(textBuff + addr, n);
+ bzero2(attrBuff + addr, n);
+ bzero2(flagBuff + addr, n);
+}
+
+void TextRefresh(void)
+{
+ u_int fnt, i;
+ u_char ch, ch2, fc, bc;
+
+ busy = TRUE;
+ if (!con.active) {
+ busy = FALSE;
+ return;
+ }
+ ShowCursor(&cInfo, FALSE);
+#ifndef MINI_KON
+ ShowCursor(&mouseCursor, FALSE);
+#endif
+ if (textClear) vInfo.clear_all();
+ if (useHardScroll) {
+ if (scrollLine > 0) vInfo.hard_scroll_up(scrollLine);
+ else if (scrollLine < 0) vInfo.hard_scroll_down(- scrollLine);
+ scrollLine = 0;
+ }
+ textClear = FALSE;
+ for (i = 0; i < textSize; i ++) {
+ if (*(flagBuff + i)&CLEAN_S) continue; /* already clean */
+ vInfo.set_address(i);
+ fc = *(attrBuff + i);
+ bc = *(attrBuff + i) >> 4;
+ ch = *(textBuff + i);
+ *(flagBuff + i) |= CLEAN_S;
+ if (*(flagBuff + i) & CODEIS_1) {
+ dbFReg = &fDRegs[*(flagBuff + i)&LANG_CODE];
+ i ++;
+ *(flagBuff + i) |= CLEAN_S;
+ ch2 = *(textBuff + i);
+ fnt = dbFReg->addr(ch2, ch);
+#if 0
+ {
+ FILE *fp=fopen("errlog", "a");
+ fprintf(fp,"<%x %s %d %X %X %X>\n",
+ *(flagBuff + i - 1)&LANG_CODE,
+ dbFReg->registry, dbFReg->size, ch2, ch, fnt);
+ fclose(fp);
+ }
+#endif
+ if (con.ins) TextInsertChar(2);
+ if (fnt < dbFReg->size)
+ vInfo.wput(dbFReg->bitmap + fnt, fc, bc);
+ } else {
+ sbFReg = &fSRegs[*(flagBuff + i)&LANG_CODE];
+#if 0
+ {
+ FILE *fp=fopen("errlog", "a");
+ fprintf(fp,"<%x %s %d>\n",
+ *(flagBuff + i)&LANG_CODE,
+ sbFReg->registry, sbFReg->size);
+ fclose(fp);
+ }
+#endif
+ if (con.ins) TextInsertChar(1);
+ vInfo.sput(ch ? sbFReg->bitmap + (ch << 4):0, fc, bc);
+ }
+ }
+ cInfo.kanji = IsKanji(con.x, con.y);
+ vInfo.set_cursor_address(&cInfo, con.x, con.y);
+ ShowCursor(&cInfo, TRUE);
+ busy = FALSE;
+ if (release)
+ LeaveVC(SIGUSR1);
+}
+
+static struct winsize text_win;
+
+static void SetTextMode(void)
+{
+ ShowCursor(&cInfo, FALSE);
+ vInfo.clear_all();
+ vInfo.text_mode();
+ ioctl(0, KDSETMODE, KD_TEXT);
+ ioctl(0, TIOCCONS, NULL);
+}
+
+void TextMode(void)
+{
+ struct vt_mode vtm;
+
+ signal(SIGUSR1, SIG_DFL);
+ signal(SIGUSR2, SIG_DFL);
+ vtm.mode = VT_AUTO;
+ vtm.waitv = 0;
+ vtm.relsig = 0;
+ vtm.acqsig = 0;
+ ioctl(0, VT_SETMODE, &vtm);
+#if defined(__FreeBSD__)
+ ioctl(0, VT_RELDISP, 1);
+#endif
+ con.text_mode = TRUE;
+ SetTextMode();
+ ioctl(masterPty, TIOCSWINSZ, &text_win);
+}
+
+void GraphMode(void)
+{
+ struct winsize win;
+ struct vt_mode vtm;
+
+ con.text_mode = FALSE;
+ ioctl(0, KDSETMODE, KD_GRAPHICS);
+#if defined(__FreeBSD__)
+ ioctl(0, VT_RELDISP, VT_ACKACQ);
+#endif
+ signal(SIGUSR1, LeaveVC);
+ signal(SIGUSR2, EnterVC);
+ vtm.mode = VT_PROCESS;
+ vtm.waitv = 0;
+ vtm.relsig = SIGUSR1;
+ vtm.acqsig = SIGUSR2;
+ ioctl(0, VT_SETMODE, &vtm);
+ vInfo.graph_mode();
+ if (useHardScroll)
+ vInfo.set_start_address();
+
+ win.ws_row = dInfo.tymax + 1; /* Note: con.ymax may be changed by application */
+ win.ws_col = dInfo.txmax + 1;
+ win.ws_xpixel = win.ws_ypixel = 0;
+ ioctl(masterPty, TIOCSWINSZ, &win);
+ ioctl(masterPty, TIOCCONS, NULL);
+
+ llatch(flagBuff, textSize);
+ textClear = TRUE;
+ TextRefresh();
+}
+
+static
+ void LeaveVC(int signum)
+{
+
+ signal(SIGUSR1, LeaveVC); /* should use sigaction()? */
+ if (busy) {
+ release = TRUE;
+ return;
+ }
+ release = FALSE;
+ con.active = FALSE;
+ SetTextMode();
+#ifdef HAS_MOUSE
+ if (mInfo.has_mouse) {
+ MouseResetRfd(mouseFd);
+ MouseCleanup();
+ }
+#endif
+ ioctl(0, VT_RELDISP, 1);
+}
+
+static
+ void EnterVC(int signum)
+{
+ signal(SIGUSR2, EnterVC);
+ if (!con.active) {
+ con.active = TRUE;
+ GraphMode();
+ signal(SIGUSR2, EnterVC);
+#ifdef HAS_MOUSE
+ if (mInfo.has_mouse) {
+ MouseStart();
+ MouseSetRfd(mouseFd);
+ }
+#endif
+ }
+}
+
+static
+ void TextScrollUp(int line)
+{
+ int oldhead, len;
+
+ oldhead = textHead;
+ textHead += line * dInfo.glineByte;
+ if (textHead > textSize) {
+ textHead -= textSize;
+ len = textSize - oldhead;
+ if (textHead) {
+ lzero(textBuff, textHead);
+ lzero(attrBuff, textHead);
+ lzero(flagBuff, textHead);
+ }
+ } else len = textHead - oldhead;
+ lzero(textBuff + oldhead, len);
+ lzero(attrBuff + oldhead, len);
+ lzero(flagBuff + oldhead, len);
+}
+
+static
+ void TextScrollDown(int line)
+{
+ int oldhead, len;
+
+ oldhead = textHead;
+ textHead -= line * dInfo.glineByte;
+ if (textHead < 0) {
+ textHead += textSize;
+ if (oldhead) {
+ lzero(textBuff, oldhead);
+ lzero(attrBuff, oldhead);
+ lzero(flagBuff, oldhead);
+ }
+ len = textSize - textHead;
+ } else len = oldhead - textHead;
+ lzero(textBuff + textHead, len);
+ lzero(attrBuff + textHead, len);
+ lzero(flagBuff + textHead, len);
+}
+
+void TextWput(u_char ch1, u_char ch2)
+{
+ u_int addr;
+ u_char *p;
+
+ addr = TextAddress(con.x, con.y);
+ *(attrBuff + addr) = con.fcol | (con.bcol << 4);
+ *(p = textBuff + addr) = ch2;
+ *(p + 1) = ch1;
+ *(p = flagBuff + addr) = con.db;
+ *(p + 1) = LATCH_2;
+}
+
+void TextSput(u_char ch)
+{
+ u_int addr;
+
+ addr = TextAddress(con.x, con.y);
+ *(flagBuff + addr) = LATCH_S|con.sb;
+ *(attrBuff + addr) = con.fcol | (con.bcol << 4);
+ *(textBuff + addr) = ch;
+}
+
+void TextClearAll(void)
+{
+#if 1
+ u_int y, addr;
+
+ for (y = 0; y <= con.ymax; y ++) {
+ addr = TextAddress(0, y);
+ lzero(textBuff + addr, dInfo.glineByte);
+ lzero(attrBuff + addr, dInfo.glineByte);
+ }
+#else
+ lzero(textBuff, textSize);
+ lzero(attrBuff, textSize);
+#endif
+ lzero(flagBuff, textSize);
+#ifndef MINI_KON
+ mInfo.sw = 0;
+#endif
+ textClear = TRUE;
+}
+
+void TextClearEol(u_char mode)
+{
+ u_int addr;
+ u_char len, x=0;
+
+ switch(mode) {
+ case 1:
+ len = con.x;
+ break;
+ case 2:
+ len = dInfo.glineByte;
+ break;
+ default:
+ x = con.x;
+ len = dInfo.glineByte - con.x;
+ break;
+ }
+ addr = TextAddress(x, con.y);
+ bzero2(textBuff + addr, len);
+ bzero2(attrBuff + addr, len);
+ bzero2(flagBuff + addr, len);/* needless to latch */
+}
+
+void TextClearEos(u_char mode)
+{
+ u_int addr, len, y;
+
+ if (mode == 2) {
+ TextClearAll();
+ return;
+ }
+ switch(mode) {
+ case 1:
+ for (y = 0; y < con.y; y ++) {
+ addr = TextAddress(0, y);
+ lzero(textBuff + addr, dInfo.glineByte);
+ lzero(attrBuff + addr, dInfo.glineByte);
+ lzero(flagBuff + addr, dInfo.glineByte);/* needless to latch */
+ }
+ addr = TextAddress(0, con.y);
+ bzero2(textBuff + addr, con.x);
+ bzero2(attrBuff + addr, con.x);
+ bzero2(flagBuff + addr, con.x);/* needless to latch */
+ break;
+ default:
+ for (y = con.y + 1; y <= con.ymax; y ++) {
+ addr = TextAddress(0, y);
+ lzero(textBuff + addr, dInfo.glineByte);
+ lzero(attrBuff + addr, dInfo.glineByte);
+ lzero(flagBuff + addr, dInfo.glineByte);/* needless to latch */
+ }
+ addr = TextAddress(con.x, con.y);
+ len = dInfo.glineByte - con.x;
+ bzero2(textBuff + addr, len);
+ bzero2(attrBuff + addr, len);
+ bzero2(flagBuff + addr, len);/* needless to latch */
+ break;
+ }
+}
+
+static
+ void TextClearBand(u_int top, u_int btm)
+{
+ u_int y, addr;
+
+ for (y = top; y <= btm; y ++) {
+ addr = TextAddress(0, y);
+ lzero(textBuff + addr, dInfo.glineByte);
+ lzero(attrBuff + addr, dInfo.glineByte);
+ lzero(flagBuff + addr, dInfo.glineByte);/* needless to latch */
+ }
+}
+
+void TextMoveDown(int top, int btm, int line)
+{
+ u_int n, src, dst;
+
+ if (btm - top - line + 1 <= 0) {
+ TextClearBand(top, btm);
+ return;
+ }
+ for (n = btm; n >= top + line; n --) {
+ dst = TextAddress(0, n);
+ src = TextAddress(0, n - line);
+ lmove(textBuff + dst, textBuff + src, dInfo.glineByte);
+ lmove(attrBuff + dst, attrBuff + src, dInfo.glineByte);
+ lmove(flagBuff + dst, flagBuff + src, dInfo.glineByte);
+ llatch(flagBuff + dst, dInfo.glineByte);
+ }
+ TextClearBand(top, top + line - 1);
+}
+
+void TextMoveUp(int top, int btm, int line)
+{
+ u_int n, src, dst;
+
+ if (btm - top - line + 1 <= 0) {
+ TextClearBand(top, btm);
+ return;
+ }
+ for (n = top; n <= btm - line; n ++) {
+ dst = TextAddress(0, n);
+ src = TextAddress(0, n + line);
+ lmove(textBuff + dst, textBuff + src, dInfo.glineByte);
+ lmove(attrBuff + dst, attrBuff + src, dInfo.glineByte);
+ lmove(flagBuff + dst, flagBuff + src, dInfo.glineByte);
+ llatch(flagBuff + dst, dInfo.glineByte);
+ }
+ TextClearBand(btm - line + 1, btm);
+}
+
+void ScrollUp(int line)
+{
+ if (useHardScroll && !con.soft) {
+ TextScrollUp(line);
+ scrollLine += line;
+ } else
+ TextMoveUp(con.ymin, con.ymax, line);
+}
+
+void ScrollDown(int line)
+{
+ if (useHardScroll && !con.soft) {
+ TextScrollDown(line);
+ scrollLine -= line;
+ } else
+ TextMoveDown(con.ymin, con.ymax, line);
+}
+
+static inline void KanjiAdjust(int *x, int *y)
+{
+ if (IsKanji2(*x, *y)) {
+ --*x;
+ }
+}
+
+void TextReverse(int fx, int fy, int tx, int ty)
+{
+ u_int from, to, y, swp, xx, x;
+ u_char fc, bc, fc2, bc2;
+
+ KanjiAdjust(&fx, &fy);
+ KanjiAdjust(&tx, &ty);
+ if (fy > ty) {
+ swp = fy;
+ fy = ty;
+ ty = swp;
+ swp = fx;
+ fx = tx;
+ tx = swp;
+ } else if (fy == ty && fx > tx) {
+ swp = fx;
+ fx = tx;
+ tx = swp;
+ }
+ for (xx = dInfo.txmax, y = fy; y <= ty; y ++) {
+ if (y == ty) xx = tx;
+ from = TextAddress(fx, y);
+ to = TextAddress(xx, y);
+ if (flagBuff[from] & CODEIS_2)
+ /* 2nd byte of kanji */
+ from--;
+ for (x = from; x <= to; x ++) {
+ if (!textBuff[x]) continue;
+ fc = attrBuff[x];
+ bc = fc >> 4;
+ bc2 = (bc & 8) | (fc & 7);
+ fc2 = (fc & 8) | (bc & 7);
+ attrBuff[x] = fc2 | (bc2 << 4);
+ flagBuff[x] &= ~CLEAN_S;
+ }
+ fx = 0;
+ }
+}
+
+#ifndef MINI_KON
+
+void TextCopy(int fx, int fy, int tx, int ty)
+{
+ int fd;
+ u_int from, to, y, swp, xx, x;
+ u_char ch, ch2;
+
+ unlink(KON_TMP_FILE);
+ if ((fd = open(KON_TMP_FILE, O_WRONLY|O_CREAT, 0600)) < 0) return;
+
+ KanjiAdjust(&fx, &fy);
+ KanjiAdjust(&tx, &ty);
+ if (fy > ty) {
+ swp = fy;
+ fy = ty;
+ ty = swp;
+ swp = fx;
+ fx = tx;
+ tx = swp;
+ } else if (fy == ty && fx > tx) {
+ swp = fx;
+ fx = tx;
+ tx = swp;
+ }
+ for (xx = dInfo.txmax, y = fy; y <= ty; y ++) {
+ if (y == ty) xx = tx;
+ from = TextAddress(fx, y);
+ if (flagBuff[from] & CODEIS_2)
+ /* 2nd byte of kanji */
+ from--;
+ to = TextAddress(xx, y);
+ for (x = to; x >= from; x --) if (textBuff[x] > ' ') break;
+ to = x;
+ for (x = from; x <= to; x ++) {
+ ch = textBuff[x];
+ if (!ch) ch = ' ';
+ if (flagBuff[x] & CODEIS_1) {
+ x ++;
+ ch2 = textBuff[x];
+ switch(lInfo.sc) {
+ case CODE_EUC:
+ ch2 |= 0x80;
+ ch |= 0x80;
+ break;
+ case CODE_SJIS:
+ jistosjis(ch2, ch);
+ break;
+ }
+ write(fd, &ch2, 1);
+ write(fd, &ch, 1);
+ } else write(fd, &ch, 1);
+ }
+ if (y < ty) {
+ ch = '\n';
+ write(fd, &ch, 1);
+ }
+ fx = 0;
+ }
+ close(fd);
+}
+
+void TextPaste(void)
+{
+ u_char ch;
+ int fd;
+
+ if ((fd = open(KON_TMP_FILE, O_RDONLY)) < 0) return;
+ while(read(fd, &ch, 1) == 1) write(masterPty, &ch, 1);
+ close(fd);
+}
+
+#endif
+
+/* Cursor related routines. */
+
+static void ToggleCursor(struct cursorInfo *c)
+{
+ c->count = 0;
+ if (con.text_mode)
+ return;
+ c->shown = ! c->shown;
+ vInfo.cursor(c);
+}
+
+static void ShowCursor(struct cursorInfo *c, bool show)
+{
+ if (!con.active || !c->sw)
+ return;
+ if (c->shown != show)
+ ToggleCursor(c);
+}
+
+static void SaveScreen(bool save)
+{
+ if (saved != save) {
+ saved = save;
+ vInfo.screen_saver(save);
+ }
+ saverCount = 0;
+}
+
+#ifndef MINI_KON
+static void PollMouseCursor(void)
+{
+ ShowCursor(&mouseCursor, FALSE);
+ if (mInfo.sw > 0) {
+ --mInfo.sw;
+ if (cInfo.shown) {
+ int x = mInfo.x, y = mInfo.y;
+
+ KanjiAdjust(&x, &y);
+ mouseCursor.kanji = IsKanji(x, y);
+ vInfo.set_cursor_address(&mouseCursor, x, y);
+ ShowCursor(&mouseCursor, TRUE);
+ }
+ }
+}
+#endif
+
+/* Called when some action was over, or every 1/10 sec when idle. */
+
+void PollCursor(bool wakeup)
+{
+ if (!con.active)
+ return;
+ if (wakeup) {
+ SaveScreen(FALSE);
+ ShowCursor(&cInfo, TRUE);
+#ifndef MINI_KON
+ PollMouseCursor();
+#endif
+ return;
+ }
+ /* Idle. */
+ if (saved)
+ return;
+ if ((saveTime > 0) && (++saverCount == saveTime)) {
+ ShowCursor(&cInfo, FALSE);
+#ifndef MINI_KON
+ ShowCursor(&mouseCursor, FALSE);
+#endif
+ SaveScreen(TRUE);
+ return;
+ }
+ if ((cInfo.interval > 0) && (++cInfo.count == cInfo.interval)) {
+ ToggleCursor(&cInfo);
+ }
+#ifndef MINI_KON
+ if (mInfo.has_mouse) {
+ PollMouseCursor();
+ }
+#endif
+}
+
+/* Configuration routines. */
+
+extern int SvgaSetVideoType(struct videoInfo*, const char*);
+extern int VgaFmSetVideoType(struct videoInfo*, const char*);
+extern int S3SetVideoType(struct videoInfo*, const char*);
+extern int J31SXSetVideoType(struct videoInfo*, const char*);
+
+static struct videoconf {
+ const char *name;
+ int (*set)(struct videoInfo*, const char*);
+} videos[] = {
+#ifdef HAS_VGA
+ {"VGA", SvgaSetVideoType},
+#ifndef MINI_KON
+ {"VGAFM", VgaFmSetVideoType},
+ {"EGA", SvgaSetVideoType},
+ {"SVGA", SvgaSetVideoType},
+#endif
+#endif
+#ifdef HAS_S3
+ {"S3", S3SetVideoType},
+#endif
+#ifdef HAS_J31SX
+ {"J3100SX", J31SXSetVideoType},
+#endif
+ {NULL, NULL}
+};
+
+static int ConfigHardScroll(const char *confstr)
+{
+ bool value = BoolConf(confstr);
+ useHardScroll = value;
+ if (value) {
+ message("hardware scroll mode.\r\n");
+ }
+ return SUCCESS;
+}
+
+static char *videoName;
+
+static int ConfigDisplay(const char *config)
+{
+ struct videoconf *v;
+ char name[MAX_COLS];
+
+ sscanf(config, "%s", name);
+ for (v = videos; v->name != NULL; v++) {
+ if (strcasecmp(name, v->name) == 0) {
+ config = strchr(config, '\n');
+ if (config == NULL) {
+ error("invalid entry for %s\r\n", videoName);
+ return FAILURE;
+ }
+ if (v->set(&vInfo, config) == FAILURE)
+ return FAILURE;
+ message("video type `%s' selected\r\n", name);
+ if (vInfo.has_hard_scroll) {
+ DefineCap("HardScroll", ConfigHardScroll, "On");
+ } else
+ useHardScroll = FALSE;
+ return SUCCESS;
+ }
+ }
+ error("unknown video type `%s'\r\n", name);
+ return FAILURE;
+}
+
+/* Beep routines. */
+
+#define COUNTER_ADDR 0x61
+
+static int beepCount;
+
+static int ConfigBeep(const char *confstr)
+{
+ beepCount = atoi(confstr) * 10000;
+#if defined(linux)
+ if (beepCount > 0)
+ ioperm(COUNTER_ADDR, 1, TRUE);
+#endif
+ return SUCCESS;
+}
+
+void Beep(void)
+{
+ if (!con.active || beepCount <= 0) return;
+#if defined(linux)
+ PortOutb(PortInb(COUNTER_ADDR)|3, COUNTER_ADDR);
+ usleep(beepCount);
+ PortOutb(PortInb(COUNTER_ADDR)&0xFC, COUNTER_ADDR);
+#endif
+}
+
+static int ConfigInterval(const char *confstr)
+{
+ cInfo.interval = atoi(confstr);
+#ifndef MINI_KON
+ mouseCursor.interval = cInfo.interval;
+#endif
+ return SUCCESS;
+}
+
+static int ConfigSaver(const char *confstr)
+{
+ saveTime = atoi(confstr) * 600; /* convert unit from minitue to 1/10 sec */
+ return SUCCESS;
+}
+
+/* Initialize routine. */
+
+void ConsoleInit(const char *video)
+{
+ videoName = strdup(video);
+ DefineCap(videoName, ConfigDisplay, NULL);
+ DefineCap("BeepCounter", ConfigBeep, "5");
+ DefineCap("CursorInterval", ConfigInterval, "4");
+ DefineCap("SaveTime", ConfigSaver, "4");
+}
+
+void ConsoleStart(void)
+{
+ /* What to do if calloc failed? */
+ textBuff = (u_char *)calloc(dInfo.glineByte, dInfo.tymax + 1);
+ attrBuff = (u_char *)calloc(dInfo.glineByte, dInfo.tymax + 1);
+ flagBuff = (u_char *)calloc(dInfo.glineByte, dInfo.tymax + 1);
+ textSize = dInfo.glineByte * (dInfo.tymax + 1);
+ ioctl(0, KDSETMODE, KD_GRAPHICS);
+ ioctl(0, TIOCGWINSZ, &text_win);
+ vInfo.init();
+ cInfo.shown = FALSE;
+#ifndef MINI_KON
+ mouseCursor.shown = FALSE;
+ mouseCursor.sw = TRUE;
+#endif
+ saved = FALSE;
+ GraphMode();
+}
+
+void ConsoleCleanup(void)
+{
+ scrollLine = textHead = 0;
+ vInfo.detatch();
+ SafeFree((void **)&textBuff);
+ SafeFree((void **)&attrBuff);
+ SafeFree((void **)&flagBuff);
+#ifdef linux
+ ioperm(COUNTER_ADDR, 1, FALSE);
+#endif
+
+ SafeFree((void **)&videoName);
+}
diff --git a/loader/kon2/src/vt.c b/loader/kon2/src/vt.c
new file mode 100644
index 000000000..df019e33d
--- /dev/null
+++ b/loader/kon2/src/vt.c
@@ -0,0 +1,744 @@
+/*
+ * KON2 - Kanji ON Console -
+ * Copyright (C) 1992-1996 Takashi MANABE (manabe@papilio.tutics.tut.ac.jp)
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY TAKASHI MANABE ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE TERRENCE R. LAMBERT BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include <termios.h>
+#if defined(linux)
+#include <malloc.h>
+#elif defined(__FreeBSD__)
+#include <stdlib.h>
+#endif
+#include <sys/types.h>
+#include <sys/ioctl.h>
+
+#include <getcap.h>
+#include <defs.h>
+#include <term.h>
+#include <interface.h>
+#include <fnld.h>
+#include <vt.h>
+#include <vc.h>
+
+struct _con_info con;
+
+#define CHAR_NUL '\x00'
+#define CHAR_BEL '\x07'
+#define CHAR_BS '\x08'
+#define CHAR_HT '\x09'
+#define CHAR_LF '\x0A'
+#define CHAR_VT '\x0B'
+#define CHAR_FF '\x0C'
+#define CHAR_CR '\x0D'
+#define CHAR_SO '\x0E'
+#define CHAR_SI '\x0F'
+#define CHAR_XON '\x11'
+#define CHAR_XOFF '\x12'
+#define CHAR_CAN '\x18'
+#define CHAR_SUB '\x1A'
+#define CHAR_ESC '\x1B'
+#define CHAR_DEL '\x7F'
+#define CHAR_CSI '\x9B'
+#define CHAR_SS2 '\x8E'
+
+#define LEN_REPORT 9
+
+struct attrStack {
+ struct attrStack *prev;
+ u_char x, y, attr, bcol, fcol;
+};
+
+static struct attrStack *saveAttr;
+
+static int scroll; /* スクロール行数 */
+struct langInfo lInfo;
+
+static void
+SaveAttr(struct attrStack **asp)
+{
+ struct attrStack *tmp;
+
+ tmp = (struct attrStack *)malloc(sizeof(struct attrStack));
+ if (!asp) {
+ if (saveAttr) tmp->prev = saveAttr;
+ else tmp->prev = NULL;
+ saveAttr = tmp;
+ } else *asp = tmp;
+ tmp->x = con.x;
+ tmp->y = con.y;
+ tmp->attr = con.attr;
+ tmp->fcol = con.fcol;
+ tmp->bcol = con.bcol;
+}
+
+static void
+RestoreAttr(struct attrStack *asp)
+{
+ if (!asp) {
+ if ((asp = saveAttr) == NULL) return;
+ saveAttr = asp->prev;
+ }
+ con.x = asp->x;
+ con.y = asp->y;
+ if (con.y < con.ymin) con.y = con.ymin;
+ if (con.y > con.ymax) con.y = con.ymax;
+ con.attr = asp->attr;
+ con.fcol = asp->fcol;
+ con.bcol = asp->bcol;
+ free(asp);
+}
+
+static void EscSetAttr(int col)
+{
+ static u_char table[] = {0, 4, 2, 6, 1, 5, 3, 7};
+ u_char swp;
+
+ switch(col) {
+ case 0: /* off all attributes */
+ con.bcol = 0;
+ con.fcol = 7;
+ con.attr = 0;
+ break;
+ case 1: /* highlight */
+ con.attr |= ATTR_HIGH;
+ if (con.fcol) con.fcol |= 8;
+ break;
+ case 21:
+ con.attr &= ~ATTR_HIGH;
+ con.fcol &= ~8;
+ break;
+ case 4: /* 下線 */
+ con.attr |= ATTR_ULINE;
+ con.bcol |= 8;
+ break;
+ case 24:
+ con.attr &= ~ATTR_ULINE;
+ con.bcol &= ~8;
+ break;
+ case 7: /* 反転 */
+ if (!(con.attr & ATTR_REVERSE)) {
+ con.attr |= ATTR_REVERSE;
+ swp = con.fcol & 7;
+ if (con.attr & ATTR_ULINE) swp |= 8;
+ con.fcol = con.bcol & 7;
+ if (con.attr & ATTR_HIGH && con.fcol) con.fcol |= 8;
+ con.bcol = swp;
+ }
+ break;
+ case 27:
+ if (con.attr & ATTR_REVERSE) {
+ con.attr &= ~ATTR_REVERSE;
+ swp = con.fcol & 7;
+ if (con.attr & ATTR_ULINE) swp |= 8;
+ con.fcol = con.bcol & 7;
+ if (con.attr & ATTR_HIGH && con.fcol) con.fcol |= 8;
+ con.bcol = swp;
+ }
+ break;
+ case 10:
+ if (con.trans == CS_GRAPH) con.trans = CS_LEFT;
+ break;
+ case 11:
+ con.trans = CS_GRAPH;
+ break;
+ default:
+ if (col >= 30 && col <= 37) {
+ swp = table[col - 30];
+ if (con.attr & ATTR_REVERSE) {
+ if (con.attr & ATTR_ULINE) swp |= 8;
+ con.bcol = swp;
+ } else {
+ if (con.attr & ATTR_HIGH) swp |= 8;
+ con.fcol = swp;
+ }
+ } else if (col >= 40 && col <= 47) {
+ swp = table[col - 40];
+ if (con.attr & ATTR_REVERSE) {
+ if (con.attr & ATTR_HIGH) swp |= 8;
+ con.fcol = swp;
+ } else {
+ if (con.attr & ATTR_ULINE) swp |= 8;
+ con.bcol = swp;
+ }
+ }
+ break;
+ }
+}
+
+static void VtSetMode(u_char mode, bool sw)
+{
+ switch(mode) {
+ case 4:
+ con.ins = sw;
+ break;
+ case 25:
+ cInfo.sw = sw;
+ break;
+ }
+}
+
+static void
+EscReport(u_char mode, u_short arg)
+{
+ static char report[LEN_REPORT];
+
+ switch(mode) {
+ case 'n':
+ if (arg == 6) {
+ int x = (con.x < con.xmax) ? con.x : con.xmax;
+ int y = (con.y < con.ymax) ? con.y : con.ymax;
+ sprintf(report, "\x1B[%d;%dR", y + 1, x + 1);
+ } else if (arg == 5)
+ strcpy(report, "\x1B[0n\0");
+ break;
+ case 'c':
+ if (arg == 0) strcpy(report, "\x1B[?6c\0");
+ break;
+ }
+ write(masterPty, report, strlen(report));
+}
+
+static void
+SetRegion(int ymin, int ymax)
+{
+ con.ymin = ymin;
+ con.ymax = ymax;
+ con.x = 0;
+ if (con.y < con.ymin || con.y > con.ymax) con.y = con.ymin;
+ con.wrap = FALSE;
+ if (con.ymin || con.ymax != dInfo.tymax)
+ con.soft = TRUE;
+ else
+ con.soft = FALSE;
+}
+
+void
+SetWinSize()
+{
+ struct winsize win;
+
+ win.ws_row = con.ymax + 1;
+ win.ws_col = dInfo.txmax + 1;
+ win.ws_xpixel = win.ws_ypixel = 0;
+ ioctl(masterPty, TIOCSWINSZ, &win);
+}
+
+static void
+EscStatusLine(u_char mode)
+{
+ static void EscBracket(u_char);
+ static struct attrStack *asp;
+
+ switch(mode) {
+ case 'T': /* To */
+ if (con.sl == SL_ENTER) break;
+ if (!asp) SaveAttr(&asp);
+ case 'S': /* Show */
+ if (con.sl == SL_NONE) {
+ con.ymax = dInfo.tymax - 1;
+ SetWinSize();
+ }
+ if (mode == 'T') {
+ con.sl = SL_ENTER;
+ SetRegion(dInfo.tymax, dInfo.tymax);
+ }
+ break;
+ case 'F': /* From */
+ if (con.sl == SL_ENTER) {
+ con.sl = SL_LEAVE;
+ SetRegion(0, dInfo.tymax - 1);
+ if (asp) RestoreAttr(asp);
+ asp = NULL;
+ }
+ break;
+ case 'H': /* Hide */
+ case 'E': /* Erase */
+ if (con.sl == SL_NONE) break;
+ SetRegion(0, dInfo.tymax);
+ SetWinSize();
+ con.sl = SL_NONE;
+ break;
+ default:
+ con.esc = EscBracket;
+ EscBracket(mode);
+ return;
+ }
+ con.wrap = FALSE;
+ con.esc = NULL;
+}
+
+#define MAX_NARG 8
+
+static void
+EscBracket(u_char ch)
+{
+ u_char n;
+ static u_short varg[MAX_NARG], narg, question;
+
+ if (ch >= '0' && ch <= '9') {
+ varg[narg] = (varg[narg] * 10) + (ch - '0');
+ } else if (ch == ';') {
+ /* 引数は MAX_NARG までしかサポートしない!! */
+ if (narg < MAX_NARG) {
+ narg ++;
+ varg[narg] = 0;
+ } else con.esc = NULL;
+ } else {
+ con.esc = NULL;
+ switch(ch) {
+ case 'K':
+ TextClearEol(varg[0]);
+ break;
+ case 'J':
+ TextClearEos(varg[0]);
+ break;
+ case 'A':
+ con.y -= varg[0] ? varg[0]: 1;
+ if (con.y < con.ymin) {
+ scroll -= con.y - con.ymin;
+ con.y = con.ymin;
+ }
+ break;
+ case 'B':
+ con.y += varg[0] ? varg[0]: 1;
+ if (con.y > con.ymax) {
+ scroll += con.y - con.ymin;
+ con.y = con.ymax;
+ }
+ break;
+ case 'C':
+ con.x += varg[0] ? varg[0]: 1;
+ con.wrap = FALSE;
+ break;
+ case 'D':
+ con.x -= varg[0] ? varg[0]: 1;
+ con.wrap = FALSE;
+ break;
+ case 'G':
+ con.x = varg[0] ? varg[0] - 1: 0;
+ con.wrap = FALSE;
+ break;
+ case 'P':
+ TextDeleteChar(varg[0] ? varg[0]: 1);
+ break;
+ case '@':
+ TextInsertChar(varg[0] ? varg[0]: 1);
+ break;
+ case 'L':
+ TextMoveDown(con.y, con.ymax,
+ varg[0] ? varg[0] : 1);
+ break;
+ case 'M':
+ TextMoveUp(con.y, con.ymax,
+ varg[0] ? varg[0] : 1);
+ break;
+ case 'H':
+ case 'f':
+ if (varg[1]) con.x = varg[1] - 1;
+ else con.x = 0;
+ con.wrap = FALSE;
+ case 'd':
+ con.y = varg[0] ? varg[0] - 1: 0;
+ break;
+ case 'm':
+ for (n = 0; n <= narg; n ++)
+ EscSetAttr(varg[n]);
+ break;
+ case 'r':
+ n = varg[1] ? (varg[1] - 1): dInfo.tymax;
+ if (con.sl != SL_NONE) {
+ if (n == dInfo.tymax) n --;
+ }
+ SetRegion(varg[0] ? (varg[0] - 1): 0, n);
+ break;
+ case 'l':
+ for (n = 0; n <= narg; n ++)
+ VtSetMode(varg[n], FALSE);
+ break;
+ case 'h':
+ for (n = 0; n <= narg; n ++)
+ VtSetMode(varg[n], TRUE);
+ break;
+ case '?':
+ con.esc = EscStatusLine;
+#if 0
+ question = TRUE;
+ con.esc = EscBracket;
+#endif
+ break;
+ case 's':
+ SaveAttr(NULL);
+ break;
+ case 'u':
+ RestoreAttr(NULL);
+ break;
+ case 'n':
+ case 'c':
+ if (question != TRUE)
+ EscReport(ch, varg[0]);
+ break;
+ case 'R':
+ break;
+ }
+ if (con.esc == NULL)
+ question = narg = varg[0] = varg[1] = 0;
+ }
+}
+
+static
+ void EscSetDCodeG0(u_char ch)
+{
+ int i;
+
+ switch(ch) {
+ case '(': /* EscSetDCodeG0 */
+ case ')': /* EscSetDCodeG1 */
+ return;
+ case '@':
+ ch = 'B';
+ default:
+ i = 0;
+ while (fDRegs[i].sign0) {
+#if 0
+{FILE *fp=fopen("errlog", "a");
+fprintf(fp,"[%d %c %s]\n", i, ch, fDRegs[i].registry);
+fclose(fp);}
+#endif
+ if (fDRegs[i].sign0 == ch) {
+ con.db = (u_char)i|LATCH_1;
+ break;
+ }
+ i ++;
+ }
+ con.trans = CS_DBCS;
+ break;
+ }
+ con.esc = NULL;
+}
+
+static
+ void EscSetSCodeG0(u_char ch)
+{
+ int i=0;
+
+ switch(ch) {
+ case '0':
+ con.g[0] = CS_GRAPH;
+ break;
+ case 'U':
+ con.g[0] = CS_GRAPH;
+ break;
+ default:
+ while (fSRegs[i].sign0) {
+ if (fSRegs[i].sign0 == ch) {
+ con.sb = (u_char)i;
+ con.g[0] = CS_LEFT;
+ break;
+ } else if (fSRegs[i].sign1 == ch) {
+ con.sb = (u_char)i;
+ con.g[0] = CS_RIGHT;
+ break;
+ }
+ i ++;
+ }
+ }
+ con.trans = con.g[0];
+ con.esc = NULL;
+}
+
+static
+ void EscSetSCodeG1(u_char ch)
+{
+ switch(ch) {
+ case 'U':
+ con.g[1] = CS_LEFT;
+ break;
+ case '0':
+ con.g[1] = CS_GRAPH;
+ break;
+ case 'A':
+ case 'J':
+ case 'B':
+ break;
+ }
+ con.trans = con.g[1];
+ con.esc = NULL;
+}
+
+static
+ void EscStart(u_char ch)
+{
+ con.esc = NULL;
+ switch(ch) {
+ case '[':
+ con.esc = EscBracket;
+ break;
+ case '$':/* Set Double Byte Code */
+ con.esc = EscSetDCodeG0;
+ break;
+ case '(':/* Set 94 to G0 */
+ case ',':/* Set 96 to G0 */
+ con.esc = EscSetSCodeG0;
+ break;
+ case ')':/* Set G1 */
+ con.esc = EscSetSCodeG1;
+ break;
+ case 'E':
+ con.x = 0;
+ con.wrap = FALSE;
+ case 'D':
+ if (con.y == con.ymax) scroll ++;
+ else con.y ++;
+ break;
+ case 'M':
+ if (con.y == con.ymin) scroll --;
+ else con.y --;
+ break;
+ case 'c':
+ con.fcol = 7;
+ con.attr = 0;
+ con.knj1 = con.bcol = 0;
+ con.wrap = FALSE;
+ con.trans = CS_LEFT;
+ con.sb = lInfo.sb;
+ con.db = lInfo.db|LATCH_1;
+ case '*':
+ con.x = con.y = 0;
+ con.wrap = FALSE;
+ TextClearAll();
+ break;
+ case '7':
+ SaveAttr(NULL);
+ break;
+ case '8':
+ RestoreAttr(NULL);
+ con.wrap = FALSE;
+ break;
+ }
+}
+
+static inline
+ bool iskanji(u_char c)
+{
+ switch(lInfo.sc) {
+ case CODE_SJIS:
+ return (c >=0x81 && c<=0x9F) || (c >=0xE0 && c <=0xFC);
+ default:
+ return (c & 0x80);
+ }
+}
+
+void VtEmu(const char *buff, int nchars)
+{
+ u_char ch;
+
+#if 0
+ {
+ FILE *fff;
+ fff = fopen("esc.log", "a");
+ fwrite(buff, nchars, 1, fff);
+ fclose(fff);
+ }
+#endif
+
+ while (nchars-- > 0) {
+ ch = *buff;
+ buff ++;
+ if (! ch)
+ continue;
+ if (con.esc) {
+ con.esc(ch);
+ } else switch (ch) {
+ case CHAR_BEL:
+ Beep();
+ break;
+ case CHAR_DEL:
+ break;
+ case CHAR_BS:
+ if (con.x) con.x --;
+ con.wrap = FALSE;
+ break;
+ case CHAR_HT:
+ con.x += con.tab - (con.x % con.tab);
+ con.wrap = FALSE;
+ if (con.x > con.xmax) con.x -= con.xmax + 1;
+ else break;
+ case CHAR_VT:
+ case CHAR_FF:
+#if 1
+ con.trans = CS_LEFT;
+ con.sb = lInfo.sb;
+ con.db = lInfo.db|LATCH_1;
+#endif
+ case CHAR_LF:
+ con.wrap = FALSE;
+/* if (con.sl != SL_ENTER) {*/
+ if (con.y == con.ymax) scroll ++;
+ else con.y ++;
+/* }*/
+ break;
+ case CHAR_CR:
+ con.x = 0;
+ con.wrap = FALSE;
+ break;
+ case CHAR_ESC:
+ con.esc = EscStart;
+ continue;
+ case CHAR_SO:
+ con.trans = con.g[1] | G1_SET;
+ continue;
+ case CHAR_SI:
+ con.trans = con.g[0];
+ continue;
+/* case ' ': con.trans = CS_LEFT;*/
+ default:
+ if (con.x == con.xmax + 1) {
+ con.wrap = TRUE;
+ con.x --;
+ }
+ if (con.wrap) {
+ con.x -= con.xmax;
+/* if (con.sl != SL_ENTER) {*/
+ if (con.y == con.ymax) scroll ++;
+ else con.y ++;
+/* }*/
+ con.wrap = FALSE;
+ buff --;
+ nchars ++;
+ break;
+ }
+ if (con.knj1) {
+ /* 第 2 漢字モード */
+ if (con.knj1 & 0x80) switch(lInfo.sc) {
+ case CODE_EUC:
+ if (con.knj1 == (u_char)CHAR_SS2) {
+ /* handling 'kata-kana' */
+ if (con.ins) TextInsertChar(1);
+ TextSput(ch);
+ con.x ++;
+ con.knj1 = 0;
+ continue;
+ }
+ con.knj1 &= 0x7F;
+ ch &= 0x7F;
+ break;
+ case CODE_SJIS:
+ sjistojis(con.knj1, ch);
+ break;
+ } else {
+ if (con.db == (DF_BIG5_0|LATCH_1))
+ muletobig5(con.db, con.knj1, ch);
+ }
+ if (con.ins) TextInsertChar(2);
+ TextWput(con.knj1, ch);
+ con.x += 2;
+ con.knj1 = 0;
+ continue;
+ } else if (con.trans == CS_DBCS
+ || (iskanji(ch) && con.trans == CS_LEFT)) {
+ /* 第 1 漢字モード */
+ if (con.x == con.xmax) con.wrap = TRUE;
+ con.knj1 = ch;
+ continue;
+ } else {
+ /* ANK モード */
+ if (con.ins) TextInsertChar(1);
+ TextSput(con.trans == CS_RIGHT ? ch | 0x80: ch);
+ con.x ++;
+ continue;
+ }
+ }
+ if (scroll > 0) {
+ ScrollUp(scroll);
+ } else if (scroll < 0) {
+ ScrollDown(- scroll);
+ }
+ scroll = 0;
+ }
+ if (con.x == con.xmax + 1) {
+ con.wrap = TRUE;
+ con.x --;
+ }
+}
+
+static int ConfigCoding(const char *confstr)
+{
+ char reg[3][MAX_COLS];
+ int n, i;
+
+ *reg[0] = *reg[1] = *reg[2] = '\0';
+ sscanf(confstr, "%s %s %s", reg[0], reg[1], reg[2]);
+ for (i = 0; i < 3 && *reg[i]; i ++) {
+ n = (int)CodingByRegistry(reg[i]);
+ if (n < 0) {
+ if (!strcasecmp(reg[i], "EUC"))
+ lInfo.sc = CODE_EUC;
+ else if (!strcasecmp(reg[i], "SJIS"))
+ lInfo.sc = CODE_SJIS;
+/*
+ else if (!strcasecmp(reg[i], "BIG5"))
+ lInfo.sc = CODE_BIG5;
+*/
+ else
+ lInfo.sc = 0;
+ } else if (n & CHR_DBC)
+ lInfo.db = n & ~CHR_DFLD;
+ else
+ lInfo.sb = n & ~CHR_SFLD;
+#if 0
+{FILE *fp=fopen("errlog", "a");
+fprintf(fp,"[<%s> %d %d %d %d]\n", reg[i], n, lInfo.sb, lInfo.db, lInfo.sc);
+fclose(fp);}
+#endif
+ }
+ return SUCCESS;
+}
+
+void VtInit(void)
+{
+ con.text_mode = TRUE;
+ DefineCap("Coding", ConfigCoding,
+ "JISX0201.1976-0 JISX0208.1983-0 EUCJ");
+}
+
+void VtStart(void)
+{
+ /* xmax, ymax は kon.cfg を読んだ後でないと分からない。*/
+ con.x = con.y = 0;
+ con.xmax = dInfo.txmax;
+ con.ymax = dInfo.tymax;
+ con.tab = 8;
+ con.fcol = 7;
+ con.attr = 0;
+ con.esc = NULL;
+ con.g[0] = con.g[1] = CS_LEFT;
+ con.trans = con.soft = con.ins = con.wrap = FALSE;
+ con.sb = lInfo.sb;
+ con.db = lInfo.db|LATCH_1;
+ con.active = cInfo.sw = TRUE;
+}
diff --git a/loader/kon2/termcap.kon b/loader/kon2/termcap.kon
new file mode 100644
index 000000000..cadba2ca8
--- /dev/null
+++ b/loader/kon2/termcap.kon
@@ -0,0 +1,19 @@
+kon|kanji on console:\
+ :am:eo:mi:ms:ut:xn:xo:\
+ :co#80:it#8:li#25:\
+ :&7=^Z:@7=\E[4~:AL=\E[%dL:DC=\E[%dP:DL=\E[%dM:\
+ :F1=\E[23~:F2=\E[24~:F3=\E[25~:F4=\E[26~:F5=\E[28~:\
+ :F6=\E[29~:F7=\E[31~:F8=\E[32~:F9=\E[33~:FA=\E[34~:\
+ :IC=\E[%d@:K2=\E[G:al=\E[L:bl=^G:cd=\E[J:ce=\E[K:\
+ :ch=\E[%i%dG:cl=\E[H\E[J:cm=\E[%i%d;%dH:cr=^M:\
+ :cs=\E[%i%d;%dr:ct=\E[3g:cv=\E[%i%dd:dc=\E[P:dl=\E[M:\
+ :do=^J:ei=\E[4l:ho=\E[H:ic=\E[@:im=\E[4h:k1=\E[[A:\
+ :k2=\E[[B:k3=\E[[C:k4=\E[[D:k5=\E[[E:k6=\E[17~:\
+ :k7=\E[18~:k8=\E[19~:k9=\E[20~:k;=\E[21~:kB=\E[Z:\
+ :kD=\E[3~:kI=\E[2~:kN=\E[6~:kP=\E[5~:kb=^H:kd=\E[B:\
+ :kh=\E[1~:kl=\E[D:kr=\E[C:ku=\E[A:le=^H:mr=\E[7m:\
+ :nd=\E[C:nw=^M^J:r1=\Ec:rc=\E8:sc=\E7:sf=^J:sr=\EM:\
+ :st=\EH:ta=^I:u6=\E[%i%d;%dR:u7=\E[6n:u8=\E[?6c:\
+ :u9=\E[c:up=\E[A:vb=200\E[?5h\E[?5l:ve=\E[?25h:\
+ :vi=\E[?25l:tc=klone+sgr:tc=klone+color:\
+ :hs:es:ts=\E[?T:fs=\E[?F:ds=\E[?H\E[?E:
diff --git a/loader/kon2/terminfo.kon b/loader/kon2/terminfo.kon
new file mode 100644
index 000000000..b51d75e69
--- /dev/null
+++ b/loader/kon2/terminfo.kon
@@ -0,0 +1,32 @@
+kon|kanji on console,
+ am, bce, ccc, eo, mir, msgr, xenl, xon,
+ colors#8, cols#80, it#8, lines#25, ncv#3, pairs#64,
+ acsc=`\004a\261f\370g\361h\260j\331k\277l\332m\300n\305o~q\304r\362s_t\303u\264v\301w\302x\263y\371z\372{\373|\374}\375~\376.\031-\030\054\021+^P0\333p\304r\304y\363z\362{\343|\330}\234,
+ bel=^G, blink=\E[5m, bold=\E[1m, civis=\E[?25l,
+ clear=\E[H\E[J, cnorm=\E[?25h, cr=^M,
+ csr=\E[%i%p1%d;%p2%dr, cub1=^H, cud1=^J, cuf1=\E[C,
+ cup=\E[%i%p1%d;%p2%dH, cuu1=\E[A, dch=\E[%p1%dP,
+ dch1=\E[P, dim=\E[2m, dl=\E[%p1%dM, dl1=\E[M,
+ ed=\E[J, el=\E[K, flash=\E[?5h\E[?5l$<200/>,
+ home=\E[H, hpa=\E[%i%p1%dG, ht=^I, hts=\EH,
+ ich=\E[%p1%d@, ich1=\E[@, il=\E[%p1%dL, il1=\E[L,
+ ind=^J, initc=\E]P%p1%x%p2%02x%p3%02x%p4%02x,
+ invis=\E[8m, kb2=\E[G, kbs=\177, kcbt=\E[Z,
+ kcub1=\E[D, kcud1=\E[B, kcuf1=\E[C, kcuu1=\E[A,
+ kdch1=\E[3~, kend=\E[4~, kf1=\E[[A, kf10=\E[21~,
+ kf11=\E[23~, kf12=\E[24~, kf13=\E[25~, kf14=\E[26~,
+ kf15=\E[28~, kf16=\E[29~, kf17=\E[31~, kf18=\E[32~,
+ kf19=\E[33~, kf2=\E[[B, kf20=\E[34~, kf3=\E[[C,
+ kf4=\E[[D, kf5=\E[[E, kf6=\E[17~, kf7=\E[18~,
+ kf8=\E[19~, kf9=\E[20~, khome=\E[1~, kich1=\E[2~,
+ knp=\E[6~, kpp=\E[5~, kspd=^Z, nel=^M^J, oc=\E]R,
+ op=\E[m, rc=\E8, rev=\E[7m, ri=\EM, rmacs=\E[10m,
+ rmir=\E[4l, rmpch=\E[10m, rmso=\E[m, rmul=\E[24m,
+ rs1=\Ec, sc=\E7, setab=\E[4%p1%dm,
+ setaf=\E[3%p1%dm, setb=\E[%p1%{40}%+%dm,
+ setf=\E[%p1%{30}%+%dm,
+ sgr=\E[0;10%?%p1%t;7%;%?%p2%t;4%;%?%p3%t;7%;%?%p4%t;5%;%?%p5%t;2%;%?%p6%t;1%;%?%p7%t;8%;%?%p9%t;11%;m,
+ sgr0=\E[0;10m, smacs=\E[11m, smir=\E[4h,
+ smpch=\E[11m, smso=\E[7m, smul=\E[4m, tbc=\E[3g,
+ u6=\E[%i%d;%dR, u7=\E[6n, u8=\E[?6c, u9=\E[c,
+ vpa=\E[%i%p1%dd, hs, eslok, tsl=\E[?T, fsl=\E[?F, dsl=\E[?H\E[?E,
diff --git a/loader/kon2/tools/Configure.FreeBSD b/loader/kon2/tools/Configure.FreeBSD
new file mode 100755
index 000000000..94d19b5e9
--- /dev/null
+++ b/loader/kon2/tools/Configure.FreeBSD
@@ -0,0 +1,108 @@
+#! /bin/sh
+
+CONFIG_H=include/config.h
+CONFIG_IN=config.in.FreeBSD
+CONFIG_OUT=config.out
+CONFIG_MK=.config
+
+#if [ -f config.org ]
+#then
+# echo -n >$CONFIG_OUT
+#else
+# mv config.in config.org
+#fi
+
+echo -n >$CONFIG_OUT
+
+cat << 'END' > $CONFIG_H
+
+/*
+ * KON2 - Kanji ON Console -
+ * Copyright (C) 1992, 1993 MAEDA Atusi (mad@math.keio.ac.jp)
+ * Copyright (C) 1992-1996 Takashi MANABE (manabe@papilio.tutics.tut.ac.jp)
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY TAKASHI MANABE ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE TERRENCE R. LAMBERT BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+/*
+ NOTE: This is automatically generated config.
+ >>>>>>>>>>>>>> DO NOT EDIT !! <<<<<<<<<<<<<<
+*/
+
+#ifndef CONFIG_H
+#define CONFIG_H
+
+END
+
+cat << 'END' > $CONFIG_MK
+
+TOPDIR = /usr/local
+BINDIR = $(TOPDIR)/bin
+LIBDIR = $(TOPDIR)/etc
+MANDIR = $(TOPDIR)/man/ja_JP.EUC/man1
+CONFIG_NAME = kon.cfg
+CFLAGS += -DCONFIG_NAME=\"$(LIBDIR)/$(CONFIG_NAME)\"
+
+END
+
+echo "KON Kanji ON FreeBSD console"
+
+while read mess
+do
+ echo $mess >>$CONFIG_OUT
+ echo >>$CONFIG_H
+ echo '/*' $mess '*/' >>$CONFIG_H
+ read sig def
+ echo -n $mess '['$def']? '
+ read ans < /dev/tty
+ if [ "$ans" = "" ]
+ then
+ ans=$def
+ fi
+ echo $sig $ans >>$CONFIG_OUT
+ if [ "$def" != "y" -a "$def" != "n" ]
+ then
+ if [ "$sig" = "SELECTION" ]
+ then
+ echo "#define" $ans >>$CONFIG_H
+ else
+ echo $expr >>$CONFIG_OUT
+ echo -n "#define "$sig" " >>$CONFIG_H
+ fi
+ else
+ if [ "$ans" = "y" ]
+ then
+ echo "#define" $sig >>$CONFIG_H
+ echo $sig" = "$sig >>$CONFIG_MK
+ fi
+ fi
+ prep=$ans
+done
+
+#mv config.out config.in
+
+echo "#endif" >>$CONFIG_H
+
+cat << 'END'
+
+END
diff --git a/loader/kon2/tools/Configure.linux b/loader/kon2/tools/Configure.linux
new file mode 100755
index 000000000..153a05bba
--- /dev/null
+++ b/loader/kon2/tools/Configure.linux
@@ -0,0 +1,119 @@
+#! /bin/sh
+
+CONFIG_H=include/config.h
+CONFIG_IN=config.in.linux
+CONFIG_OUT=config.out
+CONFIG_MK=.config
+
+#if [ -f config.org ]
+#then
+# echo -n >$CONFIG_OUT
+#else
+# mv config.in config.org
+#fi
+echo -n >$CONFIG_OUT
+
+cat << 'END' > $CONFIG_H
+
+/*
+ * KON2 - Kanji ON Console -
+ * Copyright (C) 1992, 1993 MAEDA Atusi (mad@math.keio.ac.jp)
+ * Copyright (C) 1992-1996 Takashi MANABE (manabe@papilio.tutics.tut.ac.jp)
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY TAKASHI MANABE ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE TERRENCE R. LAMBERT BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+/*
+ NOTE: This is automatically generated config.
+ >>>>>>>>>>>>>> DO NOT EDIT !! <<<<<<<<<<<<<<
+*/
+
+#ifndef CONFIG_H
+#define CONFIG_H
+
+END
+
+echo "INCDIR = "`pwd`/include > $CONFIG_MK
+echo "LIB = "`pwd`/lib/libgon.a >> $CONFIG_MK
+
+cat << 'END' >> $CONFIG_MK
+
+TOPDIR =
+BINDIR = $(TOPDIR)/usr/bin
+LIBDIR = $(TOPDIR)/etc
+MANDIR = $(TOPDIR)/usr/man/ja_JP.ujis/man1
+CONFIG_NAME = kon.cfg
+OPTS = -DCONFIG_NAME=\"$(LIBDIR)/$(CONFIG_NAME)\" -I$(INCDIR)
+CFLAGS = -O2 -Wall $(OPTS)
+LD = gcc $(CFLAGS)
+RM = rm -f
+INSTALL = install -c -s
+
+END
+
+echo "KON Kanji ON Linux console"
+
+while read mess
+do
+ echo $mess >>$CONFIG_OUT
+ echo >>$CONFIG_H
+ echo '/*' $mess '*/' >>$CONFIG_H
+ read sig def
+ echo -n $mess '['$def']? '
+ read ans < /dev/tty
+ if [ "$ans" = "" ]
+ then
+ ans=$def
+ fi
+ echo $sig $ans >>$CONFIG_OUT
+ if [ "$def" != "y" -a "$def" != "n" ]
+ then
+ if [ "$sig" = "SELECTION" ]
+ then
+ echo "#define" $ans >>$CONFIG_H
+ else
+ echo $expr >>$CONFIG_OUT
+ echo -n "#define "$sig" " >>$CONFIG_H
+ fi
+ else
+ if [ "$ans" = "y" ]
+ then
+ echo "#define" $sig >>$CONFIG_H
+ echo $sig" = "$sig >>$CONFIG_MK
+ fi
+ fi
+ prep=$ans
+done
+
+#mv config.out config.in
+
+echo "#endif" >>$CONFIG_H
+
+cat << 'END' >> $CONFIG_H
+
+#ifdef MINI_KON
+#undef USE_ROMFONT
+#define USE_ROMFONT
+#endif
+
+END
diff --git a/loader/kon2/tools/Makefile b/loader/kon2/tools/Makefile
new file mode 100644
index 000000000..9b7ebd83e
--- /dev/null
+++ b/loader/kon2/tools/Makefile
@@ -0,0 +1,37 @@
+TOOLS = swkon rel newvc mkminifont
+SRCS = swkon.c rel.c newvc.c mkminifont.c
+
+ifeq (../.config,$(wildcard ../.config))
+include ../.config
+endif
+
+ifdef SYSLOG_K
+SYSTOOLS = syslogk
+SYSSRCS = syslogk.c
+SYSDIR = $(TOPDIR)/etc
+endif
+CC:=$(CC) -g
+
+LDFLAGS = -N
+LOADLIBES = $(LIB)
+
+all: $(TOOLS) $(SYSTOOLS)
+
+depend .depend:
+ $(CC) $(CFLAGS) -M $(SRCS) $(SYSSRCS) > .depend
+
+clean:
+ $(RM) -f *.o $(TOOLS) $(SYSTOOLS) *~ .depend
+
+install: all
+ $(INSTALL) swkon $(BINDIR)
+ $(INSTALL) -m 4755 newvc $(BINDIR)
+ifdef SYSLOG_K
+ $(INSTALL) $(SYSTOOLS) $(SYSDIR)
+endif
+
+swkon: $(LIB)
+
+ifeq (.depend,$(wildcard .depend))
+include .depend
+endif
diff --git a/loader/kon2/tools/logto.c b/loader/kon2/tools/logto.c
new file mode 100644
index 000000000..d3abf4875
--- /dev/null
+++ b/loader/kon2/tools/logto.c
@@ -0,0 +1,40 @@
+#define LOGTO_C
+#include <stdio.h>
+#include <limits.h>
+#include <sys/stat.h>
+#include <sys/socket.h>
+
+#include <interface.h>
+
+void main(argc, argv)
+int argc;
+char *argv[];
+{
+ int s, len;
+ char name[_POSIX_PATH_MAX], path[_POSIX_PATH_MAX];
+
+ if ((s = SocketClientOpen()) == -1) {
+ fprintf(stderr, "%s> connect fail.\n", argv[0]);
+ exit(EOF);
+ }
+ if (argc < 2) {
+ len = 0;
+ } else {
+ getcwd(path, _POSIX_PATH_MAX);
+ sprintf(name, "%s/%s", path, argv[1]);
+ len = strlen(name) + 1;
+ }
+ SocketSendStr(s, STR_LOGTO);
+ if (SocketRecCtrl(s) != CHR_ACK) {
+ fprintf(stderr, "%s> no answer.\n", argv[0]);
+ exit(EOF);
+ }
+ if (SocketSendData((void *)&len, sizeof(int), s) == EOF) {
+ fprintf(stderr, "%s> data length send error.\n", argv[0]);
+ exit(EOF);
+ }
+ if (SocketSendData(name, len, s) == EOF) {
+ fprintf(stderr, "%s> data send error.\n", argv[0]);
+ exit(EOF);
+ }
+}
diff --git a/loader/kon2/tools/makedir b/loader/kon2/tools/makedir
new file mode 100755
index 000000000..54812e5c5
--- /dev/null
+++ b/loader/kon2/tools/makedir
@@ -0,0 +1,11 @@
+#!/bin/sh
+
+echo -n 'checking' $1 '...'
+
+if [ -d $1 ]
+then
+ echo 'ok'
+else
+ echo ' not exist'
+ mkdir -p $1
+fi
diff --git a/loader/kon2/tools/minifont.list b/loader/kon2/tools/minifont.list
new file mode 100644
index 000000000..c89ac9da0
--- /dev/null
+++ b/loader/kon2/tools/minifont.list
@@ -0,0 +1,2526 @@
+ 
+、
+。
+,
+.
+・
+:
+;
+?
+!
+゛
+゜
+`
+^
+ ̄
+_
+ヽ
+ヾ
+ゝ
+ゞ
+〃
+仝
+々
+〆
+〇
+ー
+―
+‐
+/
+\
+〜
+‖
+|
+…
+‥
+‘
+’
+“
+”
+(
+)
+〔
+〕
+[
+]
+{
+}
+〈
+〉
+《
+》
+「
+」
+『
+』
+【
+】
++
+−
+=
+≠
+<
+>
+≦
+≧
+∞
+∴
+♂
+♀
+′
+″
+℃
+¥
+$
+%
+#
+&
+*
+@
+☆
+★
+○
+●
+◎
+◇
+◆
+□
+■
+△
+▲
+▽
+▼
+※
+〒
+→
+←
+↑
+↓
+〓
+∈
+∋
+⊆
+⊇
+⊂
+⊃
+∪
+∩
+∧
+∨
+⇒
+⇔
+∀
+∃
+∠
+⊥
+⌒
+∂
+∇
+≡
+≒
+≪
+≫
+√
+∽
+∝
+∵
+∫
+∬
+Å
+‰
+♯
+♭
+♪
+†
+‡
+◯
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+0
+1
+2
+3
+4
+5
+6
+7
+8
+9
+A
+B
+C
+D
+E
+F
+G
+H
+I
+J
+K
+L
+M
+N
+O
+P
+Q
+R
+S
+T
+U
+V
+W
+X
+Y
+Z
+a
+b
+c
+d
+e
+f
+g
+h
+i
+j
+k
+l
+m
+n
+o
+p
+q
+r
+s
+t
+u
+v
+w
+x
+y
+z
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ぁ
+あ
+ぃ
+い
+ぅ
+う
+ぇ
+え
+ぉ
+お
+か
+が
+き
+ぎ
+く
+ぐ
+け
+げ
+こ
+ご
+さ
+ざ
+し
+じ
+す
+ず
+せ
+ぜ
+そ
+ぞ
+た
+だ
+ち
+ぢ
+っ
+つ
+づ
+て
+で
+と
+ど
+な
+に
+ぬ
+ね
+の
+は
+ば
+ぱ
+ひ
+び
+ぴ
+ふ
+ぶ
+ぷ
+へ
+べ
+ぺ
+ほ
+ぼ
+ぽ
+ま
+み
+む
+め
+も
+ゃ
+や
+ゅ
+ゆ
+ょ
+よ
+ら
+り
+る
+れ
+ろ
+ゎ
+わ
+ゐ
+ゑ
+を
+ん
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ァ
+ア
+ィ
+イ
+ゥ
+ウ
+ェ
+エ
+ォ
+オ
+カ
+ガ
+キ
+ギ
+ク
+グ
+ケ
+ゲ
+コ
+ゴ
+サ
+ザ
+シ
+ジ
+ス
+ズ
+セ
+ゼ
+ソ
+ゾ
+タ
+ダ
+チ
+ヂ
+ッ
+ツ
+ヅ
+テ
+デ
+ト
+ド
+ナ
+ニ
+ヌ
+ネ
+ノ
+ハ
+バ
+パ
+ヒ
+ビ
+ピ
+フ
+ブ
+プ
+ヘ
+ベ
+ペ
+ホ
+ボ
+ポ
+マ
+ミ
+ム
+メ
+モ
+ャ
+ヤ
+ュ
+ユ
+ョ
+ヨ
+ラ
+リ
+ル
+レ
+ロ
+ヮ
+ワ
+ヰ
+ヱ
+ヲ
+ン
+ヴ
+ヵ
+ヶ
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ο
+п
+亜
+哀
+愛
+悪
+握
+圧
+扱
+安
+暗
+案
+以
+位
+依
+偉
+囲
+委
+威
+尉
+意
+慰
+易
+為
+異
+移
+維
+緯
+胃
+衣
+違
+遺
+医
+井
+域
+育
+一
+壱
+逸
+稲
+芋
+印
+員
+因
+姻
+引
+飲
+院
+陰
+隠
+韻
+右
+宇
+羽
+雨
+渦
+浦
+運
+雲
+営
+影
+映
+栄
+永
+泳
+英
+衛
+詠
+鋭
+液
+疫
+益
+駅
+悦
+謁
+越
+閲
+円
+園
+宴
+延
+援
+沿
+演
+炎
+煙
+猿
+縁
+遠
+鉛
+塩
+汚
+凹
+央
+奥
+往
+応
+押
+横
+欧
+殴
+王
+翁
+黄
+沖
+億
+屋
+憶
+乙
+卸
+恩
+温
+穏
+音
+下
+化
+仮
+何
+価
+佳
+加
+可
+夏
+嫁
+家
+寡
+科
+暇
+果
+架
+歌
+河
+火
+禍
+稼
+箇
+花
+荷
+華
+菓
+課
+貨
+過
+蚊
+我
+画
+芽
+賀
+雅
+餓
+介
+会
+解
+回
+塊
+壊
+快
+怪
+悔
+懐
+戒
+拐
+改
+械
+海
+灰
+界
+皆
+絵
+開
+階
+貝
+劾
+外
+害
+慨
+概
+涯
+街
+該
+垣
+嚇
+各
+拡
+格
+核
+殻
+獲
+確
+穫
+覚
+角
+較
+郭
+閣
+隔
+革
+学
+岳
+楽
+額
+掛
+潟
+割
+喝
+括
+活
+渇
+滑
+褐
+轄
+且
+株
+刈
+乾
+冠
+寒
+刊
+勘
+勧
+巻
+喚
+堪
+完
+官
+寛
+干
+幹
+患
+感
+慣
+憾
+換
+敢
+棺
+款
+歓
+汗
+漢
+環
+甘
+監
+看
+管
+簡
+緩
+缶
+肝
+艦
+観
+貫
+還
+鑑
+間
+閑
+関
+陥
+館
+丸
+含
+岸
+眼
+岩
+頑
+顔
+願
+企
+危
+喜
+器
+基
+奇
+寄
+岐
+希
+幾
+忌
+揮
+机
+旗
+既
+期
+棋
+棄
+機
+帰
+気
+汽
+祈
+季
+紀
+規
+記
+貴
+起
+軌
+輝
+飢
+騎
+鬼
+偽
+儀
+宜
+戯
+技
+擬
+欺
+犠
+疑
+義
+議
+菊
+吉
+喫
+詰
+却
+客
+脚
+虐
+逆
+丘
+久
+休
+及
+吸
+宮
+弓
+急
+救
+朽
+求
+泣
+球
+究
+窮
+級
+糾
+給
+旧
+牛
+去
+居
+巨
+拒
+拠
+挙
+虚
+許
+距
+漁
+魚
+享
+京
+供
+競
+共
+凶
+協
+叫
+境
+峡
+強
+恐
+恭
+挟
+教
+橋
+況
+狂
+狭
+矯
+胸
+脅
+興
+郷
+鏡
+響
+驚
+仰
+凝
+暁
+業
+局
+曲
+極
+玉
+勤
+均
+斤
+琴
+禁
+筋
+緊
+菌
+襟
+謹
+近
+金
+吟
+銀
+九
+句
+区
+苦
+駆
+具
+愚
+虞
+空
+偶
+遇
+隅
+屈
+掘
+靴
+繰
+桑
+勲
+君
+薫
+訓
+群
+軍
+郡
+係
+傾
+刑
+兄
+啓
+型
+契
+形
+径
+恵
+慶
+憩
+掲
+携
+敬
+景
+渓
+系
+経
+継
+茎
+蛍
+計
+警
+軽
+鶏
+芸
+迎
+鯨
+劇
+撃
+激
+傑
+欠
+決
+潔
+穴
+結
+血
+月
+件
+倹
+健
+兼
+券
+剣
+圏
+堅
+嫌
+建
+憲
+懸
+検
+権
+犬
+献
+研
+絹
+県
+肩
+見
+謙
+賢
+軒
+遣
+険
+顕
+験
+元
+原
+厳
+幻
+弦
+減
+源
+玄
+現
+言
+限
+個
+古
+呼
+固
+孤
+己
+庫
+弧
+戸
+故
+枯
+湖
+誇
+雇
+顧
+鼓
+五
+互
+午
+呉
+娯
+後
+御
+悟
+碁
+語
+誤
+護
+交
+侯
+候
+光
+公
+功
+効
+厚
+口
+向
+后
+坑
+好
+孔
+孝
+工
+巧
+幸
+広
+康
+恒
+慌
+抗
+拘
+控
+攻
+更
+校
+構
+江
+洪
+港
+溝
+甲
+皇
+硬
+稿
+紅
+絞
+綱
+耕
+考
+肯
+航
+荒
+行
+衡
+講
+貢
+購
+郊
+酵
+鉱
+鋼
+降
+項
+香
+高
+剛
+号
+合
+拷
+豪
+克
+刻
+告
+国
+穀
+酷
+黒
+獄
+腰
+骨
+込
+今
+困
+墾
+婚
+恨
+懇
+昆
+根
+混
+紺
+魂
+佐
+唆
+左
+差
+査
+砂
+詐
+鎖
+座
+債
+催
+再
+最
+妻
+宰
+彩
+才
+採
+栽
+歳
+済
+災
+砕
+祭
+斎
+細
+菜
+裁
+載
+際
+剤
+在
+材
+罪
+財
+坂
+咲
+崎
+作
+削
+搾
+昨
+策
+索
+錯
+桜
+冊
+刷
+察
+撮
+擦
+札
+殺
+雑
+皿
+三
+傘
+参
+山
+惨
+散
+桟
+産
+算
+蚕
+賛
+酸
+暫
+残
+仕
+伺
+使
+刺
+司
+史
+嗣
+四
+士
+始
+姉
+姿
+子
+市
+師
+志
+思
+指
+支
+施
+旨
+枝
+止
+死
+氏
+祉
+私
+糸
+紙
+紫
+肢
+脂
+至
+視
+詞
+詩
+試
+誌
+諮
+資
+賜
+雌
+飼
+歯
+事
+似
+侍
+児
+字
+寺
+慈
+持
+時
+次
+滋
+治
+璽
+磁
+示
+耳
+自
+辞
+式
+識
+軸
+七
+執
+失
+室
+湿
+漆
+疾
+質
+実
+芝
+舎
+写
+射
+捨
+赦
+斜
+煮
+社
+者
+謝
+車
+遮
+蛇
+邪
+借
+勺
+尺
+爵
+酌
+釈
+若
+寂
+弱
+主
+取
+守
+手
+朱
+殊
+狩
+珠
+種
+趣
+酒
+首
+儒
+受
+寿
+授
+樹
+需
+囚
+収
+周
+宗
+就
+州
+修
+愁
+拾
+秀
+秋
+終
+習
+臭
+舟
+衆
+襲
+週
+酬
+集
+醜
+住
+充
+十
+従
+柔
+汁
+渋
+獣
+縦
+重
+銃
+叔
+宿
+淑
+祝
+縮
+粛
+塾
+熟
+出
+術
+述
+俊
+春
+瞬
+准
+循
+旬
+殉
+準
+潤
+盾
+純
+巡
+遵
+順
+処
+初
+所
+暑
+庶
+緒
+署
+書
+諸
+助
+叙
+女
+序
+徐
+除
+傷
+償
+勝
+匠
+升
+召
+商
+唱
+奨
+宵
+将
+小
+少
+尚
+床
+彰
+承
+抄
+招
+掌
+昇
+昭
+晶
+松
+沼
+消
+渉
+焼
+焦
+照
+症
+省
+硝
+礁
+祥
+称
+章
+笑
+粧
+紹
+肖
+衝
+訟
+証
+詔
+詳
+象
+賞
+鐘
+障
+上
+丈
+乗
+冗
+剰
+城
+場
+壌
+嬢
+常
+情
+条
+浄
+状
+畳
+蒸
+譲
+醸
+錠
+嘱
+飾
+植
+殖
+織
+職
+色
+触
+食
+辱
+伸
+信
+侵
+唇
+娠
+寝
+審
+心
+慎
+振
+新
+森
+浸
+深
+申
+真
+神
+紳
+臣
+薪
+親
+診
+身
+辛
+進
+針
+震
+人
+仁
+刃
+尋
+甚
+尽
+迅
+陣
+酢
+図
+吹
+垂
+帥
+推
+水
+炊
+睡
+粋
+衰
+遂
+酔
+錘
+随
+髄
+崇
+数
+枢
+据
+杉
+澄
+寸
+世
+瀬
+畝
+是
+制
+勢
+姓
+征
+性
+成
+政
+整
+星
+晴
+正
+清
+牲
+生
+盛
+精
+聖
+声
+製
+西
+誠
+誓
+請
+逝
+青
+静
+斉
+税
+隻
+席
+惜
+斥
+昔
+析
+石
+積
+籍
+績
+責
+赤
+跡
+切
+拙
+接
+摂
+折
+設
+窃
+節
+説
+雪
+絶
+舌
+仙
+先
+千
+占
+宣
+専
+川
+戦
+扇
+栓
+泉
+浅
+洗
+染
+潜
+旋
+線
+繊
+船
+薦
+践
+選
+遷
+銭
+銑
+鮮
+前
+善
+漸
+然
+全
+禅
+繕
+塑
+措
+疎
+礎
+祖
+租
+粗
+素
+組
+訴
+阻
+僧
+創
+双
+倉
+喪
+壮
+奏
+層
+想
+捜
+掃
+挿
+操
+早
+曹
+巣
+槽
+燥
+争
+相
+窓
+総
+草
+荘
+葬
+藻
+装
+走
+送
+遭
+霜
+騒
+像
+増
+憎
+臓
+蔵
+贈
+造
+促
+側
+則
+即
+息
+束
+測
+足
+速
+俗
+属
+賊
+族
+続
+卒
+存
+孫
+尊
+損
+村
+他
+多
+太
+堕
+妥
+惰
+打
+駄
+体
+対
+耐
+帯
+待
+怠
+態
+替
+泰
+滞
+胎
+袋
+貸
+退
+逮
+隊
+代
+台
+大
+第
+題
+滝
+卓
+宅
+択
+拓
+沢
+濯
+託
+濁
+諾
+但
+達
+奪
+脱
+棚
+谷
+丹
+単
+嘆
+担
+探
+淡
+炭
+短
+端
+胆
+誕
+鍛
+団
+壇
+弾
+断
+暖
+段
+男
+談
+値
+知
+地
+恥
+池
+痴
+稚
+置
+致
+遅
+築
+畜
+竹
+蓄
+逐
+秩
+窒
+茶
+嫡
+着
+中
+仲
+宙
+忠
+抽
+昼
+柱
+注
+虫
+衷
+鋳
+駐
+著
+貯
+丁
+兆
+帳
+庁
+弔
+張
+彫
+徴
+懲
+挑
+朝
+潮
+町
+眺
+聴
+脹
+腸
+調
+超
+跳
+長
+頂
+鳥
+勅
+直
+朕
+沈
+珍
+賃
+鎮
+陳
+津
+墜
+追
+痛
+通
+塚
+漬
+坪
+釣
+亭
+低
+停
+偵
+貞
+呈
+堤
+定
+帝
+底
+庭
+廷
+弟
+抵
+提
+程
+締
+艇
+訂
+逓
+邸
+泥
+摘
+敵
+滴
+的
+笛
+適
+哲
+徹
+撤
+迭
+鉄
+典
+天
+展
+店
+添
+転
+点
+伝
+殿
+田
+電
+吐
+塗
+徒
+斗
+渡
+登
+途
+都
+努
+度
+土
+奴
+怒
+倒
+党
+冬
+凍
+刀
+唐
+塔
+島
+悼
+投
+搭
+東
+桃
+棟
+盗
+湯
+灯
+当
+痘
+等
+答
+筒
+糖
+統
+到
+討
+謄
+豆
+踏
+逃
+透
+陶
+頭
+騰
+闘
+働
+動
+同
+堂
+導
+洞
+童
+胴
+道
+銅
+峠
+匿
+得
+徳
+特
+督
+篤
+毒
+独
+読
+凸
+突
+届
+屯
+豚
+曇
+鈍
+内
+縄
+南
+軟
+難
+二
+尼
+弐
+肉
+日
+乳
+入
+如
+尿
+任
+妊
+忍
+認
+寧
+猫
+熱
+年
+念
+燃
+粘
+悩
+濃
+納
+能
+脳
+農
+把
+覇
+波
+派
+破
+婆
+馬
+俳
+廃
+拝
+排
+敗
+杯
+背
+肺
+輩
+配
+倍
+培
+媒
+梅
+買
+売
+賠
+陪
+伯
+博
+拍
+泊
+白
+舶
+薄
+迫
+漠
+爆
+縛
+麦
+箱
+肌
+畑
+八
+鉢
+発
+髪
+伐
+罰
+抜
+閥
+伴
+判
+半
+反
+帆
+搬
+板
+版
+犯
+班
+畔
+繁
+般
+藩
+販
+範
+煩
+頒
+飯
+晩
+番
+盤
+蛮
+卑
+否
+妃
+彼
+悲
+扉
+批
+披
+比
+泌
+疲
+皮
+碑
+秘
+罷
+肥
+被
+費
+避
+非
+飛
+備
+尾
+微
+美
+鼻
+匹
+必
+筆
+姫
+百
+俵
+標
+氷
+漂
+票
+表
+評
+描
+病
+秒
+苗
+品
+浜
+貧
+賓
+頻
+敏
+瓶
+不
+付
+夫
+婦
+富
+布
+府
+怖
+扶
+敷
+普
+浮
+父
+符
+腐
+膚
+譜
+負
+賦
+赴
+附
+侮
+武
+舞
+部
+封
+風
+伏
+副
+復
+幅
+服
+福
+腹
+複
+覆
+払
+沸
+仏
+物
+分
+噴
+墳
+憤
+奮
+粉
+紛
+雰
+文
+聞
+丙
+併
+兵
+塀
+幣
+平
+弊
+柄
+並
+閉
+陛
+米
+壁
+癖
+別
+偏
+変
+片
+編
+辺
+返
+遍
+便
+勉
+弁
+保
+舗
+捕
+歩
+補
+穂
+募
+墓
+慕
+暮
+母
+簿
+倣
+俸
+包
+報
+奉
+宝
+峰
+崩
+抱
+放
+方
+法
+泡
+砲
+縫
+胞
+芳
+褒
+訪
+豊
+邦
+飽
+乏
+亡
+傍
+剖
+坊
+妨
+帽
+忘
+忙
+房
+暴
+望
+某
+棒
+冒
+紡
+肪
+膨
+謀
+貿
+防
+北
+僕
+墨
+撲
+朴
+牧
+没
+堀
+奔
+本
+翻
+凡
+盆
+摩
+磨
+魔
+麻
+埋
+妹
+枚
+毎
+幕
+膜
+又
+抹
+末
+繭
+万
+慢
+満
+漫
+味
+未
+魅
+岬
+密
+脈
+妙
+民
+眠
+務
+夢
+無
+矛
+霧
+婿
+娘
+名
+命
+明
+盟
+迷
+銘
+鳴
+滅
+免
+綿
+面
+模
+茂
+妄
+毛
+猛
+盲
+網
+耗
+木
+黙
+目
+戻
+問
+紋
+門
+匁
+夜
+野
+矢
+厄
+役
+約
+薬
+訳
+躍
+柳
+愉
+油
+癒
+諭
+輸
+唯
+優
+勇
+友
+幽
+悠
+憂
+有
+猶
+由
+裕
+誘
+遊
+郵
+雄
+融
+夕
+予
+余
+与
+誉
+預
+幼
+容
+庸
+揚
+揺
+擁
+曜
+様
+洋
+溶
+用
+窯
+羊
+葉
+要
+謡
+踊
+陽
+養
+抑
+欲
+浴
+翌
+翼
+羅
+裸
+来
+頼
+雷
+絡
+落
+酪
+乱
+卵
+欄
+濫
+覧
+利
+吏
+履
+理
+痢
+裏
+里
+離
+陸
+律
+率
+立
+略
+流
+留
+硫
+粒
+隆
+竜
+慮
+旅
+虜
+了
+僚
+両
+寮
+料
+涼
+猟
+療
+糧
+良
+量
+陵
+領
+力
+緑
+倫
+厘
+林
+臨
+輪
+隣
+塁
+涙
+累
+類
+令
+例
+冷
+励
+礼
+鈴
+隷
+零
+霊
+麗
+齢
+暦
+歴
+列
+劣
+烈
+裂
+廉
+恋
+練
+連
+錬
+炉
+路
+露
+労
+廊
+朗
+楼
+浪
+漏
+老
+郎
+六
+録
+論
+和
+話
+賄
+惑
+枠
+湾
+腕
diff --git a/loader/kon2/tools/mkminifont b/loader/kon2/tools/mkminifont
new file mode 100755
index 000000000..8609f3276
--- /dev/null
+++ b/loader/kon2/tools/mkminifont
Binary files differ
diff --git a/loader/kon2/tools/mkminifont.c b/loader/kon2/tools/mkminifont.c
new file mode 100644
index 000000000..f94b41a98
--- /dev/null
+++ b/loader/kon2/tools/mkminifont.c
@@ -0,0 +1,40 @@
+#include <stdio.h>
+#include <errno.h>
+#include <interface.h>
+#include <fnld.h>
+
+struct _fontent {
+ unsigned short code;
+ unsigned char bitmap[32];
+} fent[65535];
+
+void
+main()
+{
+ unsigned short code, max=0;
+ unsigned int fnt, i, num=0;
+ unsigned char line[10], *font, bytes, high;
+ struct fontInfo *fi;
+ struct fontRegs *freg=&fDRegs[1];
+
+ if ((font = GetShmem(1|CHR_DFLD)) == NULL) {
+ perror("GetShmem");
+ exit(-1);
+ }
+ fi = (struct fontInfo *)font;
+ high = fi->high;
+ bytes = sizeof(fent[0].code) + high * 2;
+ font += sizeof(struct fontInfo);
+ while (fgets(line, sizeof(line), stdin)) {
+ code = ((line[0] << 8) & 0x7F00) | (line[1] & 0x7F);
+ if (code > max) max = code;
+ fnt = freg->addr(line[0] & 0x7F, line[1] & 0x7F);
+ fent[num].code = code;
+ memcpy(fent[num].bitmap, font + fnt, 32);
+ num ++;
+ }
+ fwrite(&high, sizeof(high), 1, stdout);
+ fwrite(&max, sizeof(max), 1, stdout);
+ for (i = 0; i < num; i ++) if (fent[i].code)
+ fwrite(&fent[i], bytes, 1, stdout);
+}
diff --git a/loader/kon2/tools/newvc b/loader/kon2/tools/newvc
new file mode 100755
index 000000000..a64cf2122
--- /dev/null
+++ b/loader/kon2/tools/newvc
Binary files differ
diff --git a/loader/kon2/tools/newvc.c b/loader/kon2/tools/newvc.c
new file mode 100644
index 000000000..3b60e7e5f
--- /dev/null
+++ b/loader/kon2/tools/newvc.c
@@ -0,0 +1,167 @@
+/* Newvc - run a program in another virtual console */
+
+/* Copyright (C) 1992 by MAEDA Atusi (mad@math.keio.ac.jp) */
+/* Version 0.1 92/1/11 */
+/* Version 0.2 92/1/19 */
+
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <limits.h>
+#include <pwd.h>
+#include <utmp.h>
+#include <time.h>
+#include <sys/file.h>
+#include <sys/ioctl.h>
+#include <sys/kd.h>
+#include <sys/vt.h>
+#include <sys/wait.h>
+
+#define MAXTTYLEN 12
+
+#define MAXCMDLEN 4096
+
+char cmdBuf[MAXCMDLEN];
+
+char *progName;
+char newTtyName[MAXTTYLEN];
+
+void error(const char *message, const char *perrorMessage) {
+ fprintf(stderr, "%s: %s\n", progName, message);
+ if (perrorMessage) {
+ perror(perrorMessage);
+ }
+ exit(EXIT_FAILURE);
+}
+
+struct passwd *pw;
+struct utmp ut;
+
+void setUtmpEntry(int pid) {
+
+ pw = getpwuid(getuid());
+ setutent(); /* open utmp */
+ strncpy(ut.ut_id, newTtyName + strlen("/dev/tty"), sizeof(ut.ut_id));
+ ut.ut_type = DEAD_PROCESS;
+ getutid(&ut); /* set position */
+ /* Set up the new entry. */
+ ut.ut_type = USER_PROCESS;
+ strncpy(ut.ut_line, newTtyName + strlen("/dev/"), sizeof(ut.ut_line));
+ strncpy(ut.ut_user, (pw && pw->pw_name) ? pw->pw_name : "????",
+ sizeof(ut.ut_user));
+/*
+ gethostname(ut.ut_host, sizeof(ut.ut_host));
+*/
+ ut.ut_pid = pid;
+ ut.ut_time = time(NULL);
+ pututline(&ut);
+ endutent(); /* close utmp */
+}
+
+void restoreUtmpEntry(int pid) {
+ struct utmp *utp;
+
+ pw = getpwuid(getuid());
+ setutent(); /* open utmp */
+ strncpy(ut.ut_id, newTtyName + strlen("/dev/tty"), sizeof(ut.ut_id));
+ ut.ut_type = USER_PROCESS;
+ utp = getutid(&ut); /* search entry */
+ /* Set up the new entry. */
+ if (utp && utp->ut_pid == pid) {
+ ut.ut_type = DEAD_PROCESS;
+ ut.ut_time = time(NULL);
+ pututline(&ut);
+ }
+ endutent(); /* close utmp */
+}
+
+int main(int argc, char* argv[]) {
+ int curVcNum, newVcNum;
+ int consoleFd = 0;
+ int newVcFd;
+ int childPid;
+ struct vt_stat vts;
+
+ progName = argv[0];
+
+ if ((consoleFd = open("/dev/console", 0)) < 0) {
+ error("can't open console", "/dev/console");
+ }
+
+ ioctl(consoleFd, VT_GETSTATE, &vts);
+ curVcNum = vts.v_active;
+
+ ioctl(consoleFd, VT_OPENQRY, &newVcNum);
+ if (newVcNum < 0) {
+ error("can't find unused virtual console", NULL);
+ }
+ sprintf(newTtyName, "/dev/tty%d", newVcNum);
+
+ setsid();
+
+ if ((newVcFd = open(newTtyName, O_RDWR)) < 0) {
+ error("can't open virtual console", newTtyName);
+ }
+ if (ioctl(consoleFd, VT_ACTIVATE, newVcNum) != 0) {
+ error("can't switch virtual console", "ioctl VT_ACTIVATE");
+ }
+
+ dup2(newVcFd, 0);
+ dup2(newVcFd, 1);
+ dup2(newVcFd, 2);
+
+ if ((childPid = fork()) < 0) {
+ error("fork failed", "fork");
+ }
+ if (childPid) {
+ /* Parent process. */
+ int status;
+
+ setUtmpEntry(childPid);
+
+ wait(&status);
+
+ restoreUtmpEntry(childPid);
+
+ if (ioctl(0, VT_ACTIVATE, curVcNum) != 0) {
+ error("couldn't restore original console", "ioctl(0, VT_ACTIVATE)");
+ }
+ return WEXITSTATUS(status);
+ } else {
+ /* Child process. */
+ char *shell, *command;
+ char *newArgv[] = {"/bin/sh", "-c", cmdBuf, NULL};
+
+ setuid(getuid());
+ setgid(getgid());
+
+ if ((shell = getenv("SHELL")) == NULL) {
+ shell = "/bin/sh";
+ }
+ if (argc == 1) {
+ /* No command specified. Run shell as default. */
+ if ((command = rindex(shell, '/')) == NULL) {
+ command = shell;
+ } else {
+ command++;
+ }
+ newArgv[1] = NULL;
+ } else {
+ int i;
+
+ command = argv[1];
+ for (i = 1; i < argc; i++) {
+ strncat(cmdBuf, argv[i], MAXCMDLEN);
+ strncat(cmdBuf, " ", MAXCMDLEN);
+ }
+ }
+ newArgv[0] = command;
+
+ execv(shell, newArgv);
+
+ error("can't exec", shell);
+
+ return EXIT_FAILURE;
+ }
+}
diff --git a/loader/kon2/tools/rel b/loader/kon2/tools/rel
new file mode 100755
index 000000000..80e674c54
--- /dev/null
+++ b/loader/kon2/tools/rel
Binary files differ
diff --git a/loader/kon2/tools/rel.c b/loader/kon2/tools/rel.c
new file mode 100644
index 000000000..d5e8afd78
--- /dev/null
+++ b/loader/kon2/tools/rel.c
@@ -0,0 +1,18 @@
+#include <sys/types.h>
+#include <sys/kd.h>
+#include <sys/vt.h>
+#include <sys/ioctl.h>
+
+int main(void)
+{
+ struct vt_mode vtm;
+
+ ioctl(0, KDSETMODE, KD_TEXT);
+ vtm.mode = VT_AUTO;
+ vtm.waitv = 0;
+ vtm.relsig = 0;
+ vtm.acqsig = 0;
+ ioctl(0, VT_SETMODE, &vtm);
+
+ return 0;
+}
diff --git a/loader/kon2/tools/swkon.c b/loader/kon2/tools/swkon.c
new file mode 100644
index 000000000..d750e30a4
--- /dev/null
+++ b/loader/kon2/tools/swkon.c
@@ -0,0 +1,88 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <errno.h>
+#include <string.h>
+#include <ctype.h>
+#include <sys/stat.h>
+#include <sys/socket.h>
+#include <signal.h>
+
+#include <interface.h>
+
+const char *progName;
+
+int OpenSocket(void)
+{
+ int s;
+
+ if ((s = SocketClientOpen()) == -1) {
+ fprintf(stderr, "%s> connect fail.\n", progName);
+ exit(EXIT_FAILURE);
+ }
+ return s;
+}
+
+int WaitAck(int s)
+{
+ struct messageHeader mh;
+ bzero(&mh, sizeof(mh));
+ SocketRecCommand(s, &mh);
+ if (mh.cmd != CHR_ACK) {
+ fprintf(stderr, "%s> no answer.\n", progName);
+ return EXIT_FAILURE;
+ }
+ return EXIT_SUCCESS;
+}
+
+int ChangeMode(char cmd)
+{
+ int s = OpenSocket();
+ SocketSendCommand(s, cmd);
+ return WaitAck(s);
+}
+
+int ResetKon(int argc, const char *argv[])
+{
+ int s = OpenSocket();
+ int i, len;
+
+ SocketSendCommand(s, CHR_RESTART);
+ if (WaitAck(s) != EXIT_SUCCESS)
+ return EXIT_FAILURE;
+ write(s, &argc, sizeof(argc));
+ for (i = 0; i < argc; i++) {
+ len = strlen(argv[i]);
+ write(s, &len, sizeof(len));
+ write(s, argv[i], len);
+ }
+ return EXIT_SUCCESS;
+}
+
+void usage(void)
+{
+ fprintf(stderr, "usage:\n"
+ " %s -h|-help (print this help)\n"
+ " %s -t (switch to text mode)\n"
+ " %s -g (switch to graphics mode)\n"
+ " %s [video] [-capability value ...] (reset KON)\n",
+ progName, progName, progName, progName);
+}
+
+int main(int argc, const char *argv[])
+{
+ progName = argv[0];
+
+ if (argc == 2) {
+ if (strcasecmp(argv[1], "-h") == 0 || strcasecmp(argv[1], "-help") == 0) {
+ usage();
+ return EXIT_SUCCESS;
+ } else if (strcasecmp(argv[1], "-t") == 0)
+ return ChangeMode(CHR_TEXTMODE);
+ else if (strcasecmp(argv[1], "-g") == 0)
+ return ChangeMode(CHR_GRAPHMODE);
+ else if (strcasecmp(argv[1], "-s") == 0)
+ return ChangeMode(CHR_STAT);
+ }
+ return ResetKon(argc - 1, argv + 1);
+}