1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-06-26 10:29:31 +00:00

Factors out bit reversing from the HFE class.

This commit is contained in:
Thomas Harte 2017-10-03 19:12:45 -04:00
parent f41da83d97
commit 35705c5345
4 changed files with 63 additions and 15 deletions

View File

@ -21,6 +21,7 @@
4B14978F1EE4B4D200CE2596 /* CSZX8081.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4B14978E1EE4B4D200CE2596 /* CSZX8081.mm */; };
4B1497921EE4B5A800CE2596 /* ZX8081.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B1497901EE4B5A800CE2596 /* ZX8081.cpp */; };
4B1497981EE4B97F00CE2596 /* ZX8081Options.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4B1497961EE4B97F00CE2596 /* ZX8081Options.xib */; };
4B1558C01F844ECD006E9A97 /* BitReverse.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B1558BE1F844ECD006E9A97 /* BitReverse.cpp */; };
4B1D08061E0F7A1100763741 /* TimeTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4B1D08051E0F7A1100763741 /* TimeTests.mm */; };
4B1E85751D170228001EF87D /* Typer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B1E85731D170228001EF87D /* Typer.cpp */; };
4B1E85811D176468001EF87D /* 6532Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B1E85801D176468001EF87D /* 6532Tests.swift */; };
@ -504,6 +505,8 @@
4B1497901EE4B5A800CE2596 /* ZX8081.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ZX8081.cpp; path = ZX8081/ZX8081.cpp; sourceTree = "<group>"; };
4B1497911EE4B5A800CE2596 /* ZX8081.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = ZX8081.hpp; path = ZX8081/ZX8081.hpp; sourceTree = "<group>"; };
4B1497971EE4B97F00CE2596 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = "Clock Signal/Base.lproj/ZX8081Options.xib"; sourceTree = SOURCE_ROOT; };
4B1558BE1F844ECD006E9A97 /* BitReverse.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = BitReverse.cpp; path = Data/BitReverse.cpp; sourceTree = "<group>"; };
4B1558BF1F844ECD006E9A97 /* BitReverse.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; name = BitReverse.hpp; path = Data/BitReverse.hpp; sourceTree = "<group>"; };
4B1D08051E0F7A1100763741 /* TimeTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = TimeTests.mm; sourceTree = "<group>"; };
4B1E85731D170228001EF87D /* Typer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Typer.cpp; sourceTree = "<group>"; };
4B1E85741D170228001EF87D /* Typer.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = Typer.hpp; sourceTree = "<group>"; };
@ -1741,8 +1744,10 @@
4B8805F81DCFF6CD003085B1 /* Data */ = {
isa = PBXGroup;
children = (
4B1558BE1F844ECD006E9A97 /* BitReverse.cpp */,
4B8805F51DCFF6C9003085B1 /* Commodore.cpp */,
4BA0F68C1EEA0E8400E9489E /* ZX8081.cpp */,
4B1558BF1F844ECD006E9A97 /* BitReverse.hpp */,
4B8805F61DCFF6C9003085B1 /* Commodore.hpp */,
4BA0F68D1EEA0E8400E9489E /* ZX8081.hpp */,
);
@ -2917,6 +2922,7 @@
4B4518A31F75FD1C00926311 /* HFE.cpp in Sources */,
4B8378E21F336920005CA9E4 /* CharacterMapper.cpp in Sources */,
4B4518A11F75FD1C00926311 /* D64.cpp in Sources */,
4B1558C01F844ECD006E9A97 /* BitReverse.cpp in Sources */,
4BCF1FA41DADC3DD0039D2E7 /* Oric.cpp in Sources */,
4BEA525E1DF33323007E74F2 /* Tape.cpp in Sources */,
4B8334951F5E25B60097E338 /* C1540.cpp in Sources */,

View File

@ -0,0 +1,25 @@
//
// BitReverse.cpp
// Clock Signal
//
// Created by Thomas Harte on 03/10/2017.
// Copyright © 2017 Thomas Harte. All rights reserved.
//
#include "BitReverse.hpp"
void Storage::Data::BitReverse::reverse(std::vector<uint8_t> &vector) {
for(auto &byte : vector) {
byte =
static_cast<uint8_t>(
((byte & 0x01) << 7) |
((byte & 0x02) << 5) |
((byte & 0x04) << 3) |
((byte & 0x08) << 1) |
((byte & 0x10) >> 1) |
((byte & 0x20) >> 3) |
((byte & 0x40) >> 5) |
((byte & 0x80) >> 7)
);
}
}

View File

@ -0,0 +1,30 @@
//
// BitReverse.hpp
// Clock Signal
//
// Created by Thomas Harte on 03/10/2017.
// Copyright © 2017 Thomas Harte. All rights reserved.
//
#ifndef BitReverse_hpp
#define BitReverse_hpp
#include <cstdint>
#include <vector>
namespace Storage {
namespace Data {
namespace BitReverse {
/*!
Reverses the order of the bits in every byte of the vector
bit 7 exchanges with bit 0, bit 6 exchanges with bit 1, 5 with 2,
and 4 with 3.
*/
void reverse(std::vector<uint8_t> &vector);
}
}
}
#endif /* BitReverse_hpp */

View File

@ -9,6 +9,7 @@
#include "HFE.hpp"
#include "../../Track/PCMTrack.hpp"
#include "../../../Data/BitReverse.hpp"
using namespace Storage::Disk;
@ -61,21 +62,7 @@ std::shared_ptr<Track> HFE::get_track_at_position(unsigned int head, unsigned in
// Flip bytes; HFE's preference is that the least-significant bit
// is serialised first, but PCMTrack posts the most-significant first.
for(size_t i = 0; i < segment.data.size(); i++) {
uint8_t original = segment.data[i];
uint8_t flipped_byte =
(uint8_t)(
((original & 0x01) << 7) |
((original & 0x02) << 5) |
((original & 0x04) << 3) |
((original & 0x08) << 1) |
((original & 0x10) >> 1) |
((original & 0x20) >> 3) |
((original & 0x40) >> 5) |
((original & 0x80) >> 7)
);
segment.data[i] = flipped_byte;
}
Storage::Data::BitReverse::reverse(segment.data);
std::shared_ptr<Track> track(new PCMTrack(segment));
return track;