-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCHARDEF.PAS
440 lines (388 loc) · 8.98 KB
/
CHARDEF.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
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
Unit chardef;
{$X+}{$a+}
INTERFACE
uses dos,ttypes,tmaths;
const
fontshift=4; {shift by this amount to get to next font in list}
fontheight=1 shl fontshift; {font height}
Fontmax=Fontheight-1; {often need height-1}
FontsizeY=14; {size of the font in pixels -Two for tail}
{Fontheight:byte absolute $40:$85;}
fontintr=$1f;
CTproportional=1;
type
Fonttype=array[0..Fontmax] of byte;
charsettypeptr=^charsettype;
charsettype=record
typeface:array[0..255]of fonttype;
widths:array[0..255] of byte;
attrib:byte;
end;
Procedure not_font(font:bytearray;fontsize:word);
procedure ror_font(font:bytearray;fontwidth,fontheight:word);
procedure rod_font(font:bytearray;fontwidth,fontheight:word);
procedure rol_font(font:bytearray;fontwidth,fontheight:word);
procedure rou_font(font:bytearray;fontwidth,fontheight:word);
procedure flipx_font(font:bytearray;fontwidth,fontheight:word);
procedure flipy_font(font:bytearray;fontwidth,fontheight:word);
Procedure savefontlist(filename:string;var ch:charsettype);
Procedure loadfontlist(filename:string;var ch:charsettype);
Procedure Setcharset(lcharset:charsettype;block:byte);
Procedure setblock(block:byte);
Procedure Maxline(maxlines:integer);
Function TStrLen(txt:string;charset:charsettypeptr):word;
Function TStrLen_at(txt:string;index:byte;charset:charsettypeptr):word;
Function TStrLen_null(txt:pchar;charset:charsettypeptr):word;
function getindex(txt:string;x:integer;charset:charsettypeptr):byte;
Procedure proportionalize(var ch:charsettype);
function strippath(pstr:string):string;
IMPLEMENTATION
function strippath(pstr:string):string;
var i,lastindx:byte;
retstr:string;
begin
for i:=1 to length(pstr) do begin
if pstr[i]='\' then
lastindx:=i;
end;
retstr:=copy(pstr,0,lastindx);
strippath:=retstr;
end;
Function TStrLen_at(txt:string;index:byte;charset:charsettypeptr):word;
var len:word; lop:byte;
begin
if index<=1 then
TStrLen_at:=0
else
with charset^ do
if attrib=CTproportional then begin
len:=0;
for lop:=1 to index-1 do begin
inc(len,widths[byte(txt[lop])]);
end;
TStrLen_at:=len;
end else
TStrLen_at:=index shl 3;
end;
function TStrLen(txt:string;charset:charsettypeptr):word;
var len:word; lop:byte;
begin
with charset^ do
if attrib=CTproportional then begin
len:=0;
for lop:=1 to byte(txt[0]) do begin
inc(len,widths[byte(txt[lop])]);
end;
TStrLen:=len;
end else
TStrLen:=byte(txt[0]) shl 3;
end;
function getindex(txt:string;x:integer;charset:charsettypeptr):byte;
var lop:byte;currlen:integer;
begin
currlen:=0;
lop:=0;
while x>currlen do begin
inc(lop);
inc(currlen,charset^.widths[byte(txt[lop])])
end;
getindex:=lop;
end;
function TStrLen_null(txt:pchar;charset:charsettypeptr):word;
var len:word;
begin
len:=0;
with charset^ do
if attrib=CTproportional then
while byte(txt^)<>0 do begin
inc(len,widths[byte(txt^)]);
inc(txt);
end
else
while byte(txt^)<>0 do begin
inc(len,8);
inc(txt);
end;
TStrLen_null:=len;
end;
Procedure Maxline(maxlines:integer);
Begin
port[$3d4]:=9;port[$3d5]:=maxlines;
end;
Procedure setblock(block:byte);assembler;
asm
mov bl,block
mov ax,$1103
int $10
end;
procedure mapmask(mask:byte);assembler;
asm
mov dx,$3c5
mov al,2
out dx,al
mov al,mask
out dx,al
end;
{Procedure Setcharset(lcharset:charsettype);assembler;
const block=0;
asm
{set mapmask to two}
{mov dx,$3c5
mov al,2
out dx,al
mov al,$4
out dx,al
{load character set into generator 0)}
{push ds
lds si,lcharset
mov ax,$B800
mov es,ax
mov di,block
mov cx,256*4
movsw
{set block to 0}
{
end;}
Procedure setcharset(lcharset:charsettype;block:byte);assembler;
asm
mov ah,$11
mov al,$0
{mov ax,2816}
mov bh,Fontheight
mov bl,block
mov cx,255
mov dx,0
push bp
les bp,lcharset
int $10
pop bp
end;
Procedure savefontlist(filename:string;var ch:charsettype);
Var scans:byte;norecs:word;
f:file;
Begin
norecs:=1;
assign(f,filename);
Rewrite(f,norecs);
scans:=Fontheight;
blockwrite(f,scans,1,norecs);
blockwrite(f,ch.typeface,256*Fontheight,norecs);
close(f);
end;
Procedure proportionalize(var ch:charsettype);
var
currwidth:byteptr;
fontlop,bytelop,bitlop,currbit:byte;
begin
currwidth:[email protected];
ch.attrib:=ctproportional;
for fontlop:=0 to 255 do begin
currwidth^:=0;
for bytelop:=0 to fontmax do begin
currbit:=0;
for bitlop:=7 downto 0 do begin
if ch.typeface[fontlop][bytelop] and (1 shl bitlop)<>0 then
currbit:=bitlop xor 7;
end;
if currbit>currwidth^ then
currwidth^:=currbit;
end;
inc(currwidth^,2);
inc(currwidth);
end;
ch.widths[32]:=6;
end;
Procedure loadfontlist(filename:string;var ch:charsettype);
const offset=0;
Var scans:byte;norecs:word;
fontlop,bytelop,bitlop,currbit:byte;
dummy:array[0..offset] of word;
f:file;
Begin
norecs:=1;
assign(f,filename);
Reset(f,norecs);
blockread(f,scans,1,norecs);
blockread(f,dummy,offset,norecs);
blockread(f,ch.typeface,256*scans,norecs);
proportionalize(ch);
close(f);
end;
{Procedure loadfontlistb(filename:string;var ch:charsettype);
Var lop,lop2,scans:byte;f:text;temp:char;tempstr:string;code:integer;
Begin
Assign(f,filename);
Reset(f);
readln(f,tempstr);
tempstr:=copy(tempstr,1,9);
val(tempstr,scans,code);
for lop:=0 to 255 do
for lop2:=1 to Fontheight do
begin
read(f,temp);ch^[lop][lop2]:=ord(temp);
end;
close(f);
end;
{the above is the old byte by byte method
below is the dynamicly sized array saver}
{Procedure loadfontlistc(filename:string;var ch:charsettype);
Var scans,lop:byte;f:file;norecs:word;
Begin
norecs:=1;
Assign(f,filename);
Reset(f,norecs);
blockread(f,scans,1,norecs);
for lop:=0 to 255 do
blockread(f,ch^[lop],scans,norecs);
close(f);
end;}
procedure rorblock(block:pointer;count:word;shiftby:byte);assembler;
asm
les di,block
mov cl,shiftby
mov bx,count
dec bx
add di,bx
{do first byte, save in dx}
mov dl,es:[di]
xor dh,dh
ror dx,cl
mov es:[di],dl
dec di
cmp bx,0
jz @lastbyte
@shiftloop:
mov al,es:[di]
xor ah,ah
ror ax,cl
mov es:[di],al
or es:[di+1],ah
dec di
dec bx
jnz @shiftloop
{do last byte}
@lastbyte:
or es:[di+1],dh
end;
procedure rolblock(block:pointer;count:word;shiftby:byte);assembler;
asm
les di,block
mov cl,shiftby
mov bx,count
dec bx
{do first byte, save in dx}
mov dh,es:[di]
xor dl,dl
rol dx,cl
mov es:[di],dh
inc di
cmp bx,0
jz @lastbyte
@shiftloop:
mov ah,es:[di]
xor al,al
rol ax,cl
mov es:[di],ah
or es:[di-1],al
inc di
dec bx
jnz @shiftloop
{do last byte}
@lastbyte:
or es:[di-1],dl
end;
procedure rol_font(font:bytearray;fontwidth,fontheight:word);
var lop:byte;
begin
for lop:=0 to fontheight-1 do
rolblock(@font^[lop*(fontwidth shr 3)],fontwidth shr 3,1);
end;
procedure rou_font(font:bytearray;fontwidth,fontheight:word);
var lop:word;
xbytes:byte;
temp:^byte;
begin
getmem(temp,xbytes);
xbytes:=fontwidth shr 3;
move(font^[0],temp^,xbytes);
for lop:=0 to fontheight-2 do
move(font^[(lop+1)*xbytes],font^[lop*xbytes],xbytes);
move(temp^,font^[(fontheight-1)*xbytes],xbytes);
end;
procedure ror_font(font:bytearray;fontwidth,fontheight:word);
var lop:byte;
begin
for lop:=0 to fontheight-1 do
rorblock(@font^[lop*(fontwidth shr 3)],fontwidth shr 3,1);
end;
procedure rod_font(font:bytearray;fontwidth,fontheight:word);
var lop:word;
xbytes:byte;
temp:^byte;
begin
xbytes:=fontwidth shr 3;
getmem(temp,xbytes);
move(font^[(fontheight-1)*xbytes],temp^,xbytes);
for lop:=fontheight-1 downto 1 do
move(font^[(lop-1)*xbytes],font^[(lop)*xbytes],xbytes);
move(temp^,font^[0],xbytes);
freemem(temp,xbytes);
end;
{assembler;
asm
les di,font
mov cx,Fontheight
dec cx
mov ah,es:[di]
@shiftlop:
mov al,es:[di+1]
mov es:[di],al
inc di
loop @shiftlop
mov es:[di],ah
end;}
procedure not_font(font:bytearray;fontsize:word);assembler;
asm
les di,font
mov cx,Fontsize
@notlop:
mov al,es:[di]
not al
mov es:[di],al
inc di
loop @notlop
end;
procedure flipbyte(var c:byte);assembler;
asm
les di,c
mov al,es:[di]
mov cx,8
@bitlop:
rcr al,1
adc ah,0
cmp cl,1
jz @noshift
shl ah,1
@noshift:
loop @bitlop
mov es:[di],ah
end;
procedure flipx_font(font:bytearray;fontwidth,fontheight:word);
var xlop,ylop,xbytes,byte1,byte2:word;
begin
xbytes:=(fontwidth shr 3);
for ylop:=0 to xbytes*fontheight do
flipbyte(font^[ylop]);
if xbytes>1 then
for ylop:=0 to fontheight-1 do
for xlop:=0 to (xbytes-1) shr 1 do
fswap(font^[(ylop*xbytes)+xlop],font^[(ylop*xbytes)+xbytes-1-xlop],1);
end;
procedure flipy_font(font:bytearray;fontwidth,fontheight:word);
var lop,xbytes:byte;
begin
xbytes:=fontwidth shr 3;
for lop:=0 to (Fontheight-1) shr 1 do
fswap(font^[lop*xbytes],font^[(fontheight-1-lop)*xbytes],xbytes);
end;
End.