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

From: Payton Byrd <plbyrd1gmail.com>
Date: 2013-01-22 08:46:40
What I currently have is this:

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


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

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


Unfortunately, the value in fontIndex is the address of _ormand and
IndexPtr added together.  I need fontIndex to contain the address of
_ormand and the value of IndexPtr added together.



On Tue, Jan 22, 2013 at 1:43 AM, 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>
>



-- 
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 08:47:11 2013

This archive was generated by hypermail 2.1.8 : 2013-01-22 08:47:15 CET