BASIC compiler/interpreter for PIC32MX/MZ-80K
Revisão | a49236372f3424b6661354cf8a866c5309e667a5 (tree) |
---|---|
Hora | 2019-02-24 16:10:53 |
Autor | Katsumi <kmorimatsu@sour...> |
Commiter | Katsumi |
Class CKNJ16
@@ -0,0 +1,169 @@ | ||
1 | +REM CKNJ16.BAS ver 0.1 | |
2 | +REM Class CKNJ16 for MachiKania Type Z/M | |
3 | +REM using Shinonome 16x16 font | |
4 | + | |
5 | +STATIC PRIVATE MODE,FBUFF,FO,PLT,BMPF | |
6 | + | |
7 | +METHOD INIT | |
8 | + REM File buffer size is 32 bytes | |
9 | + dim FBUFF(7) | |
10 | + REM 16x16 bytes matrix for PUTBMP | |
11 | + dim BMPF(63) | |
12 | + REM Set encoding | |
13 | + REM MODE: either "EUC-JP", or "UTF-8" | |
14 | + if 0<args(0) then | |
15 | + if 0=STRNCMP("EUC-JP",args$(1),7) then | |
16 | + MODE=1 | |
17 | + elseif 0=STRNCMP("UTF-8",args$(1),6) then | |
18 | + MODE=2 | |
19 | + else | |
20 | + print "Illegal encoding:";args$(1) | |
21 | + end | |
22 | + endif | |
23 | + else | |
24 | + REM Default: EUC-JP | |
25 | + MODE=1 | |
26 | + endif | |
27 | + return | |
28 | + | |
29 | +METHOD GPRT | |
30 | + var t$,b,i,j | |
31 | + fclose | |
32 | + FO=0 | |
33 | + REM Set palette | |
34 | + PLT=args(2)*256+args(3) | |
35 | + gosub GPSTR,args$(1) | |
36 | + fclose | |
37 | + return | |
38 | + | |
39 | +REM Private method GPRTCH | |
40 | +REM 1st param: JIS code # | |
41 | +LABEL GPRTCH | |
42 | + var i,x,y | |
43 | + REM Create BMP from font file | |
44 | + gosub FGETCH,args(1) | |
45 | + for y=0 to 15 | |
46 | + i=peek(FBUFF+y*2) | |
47 | + for x=0 to 7 | |
48 | + if i and (1<<(7-x)) then | |
49 | + poke BMPF+y*16+x,PLT>>8 | |
50 | + else | |
51 | + poke BMPF+y*16+x,PLT and 0xff | |
52 | + endif | |
53 | + next | |
54 | + i=peek(FBUFF+y*2+1) | |
55 | + for x=8 to 15 | |
56 | + if i and (1<<(15-x)) then | |
57 | + poke BMPF+y*16+x,PLT>>8 | |
58 | + else | |
59 | + poke BMPF+y*16+x,PLT and 0xff | |
60 | + endif | |
61 | + next | |
62 | + next | |
63 | + REM Draw in graphic | |
64 | + putbmp ,16,16,BMPF | |
65 | + point SYSTEM(28)+16,SYSTEM(29) | |
66 | + return | |
67 | + | |
68 | +REM Private medthod FGETCH | |
69 | +REM 1st param: JIS code # | |
70 | +LABEL FGETCH | |
71 | + var p | |
72 | + if 0=FO then | |
73 | + REM File isn't yet open | |
74 | + REM open it | |
75 | + FO=1 | |
76 | + if 2=MODE then | |
77 | + fopen "SINONOME.UNI","r" | |
78 | + else | |
79 | + fopen "SINONOME.JIS","r" | |
80 | + endif | |
81 | + endif | |
82 | + p=args(1) | |
83 | + if 2=MODE then | |
84 | + REM UTF-8 | |
85 | + if p<0x0500 then | |
86 | + p=p-0x500 | |
87 | + elseif p<0x2000 then | |
88 | + REM ERR | |
89 | + elseif p<0x2700 then | |
90 | + p=p-0x2000+0x0500 | |
91 | + elseif p<0x3000 then | |
92 | + REM ERR | |
93 | + elseif p<0x3100 then | |
94 | + p=p-0x3000+0x0c00 | |
95 | + elseif p<0x4e00 then | |
96 | + REM ERR | |
97 | + elseif p<0xa000 then | |
98 | + p=p-0x4e00+0x0d00 | |
99 | + elseif p<0xff00 then | |
100 | + REM ERR | |
101 | + else | |
102 | + p=p-0xff00+0x5f00 | |
103 | + endif | |
104 | + else | |
105 | + REM EUC | |
106 | + p=p-0xa1a1 | |
107 | + endif | |
108 | + fseek p*32 | |
109 | + fget FBUFF,32 | |
110 | + return | |
111 | + | |
112 | +REM Private method GPSTR | |
113 | +REM 1st param: JIS/EUC/UTF string | |
114 | +REM return: string with PCG set | |
115 | +LABEL GPSTR | |
116 | + t$="" | |
117 | + i=0 | |
118 | + if 1=MODE then | |
119 | + goto EUCSTR | |
120 | + elseif 2=MODE then | |
121 | + goto UTFSTR | |
122 | + else | |
123 | + goto EUCSTR | |
124 | + endif | |
125 | + | |
126 | +REM Private method EUCSTR | |
127 | +REM supports EUC-JP string | |
128 | +LABEL EUCSTR | |
129 | + while i<len(args$(1)) | |
130 | + b=peek(args(1)+i) | |
131 | + if 0xa0<b then | |
132 | + REM Detect Kanji | |
133 | + REM Get EUC code in var j | |
134 | + j=b*256+peek(args(1)+i+1) | |
135 | + i=i+2 | |
136 | + REM GPrint character | |
137 | + gosub GPRTCH,j | |
138 | + elseif 0x20<b then | |
139 | + REM 7 bit character | |
140 | + gosub GPRTCH,0xa3b0+b-0x30 | |
141 | + i=i+1 | |
142 | + endif | |
143 | + wend | |
144 | + return | |
145 | + | |
146 | +REM Private method UTFSTR | |
147 | +REM supports UTF-8 string | |
148 | +LABEL UTFSTR | |
149 | + while i<len(args$(1)) | |
150 | + b=peek(args(1)+i) | |
151 | + if 0xc0 = (0xe0 and b) then | |
152 | + REM Get Unicode in j | |
153 | + j=((b and 0x1f)<<6)+(peek(args(1)+i+1) and 0x3f) | |
154 | + i=i+2 | |
155 | + REM GPrint character | |
156 | + gosub GPRTCH,j | |
157 | + elseif 0xe0 = (0xf0 and b) then | |
158 | + REM Get Unicode in j | |
159 | + j=((b and 0x0f)<<12)+((peek(args(1)+i+1) and 0x3f)<<6)+(peek(args(1)+i+2) and 0x3f) | |
160 | + i=i+3 | |
161 | + REM GPrint character | |
162 | + gosub GPRTCH,j | |
163 | + elseif 0x20<b then | |
164 | + REM 7 bit character | |
165 | + gosub GPRTCH,0xff00+b-0x20 | |
166 | + i=i+1 | |
167 | + endif | |
168 | + wend | |
169 | + return |
@@ -0,0 +1,60 @@ | ||
1 | +<?php | |
2 | + | |
3 | +/* | |
4 | + | |
5 | + Binary font file generator for Misaki 8x8 font. | |
6 | + Place 'shnmk16.bdf' in the same directory and run this script. | |
7 | + The font file is used for EUC-JP. | |
8 | + On 2/23/2019, Shinonome font is available from: https://www.mgo-tec.com/kanji-font-shinonome | |
9 | + | |
10 | +*/ | |
11 | + | |
12 | +$tfile=file_get_contents('./shnmk16.bdf'); | |
13 | +$ftable=array(); | |
14 | +preg_replace_callback('/STARTCHAR[\s]+([0-9a-f]{4})[\s\S]*?(([0-9a-f]{4}[\s]+){16})/',function($m) use(&$ftable){ | |
15 | + /* JIS 0x3835: 元 */ | |
16 | + /* example: | |
17 | + STARTCHAR 3835 | |
18 | + ENCODING 14389 | |
19 | + SWIDTH 960 0 | |
20 | + DWIDTH 16 0 | |
21 | + BBX 16 16 0 -2 | |
22 | + BITMAP | |
23 | + 0000 | |
24 | + 0ff8 | |
25 | + 0000 | |
26 | + 0000 | |
27 | + 0000 | |
28 | + 0000 | |
29 | + 7fff | |
30 | + 0220 | |
31 | + 0220 | |
32 | + 0220 | |
33 | + 0220 | |
34 | + 0420 | |
35 | + 0420 | |
36 | + 0821 | |
37 | + 1011 | |
38 | + 200f | |
39 | + ENDCHAR | |
40 | + */ | |
41 | + $ftable[hexdec($m[1])]=preg_replace('/[\s]+/','',$m[2]); | |
42 | +},$tfile); | |
43 | +//print_r($ftable);exit; | |
44 | + | |
45 | +$result=''; | |
46 | +for($code=0x2121;$code<=0x7426;$code++){ | |
47 | + if (isset($ftable[$code])) { | |
48 | + for($i=0;$i<64;$i+=2){ | |
49 | + $b=substr($ftable[$code],$i,2); | |
50 | + $result.=chr(hexdec($b)); | |
51 | + } | |
52 | + } else { | |
53 | + $result.="\x00\x00\x00\x00\x00\x00\x00\x00"; | |
54 | + $result.="\x00\x00\x00\x00\x00\x00\x00\x00"; | |
55 | + $result.="\x00\x00\x00\x00\x00\x00\x00\x00"; | |
56 | + $result.="\x00\x00\x00\x00\x00\x00\x00\x00"; | |
57 | + } | |
58 | +} | |
59 | + | |
60 | +file_put_contents('./SINONOME.JIS',$result); |
@@ -0,0 +1,110 @@ | ||
1 | +<?php | |
2 | +/* | |
3 | + | |
4 | + Binary font file generator for Misaki 8x8 font. | |
5 | + Place 'shnmk16.bdf' in the same directory and run this script. | |
6 | + Place 'JIS0208.TXT' in the same directory and run this script. | |
7 | + The font file is used for UTF-8. | |
8 | + On 2/23/2019, Shinonome font is available from: https://www.mgo-tec.com/kanji-font-shinonome | |
9 | + Unicode - JIS table was obtained from: http://www.unicode.org/Public/MAPPINGS/OBSOLETE/EASTASIA/JIS/JIS0208.TXT | |
10 | + | |
11 | +*/ | |
12 | + | |
13 | +$tfile=file_get_contents('./shnmk16.bdf'); | |
14 | +$ftable=array(); | |
15 | +preg_replace_callback('/STARTCHAR[\s]+([0-9a-f]{4})[\s\S]*?(([0-9a-f]{4}[\s]+){16})/',function($m) use(&$ftable){ | |
16 | + /* JIS 0x3835: 元 */ | |
17 | + /* example: | |
18 | + STARTCHAR 3835 | |
19 | + ENCODING 14389 | |
20 | + SWIDTH 960 0 | |
21 | + DWIDTH 16 0 | |
22 | + BBX 16 16 0 -2 | |
23 | + BITMAP | |
24 | + 0000 | |
25 | + 0ff8 | |
26 | + 0000 | |
27 | + 0000 | |
28 | + 0000 | |
29 | + 0000 | |
30 | + 7fff | |
31 | + 0220 | |
32 | + 0220 | |
33 | + 0220 | |
34 | + 0220 | |
35 | + 0420 | |
36 | + 0420 | |
37 | + 0821 | |
38 | + 1011 | |
39 | + 200f | |
40 | + ENDCHAR | |
41 | + */ | |
42 | + $ftable[hexdec($m[1])]=preg_replace('/[\s]+/','',$m[2]); | |
43 | +},$tfile); | |
44 | +//print_r($ftable);exit; | |
45 | + | |
46 | +$tfile=file_get_contents('./JIS0208.TXT'); | |
47 | +$jtable=array(); | |
48 | +preg_replace_callback('/[\r\n]0x([0-9A-F]{4})[\s]+0x([0-9A-F]{4})[\s]+0x([0-9A-F]{4})/',function($m) use(&$jtable,&$ftable){ | |
49 | + // $m[1]: SJIS, $m[2]: JIS, $m[3]: UTF16 | |
50 | + if (isset($ftable[hexdec($m[2])])) { | |
51 | + $jtable[hexdec($m[3])]=$ftable[hexdec($m[2])]; | |
52 | + } | |
53 | +},$tfile); | |
54 | + | |
55 | +$result=''; | |
56 | +for($code=0x0000;$code<=0xffff;$code++){ | |
57 | + /* | |
58 | + Skip: | |
59 | + 0500 - 1fff | |
60 | + 2700 - 2fff | |
61 | + 3100 - 4dff | |
62 | + a000 - feff | |
63 | + Valid: | |
64 | + 0000 - 04ff (0500, total 0500) | |
65 | + 2000 - 26ff (0700, total 0c00) | |
66 | + 3000 - 30ff (0100, total 0d00) | |
67 | + 4e00 - 9fff (5200, total 5f00) | |
68 | + ff00 - ffff (0100, total 6000) | |
69 | + Therefore: | |
70 | + if P<0x0500 then | |
71 | + P=P-0x500 | |
72 | + elseif P<0x2000 then | |
73 | + REM ERR | |
74 | + elseif P<0x2700 then | |
75 | + P=P-0x2000+0x0500 | |
76 | + elseif P<0x3000 then | |
77 | + REM ERR | |
78 | + elseif P<0x3100 then | |
79 | + P=P-0x3000+0x0c00 | |
80 | + elseif P<0x4e00 then | |
81 | + REM ERR | |
82 | + elseif P<0xa000 then | |
83 | + P=P-0x4e00+0x0d00 | |
84 | + elseif P<0xff00 then | |
85 | + REM ERR | |
86 | + else | |
87 | + P=P-0xff00+0x5f00 | |
88 | + endif | |
89 | + */ | |
90 | + switch($code){ | |
91 | + case 0x0500: $code=0x2000; break; | |
92 | + case 0x2700: $code=0x3000; break; | |
93 | + case 0x3100: $code=0x4e00; break; | |
94 | + case 0xa000: $code=0xff00; break; | |
95 | + default: break; | |
96 | + } | |
97 | + if (isset($jtable[$code])) { | |
98 | + for($i=0;$i<64;$i+=2){ | |
99 | + $b=substr($jtable[$code],$i,2); | |
100 | + $result.=chr(hexdec($b)); | |
101 | + } | |
102 | + } else { | |
103 | + $result.="\x00\x00\x00\x00\x00\x00\x00\x00"; | |
104 | + $result.="\x00\x00\x00\x00\x00\x00\x00\x00"; | |
105 | + $result.="\x00\x00\x00\x00\x00\x00\x00\x00"; | |
106 | + $result.="\x00\x00\x00\x00\x00\x00\x00\x00"; | |
107 | + } | |
108 | +} | |
109 | +file_put_contents('./SINONOME.UNI',$result); | |
110 | + |
@@ -0,0 +1,45 @@ | ||
1 | +<クラス名およびバージョン> | |
2 | +CKNJ16 | |
3 | +ver 0.1 | |
4 | + | |
5 | +<ファイル名> | |
6 | +CKNJ16.BAS | |
7 | +SINONOME.JIS | |
8 | +SINONOME.UNI | |
9 | + | |
10 | +<概要> | |
11 | +日本語表示クラス。東雲フォント(16x16)を使用し、グラフィックディスプレイに日本語を | |
12 | +含む文字列を表示する。文字コードは、EUC-JP, UTF-8に対応。 | |
13 | + | |
14 | +<コンストラクター> | |
15 | +第1引数 | |
16 | + 文字コードとして、"EUC-JP", "UTF-8"のいずれかを選択。省略した場合は、 | |
17 | + "EUC-JP"。 | |
18 | + | |
19 | +<パブリックフィールド> | |
20 | +なし | |
21 | + | |
22 | +<パブリックメソッド> | |
23 | +GPRT(x$,y,z) | |
24 | + 日本語を含む文字列x$を、グラフィックディスプレイに表示する。yは文字色、zは | |
25 | + 背景色を指定。 | |
26 | + | |
27 | +<使用例> | |
28 | +テキストモードでの日本語表示例。この場合は、BASファイルをUTF-8(BOMなし)で保存す | |
29 | +る事。 | |
30 | + | |
31 | +USECLASS CKNJ16 | |
32 | +USEGRAPHIC | |
33 | +POINT 50,50 | |
34 | +K=new(CKNJ16,"UTF-8") | |
35 | +K.GPRT("本日は晴天なり",7,0) | |
36 | +A$=INPUT$() | |
37 | + | |
38 | +次のように使用する事も出来る。 | |
39 | + | |
40 | +USECLASS CKNJ16 | |
41 | +USEGRAPHIC | |
42 | +POINT 50,50 | |
43 | +CKNJ16::INIT("UTF-8") | |
44 | +CKNJ16::GPRT("本日は晴天なり",7,0) | |
45 | +A$=INPUT$() |