nesdev.com
http://forums.nesdev.com/

CA65 warning didn't use zero page addressing
http://forums.nesdev.com/viewtopic.php?f=10&t=17025
Page 1 of 1

Author:  instantaphex [ Sun Feb 04, 2018 5:08 pm ]
Post subject:  CA65 warning didn't use zero page addressing

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:
; set direction
lda #$00
sta player_direction


Player direction is defined like this:

Code:
.segment "ZEROPAGE"
player_direction: .res 1


Although this assembles, I'm getting the following warning:

Code:
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

Author:  thefox [ Sun Feb 04, 2018 5:15 pm ]
Post subject:  Re: CA65 warning didn't use zero page addressing

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

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

Author:  tokumaru [ Sun Feb 04, 2018 5:17 pm ]
Post subject:  Re: CA65 warning didn't use zero page addressing

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.

Author:  tepples [ Sun Feb 04, 2018 5:23 pm ]
Post subject:  Re: CA65 warning didn't use zero page addressing

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?

Author:  dougeff [ Sun Feb 04, 2018 5:38 pm ]
Post subject:  Re: CA65 warning didn't use zero page addressing

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

.importzp player_direction

Author:  instantaphex [ Sun Feb 04, 2018 8:59 pm ]
Post subject:  Re: CA65 warning didn't use zero page addressing

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?

Author:  tepples [ Sun Feb 04, 2018 9:08 pm ]
Post subject:  Re: CA65 warning didn't use zero page addressing

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

Author:  instantaphex [ Sun Feb 04, 2018 9:30 pm ]
Post subject:  Re: CA65 warning didn't use zero page addressing

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.

Author:  thefox [ Mon Feb 05, 2018 2:01 pm ]
Post subject:  Re: CA65 warning didn't use zero page addressing

I'll just note that unlike C, ca65 doesn't have a separate preprocessing step. The net effect is similar, though.

Page 1 of 1 All times are UTC - 7 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/