CA65 warning didn't use zero page addressing

Are you new to 6502, NES, or even programming in general? Post any of your questions here. Remember - the only dumb question is the question that remains unasked.

Moderator: Moderators

Post Reply
User avatar
instantaphex
Posts: 30
Joined: Sat Sep 27, 2014 10:10 pm
Location: Houston, TX

CA65 warning didn't use zero page addressing

Post by instantaphex »

I recently switched to ca65 from nesasm and now I'm getting a bunch of errors for every time I'm trying to use a zero page variable. My code is still working correctly but I'm trying to figure out what's going on.

Here's an example of what I'm doing:

Code: Select all

; set direction
lda #$00
sta player_direction
Player direction is defined like this:

Code: Select all

.segment "ZEROPAGE"
player_direction: .res 1
Although this assembles, I'm getting the following warning:

Code: Select all

update-player.asm(17): Warning: Didn't use zeropage addressing for `player_direction'
I remember reading somewhere that there is some specific thing that I need to do to indi
User avatar
thefox
Posts: 3134
Joined: Mon Jan 03, 2005 10:36 am
Location: 🇫🇮
Contact:

Re: CA65 warning didn't use zero page addressing

Post by thefox »

Simply move your "ZEROPAGE" segment before the code, e.g.:

Code: Select all

.segment "ZEROPAGE"
player_dir: .res 1
; ...
sta player_dir
The problem is that ca65 is a single-pass assembler, so it has already assembled the code using absolute addressing (to be safe), until it sees that you defined the symbol in zeropage, and issues a warning.
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: fo.aspekt.fi
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: CA65 warning didn't use zero page addressing

Post by tokumaru »

Ninja'd, but here it goes anyway: Keep in mind that ca65 is a 1-pass assembler, so you must declare the variable before you use it, because it can't tell in advance if it can use ZP addressing.
tepples
Posts: 22708
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: CA65 warning didn't use zero page addressing

Post by tepples »

Are player_direction: .res 1 and sta player_direction in the same source file?

If they are in the same source file
Is player_direction: .res 1 above sta player_direction? ca65 knows what size an address is only if the label is declared above its use. Otherwise, it assumes the label is absolute ($000100-$00FFFF).

If they are in different source files
Is .globalzp player_direction above sta player_direction?
User avatar
dougeff
Posts: 3079
Joined: Fri May 08, 2015 7:17 pm

Re: CA65 warning didn't use zero page addressing

Post by dougeff »

The simplest solution is, at the top of update-player.asm add the line

.importzp player_direction
nesdoug.com -- blog/tutorial on programming for the NES
User avatar
instantaphex
Posts: 30
Joined: Sat Sep 27, 2014 10:10 pm
Location: Houston, TX

Re: CA65 warning didn't use zero page addressing

Post by instantaphex »

Yeah you guys were right. I have a variables file that has all my zero page stuff. I was refactoring and I had it included after all of my other includes. Moving it up to the top fixed it. I'm not sure about the import export stuff. Does ca65 have a module system?
tepples
Posts: 22708
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: CA65 warning didn't use zero page addressing

Post by tepples »

The "module system" in ca65 is the same as that of familiar implementations of the C language.

First, each source file (.s) is preprocessed to resolve macros and .include commands. The latter causes a header file to get included into the current translation unit. This header file contains label definitions (e.g. PPUDATA = $2007), macro definitions, and declarations of functions and variables to be found in other source files.

Preprocessing results in a "translation unit" that gets assembled to an object code file (.o). Then ld65 combines multiple object code files, packs their data into segments as described in the linker configuration, and produces an executable file (.nes).
User avatar
instantaphex
Posts: 30
Joined: Sat Sep 27, 2014 10:10 pm
Location: Houston, TX

Re: CA65 warning didn't use zero page addressing

Post by instantaphex »

tepples wrote:The "module system" in ca65 is the same as that of familiar implementations of the C language.

First, each source file (.s) is preprocessed to resolve macros and .include commands. The latter causes a header file to get included into the current translation unit. This header file contains label definitions (e.g. PPUDATA = $2007), macro definitions, and declarations of functions and variables to be found in other source files.

Preprocessing results in a "translation unit" that gets assembled to an object code file (.o). Then ld65 combines multiple object code files, packs their data into segments as described in the linker configuration, and produces an executable file (.nes).
Thanks for the explanation. The ca65 docs are a little light for someone that's not done any assembly programming before.
User avatar
thefox
Posts: 3134
Joined: Mon Jan 03, 2005 10:36 am
Location: 🇫🇮
Contact:

Re: CA65 warning didn't use zero page addressing

Post by thefox »

I'll just note that unlike C, ca65 doesn't have a separate preprocessing step. The net effect is similar, though.
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: fo.aspekt.fi
Post Reply