How to define a numeric constant in ca65?

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems. See the NESdev wiki for more information.

Moderator: Moderators

Post Reply
User avatar
nesrocks
Posts: 563
Joined: Thu Aug 13, 2015 4:40 pm
Location: Rio de Janeiro - Brazil
Contact:

How to define a numeric constant in ca65?

Post by nesrocks »

When I try to define a constant as simple number what I get is either an error or a memory address, no matter what I try. What am I doing wrong?

According to this page doing this: "two = 2" would define "two" as a numeric constant, but when I do that what I get is the address $2, not the number #2. If I try "two = #2" I get "trailing garbage characters" error.

ca65 is v2.16

edit: apparently this feature is only for cc65? Is that correct? Is there a way to do it on ca65?
https://twitter.com/bitinkstudios <- Follow me on twitter! Thanks!
https://www.patreon.com/bitinkstudios <- Support me on Patreon!
User avatar
thefox
Posts: 3134
Joined: Mon Jan 03, 2005 10:36 am
Location: 🇫🇮
Contact:

Re: How to define a numeric constant in ca65?

Post by thefox »

This is probably what you want:

Code: Select all

two = 2
lda #two
This is possible, but NOT recommended:

Code: Select all

.define two #2
lda two
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: fo.aspekt.fi
User avatar
nesrocks
Posts: 563
Joined: Thu Aug 13, 2015 4:40 pm
Location: Rio de Janeiro - Brazil
Contact:

Re: How to define a numeric constant in ca65?

Post by nesrocks »

Precisely, thanks! That works fine. :beer:
https://twitter.com/bitinkstudios <- Follow me on twitter! Thanks!
https://www.patreon.com/bitinkstudios <- Support me on Patreon!
Post Reply