ElEctric_EyE wrote:
GARTHWILSON wrote:
Time for macros!
They would dramatically shorten the source code and make it more clear, and still assemble the same result.
Great, give us an example Garth!
Actually, in the portion
Code:
LDY #128
LDA scratchx1,Y
STA lx0
LDA scratchy1,Y
STA ly0
LDA scratchx2,Y
STA lx1
LDA scratchy2,Y
STA ly1
LDY #256+128
LDA scratchx1,Y
STA lx0
LDA scratchy1,Y
STA ly0
LDA scratchx2,Y
STA lx1
LDA scratchy2,Y
STA ly1
LDY #512+128
LDA scratchx1,Y
STA lx0
LDA scratchy1,Y
STA ly0
LDA scratchx2,Y
STA lx1
LDA scratchy2,Y
STA ly1
LDY #768+128
LDA scratchx1,Y
STA lx0
LDA scratchy1,Y
STA ly0
LDA scratchx2,Y
STA lx1
LDA scratchy2,Y
STA ly1
there's more similarity that I saw at first glance, and the
Code:
LDA scratchx1,Y
STA lx0
LDA scratchy1,Y
STA ly0
LDA scratchx2,Y
STA lx1
LDA scratchy2,Y
STA ly1
portion could even be a subroutine, unless you don't want the JSR/RTS overhead, in which case you could make it a macro and include the LDY# line, like
Code:
FOOBAR: MACRO input ; (Give it a descriptive name though.)
LDY #input
LDA scratchx1,Y
STA lx0
LDA scratchy1,Y
STA ly0
LDA scratchx2,Y
STA lx1
LDA scratchy2,Y
STA ly1
ENDM
;------------------
and then replace the entire first section above with
Code:
FOOBAR 128
FOOBAR 256+128
FOOBAR 512+128
FOOBAR 768+128
taking it from 39 lines down to four.
In applications that have a lot of LDA#...STA_abs, I like to use a macro I call PUT, like this:
Code:
PUT 750, IN, XORG
PUT 350, IN, YORG
(Macros require commas separating the input parameters.) The "IN" is previously defined as 0 and is not actually used in the macro, being there only to make it more English-like.
When there are a lot of LDA_abs, STA_abs, I like to use a macro I call COPY, like this:
Code:
COPY FOOBAR, TO, XLERB
(Again, "TO" is only there to make it more English-like, and is not actually used by the macro.) You could go further and add another parameter telling how many address units to copy, so if you had a 32- or 64-bit quantity to copy, it would all get handled in one line.
You also have a lot of occurrences of LSR LSR (two lines), so it would be worth making those a macro and call it LSR2 for example, and then it only uses one line each time instead of two.
The macros for looping, conditional branching, etc, giving it all a more-visible structure are extra, and now I'm hooked on them and never want to go back.