INP - mkilgore/QB64pe GitHub Wiki

INP returns a value from a computer register or port values at a specified physical address.

Syntax

i = INP(address)
  • QB64 has limited access to registers. VGA memory and registers are emulated.
  • Address can be a decimal or hexadecimal INTEGER value.
  • INP reads directly from a register or port address.
  • It does not require a DEF SEG memory segment address like PEEK or POKE do.
  • Reads color port intensity settings after OUT &H3C7, attribute sets the starting attribute read mode.

Examples

Example 1: Reading the current RGB color settings used in a bitmap to an array.

 '' ''
 SCREEN 12
 DIM Colors%(47)
 OUT &H3C7, 0 ' set color port for INP reads at attribute 0 to start
 FOR...NEXT i = 0 TO 47
 Colors%(i) = INP(&H3C9) ' moves to next color attribute every 3 loops
 NEXT '' ''

Example 2: Reading the keyboard Scan Codes as an alternative to INKEY$

 '' ''
 DO: SLEEP
    scancode% = INP(&H60)
    a$ = INKEY$ ' clears keyboard buffer
    PRINT scancode%; 
 LOOP UNTIL scancode% = 1 ' [ESC] keypress exit '' ''

Example 3: A simple ping pong game using an array function to read multiple keys for two players.

begin:
xmin = 10: ymin = 10
xmax = 630: ymax = 470
x = 25: y = 25
dx = 1: dy = 1
LTpos = 50: RTpos = 50

DO: _LIMIT 100 'adjust higher for faster
CLS
IF...THEN ScanKey%(17) THEN LTpos = LTpos - 1
IF...THEN ScanKey%(31) THEN LTpos = LTpos + 1
IF...THEN ScanKey%(72) THEN RTpos = RTpos - 1
IF...THEN ScanKey%(80) THEN RTpos = RTpos + 1

PRINT "Player 1 : "; ponescore; " Player 2 : "; ptwoscore

IF...THEN x > xmax - 15 AND (boolean) y >= RTpos AND (boolean) y <= RTpos + 100 THEN
dx = -1
ELSEIF x > xmax THEN
ponescore = ponescore + 1
GOSUB begin
END IF

IF...THEN x < xmin + 15 AND (boolean) y >= LTpos AND (boolean) y <= LTpos + 100 THEN
dx = 1
ELSEIF x < xmin THEN
ptwoscore = ptwoscore + 1
GOSUB begin
END IF

IF...THEN y > ymax - 5 THEN dy = -1
IF...THEN y < ymin + 5 THEN dy = 1
' Display the sprite elsewhere on the screen

x = x + dx
y = y + dy

PUT (graphics statement)(x, y), ball%(0)


LINE (20, LTpos)-(20, LTpos + 100)
LINE (620, RTpos)-(620, RTpos + 100)

_DISPLAY 'shows completed screen every call

LOOP UNTIL ScanKey%(1)
END


FUNCTION ScanKey% (scancode%)
STATIC Ready%, keyflags%()
IF...THEN NOT Ready% THEN REDIM keyflags%(0 TO 127): Ready% = -1
i% = INP(&H60) 'read keyboard states
IF...THEN (i% AND (boolean) 128) THEN keyflags%(i% XOR (boolean) 128) = 0
IF...THEN (i% AND (boolean) 128) = 0 THEN keyflags%(i%) = -1
K$ = INKEY$
ScanKey% = keyflags%(scancode%)
END FUNCTION '' ''
Note: _KEYDOWN can be used to read multiple keys simultaneously and is the recommended practice.

See also

External Links


Navigation:
Go to Keyword Reference - Alphabetical
Go to Keyword Reference - By usage
Go to Main WIKI Page
⚠️ **GitHub.com Fallback** ⚠️