-
Notifications
You must be signed in to change notification settings - Fork 1
/
vidutil.pas
70 lines (56 loc) · 1.67 KB
/
vidutil.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
unit vidutil;
(*
Unit to add more functionality to the Video Unit.
Last Modified 22/8/2016.
Coded by Velorek.
*)
Interface
uses
video,hex2bin;
Procedure TextOut(X,Y : Word;Const S : String);
Procedure Esc(X,Y : Word;Const S : String;bcolor,fcolor:integer;update:boolean);
Function VideoReadChar(x,y,z:integer):char;
{ Coordinates are 1 based, z=0 gets the character, z=1 gets the attribute.}
property screen[x,y,z:integer]:char read videoreadchar;
Implementation
Procedure TextOut(X,Y : Word;Const S : String);
{Write string to buffer without attributes in the specified positions}
Var
P,I,M : Word;
begin
P:=((X-1)+(Y-1)*ScreenWidth);
M:=Length(S);
If P+M>ScreenWidth*ScreenHeight then
M:=ScreenWidth*ScreenHeight-P;
For I:=1 to M do
VideoBuf^[P+I-1]:=Ord(S[i])+($07 shl 8);
updatescreen(true);
end;
Procedure Esc(X,Y : Word;Const S : String;bcolor,fcolor:integer;update:boolean);
{Write string to buffer with attributes}
{Update is conditional if true might be very slow to display items}
Var
P,I,M : Word;
fc,bc, bit2: string;
begin
P:=((X-1)+(Y-1)*ScreenWidth);
M:=Length(S);
If P+M>ScreenWidth*ScreenHeight then
M:=ScreenWidth*ScreenHeight-P;
fc:=dec2hex(fcolor,false); {turn the bit value to hex}
bc:=dec2hex(bcolor,false);
bit2 := bc+fc;
For I:=1 to M do
VideoBuf^[P+I-1]:=Ord(S[i])+(hex2dec(bit2) shl 8);
if update=true then updatescreen(true);
end;
Function videoreadchar(x,y,z:integer):char;
{Read char and attributes from screen at the specified position}
{Coordinates are 1 based, z=0 gets the character, z=1 gets the attribute.}
Var
P: Integer;
begin
P:=((X-1)+(Y-1)*ScreenWidth);
videoreadchar:=pchar(@VideoBuf^[P])[z];
End;
end.