User Tag List

Page 2 of 3 FirstFirst 1 2 3 LastLast
Results 11 to 20 of 23

Thread: Problem Writing a Function

  1. #11
    The Timelord
    QDB Manager
    ZC Developer

    Join Date
    Oct 2006
    Location
    Prydon Academy
    Posts
    1,396
    Mentioned
    112 Post(s)
    Tagged
    1 Thread(s)
    vBActivity - Stats
    Points
    4,760
    Level
    21
    vBActivity - Bars
    Lv. Percent
    68.7%
    I think that I may have found the cause of that bizarre error, so I'm testing now. I managed to get everything to compile in ZQ without generating it, so I am reverting one change to see if it was the cause. if not, then I will have at least narrowed the possibilities.

    The functions compile now, but they do not return or set the correct values, so clearly something in my method is wrong.

    @Gleeok : You should wait a little bit, until i post the revised code, as that at least doesn't spill errors, and thank you.

    ...also...

    I know that AS would be easier. I'm not against AS... I'm against deprecating ZScript. I think they could coincide, but Saffith is against that because of the extra work. What can I say?

    But give me credit for adding so much stuff that does work without breaking everything/ Getting those warp sounds not to conflict was a pain, and I think I'm going to do some mild rewrites of the warp code so that it's easier to handle this sort of thing, and to segregate these into individual vars, so that it is easy for the user to set up sounds per type, and to enable/disable them at will.

    How is the merge of the script drawing stuff going?

    We're working on migrating to ag 4.4.2 over on our end, in theory.

    @Gleeok & @DarkDragon : Between the three of us, I think we could make a very good, succinct, compact, master doc for adding ZScript. What do you say? I can make the majority of it, and pass it to you two to fill in the blanks, and clarify things.

  2. #12
    Administrator DarkDragon's Avatar
    Join Date
    Oct 2001
    Posts
    6,228
    Mentioned
    70 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    11,025
    Level
    31
    vBActivity - Bars
    Lv. Percent
    8.16%
    Well, it's easy compared to other changes like modifying the language grammar or adding support for arrays or strings, etc

  3. #13
    The Time-Loop Continues ZC Developer
    Gleeok's Avatar
    Join Date
    Apr 2007
    Posts
    4,815
    Mentioned
    259 Post(s)
    Tagged
    10 Thread(s)
    vBActivity - Stats
    Points
    12,933
    Level
    33
    vBActivity - Bars
    Lv. Percent
    23.44%
    It's also easier than writing my own scripting language, in fairness.


    Quote Originally Posted by ZoriaRPG View Post
    How is the merge of the script drawing stuff going?
    I'm not doing anything until the master branch gets sorted out. Also, it's the holidays and I probably won't get around to anything major until January.
    This post contains the official Gleeok seal of approval. Look for these and other posts in an area near you.

  4. #14
    The Timelord
    QDB Manager
    ZC Developer

    Join Date
    Oct 2006
    Location
    Prydon Academy
    Posts
    1,396
    Mentioned
    112 Post(s)
    Tagged
    1 Thread(s)
    vBActivity - Stats
    Points
    4,760
    Level
    21
    vBActivity - Bars
    Lv. Percent
    68.7%
    Here is the entire set of code sections across all the files for these three functions.

    @Gleeok @DarkDragon , this should be a cleaner way to look at it:

    Code:
    //Beta 24
    
    //////////////
    /// link.h ///
    //////////////
    
    void setTile(int state, int tile, int dir, int flip);
    int getExtend(int state, int dir);
    void setExtend(int state, int dir, int value);
        
        
    ////////////////
    /// link.cpp ///
    ////////////////
    
    //Set Link's tile
    //Link->SetTile(state, tile, dir, flip)
    void LinkClass::setTile(int state, int tile, int dir, int flip){
    	setlinktile(tile, flip, getExtend(state,dir), state, dir);
    }
    
    //Link->Extend
    
    void LinkClass::setExtend(int state, int dir, int value){
    	switch(state){
    		case 1: 
    			walkspr[dir][spr_extend] = value;
    			break;
    		case 2: 
    			floatspr[dir][spr_extend] = value;
    			break;
    		case 3: 
    			swimspr[dir][spr_extend] = value;
    			break;
    		case 4: 
    			divespr[dir][spr_extend] = value;
    			break;
    		case 5:
    			slashspr[dir][spr_extend] = value;
    			break;
    		case 6:
    			jumpspr[dir][spr_extend] = value;
    			break;
    		case 7: 
    			chargespr[dir][spr_extend] = value;
    			break;
    		case 8:
    			stabspr[dir][spr_extend] = value;
    			break;
    		case 9: 
    			poundspr[dir][spr_extend] = value;
    			break;
    		case 10: 
    			castingspr[spr_extend] = value;
    			break;
    		case 11: 
    			holdspr[spr_landhold][spr_hold1][spr_extend] = value;
    			break;
    		case 12: 
    			holdspr[spr_landhold][spr_hold2][spr_extend] = value;
    			break;
    		case 13: 
    			holdspr[spr_waterhold][spr_hold1][spr_extend] = value;
    			break;
    		case 14: 
    			holdspr[spr_waterhold][spr_hold2][spr_extend] = value;
    		
    		default: break;
    	}
    }
    
    int LinkClass::getExtend(int state, int dir){
    	switch(state){
    		case 1: 
    			return walkspr[dir][spr_extend];
    		case 2: 
    			return floatspr[dir][spr_extend];
    		case 3: 
    			return swimspr[dir][spr_extend];
    		case 4: 
    			return divespr[dir][spr_extend];		
    		case 5: 
    			return slashspr[dir][spr_extend];
    		case 6:
    			return jumpspr[dir][spr_extend];
    		case 7: 
    			return chargespr[dir][spr_extend];
    		case 8:
    			return stabspr[dir][spr_extend];
    		case 9: 
    			return poundspr[dir][spr_extend];
    		case 10: 
    			return castingspr[spr_extend];
    		case 11: 
    			return holdspr[spr_landhold][spr_hold1][spr_extend];
    		case 12: 
    			return holdspr[spr_landhold][spr_hold2][spr_extend];
    		case 13: 
    			return holdspr[spr_waterhold][spr_hold1][spr_extend];
    		case 14: 
    			return holdspr[spr_waterhold][spr_hold2][spr_extend];
    		default: return -1;
    	}
    }
    
    
    /////////////////
    /// ffasm.cpp ///
    /////////////////
    
    { "SETLINKTILE", 0,   0,   0,   0},
    { "SETLINKEXTEND", 0,   0,   0,   0},
    { "GETLINKEXTEND", 2,   0,   0,   0},
    
    
    //////////////////
    /// ffscript.h ///
    //////////////////
    
    SETLINKTILE, //0x00F1
    SETLINKEXTEND, //0x00F2
    GETLINKEXTEND, //0x00F3
         
    
    ////////////////////
    /// ffscript.cpp ///
    ////////////////////
        
        case SETLINKTILE:
    		Z_message("Trying to set Link's tile.\n");
    		set_link_tile(false);
    		break;
        
        case SETLINKEXTEND:
    		Z_message("Trying to set Link->SetExtend().\n");
    		set_link_extend(false);
    		break;
        
        case GETLINKEXTEND:
    		Z_message("Trying to get Link->GetExtend().\n");
    		get_link_extend(true);
    		break;
    	
    	
    	
    void set_link_tile(bool v)
    {
        int state   = SH::read_stack(ri->sp + 3) / 10000;
        int tile = SH::read_stack(ri->sp + 2) / 10000;
        int dir   = SH::read_stack(ri->sp + 1) / 10000;
        int flip   = SH::read_stack(ri->sp + 0) / 10000;
        Link.setTile(vbound(state,1,14),vbound(tile,0,65519),vbound(dir,0,16),vbound(flip,0,16));
    }
    
    void set_link_extend(bool v)
    {
        int state   = SH::read_stack(ri->sp + 2) / 10000;
        int extend = SH::read_stack(ri->sp + 1) / 10000;
        int dir   = SH::read_stack(ri->sp + 0) / 10000;
        Link.setExtend(vbound(state,1,14),vbound(dir,0,16),vbound(extend,0,16));
    }
    
    void get_link_extend(bool v)
    {
        int state   = SH::read_stack(ri->sp + 1) / 10000;
        int dir   = SH::read_stack(ri->sp + 0) / 10000;
        int extend = (int)Link.getExtend(state, dir);
        set_register(sarg1, extend*10000);
    }
    
    //////////////////
    /// Bytecode.h ///
    //////////////////
    
    #define LINKEXTEND 392
    #define SETLINKEXTEND 393
    #define GETLINKEXTEND 394
    
    
    class OSetLinkTile : public Opcode
    {
    public:
        string toString();
        Opcode *clone()
        {
            return new OSetLinkTile();
        }
    };
    
    class OSetLinkExtend : public Opcode
    {
    public:
        string toString();
        Opcode *clone()
        {
            return new OSetLinkExtend();
        }
    };
    
    class OGetLinkExtend : public BinaryOpcode
    {
    public:
        OGetLinkExtend(Argument *A, Argument *B) : BinaryOpcode(A,B) {}
        string toString();
        Opcode *clone()
        {
            return new OGetLinkExtend(a->clone(), b->clone());
        }
    };
    
    ////////////////////
    /// Bytecode.cpp ///
    ////////////////////
    
    string OSetLinkTile::toString()
    {
        return "SETLINKTILE";
    }
    
    string OSetLinkExtend::toString()
    {
        return "SETLINKEXTEND";
    }
    string OGetLinkExtend::toString()
    {
        return "GETLINKEXTEND " + getFirstArgument()->toString() + "," + getSecondArgument()->toString();
    }
    
    /////////////////////////
    /// GLobalSymbols.cpp ///
    /////////////////////////
    
    { "SetTile",                ScriptParser::TYPE_VOID,          FUNCTION,     0,                    1,      {  ScriptParser::TYPE_LINK,          ScriptParser::TYPE_FLOAT,         ScriptParser::TYPE_FLOAT,    ScriptParser::TYPE_FLOAT,   ScriptParser::TYPE_FLOAT,                           -1,                           -1,                           -1,                           -1,                           -1,                           -1,                           -1,                           -1,                           -1,                           -1,                           -1,                           -1,                           -1,                           -1,                           -1                           } },
    { "SetLinkExtend",                ScriptParser::TYPE_VOID,          FUNCTION,     0,                    1,      {  ScriptParser::TYPE_LINK,          ScriptParser::TYPE_FLOAT,         ScriptParser::TYPE_FLOAT,    ScriptParser::TYPE_FLOAT,   -1,                           -1,                           -1,                           -1,                           -1,                           -1,                           -1,                           -1,                           -1,                           -1,                           -1,                           -1,                           -1,                           -1,                           -1,                           -1                           } },
    { "GetLinkExtend",                ScriptParser::TYPE_FLOAT,          FUNCTION,     0,                    1,      {  ScriptParser::TYPE_LINK,          ScriptParser::TYPE_FLOAT,         ScriptParser::TYPE_FLOAT,    -1,   -1,                           -1,                           -1,                           -1,                           -1,                           -1,                           -1,                           -1,                           -1,                           -1,                           -1,                           -1,                           -1,                           -1,                           -1,                           -1                           } },
       
    //void SetLinkTile(link, int,int,int,int)
        {
            int id = memberids["SetTile"];
            int label = lt.functionToLabel(id);
            vector<Opcode *> code;
            Opcode *first = new OSetLinkTile();
            first->setLabel(label);
            code.push_back(first);
            code.push_back(new OPopRegister(new VarArgument(EXP2))); //!ZoriaRPG this can't be right
            code.push_back(new OPopRegister(new VarArgument(EXP2))); //only one expr accumulator?
            code.push_back(new OPopRegister(new VarArgument(EXP2)));
            code.push_back(new OPopRegister(new VarArgument(EXP2))); 
            //pop pointer, and ignore it
            code.push_back(new OPopRegister(new VarArgument(NUL)));
            
            code.push_back(new OPopRegister(new VarArgument(EXP2)));
            code.push_back(new OGotoRegister(new VarArgument(EXP2)));
            rval[label]=code;
        }
        
        //void OSetLinkExtend
        {
            int id = memberids["SetLinkExtend"];
            int label = lt.functionToLabel(id);
            vector<Opcode *> code;
            Opcode *first = new OSetLinkExtend();
            first->setLabel(label);
            code.push_back(first);
            code.push_back(new OPopRegister(new VarArgument(EXP2))); //!ZoriaRPG this can't be right
            code.push_back(new OPopRegister(new VarArgument(EXP2))); //only one expr accumulator, and number two?
            code.push_back(new OPopRegister(new VarArgument(EXP2))); //is this extraneous?
            //pop pointer, and ignore it
            code.push_back(new OPopRegister(new VarArgument(NUL)));
            
            code.push_back(new OPopRegister(new VarArgument(EXP2)));
            code.push_back(new OGotoRegister(new VarArgument(EXP2)));
            rval[label]=code;
        }
        //void GetLinkExtend(link, int, int)
        {
            int id = memberids["GetLinkExtend"];
            int label = lt.functionToLabel(id);
            vector<Opcode *> code;
            //pop off the params
            Opcode *first = new OPopRegister(new VarArgument(EXP1));
            first->setLabel(label);
            code.push_back(first);
            code.push_back(new OPopRegister(new VarArgument(EXP2)));
            //pop pointer, and ignore it
            code.push_back(new OPopRegister(new VarArgument(NUL)));
            code.push_back(new OGetLinkExtend(new VarArgument(EXP2), new VarArgument(EXP1)));
            code.push_back(new OPopRegister(new VarArgument(EXP2)));
            code.push_back(new OGotoRegister(new VarArgument(EXP2)));
            rval[label] = code;
        }
    That function label error was because I was trying to have both setTile and SetTile, with different definitions in GlobalSymbols.cpp. I thought it was case-sensitive, removing the lowercase 'set' from setTile for the setter, and that it would not do this for SetTile uppercase Set) for the function. That part is fixed. All now, that remains, is to determine why the values aren't being read, or set.

    I do need to know what the '1' in this set does:

    Code:
    { "GETSIDEWARPSCR",      1,   0,   0,   0},
    ...versus the '2' in this set:

    Code:
    { "GETDMAPTITLE",        2,   0,   0,   0},
    Does the '2' signify that the stack is handling two values (one boolean return, one array pointer), or does it signify the number of inputs to the ZScript function? I think it's the former??

    I wonder if @jman kept any notes, and if anyone can reach him? It would be interesting to read through any materials that he wrote as refs for himself.

  5. #15
    The Time-Loop Continues ZC Developer
    Gleeok's Avatar
    Join Date
    Apr 2007
    Posts
    4,815
    Mentioned
    259 Post(s)
    Tagged
    10 Thread(s)
    vBActivity - Stats
    Points
    12,933
    Level
    33
    vBActivity - Bars
    Lv. Percent
    23.44%
    Bad place for typos, right?

    Now that it's narrowed down a bit; try setting a breakpoint in ffcscript.cpp ; set_register, get_register; inspect the values, and follow through to see what is happening instead of hitting *LINKTILE et. al.
    This post contains the official Gleeok seal of approval. Look for these and other posts in an area near you.

  6. #16
    The Time-Loop Continues ZC Developer
    Gleeok's Avatar
    Join Date
    Apr 2007
    Posts
    4,815
    Mentioned
    259 Post(s)
    Tagged
    10 Thread(s)
    vBActivity - Stats
    Points
    12,933
    Level
    33
    vBActivity - Bars
    Lv. Percent
    23.44%
    Quote Originally Posted by ZoriaRPG View Post
    I do need to know what the '1' in this set does:

    Code:
    { "GETSIDEWARPSCR",      1,   0,   0,   0},
    ...versus the '2' in this set:

    Code:
    { "GETDMAPTITLE",        2,   0,   0,   0},
    Does the '2' signify that the stack is handling two values (one boolean return, one array pointer), or does it signify the number of inputs to the ZScript function? I think it's the former??

    I wonder if @jman kept any notes, and if anyone can reach him? It would be interesting to read through any materials that he wrote as refs for himself.
    You ninja'd me.

    The 2 is number of args, next is arg 1, arg2 (IIRC). If those are register values then they should be 1, otherwise 0. (I hope I got that right) [edit] No, I didn't. It's 0, otherwise 1...
    Last edited by Gleeok; 12-16-2016 at 06:11 AM.
    This post contains the official Gleeok seal of approval. Look for these and other posts in an area near you.

  7. #17
    The Timelord
    QDB Manager
    ZC Developer

    Join Date
    Oct 2006
    Location
    Prydon Academy
    Posts
    1,396
    Mentioned
    112 Post(s)
    Tagged
    1 Thread(s)
    vBActivity - Stats
    Points
    4,760
    Level
    21
    vBActivity - Bars
    Lv. Percent
    68.7%
    Quote Originally Posted by Gleeok View Post
    Bad place for typos, right?

    Now that it's narrowed down a bit; try setting a breakpoint in ffcscript.cpp ; set_register, get_register; inspect the values, and follow through to see what is happening instead of hitting *LINKTILE et. al.
    What's the best way to inspect the stack without a live stack debuger? Throw out ZConsole messages with the values of the expression accumulators?

    I'm sort of in the 'how does Gleeok do this' mode...which is why I was hoping for a procedural list from you, on what the flidd you would do; or some kind of step-by-step details on how to build this kind of function in the frrst place.

  8. #18
    The Time-Loop Continues ZC Developer
    Gleeok's Avatar
    Join Date
    Apr 2007
    Posts
    4,815
    Mentioned
    259 Post(s)
    Tagged
    10 Thread(s)
    vBActivity - Stats
    Points
    12,933
    Level
    33
    vBActivity - Bars
    Lv. Percent
    23.44%
    No wait, 0 means register! #$%^ dammit. :mad:

    Also, DarkDragon is much more knowledgeable about the ZScript compiler than I am.


    Quote Originally Posted by ZoriaRPG View Post
    What's the best way to inspect the stack without a live stack debuger? Throw out ZConsole messages with the values of the expression accumulators?

    I'm sort of in the 'how does Gleeok do this' mode...which is why I was hoping for a procedural list from you, on what the flidd you would do; or some kind of step-by-step details on how to build this kind of function in the frrst place.
    Honestly, I usually half forget some of this stuff, so I just go in order of: 1) Declare constants and opcodes; update script tables; implement compiler procedure as needed; update bytecode in ffscript.cpp; and finally, implement function that gets called.


    [edit]
    Also, what compiler are you using that doesn't have a debugger?
    This post contains the official Gleeok seal of approval. Look for these and other posts in an area near you.

  9. #19
    Administrator DarkDragon's Avatar
    Join Date
    Oct 2001
    Posts
    6,228
    Mentioned
    70 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    11,025
    Level
    31
    vBActivity - Bars
    Lv. Percent
    8.16%
    ZoriaRPG, to answer your question in your commented lines: the ZScript calling convention is more or less equivalent to C's. The caller first pushes the return address onto the stack, then all of the function's explicit argument, and finally, if the function is a member function, the "this" pointer is implicitly pushed as the last argument.

    The return value of the function is by convention stored in EXP1.

    The callee, then, before it can return, must pop all of the arguments (including the "this" pointer) off of the stack. That's what the lines are doing that you've commented about. The ZASM instruction uses the top 4 entries of the stack, but leaves them untouched, so ZScript pops them off, then pops off the return address and jumps to it. You could use NUL instead of EXP2 for these pops if you wanted.

    The reason EXP2 is used as scratch space instead of EXP1 is simply to avoid accidentally tampering with the return value of the function.

  10. #20
    The Timelord
    QDB Manager
    ZC Developer

    Join Date
    Oct 2006
    Location
    Prydon Academy
    Posts
    1,396
    Mentioned
    112 Post(s)
    Tagged
    1 Thread(s)
    vBActivity - Stats
    Points
    4,760
    Level
    21
    vBActivity - Bars
    Lv. Percent
    68.7%
    Quote Originally Posted by DarkDragon View Post
    ZoriaRPG, to answer your question in your commented lines: the ZScript calling convention is more or less equivalent to C's. The caller first pushes the return address onto the stack, then all of the function's explicit argument, and finally, if the function is a member function, the "this" pointer is implicitly pushed as the last argument.

    The return value of the function is by convention stored in EXP1.

    The callee, then, before it can return, must pop all of the arguments (including the "this" pointer) off of the stack. That's what the lines are doing that you've commented about. The ZASM instruction uses the top 4 entries of the stack, but leaves them untouched, so ZScript pops them off, then pops off the return address and jumps to it. You could use NUL instead of EXP2 for these pops if you wanted.

    The reason EXP2 is used as scratch space instead of EXP1 is simply to avoid accidentally tampering with the return value of the function.

    Got it. Good stuff there; and I put it into the docs. :)

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Armageddon Games is a game development group founded in 1997. We are extremely passionate about our work and our inspirations are mostly drawn from games of the 8-bit and 16-bit era.
Social