Re: [cc65] size of .enum?

From: Greg King <>
Date: 2013-04-03 10:26:24
From: silverdr; on Tuesday, April 02, 2013; at 5:38 AM -0500
> On 2013-04-02, at 11:28, Ullrich von Bassewitz wrote:
>>> I see. I am wondering if I don't get better out with getting back to
>>> defining all the variables' addresses as constants. I then would
>>> have to know the value of only the last one (first one is known).
>> That's, of course, your decision. ca65 doesn't enforce one specific
>> coding style.
> That's what I so much appreciate in the cc65/ca65 package: the
> versatility, which combined with the linker goes well beyond
> alternatives.
> OK. I shall have to think whether I can come up with something smart
> enough regarding the constants; so that I always can have the right
> number and the ease of modifying the variable set.

You can use the method that I use to define the labels for the I/O chip
registers.  The .STRUCT object defines offsets for a list of various
storage units (byte, word, etc.).  It can't be used directly to allocate
_relative_ variables (because their addresses are set by the linker).  But,
it can be used to name variables that have constant, predetermined

The first unit in a .STRUCT always has an offset value of zero.  But, that
isn't a problem because we can make a unit of any length (and, we don't
need to name it).  So, for example, we can label the registers of one of
the C64's CIAs in this way:

.struct CIA1
.res    $DC00
PRA     .byte
PRB     .byte
DDRA    .byte
DDRB    .byte
TIMERA  .word
TIMERB  .word
TOD10   .byte
TODSEC  .byte
TODMIN  .byte
TODHR   .byte
SDR     .byte
ICR     .byte
CRA     .byte
CRB     .byte

That .RES pushes the offsets of the other lines up to where we want their
addresses to be.  So, CIA1::CRA is equal to a constant $DC0E.

Uz's example can be written as:

.struct    myzp
.res    $50

var0    .byte
var1    .word
var2    .dword
...    ....
varN    .byte


The size is known at assembly-time:

myzp_size = <(.sizeof(myzp) - $50)
myzp_save:    .res    myzp_size

(Note that it is neutral; it doesn't know what names you are using for the
variables within the structure.)

Those things are the "pros" for that method; there are a few slight "cons"
against it:
1) A debuginfo file won't mark those names as labels (insignificant unless
   you're making a report about how names are used in the sources).
2) The names must be scoped; otherwise, you can't use .SIZEOF().
3) I think that scoped names can't be exported. Therefore, you must put
   that structure in a header; and, import those names by including that

Maybe, (2) and (3) can be avoided by using an unnamed .STRUCT.  Then, you
would need to choose a name that you wouldn't change, put it at the end of
the structure, and use it in the place of ".sizeof(myzp)".

To unsubscribe from the list send mail to with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Wed Apr 3 11:41:51 2013

This archive was generated by hypermail 2.1.8 : 2013-06-15 17:37:38 CEST