Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
1<br />
rather time consuming, and a waste<br />
of source file space to keep keying in<br />
the same code. Instead you could<br />
define it as a macro definition called<br />
CENTRE - to achieve this type the<br />
commands as you would a normal<br />
source file, and save the file with SAVE<br />
"CENTRE",8.<br />
Each time you wish to use the given<br />
instructions instead of typing out the<br />
same code you can 'call up' or 'invoke'<br />
the macro 'CENTRE' and the instructions<br />
LDX # $10, LDY #$ 10, JSR<br />
SEFF0 will be generated into your<br />
source file. See the section on how to<br />
invoke the macro files, and add them<br />
to the macro library.<br />
Added Macro Features<br />
A couple of features are included to<br />
make the macro definitions more<br />
meaningful. The first feature is to allow<br />
true parameter passing upon invoking<br />
a macro.<br />
parameter Passing in a<br />
Macro Definition<br />
The macro definitions can accept<br />
parameters by using the ' character<br />
to preceed a parameter number<br />
between 0 and 9.<br />
eg) LDA / 0<br />
STA/ I<br />
in the macro definition would change<br />
/0 into the text passed by parameter<br />
0, and / 1 with parameter 1.<br />
See the section on macro invokation<br />
for more details of how to pass<br />
parameters within macros.<br />
Localised Symbols<br />
All labels within a macro definition<br />
will be read in as a local symbol, this<br />
is achieved by adding a unique 2-digit<br />
code to the symbol within the definition.<br />
e.g. the symbol LABEL! within<br />
a macro definition will be given as<br />
ABLABEL I on the first 'call' to the<br />
macro, ACLABEL I the next time, etc,<br />
this is so that the symbol LABEL' is<br />
not redefined everytime a macro is<br />
invoked, and also direct references can<br />
be given to labels within individual<br />
macros.<br />
Every reference within the macro<br />
definition to a label automatically<br />
refers to one within a particular macro<br />
(a local reference). If you wish to refer<br />
to a label outside of the current macro<br />
C64 PROGRAMMING<br />
definition you must signify that it is<br />
a global reference - this is achieved<br />
by prefixing the label with a full stop.<br />
The following is the source inside<br />
a macro definition:<br />
BEQ LOOP ! refers to the label<br />
'LOOP' inside the current macro<br />
definition.<br />
JMP .MAIN ! refers to the label<br />
'MAIN' outside of the current macro<br />
definition.<br />
Adding a Macro Definition to the<br />
Macro Library<br />
In order to invoke any macro it must<br />
first be stored within the macro library.<br />
A previously saved macro definition<br />
can be added to the library by prefixing<br />
the macro name with a E, symbol:<br />
10 EMACRONAME<br />
Note that there is no space between<br />
E and the filename. The macro definition<br />
must be given to the macro<br />
library BEFORE it is invoked.<br />
Listing the Files in the Macro Library<br />
To summarise what macro definitions<br />
are present in the macro library you<br />
can view the macro directory with the<br />
use of the library you can view the<br />
macro directory with the use of the<br />
editors •IVI' command,<br />
Invoking Macros<br />
This is the term used to expand the<br />
macro definitions into the source file.<br />
Once a macro definition has been<br />
stored in the macro library it can be<br />
invoked in the source file by using the<br />
symbol to preceed the macro<br />
filename to be invoked.<br />
10 imachroname ! adds the macro to<br />
the macro library<br />
20 macroname ! invokes (expands) the<br />
macro<br />
Parameter Passing During Macro<br />
Invocation<br />
The macros to be expanded can be<br />
called up with parameters as disucussed<br />
in the section on macro<br />
definitions.<br />
To invoke the following macro<br />
definition:<br />
10 LDAtt/ 10<br />
20 STA/ 1<br />
Save it to disk with SAVE<br />
"POKE, MAC",8<br />
The above example is to define a<br />
rather simple POKE x,y type of macro<br />
definition but servies its purpose. Once<br />
it is saved type NEW to clear the<br />
current source file and type in the<br />
following:<br />
10 *$C000 ! sets origin<br />
20 f.POKE.MAC ! gives definition to<br />
macro library<br />
30 POKE.MAC 5,53280 ! pass the<br />
poke value, address<br />
40 RTS<br />
It can be seen that parameter 0 is<br />
5 (the source will now contain LDA<br />
5), and parameter I is 53280 (source<br />
contains STA 53280)<br />
A parameter can take any form<br />
whatsoever, °Nodes; varius operands,<br />
or any valid expression. Each parameter<br />
is separated by a comma wso if<br />
you are passing text, as in "HELLO,<br />
MY NAME IS" the comma would tell<br />
the assembler that it is the end of that<br />
parameter so be careful!<br />
The number of parameters allocated<br />
to a parficular macri as 10 (0-<br />
9), however more than this is allowed<br />
if ASCII codes which follow "0"-"9"<br />
are given, but 0-9 should be used as<br />
standard. Because all labels within a<br />
macro definition are operated on as<br />
localised, any parameter passed to it<br />
will need to prefixed with a full stop<br />
if they refer to a global label outside<br />
of the definition.<br />
Example of a Top Level Source File<br />
10 RED = 2 ! global label outside of<br />
a macro definition<br />
20 COLOUR .RED ! prefix with<br />
a as we are using the global label<br />
RED within the macro definition.<br />
You will he told if you try to invoke<br />
a macro that is not present in the<br />
macro library. If a parameter is<br />
required by a macro definition and one<br />
isn't given on invoking it, a<br />
'PARAMETER MISSING' error will<br />
be issued. This is because no comma<br />
will be looked for (as it is param.0)<br />
and data that was expected to be in<br />
the buffer will be used. The above is<br />
of course a rarity, but worthwhile to<br />
mention. Any parameter given to a<br />
particular macro definition will only<br />
be verified once it has been expanded<br />
into the source file.<br />
Thirty Six Y O U R COMMODORE