-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmkv8font.pas
355 lines (337 loc) · 9.66 KB
/
mkv8font.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
{
Copyright (C) 2019 Jerome Shidel
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
}
program MakeV8Font;
const
CRLF=#$0d#$0a;
V8FONT: String ='V8FONT'+CRLF;
EOF: Char = #26;
type
TBlock=record
Style : byte;
Size : word;
First, Count : word;
Width, Height : word;
end;
procedure SetROMFont(ASize:byte); assembler;
asm
mov ah, ASize
mov al, 1
cmp ah, 14
je @@LoadFont
mov al, 2
cmp ah, 8
je @@LoadFont
mov al, 4
@@LoadFont:
mov ah, 11h
mov bl, 00h
int 10h
end;
procedure SetCustomFont(ASize:byte; AFont : pointer); assembler;
asm
push bp
push es
mov bh, ASize
les bp, AFont
mov ax, 1100h
mov bl, 0
mov cx, 0100h
mov dx, 0000h
int 10h
pop es
pop bp
end;
function GetFontHeight : byte; assembler;
asm
push es
push di
mov ax, 0040h
mov es, ax
mov di, 0085h
mov al, [es:di]
pop di
pop es
end;
function GetROMFontPtr(ASet:byte; Upper, Alt:Boolean) : pointer; assembler;
asm
push es
push bp
mov ax, 1130h
mov cl, Alt
mov bl, ASet
mov bh, 02h
cmp bl, 14
je @@CheckAlt14
mov bh, 06h
cmp bl, 16
je @@CheckAlt16
mov bh, 03h
mov bl, Upper
cmp bl, False
je @@GetPointer
inc bh
jmp @@GetPointer
@@CheckAlt14:
cmp cl, True
jne @@GetPointer
mov bh, 05h
jmp @@GetPointer
@@CheckAlt16:
cmp cl, True
jne @@GetPointer
mov bh, 07h
@@GetPointer:
int 10h
mov dx, es
mov ax, bp
pop bp
pop es
mov bh, ASet
mov bl, Upper
cmp bh, 8
je @@Done
cmp bl, False
je @@Done
push dx
push ax
mov ax, 0080h
mul cx
pop bx
add ax, bx
pop dx
@@Done:
end;
procedure PrintDots(AValue:Byte);
var
I : integer;
begin
for I := 0 to 7 do
if ( AValue shr (7 - I) and $1 = $1 ) then
Write(#$B2)
else
Write(' ');
end;
procedure Delay(Ms:word); assembler;
asm
push di
push es
xor dx, dx
mov ax, Ms
mov cx, 55
div cx
mov dx, 0040h
mov es, dx
mov di, 006Ch
mov dx, [es:di]
@@Waiting:
hlt
mov cx, [es:di]
cmp cx, dx
je @@Waiting
mov dx, cx
cmp ax, 0
je @@Done
dec ax
jmp @@Waiting
@@Done:
pop es
pop di
end;
function ConvertFont(AFileName: String) : integer;
var
F : File;
P, R : Pointer;
S : LongInt;
H, E, T : integer;
C : array[0..255] of boolean;
LG, G, N, L, I : integer;
A, B : Byte;
V : String;
Block : TBlock;
SA, SB, HA, HB, M : String;
AutoSkip, AutoAll, Exact : boolean;
begin
AutoSkip := false;
AutoAll := false;
FileMode:= 0;
Assign(F, AFileName);
Reset(F,1);
S := FileSize(F);
GetMem(P, S);
BlockRead(F, P^, S);
Close(F);
FillChar(C, Sizeof(C), False);
H := S div 256;
if (S mod 256 <> 0) or (H > 30) or (H < 4) then begin
WriteLn('Invalid font file');
Halt(3);
end;
if (H <> 8) and (H <> 14) and (H <> 16) then
FillChar(C, Sizeof(C), True)
else begin
repeat
LG := -1;
I := 0;
repeat
N := I and $7F;
G := I shr 7;
if LG <> G then
R := GetROMFontPtr(H, G = 1, False);
LG := G;
SA := '';
SB := '';
HA := '';
HB := '';
M := '';
Exact := True;
for L := 0 to H - 1 do
begin
A:=Mem[Seg(R^):Ofs(R^) + (N * H) + L];
B:=Mem[Seg(P^):Ofs(P^) + (G * $80 * H) + (N * H) + L];
Exact := Exact and (A = B);
PrintDots(A);
if (SA <> '') or (A <> 0) then begin
if A = 0 then
HA := HA + ' '
else begin
SA := SA + HA + Chr(A);
HA := '';
end;
end;
Write(' ');
PrintDots(B);
if (SB <> '') or (B <> 0) then begin
if B = 0 then
HB := HB + ' '
else begin
SB := SB + HB + Chr(B);
HB := '';
end;
end;
WriteLn;
end;
if Exact then begin
V := 'N';
end else
if AutoAll then begin
V := 'Y';
end else
if (not AutoSkip) or (SA <> SB) then begin
if (SA = SB) then begin
WriteLn('Probable match, use A option to automatically reject those.');
M := ',A,I';
end;
Write('Character #', G * $80 + N, ', Approve (y/N/q/p', M, ',#)?');
ReadLn(V);
if (V = 'a') or (V = 'A') then begin
AutoSkip := True;
V := 'N';
end else
if (V = 'i') or (V = 'i') then begin
AutoAll := True;
V := 'Y';
end;
end else begin
V := 'N';
end;
Val(V, T, E);
if E = 0 then
I := T
else if V = 'q' then continue
else if (V = 'p') or (V = 'P') then
dec(I)
else begin
C[G * $80 + N] := (V = 'y') or (V = 'Y');
Inc(I);
end;
until (V = 'q') or (I > 255);
SetCustomFont(H, P);
T := 0;
for I := 0 to 255 do
if C[I] = True then begin
Write(Chr(I));
Inc(T);
end;
WriteLn;
Write(T, ' font characters, Continue (Y/n/q)?');
ReadLn(V);
SetRomFont(H);
until (V <> 'n') or (V <> 'N');
if (V = 'q') or (V = 'Q') then begin
WriteLn('Aborted.');
Halt(1);
end;
end;
Write('Text Comment?');
ReadLn(V);
AFileName := Copy(AFileName, 1, Pos('.', AFileName) - 1) + '.V8F';
WriteLn('Saving ', AFileName);
Assign(F, AFilename);
Rewrite(F, 1);
BlockWrite(F, V8FONT[1], Length(V8FONT));
if V <> '' then begin
BlockWrite(F, V[1], Length(V));
V := CRLF;
BlockWrite(F, V[1], Length(V));
end;
BlockWrite(F, EOF, Sizeof(EOF));
I := 0;
Block.Style := 1;
Block.Width := 8;
Block.Height := H;
Block.First := 0;
Block.Count := 0;
while I < 255 do begin
if C[I] = True then begin
if Block.Count = 0 then
Block.First := I;
Inc(Block.Count);
end;
if (Block.Count > 0) and ((C[I] = False) or (I = 255)) then begin
Block.Size := (Sizeof(Block) - 1) + H * Block.Count;
BlockWrite(F, Block, Sizeof(Block));
R := Ptr(Seg(P^),Ofs(P^) + (Block.First * H));
BlockWrite(F, R^, H * Block.Count);
Block.Count := 0;
end;
Inc(I);
end;
A := 0;
BlockWrite(F, A, Sizeof(A));
Close(F);
end;
procedure ShowHelp;
begin
WriteLn('usage: mkV8font [bitmap font]');
WriteLn('convert a standard bitmap font to a v8f font supplement file');
WriteLn;
WriteLn('During conversion you have several "Approval" options');
WriteLn;
WriteLn(' y - accept character and include it in the v8f file');
WriteLn(' n - reject character and exclude include it from the v8f file');
WriteLn(' q - abort conversion');
WriteLn(' p - decide later');
WriteLn;
WriteLn(' a - automatically reject all probable matches (same but shifted up or down)');
WriteLn(' i - automatically include everything except exact matches');
WriteLn;
WriteLn(' exact matches are always automatically rejected');
end;
begin
if (ParamStr(1) = '/h') or (ParamStr(1) = '/?') or (ParamCOunt = 0) then
ShowHelp
else
ConvertFont (ParamStr(1));
end.