this if statement doesnt work

Help
slenk
2013-06-14
2013-06-14
  • slenk
    slenk
    2013-06-14

    if you compile this in linux it will work
    but if you compile for z80 it doesnt

    #include <string.h>
    #include <stdlib.h>
    #ifdef __linux__
    #include <stdio.h>
    #endif
    
    const squareclosed=1;
    const squareopen=2;
    
    const pathfound=1;
    const pathnotfound=2;
    const TargetSquareIsStartSquare=3;
    int pathtowalkx[20];
    int pathtowalky[20];
    int numberofopenlistitems;
    
    char pathresult;
    int iter1;
    int iter2;
    
    void drawdot();
    void drawdot2();
    char findpath(char startx,char starty,char targetx,char targety);
    void clearpath();
    
    struct maptile {
        char hcost;
        char parentX;
        char parentY;
        char state;
        char occupied;
    };
    
    struct maptile * maptiles[32][24];
    void main(void)
    {
    
    for (iter1=0;iter1<32;iter1++)
    {
        for(iter2=0;iter2<24;iter2++)
        {
    
        maptiles[iter1][iter2]=malloc(sizeof(struct maptile));
        }
    }
    //
    maptiles[1][10]->occupied=1;
    pathresult=findpath(1,1,1,10);
    
    #ifdef __linux__
    printf("end");
    #else
    while(1)
    {}
    #endif
    
    }
    
    char findpath(char startx,char starty,char targetx,char targety)
    {
    struct maptile * targetsquare;
    clearpath();    
    
    if ((startx==targetx)&&(starty==targety))
    {
    return pathnotfound;
    }
    
    targetsquare=maptiles[targetx][targety];
    
    if (targetsquare->occupied==1)
    {
    drawdot2();
    return TargetSquareIsStartSquare;
    }
    
    //HCost(startx,starty)=GetHCost(startx,starty,targetx,targety)
    //AddToOpenList(startx,starty,startx,starty)
    //LowestFCostSquareX=startx
    //LowestFCostSquareY=starty
    
    return pathnotfound;
    }
    
    void clearpath()
    {
    #ifdef __linux__
    printf("clear path");
    #else
    drawdot();
    
    #endif
             }
    
    void drawdot()
    {
    #ifdef __linux__
    printf("drawdot");
    #else
    __asm
    LD A,#0xFF
    LD HL,#0x4000
    LD (HL),A
    __endasm;
    #endif
    
    }
    
    void drawdot2()
    {
    #ifdef __linux__
    printf("drawdot2");
    #else
    __asm
    LD A,#0xF
    LD HL,#0x4000
    LD (HL),A
    __endasm;
    #endif
    
    }
    

    drawdot2 is never called on the zx spectrum
    I know drawdot2 works because I tested it ,
    drawdot1 works in the spectrum

    the line that doesnt work seems to be

    if (targetsquare->occupied==1)

    to compile it for spectrum I did this
    bin/sdcc -mz80 --code-loc 26000 --opt-code-size --no-std-crt0 spec.c
    bin/hex2bin spec.ihx
    bin/bin2tap -b -a 26000 -c 25999 -r 26000 -o spec.tap spec.bin
    fuse-gtk spec.tap

     
    Last edit: slenk 2013-06-14