home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gold Fish 2
/
goldfish_vol2_cd1.bin
/
files
/
comm
/
misc
/
elcheapofax
/
faxcmd
/
libfax
/
rcs
/
swap.c,v
< prev
next >
Wrap
Text File
|
1993-12-21
|
3KB
|
185 lines
head 1.3;
access;
symbols
OCT93:1.3;
locks;
comment @ * @;
1.3
date 93.10.25.02.20.15; author Rhialto; state Exp;
branches;
next 1.2;
1.2
date 93.06.11.16.15.25; author Rhialto; state Exp;
branches;
next 1.1;
1.1
date 93.06.11.15.19.27; author Rhialto; state Exp;
branches;
next ;
desc
@Bit reversal
@
1.3
log
@Make +FBOR flexible.
@
text
@/* $Id: swap.c,v 1.2 1993/06/11 16:15:25 Rhialto Exp $
* $Log: swap.c,v $
* Revision 1.2 1993/06/11 16:15:25 Rhialto
* First real RCS checkin
*
*/
/*
This file is part of the NetFax system.
(c) Copyright 1989 by David M. Siegel and Sundar Narasimhan.
All rights reserved.
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.
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, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <stdio.h>
#include "c2proto.h"
#include "swap.h"
#include "log.h"
int bor_value = BOR_VALUE; /* to be used for +FBOR= */
static unsigned char swaptable[256];
/*
* Adjust the byte swap table according to the phase C bit order.
* If "direct", i.e. lsb first, we swap the bits.
* if "reversed", i.e. msb first, they are in the right order already.
* Called after/by setting +FBOR=.
*/
void
set_swapmode(int code)
{
if ((code & BOR_C) == BOR_C_DIR) {
int i, j;
if (swaptable[0x01] == 0x80) {
log(L_DEBUG, "set_swapmode: swap, already initialised");
return;
}
for (i = 0; i < 256; i++) {
j = ( ((i & 0x01) << 7) |
((i & 0x02) << 5) |
((i & 0x04) << 3) |
((i & 0x08) << 1) |
((i & 0x10) >> 1) |
((i & 0x20) >> 3) |
((i & 0x40) >> 5) |
((i & 0x80) >> 7) );
swaptable[i] = j;
}
} else {
int i;
if (swaptable[0x01] == 0x01) {
log(L_DEBUG, "set_swapmode: don't swap, already initialised");
return;
}
for (i = 0; i < 256; i++)
swaptable[i] = i;
}
}
/*
Reverses the low order 8 bits of a byte, if needed.
*/
unsigned char swap_bits(c)
unsigned char c;
{
if (!swaptable[1]) {
set_swapmode(0); /* default for +FBOR */
}
return(swaptable[c]);
}
@
1.2
log
@First real RCS checkin
@
text
@d1 5
a5 2
/* $Id$
* $Log$
d31 1
d33 1
a33 1
static void init_swaptable(unsigned char *swaptable);
d35 2
d38 8
a45 4
Builds table to swap the low order 4 bitswith the high order.
*/
static void init_swaptable(swaptable)
unsigned char *swaptable;
d47 26
a72 1
int i, j;
d74 2
a75 10
for (i = 0; i < 256; i++) {
j = ( ((i & 0x01) << 7) |
((i & 0x02) << 5) |
((i & 0x04) << 3) |
((i & 0x08) << 1) |
((i & 0x10) >> 1) |
((i & 0x20) >> 3) |
((i & 0x40) >> 5) |
((i & 0x80) >> 7) );
swaptable[i] = j;
d80 1
a80 1
Reverses the low order 8 bits of a byte
a84 2
static unsigned char swaptable[256];
static int swaptable_init = FALSE;
d86 2
a87 3
if (!swaptable_init) {
init_swaptable(swaptable);
swaptable_init = TRUE;
@
1.1
log
@Initial revision
@
text
@d1 3
@