123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- #!/usr/bin/perl
- use integer;
- use strict;
- # 1 bit/byte patterns
- print "#if BITS_PER_PATTERN_BYTE == 1\n\n";
- print "static const uint8_t fm_pat[2] = {\n";
- print "\t0xff, 0x0f";
- print "\n};\n\n";
- # 2 bits/byte patterns
- print "#elif BITS_PER_PATTERN_BYTE == 2\n\n";
- print "static const uint8_t fm_pat[4] = {\n";
- for (my $i = 0; $i < 4; $i++) {
- my $pat = 0;
- my $inc = 0; # Previous bit
- for (my $j = 0; $j < 2; $j++) {
- my $bp = ($i & (1 << $j)) ? 0x3 : 0xf;
- $bp ^= $inc * 15;
- $inc = $bp >> 3;
- $pat |= $bp << ($j*4);
- }
- printf "%s0x%02x", ($i ? ', ' : "\t"), $pat;
- }
- print "\n};\n\n";
- print "\n#elif BITS_PER_PATTERN_BYTE == 4\n\n";
- # 4 bits/byte patterns
- print "static const uint8_t fm_pat[16] = {\n";
- for (my $i = 0; $i < 16; $i++) {
- my $pat = 0;
- my $inc = 0; # Previous bit
- for (my $j = 0; $j < 4; $j++) {
- my $bp = ($i & (1 << $j)) ? 0x1 : 0x3;
- $bp ^= $inc * 3;
- $inc = $bp >> 1;
- $pat |= $bp << ($j*2);
- }
- printf "%s0x%02x", ($i ? ', ' : "\t"), $pat;
- }
- print "\n};\n\n";
- print "#else\n\n";
- print "#error \"Invalid BITS_PER_PATTERN_BYTE\"\n";
- print "\n#endif\n";
|