From aeaea073c6356674edc302e952392c8b0241daf5 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sat, 9 Oct 2021 13:45:19 -0700 Subject: [PATCH] Switch both: (i) which bits are odd/even; and (ii) nibble ordering. --- Storage/Disk/DiskImage/Formats/AmigaADF.cpp | 38 +++++++++++---------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/Storage/Disk/DiskImage/Formats/AmigaADF.cpp b/Storage/Disk/DiskImage/Formats/AmigaADF.cpp index 66cc7dd7c..b689c418b 100644 --- a/Storage/Disk/DiskImage/Formats/AmigaADF.cpp +++ b/Storage/Disk/DiskImage/Formats/AmigaADF.cpp @@ -20,17 +20,18 @@ template void write_block(IteratorT begin, IteratorT end, s // Parse 1: write odd bits. auto cursor = begin; while(cursor != end) { - uint8_t source = - ((*cursor & 0x01) >> 0) | - ((*cursor & 0x04) >> 1) | - ((*cursor & 0x10) >> 2) | - ((*cursor & 0x40) >> 3); + auto source = uint8_t( + ((*cursor & 0x02) << 3) | + ((*cursor & 0x08) << 2) | + ((*cursor & 0x20) << 1) | + ((*cursor & 0x80) << 0) + ); ++cursor; source |= - ((*cursor & 0x01) << 4) | - ((*cursor & 0x04) << 3) | - ((*cursor & 0x10) << 2) | - ((*cursor & 0x40) << 1); + ((*cursor & 0x02) >> 1) | + ((*cursor & 0x08) >> 2) | + ((*cursor & 0x20) >> 3) | + ((*cursor & 0x80) >> 4); ++cursor; encoder->add_byte(source); @@ -39,17 +40,18 @@ template void write_block(IteratorT begin, IteratorT end, s // Parse 2: write even bits. cursor = begin; while(cursor != end) { - uint8_t source = - ((*cursor & 0x02) >> 1) | - ((*cursor & 0x08) >> 2) | - ((*cursor & 0x20) >> 3) | - ((*cursor & 0x80) >> 4); + auto source = uint8_t( + ((*cursor & 0x01) << 4) | + ((*cursor & 0x04) << 3) | + ((*cursor & 0x10) << 2) | + ((*cursor & 0x40) << 1) + ); ++cursor; source |= - ((*cursor & 0x02) << 3) | - ((*cursor & 0x08) << 2) | - ((*cursor & 0x20) << 1) | - ((*cursor & 0x80) << 0); + ((*cursor & 0x01) >> 0) | + ((*cursor & 0x04) >> 1) | + ((*cursor & 0x10) >> 2) | + ((*cursor & 0x40) >> 3); ++cursor; encoder->add_byte(source);