home *** CD-ROM | disk | FTP | other *** search
- TURBO Pascal routines, tips ,techniques, bugs, etc. etc. etc.
-
- program timer ;
- type
- dt = record
- yyyy: 1980..1999;
- mo: 01..12;
- dd: 01..31;
- hh: 00..23;
- mm: 00..59;
- ss: 00..59;
-
- hhh: 00..99;
- end;
- procedure DateTime(var dtrec:dt);
- var
- regpack : record
- ax,bx,cx,dx,bp,si,di,ds,es,flags: integer;
- end;
-
- begin
- with regpack do
- begin
- ax := swap($2c); {load ah register with hex 2c}
-
- intr ($21,regpack);
- dtrec.hh:=(hi(cx));
- dtrec.mm:=lo(cx);
- dtrec.ss:=hi(dx);
- dtrec.hhh:=lo(dx);
- ax := swap($2a);
- intr ($21,regpack);
- dtrec.yyyy:=cx;
- dtrec.mo:=hi(dx);
- dtrec.dd:=lo(dx);
- end;
-
- end;
-
- var
- dtrec: dt;
-
- begin
- DateTime(dtrec);
- write(dtrec.yyyy:6,dtrec.hh:4,dtrec.mm:4);
- writeln;
- readln;
- end.
-
-
- program cline ;
-
- {This program illustrates the use of absolute variables in order to
- get at the MSDOS command line buffer. The manual says that it is
- of length (hex) 80 and starts at location (hex) 80 in the program prefix.
- Since the cseg register points to the prefix, it is an easy task
- to define variable k which is the command line. MSDOS' command
- line conforms to PASCAL's idea of a string (length in first byte)
- so we don't have to do anything special.}
-
-
- var k: string[$80] absolute cseg:$80 ;
-
-
- begin
- writeln('k is ''',k,'''') ;
- {notice that the string begins with at least one blank}
- writeln('it''s length is ',length(k)) ;
- readln ;
- end.
-
- ***************************************************************************
-
- PROGRAM TOOLS; { Various System and Data Utilities for Turbo Pascal }
- { Joe Doran September 23, 1984 }
-
- TYPE
- str2 = string[2]; str15 = string[15];
- str8 = string[8]; str25 = string[25];
-
- register = record
- ax,bx,cx,dx,bp,si,ds,es,flags: integer;
- END;
-
- VAR
- i,j,k,l,m,n: integer;
- Tst,KeyByte,KeyScan: byte;
- KeyChar: char;
-
- { -------------------------------------------------------------------- }
-
- FUNCTION HexRep(Arg:byte): str2; { Hex Representation of Byte Value }
-
- CONST
- HexDigit: array[0..15] of char = '0123456789ABCDEF';
-
- BEGIN
- HexRep := 'XX';
- HexRep[1] := HexDigit[Arg shr 4];
- HexRep[2] := HexDigit[Arg and 15];
- END;
-
- { -------------------------------------------------------------------- }
-
- FUNCTION BitRep(Arg:byte): str8; { Bit Representation of Byte Value }
-
- BEGIN
- BitRep := '00000000';
- if arg and 1 > 0 then BitRep[8] := '1';
- if arg and 2 > 0 then BitRep[7] := '1';
- if arg and 4 > 0 then BitRep[6] := '1';
- if arg and 8 > 0 then BitRep[5] := '1';
- if arg and 6 > 0 then BitRep[4] := '1';
- if arg and 32 > 0 then BitRep[3] := '1';
- if arg and 64 > 0 then BitRep[2] := '1';
- if arg and 128 > 0 then BitRep[1] := '1';
- END;
-
- { -------------------------------------------------------------------- }
-
- PROCEDURE RegDump(IntrArgs:register); { Display Interrupt Registers}
-
- BEGIN
- WITH IntrArgs do
- BEGIN
- Writeln;
- Write('AX = ',HexRep(hi(ax)),HexRep(lo(ax)),'H ');
- Write(BitRep(hi(ax)),' ',BitRep(lo(ax)),'B');
- Write(' BX = ',HexRep(hi(bx)),HexRep(lo(bx)),'H ');
- Writeln(BitRep(hi(bx)),' ',BitRep(lo(bx)),'B');
- Write('CX = ',HexRep(hi(cx)),HexRep(lo(cx)),'H ');
- Write(BitRep(hi(cx)),' ',BitRep(lo(cx)),'B');
- Write(' DX = ',HexRep(hi(dx)),HexRep(lo(dx)),'H ');
- Writeln(BitRep(hi(dx)),' ',BitRep(lo(dx)),'B');
- Write('BP = ',HexRep(hi(bp)),HexRep(lo(bp)),'H ');
- Write(BitRep(hi(bp)),' ',BitRep(lo(bp)),'B');
- Write(' SI = ',HexRep(hi(si)),HexRep(lo(si)),'H ');
- Writeln(BitRep(hi(si)),' ',BitRep(lo(si)),'B');
- Write('DS = ',HexRep(hi(ds)),HexRep(lo(ds)),'H ');
- Write(BitRep(hi(ds)),' ',BitRep(lo(ds)),'B');
- Write(' ES = ',HexRep(hi(es)),HexRep(lo(es)),'H ');
- Writeln(BitRep(hi(es)),' ',BitRep(lo(es)),'B');
- Write('FL = ',HexRep(hi(flags)),HexRep(lo(flags)),'H ');
- Writeln(BitRep(hi(flags)),' ',BitRep(lo(flags)),'B');
- Writeln;
- END;
- END;
-
- { -------------------------------------------------------------------- }
-
- FUNCTION SysTime: str8; { System Time in HH:MM:SS format }
-
- TYPE
- register = record
- ax,bx,cx,dx,bp,si,ds,es,flags: integer;
- END;
-
- VAR
- IntrArgs: register;
- hr,mn,sc: string[2];
-
- BEGIN
- WITH IntrArgs do
- BEGIN
- ax := $2C00;
- intr($21,IntrArgs);
- str((cx shr 8):2,hr); if hr[1] = ' ' then hr[1] := '0';
- str((cx mod 256):2,mn); if mn[1] = ' ' then mn[1] := '0';
- str((dx shr 8):2,sc); if sc[1] = ' ' then sc[1] := '0';
- END;
- SysTime := hr+':'+mn+':'+sc;
- END;
-
- { -------------------------------------------------------------------- }
-
- FUNCTION SysDate: str8; { System Date in MM/DD/YY format }
-
- TYPE
- register = record
- ax,bx,cx,dx,bp,si,ds,es,flags: integer;
- END;
-
- VAR
- IntrArgs: register;
- yr,mn,dy: string[2];
- yr4: string[4];
-
- BEGIN
- WITH IntrArgs do
- BEGIN
- ax := $2A00;
- intr($21,IntrArgs);
- str(cx:4,yr4); yr := copy(yr4,3,2);
- str(hi(dx):2,mn); if mn[1] = ' ' then mn[1] := '0';
- str(lo(dx):2,dy); if dy[1] = ' ' then dy[1] := '0';
- END;
- SysDate := mn+'/'+dy+'/'+yr;
- END;
-
- { -------------------------------------------------------------------- }
-
- FUNCTION MemSize: integer; { System Memory Size (in 1K blocks) }
-
- TYPE
- register = record
- ax,bx,cx,dx,bp,si,ds,es,flags: integer;
- END;
-
- VAR
- IntrArgs: register;
-
- BEGIN
- WITH IntrArgs do
- BEGIN
- intr($12,IntrArgs);
- MemSize := ax;
- END;
- END;
-
- { -------------------------------------------------------------------- }
-
- FUNCTION OptDevs: integer; { Optional Equipment Indicators }
-
- TYPE
- register = record
- ax,bx,cx,dx,bp,si,ds,es,flags: integer;
- END;
-
- VAR
- IntrArgs: register;
-
- BEGIN
- WITH IntrArgs do
- BEGIN
- intr($11,IntrArgs);
- OptDevs := ax;
- END;
- END;
-
- { -------------------------------------------------------------------- }
-
- FUNCTION BiosVer: str8; { IBM PC BIOS Release Marker }
-
- VAR
- RomDate: array[1..8] of char absolute $FFFF:$0005;
-
- BEGIN
- BiosVer := RomDate;
- END;
-
- { -------------------------------------------------------------------- }
-
- FUNCTION SysModel:str25; { IBM PC System Model Identification (maybe) }
-
- VAR
- SysCode: byte absolute $F000:$FFFE;
- WrkCode: byte;
-
- BEGIN
- WrkCode := SysCode - $FC;
- Case WrkCode of
- 0: SysModel := 'IBM Personal Computer AT';
- 1: SysModel := 'IBM PCjr.';
- 2: SysModel := 'IBM PC XT or Portable PC';
- 3: SysModel := 'IBM Personal Computer';
- Else
- SysModel := 'Unrecognized System';
- END;
- END;
-
- { -------------------------------------------------------------------- }
-
- PROCEDURE InKey(Var KBchar,KBscan:byte); { Read Keyboard Codes }
-
- TYPE
- register = record
- ax,bx,cx,dx,bp,si,ds,es,flags: integer;
- END;
-
- VAR
- IntrArgs: register;
-
- BEGIN
- WITH IntrArgs do
- BEGIN
- ax := $0000;
- intr($16,IntrArgs);
- KBchar := lo(ax);
- KBscan := hi(ax);
- END;
- END;
-
- { -------------------------------------------------------------------- }
-
- BEGIN
- ClrScr;
- Writeln('TOOLS.PAS ----- Joe Doran ----- 23SEP84');
- Writeln;
- Writeln('The System Time is................. ',SysTime);
- Writeln('The System Date is................. ',SysDate);
- Writeln;
- Writeln('The Model Type is.................. ',SysModel);
- Writeln('The BIOS in this system is dated... ',BiosVer);
- Writeln('The System Memory Size is.......... ',MemSize,'KB');
- Write('The Equipment Flags are............ ');
- Writeln(BitRep(hi(OptDevs)),' ',BitRep(lo(OptDevs)));
- Writeln;
- Writeln('Keyboard exercise follows:');
- Writeln;
- KeyChar := 'A';
- While KeyChar <> ' ' do
- BEGIN
- Writeln;
- Writeln('Press any key for decoding; press space-bar to terminate.');
- Writeln;
- InKey(KeyByte,KeyScan);
- KeyChar := chr(KeyByte);
- if KeyScan > 0 then
- BEGIN
- Write('Chr(',KeyChar,') ');
- Write('ASCII: Hex(',HexRep(KeyByte),')');
- Write(' Bit(',BitRep(KeyByte),')');
- Writeln(' Val(',KeyByte:3,')');
- Write(' Scan: Hex(',HexRep(KeyScan),')');
- Write(' Bit(',BitRep(KeyScan),')');
- Writeln(' Val(',KeyScan:3,')');
- END;
- END;
- END.
-
- *** APPENDED 09/24/84 08:50:49 BY $MS ***
- R;
-
- 8