Re: [cc65] How to properly use a .union

From: thefox xofeht <thefox1aspekt.fi>
Date: 2013-01-22 08:21:32
On Tue, Jan 22, 2013 at 7:30 AM, Payton Byrd <plbyrd@gmail.com> wrote:

> Hello,
>
> I have a scenario where I want to be able to define a font in a file and
> then overlay a struct on top of the loaded file such that I can access the
> values of the file as struct values.  To that end I've created the
> following code, which compiles:
>
> .struct font
> 	Baseline	.byte
> 	TotalWidth	.word
> 	Height		.byte
> 	IndexPtr	.word
> 	FontDataPtr	.word
> .endstruct
>
> .union Ormand
> 	Font .tag font
>
>
> .endunion
>
> fontRowLength = _ormand+font::TotalWidth
> fontIndex = _ormand + _ormand+font::IndexPtr
> fontData = _ormand + _ormand+font::FontDataPtr
>
> .rodata
> _ormand: .tag Ormand
> 	.incbin "..\res\ormand.geosfont"
>
>
> The problem I'm having is that the values I retrieve from the
> fontRowLength, fontIndex, and fontData variables do not reflect the data in
> the file.  What am I doing wrong here?  I've searched google (including the
> mailing list) and found no answer.
>

Hi,

I'm guessing you want something like this:

 .struct font
Baseline .byte
TotalWidth .word
Height .byte
IndexPtr .word
FontDataPtr .word
.endstruct

fontRowLength = _ormand+font::TotalWidth
fontIndex = _ormand+font::IndexPtr
fontData = _ormand+font::FontDataPtr

.rodata
_ormand:
.incbin "..\res\ormand.geosfont"

No need for union. And note that .tag actually allocates memory, so if you
put .tag in rodata, it will allocate bunch of zeroes from it according to
the data structure given to it.

-thefox

----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo@musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Tue Jan 22 08:21:41 2013

This archive was generated by hypermail 2.1.8 : 2013-01-22 08:21:44 CET