!pr3
A CALL Utility for Applesoft...................David C. Johnson
                                            Applied Engineering

Anyone who has ever used Applesoft eventually realizes that the most powerful statement in the language is CALL.  It allows you to get to the Monitor for instance (however, Extended Debugging Monitor users have a better way).  When writing a program in BASIC, you invariably will want to do something that is at best difficult and often impossible to code using the other Applesoft statements.

The solution to this type of situation is to speak to your Apple in its native tongue.  There are several way this can be done.  Ampersand (&) routines are a popular technique.  The USR( function even has its uses.  The most logical way, for me, is the CALL statement.

Using CALL neatly transfers control from the Applesoft interpreter to whatever you want to do in machine language.  The one disadvantage to CALL is that the processor's registers do not contain useful data when your machine code gets control.

The CALL utility presented in this article will allow you to specify, as part of the CALL statement, the contents of any or all of the registers upon entry of your machine language subroutine.  You assign the register contents with LET-like structures.  Obviously you can only fit an 8 bit value into the 8 bit registers and the program counter value will probably be a 16 bit number.  Here's how the CALL statement should be written:

         CALL 768,PC=word,A=byte,X=byte,Y=byte,P=byte

The expressions "word" and "byte" may be any valid Applesoft numeric expression.  This is because the utility calls routines internal to Applesoft to evaluate the expressions.  If an expression results in a value larger than the register to which it is being assigned, or isn't numeric, or is invalid, you will get one of the usual errors.  The commas shown separating the register assignments are required (syntax error if comma missing).  The equals characters ("=") are also required.  The register names ( PC, A, X, Y, & P) must be upper case on older Apples, while the newer firmware will convert lower case for you (or in spite of you).  The register assignments may appear, after the first comma, in any order and need not all be specified.  Unspecified registers will be loaded with their last used value.  Previously unused registers default to zero, except the P-register which defaults to $04 in order to set the interrupt disable flag.

The program is well commented, but I'll add one more note of caution. Readers with Apples containing reqular 6502s (not 65C02s or 65802s) should avoid re-assembling the code with the label PC.Sav's bytes falling across a page boundary ($XXFF).

The program was written using the ProDOS version of the S-C Macro Assembler 2.0, while I was beta testing it for Bob.  It works GREAT!
