home *** CD-ROM | disk | FTP | other *** search
-
- Comm_TP4.PAS Ver. 1.01, RS-232 Support for the IBM PC - Documention
-
- Author: Kevin R. Bulgrien
- February, 1989
-
- LeTourneau College
- Microcomputer Services
- P.O. Box 7001
- Longview, TX 75607
-
-
- INTRODUCTION
-
- This utility is an answer to the many public domain serial port routines which
- I have acquired in the quest for good RS-232 support under Turbo Pascal. Unlike
- the others, this one works. Not only does it work, but it also allows you to
- use both COM1 and COM2 at the same time. Designed to be relatively simple and
- easy to use, I hope many will benefit from it.
-
- This code only works under Turbo Pascal versions 4.0 and 5.0. For functionally
- equivalent routines that work under Turbo Pascal 3.0, look for COMM_TP3. Also,
- a Turbo C version called COMM_TC2 is available. While it was written for Turbo
- C 2.0, it will probably also work for lower versions.
-
-
- DISTRIBUTION POLICY
-
- This package may be used in any application without restriction, although I do
- ask that it is not distributed in a modified form unless you give credit where
- credit is due. This document must always accompany the software as well. The
- files which make up this package are called COMM_TP4.PAS and COMM_TP4.DOC.
-
-
- CREDITS
-
- Credit for this product must go to the various authors who showed me that if I
- wanted something that worked, I would have to write it myself - I won't bother
- to mention their names. The most credit, however, must go to the book "Systems
- Software Tools" by Ted J. Biggerstaff. I was amazed to find a book that so
- clearly outlined the IBM PC interrupt and serial port hardware. The world of
- IBM PC technical information is a desert, and this book is a rare oasis in the
- midst of it.
-
-
- FEATURES
-
- - Interrupt driven receive routine
- - Easily expandable interrupt routine
- - Uninstalls the interrupt handlers on abnormal program termination
- - Carrier Detect monitoring for modem support
- - COM1 & COM2 simultaneously supported
- - Example TTY and Port Setup routines included
- - Easy to use even if you don't understand how it works
- - Turbo Pascal 4.0 & 5.0 compatible source code
- - The price tag reads "FREE"
-
-
- DISCLAIMER
-
- While the author has extensively tested the routines in this package, he will
- not be held responsible for any consequence arising from the use thereof. It
- is the responsibility of the user to determine whether or not the enclosed
- routines will satisfactorily perform the required functions.
-
-
- GETTING STARTED - DOES IT REALLY WORK?
-
- If you want to prove that these routines really work, just run the program as
- it is distributed. What you will see is a crude terminal emulation program
- that is capable of receiving information from both COM ports at the same time.
- The screen echoes data from the "logged" COM port and buffers the data from
- the other port. When the other COM port is logged, the buffered data is sent
- to the screen. Also provided is a setup routine that lets you select a baud
- rate from 110 to 38400. The other protocol attributes are also selectable.
-
-
- SETTING COMM_TP4 UP TO USE IN YOUR OWN PROGRAMS
-
- Important Note: Never compile interrupt driven routines with the stack
- checking code enabled. Doing so will cause the program to
- crash whenever the interrupt is invoked.
-
- In order to use the serial routines, you may remove all of the extra code that
- is included for the TTY example routines. It is not important for you to
- understand how the routines work, but the following declarations are not
- optional and are required for normal RS-232 operation:
-
- USES DOS, CRT;
-
- CONST
- MaxSize = 511; { This is the input buffer size, and you may change it }
-
- TYPE
- INS8250 = RECORD
- THR : INTEGER;
- RHR : INTEGER;
- DLL : INTEGER;
- IER : INTEGER;
- DLM : INTEGER;
- IIR : INTEGER;
- LCR : INTEGER;
- MCR : INTEGER;
- LSR : INTEGER;
- MSR : INTEGER;
- END;
-
- ComSettingsRecord = RECORD
- Baud : BYTE;
- Parity : BYTE;
- Stop : BYTE;
- Bits : BYTE;
- END;
-
- ComSettingsType = ARRAY [1..2] OF ComSettingsRecord;
- ComBuffersType = ARRAY [1..2, 0..MaxSize] OF BYTE;
-
- CONST
- RS232 : ARRAY [1..2] OF INS8250 = ( ( THR:$3F8; RHR:$3F8; DLL:$3F8;
- IER:$3F9; DLM:$3F9; IIR:$3FA;
- LCR:$3FB; MCR:$3FC; LSR:$3FD;
- MSR:$3FE ),
- ( THR:$2F8; RHR:$2F8; DLL:$2F8;
- IER:$2F9; DLM:$2F9; IIR:$2FA;
- LCR:$2FB; MCR:$2FC; LSR:$2FD;
- MSR:$2FE ) );
-
- VAR
- IntInstalled : ARRAY [1..2] OF BOOLEAN;
- OldIntVector : ARRAY [1..2] OF POINTER;
- InHead, InTail : ARRAY [1..2] OF WORD;
- Carrier : ARRAY [1..2] OF BOOLEAN;
- ComSettings : ComSettingsType;
- InBuffer : ComBuffersType;
- ExitSave : POINTER;
- MaxPorts : WORD;
- Regs : REGISTERS;
-
- PROCEDURE DisableInts; INLINE ($FA);
- PROCEDURE EnableInts; INLINE ($FB);
- PROCEDURE SetupRS232 (Com, Baud, Parity, StopBits, DataBits : BYTE);
- PROCEDURE IntHandler; INTERRUPT;
- PROCEDURE InstallInt (Com : BYTE);
- PROCEDURE RemoveInt (Com : BYTE);
- PROCEDURE RemoveIntOnExit;
- FUNCTION Equipment : WORD;
-
- The following declarations are optional in that you can write your own routines
- to actually send and receive RS-232 information in the form that you wish to
- send it. They are not optional if you do not write your own replacements.
-
- PROCEDURE WriteCOM (Com : BYTE; Data : STRING);
- FUNCTION ReadCOM (Com : BYTE) : CHAR;
-
- These routines are relevant only to the TTY emulation, but you may be able to
- use them to better understand how to use the actual port routines:
-
- PROCEDURE SetUpPort (Com : BYTE);
- PROCEDURE TTY (LocalEcho : BOOLEAN);
-
- The main program MUST include the following code as it will cause the program
- to safely remove the interrupt handlers no matter how the program terminates:
-
- BEGIN
- ExitSave := ExitProc;
- ExitProc := @RemoveIntOnExit;
- IntInstalled [1] := FALSE;
- IntInstalled [2] := FALSE;
-
- { MaxPorts provides error checking in some of the required procedures }
-
- MaxPorts := (Equipment AND $0E00) SHR 9;
-
- { The rest of your program body goes here }
-
- END.
-
-
- HOW TO USE THE INTERRUPT HANDLERS IN YOUR PROGRAM
-
- At any time you may invoke SetupRS232 to change the settings of the COM ports.
- Unless you are sure the port is already set up correctly, you should invoke
- SetupRS232 before you install the interrupt with InstallInt.
-
- You may install either COM1, COM2 or both with InstallInt at any time and in
- any order.
-
- You may uninstall either COM1, COM2 or both with RemoveInt at any time and in
- any order.
-
- To read data that has come in from the port, one of the following is required:
-
- 1) FUNCTION ReadCOM (Com : BYTE) : CHAR;
-
- where Com is 1 or 2 for COM1 or COM2. If no data is available, this
- routine waits until it arrives.
-
- 2) DisableInts;
- CharReady := InTail [Com] <> InHead [Com];
- EnableInts;
-
- where CharReady is a user defined BOOLEAN that will be TRUE if data is
- waiting in the buffer or FALSE if not data is waiting.
-
- DisableInts;
- CharData := CHR(InBuffer [Com, InHead [Com]]);
- InHead [Com] := (InHead [Com] + 1) MOD (MaxSize + 1);
- EnableInts;
-
- where CharData is a user defined CHAR variable that will contain the
- next item in the buffer IF AND ONLY IF CharReady is TRUE. The item is
- removed from the buffer with the statement following the assignment.
-
- NEVER omit the DisableInts and EnableInts from these program fragments.
- To do so would cause the program to operate unpredicatably.
-
- To write data to the port, use one of the following methods:
-
- 1) PROCEDURE WriteCOM (Com : BYTE; Data : STRING);
-
- where Com is the 1 or 2 for COM1 or COM2 and Data is either STRING or
- CHAR data to be sent to the port. This routine will pause until all of
- the data has been sent.
-
- 2) PortReady := ((PORT [RS232 [Com].LSR] AND $20) = $20);
-
- where PortReady is a user defined BOOLEAN variable which will be TRUE
- if the port Transmitter Holding Register is ready for a character to
- send to the port.
-
- PortReady := PortReady AND ((PORT [RS232 [Com].MSR] AND $30) = $30);
-
- This statement allows you to see if the CTS and DTR lines indicate that
- the other serial device is ready to receive data. It may be omitted if
- you do not want to check these lines.
-
- DisableInts;
- PORT [RS232 [Com].LCR] := PORT [RS232 [Com].LCR] AND $7F;
- PORT [RS232 [Com].THR] := ORD (CharData);
- EnableInts;
-
- where CharData is a userdefined CHAR variable that contains a character
- to send to the port. PortReady MUST be TRUE before placing this data
- in the Transmitter Holding Register otherwise the previous data item
- will be lost.
-
- NEVER omit the DisableInts and EnableInts from these program fragments.
- To do so would cause the program to operate unpredicatably.
-
-
- SUPPORT
-
- User support may be obtained by contacting me via the LeTourneau College BBS
- at (214) 237-2742. The BBS runs 24 hours a day and accepts calls at 300, 1200,
- and 2400 baud. Since I am the SysOp of this board, this is the fastest way to
- reach me. My GEnie mail address is K.BULGRIEN, but money being at a premium,
- I do not always check in on a regular basis. I may also be reached during
- business hours at (214) 753-0231 ext. 352.
-
- Support will be limited to clarification of the routines I wrote. I will not
- debug your routines or enhance my routines for your specific application.
-
-
- UPDATES
-
- I will place updates of the enclosed routines on LeTourneau College BBS at
- (214) 237-2742. The BBS runs 24 hours a day and accepts calls at 300, 1200,
- and 2400 baud.
-
- I will also place updates in the BORLAND RT on the GEnie information service.
-
- Possible updates may include:
-
- 1) An interrupt driven transmitter
- 2) More complete support of the Modem Status interrupt
- 3) Support of the Line Status interrupt
- 4) Support additional COM ports
- 5) Miscellaneous enhancements
- 6) Bug fixes
-
-
- VERSION HISTORY
-
- 1.00 11/88 The original version placed in the Borland Roundtable on GEnie.
- 1.01 02/89 Bug fix in Procedure RemoveInt. It correctly uninstalled the
- interrupt code except that it would disable all IRQ interrupts
- except the one used by the specified COM port. (An AND instead
- of an OR in the statement writing to PORT [$21]. Uploaded the
- new version to GEnie to replace the old one.
-
- THE END