X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=pico%2Fcart.c;h=26fb59bb81fafa9cfa334b150df4c7148d7f327c;hb=83ff19ec52ff47992b5d6ceda3900b914eda2123;hp=cbd4bb6323227788c82225fd376519fd7dcdf5be;hpb=5e49c3a88d1c3ece302a40d8c3a32285d3199ab6;p=picodrive.git diff --git a/pico/cart.c b/pico/cart.c index cbd4bb6..26fb59b 100644 --- a/pico/cart.c +++ b/pico/cart.c @@ -378,23 +378,21 @@ int pm_close(pm_file *fp) return ret; } - -static void Byteswap(unsigned char *data,int len) +// byteswap, data needs to be int aligned, src can match dst +void Byteswap(void *dst, const void *src, int len) { - int i=0; - - if (len<2) return; // Too short + const unsigned int *ps = src; + unsigned int *pd = dst; + int i, m; - do - { - unsigned short *pd=(unsigned short *)(data+i); - int value=*pd; // Get 2 bytes + if (len < 2) + return; - value=(value<<8)|(value>>8); // Byteswap it - *pd=(unsigned short)value; // Put 2b ytes - i+=2; + m = 0x00ff00ff; + for (i = 0; i < len / 4; i++) { + unsigned int t = ps[i]; + pd[i] = ((t & m) << 8) | ((t & ~m) >> 8); } - while (i+2<=len); } // Interleve a 16k block and byteswap @@ -524,7 +522,7 @@ int PicoCartLoad(pm_file *f,unsigned char **prom,unsigned int *psize,int is_sms) elprintf(EL_STATUS, "SMD format detected."); DecodeSmd(rom,size); size-=0x200; // Decode and byteswap SMD } - else Byteswap(rom,size); // Just byteswap + else Byteswap(rom, rom, size); // Just byteswap } else { @@ -621,9 +619,9 @@ static unsigned int rom_crc32(void) elprintf(EL_STATUS, "caclulating CRC32.."); // have to unbyteswap for calculation.. - Byteswap(Pico.rom, Pico.romsize); + Byteswap(Pico.rom, Pico.rom, Pico.romsize); crc = crc32(0, Pico.rom, Pico.romsize); - Byteswap(Pico.rom, Pico.romsize); + Byteswap(Pico.rom, Pico.rom, Pico.romsize); return crc; }