-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new input filter : nibble_swap (#62)
* input filters: add -Nibble-Swap filter Simply exchanges upper and lower nibbles of each bytes. This should only be a few opcodes per byte on most CPUs; probably faster than a look-up table (e.g. like the bit-reverse filter).
- Loading branch information
Showing
9 changed files
with
203 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// | ||
// Copyright (c) 2023 fenugrec | ||
// | ||
// srecord filter: exchanges upper and lower nibble of each byte, | ||
// e.g. "0xA6" => "0x6A" | ||
// | ||
// This program is free software; you can redistribute it and/or modify | ||
// it under the terms of the GNU Lesser General Public License as published by | ||
// the Free Software Foundation; either version 3 of the License, or (at | ||
// your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
// General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
// | ||
|
||
#include <srecord/input/filter/nibble_swap.h> | ||
#include <srecord/record.h> | ||
|
||
|
||
srecord::input_filter_nibble_swap::input_filter_nibble_swap( | ||
const srecord::input::pointer &arg | ||
) : | ||
srecord::input_filter(arg) | ||
{ | ||
} | ||
|
||
|
||
srecord::input::pointer | ||
srecord::input_filter_nibble_swap::create(const input::pointer &a_deeper) | ||
|
||
{ | ||
return pointer(new srecord::input_filter_nibble_swap(a_deeper)); | ||
} | ||
|
||
|
||
bool | ||
srecord::input_filter_nibble_swap::read(srecord::record &record) | ||
{ | ||
if (!srecord::input_filter::read(record)) | ||
return false; | ||
if (record.get_type() == srecord::record::type_data) | ||
{ | ||
for (size_t j = 0; j < record.get_length(); ++j) { | ||
uint8_t tmp = record.get_data(j); | ||
record.set_data(j, ((tmp & 0x0F) << 4) | ((tmp & 0xF0) >> 4)); | ||
} | ||
} | ||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// | ||
// Copyright (c) 2023 fenugrec | ||
// | ||
// srecord filter: exchanges upper and lower nibble of each byte, | ||
// e.g. "0xA6" => "0x6A" | ||
// | ||
// This program is free software; you can redistribute it and/or modify | ||
// it under the terms of the GNU Lesser General Public License as published by | ||
// the Free Software Foundation; either version 3 of the License, or (at | ||
// your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
// General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
// | ||
|
||
#ifndef SRECORD_INPUT_FILTER_NIBBLE_SWAP_H | ||
#define SRECORD_INPUT_FILTER_NIBBLE_SWAP_H | ||
|
||
#include <srecord/input/filter.h> | ||
|
||
namespace srecord { | ||
|
||
/** | ||
* The srecord::input_filter_nibble_swap class is used to represent the | ||
* input state of a filter which swaps upper/lower nibbles of each byte. | ||
*/ | ||
class input_filter_nibble_swap: | ||
public input_filter | ||
{ | ||
public: | ||
/** | ||
* The destructor. | ||
*/ | ||
~input_filter_nibble_swap() override = default; | ||
|
||
private: | ||
/** | ||
* The constructor. | ||
* | ||
* @param deeper | ||
* The deeper input to be used as a data source. | ||
*/ | ||
input_filter_nibble_swap(const input::pointer &deeper); | ||
|
||
public: | ||
/** | ||
* The create class method is used to create new dynamically | ||
* allocated instances of this class. | ||
* | ||
* @param deeper | ||
* The incoming data source to be filtered | ||
*/ | ||
static pointer create(const input::pointer &deeper); | ||
|
||
protected: | ||
// See base class for documentation. | ||
bool read(record &record) override; | ||
|
||
public: | ||
/** | ||
* The default constructor. | ||
*/ | ||
input_filter_nibble_swap() = delete; | ||
|
||
/** | ||
* The copy constructor. | ||
*/ | ||
input_filter_nibble_swap(const input_filter_nibble_swap &) = delete; | ||
|
||
/** | ||
* The assignment operator. | ||
*/ | ||
input_filter_nibble_swap &operator= \ | ||
(const input_filter_nibble_swap &) = delete; | ||
}; | ||
|
||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/bin/sh | ||
# | ||
# srecord - manipulate eprom load files | ||
# Copyright (C) 2023 fenugrec | ||
# | ||
# This program is free software; you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation; either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see | ||
# <http://www.gnu.org/licenses/>. | ||
# | ||
|
||
TEST_SUBJECT="nibble swap filter" | ||
. test_prelude.sh | ||
|
||
cat > test.in << 'fubar' | ||
S00600004844521B | ||
S1070000F08008552B | ||
S5030001FB | ||
fubar | ||
if test $? -ne 0; then no_result; fi | ||
|
||
cat > test.ok << 'fubar' | ||
S00600004844521B | ||
S10700000F0880550C | ||
S5030001FB | ||
fubar | ||
if test $? -ne 0; then no_result; fi | ||
|
||
srec_cat test.in -ns -o test.out | ||
if test $? -ne 0; then fail; fi | ||
|
||
diff test.ok test.out | ||
if test $? -ne 0; then fail; fi | ||
|
||
# | ||
# The things tested here, worked. | ||
# No other guarantees are made. | ||
# | ||
pass |