By "loop macro" do you mean you are using a .repeat? You could try recursion instead, since the .repeat is basically a form of recursion. Maybe give a more defined example.blargg wrote:And next, how to define a global symbol within a scope...The context is using scopes in a nice loop macro
spca65
Moderator: Moderators
Forum rules
- For making cartridges of your Super NES games, see Reproduction.
Re: spca65
Re: spca65
I wouldn't be so sure that ca65's macro processor optimizes tail calls. How deep of recursion were you thinking?
Re: spca65
I'm not sure what you mean with tail calls in this context, tepples.
Example comparison: A macro called hex as recursive and with .repeat (untested)
Usage:
Recursive:
With .repeat
Both are technically recursive.
Example comparison: A macro called hex as recursive and with .repeat (untested)
Usage:
Code: Select all
hex 01 03 a0 ba 23 43 fe ee fc 01 03 a0 ba 23 43 fe ee fc
Code: Select all
macro hex data
.ifblank data
.error "Please provide some data!"
.endif
.byte $.left(1,data)
.if .tcount(data) > 1
hex .mid(1, .tcount(data) - 1, data)
.endif
.endmacro
Code: Select all
macro hex data
.ifblank data
.error "Please provide some data!"
.endif
.repeat .tcount(data), I
.byte $.mid(I, 1, data)
.endrepeat
.endmacro
Re: spca65
Unless ca65's macro expander handles tail calls specially, your recursive example will eat up about 18 levels of call stack inside the macro expander when hex calls itself, one for each byte. The iterative example won't.
Re: spca65
Yes, I'm sure the recursive example will use more memory vs .repeat, but it shouldn't matter much on a modern PC. The benefit being recursive example will allow you to have .local constants defined that are unique for each recursive expansion and hopefully avoid using any unnamed scopes (and making a global definition no problem).
Re: spca65
Unless you have to recompile ca65 for a greater recursion depth. A lot of interpreters* cap the call stack depth to prevent runaway recursion from making your machine unresponsive from swapping. Good luck getting a recursive macro to run 32768 deep, once for each byte in a bank.Movax12 wrote:Yes, I'm sure the recursive example will use more memory vs .repeat, but it shouldn't matter much on a modern PC.
When I try to assemble this, I get an error because ca65 is capping the macro call stack at 255 levels.
Code: Select all
.macro recursefromhell i
.if i > 0
.local i1
i1 = i
.byte <i1
recursefromhell (i1 - 1)
.endif
.endmacro
; this works
recursefromhell 255
; this raises Error: Too many nested macro expansions
recursefromhell 256
What does this necessarily provide over .local once and then .set within the .repeat loop?The benefit being recursive example will allow you to have .local constants defined that are unique for each recursive expansion and hopefully avoid using any unnamed scopes (and making a global definition no problem).
* ca65 is an assembler, but its macro language is an interpreter within an assembler.
Re: spca65
No, just the equivalent of a for loop with braces for scope, that allows nesting, and doesn't require you to name each loop. I'm writing a CPU instruction tester and want to make several nested for loops to go over arrays of bytes.Movax12 wrote:By "loop macro" do you mean you are using a .repeat? You could try recursion instead, since the .repeat is basically a form of recursion. Maybe give a more defined example.blargg wrote:And next, how to define a global symbol within a scope...The context is using scopes in a nice loop macro
Code: Select all
loop_bytes { 0, 1, $7f, $80, $ff }, in_a
loop_bytes { 0, 1, $7f, $80, $ff }, operand
cmp operand
; A operand
; 00 00
; 00 01
; 00 7f
; 00 80
; 00 ff
; 01 00
; 01 01
; ...
loop_end
loop_end
Re: spca65
I found it helpful in the instances where the recursive expansion would end and the .local would retain the value from before the expansion call. Not sure if I could come up with a good example vs .repeattepples wrote: What does this necessarily provide over .local once and then .set within the .repeat loop?
Re: spca65
Back to topic:
What's the license on this set of macros?
(And after how many days since last post must I calculate days since last post?)
What's the license on this set of macros?
(And after how many days since last post must I calculate days since last post?)
Re: spca65
The uses of DEFAULT_ABS inside macros need to be changed to ::DEFAULT_ABS so that they'll work even inside a .proc block.
- rainwarrior
- Posts: 8732
- Joined: Sun Jan 22, 2012 12:03 pm
- Location: Canada
- Contact:
Re: spca65
Does anyone have copies of these?blargg wrote: ↑Fri Nov 29, 2013 12:29 am Finally ready to post what I've got. First, SPC-700 assembly using ca65:
spc-ca65-0.1.0.zip
Then, 65C02 syntax for SPC-700:
spc65-0.1.0.zip
And, a buildable source code example using it that plays a chord using the SPC-700:
spc-chord.zip
- NovaSquirrel
- Posts: 483
- Joined: Fri Feb 27, 2009 2:35 pm
- Location: Fort Wayne, Indiana
- Contact:
Re: spca65
That sounds like these files:
https://github.com/pinobatch/lorom-temp ... c-ca65.inc
https://github.com/pinobatch/lorom-temp ... -65c02.inc
But I wouldn't know where to find the code example.
https://github.com/pinobatch/lorom-temp ... c-ca65.inc
https://github.com/pinobatch/lorom-temp ... -65c02.inc
But I wouldn't know where to find the code example.
- rainwarrior
- Posts: 8732
- Joined: Sun Jan 22, 2012 12:03 pm
- Location: Canada
- Contact:
Re: spca65
Thanks.
- Augustus Blackheart
- Posts: 61
- Joined: Sat Jul 26, 2014 9:50 am
Re: spca65
Here there be files
- Attachments
-
- spc-chord.zip
- (15.59 KiB) Downloaded 20 times
-
- spc-ca65-0.1.0.zip
- (8.35 KiB) Downloaded 23 times
-
- spc65-0.1.0.zip
- (9.27 KiB) Downloaded 22 times
-
- spc65-0.1.1.zip
- (9.63 KiB) Downloaded 27 times
- rainwarrior
- Posts: 8732
- Joined: Sun Jan 22, 2012 12:03 pm
- Location: Canada
- Contact: