It is currently Sun Aug 19, 2018 4:28 am

All times are UTC - 7 hours





Post new topic Reply to topic  [ 9 posts ] 
Author Message
PostPosted: Sun Feb 04, 2018 5:08 pm 
Offline
User avatar

Joined: Sat Sep 27, 2014 10:10 pm
Posts: 30
Location: Houston, TX
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


Top
 Profile  
 
PostPosted: Sun Feb 04, 2018 5:15 pm 
Offline
User avatar

Joined: Mon Jan 03, 2005 10:36 am
Posts: 3111
Location: Tampere, Finland
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.

_________________
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: fo.aspekt.fi


Top
 Profile  
 
PostPosted: Sun Feb 04, 2018 5:17 pm 
Offline
User avatar

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 10714
Location: Rio de Janeiro - Brazil
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.


Top
 Profile  
 
PostPosted: Sun Feb 04, 2018 5:23 pm 
Offline

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


Top
 Profile  
 
PostPosted: Sun Feb 04, 2018 5:38 pm 
Offline
User avatar

Joined: Fri May 08, 2015 7:17 pm
Posts: 2200
Location: DIGDUG
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


Top
 Profile  
 
PostPosted: Sun Feb 04, 2018 8:59 pm 
Offline
User avatar

Joined: Sat Sep 27, 2014 10:10 pm
Posts: 30
Location: Houston, TX
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?


Top
 Profile  
 
PostPosted: Sun Feb 04, 2018 9:08 pm 
Offline

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


Top
 Profile  
 
PostPosted: Sun Feb 04, 2018 9:30 pm 
Offline
User avatar

Joined: Sat Sep 27, 2014 10:10 pm
Posts: 30
Location: Houston, TX
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.


Top
 Profile  
 
PostPosted: Mon Feb 05, 2018 2:01 pm 
Offline
User avatar

Joined: Mon Jan 03, 2005 10:36 am
Posts: 3111
Location: Tampere, Finland
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group