dos_compilers/Borland Turbo Pascal v2/INTRPTCL.DOC
2024-06-30 15:28:49 -07:00

47 lines
1.3 KiB
Plaintext
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

{* WARNING WARNING WARNING WARNING WARNING WARNING WARNING
In order to use the Intr procedure in Turbo Pascal you
must be familiar with interrupts and have access to a
technical reference manual.
The following program uses the Intr function in Turbo to
get the time. Registers have to be set correctly according
to the DOS technical reference manual before the function
is called.
The program simply returns the time in a string at the top
of the screen.*}
program TimeInterrupt;
type
TimeString = string[8];
function time: TimeString;
type
regpack = record
ax,bx,cx,dx,bp,di,si,ds,es,flags: integer;
end;
var
recpack: regpack; {assign record}
ah,al,ch,cl,dh: byte;
hour,min,sec: string[2];
begin
ah := $2c; {initialize correct registers}
with recpack do
begin
ax := ah shl 8 + al;
end;
intr($21,recpack); {call interrupt}
with recpack do
begin
str(cx shr 8,hour); {convert to string}
str(cx mod 256,min); { " }
str(dx shr 8,sec); { " }
end;
time := hour+':'+min+':'+sec;
end;
begin
writeln(time);
end.