home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.barnyard.co.uk
/
2015.02.ftp.barnyard.co.uk.tar
/
ftp.barnyard.co.uk
/
cpm
/
walnut-creek-CDROM
/
BEEHIVE
/
UTILITYS
/
TIMEZONE.ARK
/
TIMEZONE.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1989-09-27
|
6KB
|
256 lines
program timezone;
{ program to display the time in cities around the world. }
const
local_city = 'Sydney Australia';
local_tz = +10; { GMT + 10 hours }
century = 1900; { what century is this - for date function }
debug = false;
defaultcityname = 'CITIES.TXT';
grafixname = 'WORLD.SCN';
type
TimeRec = record
hour, minute, second: integer;
weekday, day, month, year: integer;
end;
str20 = string[20];
Cptr = ^citytype;
citytype = record
name: str20;
timezone: integer;
xpos, ypos: byte;
next: Cptr;
end;
screentype = array [1..2048] of byte;
var
cities,head: cptr;
i,hours: integer;
cityfile: text;
grafixfile: file;
temp: real;
tempname: str20;
scrtemp: screentype;
procedure GetTime(var time:TimeRec);
function GetRegister(reg: byte):byte;
var
i:byte;
begin
if debug then
begin
write ('Register ',reg,' =');
readln (i);
GetRegister := i;
end
else
begin
repeat port [4] := 10 until ((port[7] and 128)=0);
port[4] := reg;
i := port[7];
GetRegister := i - (i div 16) * 6;
end;
end;
begin
with time do
begin
second:=GetRegister (0);
minute:=GetRegister (2);
hour:=GetRegister (4);
weekday:=GetRegister (6);
day:=GetRegister (7);
month:=GetRegister (8);
year:=GetRegister (9) + century;
end;
end;
procedure WriteTime (time: TimeRec);
const
WeekdayName : array [1..7] of string[9] =
('Monday','Tuesday','Wednesday,','Thursday','Friday',
'Saturday','Sunday');
function j(num: byte): byte;
begin
if num in [0..9] then write ('0');
j:=num;
end;
begin
with time do
begin
write (j(hour),':',j(minute));
{ ,':',j(second),' ');
write (WeekdayName[weekday],' ',j(day),'/',j(month),'/',year);
}
end;
end;
procedure Regularize (var time:TimeRec);
const
month_count: array[1..12] of byte = (31,28,31,30,31,30,
31,31,30,31,30,31);
begin
with time do
begin
if (hour > 23) then
begin
hour := hour - 24;
weekday := weekday + 1;
if (weekday > 7) then weekday := weekday - 7;
day := day + 1;
if not ( (month = 2) and
((year mod 4) = 0) and ((year mod 400) <> 0) and
(day = 29) ) then
if (day > month_count[month]) then
begin
month := month + 1;
if (month > 12) then
begin
month := month - 12;
year := year + 1;
end;
day := 1;
end;
end
else if (hour < 0) then
begin
hour := hour + 24;
weekday := weekday - 1;
if (weekday < 1) then weekday := weekday + 7;
day := day - 1;
if (day < 1) then
begin
month := month - 1;
if (month < 1) then
begin
month := month + 12;
year := year - 1;
end;
day := day + month_count [month];
if (month = 2) then
begin
{is year divisible by four?}
if ((year mod 4) = 0) and ((year mod 400) <> 0) then
day := day + 1;
end;
end;
end;
end; {with}
end;
procedure fix_long(var Long: real);
begin
if (Long < -180) then Long:=Long + 360.0
else if (Long > 180) then Long:=Long - 360.0
end;
procedure print_time (TimeZone: integer;
TargetCity: str20;
time: TimeRec);
{ this procedure will print the time/date at a target city }
begin
{ write (TargetCity,' is in timezone GMT');
if (TimeZone >= 0) then write ('+');
write (TimeZone,' hours ');
}
time.hour := time.hour - local_tz + TimeZone;
Regularize (time);
{ write ('Target time is '); }
WriteTime (time);
writeln;
end;
procedure DisplayTimes (head2: Cptr);
var
time: TimeRec;
workptr: Cptr;
begin
{ write ('Local city is ',local_city,', in timezone GMT');
if (local_tz>=0) then write ('+');
writeln (local_tz,' hours');
write ('Current time is ');
WriteTime (time);
writeln;
} workptr:=head2;
GetTime (time);
while (workptr <> nil) do
begin
gotoxy (workptr^.xpos,workptr^.ypos);
print_time (workptr^.timezone,workptr^.name,time);
workptr:=workptr^.next;
end; {while}
gotoxy (1,25);
repeat GetTime(time) until (time.second <> 0);
end;
procedure PrintContinuous(head2: Cptr);
var
time: TimeRec;
j: byte;
begin
repeat
begin
GetTime (time);
if (time.second = 0) then DisplayTimes(head2);
j:=bdos (6,255);
end {repeat}
until j=27;
end;
begin
writeln ('Attempting to read city declarations from file');
assign(cityfile,defaultcityname);
{$I-}
reset (cityfile);
{$I+}
If IOresult = 0 then
begin
cities := nil;
while not eof (cityfile) do
begin
new (head);
head^.next := cities;
read (cityfile,temp);
fix_long(temp);
head^.timezone:=round (temp / 15.0);
read (cityfile, head^.xpos, head^.ypos);
readln (cityfile,tempname);
head^.name := copy(tempname,2,length(tempname));
cities := head;
end;
close (cityfile);
assign (grafixfile,grafixname);
reset (grafixfile);
blockread (grafixfile,scrtemp,15);
close (grafixfile);
for i:=$f810 to $f81f do mem[i]:=$ff;
for i:=$f820 to $f82f do mem[i]:=$10;
gotoxy (1,25); {get rid of cursor}
for i:=1 to 1920 do mem[$0f000+i-1]:=scrtemp[i];
port [8]:=$40;
for i:=1 to 1920 do
begin
if (scrtemp[i]=$81) then mem[$f800-1+i]:=8+3 else mem[$f800-1+i]:=6;
end;
port [8]:=0;
gotoxy (1,24); write ('World Clock by krd 1991');
DisplayTimes(head);
PrintContinuous(head);
port [8]:=$40;
for i:=1 to 1920 do
begin
mem[$f800+i-1]:=2;
end;
clrscr;
end
else
begin
writeln (defaultcityname,' not found.');
end;
end.