FictionTools/z88dk/src/sccz80/codegen.c
/* Fetch the specified object type indirect through the */
/*      primary register into the primary register */
Fetch the specified object type indirect through the
primary register into the primary register
Fetch the specified object type indirect through the primary register into the primary register
void indirect(LVALUE* lval)
{
    char sign;
    char flags;
    Kind typeobj;
    typeobj = lval->indirect_kind;
    flags = lval->flags;
    sign = lval->ltype->isunsigned;
    if (flags & FARACC) { 
        switch (typeobj) {
        case KIND_CHAR:
            callrts("lp_gchar");
            if (!sign)
                callrts("l_sxt");
            break;
        case KIND_CPTR:
            callrts("lp_gptr");
            break;
        case KIND_LONG:
            callrts("lp_glong");
            break;
        case KIND_DOUBLE:
            callrts("lp_gdoub");
            break;
        case KIND_STRUCT:
            warningfmt("incompatible-pointer-types","Cannot retrieve a struct via __far");
        default:
            callrts("lp_gint");
        }
        return;
    }
    if ( lval->ltype->bit_size ) {
        int bit_offset = lval->ltype->bit_offset;
        if ( bit_offset >= 8 ) {
            bit_offset -= 8;
            ol("inc\thl");
        }
        if ( lval->ltype->bit_size + bit_offset <= 8 ) {
            int i;
            ol("ld\ta,(hl)");
            if ( bit_offset >= 4) {
                for ( i = 0; i < (8 - bit_offset); i++ ) {
                    ol("rlca");
                }
            } else {
                for ( i = 0; i < bit_offset; i++ ) {
                    ol("rrca");
                }
            }
            if ( lval->ltype->bit_size % 8 ) { 
                outfmt("\tand\t%d\n",(1 << lval->ltype->bit_size) - 1);
            }
            if ( lval->ltype->isunsigned == 0 ) {
                if ( lval->ltype->bit_size % 8 ) {
                    outfmt("\tbit\t%d,a\n",lval->ltype->bit_size - 1);
                    if ( IS_8080() ) {
                        ol("jp\tz,ASMPC+5");
                    } else {
                        ol("jr\tz,ASMPC+4");
                    }
                    outfmt("\tor\t%d\n",0xff - ((1 << lval->ltype->bit_size) - 1));
                }
                ol("ld\tl,a");
                ol("rlca");
                ol("sbc\ta,a");
                ol("ld\th,a");
            } else {
                ol("ld\tl,a");
                ol("ld\th,0");
            }
        } else {
            ol("ld\te,(hl)");
            ol("inc\thl");
            ol("ld\ta,(hl)");
            if ( lval->ltype->bit_size % 8 ) { 
                outfmt("\tand\t%d\n",(1 << (lval->ltype->bit_size - 8)) - 1);
                if ( lval->ltype->isunsigned == 0 ) {
                    outfmt("\tbit\t%d,a\n",(lval->ltype->bit_size - 8) - 1);
                    if ( IS_8080() ) {
                        ol("jp\tz,ASMPC+5");
                    } else {
                        ol("jr\tz,ASMPC+4");
                    }
                    outfmt("\tor\t%d\n",0xff - ((1 << (lval->ltype->bit_size - 8)) - 1));
                }
            }
            ol("ld\th,a");
            ol("ld\tl,e");
        }
        return;
    }
    switch (typeobj) {
    case KIND_CHAR:
        if (!sign) {
#ifdef PREAPR00
            ol("ld\ta,(hl)");
            callrts("l_sxt");
#else
            callrts("l_gchar");
#endif
        } else {
            ol("ld\tl,(hl)");
            ol("ld\th,0");
        }
        break;
    case KIND_CPTR:
        callrts("l_getptr");
        break;
    case KIND_LONG:
        callrts("l_glong");
        break;
    case KIND_DOUBLE:
        callrts("dload");
        break;
    case KIND_STRUCT:
        break;
    default:
        ot("call\tl_gint\t;");
#ifdef USEFRAME
        if (c_framepointer_is_ix != -1 && CheckOffset(lval->offset)) {
            OutIndex(lval->offset);
        }
#endif
        nl();
    }
}
void indirect ( LVALUE * lval ) { char sign ; char flags ; Kind typeobj ; typeobj = lval -> indirect_kind ; flags = lval -> flags ; sign = lval -> ltype -> isunsigned ; if ( flags & FARACC ) { switch ( typeobj ) { case KIND_CHAR : callrts ( " " ) ; if ( ! sign ) callrts ( " " ) ; break ; case KIND_CPTR : callrts ( " " ) ; break ; case KIND_LONG : callrts ( " " ) ; break ; case KIND_DOUBLE : callrts ( " " ) ; break ; case KIND_STRUCT : warningfmt ( " " , " " ) ; default : callrts ( " " ) ; } return ; } if ( lval -> ltype -> bit_size ) { int bit_offset = lval -> ltype -> bit_offset ; if ( bit_offset >= 8 ) { bit_offset -= 8 ; ol ( " \t " ) ; } if ( lval -> ltype -> bit_size + bit_offset <= 8 ) { int i ; ol ( " \t " ) ; if ( bit_offset >= 4 ) { for ( i = 0 ; i < ( 8 - bit_offset ) ; i ++ ) { ol ( " " ) ; } } else { for ( i = 0 ; i < bit_offset ; i ++ ) { ol ( " " ) ; } } if ( lval -> ltype -> bit_size % 8 ) { outfmt ( " \t \t \n " , ( 1 << lval -> ltype -> bit_size ) - 1 ) ; } if ( lval -> ltype -> isunsigned == 0 ) { if ( lval -> ltype -> bit_size % 8 ) { outfmt ( " \t \t \n " , lval -> ltype -> bit_size - 1 ) ; if ( IS_8080 ( ) ) { ol ( " \t " ) ; } else { ol ( " \t " ) ; } outfmt ( " \t \t \n " , 0xff - ( ( 1 << lval -> ltype -> bit_size ) - 1 ) ) ; } ol ( " \t " ) ; ol ( " " ) ; ol ( " \t " ) ; ol ( " \t " ) ; } else { ol ( " \t " ) ; ol ( " \t " ) ; } } else { ol ( " \t " ) ; ol ( " \t " ) ; ol ( " \t " ) ; if ( lval -> ltype -> bit_size % 8 ) { outfmt ( " \t \t \n " , ( 1 << ( lval -> ltype -> bit_size - 8 ) ) - 1 ) ; if ( lval -> ltype -> isunsigned == 0 ) { outfmt ( " \t \t \n " , ( lval -> ltype -> bit_size - 8 ) - 1 ) ; if ( IS_8080 ( ) ) { ol ( " \t " ) ; } else { ol ( " \t " ) ; } outfmt ( " \t \t \n " , 0xff - ( ( 1 << ( lval -> ltype -> bit_size - 8 ) ) - 1 ) ) ; } } ol ( " \t " ) ; ol ( " \t " ) ; } return ; } switch ( typeobj ) { case KIND_CHAR : if ( ! sign ) { #ifdef PREAPR00 ol ( " \t " ) ; callrts ( " " ) ; #else callrts ( " " ) ; #endif } else { ol ( " \t " ) ; ol ( " \t " ) ; } break ; case KIND_CPTR : callrts ( " " ) ; break ; case KIND_LONG : callrts ( " " ) ; break ; case KIND_DOUBLE : callrts ( " " ) ; break ; case KIND_STRUCT : break ; default : ot ( " \t \t " ) ; #ifdef USEFRAME if ( c_framepointer_is_ix != -1 && CheckOffset ( lval -> offset ) ) { OutIndex ( lval -> offset ) ; } #endif nl ( ) ; } }
Fetch the specified object type indirect through the
primary register into the primary register
Fetch the specified object type indirect through the primary register into the primary register
/* Fetch from far pointer */ /* Access via far method */ /*                        else ol("ld\th,0"); */ // TODO: Shift left as necessary // We need to do some bit extension here // It's an int > 8 bits