1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27

4.2 Reading paddles/joysticks

Up to 4 single-axis analog devices can be connected to an Apple II;
these can be either paddles or 2-axis joysicks. The 'PDL(n)' command
reads a single axis. n=0 for the first paddle or the horizontal axis
of a joystick, n=1 for the second paddle or the vertical axis of a
joystick (n=2,3 for the third and fourth paddles or second joystick).
PDL() returns a value between 0 and 255; the 'center' is approximately
127. There should be a slight pause between calls to PDL to allow the
hardware time to recover from the analog reading and prepare for
another. A quick FOR-NEXT loop does the job nicely: 'XP%=PDL(0): FOR
PD=1 TO 10:NEXT: YP%=PDL(1)'

Using a paddle number greater than 3 is a BAD idea-- you'll blindly
stomp over various softswitches, which can have very disastrous
effects on your computer.

Button #n (n==0..2) can be read with a 'PEEK (49249+n)'. If the
returned value is <127, it's being pressed or is not connected. There
is no way to tell in Applesoft whether a 'button down' is due to a
paddle/joystick or the corresponding apple key. [Open-apple (command)
on the keyboard appears like button 0, closed apple (option) appears
like button 1]

4.3 Program comments

Anything following a 'REM' command until the end of the line is
regarded as a comment, even if it's valid code. 'REM GOTO 500: GOTO
500' is just a comment, and neither GOTO will work.

4.4 Internal Data Storage.

Applesoft allows you to store a number of numeric or string constants
within your code and get them. The format for storing them is 'DATA
const1[,const2[,const3]]', with string constants enclosed in quotes.
To read them, use 'READ varb1[,varb2[,varb3]]'. The position of the
DATA and READ statements in the body program doesn't matter, but you
should READ out elements from your DATAs with the correct variable
type to avoid an error.

The DATA list is sequential access only-- it starts at the first DATA
in the code and works its way down, one element at a time. The
'RESTORE' command resets the DATA list pointer to the first DATA
statement in the program. [Unlike other BASICs, there is no way to
restore to an arbitrary data index number or data line number; you'll
have to manually do other things.]

4.5 Error Handling

Applesoft lets you define a section of your code that'll be executed
when an error occurs. Use 'ONERR GOTO line' to jump to that line when
an error occurrs; only one line can be specified. At that time, use
'PEEK(222)' to get the error code number. 'RESUME' will attempt to go
back to where the error happened if you've dealt with it, however, if
in the middle of a FOR-NEXT loop or a subroutine call, you cannot use
RESUME correctly without running a short machine-language patch for a
bug.

Also note that due to a bug, any program statements after the onerr
are ignored.

'POKE 216,0' will cancel any pending ONERR. It is recommended that
thisPOKE be the first statement of your error handling routine, to
prevent any errors in the error handler from calling the error
handling again.