Leaked source code of windows server 2003
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.

194 lines
3.7 KiB

  1. /* File: C:\WACKER\tdll\mdmx_res.c (Created: 17-Jan-1994)
  2. * created from HAWIN source file
  3. * mdmx_res.c -- Routines to handle xmodem sending for HA5G
  4. *
  5. * Copyright 1989,1994 by Hilgraeve Inc. -- Monroe, MI
  6. * All rights reserved
  7. *
  8. * $Revision: 1 $
  9. * $Date: 10/05/98 1:16p $
  10. */
  11. #include <windows.h>
  12. #pragma hdrstop
  13. #include <setjmp.h>
  14. #define BYTE unsigned char
  15. #include <tdll\stdtyp.h>
  16. #include <tdll\session.h>
  17. #include <tdll\xfer_msc.h>
  18. #include <tdll\file_io.h>
  19. #include "xfr_srvc.h"
  20. #include "xfr_todo.h"
  21. #include "xfr_dsp.h"
  22. #include "xfer_tsc.h"
  23. #include "foo.h"
  24. #include "xfer.h"
  25. #include "xfer.hh"
  26. #include "mdmx.h"
  27. #include "mdmx.hh"
  28. /*lint -e502*/ /* lint seems to want the ~ operator applied
  29. * only to unsigned, wer'e using uchar
  30. */
  31. // #pragma optimize("a", on)
  32. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  33. * load_pckt
  34. *
  35. * DESCRIPTION:
  36. * Prepares an XMODEM packet for transmission by filling it with data and
  37. * initializing other fields such as
  38. *
  39. * ARGUMENTS:
  40. *
  41. * RETURNS:
  42. *
  43. */
  44. int load_pckt(ST_MDMX *pX,
  45. struct s_mdmx_pckt *p,
  46. unsigned pcktnum,
  47. int kpckt,
  48. int chktype)
  49. {
  50. BYTE checksum;
  51. unsigned int crc;
  52. BYTE *cp;
  53. int cnt;
  54. int cc;
  55. p->pcktnum = (BYTE)(pcktnum % 0x100);
  56. p->npcktnum = (BYTE)(~p->pcktnum);
  57. cp = p->bdata;
  58. checksum = 0;
  59. p->result = 0; /* will set TRUE if end of data is reached */
  60. for (cnt = (kpckt ? LARGE_PACKET : SMALL_PACKET); cnt > 0; --cnt)
  61. {
  62. if ((cc = (*pX->p_getc)(pX)) == EOF)
  63. {
  64. p->result = 1; /* so compression display won't check */
  65. #if FALSE
  66. /* TODO: figure out how to do this */
  67. if (nb_error(pX->fh))
  68. return FALSE;
  69. #endif
  70. break;
  71. }
  72. checksum += (*cp++ = (BYTE)cc);
  73. }
  74. /* see if we're at end of file */
  75. if (cnt == (kpckt ? LARGE_PACKET : SMALL_PACKET))
  76. {
  77. p->start_char = EOT;
  78. p->pcktsize = 1;
  79. return TRUE;
  80. }
  81. /* if using large packets but this one is small enough, switch */
  82. if (kpckt && ((LARGE_PACKET-cnt) <= SMALL_PACKET))
  83. {
  84. kpckt = FALSE; /* set small packet flag */
  85. /* set count to 128-(1024-cnt) */
  86. cnt = (SMALL_PACKET - (LARGE_PACKET - cnt));
  87. }
  88. while (cnt-- > 0)
  89. {
  90. *cp++ = CPMEOF;
  91. checksum += CPMEOF;
  92. }
  93. p->start_char = (BYTE)(kpckt ? STX : SOH);
  94. p->pcktsize = (kpckt ? LARGE_PACKET : SMALL_PACKET) + 4;
  95. p->byte_count = pX->mdmx_byte_cnt;/* amt. transferred after this packet */
  96. /* is sent */
  97. if (chktype == CHECKSUM)
  98. {
  99. *cp = checksum;
  100. }
  101. else
  102. {
  103. *cp = 0;
  104. *(cp + 1) = 0;
  105. crc = calc_crc(pX, (unsigned)0, p->bdata,
  106. (kpckt ? LARGE_PACKET : SMALL_PACKET) + 2 );
  107. *cp++ = (BYTE)(crc / 0x100);
  108. *cp = (BYTE)(crc % 0x100);
  109. ++p->pcktsize;
  110. }
  111. return(TRUE);
  112. }
  113. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  114. * xm_getc
  115. *
  116. * DESCRIPTION:
  117. *
  118. * ARGUMENTS:
  119. *
  120. * RETURNS:
  121. *
  122. */
  123. int xm_getc(ST_MDMX *pX)
  124. {
  125. ++pX->mdmx_byte_cnt;
  126. return(fio_getc(pX->fh));
  127. // return(nb_getc(pX->fh));
  128. }
  129. // Receive routines
  130. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  131. * FUNCTION:
  132. *
  133. * DESCRIPTION:
  134. *
  135. *
  136. * ARGUMENTS:
  137. *
  138. *
  139. * RETURNS:
  140. *
  141. */
  142. int xs_unload(ST_MDMX *pX, BYTE *cp, int size)
  143. {
  144. int cnt;
  145. for (cnt = size + 1; --cnt > 0; )
  146. {
  147. if ((*pX->p_putc)(pX, (int)*cp++) == (-1) /* ERROR */)
  148. return ERROR;
  149. }
  150. return 0;
  151. }
  152. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  153. * xm_putc
  154. *
  155. * DESCRIPTION:
  156. *
  157. * ARGUMENTS:
  158. *
  159. * RETURNS:
  160. *
  161. */
  162. int NEAR xm_putc(ST_MDMX *pX, int c)
  163. {
  164. pX->mdmx_byte_cnt += 1;
  165. return ((int)(fio_putc(c, pX->fh)));
  166. // return ((int)(nb_putc(c, pX->fh)));
  167. }