BASIC compiler/interpreter for PIC32MX/MZ-80K
Revision | 97b183d0ef6865a260d06dfd58c115092667294b (tree) |
---|---|
Zeit | 2019-02-25 14:20:38 |
Autor | Katsumi <kmorimatsu@sour...> |
Commiter | Katsumi |
New class, CKNJ12. CRLF for GPRT method. Error handling.
@@ -0,0 +1,200 @@ | ||
1 | +REM CKNJ16.BAS ver 0.1 | |
2 | +REM Class CKNJ12 for MachiKania Type Z/M | |
3 | +REM using Shinonome 12x12 font | |
4 | + | |
5 | +STATIC PRIVATE MODE,FBUFF,FO,PLT,BMPF | |
6 | + | |
7 | +METHOD INIT | |
8 | + REM File buffer size is 18 bytes | |
9 | + dim FBUFF(4) | |
10 | + REM 12x12 bytes matrix for PUTBMP | |
11 | + dim BMPF(35) | |
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 5 | |
46 | + i=peek(FBUFF+y*3) | |
47 | + for x=0 to 7 | |
48 | + if i and (1<<(7-x)) then | |
49 | + poke BMPF+y*24+x,PLT>>8 | |
50 | + else | |
51 | + poke BMPF+y*24+x,PLT and 0xff | |
52 | + endif | |
53 | + next | |
54 | + i=peek(FBUFF+y*3+1) | |
55 | + for x=8 to 11 | |
56 | + if i and (1<<(15-x)) then | |
57 | + poke BMPF+y*24+x,PLT>>8 | |
58 | + else | |
59 | + poke BMPF+y*24+x,PLT and 0xff | |
60 | + endif | |
61 | + next | |
62 | + for x=0 to 3 | |
63 | + if i and (1<<(3-x)) then | |
64 | + poke BMPF+(y*2+1)*12+x,PLT>>8 | |
65 | + else | |
66 | + poke BMPF+(y*2+1)*12+x,PLT and 0xff | |
67 | + endif | |
68 | + next | |
69 | + i=peek(FBUFF+y*3+2) | |
70 | + for x=4 to 11 | |
71 | + if i and (1<<(11-x)) then | |
72 | + poke BMPF+(y*2+1)*12+x,PLT>>8 | |
73 | + else | |
74 | + poke BMPF+(y*2+1)*12+x,PLT and 0xff | |
75 | + endif | |
76 | + next | |
77 | + next | |
78 | + REM Draw in graphic | |
79 | + x=SYSTEM(28) | |
80 | + y=SYSTEM(29) | |
81 | + putbmp x,y,12,12,BMPF | |
82 | + if x+24<SYSTEM(22) then | |
83 | + x=x+12 | |
84 | + else | |
85 | + x=0 | |
86 | + y=y+12 | |
87 | + endif | |
88 | + point x,y | |
89 | + return | |
90 | + | |
91 | +REM Private medthod FGETCH | |
92 | +REM 1st param: JIS code # | |
93 | +LABEL FGETCH | |
94 | + var p | |
95 | + if 0=FO then | |
96 | + REM File isn't yet open | |
97 | + REM open it | |
98 | + FO=1 | |
99 | + if 2=MODE then | |
100 | + fopen "SHNMK12.UNI","r" | |
101 | + else | |
102 | + fopen "SHNMK12.JIS","r" | |
103 | + endif | |
104 | + endif | |
105 | + p=args(1) | |
106 | + if 2=MODE then | |
107 | + REM UTF-8 | |
108 | + if p<0x0500 then | |
109 | + p=p-0x500 | |
110 | + elseif p<0x2000 then | |
111 | + REM ERR | |
112 | + p=-1 | |
113 | + elseif p<0x2700 then | |
114 | + p=p-0x2000+0x0500 | |
115 | + elseif p<0x3000 then | |
116 | + p=-1 | |
117 | + elseif p<0x3100 then | |
118 | + p=p-0x3000+0x0c00 | |
119 | + elseif p<0x4e00 then | |
120 | + p=-1 | |
121 | + elseif p<0xa000 then | |
122 | + p=p-0x4e00+0x0d00 | |
123 | + elseif p<0xff00 then | |
124 | + p=-1 | |
125 | + else | |
126 | + p=p-0xff00+0x5f00 | |
127 | + endif | |
128 | + else | |
129 | + REM EUC | |
130 | + p=p-0xa1a1 | |
131 | + endif | |
132 | + p=p*18 | |
133 | + if 0<=p and p+18<flen() then | |
134 | + fseek p | |
135 | + fget FBUFF,18 | |
136 | + else | |
137 | + for p=0 to 4 | |
138 | + FBUFF(p)=0 | |
139 | + next | |
140 | + endif | |
141 | + return | |
142 | + | |
143 | +REM Private method GPSTR | |
144 | +REM 1st param: JIS/EUC/UTF string | |
145 | +REM return: string with PCG set | |
146 | +LABEL GPSTR | |
147 | + t$="" | |
148 | + i=0 | |
149 | + if 1=MODE then | |
150 | + goto EUCSTR | |
151 | + elseif 2=MODE then | |
152 | + goto UTFSTR | |
153 | + else | |
154 | + goto EUCSTR | |
155 | + endif | |
156 | + | |
157 | +REM Private method EUCSTR | |
158 | +REM supports EUC-JP string | |
159 | +LABEL EUCSTR | |
160 | + while i<len(args$(1)) | |
161 | + b=peek(args(1)+i) | |
162 | + if 0xa0<b then | |
163 | + REM Detect Kanji | |
164 | + REM Get EUC code in var j | |
165 | + j=b*256+peek(args(1)+i+1) | |
166 | + i=i+2 | |
167 | + REM GPrint character | |
168 | + gosub GPRTCH,j | |
169 | + elseif 0x20<b then | |
170 | + REM 7 bit character | |
171 | + gosub GPRTCH,0xa3b0+b-0x30 | |
172 | + i=i+1 | |
173 | + endif | |
174 | + wend | |
175 | + return | |
176 | + | |
177 | +REM Private method UTFSTR | |
178 | +REM supports UTF-8 string | |
179 | +LABEL UTFSTR | |
180 | + while i<len(args$(1)) | |
181 | + b=peek(args(1)+i) | |
182 | + if 0xc0 = (0xe0 and b) then | |
183 | + REM Get Unicode in j | |
184 | + j=((b and 0x1f)<<6)+(peek(args(1)+i+1) and 0x3f) | |
185 | + i=i+2 | |
186 | + REM GPrint character | |
187 | + gosub GPRTCH,j | |
188 | + elseif 0xe0 = (0xf0 and b) then | |
189 | + REM Get Unicode in j | |
190 | + j=((b and 0x0f)<<12)+((peek(args(1)+i+1) and 0x3f)<<6)+(peek(args(1)+i+2) and 0x3f) | |
191 | + i=i+3 | |
192 | + REM GPrint character | |
193 | + gosub GPRTCH,j | |
194 | + elseif 0x20<b then | |
195 | + REM 7 bit character | |
196 | + gosub GPRTCH,0xff00+b-0x20 | |
197 | + i=i+1 | |
198 | + endif | |
199 | + wend | |
200 | + return |
@@ -0,0 +1,55 @@ | ||
1 | +<?php | |
2 | + | |
3 | +/* | |
4 | + | |
5 | + Binary font file generator for Shinonome 12x12 font. | |
6 | + Place 'shnmk12.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 not available from: http://openlab.ring.gr.jp/efont/shinonome/ | |
9 | + but archive is found from: https://web.archive.org/ | |
10 | + | |
11 | +*/ | |
12 | + | |
13 | +$tfile=file_get_contents('./shnmk12.bdf'); | |
14 | +$ftable=array(); | |
15 | +preg_replace_callback('/STARTCHAR[\s]+([0-9a-f]{4})[\s\S]*?(([0-9a-f]{4}[\s]+){12})/',function($m) use(&$ftable){ | |
16 | + /* JIS 0x3835: 元 */ | |
17 | + /* example: | |
18 | + STARTCHAR 3835 | |
19 | + ENCODING 14389 | |
20 | + SWIDTH 960 0 | |
21 | + DWIDTH 12 0 | |
22 | + BBX 12 12 0 -2 | |
23 | + BITMAP | |
24 | + 0000 | |
25 | + 1f80 | |
26 | + 0000 | |
27 | + 0000 | |
28 | + 7fe0 | |
29 | + 0900 | |
30 | + 0900 | |
31 | + 0900 | |
32 | + 1100 | |
33 | + 1120 | |
34 | + 2120 | |
35 | + 40e0 | |
36 | + ENDCHAR | |
37 | + */ | |
38 | + $ftable[hexdec($m[1])]=preg_replace('/([0-9a-f]{3})[0-9a-f][\s]+/','$1',$m[2]); | |
39 | +},$tfile); | |
40 | +//print_r($ftable);exit; | |
41 | + | |
42 | +$result=''; | |
43 | +for($code=0x2121;$code<=0x7426;$code++){ | |
44 | + if (isset($ftable[$code])) { | |
45 | + for($i=0;$i<36;$i+=2){ | |
46 | + $b=substr($ftable[$code],$i,2); | |
47 | + $result.=chr(hexdec($b)); | |
48 | + } | |
49 | + } else { | |
50 | + $result.="\x00\x00\x00\x00\x00\x00\x00\x00\x00"; | |
51 | + $result.="\x00\x00\x00\x00\x00\x00\x00\x00\x00"; | |
52 | + } | |
53 | +} | |
54 | + | |
55 | +file_put_contents('./SHNMK12.JIS',$result); |
@@ -0,0 +1,105 @@ | ||
1 | +<?php | |
2 | +/* | |
3 | + | |
4 | + Binary font file generator for Shinonome 12x12 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 not available from: http://openlab.ring.gr.jp/efont/shinonome/ | |
9 | + but archive is found from: https://web.archive.org/ | |
10 | + Unicode - JIS table was obtained from: http://www.unicode.org/Public/MAPPINGS/OBSOLETE/EASTASIA/JIS/JIS0208.TXT | |
11 | + | |
12 | +*/ | |
13 | + | |
14 | +$tfile=file_get_contents('./shnmk12.bdf'); | |
15 | +$ftable=array(); | |
16 | +preg_replace_callback('/STARTCHAR[\s]+([0-9a-f]{4})[\s\S]*?(([0-9a-f]{4}[\s]+){12})/',function($m) use(&$ftable){ | |
17 | + /* JIS 0x3835: 元 */ | |
18 | + /* example: | |
19 | + STARTCHAR 3835 | |
20 | + ENCODING 14389 | |
21 | + SWIDTH 960 0 | |
22 | + DWIDTH 12 0 | |
23 | + BBX 12 12 0 -2 | |
24 | + BITMAP | |
25 | + 0000 | |
26 | + 1f80 | |
27 | + 0000 | |
28 | + 0000 | |
29 | + 7fe0 | |
30 | + 0900 | |
31 | + 0900 | |
32 | + 0900 | |
33 | + 1100 | |
34 | + 1120 | |
35 | + 2120 | |
36 | + 40e0 | |
37 | + ENDCHAR | |
38 | + */ | |
39 | + $ftable[hexdec($m[1])]=preg_replace('/([0-9a-f]{3})[0-9a-f][\s]+/','$1',$m[2]); | |
40 | +},$tfile); | |
41 | +//print_r($ftable);exit; | |
42 | + | |
43 | +$tfile=file_get_contents('./JIS0208.TXT'); | |
44 | +$jtable=array(); | |
45 | +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){ | |
46 | + // $m[1]: SJIS, $m[2]: JIS, $m[3]: UTF16 | |
47 | + if (isset($ftable[hexdec($m[2])])) { | |
48 | + $jtable[hexdec($m[3])]=$ftable[hexdec($m[2])]; | |
49 | + } | |
50 | +},$tfile); | |
51 | + | |
52 | +$result=''; | |
53 | +for($code=0x0000;$code<=0xffff;$code++){ | |
54 | + /* | |
55 | + Skip: | |
56 | + 0500 - 1fff | |
57 | + 2700 - 2fff | |
58 | + 3100 - 4dff | |
59 | + a000 - feff | |
60 | + Valid: | |
61 | + 0000 - 04ff (0500, total 0500) | |
62 | + 2000 - 26ff (0700, total 0c00) | |
63 | + 3000 - 30ff (0100, total 0d00) | |
64 | + 4e00 - 9fff (5200, total 5f00) | |
65 | + ff00 - ffff (0100, total 6000) | |
66 | + Therefore: | |
67 | + if P<0x0500 then | |
68 | + P=P-0x500 | |
69 | + elseif P<0x2000 then | |
70 | + REM ERR | |
71 | + elseif P<0x2700 then | |
72 | + P=P-0x2000+0x0500 | |
73 | + elseif P<0x3000 then | |
74 | + REM ERR | |
75 | + elseif P<0x3100 then | |
76 | + P=P-0x3000+0x0c00 | |
77 | + elseif P<0x4e00 then | |
78 | + REM ERR | |
79 | + elseif P<0xa000 then | |
80 | + P=P-0x4e00+0x0d00 | |
81 | + elseif P<0xff00 then | |
82 | + REM ERR | |
83 | + else | |
84 | + P=P-0xff00+0x5f00 | |
85 | + endif | |
86 | + */ | |
87 | + switch($code){ | |
88 | + case 0x0500: $code=0x2000; break; | |
89 | + case 0x2700: $code=0x3000; break; | |
90 | + case 0x3100: $code=0x4e00; break; | |
91 | + case 0xa000: $code=0xff00; break; | |
92 | + default: break; | |
93 | + } | |
94 | + if (isset($jtable[$code])) { | |
95 | + for($i=0;$i<36;$i+=2){ | |
96 | + $b=substr($jtable[$code],$i,2); | |
97 | + $result.=chr(hexdec($b)); | |
98 | + } | |
99 | + } else { | |
100 | + $result.="\x00\x00\x00\x00\x00\x00\x00\x00\x00"; | |
101 | + $result.="\x00\x00\x00\x00\x00\x00\x00\x00\x00"; | |
102 | + } | |
103 | +} | |
104 | +file_put_contents('./SHNMK12.UNI',$result); | |
105 | + |
@@ -0,0 +1,45 @@ | ||
1 | +<クラス名およびバージョン> | |
2 | +CKNJ12 | |
3 | +ver 0.1 | |
4 | + | |
5 | +<ファイル名> | |
6 | +CKNJ12.BAS | |
7 | +SHNMK12.JIS | |
8 | +SHNMK12.UNI | |
9 | + | |
10 | +<概要> | |
11 | +日本語表示クラス。東雲フォント(12x12)を使用し、グラフィックディスプレイに日本語を | |
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 CKNJ12 | |
32 | +USEGRAPHIC | |
33 | +POINT 50,50 | |
34 | +K=new(CKNJ12,"UTF-8") | |
35 | +K.GPRT("本日は晴天なり",7,0) | |
36 | +A$=INPUT$() | |
37 | + | |
38 | +次のように使用する事も出来る。 | |
39 | + | |
40 | +USECLASS CKNJ12 | |
41 | +USEGRAPHIC | |
42 | +POINT 50,50 | |
43 | +CKNJ12::INIT("UTF-8") | |
44 | +CKNJ12::GPRT("本日は晴天なり",7,0) | |
45 | +A$=INPUT$() |
@@ -1,4 +1,4 @@ | ||
1 | -REM CKNJ16.BAS ver 0.1 | |
1 | +REM CKNJ16.BAS ver 0.11 | |
2 | 2 | REM Class CKNJ16 for MachiKania Type Z/M |
3 | 3 | REM using Shinonome 16x16 font |
4 | 4 |
@@ -61,8 +61,16 @@ LABEL GPRTCH | ||
61 | 61 | next |
62 | 62 | next |
63 | 63 | REM Draw in graphic |
64 | - putbmp ,16,16,BMPF | |
65 | - point SYSTEM(28)+16,SYSTEM(29) | |
64 | + x=SYSTEM(28) | |
65 | + y=SYSTEM(29) | |
66 | + putbmp x,y,16,16,BMPF | |
67 | + if x+32<SYSTEM(22) then | |
68 | + x=x+16 | |
69 | + else | |
70 | + x=0 | |
71 | + y=y+16 | |
72 | + endif | |
73 | + point x,y | |
66 | 74 | return |
67 | 75 | |
68 | 76 | REM Private medthod FGETCH |
@@ -86,18 +94,19 @@ LABEL FGETCH | ||
86 | 94 | p=p-0x500 |
87 | 95 | elseif p<0x2000 then |
88 | 96 | REM ERR |
97 | + p=-1 | |
89 | 98 | elseif p<0x2700 then |
90 | 99 | p=p-0x2000+0x0500 |
91 | 100 | elseif p<0x3000 then |
92 | - REM ERR | |
101 | + p=-1 | |
93 | 102 | elseif p<0x3100 then |
94 | 103 | p=p-0x3000+0x0c00 |
95 | 104 | elseif p<0x4e00 then |
96 | - REM ERR | |
105 | + p=-1 | |
97 | 106 | elseif p<0xa000 then |
98 | 107 | p=p-0x4e00+0x0d00 |
99 | 108 | elseif p<0xff00 then |
100 | - REM ERR | |
109 | + p=-1 | |
101 | 110 | else |
102 | 111 | p=p-0xff00+0x5f00 |
103 | 112 | endif |
@@ -105,8 +114,15 @@ LABEL FGETCH | ||
105 | 114 | REM EUC |
106 | 115 | p=p-0xa1a1 |
107 | 116 | endif |
108 | - fseek p*32 | |
109 | - fget FBUFF,32 | |
117 | + p=p*32 | |
118 | + if 0<=p and p+32<flen() then | |
119 | + fseek p | |
120 | + fget FBUFF,32 | |
121 | + else | |
122 | + for p=0 to 7 | |
123 | + FBUFF(p)=0 | |
124 | + next | |
125 | + endif | |
110 | 126 | return |
111 | 127 | |
112 | 128 | REM Private method GPSTR |
@@ -2,7 +2,7 @@ | ||
2 | 2 | |
3 | 3 | /* |
4 | 4 | |
5 | - Binary font file generator for Misaki 8x8 font. | |
5 | + Binary font file generator for Shinonome 16x16 font. | |
6 | 6 | Place 'shnmk16.bdf' in the same directory and run this script. |
7 | 7 | The font file is used for EUC-JP. |
8 | 8 | On 2/23/2019, Shinonome font is available from: https://www.mgo-tec.com/kanji-font-shinonome |
@@ -1,7 +1,7 @@ | ||
1 | 1 | <?php |
2 | 2 | /* |
3 | 3 | |
4 | - Binary font file generator for Misaki 8x8 font. | |
4 | + Binary font file generator for Shinonome 16x16 font. | |
5 | 5 | Place 'shnmk16.bdf' in the same directory and run this script. |
6 | 6 | Place 'JIS0208.TXT' in the same directory and run this script. |
7 | 7 | The font file is used for UTF-8. |
@@ -1,6 +1,6 @@ | ||
1 | 1 | <クラス名およびバージョン> |
2 | 2 | CKNJ16 |
3 | -ver 0.1 | |
3 | +ver 0.11 | |
4 | 4 | |
5 | 5 | <ファイル名> |
6 | 6 | CKNJ16.BAS |