Jump to content
IGNORED

MADS Struct Problem


Recommended Posts

I've used MADS structs moderately in the past, but now I'm implementing an object tree and I'm using enumerated variables as CLASS IDs (no problem), and structs as objects. I have:

 

; Menu object

MENU  .struct
class .byte
parent .word ; pointer to parent (menu bar or parent menu)
child .word ; pointer to first child (menu item)
children .byte
prev  .word
next  .word
x  .word ; x-coordinate (all items in menu will all inherit this value)
y  .byte ; y-coordinate (first item in menu will inherit this value)
width .byte ; pre-computed values
height .byte
visible .byte

items .byte ; number of items in menu
curr_item .byte ; current item

.ends

; Menu-item object (used for both menus and menu bar)

MENU_ITEM  .struct
class .byte
parent .word ; pointer to menu object this item belongs to (menu or menu bar)
child .word ; pointer to child (top-level menu or sub-menu), or event procedure for this item
children .byte
prev  .word  ; pointer to previous menu item in list
next  .word ; pointer to next menu item in list
x  .word ; x-coordinate
y  .byte ; y-coordinate
width .byte ; item width (inherited from parent)
height .byte ; item height
visible .byte

data  .word ; pointer to static menu data block
offset .byte ; size of right-aligned text
.ends

In order to allocate RAM for objects, I need to know the size of the structure. MADS is supposed to yield the size of the struct with:

 

LDA #[name]

 

Indeed it does, but on every occasion I use this notation, the compiler flags up an error:

 

Could not use [name] in this context.

 

However, the compiler produces the correct code (i.e. LDA # <bytes in structure>)

 

It's most confusing having the compilation flooded with errors, however. Any ideas?

Edited by flashjazzcat
Link to comment
Share on other sites

Seems I was using a beta of the 1.9.2 release without realizing it. I noticed a news item about MADS 1.9.2 at AtariArea this evening, downloaded and installed it and the structure context error showed up again. I've reported the bug(?) to Tebe.

Edited by flashjazzcat
Link to comment
Share on other sites

I just have to say that the latest version of MADS is absolutely superb. The new constructors work brilliantly, and make assembly lanuguage source listings every bit as readable as C code. The only thing I can't do is:

 

lda #.len widget.class

 

I thought this might have returned the size of "class" in bytes (i.e. whether it's a byte or word), but it returns 0. This would have been kind of useful if you changed "class" from a byte to a word in the structure and wanted the code which handles it to automatically change to suit.

 

But hey - if I have to go to those lengths to find something that MADS won't do... :)

Link to comment
Share on other sites

  • 2 weeks later...

.LEN is for LOCAL_NAME, PROC_NAME, STRUCT_NAME, ARRAY_NAME

 

.LEN is not for field, only for BLOCK_NAME

 

.LEN block_name
.len (block_name)

.local temp              ; = LOCAL_NAME
label lda #0
.endl

.print .len temp         ; = 2
.print .len temp.label   ; = 0


.array tab [255] .byte
[1] = 100
[150]= 12
.enda

.print .len tab          ; = 256

 

 

if you want field size in struct then

 

lda #struct.field

Link to comment
Share on other sites

.LEN is for LOCAL_NAME, PROC_NAME, STRUCT_NAME, ARRAY_NAME

 

.LEN is not for field, only for BLOCK_NAME

 

.LEN block_name
.len (block_name)

.local temp              ; = LOCAL_NAME
label lda #0
.endl

.print .len temp 		; = 2
.print .len temp.label   ; = 0


.array tab [255] .byte
[1] = 100
[150]= 12
.enda

.print .len tab          ; = 256

 

 

if you want field size in struct then

 

lda #struct.field

Excellent. It was hard to deduce from the docs that .len was so versatile.

 

However,

 

lda #struct.field

returns the index to the field (i.e. the offset from the start of the struct). I was referring to the size of the field (i.e. 1 for a byte, 2 for a word, or n for a nested structure):

 

.struct   widget
class        	.byte
parent 		.word
child        	.word
.ends

.struct menu
widget

ID   			.byte
.ends

lda #.len widget.class ; 1
lda #.len menu.widget ; 5
lda #.len menu.widget.parent ; 2

I realize that would probably break something else, though, and I can get along just fine without it. MADS is making light work of some very complex assembly code: thanks again! icon_smile.gif

Edited by flashjazzcat
Link to comment
Share on other sites

flashjazzcat,

 

Isn't having the offset to the starting position of a field almost tantamount to having the size of the preceeding field?

 

I mean if MADS will give you the offset to the start of parent, and you know the location of the start of the struct, don't you now know how big class is? I will admit that you still don't have the simplicity of .len widget.class, but it is deducible, is it not?

Link to comment
Share on other sites

Isn't having the offset to the starting position of a field almost tantamount to having the size of the preceeding field?

 

I mean if MADS will give you the offset to the start of parent, and you know the location of the start of the struct, don't you now know how big class is? I will admit that you still don't have the simplicity of .len widget.class, but it is deducible, is it not?

You're right, by Jove! :)

 

Thanks.

Link to comment
Share on other sites

  • 1 month later...
  • 1 month later...

1.

.SEGDEF label address length [attrib] [vbank]
.SEGMENT label
.ENDSEG

attrib: r,w,rw

.segdef bcart0 $8000 $2000 r


.segment bcart0
lda #0
...
...
temp
sta temp         ; error (only READ)

.endseg

 

 

2.

lmb #1             ; load vmemmory bank = 1

;.... code
temp1              ; if v memmory <> 0 -> all labels local
temp2


lmb #2             ; vmemmory = 2

; .... code
lda temp1         ; error -> undefined label


rmb                ; reset vmemmory bank = 0 (lmb #0)

lda temp1         ; if v memmory = 0 -> full access for all vmemmory banks
lda temp2

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...