home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 2 / ctrom_ii_b.zip / ctrom_ii_b / PROGRAM / PASCAL / PASTUT34 / COMPORT.TXT < prev    next >
Text File  |  1993-06-12  |  5KB  |  141 lines

  1.  
  2.          DIRECT MEMORY AND PORT ACCESS AND COMMUNICATION.
  3.          ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
  4.  
  5.  Memory access.
  6.  ══════════════
  7.  Mem  {byte}        )
  8.  MemW {word}        )   are used to directly access memory.
  9.  MemL {longint}     )
  10.  
  11.  e.g.  Mem[$0040:$0049] := 7;
  12.  
  13.        stores the value 7 in the byte of memory at $0040:$0049.
  14.  
  15.        Data := MemW[Seg(V):Ofs(V)];
  16.  
  17.        moves the word value stored in the first two bytes of the
  18.        variable V into the variable Data.
  19.  
  20.        MemLong := MemL[64:3*4];
  21.  
  22.        MemLong variable takes the value stored at $0040:$000C.
  23.  
  24.  
  25.  Port access.
  26.  ════════════
  27.  Port  {byte}    )   are one-dimensional arrays, each element
  28.                  )   representing a data port, whose port address
  29.  PortW {word}    )   corresponds to its index.
  30.  
  31.  When a value is assigned to a component of Port or PortW, the value is
  32.  sent as output to the selected port.
  33.  When a component of Port or PortW is referenced in an expression, its
  34.  value is received as input from the selected port.
  35.  
  36.  e.g.  port[data_port_low] := low_order_byte;
  37.  
  38.        where data_port_low and low_order_byte have been previously evaluated.
  39.  
  40.        test := port[data_port_low + 2] div 128;
  41.  
  42.  
  43.  Communication.
  44.  ══════════════
  45.  A Unit called 'AuxInOut' implements a text file device driver for the
  46.  communication ports (serial) of an IBM PC. This unit is shown on pages
  47.  213-5 of the Reference Guide (version 5.5) and itself uses procedures
  48.  and functions which call short 'in-line' machine code. This unit also
  49.  uses the DOS unit, which defines TestRec used by AuxInOut.
  50.  
  51.  The inline machine code procedures and functions use the four BIOS
  52.  interrupts $14/$00, $14/$01, $14/$02 and $14/$03 (see pages 38-40 of 'DOS
  53.  and BIOS Functions' (Que Corporation). 
  54.  
  55.  Interrupt $14/$00, Initialize Communications Port, requires that the AL
  56.  register contains  a parameter evaluated as follows: 
  57.  
  58.       Bits 7,6,5        Bits 4,3        Bit2          Bits 1,0 
  59.       Baud rate         Parity          Stop bits     Word length 
  60.       ---------         -------         ----------    ------------ 
  61.       000 = 110 baud    x0 = none       0 = 1 bit     10 = 7 bits 
  62.       001 = 150         01 = odd        1 = 2 bits    11 = 8 bits 
  63.       010 = 300         10 = none 
  64.       011 = 600         11 = even 
  65.       100 = 1200   
  66.       101 = 2400 
  67.       110 = 4800 
  68.       111 = 9600 
  69.  
  70.  
  71.  The following program uses the AuxInOut unit to write a string to one of
  72.  the communication ports. Through the AssignAux procedure, the Com1 file is
  73.  associated with the COM1 port, because the first parameter is COM1 and the
  74.  second parameter is 0, which must be placed in the DX register to identify
  75.  the port, COM1.                          
  76.  
  77.  In this case the following values apply: 1200 baud, no parity, 1 stop bit
  78.  and 8 data bits. Thus the value in AL must be 100 00 0 11 or 1000 0011 or 
  79.  $83
  80.  
  81.  program TestAux;
  82.  
  83.  uses AuxInOut;
  84.  
  85.  var
  86.     Com1 : text;
  87.  
  88.  begin
  89.     AssignAux(Com1,0,$83);
  90.     Rewrite(Com1);
  91.     Writeln(Com1,'Good morning. Any messages?');
  92.     Close(Com1);
  93.  end.
  94.  
  95.  
  96.  where the procedure AssignAux(var F:Text;Port,Params:word); indicates that
  97.  Text file = COM1, Port:=0 and Params:=$83 as evaluated above. 
  98.  
  99.  The unit AuxInOut is not mentioned in the manuals for version 6.0, but
  100.  Borland now provide the Async coms routines on a Pascal Utilities diskette.
  101.  The unit ASYNC4U has a function Async_Open, which has the following
  102.  parameters:    (ComPort  : Integer; 
  103.                  BaudRate : Integer; 
  104.                  Parity   : Char; 
  105.                  WordSize : Integer; 
  106.                  StopBits : Integer;)             
  107.  
  108.  
  109.  BLAISE Turbo Asynch Plus.
  110.  ═════════════════════════
  111.  Blaise Computing Inc., 2560 Ninth Street, Suite 316, Berkeley, CA 94710
  112.  produce Blaise Computing Power Tools Plus, which include Norton Guides,
  113.  and also Blaise Turbo Asynch Plus, which provides a set of communication
  114.  utilities.
  115.  
  116.  When communicating by means of the serial data ports, the data and the
  117.  control information are transmitted over a single line, one bit at a time.
  118.  With asynchronous communication, start and stop bits synchronise the
  119.  transmission. This compares with synchronous transmission of data which is
  120.  according to a definite time schedule.
  121.  
  122.  The Blaise utilities allow:  Open COM port, Close, Write, Read COM port,
  123.  Set and Return COM port options ( baud, parity, etc ).
  124.  
  125.  The standard IBM COM port addresses are as follows:
  126.  
  127.     Port           Base address.
  128.     ----           -------------
  129.  
  130.     COM1           $03F8
  131.     COM2           $02F8
  132.  
  133.  These addresses can be verified by use of the DOS command DEVICE (with some
  134.  versions of DOS). 
  135.  
  136.  
  137.  
  138.  COMPORT.TXT  
  139.  31.1.90 
  140.  10.10.92
  141.