flashjazzcat Posted January 20, 2011 Share Posted January 20, 2011 (edited) 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 January 20, 2011 by flashjazzcat Quote Link to comment Share on other sites More sharing options...
flashjazzcat Posted January 20, 2011 Author Share Posted January 20, 2011 OK - solved it. Seemed to be a buggy version of MADS of uncertain origin. I went back to MADS 1.9.0 and all is well. Quote Link to comment Share on other sites More sharing options...
flashjazzcat Posted January 24, 2011 Author Share Posted January 24, 2011 (edited) 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 January 24, 2011 by flashjazzcat Quote Link to comment Share on other sites More sharing options...
tebe Posted January 25, 2011 Share Posted January 25, 2011 don't use LDA #[name_struct] use LDA #.len [name_struct] Quote Link to comment Share on other sites More sharing options...
flashjazzcat Posted January 25, 2011 Author Share Posted January 25, 2011 don't use LDA #[name_struct] use LDA #.len [name_struct] Brilliant - thanks Tebe. I hope you can appreciate it's not easy to get this information from Google translated docs. Quote Link to comment Share on other sites More sharing options...
flashjazzcat Posted January 31, 2011 Author Share Posted January 31, 2011 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... Quote Link to comment Share on other sites More sharing options...
tebe Posted February 8, 2011 Share Posted February 8, 2011 .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 Quote Link to comment Share on other sites More sharing options...
flashjazzcat Posted February 8, 2011 Author Share Posted February 8, 2011 (edited) .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! Edited February 8, 2011 by flashjazzcat Quote Link to comment Share on other sites More sharing options...
Kylev Posted February 8, 2011 Share Posted February 8, 2011 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? Quote Link to comment Share on other sites More sharing options...
tebe Posted February 9, 2011 Share Posted February 9, 2011 lda #struct.field sorry, not size, offset Quote Link to comment Share on other sites More sharing options...
flashjazzcat Posted February 9, 2011 Author Share Posted February 9, 2011 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. Quote Link to comment Share on other sites More sharing options...
flashjazzcat Posted March 10, 2011 Author Share Posted March 10, 2011 Does MADS have a ".bank" function similar to that found in the latest version of ATASM? I'm thinking ahead here to coding for a banked cartridge, and it would be useful to know which bank a label is in. Quote Link to comment Share on other sites More sharing options...
tebe Posted April 15, 2011 Share Posted April 15, 2011 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.