netbitutils.pp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. {$MACRO ON}
  2. (******************************************************************************
  3. *
  4. * Copyright (c) 1997-2000 Palm, Inc. or its subsidiaries.
  5. * All rights reserved.
  6. *
  7. * File: NetBitUtils.h
  8. *
  9. * Release: Palm OS SDK 4.0 (63220)
  10. *
  11. * Description:
  12. * Header file for bit manipulation routines used primarily
  13. * by wireless network protocols.
  14. *
  15. * These routines live in the NetLib but are broken out here into
  16. * a separate header so that they can be more easily used by source
  17. * files that don't need access to the other NetLib functions.
  18. *
  19. * History:
  20. * 6/11/97 Created by Ron Marianetti
  21. * Name Date Description
  22. * ---- ---- -----------
  23. * vmk 8/25/98 Defined bitVarIntMaxBits and bitVarIntMaxBytes
  24. *
  25. *****************************************************************************)
  26. unit netbitutils;
  27. interface
  28. uses palmos, netmgr;
  29. // # of bits in a byte
  30. const
  31. bitsInByte = 8;
  32. // Maximum size of variable-size ints in # of bits and bytes. This is based on
  33. // the largest variable size int, which is encoded as follows: 1111 Bit[32]
  34. bitVarIntMaxBits = 36;
  35. // #define bitVarIntMaxBytes ((bitVarIntMaxBits + bitsInByte - 1) / bitsInByte)
  36. //=====================================================
  37. // BitXXX Macros
  38. //
  39. // The following macros are handy because they don't require that
  40. // the source code pass in the NetLib library refnum to every
  41. // call.
  42. //
  43. // When building server code or other emulation code where th
  44. // library trap dispatcher is not used, the libRefNUm is unused
  45. // and can be 0.
  46. //
  47. // When building for the viewer, the libRefNum must be the refNum
  48. // of the NetLib. For applications, this libRefNum must be put
  49. // into an application global named 'AppNetRefnum'.
  50. //
  51. //====================================================
  52. (*
  53. #if USE_TRAPS == 0
  54. #define netPrvRefnum 0
  55. #else
  56. #define netPrvRefnum AppNetRefnum
  57. #endif
  58. *)
  59. (*
  60. #define BitMove( dstP, dstBitOffsetP, srcP, srcBitOffsetP, numBits) \
  61. NetLibBitMove(netPrvRefnum, dstP, dstBitOffsetP, srcP, srcBitOffsetP, numBits)
  62. #define BitPutFixed( dstP, dstBitOffsetP, value, numBits) \
  63. NetLibBitPutFixed(netPrvRefnum, dstP, dstBitOffsetP, value, numBits)
  64. #define BitGetFixed(srcP, srcBitOffsetP, numBits) \
  65. NetLibBitGetFixed(netPrvRefnum, srcP, srcBitOffsetP, numBits)
  66. #define BitPutUIntV(dstP, dstBitOffsetP, value) \
  67. NetLibBitPutUIntV(netPrvRefnum, dstP, dstBitOffsetP, value)
  68. #define BitGetUIntV(srcP, srcBitOffsetP) \
  69. NetLibBitGetUIntV(netPrvRefnum, srcP, srcBitOffsetP)
  70. #define BitPutIntV(dstP, dstBitOffsetP, value) \
  71. NetLibBitPutIntV(netPrvRefnum, dstP, dstBitOffsetP, value)
  72. #define BitGetIntV(srcP, srcBitOffsetP) \
  73. NetLibBitGetIntV(netPrvRefnum, srcP, srcBitOffsetP)
  74. *)
  75. //=====================================================
  76. // Macros that convert native integers to and from
  77. // big-endian (network) order which is the order used to store
  78. // variable length integers by the BitMove utilities.
  79. //====================================================
  80. (*
  81. #if CPU_TYPE == CPU_x86
  82. #define _NetSwap16(x) \
  83. ((((x) >> 8) & 0xFF) | \
  84. (((x) & 0xFF) << 8))
  85. #define _NetSwap32(x) \
  86. ((((x) >> 24) & 0x00FF) | \
  87. (((x) >> 8) & 0xFF00) | \
  88. (((x) & 0xFF00) << 8) | \
  89. (((x) & 0x00FF) << 24))
  90. #define NetHToNS(x) _NetSwap16(x)
  91. #define NetHToNL(x) _NetSwap32(x)
  92. #define NetNToHS(x) _NetSwap16(x)
  93. #define NetNToHL(x) _NetSwap32(x)
  94. #elif CPU_TYPE == CPU_68K
  95. #define NetHToNS(x) (x)
  96. #define NetHToNL(x) (x)
  97. #define NetNToHS(x) (x)
  98. #define NetNToHL(x) (x)
  99. #else
  100. // We'll define these macros for any other architectures needed as we come
  101. // across them.
  102. #endif
  103. *)
  104. //=====================================================
  105. // Functions
  106. //====================================================
  107. //--------------------------------------------------
  108. // Bit Moving functions. For "slim" bit packing protocols
  109. // used over wireless.
  110. //--------------------------------------------------
  111. procedure NetLibBitMove(libRefNum: UInt16; var dstP: UInt8; var dstBitOffsetP: UInt32;
  112. var srcP: UInt8; var srcBitOffsetP: UInt32; numBits: UInt32); syscall netLibTrapBitMove;
  113. procedure NetLibBitPutFixed(libRefNum: UInt16; var dstP: UInt8; var dstBitOffsetP: UInt32;
  114. value: UInt32; numBits: UInt16); syscall netLibTrapBitPutFixed;
  115. function NetLibBitGetFixed(libRefNum: UInt16; var dstP: UInt8; var dstBitOffsetP: UInt32;
  116. numBits: UInt16): UInt32; syscall netLibTrapBitGetFixed;
  117. procedure NetLibBitPutUIntV(libRefNum: UInt16; var dstP: UInt8; var dstBitOffsetP: UInt32;
  118. value: UInt32); syscall netLibTrapBitPutUIntV;
  119. function NetLibBitGetUIntV(libRefNum: UInt16; var dstP: UInt8; var dstBitOffsetP: UInt32): UInt32; syscall netLibTrapBitGetUIntV;
  120. procedure NetLibBitPutIntV(libRefNum: UInt16; var dstP: UInt8; var dstBitOffsetP: UInt32;
  121. value: Int32); syscall netLibTrapBitPutUIntV;
  122. function NetLibBitGetIntV(libRefNum: UInt16; var dstP: UInt8; var dstBitOffsetP: UInt32): Int32; syscall netLibTrapBitGetUIntV;
  123. implementation
  124. end.