Q(uick)BASIC Function: INP

Quick View

INP

A device I/O function that returns the byte read from an I/O port

Worth knowing

Useful and cross-version information about the programming environments of QBasic and QuickBasic.

Syntax
  • INP(port%)
  • OUT port%, data%
Description/Parameter(s)
port% A number in the range 0 through 65,535 that identifies the port.
data% A numeric expression in the range 0 through 255 to send to the port.
Example
x% = INP(&H3FC) 'Read COM1 Modem Control Register. OUT &H3FC, (x% XOR 1) 'Change Data Terminal Ready bit.

See also:

Syntax
  • INP(port)
Description/Parameter(s)

The port must be an integer in the range 0-65,535. The INP function complements the OUT statement.

The INP and OUT statements give a BASIC program direct control over the hardware in a system through the I/O ports. These statements must be used carefully because they directly manipulate the system hardware.

Example

See the OUT statement programming example , which uses both the INP and the OUT statements.

Syntax
  • INP(port)
Description/Parameter(s)

Usage Notes

  • The INP function complements the OUT statement, which sends a byte to a hardware I/O port.
  • INP and OUT give a BASIC program direct control over the hardware in a system through the I/O ports. INP and OUT must be used carefully because they directly manipulate the system hardware.
Example

This example uses the OUT statement and the INP function to control the timer and speaker to produce a note.

'Play a scale using speaker and timer. CONST WHOLE = 5000!, QRTR = WHOLE / 4! CONST C = 523!, D = 587.33, E = 659.26, F = 698.46, G = 783.99, A = 880! CONST B = 987.77, C1 = 1046.5 CALL Sounds(C, QRTR): CALL Sounds(D, QRTR) CALL Sounds(E, QRTR): CALL Sounds(F, QRTR) CALL Sounds(G, QRTR): CALL Sounds(A, QRTR) CALL Sounds(B, QRTR): CALL Sounds(C1, WHOLE) SUB Sounds (Freq!, Length!) STATIC 'Ports 66, 67, and 97 control timer and speaker. 'Divide clock frequency by sound frequency 'to get number of "clicks" clock must produce. Clicks% = CINT(1193280! / Freq!) LoByte% = Clicks% AND &HFF HiByte% = Clicks% \ 256 'Tell timer that data is coming. OUT 67, 182 'Send count to timer. OUT 66, LoByte% OUT 66, HiByte% 'Turn speaker on by setting bits 0 and 1 of PPI chip. SpkrOn% = INP(97) OR &H3 OUT 97, SpkrOn% 'Leave speaker on. FOR I! = 1 TO Length!: NEXT I! 'Turn speaker off. SpkrOff% = INP(97) AND &HFC OUT 97, SpkrOff% END SUB