[f40a309] | 1 | /*
|
---|
| 2 | =============================================================================
|
---|
| 3 | mangle.c -- mangle a bit stream
|
---|
| 4 | Version 2 -- 1987-08-28 -- D.N. Lynx Crowe
|
---|
| 5 | (c) Copyright 1987 - D.N. Lynx Crowe
|
---|
| 6 | =============================================================================
|
---|
| 7 | */
|
---|
| 8 |
|
---|
| 9 | /*
|
---|
| 10 | =============================================================================
|
---|
| 11 | mangle(bitmap, nb, ib) -- reorder the 'nb' least significant bits
|
---|
| 12 | in 'ib' according to 'bitmap'. Assumes that 'bitmap' is at least 'nb'
|
---|
| 13 | words long, and that nb <= 32. The 'bitmap' translation table contains
|
---|
| 14 | an output word for each bit in the input word, with each 'bitmap' entry
|
---|
| 15 | corresponding to the bit number matching its index. For example,
|
---|
| 16 | 'bitmap[0]' contains the word which will be 'OR'ed into the output if
|
---|
| 17 | the least significant bit of the input word is set, while 'bitmap[31]'
|
---|
| 18 | corresponds to the most significant bit of the input word.
|
---|
| 19 | =============================================================================
|
---|
| 20 | */
|
---|
| 21 |
|
---|
[b28a12e] | 22 | #include "ram.h"
|
---|
[6262b5c] | 23 |
|
---|
[7258c6a] | 24 | int32_t mangle(int32_t *bitmap, int16_t nb, int32_t ib)
|
---|
[f40a309] | 25 | {
|
---|
[7258c6a] | 26 | register int32_t bm; /* scan mask */
|
---|
| 27 | register int32_t rv; /* result value */
|
---|
| 28 | register int16_t bn; /* bit number (bitmap index) */
|
---|
[f40a309] | 29 |
|
---|
| 30 | bm = 0x00000001L; /* setup scan mask */
|
---|
| 31 | rv = 0x00000000L; /* clear the output word */
|
---|
| 32 |
|
---|
| 33 | for (bn = 0; bn < nb; bn++) { /* scan across nb bits */
|
---|
| 34 |
|
---|
| 35 | if (ib & bm) /* if the input bit is 1 */
|
---|
| 36 | rv |= bitmap[bn]; /* 'OR' the bitmap into rv */
|
---|
| 37 |
|
---|
| 38 | bm <<= 1; /* shift the scan mask left */
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | return(rv); /* return rv as the result */
|
---|
| 42 | }
|
---|