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 >
Text File  |  1993-12-21  |  3KB  |  185 lines

  1. head    1.3;
  2. access;
  3. symbols
  4.     OCT93:1.3;
  5. locks;
  6. comment    @ * @;
  7.  
  8.  
  9. 1.3
  10. date    93.10.25.02.20.15;    author Rhialto;    state Exp;
  11. branches;
  12. next    1.2;
  13.  
  14. 1.2
  15. date    93.06.11.16.15.25;    author Rhialto;    state Exp;
  16. branches;
  17. next    1.1;
  18.  
  19. 1.1
  20. date    93.06.11.15.19.27;    author Rhialto;    state Exp;
  21. branches;
  22. next    ;
  23.  
  24.  
  25. desc
  26. @Bit reversal
  27. @
  28.  
  29.  
  30. 1.3
  31. log
  32. @Make +FBOR flexible.
  33. @
  34. text
  35. @/* $Id: swap.c,v 1.2 1993/06/11 16:15:25 Rhialto Exp $
  36.  * $Log: swap.c,v $
  37.  * Revision 1.2  1993/06/11  16:15:25  Rhialto
  38.  * First real RCS checkin
  39.  *
  40.  */
  41. /*
  42.   This file is part of the NetFax system.
  43.  
  44.   (c) Copyright 1989 by David M. Siegel and Sundar Narasimhan.
  45.       All rights reserved.
  46.  
  47.     This program is free software; you can redistribute it and/or modify
  48.     it under the terms of the GNU General Public License as published by
  49.     the Free Software Foundation.
  50.  
  51.     This program is distributed in the hope that it will be useful,
  52.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  53.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  54.     GNU General Public License for more details.
  55.  
  56.     You should have received a copy of the GNU General Public License
  57.     along with this program; if not, write to the Free Software
  58.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  59. */
  60.  
  61. #include <stdio.h>
  62.  
  63. #include "c2proto.h"
  64. #include "swap.h"
  65. #include "log.h"
  66.  
  67. int        bor_value = BOR_VALUE;    /* to be used for +FBOR= */
  68.  
  69. static unsigned char swaptable[256];
  70.  
  71. /*
  72.  * Adjust the byte swap table according to the phase C bit order.
  73.  * If "direct", i.e. lsb first, we swap the bits.
  74.  * if "reversed", i.e. msb first, they are in the right order already.
  75.  * Called after/by setting +FBOR=.
  76.  */
  77.  
  78. void
  79. set_swapmode(int code)
  80. {
  81.     if ((code & BOR_C) == BOR_C_DIR) {
  82.     int i, j;
  83.  
  84.     if (swaptable[0x01] == 0x80) {
  85.         log(L_DEBUG, "set_swapmode: swap, already initialised");
  86.         return;
  87.     }
  88.  
  89.     for (i = 0; i < 256; i++) {
  90.         j = ( ((i & 0x01) << 7) |
  91.          ((i & 0x02) << 5) |
  92.          ((i & 0x04) << 3) |
  93.          ((i & 0x08) << 1) |
  94.          ((i & 0x10) >> 1) |
  95.          ((i & 0x20) >> 3) |
  96.          ((i & 0x40) >> 5) |
  97.          ((i & 0x80) >> 7) );
  98.         swaptable[i] = j;
  99.     }
  100.     } else {
  101.     int i;
  102.  
  103.     if (swaptable[0x01] == 0x01) {
  104.         log(L_DEBUG, "set_swapmode: don't swap, already initialised");
  105.         return;
  106.     }
  107.  
  108.     for (i = 0; i < 256; i++)
  109.         swaptable[i] = i;
  110.     }
  111. }
  112.  
  113. /*
  114.   Reverses the low order 8 bits of a byte, if needed.
  115. */
  116. unsigned char swap_bits(c)
  117.      unsigned char c;
  118. {
  119.  
  120.     if (!swaptable[1]) {
  121.     set_swapmode(0);    /* default for +FBOR */
  122.     }
  123.  
  124.     return(swaptable[c]);
  125. }
  126. @
  127.  
  128.  
  129. 1.2
  130. log
  131. @First real RCS checkin
  132. @
  133. text
  134. @d1 5
  135. a5 2
  136. /* $Id$
  137.  * $Log$
  138. d31 1
  139. d33 1
  140. a33 1
  141. static void init_swaptable(unsigned char *swaptable);
  142. d35 2
  143. d38 8
  144. a45 4
  145.   Builds table to swap the low order 4 bitswith the high order.
  146. */
  147. static void init_swaptable(swaptable)
  148.      unsigned char *swaptable;
  149. d47 26
  150. a72 1
  151.     int i, j;
  152. d74 2
  153. a75 10
  154.     for (i = 0; i < 256; i++) {
  155.     j = ( ((i & 0x01) << 7) |
  156.          ((i & 0x02) << 5) |
  157.          ((i & 0x04) << 3) |
  158.          ((i & 0x08) << 1) |
  159.          ((i & 0x10) >> 1) |
  160.          ((i & 0x20) >> 3) |
  161.          ((i & 0x40) >> 5) |
  162.          ((i & 0x80) >> 7) );
  163.     swaptable[i] = j;
  164. d80 1
  165. a80 1
  166.   Reverses the low order 8 bits of a byte
  167. a84 2
  168.     static unsigned char swaptable[256];
  169.     static int swaptable_init = FALSE;
  170. d86 2
  171. a87 3
  172.     if (!swaptable_init) {
  173.     init_swaptable(swaptable);
  174.     swaptable_init = TRUE;
  175. @
  176.  
  177.  
  178. 1.1
  179. log
  180. @Initial revision
  181. @
  182. text
  183. @d1 3
  184. @
  185.