Submitted by Steve Fewell
Description:
If the 6502 Stack pointer address is more than or equal to #&FC (i.e. Stack physical address &01FC), then a
subroutine is not currently active, as when a subroutine is called, 4 bytes are pushed to the 6502 stack [Those
bytes are as follows: 1) the Keyword token for either FN or PROC (1 byte); 2) the current program location and offset
(&0A-&0C) (3 bytes)], so issue 'No FN' error.
If the first byte pushed to the 6502 stack (at address &01FF) is not the FN-Keyword token (#&A4), then the most
recent subroutine called is not a FuNction (it must be a PROCedure instead), so issue 'No FN' error.
Otherwise, we have correctly found the end of the Function definition, so call routine &9D2F to set BASIC text
pointer B to BASIC text pointer A location and obtain the value of the expression following the equals '=' character;
and jump to routine &9B91 to set A to X (the next character after the expression) and check that the '='-statement
is valid (and is followed by either a carriage return, ELSE-token or ':' character) and to return (RTS) to the code within
the Call Subroutine routine (at address &B08C) to process the return from the subroutine call and handle the transfer
of program control, and the Function return value, back to the statement following the Function call (FN) expression.
9060 | 186 | BA | TSX | |
9061 | 224 252 | E0 FC | CPX#&FC | |
9063 | ' | 176 039 | B0 27 | BCS 39 --> &908C 'No FN' error |
9065 | 173 255 001 | AD FF 01 | LDA &01FF | |
9068 | 201 164 | C9 A4 | CMP#&A4 | |
906A | 208 032 | D0 20 | BNE 32 --> &908C 'No FN' error | |
906C | / | 032 047 157 | 20 2F 9D | JSR &9D2F Ptr B = Ptr A & Get result of expression [PTR B] |
906F | L | 076 145 155 | 4C 91 9B | JMP &9B91 X = A; Check for end of Statement (PTR B) |