Menu

#3985 FATAL Compiler Internal Error: ld_cost op1: AOP_IY, op2: 13

open
nobody
None
other
5
3 days ago
3 days ago
Under4Mhz
No

In the following code I get the error:

$ sdcc -mz80 --fverbose-asm  ./var_not_init.c  -o var_not_init.ihx && ucsim_z80 -I if=outputs[0xff] var_not_init.ihx
./var_not_init.c:80: warning 84: 'auto' variable 'shipx' may be used before initialization
ld_cost op1: AOP_IY, op2: 13
./var_not_init.c:84: error 9: FATAL Compiler Internal Error in file 'gen.c' line number '1117' : code generator internal error 
Contact Author with source code
ld_cost op1: AOP_IY, op2: 13
...

$ gcc ./var_not_init.c && ./a.out
Start
y 64
End

I wasn't able to reduce the code without removing the error.

/// GPL 2.0 or later
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdlib.h>

#define u8 uint8_t
#define u16 uint16_t

typedef struct {

    u16 x;
    u16 y;

} maths_point;

typedef struct {

    maths_point position;               // current position

} ShipData;

ShipData shipData;                      // ship data

enum {

    colourShipMiddle,
};

typedef enum {

    spriteShipMiddle,

} SpriteType;

const u8 playerColors[] = { 1 , 2, 3 };

ShipData *PlayerGet(void) { return &shipData; }

#define SHIP_X 1024
#define SHIP_Y 512
#define SPRITE_WIDTH 16
#define SHIP_ENLARGE_WIDTH 24

#define TO_SCREEN(x) (x / 8)

typedef enum {

    bonusEnlarge,

} BonusType;

u8 StateBonusModeGet(void) { return 1; }

void SpriteSet( uint8_t id, uint8_t tile, uint8_t x, uint8_t y, uint8_t colour ) {

    (void)id;
    (void)tile;
    (void)x;
    (void)colour;

    printf( "y %d\n", y );
}

///< Ship sprites
void ShipDraw(void) {

    ShipData *ship = PlayerGet();

    // Ships
    u16 width = TO_SCREEN( SPRITE_WIDTH );
    u16 shipx = TO_SCREEN( ship->position.x );
    u16 shipy = TO_SCREEN( ship->position.y );
    u8 index = 0;

    if ( StateBonusModeGet() == bonusEnlarge )
        width += TO_SCREEN( SHIP_ENLARGE_WIDTH );

    u16 shipxl = shipx;
    u16 shipxm = shipxl + width;
    u16 shipxr = shipxm + width;

    // Middle first to overlay the edges
    SpriteSet( index, spriteShipMiddle, shipxm, shipy, playerColors[colourShipMiddle] );
}

void main(void) {

    printf( "Start\n" );
    ShipDraw();
    printf( "End\n" );

}

#ifdef __SDCC
__sfr __at 0xff sif;
int putchar( int c ) {

    sif = 'p';
    sif = c;

    return c;
}
#endif

// sdcc -mz80 --fverbose-asm ./var_not_init.c  -o var_not_init.ihx && ucsim_z80 -I if=outputs[0xff] var_not_init.ihx
// gcc ./var_not_init.c && ./a.out
$ sdcc -v
SDCC : z80/sm83/ez80/z80n/mos6502/mos65c02/f8/f8l TD- 4.5.24 #16510 (Linux)

Discussion


Log in to post a comment.

MongoDB Logo MongoDB