Announcement

Collapse
No announcement yet.

Diablo 16 Internal 4DGL function for SPE environment

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

  • #16
    I solved global variable problem by declaring all global variables in the master and pass that variable to slave via the parameters.

    I have another question. All variables in the slave must be declared in the main function, if a large-sized array will result in a stack overflow, how the solution to this problem? How to change stack size of slave bank? Thank you.

    Error as follows:
    EVE Stack Overflow
    errno=15
    PC=48
    SP=-5
    UserHeap 0
    SysHeap 11984

    Touch to continue...
    Last edited by rwin; 20th June 2015, 05:15 PM.

    Comment


    • #17
      I presume you mean a local array, not a global one (in the main bank).

      The #STACK nnn parameter in the main bank will set the stack space.

      When calling each other bank, since you are calling it, the stack space from the main bank is used.
      Mark

      Comment


      • #18
        Thank you mark, #STACK 1024 resolved my problem for stack overflow.

        How to passing struct from master to parameter of slave over pointer? I want assign structure values of master from slave.

        Struct:
        Code:
        #CONST
           ID     0
           XPOS   1
           YPOS   2
           VALUES 3
        #END
        var array0[STRUCT_LENGTH];
        var array1[STRUCT_LENGTH];
        ​var array2[STRUCT_LENGTH];
        Last edited by rwin; 21st June 2015, 05:39 AM.

        Comment


        • #19
          Not sure I completely understand the question.

          A struct is what is effectively passed when you use 'xbstg'.

          If you need separate strucs then just add another one, or add more elements to 'xbstg' (which perhaps 'globalises' it depending on how you look at it)
          Mark

          Comment


          • rwin
            rwin commented
            Editing a comment
            I create struct in master and slave. I send address struct of slave to the master. In the master side, just copy the value of the given address of the slave. Thank you for the help
            Last edited by rwin; 21st June 2015, 10:02 AM.

        • #20
          How to passing string from master to slave. I tried like the follow code but failed.

          //inherit files
          Code:
          #CONST
              fWRITEHEADER
          #END
          
          #CONST
              a,
              aArray + 64,
              b,
              c,
              d,
              e,
              xmLimit
          #END
          //master
          Code:
          #platform "uLCD-35DT"
          #MODE FLASHBANK_0
          #inherit "xbdefs.inc"
          
          var xbstg[xmLimit], args[3] ;
          
          func xbcall(var xfunc)
              args[2] := xfunc ;
              flash_Exec(FLASHBANK_1, args);
          endfunc
          
          func writeHeader(var *msg)
              xbstg[a] := msg;
              xbcall(fWRITEHEADER) ;
          endfunc
          
          func main()
              writeHeader("this is message from master");
          endfunc
          //slave
          Code:
          #platform "uLCD-35DT"
          #MODE FLASHBANK_1
          #inherit "xbdefs.inc"
          
          func main(var *xbstg, var funcId)
              var msg[64];
          
              switch(funcId)
                case fWRITEHEADER:
                    mem_Set(msg, '\0', sizeof(msg));
                    str_Copy(str_Ptr(msg), str_Ptr(xbstg[a]));
                  
                    gfx_Cls();
                    putstr(msg);
                    break;
                endswitch
          endfunc
          Last edited by rwin; 26th June 2015, 07:47 AM.

          Comment


          • #21
            Flash memory from one bank cannot be seen in another, but for your example there are ways around that. This shows how you can print from both RAM and Flash.

            Code:
            #CONST
                fWRITEHEADERram
                fWRITEHEADERflash
            #END
            
            #CONST
                a,
                b,
                c,
                d,
                e,
                xmLimit
            #END
            Code:
            #platform "uLCD-43DT"
            
            #MODE FLASHBANK_0
            #inherit "xbdefs.inc"
            
            var xbstg[xmLimit], args[3] ;
            
            func xbcall(var xfunc)
                args[2] := xfunc ;
                flash_Exec(FLASHBANK_1, args);
            endfunc
            
            func writeHeader(var *msg)
                xbstg[a] := msg;
                xbcall(fWRITEHEADERflash) ;
            endfunc
            
            func writeHeaderRam(var *msg)
                xbstg[a] := msg;
                xbcall(fWRITEHEADERram) ;
            endfunc
            
            func main()
                var strx[40] ;
                args[0] := 2 ;
                args[1] := xbstg ;
            
                writeHeader("This is a message from master in flash\n");
            
                to(strx) ;
                print("This is a message from master in RAM\n") ;
                writeHeaderRam(strx);
            
                repeat
                forever
            endfunc

            Code:
            #platform "uLCD-43DT"
            
            #MODE FLASHBANK_1
            #inherit "xbdefs.inc"
            
            func main(var *xbstg, var funcId)
                switch(funcId)
                  case fWRITEHEADERram:
            //          gfx_Cls();
                      putstr(xbstg[a]);
                      break;
                  case fWRITEHEADERflash:
            //          gfx_Cls();
                      flash_putstr(FLASHBANK_0, 16 + (xbstg[a] & 0x7fff));      // need to adjust address for flash_putstr
                      break;
                  endswitch
            endfunc
            Mark

            Comment


            • rwin
              rwin commented
              Editing a comment
              @Mark, Thank you for the prompts.

          • #22
            Hello Sir, I want to ask is related to the above topic.
            1. How to point to function in master from slave? I want to call keyboardHandler function in master from slave.
            2. Is possible to move keyboardHandler function to slave?

            master (bank0)
            func keyboardHandler(var key)

            endfunc

            slave (bank1)
            Code:
                          
            keyTouched := img_Touched(hndl, -1) ;
            if ((keyTouched >= iKeyboard1) && (keyTouched <= iKeyboard1 + oKeyboard1[KbButtons]))
                kbDown(hndl, iKeyboard1, oKeyboard1, iKeyboard1keystrokes, keyTouched-iKeyboard1, keyboardHandler);
            endif
            if (oKeyboard1[KbDown] != -1)
                kbUp(hndl, iKeyboard1, oKeyboard1);
            endif

            Comment


            • #23
              No, they really need to be in the same bank.

              Why do you need keyboardHandler to be in bank0?
              Mark

              Comment


              • #24
                I have difficulties when they want to move all the routine associated with a keyboard to another bank. The following functions(master) work properly when run in bank0, but when I moved to BANK2, an error occurred. I get error message: Error 29 PC=28496 v1=0 v2=0.

                master:
                Code:
                func enableKeyboard()
                    var i;
                    if(currentKeyboard==NUMERIC)
                        hndl                 := numericKeyboardHandle;
                        iKeyboard1           := iNumKeyboard1;
                        oKeyboard1           := oNumKeyboard1;
                        iKeyboard1keystrokes := iNumKeyboard1keystrokes;
                    else if(currentKeyboard==QWERTY)
                        hndl                 := qwertyKeyboardHandle;
                        iKeyboard1           := iQweKeyboard1;
                        oKeyboard1           := oQweKeyboard1;
                        iKeyboard1keystrokes := iQweKeyboard1keystrokes;
                    endif
                    if(currentKeyboard==NUMERIC || currentKeyboard==QWERTY)
                        for (i := iKeyboard1 + 1; i<=(iKeyboard1 + oKeyboard1[KbButtons]); i++)
                            img_SetWord(hndl, i, IMAGE_FLAGS, (img_GetWord(hndl, i, IMAGE_FLAGS) | I_STAYONTOP) & ~I_TOUCH_DISABLE);
                        next
                        img_Enable(hndl, iKeyboard1);
                        img_Show(hndl, iKeyboard1);
                
                        isKeyboardVisible := TRUE;
                    endif
                endfunc
                
                func readKeyboard()
                    if(isKeyboardVisible==TRUE)
                        if(currentKeyboard== NUMERIC)
                            hndl                 := numericKeyboardHandle;
                            iKeyboard1           := iNumKeyboard1;
                            oKeyboard1           := oNumKeyboard1;
                            iKeyboard1keystrokes := iNumKeyboard1keystrokes;
                        else if(currentKeyboard == QWERTY)
                            hndl                 := qwertyKeyboardHandle;
                            iKeyboard1           := iQweKeyboard1;
                            oKeyboard1           := oQweKeyboard1;
                            iKeyboard1keystrokes := iQweKeyboard1keystrokes;
                        endif
                        keyTouched := img_Touched(hndl, -1) ;
                        if ((keyTouched >= iKeyboard1) && (keyTouched <= iKeyboard1 + oKeyboard1[KbButtons]))
                            kbDown(hndl, iKeyboard1, oKeyboard1, iKeyboard1keystrokes, keyTouched-iKeyboard1, keyboardHandler);
                        endif
                        if (oKeyboard1[KbDown] != -1)
                            kbUp(hndl, iKeyboard1, oKeyboard1);
                        endif
                    endif
                endfunc
                
                func keyboardHandler(var keyval)
                    var chrKey;
                
                    if(isKeyboardVisible==TRUE)
                        if(currentWindow==KEYBOARD_WINDOW)
                            // asciiKey=public access, key=private access
                            asciiKey := NULL;
                            if(keyval==CANCEL || keyval==ESCAPE)
                                asciiKey := CANCEL;
                            else if(keyval==CLEAR)
                                clearKeyboardBuffer(RECYCLE_WAVE);
                            else if(keyval==ENTER)
                                str_PutByte(kb[KB_PMSG]++, NULL);  // null
                                asciiKey := ENTER;
                                //memSet(info, NULL, sizeof(info)); to(info); print([STR]&kb[MSG]); writeHalfHeader(LEFT_ALIGN, info);
                            else if (keyval>=0x20 && keyval<=0x7F)
                                if(kb[KB_COUNT]==0) keyboardInit();
                                if(kb[KB_COUNT] < kb[KB_LENGTH])
                                    str_PutByte(kb[KB_PMSG]++, keyval); // ascii
                                    if(previousWindow==MAIN_WINDOW)
                                        gfx_RectangleFilled(kb[KB_XPOS], kb[KB_YPOS], kb[KB_XPOS]+9, kb[KB_YPOS]+12, TEXT_FONTCOLOR);
                                        kb[KB_XPOS] += 14;
                                    else
                                        to(chrKey); putch(keyval);      // char
                                        setText(0, 0, kb[KB_XPOS], kb[KB_YPOS], TEXT_FONTCOLOR, FONT3, chrKey);
                                        kb[KB_XPOS] += 9;
                                    endif
                                    kb[KB_COUNT] += 1;
                                    playSound(TOUCH_WAVE);
                                endif
                            endif
                        endif
                    endif
                endfunc
                I split above program as follows:

                master:
                Code:
                var params[_paramsLimit], args[3] ;
                
                func callBank(var funcId, var bankId)
                    args[0] :=  2;          // two slave parameters (*params, funcId)
                    args[1] := params;  // passing input/output to slave *params
                    args[2] := funcId;    // passing function id (input)
                    flash_Exec(bankId, args);
                endfunc
                
                func enableKeyboard()
                    params[_a] := currentKeyboard;
                    if(currentKeyboard==NUMERIC)
                        params[_b] := numericKeyboardHandle;
                    else if(currentKeyboard==QWERTY)
                       params[_b] := qwertyKeyboardHandle;
                    endif
                    callBank(_enableKeyboard, FLASHBANK_2);
                    isKeyboardVisible := params[_c];
                endfunc
                
                func readKeyboard()
                    params[_a] := isKeyboardVisible;
                    params[_b] := currentKeyboard;
                    if(currentKeyboard==NUMERIC)
                        params[_c] := numericKeyboardHandle;
                    else if(currentKeyboard==QWERTY)
                        params[_c] := qwertyKeyboardHandle;
                    endif
                    callBank(_readKeyboard, FLASHBANK_2);
                endfunc
                
                func keyboardHandler(var keyval)
                
                endfunc
                slave:
                Code:
                #platform "uLCD-43DT"
                #MODE FLASHBANK_2
                #STACK 4096
                #inherit  "qweKbConst.inc"
                #inherit  "numKbConst.inc"
                #inherit  "kbRoutines.inc"
                #inherit  "shared.inc"
                
                /////// KEYBOARD ROUTINES ///////
                
                func main(var *params, var funcId)
                    // local variable
                    var *hndl, *iKeyboard1, *oKeyboard1, *iKeyboard1keystrokes;
                    var i;
                
                    // input passed from master
                    var *numericKeyboardHandle, *qwertyKeyboardHandle;
                    var currentKeyboard, keyTouched, keyboardHandler;
                
                    // output passed to master
                    var isKeyboardVisible;
                
                    switch (funcId)
                        case _enableKeyboard:
                            // input currentKeyboard
                            currentKeyboard := params[_a];
                
                            if(currentKeyboard==NUMERIC)
                                // input numericKeyboardHandle
                                numericKeyboardHandle   := params[_b];
                
                                hndl                 := numericKeyboardHandle;
                                iKeyboard1           := iNumKeyboard1;           // numKbConst.inc
                                oKeyboard1           := oNumKeyboard1;           // numKbConst.inc
                                iKeyboard1keystrokes := iNumKeyboard1keystrokes; // numKbConst.inc
                
                            else if(currentKeyboard==QWERTY)
                                // input qwertyKeyboardHandle
                                qwertyKeyboardHandle    := params[_b];
                
                                hndl                 := qwertyKeyboardHandle;
                                iKeyboard1           := iQweKeyboard1;           // kbRoutines.inc
                                oKeyboard1           := oQweKeyboard1;           // kbRoutines.inc
                                iKeyboard1keystrokes := iQweKeyboard1keystrokes; // kbRoutines.inc
                            endif
                
                            if(currentKeyboard==NUMERIC || currentKeyboard==QWERTY)
                                for (i := iKeyboard1 + 1; i<=(iKeyboard1 + oKeyboard1[KbButtons]); i++)
                                    img_SetWord(hndl, i, IMAGE_FLAGS, (img_GetWord(hndl, i, IMAGE_FLAGS) | I_STAYONTOP) & ~I_TOUCH_DISABLE);
                                next
                                img_Enable(hndl, iKeyboard1);
                                img_Show(hndl, iKeyboard1);
                
                                isKeyboardVisible := TRUE;
                
                                // output isKeyboardVisible
                                params[_c] := isKeyboardVisible;
                            endif
                            break;
                
                        case _readKeyboard:
                            // input isKeyboardVisible
                            isKeyboardVisible := params[_a];
                            // input currentKeyboard
                            currentKeyboard := params[_b];
                
                            if(isKeyboardVisible==TRUE)
                                if(currentKeyboard== NUMERIC)
                                    // input numericKeyboardHandle
                                    numericKeyboardHandle   := params[_c];
                
                                    hndl                 := numericKeyboardHandle;
                                    iKeyboard1           := iNumKeyboard1;           // numKbConst.inc
                                    oKeyboard1           := oNumKeyboard1;           // numKbConst.inc
                                    iKeyboard1keystrokes := iNumKeyboard1keystrokes; // numKbConst.inc
                
                                else if(currentKeyboard == QWERTY)
                                    // input qwertyKeyboardHandle
                                    qwertyKeyboardHandle    := params[_c];
                
                                    hndl                 := qwertyKeyboardHandle;
                                    iKeyboard1           := iQweKeyboard1;           // kbRoutines.inc
                                    oKeyboard1           := oQweKeyboard1;           // kbRoutines.inc
                                    iKeyboard1keystrokes := iQweKeyboard1keystrokes; // kbRoutines.inc
                                endif
                
                                keyTouched := img_Touched(hndl, -1) ;
                                if ((keyTouched >= iKeyboard1) && (keyTouched <= iKeyboard1 + oKeyboard1[KbButtons]))
                                    kbDown(hndl, iKeyboard1, oKeyboard1, iKeyboard1keystrokes, keyTouched-iKeyboard1, _keyboardHandler);  // how to point to keyboard handler ??
                                endif
                                if (oKeyboard1[KbDown] != -1)
                                    kbUp(hndl, iKeyboard1, oKeyboard1);
                                endif
                            endif
                            break;
                    
                    case _keyboardHandler:
                            break;
                
                    endswitch
                endfunc
                Last edited by rwin; 27th June 2015, 10:31 AM.

                Comment


                • #25
                  The solution to that was described in post 15
                  Mark

                  Comment


                  • #26
                    I can see

                    var oQweKeyboard1
                    and
                    var oNumKeyboard1

                    In the attached files, I imagine they will end up as global variables.
                    Mark

                    Comment


                    • rwin
                      rwin commented
                      Editing a comment
                      Yes, you are right, still array variable on there. Thank you mark.
                  Working...
                  X