Commodore 128 Programmer's Reference Manual page 403

Hide thumbs Also See for 128:
Table of Contents

Advertisement

n
n
n
n
n
n
INPUT/OUTPUT GUIDE
393
LIGHT PEN
The light pen input latches the current screen position into a pair of registers (LPX,
LPY) on a low-going edge. The X position register 53267 ($D013) will contain the 8 MSB
of the X position at the time of transition. Since the X position is defined by a 512-state
counter (9 bits), resolution to two horizontal dots is provided. Similarly, the Y position
is latched in its register 53268 ($D014), but here 8 bits provide single raster resolution
within the visible display. The light pen latch may be triggered only once per frame, and
subsequent triggers within the same frame will have no effect. Therefore, you must take
several samples before turning the pen to the screen (three or more samples average),
depending upon the characteristics of your light pen. The following program is a light
pen draw routine in C128 mode:
10
REM C128 MODE LIGHT PEN DRAW ROUTINE
20 REM PLACE LIGHT PEN IN CONTROLLER PORT 1
_
30 COLOR 0,2:COLOR 4,2:COLOR 1,1:REM SELECT SCREEN COLORS
I
40 GRAPHIC 1,1:REM SELECT BIT MAP MODE
50
DO
60
:
X=PEN(0)
:REM GET HORIZONTAL COORDINATE
70
:
Y=PEN(1)
:REM GET VERTICAL COORDINATE
80
:
DRAW
1,X,Y
:REM PLOT POINT
90 LOOP
:REM DO
IT AGAIN
100
:
110
REM
IF YOU LIKE THE DRAWING,
120 REM
BREAK THE PROGRAM AND
130
REM
SAVE
IT AS A BINARY FILE
140
REM
FROM $2000-$3FFF.
OUTPUT CONTROL TO
ALL DEVICES
Each peripheral device is identified by a device number, as listed in Table 12-3.
DEVICE
Keyboard
Datasette
Modem (RS232)
Screen
Printer
Disk Drive
DEVICE NUMBER
0
1
2
3
4 or 5
8,9,10,11
SECONDARY ADDRESSES
0,1,2
0
0,1
0,7,etc
2-14,15
Table 12-3. Device Numbers
Serial devices can be numbered 4 through 30, but they usually conform to the
above conventions. All devices can be accessed in a single OPEN statement by using
an integer variable:

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents