Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

113 lines
3.2 KiB

  1. /*
  2. * $Log: V:/Flite/archives/TrueFFS5/Src/FLBASE.C_V $
  3. *
  4. * Rev 1.3 Sep 15 2001 23:45:32 oris
  5. * Changed BIG_ENDIAN to FL_BIG_ENDIAN
  6. *
  7. * Rev 1.2 Apr 09 2001 15:07:34 oris
  8. * End with an empty line.
  9. *
  10. * Rev 1.1 Apr 01 2001 07:45:30 oris
  11. * Updated copywrite notice
  12. *
  13. * Rev 1.0 Feb 04 2001 11:05:28 oris
  14. * Initial revision.
  15. *
  16. */
  17. /***********************************************************************************/
  18. /* M-Systems Confidential */
  19. /* Copyright (C) M-Systems Flash Disk Pioneers Ltd. 1995-2001 */
  20. /* All Rights Reserved */
  21. /***********************************************************************************/
  22. /* NOTICE OF M-SYSTEMS OEM */
  23. /* SOFTWARE LICENSE AGREEMENT */
  24. /* */
  25. /* THE USE OF THIS SOFTWARE IS GOVERNED BY A SEPARATE LICENSE */
  26. /* AGREEMENT BETWEEN THE OEM AND M-SYSTEMS. REFER TO THAT AGREEMENT */
  27. /* FOR THE SPECIFIC TERMS AND CONDITIONS OF USE, */
  28. /* OR CONTACT M-SYSTEMS FOR LICENSE ASSISTANCE: */
  29. /* E-MAIL = [email protected] */
  30. /***********************************************************************************/
  31. #include "flbase.h"
  32. #ifdef FL_BIG_ENDIAN
  33. /*----------------------------------------------------------------------*/
  34. /* Little / Big - Endian Conversion Routines */
  35. /*----------------------------------------------------------------------*/
  36. void toLEushort(unsigned char FAR0 *le, unsigned short n)
  37. {
  38. le[1] = (unsigned char)(n >> 8);
  39. le[0] = (unsigned char)n;
  40. }
  41. unsigned short fromLEushort(unsigned char const FAR0 *le)
  42. {
  43. return ((unsigned short)le[1] << 8) + le[0];
  44. }
  45. void toLEulong(unsigned char FAR0 *le, unsigned long n)
  46. {
  47. le[3] = (unsigned char)(n >> 24);
  48. le[2] = (unsigned char)(n >> 16);
  49. le[1] = (unsigned char)(n >> 8);
  50. le[0] = (unsigned char)n;
  51. }
  52. unsigned long fromLEulong(unsigned char const FAR0 *le)
  53. {
  54. return ((unsigned long)le[3] << 24) +
  55. ((unsigned long)le[2] << 16) +
  56. ((unsigned long)le[1] << 8) +
  57. le[0];
  58. }
  59. extern void copyShort(unsigned char FAR0 *to, unsigned char const FAR0 *from)
  60. {
  61. to[0] = from[0];
  62. to[1] = from[1];
  63. }
  64. extern void copyLong(unsigned char FAR0 *to, unsigned char const FAR0 *from)
  65. {
  66. to[0] = from[0];
  67. to[1] = from[1];
  68. to[2] = from[2];
  69. to[3] = from[3];
  70. }
  71. #else
  72. void toUNAL(unsigned char FAR0 *unal, unsigned short n)
  73. {
  74. unal[1] = (unsigned char)(n >> 8);
  75. unal[0] = (unsigned char)n;
  76. }
  77. unsigned short fromUNAL(unsigned char const FAR0 *unal)
  78. {
  79. return ((unsigned short)unal[1] << 8) + unal[0];
  80. }
  81. void toUNALLONG(Unaligned FAR0 *unal, unsigned long n)
  82. {
  83. toUNAL(unal[0],(unsigned short)n);
  84. toUNAL(unal[1],(unsigned short)(n >> 16));
  85. }
  86. unsigned long fromUNALLONG(Unaligned const FAR0 *unal)
  87. {
  88. return fromUNAL(unal[0]) +
  89. ((unsigned long)fromUNAL(unal[1]) << 16);
  90. }
  91. #endif /* FL_BIG_ENDIAN */