Hi,

i think i found two bugs in the z80 port:

buggy.c:
__sfr __banked __at 0xf500 SPI_PORT_IN;

struct {
        unsigned char SDHC : 1;
        unsigned char FAT32 : 1;
} SDFlags;

int main () {
        SDFlags.SDHC = (SPI_PORT_IN & 0x40) ? 1 : 0;
        return(SDFlags.SDHC);
}

compiles to:
                             53 ;buggy.c:9: SDFlags.SDHC = (SPI_PORT_IN
& 0x40) ? 1 : 0;
   0000 3E F5         [ 7]   54         ld      a,#>(_SPI_PORT_IN)
   0002 DB 00         [11]   55         in      a,(#<(_SPI_PORT_IN))

SPI_PORT_IN should be:
                                        ld      bc,#SPI_PORT_IN
                                        in      a,(c)

   0004 E6 40         [ 7]   56         and     a, #0x40
   0006 21r00r00      [10]   57         ld      hl,#_SDFlags
   0009 E6 01         [ 7]   58         and     a,#0x01

What is this? It makes "a" broken.

   000B 4F            [ 4]   59         ld      c,a
   000C 7E            [ 7]   60         ld      a,(hl)
   000D E6 FE         [ 7]   61         and     a,#0xFE
   000F B1            [ 4]   62         or      a,c
   0010 77            [ 7]   63         ld      (hl),a

I think, it should be:
                                        ld      hl,#_SDFlags
                                        ld      c,a
                                        ld      a,(hl)
                                        bit     6,c
                                        jr      z,zero
                                        or      a,#0x01
                                        jr      save
zero:                                   and     a,#0xFE
save:                                   ld      (hl),a

(or so...)

SDCC :
mcs51/z80/z180/r2k/r3ka/gbz80/tlcs90/ds390/TININative/ds400/hc08/s08/st
m8 3.5.0 #9253 (Mar 19 2016) (Linux)
published under GNU General Public License (GPL)

# sdcc -mz80 buggy.c

I also testet with the latest snapshot, same behaviour.

Regards

Klaus



_______________________________________________
Sdcc-user mailing list
Sdcc-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sdcc-user

Reply via email to