Announcement

Collapse
No announcement yet.

Problem passing argument to child program

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem passing argument to child program

    Hi!
    I've a parent program, written with VISI-GENIE, that run on FLASH BANK 0 and a child program, written in VISI, in the FLASH BLANK 1.
    I call the child with
    flash_Exec(1, myGlobal);
    where myGlobal is a global array located at the address 0x00DE.
    But, in the child program the argument of the main function always has value zero.
    Why?Am I doing something wrong?
    Regards
    Pietro

  • #2
    Is myGlobal set up as per the manual?

    eg

    Code:
    var myGlobal[2] ;
    var vars[20] ;
    
    myGlobal[0] := 1 ;      // one parameter present
    myGlobal[1] := vars ; // parameter 1
    Mark

    Comment


    • #3
      From the manual: "If arglistptr is 0, no arguments are passed, else arglist points to an array, the first element being the number of elements in the array."
      It is a bit different from what you are saying... But, even if I do as you say, the result is the same.

      Here is the code...

      Code:
      // MAIN PROGRAM
      
      var myGlob[GLOBAL_LEN];
      var argptr[2] := [2,myGlob];
      
      func toChild(var newval)
          print("before myGlobal := ", myGlob, "\n");
          pause(5000);
          var argptr[2];
          argptr[0] := 2;
          argptr[1] := myGlob;
          flash_Exec(2, argptr);
          print("RETURN");
      endfunc
      
      //////////////////////////////////
      
      //CHILD PROGRAM
      
      func main(var *argptr)
              var myGlobal;
              myGlobal := argptr[1];
              print("myGlobal := ", myGlobal, "\n");
              pause(5000);
      endfunc
      
      /////////////////////
      in this case, the main program print "before myGlobal := 222" and the child program print "myGlobal := 13510"
      If I instead declare argptr as global

      Code:
      // MAIN PROGRAM
      
      var myGlob[GLOBAL_LEN];
      var argptr[2] := [2,myGlob];
      
      func toChild(var newval)
          print("before myGlobal := ", myGlob, "\n");
          pause(5000);
          flash_Exec(2, argptr);
          print("RETURN");
      endfunc
      
      //////////////////////////////////
      the main main program print "before myGlobal := 222" and the child program print "myGlobal := -1"
      Pietro

      Comment


      • #4
        Hi,
        I've done several test and these are the results.
        Here the code for the child program

        Code:
        #platform "Gen4-uLCD-70DCT-CLB"
        
         #constant NOGLOBALS
        
         #MODE FLASHBANK_1
        // Program Skeleton 1.3 generated 19/04/2019 11:08:42
        
        #inherit "4DGL_16bitColours.fnc"
        
        #inherit "VisualConst.inc"
        
        #inherit "FiglioConst.inc"
        
        func main(var arg, var argv)
            var hndl;
        //  var hstrings ; // Handle to access uSD strings, uncomment if required
        //  var hFontx ;   // Handle to access uSD fonts, uncomment if required and change n to font number
        //  Uncomment the following if uSD images, fonts or strings used.
              /*
            putstr("Mounting...\n");
            if (!(file_Mount()))
                while(!(file_Mount()))
                    putstr("Drive not mounted...");
                    pause(200);
                    gfx_Cls();
                    pause(200);
                wend
            endif    */
        //    gfx_TransparentColour(0x0020);    // uncomment if transparency required
        //    gfx_Transparency(ON);             // uncomment if transparency required
        
        //  hFontn := file_LoadImageControl("Figlio.dan", "Figlio.gcn", 1); // Open handle to access uSD fonts, uncomment if required and change n to font number dropping a and c if > 9
        //  hstrings := file_Open("Figlio.txf", 'r') ; // Open handle to access uSD strings, uncomment if required
        
            hndl := file_LoadImageControl("Figlio.dat", "Figlio.gci", 1);
        
        
            gfx_Set(SCREEN_MODE,LANDSCAPE_R) ;
            gfx_BGcolour(arg[0]);
            gfx_Cls();
            print("SONO IL FIGLIO con hndl ", hndl, "\n");
            print("arg[0] := ", arg[0], " != ", WHITE, "\n");
            print("arg := ", arg, " != ", WHITE, "\n");
            //print("argv := ", argv, " != ", WHITE, "\n");
            pause(1000);
        
        
            // Winbutton1 1.0 generated 19/04/2019 11:14:16
            img_ClearAttributes(hndl, iWinbutton1, I_TOUCH_DISABLE); // set to enable touch, only need to do this once
            img_Show(hndl, iWinbutton1);  // show button, only do this once
            touch_Set(TOUCH_ENABLE);
            repeat
            if(touch_Get(TOUCH_STATUS) == TOUCH_RELEASED)
                print("ritorno da papa' tra 1 secondo\n");
                pause(1000);
                return;
            endif
            forever
        endfunc
        It works only if I put the second useless argument in the main function. Without var argv, the argument doesn't pass right.
        The main program is written in VISI-GENIE and, when required, it goes to the child with this code

        Code:
        print("global := ", global, "\n");
            print("argList := ", argList, "\n");
            pause(5000);
            flash_Exec(1,argList);
            ActivateForm(0);
        where arglist has been defined as

        Code:
        var global[2] := [WHITE,33];
        var argList[2] := [2,global];
        How can you explain this behavior?
        Pietro

        Comment


        • #5
          Not sure how you've interpreted the manual the way you have, this is the way it works

          Code:
          #platform "uLCD-43DT"
          
          #constant GLOBAL_LEN 50
          
          var dummy[123] ;            // move myGlob away from 0/1
          
          var myGlob[GLOBAL_LEN];        // could be global, or even local in func
          
          var argptr[2] := [1,myGlob];          // 1 parameter, can set in this way in global, or in func
          
          func toChild(var newval)
              print("before myGlob := ", myGlob, "\n");
              myGlob[0] := 12345 ;
              print("before myGlob[0] := ", myGlob[0], "\n");
              pause(5000);
              flash_Exec(FLASHBANK_2, argptr);    // could just use 2 here, but FLASHBANK_2 more readable
              print("RETURN");
          
              repeat forever
          endfunc

          Code:
          #platform "uLCD-43DT"
          
          #MODE FLASHBANK_2
          
          func main(var *myGlobal)
                  print("myGlobal := ", myGlobal, "\n");
                  print("myGlobal[0] := ", myGlobal[0], "\n");
                  pause(5000);
          endfunc
          Mark

          Comment


          • #6
            You've right...
            " ...else arglist points to an array, the first element being the number of elements in the array."

            Code:
            #constant NUMBER_OF_ELEMENTS 2
            
            var * arglist;
            var array[NUMBER_OF_ELEMENTS];
            arglist:= array; //arglist points to an array...
            
            // how many are the "elements in the array"? I think NUMBER_OF_ELEMENTS! 
            array[0] := NUMBER_OF_ELEMENTS; // should be...
            //but you say
            array[0] := (NUMBER_OF_ELEMENTS - 1);
            You are right, of course, and I can't read.
            Maybe an example in the manual, passing arguments, could be a good idea.

            Regards
            Pietro

            Comment

            Working...
            X