This page is a mirror of Tepples' nesdev forum mirror (URL TBD).
Last updated on Oct-18-2019 Download

ca65 changing address size of a symbol?

ca65 changing address size of a symbol?
by on (#189008)
The ca65 docs say:

Code:
ca65 assigns each segment and each symbol an address size. This is true, even if the symbol is not used as an address. You may also think of a value range of the symbol instead of an address size.

Possible address sizes are:

Zeropage or direct (8 bits)
Absolute (16 bits)
Far (24 bits)
Long (32 bits)
Since the assembler uses default address sizes for the segments and symbols, it is usually not necessary to override the default behaviour. In cases, where it is necessary, the following keywords may be used to specify address sizes:

DIRECT, ZEROPAGE or ZP for zeropage addressing (8 bits).
ABSOLUTE, ABS or NEAR for absolute addressing (16 bits).
FAR for far addressing (24 bits).
LONG or DWORD for long addressing (32 bits).



How do you use these keywords? I've tried placing them before, between, and after a symbol definition as well as a symbol import, and also with and without a "." preceding. So it feels as though I've tried every permutation possible for applying these keywords, however ca65 was not happy with any given attempt.

The particular use case is I'm trying to get rid of a warning from ld65 saying my symbol is exported as zp but imported as absolute. I'm using .global to both import and export the symbol. It's happening because I'm tracking start and end locations of chr chunks in a CHR-ROM segment, where the address space starts at $0, so I assume that's why the assembler/linker is assigning zeropage in one case but doesn't know what to do in the other case.
Re: ca65 changing address size of a symbol?
by on (#189009)
Have you tried colon (:)? Like ".export symbol : absolute". Not sure if it works with .global
Re: ca65 changing address size of a symbol?
by on (#189010)
Perfect, that worked! Thanks sir.
Re: ca65 changing address size of a symbol?
by on (#189015)
Alternatively there's .importzp / .exportzp / .globalzp as a shorthand.

If you want to read the documentation about it:
http://cc65.github.io/doc/ca65.html#ss11.39