Is there an easy way of make unrolled loops with macros?

This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade.
View original topic
Is there an easy way of make unrolled loops with macros?
by on (#207775)
The guy who programmed Toy Story used unrolled loops for 3D maze. Is that possible to do bass.exe or other assemblers?
Re: Is there an easy way of make unrolled loops with macros?
by on (#207776)
ca65 has the .repeat directive.
Re: Is there an easy way of make unrolled loops with macros?
by on (#207783)
I looked through the documentation of bass.exe, and I figured out how to have a repeating macros.

Code:
define n(0)
while {n} < 16 {
jsr spawn_single_explosion
evaluate n({n}+1)
}
Re: Is there an easy way of make unrolled loops with macros?
by on (#207785)
I always use macros to make unrolled loops. Doing it manually is too error-prone and difficult to maintain.
Re: Is there an easy way of make unrolled loops with macros?
by on (#207796)
In a situation where you have a way to define a macro (but no repeat), I've found this kind of thing to be a relatively straightforward / low risk of error way to unroll loops:
Code:
.macro THING index
   ; loop iteration here
.endmacro

THING 0
THING 1
THING 2
THING 3
THING 4
THING 5
; ...

Mostly this has come up for me in C or C++ cases where I knew an unroll was warranted but the compiler's optimizer wasn't going to do it on its own. (In a lot of cases just writing a for loop with a simple static range is enough to get the optimizer to unroll anyway, though. This is not something I've had to use frequently at all.)
Re: Is there an easy way of make unrolled loops with macros?
by on (#207830)
^This, and automated with the command to print it in comments.

// for i in `seq 0 15`; do echo THING $i; done