mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-09-27 23:19:21 +02:00
+ Initial implementation
This commit is contained in:
parent
c957bff371
commit
754e4047a6
58
docs/videoex/Makefile
Normal file
58
docs/videoex/Makefile
Normal file
@ -0,0 +1,58 @@
|
||||
#######################################################################
|
||||
#
|
||||
# Makefile to compile all examples and convert them to LaTeX
|
||||
#
|
||||
#######################################################################
|
||||
|
||||
# Compiler
|
||||
PP=ppc386
|
||||
|
||||
# Unit directory
|
||||
# UNITDIR=/usr/lib/ppc/0.99.0/linuxunits
|
||||
|
||||
|
||||
# Any options you wish to pass.
|
||||
PPOPTS=
|
||||
|
||||
# Script to convert the programs to LaTeX examples which can be included.
|
||||
PP2TEX=../pp2tex
|
||||
|
||||
# Script to collect all examples in 1 file.
|
||||
MAKETEX=make1tex
|
||||
|
||||
#######################################################################
|
||||
# No need to edit after this line.
|
||||
#######################################################################
|
||||
|
||||
ifdef UNITDIR
|
||||
PPOPTS:=$(PPOPTS) -Up$(UNITDIR);
|
||||
endif
|
||||
|
||||
.SUFFIXES: .pp .tex
|
||||
|
||||
.PHONY: all tex clean
|
||||
|
||||
OBJECTS=ex1 ex2 ex3 ex4 ex5 ex6 ex7 ex8
|
||||
# ex9
|
||||
# ex10 ex11 ex12 ex13 ex14 ex15 ex16 ex17 ex18
|
||||
|
||||
TEXOBJECTS=$(addsuffix .tex, $(OBJECTS))
|
||||
|
||||
all : $(OBJECTS)
|
||||
|
||||
tex : $(TEXOBJECTS)
|
||||
|
||||
onetex : tex
|
||||
$(MAKETEX) $(TEXOBJECTS)
|
||||
|
||||
clean :
|
||||
rm -f *.o *.s $(OBJECTS) $(TEXOBJECTS) vidutil.ppu vidutil.o
|
||||
|
||||
$(OBJECTS): %: %.pp vidutil.ppu
|
||||
$(PP) $(PPOPTS) $*
|
||||
|
||||
$(TEXOBJECTS): %.tex: %.pp head.tex foot.tex
|
||||
$(PP2TEX) $*
|
||||
|
||||
vidutil.ppu: vidutil.pp
|
||||
$(PP) $(PPOPTS) vidutil.pp
|
12
docs/videoex/README
Normal file
12
docs/videoex/README
Normal file
@ -0,0 +1,12 @@
|
||||
This directory contains the examples for the video unit documentation.
|
||||
|
||||
vidutil.pp Containst the textout function.
|
||||
|
||||
ex1.pp demonstrates the vidutil unit.
|
||||
ex2.pp contains an example of the SetCursorPos function.
|
||||
ex3.pp contains an example of the ClearScreen function.
|
||||
ex4.pp contains an example of the GetCapabilities function.
|
||||
ex5.pp contains an example of the GetCursorType function.
|
||||
ex6.pp contains an example of the GetLockScreenCount function.
|
||||
ex7.pp contains an example of the GetVideoMode function.
|
||||
ex8.pp contains an example of the GetVideoModeCount function.
|
18
docs/videoex/ex1.pp
Normal file
18
docs/videoex/ex1.pp
Normal file
@ -0,0 +1,18 @@
|
||||
program testvideo;
|
||||
|
||||
uses video,keyboard,vidutil;
|
||||
|
||||
Var
|
||||
i : longint;
|
||||
k : TkeyEvent;
|
||||
|
||||
begin
|
||||
InitVideo;
|
||||
InitKeyboard;
|
||||
For I:=1 to 10 do
|
||||
TextOut(i,i, 'Press any key to end');
|
||||
UpdateScreen(False);
|
||||
K:=GetKeyEvent;
|
||||
DoneKeyBoard;
|
||||
DoneVideo;
|
||||
end.
|
48
docs/videoex/ex2.pp
Normal file
48
docs/videoex/ex2.pp
Normal file
@ -0,0 +1,48 @@
|
||||
program example2;
|
||||
|
||||
uses video,keyboard;
|
||||
|
||||
Var
|
||||
P,PP,D : Integer;
|
||||
K: TKeyEvent;
|
||||
|
||||
Procedure PutSquare (P : INteger; C : Char);
|
||||
|
||||
begin
|
||||
VideoBuf^[P]:=Ord(C)+($07 shr 8);
|
||||
VideoBuf^[P+ScreenWidth]:=Ord(c)+($07 shr 8);
|
||||
VideoBuf^[P+1]:=Ord(c)+($07 shr 8);
|
||||
VideoBuf^[P+ScreenWidth+1]:=Ord(c)+($07 shr 8);
|
||||
end;
|
||||
|
||||
begin
|
||||
InitVideo;
|
||||
InitKeyBoard;
|
||||
P:=0;
|
||||
PP:=-1;
|
||||
Repeat
|
||||
If PP<>-1 then
|
||||
PutSquare(PP,' ');
|
||||
PutSquare(P,'#');
|
||||
SetCursorPos(P Mod ScreenWidth,P div ScreenWidth);
|
||||
UpdateScreen(False);
|
||||
PP:=P;
|
||||
Repeat
|
||||
D:=0;
|
||||
K:=TranslateKeyEvent(GetKeyEvent);
|
||||
Case GetKeyEventCode(K) of
|
||||
kbdLeft : If (P Mod ScreenWidth)<>0 then
|
||||
D:=-1;
|
||||
kbdUp : If P>=ScreenWidth then
|
||||
D:=-ScreenWidth;
|
||||
kbdRight : If ((P+2) Mod ScreenWidth)<>0 then
|
||||
D:=1;
|
||||
kbdDown : if (P<(VideoBufSize div 2)-(ScreenWidth*2)) then
|
||||
D:=ScreenWidth;
|
||||
end;
|
||||
Until (D<>0) or (GetKeyEventChar(K)='q');
|
||||
P:=P+D;
|
||||
until GetKeyEventChar(K)='q';
|
||||
DoneKeyBoard;
|
||||
DoneVideo;
|
||||
end.
|
22
docs/videoex/ex3.pp
Normal file
22
docs/videoex/ex3.pp
Normal file
@ -0,0 +1,22 @@
|
||||
program testvideo;
|
||||
|
||||
uses video,keyboard,vidutil;
|
||||
|
||||
Var
|
||||
i : longint;
|
||||
k : TkeyEvent;
|
||||
|
||||
begin
|
||||
InitVideo;
|
||||
InitKeyboard;
|
||||
For I:=1 to 10 do
|
||||
TextOut(i,i, 'Press any key to clear screen');
|
||||
UpdateScreen(false);
|
||||
K:=GetKeyEvent;
|
||||
ClearScreen;
|
||||
TextOut(1,1,'Cleared screen. Press any key to end');
|
||||
UpdateScreen(true);
|
||||
K:=GetKeyEvent;
|
||||
DoneKeyBoard;
|
||||
DoneVideo;
|
||||
end.
|
29
docs/videoex/ex4.pp
Normal file
29
docs/videoex/ex4.pp
Normal file
@ -0,0 +1,29 @@
|
||||
Program Example4;
|
||||
|
||||
{ Program to demonstrate the GetCapabilities function. }
|
||||
|
||||
Uses video;
|
||||
|
||||
Var
|
||||
W: Word;
|
||||
|
||||
Procedure TestCap(Cap: Word; Msg : String);
|
||||
|
||||
begin
|
||||
Write(Msg,' : ');
|
||||
If (W and Cap=Cap) then
|
||||
Writeln('Yes')
|
||||
else
|
||||
Writeln('No');
|
||||
end;
|
||||
|
||||
begin
|
||||
W:=GetCapabilities;
|
||||
Writeln('Video driver supports following functionality');
|
||||
TestCap(cpUnderLine,'Underlined characters');
|
||||
TestCap(cpBlink,'Blinking characters');
|
||||
TestCap(cpColor,'Color characters');
|
||||
TestCap(cpChangeFont,'Changing font');
|
||||
TestCap(cpChangeMode,'Changing video mode');
|
||||
TestCap(cpChangeCursor,'Changing cursor shape');
|
||||
end.
|
20
docs/videoex/ex5.pp
Normal file
20
docs/videoex/ex5.pp
Normal file
@ -0,0 +1,20 @@
|
||||
Program Example5;
|
||||
|
||||
{ Program to demonstrate the GetCursorType function. }
|
||||
|
||||
Uses video,keyboard,vidutil;
|
||||
|
||||
Const
|
||||
Cursortypes : Array[crHidden..crHalfBlock] of string =
|
||||
('Hidden','UnderLine','Block','HalfBlock');
|
||||
|
||||
begin
|
||||
InitVideo;
|
||||
InitKeyboard;
|
||||
TextOut(1,1,'Cursor type: '+CursorTypes[GetCursorType]);
|
||||
TextOut(1,2,'Press any key to exit.');
|
||||
UpdateScreen(False);
|
||||
GetKeyEvent;
|
||||
DoneKeyboard;
|
||||
DoneVideo;
|
||||
end.
|
34
docs/videoex/ex6.pp
Normal file
34
docs/videoex/ex6.pp
Normal file
@ -0,0 +1,34 @@
|
||||
Program Example6;
|
||||
|
||||
{ Program to demonstrate the GetLockScreenCount function. }
|
||||
|
||||
Uses video,keyboard,vidutil;
|
||||
|
||||
Var
|
||||
I : Longint;
|
||||
S : String;
|
||||
|
||||
begin
|
||||
InitVideo;
|
||||
InitKeyboard;
|
||||
TextOut(1,1,'Press key till new text appears.');
|
||||
UpdateScreen(False);
|
||||
Randomize;
|
||||
For I:=0 to Random(10)+1 do
|
||||
LockScreenUpdate;
|
||||
I:=0;
|
||||
While GetLockScreenCount<>0 do
|
||||
begin
|
||||
Inc(I);
|
||||
Str(I,S);
|
||||
UnlockScreenUpdate;
|
||||
GetKeyEvent;
|
||||
TextOut(1,1,'UnLockScreenUpdate had to be called '+S+' times');
|
||||
UpdateScreen(False);
|
||||
end;
|
||||
TextOut(1,2,'Press any key to end.');
|
||||
UpdateScreen(False);
|
||||
GetKeyEvent;
|
||||
DoneKeyboard;
|
||||
DoneVideo;
|
||||
end.
|
28
docs/videoex/ex7.pp
Normal file
28
docs/videoex/ex7.pp
Normal file
@ -0,0 +1,28 @@
|
||||
Program Example7;
|
||||
|
||||
{ Program to demonstrate the GetVideoMode function. }
|
||||
|
||||
Uses video,keyboard,vidutil;
|
||||
|
||||
Var
|
||||
M : TVideoMode;
|
||||
S : String;
|
||||
|
||||
begin
|
||||
InitVideo;
|
||||
InitKeyboard;
|
||||
GetVideoMode(M);
|
||||
if M.Color then
|
||||
TextOut(1,1,'Current mode has color')
|
||||
else
|
||||
TextOut(1,1,'Current mode does not have color');
|
||||
Str(M.Row,S);
|
||||
TextOut(1,2,'Number of rows : '+S);
|
||||
Str(M.Col,S);
|
||||
TextOut(1,3,'Number of columns : '+S);
|
||||
Textout(1,4,'Press any key to exit.');
|
||||
UpdateScreen(False);
|
||||
GetKeyEvent;
|
||||
DoneKeyboard;
|
||||
DoneVideo;
|
||||
end.
|
44
docs/videoex/ex8.pp
Normal file
44
docs/videoex/ex8.pp
Normal file
@ -0,0 +1,44 @@
|
||||
Program Example8;
|
||||
|
||||
{ Program to demonstrate the GetVideoModeCount function. }
|
||||
|
||||
Uses video,keyboard,vidutil;
|
||||
|
||||
Procedure DumpMode (M : TVideoMode; Index : Integer);
|
||||
|
||||
Var
|
||||
S : String;
|
||||
|
||||
begin
|
||||
Str(Index:2,S);
|
||||
inc(Index);
|
||||
TextOut(1,Index,'Data for mode '+S+': ');
|
||||
if M.Color then
|
||||
TextOut(19,Index,' color,')
|
||||
else
|
||||
TextOut(19,Index,'No color,');
|
||||
Str(M.Row:3,S);
|
||||
TextOut(28,Index,S+' rows');
|
||||
Str(M.Col:3,S);
|
||||
TextOut(36,index,S+' columns');
|
||||
end;
|
||||
|
||||
Var
|
||||
i,Count : Integer;
|
||||
m : TVideoMode;
|
||||
|
||||
begin
|
||||
InitVideo;
|
||||
InitKeyboard;
|
||||
Count:=GetVideoModeCount;
|
||||
For I:=1 to Count do
|
||||
begin
|
||||
GetVideoModeData(I-1,M);
|
||||
DumpMode(M,I-1);
|
||||
end;
|
||||
TextOut(1,Count+1,'Press any key to exit');
|
||||
UpdateScreen(False);
|
||||
GetKeyEvent;
|
||||
DoneKeyboard;
|
||||
DoneVideo;
|
||||
end.
|
2
docs/videoex/foot.tex
Normal file
2
docs/videoex/foot.tex
Normal file
@ -0,0 +1,2 @@
|
||||
\end{verbatim}
|
||||
\end{FPCList}
|
3
docs/videoex/head.tex
Normal file
3
docs/videoex/head.tex
Normal file
@ -0,0 +1,3 @@
|
||||
\begin{FPCList}
|
||||
\item[Example]
|
||||
\begin{verbatim}
|
8
docs/videoex/newex
Normal file
8
docs/videoex/newex
Normal file
@ -0,0 +1,8 @@
|
||||
#!/bin/sh
|
||||
if [ -e ex${1}.pp ]; then
|
||||
mv ex${1}.pp ex${1}.pp.orig
|
||||
fi
|
||||
sed -e s/Example/Example$1/ -e s/\\\*\\\*\\\*/$2/ <template.pp >ex${1}.pp
|
||||
echo "ex${1}.pp contains an example of the $2 function." >>README
|
||||
joe ex${1}.pp
|
||||
ppc386 ex${1}.pp && ex${1}
|
12
docs/videoex/template.pp
Normal file
12
docs/videoex/template.pp
Normal file
@ -0,0 +1,12 @@
|
||||
Program Example;
|
||||
|
||||
{ Program to demonstrate the *** function. }
|
||||
|
||||
Uses video,keyboard,vidutil;
|
||||
|
||||
begin
|
||||
InitVideo;
|
||||
InitKeyboard;
|
||||
DoneKeyboard;
|
||||
DoneVideo;
|
||||
end.
|
26
docs/videoex/vidutil.pp
Normal file
26
docs/videoex/vidutil.pp
Normal file
@ -0,0 +1,26 @@
|
||||
unit vidutil;
|
||||
|
||||
Interface
|
||||
|
||||
uses
|
||||
video;
|
||||
|
||||
Procedure TextOut(X,Y : Word;Const S : String);
|
||||
|
||||
Implementation
|
||||
|
||||
Procedure TextOut(X,Y : Word;Const S : String);
|
||||
|
||||
Var
|
||||
W,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 shr 8);
|
||||
end;
|
||||
|
||||
end.
|
Loading…
Reference in New Issue
Block a user