Shop OBEX P1 Docs P2 Docs Learn Events
A question about swinging Tarzan parameters through a Jungle of Methods. — Parallax Forums

A question about swinging Tarzan parameters through a Jungle of Methods.

ElectricAyeElectricAye Posts: 4,561
edited 2009-05-29 15:46 in Propeller 1
I'm having a problem passing parameters from method to method which is insanely illustrated by the following quasi-code:


PUB Main

{Call up the Jungle Method and pass the Tarzan Parameter...}
Jungle(Tarzan) 'Tarzan being a Hub RAM address.


PUB Jungle(TarzanSwings) 'Method in which Tarzan isn't yet needed.
  {Call up the Swamp Method and pass the TarzanSwings Parameter...}
   Swamp(TarzanSwings)

PUB Swamp(TarzanSwingsAgain) 'Method in which Tarzan  is still not yet needed.
   {Call up the Trees Method and pass the TarzanSwingsAgain Parameter...}
   Trees(TarzanSwingsAgain)

PUB Trees(TarzanSwingsAgainAndAgain) 'Method in which Tarzan is still not yet needed.
   {Call up the HighPowerLines Method and pass the TarzanSwingsAgainAndAgain Parameter...}
   HighPowerLines(TarzanSwingsAgainAndAgain)

PUB HighPowerLines(TarzanDiesOfElectrocution)
          {This is the only place in the program where I really need Tarzan and if he hasn't been electrocuted by now then he certainly has died of exhaustion.}
   




So my question is this: Is there any way to avoid having a parameter Tarzan-swing its way from one method to another if I don't really need the parameter until "deep down" in the method calls? In my particular application, Tarzan happens to be the address of an array stored in Hub RAM. Any suggestions?

Cheetah thanks you,

smile.gif

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Watching the world pass me by, one photon at a time.

Comments

  • PhilldapillPhilldapill Posts: 1,283
    edited 2009-05-29 06:31
    LOL I love how you explained this.

    This seems to obvious to be correct... but what about using a global variable instead?
  • heaterheater Posts: 3,370
    edited 2009-05-29 06:35
    If all those methods are in the same object why not just set up a global Tarzan holding the required address ?

    If they are in different objects things get a bit more tricky.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    For me, the past is not over yet.
  • localrogerlocalroger Posts: 3,452
    edited 2009-05-29 12:36
    @EA, if it's enough of a nuisance you could always define an arbitrary high memory location and use it to pass Tarzan's location.

    PUB Jungle
    ...WORD[noparse][[/noparse]$7FFE] := @tarzan

    PUB HighPowerLines
    ...tarzan := long[noparse]/noparse]word[noparse][[/noparse]$7FFE

    This guarantees everyone can find it, but you have to be careful not to step on it if you use the technique more than once.
  • MagIO2MagIO2 Posts: 2,243
    edited 2009-05-29 13:16
    Now it gets dirty ... if this is only the case for some variables, you could use some unused COG memory ... for example OUTB, INB, PHSA, PHSB, FREQA, FREQB. You set these in the upper function and read it in the bottom function. (Of course only if you don't need them in between).

    In another thread we talked about using unused COGs as additional RAM. This would work as well in this case if you have not enough free HUB-RAM to use the high-memory trick but you have some unused COGs.

    The HIGH memory trick would be better to read, if you use constants to define the memory adress and use the constant in both places where you access it.

    Post Edited (MagIO2) : 5/29/2009 1:21:48 PM GMT
  • ElectricAyeElectricAye Posts: 4,561
    edited 2009-05-29 13:19
    localroger said...
    ....you could always define an arbitrary high memory location and use it to pass Tarzan's location.

    localroger,
    by "high memory location" are you talking about the Hub RAM or would this be an EEPROM location?

    And, if I understand this right, what you're saying is that instead of passing an address by using a variable NAME (like Tarzan, TarzanSwings, etc.), I can instead use hexadecimal notation to assign it a known NUMERICAL address???

    Thanks, guys, and I'm sorry if my question seems obviously stupid. Until now, I guess I never had to figure out what it means for variables to be "global", etc.

    Mark blush.gif
  • localrogerlocalroger Posts: 3,452
    edited 2009-05-29 15:39
    @EA: That would be hub RAM. If you hit F8 instead of F10/F11 the proptool will show you your application's memory usage; it starts at $0000 and grows toward the top of Hub RAM at $7FFF. It is generally safe to use hub RAM above your application by accessing it directly with BYTE, WORD, and LONG. This is for example how the frame buffers are handled in the graphics demo object, and it's how a lot of PASM apps get to their data in hub RAM.
  • ElectricAyeElectricAye Posts: 4,561
    edited 2009-05-29 15:46
    localroger said...
    ... It is generally safe to use hub RAM above your application by accessing it directly with BYTE, WORD, and LONG. ...

    Thanks, roger. And thanks to heater and Philldapill, too. I think I'm beginning to grok this thing now. Maybe Tarzan can take a short cut from now on.


    smile.gif
Sign In or Register to comment.