home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / BOBOLI.ZIP / SRC / COM.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-06-04  |  1.1 KB  |  51 lines

  1. /*
  2.   COM port library.
  3. */
  4.  
  5. #include "com.h"
  6.  
  7. byte data_rcvd=0;
  8. static unsigned short port;
  9. /* the various registers relative to the base port number */
  10. #define xmit_buf      (port)
  11. #define recv_buf      (port)
  12. #define baudset_lo    (port)
  13. #define baudset_hi    (port+1)
  14. #define line_control  (port+3)
  15. #define modem_control (port+4)
  16. #define line_status   (port+5)
  17. #define modem_status  (port+6)
  18.  
  19. void init_rs232(byte which) 
  20. {
  21.   short divisor;
  22.   byte divlow,divhigh;
  23.   byte settings;
  24.   if(which==0) {      /* com 1 */
  25.     port = 0x03F8;
  26.   } else {            /* com 2 */
  27.     port = 0x02F8;
  28.   }
  29.   settings=BITS_8|STOP_1|NO_PARITY;
  30.   divisor=115200/baud_rate;
  31.   disable();
  32.   outportb(line_control,settings|0x80);
  33.   outportb(baudset_lo,divisor&0xFF);
  34.   outportb(baudset_hi,(divisor>>8)&0xFF);
  35.   outportb(line_control,settings&0x7F);
  36.   enable();
  37. }
  38.  
  39. void send_packet(byte packet)
  40. {
  41.   while(~inportb(line_status)&0x20);
  42.   outportb(xmit_buf,packet);
  43. }
  44.  
  45. byte recv_packet(void)
  46. {
  47.   if(!(inportb(line_status)&1)) return 0; /* nothing to receive yet */
  48.   data_rcvd=1;
  49.   return(inportb(recv_buf));
  50. }
  51.