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 / CPM / TURBOPAS / PASPRINT.TXT < prev    next >
Text File  |  2000-06-30  |  3KB  |  77 lines

  1. TURBO PASCAL CORNER ............................................... Rick Ryall
  2.  
  3.      For those of you who program in Pascal, this column will be dedicated to
  4. sharing some things that I have discovered in the course of using Borland's
  5. excellent implementation of that language.  I will try to cover both CP/M and
  6. MS-DOS versions, to keep almost everybody happy.
  7.  
  8.      This month's installment deals with avoiding the problem that occurs when
  9. an attempt is made to send a character to a printer that is not connected to
  10. the computer, which hangs up the system until the printer is connected or the
  11. computer is reset.  It would be nice to test the printer port before sending a
  12. character out to see if the printer is ready to receive one.  Fortunately,
  13. there is a way to do just this.
  14.  
  15. FUNCTION PrinterReady : boolean;                 FUNCTION PrinterReady : boolean;
  16. type RegisterRecord =                            const
  17.   record case integer of                           Status = 14;
  18.     1:(AX,BX,CX,DX,BP,SI,DI,ES,Flags:integer);   begin { PrinterReady, CP/M version }
  19.     2:(AL,AH,BL,BH,CL,CH,DL,DH: byte);             PrinterReady:= ( Bios(Status)=255 );
  20.   end;                                           end;  { PrinterReady }
  21. var
  22.   Status : byte;
  23.   Registers : RegisterRecord;
  24.  
  25. begin { PrinterReady, MS-DOS version }
  26.   { initialize registers }
  27.   fillchar( Registers,sizeof( Registers ),0 );
  28.   with Registers do
  29.   begin
  30.     AH:= $01;                { code for reset printer }
  31.     DL:= $00;                { printer number, 0= COM1 }
  32.     intr( $17, Registers );  { reset printer port }
  33.     AH:= $02;                { code for get printer status }
  34.     DL:= $00;                { printer number }
  35.     intr( $17, Registers );  { get printer status }
  36.     Status:= AH;
  37.   end;
  38.   PrinterReady:= not Odd( Status shr 4 );
  39. end;  { PrinterReady }
  40.  
  41.  
  42.      The CP/M version is fairly straightforward and shouldn't require too much
  43. explanation.
  44.  
  45.      There are two things worth noting in the MS-DOS example above:  1).  The
  46. printer port must be reset before the status byte is returned correctly (they
  47. don't tell you this in the reference manuals)  2).  The type declaration could
  48. be a global declaration instead of a local one, since the register type is
  49. used for all interrupts and function calls in the MS-DOS version of Turbo
  50. Pascal.
  51.  
  52.      Below is an example of how this function might be used to prevent hanging
  53. up a program if someone has neglected to connect or turn on their printer.
  54. That's it for this month.
  55.  
  56. PROCEDURE CheckPrinterStatus;
  57. const
  58.   Return = ^M;
  59.   ESC    = #27;
  60. var
  61.   Key : char;
  62.   Interrupted : boolean;
  63. begin
  64.   Interrupted:= false;
  65.   while not( PrinterReady or Interrupted ) do
  66.   begin
  67.     gotoXY(1,3);
  68.     write( 'Please check your printer and press RETURN to continue, or ESC to exit' );
  69.     ClrEol;
  70.     repeat
  71.       read( Kbd, Key );
  72.       if ( Key = ESC ) and not KeyPressed then Interrupted:= true;
  73.       { not KeyPressed is required for MS-DOS only }
  74.     until ( Key = Return ) or Interrupted;
  75.   end;
  76. end;  { CheckPrinterStatus }
  77.