English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Asm / Hardware

 
 
Thread Tools
Old 19 October 2018, 21:58   #1
guy lateur
Registered User
 
guy lateur's Avatar
 
Join Date: May 2017
Location: Belgium
Age: 50
Posts: 334
vasm/mot: structure

Here's what I would like to use:
Code:
STRUCTURE   TextPage,0          ;what does this 0 mean/do?
    UWORD   tp_NrLines          ;# of lines
    UWORD   tp_CurrLine         ;current line index
    APTR    tp_TextPointersPtr  ;pointer to text pointers 
    APTR    tp_NrsCharsPtr      ;pointer to #s of chars
    LABEL   tp_SIZEOF           ;end structure (?)
I have seen this used in several books (even RKRM: includes & autodocs), and in some include files (eg, intuition.i), but I can't seem to get it to work in vasm/mot. The documentation says its support should be implemented in the syntax module (mot), and it's not mentioned there. So I'm guessing this is not supported?

If not, how do I 'roll my own'? I can imagine some offset definitions, like this (to be used with a pointer to a block of memory initialised at startup):
Code:
tp_NrLines          equ 0
tp_CurrLine         equ 2
tp_TextPointersPtr  equ 4
tp_NrsCharsPtr      equ 8
tp_SIZEOF           equ 12
Is this how it's done? Any chance of dynamic allocation of such 'structures'? Any good examples I could look at? TIA!
guy lateur is offline  
Old 19 October 2018, 22:04   #2
StingRay
move.l #$c0ff33,throat
 
StingRay's Avatar
 
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 6,863
STRUCTURE is a macro that is defined in exec/types.i, did you include that very file? The 0 means the initial offset.
StingRay is offline  
Old 19 October 2018, 22:30   #3
guy lateur
Registered User
 
guy lateur's Avatar
 
Join Date: May 2017
Location: Belgium
Age: 50
Posts: 334
Quote:
Originally Posted by StingRay View Post
STRUCTURE is a macro that is defined in exec/types.i, did you include that very file? The 0 means the initial offset.
Well I have included that file now, and I must say it's much better, so thanks a lot!

I'm still a bit confused about vasm mentioning structures as a feature, though. For once, I have been Reading TFM, and it says on page 7 of the vasm.pdf, under 2.6: "Vasm supports structures, but the directives for defining them have to be implemented in the syntax module."

Anyway, it seems like this is just a little helper for obtaining those sequential offsets I was talking about earlier, right? So you'd have something like this:
Code:
textResetPage:
    lea     testTP,a0
    move.w  #0,tp_NrLines(a0)
    move.w  #0,tp_CurrLine(a0)
    ;and so on
.return:
    rts 

    STRUCTURE   TextPage,0          
    UWORD       tp_NrLines          ;# of lines
    UWORD       tp_CurrLine         ;current line index
    APTR        tp_TextPointersPtr  ;pointer to text pointers 
    APTR        tp_NrsCharsPtr      ;pointer to #s of chars
    LABEL       tp_SIZEOF           ;end structure (?)

testTP:
    ds.b    tp_SIZEOF,0
Is this about right? Anything else I should consider/remember?
guy lateur is offline  
Old 19 October 2018, 23:08   #4
clenched
Registered User
 
Join Date: Sep 2008
Location: Gainesville U.S.A.
Posts: 771
Quote:
Originally Posted by guy lateur View Post
For once, I have been Reading TFM, and it says on page 7 of the vasm.pdf, under 2.6: "Vasm supports structures, but the directives for defining them have to be implemented in the syntax module."
The vasm manual is talking about an assembler directive named structure instead of a macro named structure. Used with oldstyle syntax. So stay with what you are doing.
clenched is offline  
Old 19 October 2018, 23:19   #5
guy lateur
Registered User
 
guy lateur's Avatar
 
Join Date: May 2017
Location: Belgium
Age: 50
Posts: 334
Quote:
Originally Posted by clenched View Post
The vasm manual is talking about an assembler directive named structure instead of a macro named structure. Used with oldstyle syntax. So stay with what you are doing.
Ok, thanks.

I seem to be not doing anything with the structure name (TextPage), ATM. I can't seem to write TextPage.tp_NrLines or anything like that. That would be cool, though, because then I would actually write TextPage.NrLines. So what purpose does this name serve?
guy lateur is offline  
Old 20 October 2018, 10:21   #6
meynaf
son of 68k
 
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,355
Quote:
Originally Posted by guy lateur View Post
I seem to be not doing anything with the structure name (TextPage), ATM. I can't seem to write TextPage.tp_NrLines or anything like that. That would be cool, though, because then I would actually write TextPage.NrLines. So what purpose does this name serve?
It does not seem to serve a useful purpose, considering the definition of the macro : it is just a label set to 0.


Personnally i would define your structure as :
Code:
 rsreset                   ; start struct TextPage
tp_NrLines rs.w 1          ; # of lines
tp_CurrLine rs.w 1         ; current line index
tp_TextPointersPtr rs.l 1  ; pointer to text pointers 
tp_NrsCharsPtr rs.l 1      ; pointer to #s of chars
tp_SIZEOF so               ; size of structure
meynaf is offline  
Old 20 October 2018, 10:39   #7
guy lateur
Registered User
 
guy lateur's Avatar
 
Join Date: May 2017
Location: Belgium
Age: 50
Posts: 334
Quote:
Originally Posted by meynaf View Post
Personnally i would define your structure as :
Code:
 rsreset                   ; start struct TextPage
tp_NrLines rs.w 1          ; # of lines
tp_CurrLine rs.w 1         ; current line index
tp_TextPointersPtr rs.l 1  ; pointer to text pointers 
tp_NrsCharsPtr rs.l 1      ; pointer to #s of chars
tp_SIZEOF so               ; size of structure
I see, thanks for the tip. The ability to specify how many bytes/words/.. to account for could come in handy, I guess.
guy lateur is offline  
Old 02 January 2020, 23:06   #8
sparhawk
Registered User
 
sparhawk's Avatar
 
Join Date: Sep 2019
Location: Essen/Germany
Age: 55
Posts: 463
I tried to create my own structure, similar as above, but how can I create a statically initialized structure object?

I have a structure like this:
Code:
 STRUCTURE CopperInfo,0
    UWORD CI_ListSize
    APTR     CI_Player
    UWORD CI_CurPos
    LABEL   sizeof_CopperInfo
I also tried the above approach with rsreset, which is probably better, but is ony a different approach to the STRUCTURE macro, right? In my vasm documentation I haven't even found that 'rs.x' being mentioned even though it is working. EDIT: Just noticed, it is mentioned in the HTML docs but not in the PDF which I use most of the time. I thought they were in sync.

When I reserve space in my module like this, it would create just a single byte with the size, right?

Code:
CopperInfo1: dc.b sizeof_CopperInfo
And like this I would just reserve a block of memory with the size of the structure, right?
Code:
CopperInfo1: ds.b sizeof_CopperInfo
What I really want in this case though is something like this:
Code:
CopperInfo1: struct CopperInfo
   CI_ListSize = MyCopperListSize
   CI_Player = MyCopperListHandler
   ; CI_CurPos is reserved but not initialized yet.
So basically for the equivalent in C/C++ I would write:

Code:
static CopperInfo ci = {
   MyCopperListSize,
   &MyCopperListAnimation
};
sparhawk is offline  
Old 02 January 2020, 23:10   #9
hooverphonique
ex. demoscener "Bigmama"
 
Join Date: Jun 2012
Location: Fyn / Denmark
Posts: 1,642
Yeah, no assemblers I know of, support that.

The macros only "declare" the struct (actually just offsets to labels); you can't use them to instantiate it, because they are not really types which the assembler can reason about like a compiler does.
hooverphonique is offline  
Old 03 January 2020, 00:26   #10
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,545
Quote:
Originally Posted by sparhawk View Post
I tried to create my own structure, similar as above, but how can I create a statically initialized structure object?

I have a structure like this:
Code:
 STRUCTURE CopperInfo,0
    UWORD CI_ListSize
    APTR     CI_Player
    UWORD CI_CurPos
    LABEL   sizeof_CopperInfo
Code:
myCopperInfo:
        dc.w    listsize
        dc.l    player
        dc.w    curpos
There is not much help from the assembler here. But read below.

Quote:
EDIT: Just noticed, it is mentioned in the HTML docs but not in the PDF which I use most of the time. I thought they were in sync.
They are. rs.x appears in both documents. Just checked it.

Quote:
What I really want in this case though is something like this:
Code:
CopperInfo1: struct CopperInfo
   CI_ListSize = MyCopperListSize
   CI_Player = MyCopperListHandler
   ; CI_CurPos is reserved but not initialized yet.
There is a more powerful Structure directive in the oldstyle syntax module, which also allows static initializations. Refer to chapter 6.5 (page 48) in the vasm.pdf.

A similar directive would be possible in mot-syntax. But I decided against it, because it is unusual and would be incompatible to any other 68k assembler.
phx is offline  
Old 03 January 2020, 12:26   #11
sparhawk
Registered User
 
sparhawk's Avatar
 
Join Date: Sep 2019
Location: Essen/Germany
Age: 55
Posts: 463
Quote:
Originally Posted by phx View Post
They are. rs.x appears in both documents. Just checked it.

WOW! Just checked again and suddenly I found it. LOL. Using the PDF search it doesn't seem to find it.



Quote:
There is a more powerful Structure directive in the oldstyle syntax module, which also allows static initializations. Refer to chapter 6.5 (page 48) in the vasm.pdf.

Does this mean, that I can switch between syntax modules in the source? Or is the respective syntax module statically linked in the assembler binary, so when I use the mk68vasm it uses the "mot" module?

I tried different variations but I always get an error "unknown mnemonic struct" or "unknown mnemonic endstruct", so I assume that the Old Style Syntax module is not enabled. So when I use a different vasm with the Old Style Syntax I probably can not assemble the standard includes, right?



So if I understand you correctly, with the mot module, I have to initialize a structure only at runtime, which is a bit limiting.

Is the source from vasm somewhere available in a repository? I only have the source as a download. I was thinking of maybe extending the documentation with a bit of examples, to make it easier to understand. Or how can one contribute?

Last edited by sparhawk; 03 January 2020 at 12:36.
sparhawk is offline  
Old 03 January 2020, 13:37   #12
hooverphonique
ex. demoscener "Bigmama"
 
Join Date: Jun 2012
Location: Fyn / Denmark
Posts: 1,642
You can switch syntax using command line flags - no need for a different binary.

Edit: This is wrong, of course - don't know what I was thinking :-D

Last edited by hooverphonique; 03 January 2020 at 15:23.
hooverphonique is offline  
Old 03 January 2020, 14:18   #13
meynaf
son of 68k
 
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,355
You can always initialize your structures with dc directives in macros...
meynaf is offline  
Old 03 January 2020, 14:56   #14
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,545
Quote:
Originally Posted by sparhawk View Post
Does this mean, that I can switch between syntax modules in the source?
No.

Quote:
Or is the respective syntax module statically linked in the assembler binary, so when I use the mk68vasm it uses the "mot" module?
Exactly. Usually it makes no sense to switch syntax modules in a source or even in a project.

Quote:
so I assume that the Old Style Syntax module is not enabled.
If you really want to try it you have to build vasm with
make CPU=m68k SYNTAX=oldstyle

But "oldstyle" is, as the name implies, intended for 8-bit CPUs. So I cannot recommend it.

Quote:
So when I use a different vasm with the Old Style Syntax I probably can not assemble the standard includes, right?
Correct.

Quote:
So if I understand you correctly, with the mot module, I have to initialize a structure only at runtime, which is a bit limiting.
Yes. But that's how it is. As I understand you're doing most of your code in C anyway, so there is still the option to initialize the structures in C and refer to them from the assembler source (xref).

Quote:
Is the source from vasm somewhere available in a repository?
Yes. In the CVS repository on Volker Barthelmann's server.

Quote:
I only have the source as a download. I was thinking of maybe extending the documentation with a bit of examples, to make it easier to understand. Or how can one contribute?
Patches and other kinds of contributions are sent to Volker or me by email (gerne in Deutsch). We will then check it and decide in which form it is applied - if at all. A patch has to make sense for us - or at least for many users.

Quote:
Originally Posted by hooverphonique View Post
You can switch syntax using command line flags - no need for a different binary.
Not in vasm. At least not the last time I checked.
You can switch the output module with -F. But neither the CPU- nor the syntax-module.
phx is offline  
Old 03 January 2020, 15:13   #15
sparhawk
Registered User
 
sparhawk's Avatar
 
Join Date: Sep 2019
Location: Essen/Germany
Age: 55
Posts: 463
Quote:
Originally Posted by phx View Post
Exactly. Usually it makes no sense to switch syntax modules in a source or even in a project.
Yes. This would sound a bit weird.

Quote:
If you really want to try it you have to build vasm with
make CPU=m68k SYNTAX=oldstyle

But "oldstyle" is, as the name implies, intended for 8-bit CPUs. So I cannot recommend it.
No. That wouldn't make much sense, as I want to be able to use the system includes and stuff, and only use some features I thought would be there.

Quote:
Yes. But that's how it is. As I understand you're doing most of your code in C anyway, so there is still the option to initialize the structures in C and refer to them from the assembler source (xref).
I created my build system so that I can do both, but my current project is focussed on pure assembly. Never had written big projects in assembler, so that's quite new to me, thus the many questions.

Quote:
Patches and other kinds of contributions are sent to Volker or me by email (gerne in Deutsch). We will then check it and decide in which form it is applied - if at all. A patch has to make sense for us - or at least for many users.
ok.
sparhawk is offline  
Old 03 January 2020, 15:26   #16
hooverphonique
ex. demoscener "Bigmama"
 
Join Date: Jun 2012
Location: Fyn / Denmark
Posts: 1,642
Quote:
Originally Posted by phx View Post
Not in vasm. At least not the last time I checked.
You can switch the output module with -F. But neither the CPU- nor the syntax-module.
Of course not - don't know why I was convinced of that when I normally use 'vasmm68k_mot'
hooverphonique is offline  
Old 03 January 2020, 15:32   #17
sparhawk
Registered User
 
sparhawk's Avatar
 
Join Date: Sep 2019
Location: Essen/Germany
Age: 55
Posts: 463
Quote:
Originally Posted by meynaf View Post
You can always initialize your structures with dc directives in macros...

Do you have some example? That's what I'm currently thinking about - if I could do some macro magic which creates a kind of "static initialization".
sparhawk is offline  
Old 03 January 2020, 16:29   #18
meynaf
son of 68k
 
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,355
Quote:
Originally Posted by sparhawk View Post
Do you have some example? That's what I'm currently thinking about - if I could do some macro magic which creates a kind of "static initialization".
Something like this :
Code:
init_copinfo macro
 dc.w \1
 dc.l \2
 dc.w \3
 endm

CopperInfo1: init_copinfo MyCopperListSize,MyCopperListHandler,0
meynaf is offline  
Old 03 January 2020, 20:08   #19
sparhawk
Registered User
 
sparhawk's Avatar
 
Join Date: Sep 2019
Location: Essen/Germany
Age: 55
Posts: 463
What is the 'dr.x' directive used for? Is there some example for this?

More general: Are there any sample sources where one could look how the various directives are used?
sparhawk is offline  
Old 03 January 2020, 22:31   #20
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,545
Quote:
Originally Posted by sparhawk View Post
What is the 'dr.x' directive used for?
I think that DR stands for Data Relative and writes the difference between the given value (usually a label) and the current address into memory.

Quote:
Is there some example for this?
Code:
label:
        dr.w    label,label
Is the same as:
        dc.w    0,-2


Quote:
More general: Are there any sample sources where one could look how the various directives are used?
There are nearly no vasm-specific directives. The mot-syntax module tries to be compatible with all common Amiga assemblers, like Devpac, AsmOne, PhxAss, etc.. So you could just look into any source you want.

Many recent projects were written with vasm. You can for example check the source from my game projects. The latest is here:
https://server.owl.de/~frank/BlkStberries.lha
phx is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Structure of CopList object? earok Coders. Blitz Basic 10 22 June 2019 05:37
Resource and Structure.offs copse Coders. General 4 23 December 2013 23:56
Side-scroller, boy in house, big friendly green monster roams around [Found: Mot] Cherno Looking for a game name ? 3 20 October 2013 00:55

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 03:22.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.10921 seconds with 13 queries