home *** CD-ROM | disk | FTP | other *** search
- { TIMESTAMP AND KBIN Routines }
-
- {
- Source: "TIMESTAMP and KBIN for the IBM-PC", TUG Lines Volume I Issue 2
- Author: Karl Gerhard
- Date: 7/5/84
- Application: PC-DOS, MS-DOS
- }
-
- type
- stdstr = string[80];
-
- RecPack = record
- AX,BX,CX,DX,BP,SI,DI,DS,ES,FLAG:integer;
- end;
-
- var
- regs:RecPack;
- ch:char;
-
- {------------------------}
- function StrInt(n:integer):stdstr;
- { return a string with the integer in ASCII }
- var s:string[6];
- begin
- str(n,s);
- strint := s;
- end;
-
- {------------------------}
- procedure CallDos(fcn:integer);
- { execute DOS fcn# call }
- begin
- with regs do begin
- ax := fcn;
- MsDos(regs);
- end; { with }
- end;
-
-
- {---------------------------}
- function kbin:char;
-
- { returns key value entered at keyboard
- immediately; no display, handle extended codes }
-
- var
- c:char;
- n:integer;
-
- begin
- CallDOS($800); { DOS pg D-8 }
- n := Lo(regs.ax);
-
- if n = 25 then begin { ^Y to halt }
- writeln('^Y program halting. What is condition of open files?');
- delay(200);
- halt;
- end;
-
- if n = 0 then begin { ext code }
- CallDOS($800);
- n := Lo(regs.ax);
- if n > 127 then n := n - 124;
- n := n + 128;
- end; { ext }
- kbin := chr(n);
- end;
-
- {------------------------}
- function timestamp:stdstr;
- { return string of "MON DAY YEAR TIME" }
- type mot = array[1..12] of string[3];
- const mon:mot = ( 'JAN','FEB','MAR','APR','MAY','JUN',
- 'JUL','AUG','SEP','OCT','NOV','DEC');
- var tsret:stdstr; hr:integer; ampm:string[2];
- begin
- CallDos($2A00);
- with regs do begin
- tsret := mon[Hi(DX)] +' '+ strint(Lo(DX)) +','+ strint(CX)+ ' ';
-
- CallDos($2C00);
- hr := Hi(cx);
- if hr > 12 then begin
- hr := hr - 12;
- ampm := 'pm';
- end
- else
- ampm := 'am';
- timestamp := tsret + (strint(hr) ) + ':' + (strint(Lo(cx)) )+ampm;
- end; { with }
- end;
-
- {- main block for the demo -}
- begin
- writeln( 'Demonstration of the TimeStamp function: ',timestamp); writeln;
- writeln('The following demonstrates kbin vs keypress (entering q will quit)');
- repeat
- writeln(' using kbin to get extended codes');
- ch := kbin;
- writeln(ch, ord(ch):4);
- writeln( ' Using read(kbd,ch)');
- read(kbd,ch);
- writeln(ch, ord(ch):4);
- until ch = 'q';
- end.