Shop OBEX P1 Docs P2 Docs Learn Events
Retrieving various data from DAT blocks — Parallax Forums

Retrieving various data from DAT blocks

CassLanCassLan Posts: 586
edited 2009-03-04 16:12 in Propeller 1
Hi folks,

I'm trying to make a re-usable menu function, where the menu choices, # of choices is stored in DAT blocks for now.

I cant seem to get this right, the code below prints "M" on the screen which makes sense, but as soon as I incement the dattemp variable, which is supposed to be the offset of the starting menudata, I get junk.

Anyone know where I'm going wrong?





PUB Main

· 'start term
· text.start(12)
· 'start the keyboard
· kb.start(26, 27)

· 'Display the Main Menu
· textmenu(MainMenu)

PUB TextMenu (StartofMenuData)
· dattemp :=0
· ''Start By Displaying Name of Menu
· text.out(StartofMenuData[noparse][[/noparse]dattemp])

DAT
MainMenu····· byte "Main Menu·· ",0,4
············· byte "System Info ",0
············· byte "Setup······ ",0
············· byte "Another Opt ",0
············· byte "Last Option ",0

Comments

  • CassLanCassLan Posts: 586
    edited 2009-02-28 20:48
    So am I wrong in assuming that every byte I make in a DAT block directly preceds the one before it?

    Cause I'm assuming that all 66 bytes of data here start at memory address [noparse][[/noparse]MainMenu] and go continuous until the 0 after "Last Option".

    Additionally, to the matter of indexing each option..my goal is to create a function that only needs to be told the begining of a menu's data, from that point on it will be able to render the menu, regardless of how many choices, the length of the choice names, or the outcomes of such choices.
    In this manner the menu can be changed in the DAT block (or eeprom later) and the program will still function, if I add or remove choices.

    Thanks,

    Rick

    Post Edited (CassLan) : 2/28/2009 8:58:57 PM GMT
  • jazzedjazzed Posts: 11,803
    edited 2009-02-28 20:53
    Spin arrays have no concept of data type. You have to use a cast.
    Also you should pass the address of MainMenu to the method: textMenu(@MainMenu)
    Then text.out ... becomes
    text.out(byte[noparse][[/noparse]StartOfMenuData+n]) 'where n is an index into the array.

    There are easier ways to do it though with text.str and the @@ operator ....
    See page 279 of the bookmarked manual for more details.

    Using grasshopper's example ...
    MainMenu long @Menu1, @Menu2, @Menu3
    Then call with
    textMenu(@@MainMenu)

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    --Steve
  • CassLanCassLan Posts: 586
    edited 2009-02-28 21:01
    Thank you!! That did it.

    I had tried @ when calling the method, but had not used·byte when referencing the data.

    Thanks!!



    Rick
  • MGreimMGreim Posts: 114
    edited 2009-03-04 16:12
    Hi Roick, Hi Steve,

    i am also just writing such a menu system, many thanks for your hints.
    If its ready i will post my code

    Regards

    Markus
Sign In or Register to comment.