spca65

Discussion of hardware and software development for Super NES and Super Famicom. See the SNESdev wiki for more information.

Moderator: Moderators

Forum rules
  • For making cartridges of your Super NES games, see Reproduction.
User avatar
Movax12
Posts: 541
Joined: Sun Jan 02, 2011 11:50 am

Re: spca65

Post by Movax12 »

blargg wrote:And next, how to define a global symbol within a scope...The context is using scopes in a nice loop macro
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.
tepples
Posts: 22708
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: spca65

Post by tepples »

I wouldn't be so sure that ca65's macro processor optimizes tail calls. How deep of recursion were you thinking?
User avatar
Movax12
Posts: 541
Joined: Sun Jan 02, 2011 11:50 am

Re: spca65

Post by Movax12 »

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:

Code: Select all

hex 01 03 a0 ba 23 43 fe ee fc 01 03 a0 ba 23 43 fe ee fc
Recursive:

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
With .repeat

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
Both are technically recursive.
tepples
Posts: 22708
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: spca65

Post by tepples »

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.
User avatar
Movax12
Posts: 541
Joined: Sun Jan 02, 2011 11:50 am

Re: spca65

Post by Movax12 »

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).
tepples
Posts: 22708
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: spca65

Post by tepples »

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.
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.

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
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).
What does this necessarily provide over .local once and then .set within the .repeat loop?


* ca65 is an assembler, but its macro language is an interpreter within an assembler.
User avatar
blargg
Posts: 3715
Joined: Mon Sep 27, 2004 8:33 am
Location: Central Texas, USA
Contact:

Re: spca65

Post by blargg »

Movax12 wrote:
blargg wrote:And next, how to define a global symbol within a scope...The context is using scopes in a nice loop macro
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.
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.

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
User avatar
Movax12
Posts: 541
Joined: Sun Jan 02, 2011 11:50 am

Re: spca65

Post by Movax12 »

tepples wrote: What does this necessarily provide over .local once and then .set within the .repeat loop?
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 .repeat
tepples
Posts: 22708
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: spca65

Post by tepples »

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?)
tepples
Posts: 22708
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: spca65

Post by tepples »

The uses of DEFAULT_ABS inside macros need to be changed to ::DEFAULT_ABS so that they'll work even inside a .proc block.
User avatar
rainwarrior
Posts: 8734
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: spca65

Post by rainwarrior »

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
Does anyone have copies of these?
User avatar
NovaSquirrel
Posts: 483
Joined: Fri Feb 27, 2009 2:35 pm
Location: Fort Wayne, Indiana
Contact:

Re: spca65

Post by NovaSquirrel »

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.
User avatar
rainwarrior
Posts: 8734
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: spca65

Post by rainwarrior »

Thanks.
User avatar
Augustus Blackheart
Posts: 61
Joined: Sat Jul 26, 2014 9:50 am

Re: spca65

Post by Augustus Blackheart »

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
User avatar
rainwarrior
Posts: 8734
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: spca65

Post by rainwarrior »

:beer: :D
Post Reply