Applesoft Internals: Using Applesoft ROM Subroutines (1 of 2)

The following notes, first published in The Apple Orchard (March 1980) are written for experienced 6502 machine language programmers who wish to use the Applesoft ROM subroutines. The addresses given are for an Apple II+ with an Applesoft firmware card, or Applesoft loaded into a Language Card.

Consult your Applesoft Reference manual for more information.
Take special note of CHRGET, the heart of Applesoft. When Applesoft wants the next character of an instruction, it points TXTPTR at the program or input buffer, and JSRs to CHRGET. TXTPTR is temporarily set to the last used DATA statement when Applesoft READS DATA.

ABBREVIATIONS

msb: most significant bit or byte
lsb: least significant bit or byte
eol: end of line token ($00)

A: the 6502 accumulator
X: the 6502 X register
Y: the 6502 Y register
Z: the zero flag of the 6502 status register
C: the carry flag of the 6502 status register

A,X is a 16 bit number where A has the msb and X the lsb.

(Y,A) is the number or string whose address is in Y and A, with the msb in Y and lsb in A.

FAC: the floating point accumulator
ARG: the ARGument register


TXTPTR Routines

CHRGET 00B1
CHRGET increments TXTPTR. Use CHRGOT to get the character. TXTPTR now points at:

CHRGOT 00B7
CHRGOT loads A from TXTPTR and sets certain 6502 status flags. X and Y are not changed. On exit:

A = the character currently pointed at by TXTPTR
Z is set if A is ":" or eol ($3A or $00)
C is clear if A is an ASCII number("0" to "9").

LINGET DA0C
LINGET read a line number (integer 0 to 63999) from TXTPTR into LINNUM. LINGET assumes the 6502 registers and A have been set up by the JSR to CHRGET that fetched the first digit. LINGET normally exits through CHARGET, which fetches the character after the last digit. When the number is greater than 63999, LINGET exits via SYNTAX ERROR. LINNUM is zero when there is no number at TXTPTR.

GTBYTC E6F5
GTBYTC causes JSR to CHRGET to gobble a character, then evaluates the formula at TXTPTR, and then it returns a single byte integer in X and FACLO. On entry TXTPTR points to the first character of the formula. GTBYTC normally exits through CHRGET. If FAC is greater than 255 or less than 0, it exits through ILLEGAL QUANTITY ERROR.

GETBYT E6F8
GETBYT evaluates the formula at TXTPTR besides returning a single byte integer in X and FACLO. On entry, TXTPTR points to the first character of the formula. GETBYT normally exits through CHRGET. When FAC is greater than 255 or less than 0, it exits through ILLEGAL QUANTITY ERROR.

PLOTFNS F1EC
PLOTFNS gets two LORES plotting coordinates separated by a comma from TXTPTR (0-47,0-47). TXTPTR when entered, points to the first number of the formula. PLOTFNS puts the first number in FIRST and the second number in H2 and V2.

HFNS F6B9
HGNS gets HIRES plotting coordinates (0-279,0-191) from TXTPTR. TXTPTR points to the first character of the formula for the first number upon entry. HFNS leaves the 6502 registers set up for HPOSN. When exiting:

A = vertical coordinate
X = lsb of horizontal coordinate
Y = msb of vertical coordinate


Device I/O Routines

INLIN D52C
Input a line of text without sending out a prompt from the current input device into the input buffer, BUF. INLIN uses GDBUF to strip off the most significant bit on all input characters.

INLIN+2 D52E
Input a line of text prompting with the character in X from the current input device into the input buffer, BUF. INLIN uses GDBUF to strip off the most significant bit on all input characters.

GDBUFS D539
Puts a zero at the end of the input buffer, BUF, and masks off the msb on all bytes. On entry: X = the end of the input line.
On exit:

A = 0
X = FF
Y = 1

INCHR D553
Get one character from the current input device in A and mask off the MSB. INCHR uses the main Apple input routines and supports normal handshaking.

STROUT DB3A
Print string pointed to by Y,A. The string must end with a null or a quote.

STRPRT DB3D
Print a string whose descriptor is pointed to by FACMO,FACLO.

OUTDO DB5C
Print the character in A. INVERSE, FLASH, and NORMAL in effect.

CRDO DAFB
Print a carriage return.

OUTSPC DB57
Print a space.

OUTQST DB5A
Print a question mark.

INPRT ED19
Print " IN " and the current line number from CURLIN. Uses LINPRT.

LINPRT ED24
Prints the 2 byte unsigned number in X,A.

PRNTFAC ED2E
Prints the current value of FAC. FAC is destroyed. Uses FOUT and STROUT.
Published Date: Feb 20, 2012