FictionTools/z88dk/src/sccz80/codegen.c
/*
 * Perform subroutine call to value on top of stack
 * Put arg count in A in case subroutine needs it
 * 
 * Returns an "nargs" adjustment to handle fastcall
 */
Perform subroutine call to value on top of stack
Put arg count in A in case subroutine needs it

Returns an "nargs" adjustment to handle fastcall
Perform subroutine call to value on top of stack Put arg count in A in case subroutine needs it Returns an " nargs " adjustment to handle fastcall
int callstk(Type *type, int n, int isfarptr, int last_argument_size)
{
    if ( isfarptr ) {
        if ( n > 0 ) {
            outfmt("\tld\thl,%d\n",n);
            ol("add\thl,de");
            ol("ld\te,(hl)");
            ol("inc\thl");
            ol("ld\td,(hl)");
            ol("inc\thl");
            ol("ld\tl,(hl)");
            ol("ex\tde,hl");
        }
        loadargc(n);
        callrts("l_farcall");
    } else if ( type->flags & FASTCALL && last_argument_size < 6 ) {
        int ret = -2;
        int label = getlabel();		  
        if ( last_argument_size == 2 ) {
            ol("pop\taf");
            outstr("\tld\tbc,"); printlabel(label);  nl();	
            ol("push\tbc");
            ol("push\taf");
            Zsp += 2;
            ret = -4;
         } else {
            ol("pop\taf");
            outstr("\tld\tbc,"); printlabel(label);  nl();	
            ol("push\tbc"); 		
            ol("push\taf");		
            Zsp += 2;
         } 
         ol("ret");		
         postlabel(label);
         return ret;
    } else {
        if (last_argument_size == 2) {
            if ( IS_GBZ80() ) {
                ol("ld\td,h");
                ol("ld\te,l");
                ol("pop\thl");
                ol("push\tde");
            } else {
                swapstk();
            }
        } else if ( last_argument_size == 4) {
            swap(); 
            swapstk(); 
            zpushde(); 
        }
        if ( type->funcattrs.hasva ) 
            loadargc(n);
        callrts("l_jphl");
    }
    return 0;
}
int callstk ( Type * type , int n , int isfarptr , int last_argument_size ) { if ( isfarptr ) { if ( n > 0 ) { outfmt ( " \t \t \n " , n ) ; ol ( " \t " ) ; ol ( " \t " ) ; ol ( " \t " ) ; ol ( " \t " ) ; ol ( " \t " ) ; ol ( " \t " ) ; ol ( " \t " ) ; } loadargc ( n ) ; callrts ( " " ) ; } else if ( type -> flags & FASTCALL && last_argument_size < 6 ) { int ret = -2 ; int label = getlabel ( ) ; if ( last_argument_size == 2 ) { ol ( " \t " ) ; outstr ( " \t \t " ) ; printlabel ( label ) ; nl ( ) ; ol ( " \t " ) ; ol ( " \t " ) ; Zsp += 2 ; ret = -4 ; } else { ol ( " \t " ) ; outstr ( " \t \t " ) ; printlabel ( label ) ; nl ( ) ; ol ( " \t " ) ; ol ( " \t " ) ; Zsp += 2 ; } ol ( " " ) ; postlabel ( label ) ; return ret ; } else { if ( last_argument_size == 2 ) { if ( IS_GBZ80 ( ) ) { ol ( " \t " ) ; ol ( " \t " ) ; ol ( " \t " ) ; ol ( " \t " ) ; } else { swapstk ( ) ; } } else if ( last_argument_size == 4 ) { swap ( ) ; swapstk ( ) ; zpushde ( ) ; } if ( type -> funcattrs . hasva ) loadargc ( n ) ; callrts ( " " ) ; } return 0 ; }
Perform subroutine call to value on top of stack
 Put arg count in A in case subroutine needs it
Perform subroutine call to value on top of stack Put arg count in A in case subroutine needs it
// The function address is on the stack at +n // TOS = address, dehl = parameter // More than one argument, TOS = last parameter, hl = function // For long sp+0 = LSW, sp +2 = MSW, hl = function // bc = return address // bc = return address /* Return address */ /* At this point, TOS = function, hl = argument */ /* At this point, TOS = function, dehl = argument */ /* MSW -> hl */ /* MSW -> stack, addr -> hl */ /* LSW -> stack, addr = hl */