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

From: thefox xofeht <thefox1aspekt.fi>
Date: 2013-01-22 09:19:56
Ok, I think I understand now. Because the binary file is constant, you want
to make symbols based on its contents. It's not possible, even though the
values are known at compile time.

-thefox

Sent from my iPhone

On 22.1.2013, at 9.44, Payton Byrd <plbyrd@gmail.com> wrote:

Yes, this is very much what I'm looking for with one change.

When I reference _ormand+font::IndexPtr, I want the actual value in
fontIndex, not the memory location.  I don't see how to do this.


On Tue, Jan 22, 2013 at 1:21 AM, thefox xofeht <thefox@aspekt.fi> wrote:

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


-- 
Payton Byrd
<http://www.paytonbyrd.com>
<http://it.toolbox.com/blogs/paytonbyrd>

----------------------------------------------------------------------
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 09:20:09 2013

This archive was generated by hypermail 2.1.8 : 2013-01-22 09:20:12 CET