PEN

From C64-Wiki
Jump to navigationJump to search
BASIC keyword
Keyword: PEN
Abbreviation: P Shift+E
Type: Function
Token code: 206/$CE 4/$04
Handling routine
in BASIC ROM:
List of all BASIC keywords


Remark: This article describes the BASIC function PEN in Commodore BASIC V7.0 or higher.

Type: Numeric Function 
General Programming-Syntax: PEN(<numeric-expression>)

The PEN command is a BASIC v7 function, used for reading the status of the light pen.

The numeric expression must be 0-4. Using any other number generates an ?ILLEGAL QUANTITY ERROR.

The PEN command returns a value depending upon the value that is supplied:

  • 0: The horizontal position of the light pen.
  • 1: The vertical position of the light pen. The first two values refer to the entire screen, not just the area that is accessible through drawing, leading to odd numerical ranges- the C128 system guide states, "The x position is given as a number, ranging from approximately 60 to 320, while the y position can be any number from 50 to 250."
  • 2: The text column position on the 80-column screen
  • 3: The text row position on the 80-column screen. The text position outputs only register when the pen is used on the 80-column screen; on the 40-column screen, they do not update, returning the last-returned value from the 80-column screen.
  • 4: Light pen button- 0=up, 1=down


Examples[edit | edit source]

10 COLOR 0,1:COLOR 1,2:COLOR 4,1
20 GRAPHIC 1,1
30 CHAR 1,10,0,"LIGHTPEN CALIBRATE"
40 CHAR 1,9,2,"CLICK WHITE LINE"
50 DRAW 1,159,48 TO 159,96
60 COLLISION 3,1000
70 DO:LOOP UNTIL KX
80 COLLISION 3
90 COLOR 0,2:COLOR 1,1
100 SCNCLR 1
110 COLLISION 3,2000
120 DO:GET K$:LOOP UNTIL K$="X"
999 END
1000 COLLISION 3:IF JOY(1) AND 1 THEN KX=PEN(0)-159
1010 COLLISION 3,1000:RETURN
2000 COLLISION 3:PX=PEN(0)-KX:PY=PEN(1)-50
2010 IF JOY(1) AND 1 THEN DRAW 1 TO PX,PY:ELSE LOCATE PX,PY
2020 COLLISION 3,1000:RETURN

A BASIC program for painting with a lightpen with a button on a 40 char screen in HiRes.

References[edit | edit source]


BASIC V7.0 Commands

ABS | AND | APPEND | ASC | ATN | AUTO | BACKUP | BANK | BEGIN | BEND | BLOAD | BOOT | BOX | BSAVE | BUMP | CATALOG | CHAR | CHR$ | CIRCLE | CLOSE | CLR | CMD | COLLECT | COLLISION | COLOR | CONCAT | CONT | COPY | COS | DATA | DCLEAR | DCLOSE | DEC | DEF FN | DELETE | DIM | DIRECTORY | DLOAD | DO | DOPEN | DRAW | DS | DS$ | DSAVE | DVERIFY | EL | ELSE | END | ENVELOPE | ER | ERR$ | EXIT | EXP | FAST | FETCH | FILTER | FN | FOR | FRE | GET | GET# | GETKEY | GO64 | GOSUB | GOTO | GRAPHIC | GSHAPE | HEADER | HELP | HEX$ | IF | INPUT | INPUT# | INSTR | INT | JOY | KEY | LEFT$ | LEN | LET | LIST | LOAD | LOCATE | LOG | LOOP | MID$ | MONITOR | MOVSPR | NEW | NEXT | NOT | (OFF) | ON | OPEN | OR | PAINT | PEEK | PEN | (PI) | PLAY | POINTER | POKE | POS | POT | PRINT | PRINT USING | PRINT# | PUDEF | (QUIT) | RCLR | RDOT | READ | RECORD | REM | RENAME | RENUMBER | RESTORE | RESUME | RETURN | RGR | RIGHT$ | RND | RREG | RSPCOLOR | RSPPOS | RSPRITE | RUN | RWINDOW | SAVE | SCALE | SCNCLR | SCRATCH | SGN | SIN | SLEEP | SLOW | SOUND | SPC( | SPRCOLOR | SPRDEF | SPRITE | SPRSAV | SQR | SSHAPE | ST | STASH | STEP | STOP | STR$ | SWAP | SYS | TAB( | TAN | TEMPO | THEN | TI | TI$ | TO | TRAP | TROFF | TRON | USR | VAL | VERIFY | VOL | WAIT | WHILE | WINDOW | WIDTH | XOR