home *** CD-ROM | disk | FTP | other *** search
/ POINT Software Programming / PPROG1.ISO / basic / bmag / qbcom4.bas < prev    next >
Encoding:
BASIC Source File  |  1994-04-13  |  3.4 KB  |  110 lines

  1. '─ Area: F-QUICKBASIC ─────────────────────────────────────────────────────────
  2. '  Msg#: 311                                          Date: 10 Apr 94  12:36:00
  3. '  From: Michael Parker                               Read: Yes    Replied: No 
  4. '    To: Bryan Copeland                               Mark:                     
  5. '  Subj: Re: Qbasic with COM4
  6. '──────────────────────────────────────────────────────────────────────────────
  7. 'OOPS! I JUST FOUDN SOMETHING! HERE IT IS!
  8. ' Quick Basic Routine OpenCom
  9. ' This routine will accept the entire OPEN command parameters
  10. ' that is in QB 4.5 , the only exception is the baud rate and
  11. ' COM port.  Baud rate is optional, if specified, this module
  12. ' will set the specifed rate up to 115,200.  If the baud rate
  13. ' is specifed at 0, the specifed port will be polled  for the
  14. ' current baud rate and the baud rate will be set at the rate
  15. ' that is present, if any.  NOTE:  the baud rate parameter on
  16. ' the command line IS  NOT optional,  if you want this module
  17. ' to set the baud rate,  put an extra comma  into the command
  18. ' line to replace the baud rate.  The COM Port will accept up
  19. ' to COM 4 now.
  20.  
  21. ' OPENCOM "COMX:{option list1 [baudrate,parity,databit]},{option list2}
  22. ' AS FileNum"
  23. ' examples:
  24. ' OPENCOM "COM1:38400 as 1"
  25. ' OPENCOM "COM4:,op500 as 1"
  26. ' OPENCOM "COM2:2400,n,8,1,op500 as 4"
  27. ' OPENCOM "COM3:,,, OP500 as 2"
  28.  
  29. DECLARE SUB OPENCOM (InString$)
  30. CALL OPENCOM(InString$)
  31. END
  32.  
  33. SUB OPENCOM (Sting$)
  34. Sting$ = LTRIM$(RTRIM$(Sting$))
  35. Port$ = UCASE$(LEFT$(Sting$, 5))
  36. Sting$ = RIGHT$(Sting$, LEN(Sting$) - 5)
  37. FOR x = 1 TO LEN(Sting$)
  38.      H$ = MID$(Sting$, x, 1)
  39.      IF UCASE$(H$) = "A" THEN
  40.           H$ = H$ + MID$(Sting$, x + 1, 1)
  41.           IF UCASE$(H$) = "AS" THEN
  42.                 FileNum = VAL(MID$(Sting$, x + 2, LEN(Sting$)))
  43.                 EXIT FOR
  44.           END IF
  45.      END IF
  46.      InputString$ = InputString$ + H$
  47. NEXT x
  48. FOR x = 1 TO LEN(InputString$)
  49.      IF MID$(InputString$, x, 1) <> "," THEN
  50.           BaudRate$ = BaudRate$ + MID$(InputString$, x, 1)
  51.      ELSE
  52.           InputString$ = MID$(InputString$, x + 1, LEN(InputString$))
  53.           EXIT FOR
  54.      END IF
  55. NEXT x
  56. IF LTRIM$(BaudRate$) = "" THEN
  57.      BaudRate& = 0
  58. END IF
  59. SELECT CASE Port$
  60.      CASE "COM1:"
  61.           BaseAddr% = &H3F8
  62.           Port1$ = "COM1:"
  63.      CASE "COM2:"
  64.           BaseAddr% = &H2F8
  65.           Port1$ = "COM2:"
  66.      CASE "COM3:"
  67.           BaseAddr% = &H2F8
  68.           Port1$ = "COM1:"
  69.      CASE "COM4:"
  70.           BaseAddr% = &H3F8
  71.           Port1$ = "COM2:"
  72.      CASE ELSE
  73.           PRINT "Illegal COM Port"
  74. END SELECT
  75.  
  76. IF BaudRate$ = "" THEN
  77.      OUT BaseAddr% + 3, INP(BaseAddr% + 3) OR &H80
  78.      LSB% = INP(BaseAddr%)
  79.      MSB% = INP(BaseAddr% + 1)
  80.      OUT BaseAddr% + 3, INP(BaseAddr% + 3) AND &H7F
  81.      Divisor& = MSB% * &H100 + LSB%
  82.      IF Divisor& = 0 THEN
  83.           BaudRate& = 0
  84.      ELSE
  85.           BaudRate& = 115200 / Divisor&
  86.      END IF
  87. ELSE
  88.      BaudRate& = VAL(BaudRate$)
  89. END IF
  90. IF LEFT$(InputString$, 1) <> "," THEN
  91.      InputString$ = "," + InputString$
  92. END IF
  93. OPEN Port1$ + "300" + InputString$ FOR RANDOM AS FileNum
  94. IF Port$ = "COM3:" THEN
  95.      POKE &H400, &HE8
  96. ELSEIF Port$ = "COM4:" THEN
  97.      POKE &H402, &HE8
  98. END IF
  99. IF BaudRate& <> 0 THEN
  100.      Divisors# = 115200 / BaudRate&
  101. END IF
  102. LCR = BaseAddr% + 3
  103. Temp = INP(LCR)
  104. OUT LCR, Temp OR 128
  105. OUT BaseAddr% + 1, INT(Divisors# / 256)
  106. OUT BaseAddr%, Divisors#
  107. OUT LCR, Temp AND 127
  108.  
  109. END SUB
  110.