Quick ref: Pass arguments to machine code from the Monitor
When parsing commands, the Monitor stores arguments in the zero-page pointers A1, A2, A3, A4 at locations $3C, $3E, $40, $42 as follows:
A1 | $3C-$3D | Contains the default address parsed from the command-line. When calling a machine language subroutine with the G command, A1 contains the address of the routine. |
A2 | $3E-$3F | Contains the address parsed from the command-line after the "." delimiter. If no delimiter is specified, then A2 contains a duplicate copy of A1. |
A3 | $40-$41 | Contains a duplicate copy of A1. |
A4 | $42-$43 | Contains the address parsed from the command-line before the "<" delimeter. If the "<" delimiter was not specified, then A4 retains its previous contents. |
Here's a machine code subroutine that prints the contents of A1, A2, A3, A4 to demonstrate how command-line arguments are parsed.
When the 'G' command is used in its simplest form, the only argument is the address of the target subroutine. By default, that argument is stored in A1, A2, A3 while A4 is left untouched. (A4 retains its previous value, whatever that might be.)
A second argument can be passed by typing a '.' delimeter after the subroutine address on the command line. The argument after the '.' delimiter is stored in A2 when the machine code subroutine is called.
Another argument can be inserted before the subroutine address by typing the '<' delimiter. The value before the '<' delimiter is stored in A4.
Both delimiters can be specified in the same command-line in order to pass two arguments to a machine code subroutine, in addition to the default argument.
- S.Elliott's blog
- Log in or register to post comments