home *** CD-ROM | disk | FTP | other *** search
- Unit EchoDev;
- { This routine implements a Text File Device Driver that will }
- { echo a single write or writeln statement to the screen and }
- { to the printer. It does this by outputting each character }
- { in the buffer to the screen with a BIOS interrupt, and to }
- { the printer. It can easily be expaned to include a boolean }
- { variable that will determine whether the echoing is to take }
- { place or not. }
- Interface
-
- Uses
- Dos; { This unit is necessary for a TFDD }
-
- Var
- Echo : Text; { This is the Echo device }
- LptPort : Byte; { LPT Port number for output }
-
- Implementation
-
- {$F+}
-
- Function NulRoutine( Var F : TextRec ) : Integer;
- { This routine will be called for any routine that is not }
- { necessary for usage by the Text File Device Driver. }
- Begin
- NulRoutine := 0; { Return an I/O result of 0 }
- End;
-
- Procedure WriteChar( Ch : Char );
- { This routine will output the character passed with a BIOS }
- { routine. This handles the screen part of the echoing TFDD }
- Var
- DisplayPage : Byte Absolute $40:$62;
- { BIOS Data Area of Active Page }
- Regs : Registers; { Used in the INTR call }
-
- Begin
- Regs.AH := $0E;
- Regs.AL := Ord( Ch );
- Regs.BH := DisplayPage;
- Regs.BL := 0;
- Intr( $10, Regs );
- End;
-
- Function EchoOutput( Var F: TextRec ): integer;
- { This is the Output driving routine. It is called for each }
- { write or writeln statement. When this routine is invoked, }
- { each character in the buffer will be written to the printer }
- { and written to the screen. }
- Var
- Regs: Registers; { Used in the INTR Call }
- P : word; { Position within the Text Buffer }
-
- Begin
- With F do
- Begin
- P := 0;
- Regs.AH := 16;
- While (P < BufPos) and ((regs.ah and 16) = 16) do
- Begin
- WriteChar( BufPtr^[P] );
- Regs.AL := Ord(BufPtr^[P]);
- Regs.AH := 0;
- Regs.DX := UserData[1];
- Intr($17,Regs);
- Inc(P);
- end;
- BufPos := 0;
- End;
- if (Regs.AH and 16) = 16 then
- EchoOutput := 0 { No error }
- else
- if (Regs.AH and 32 ) = 32 then
- EchoOutput := 159 { Out of Paper }
- else
- EchoOutput := 160; { Device write Fault }
- End;
-
- {$F-}
-
- Procedure AssignEcho( Var F : Text );
- { This is the procedure that will set up the Text Record to }
- { allow output to both the printer and the screen. It sets }
- { up all of the fields in the TextRec, so as to support the }
- { Input and Output routines in Turbo Pascal. }
- Begin
- With TextRec( F ) Do
- begin
- Handle := $FFFF;
- Mode := fmOutput;
- BufSize := SizeOf(Buffer);
- BufPtr := @Buffer;
- BufPos := 0;
- OpenFunc := @NulRoutine;
- InOutFunc := @EchoOutput;
- FlushFunc := @EchoOutput;
- CloseFunc := @EchoOutput;
- UserData[1] := LptPort - 1; { We subtract one because }
- end; { Dos Counts from zero. }
- end;
-
- Begin { Initilization }
- LptPort := 1; { Default LPT port. Change this to }
- { output to a different LPT port. }
- AssignEcho( Echo ); { Setup the Echo device }
- End.
-