home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / CPROG / EMSLB221.ZIP / EMSTEST3.C < prev    next >
C/C++ Source or Header  |  1991-10-11  |  53KB  |  1,277 lines

  1. /***************************************************************************
  2. *   emstest3.c                                                             *
  3. *   MODULE:  EMSLIB                                                        *
  4. *   OS:      DOS                                                           *
  5. *   VERSION: 1.1                                                           *
  6. *   DATE:    10/11/91                                                      *
  7. *                                                                          *
  8. *   Copyright (c) 1991 James W. Birdsall. All Rights Reserved.             *
  9. *                                                                          *
  10. *   Requires emslib.h and emstest.h to compile.                            *
  11. *   Compiles under Borland C++ 2.0 or MSC 6.0A.                            *
  12. *                                                                          *
  13. *   Regression test and example for EMSLIB. See EMSTEST.C for more info.   *
  14. *                                                                          *
  15. ***************************************************************************/
  16.  
  17. /*
  18. ** system includes <>
  19. */
  20.  
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. #include <dos.h>
  24. #include <string.h>
  25.  
  26. /* include appropriate file according to compiler */
  27. #ifdef __TURBOC__
  28.  
  29. #include <alloc.h>
  30.  
  31. #else
  32.  
  33. #include <malloc.h>
  34.  
  35. #endif
  36.  
  37.  
  38. /*
  39. ** custom includes ""
  40. */
  41.  
  42. #include "emslib.h"
  43. #include "emstest.h"
  44.  
  45.  
  46. /*
  47. ** local #defines
  48. */
  49.  
  50. #define UCF         unsigned char far
  51. #define UCH         unsigned char huge
  52.  
  53. /*
  54. ** Define LMALLOC() and LFREE() to the appropriate functions, according to
  55. ** compiler.
  56. */
  57. #ifdef __TURBOC__
  58.  
  59. #define LMALLOC(kbytes)         farmalloc((((unsigned long) kbytes) * 1024L))
  60. #define LFREE(ptr)              farfree((ptr))
  61.  
  62. #else
  63.  
  64. #define LMALLOC(kbytes)         halloc((kbytes), 1024)
  65. #define LFREE(ptr)              hfree((ptr))
  66.  
  67. #endif
  68.  
  69. /*
  70. ** This macro is the same as TRIPLECHECK(), defined in EMSTEST.H, except that
  71. ** it calls functions which can handle a far pointer.
  72. */
  73. #define LTRIPLECHECK(fu, st, ex, fr1, fr2, fr3)                         \
  74.                          lfailcheck((fu), (st), (fr1), (fr2), (fr3));   \
  75.                          lweirdretchk((fu), (st), (fr1), (fr2), (fr3)); \
  76.                          lweirdcodechk((fu), (ex), (fr1), (fr2), (fr3))
  77.  
  78. /*
  79. ** Checks to see if a region of memory (possibly longer than 64K) is still
  80. ** incrementing longword values, handles cleanup and exit if not.
  81. */
  82. #define LONGCHECK(buf, len, msg, start)                         \
  83.     if (farinclongcheck((buf), (len), (start)) != 0) {          \
  84.         printf("Copy corrupted %s.\n", (msg)); EMMfree(handle); \
  85.         LFREE(testbuf); exit(3); }
  86.  
  87. /*
  88. ** Check source and destination buffers, respectively.
  89. */
  90. #define LSRCLONGCHECK(buf, len)    LONGCHECK(buf, len, "source buffer", 0L)
  91. #define LCPYLONGCHECK(buf, len)    LONGCHECK(buf, len, "copied bytes", 0L)
  92.  
  93. /*
  94. ** Checks buffer for nonzero values.
  95. */
  96. #define LZEROCHECK(buf, len)       LMEMCHECK(buf, len, '\0', handle, testbuf)
  97.  
  98.  
  99. /*
  100. ** misc: copyright strings, version macros, etc.
  101. */
  102.  
  103. /*
  104. ** typedefs
  105. */
  106.  
  107. /*
  108. ** global variables
  109. */
  110.  
  111. /* see EMSTEST.C for info */
  112. extern int testno;
  113. extern unsigned char far *frameptr[];
  114. extern char *gblmsg;
  115.  
  116.  
  117. /*
  118. ** static globals
  119. */
  120.  
  121. /*
  122. ** function prototypes
  123. */
  124.  
  125. static void do_nlongcopy_tests(void);
  126. static void do_ilongcopy_tests(void);
  127.  
  128. static void lfailcheck(char *function, int status, void far *tofree1,
  129.                                                      int tofree2, int tofree3);
  130. static void lnofailcheck(char *function, int status, void far *tofree1,
  131.                                                      int tofree2, int tofree3);
  132. static void lweirdretchk(char *function, int status, void far *tofree1,
  133.                                                      int tofree2, int tofree3);
  134. static void lweirdcodechk(char *function, int expected, void far *tofree1,
  135.                                                      int tofree2, int tofree3);
  136.  
  137. static void LMEMFILL(unsigned char far *buf, unsigned long len,
  138.                                                             unsigned char val);
  139. static void LMEMCHECK(unsigned char far *buf, unsigned long len,
  140.                     unsigned char val, int handle, unsigned char far *testbuf);
  141.  
  142.  
  143. /*
  144. ** functions
  145. */
  146.  
  147.  
  148. /***************************************************************************
  149. *   FUNCTION: DO_LONGCOPY_TESTS                                            *
  150. *                                                                          *
  151. *   DESCRIPTION:                                                           *
  152. *                                                                          *
  153. *       Central dispatching function for long copy tests.                  *
  154. *                                                                          *
  155. *   ENTRY:                                                                 *
  156. *                                                                          *
  157. *       Void.                                                              *
  158. *                                                                          *
  159. *   EXIT:                                                                  *
  160. *                                                                          *
  161. *       Void.                                                              *
  162. *                                                                          *
  163. *   CONSTRAINTS/SIDE EFFECTS:                                              *
  164. *                                                                          *
  165. ***************************************************************************/
  166. void do_longcopy_tests(void)
  167. {
  168.     do_nlongcopy_tests();
  169.     do_ilongcopy_tests();
  170.     return;
  171. } /* end of do_longcopy_tests() */
  172.  
  173.  
  174. /***************************************************************************
  175. *   FUNCTION: DO_NLONGCOPY_TESTS  (STATIC)                                 *
  176. *                                                                          *
  177. *   DESCRIPTION:                                                           *
  178. *                                                                          *
  179. *       Tests EMSLIB functions EMMcopyto() and EMMcopyfrom() with copies   *
  180. *       longer than one EMS page ( > 16384 bytes).                         *
  181. *                                                                          *
  182. *   ENTRY:                                                                 *
  183. *                                                                          *
  184. *       Void.                                                              *
  185. *                                                                          *
  186. *   EXIT:                                                                  *
  187. *                                                                          *
  188. *       Void.                                                              *
  189. *                                                                          *
  190. *   CONSTRAINTS/SIDE EFFECTS:                                              *
  191. *                                                                          *
  192. ***************************************************************************/
  193. static void do_nlongcopy_tests(void)
  194. {
  195.     unsigned char far *testbuf;
  196.     int handle;
  197.     int status;
  198.     unsigned long ticks, totticks;
  199.     int loop;
  200.     unsigned long loop2;
  201.  
  202.     /* allocate memory to test against */
  203.     testbuf = (unsigned char far *) LMALLOC(80);
  204.     if (testbuf == (unsigned char far *) NULL)
  205.     {
  206.         printf("Cannot allocate test memory. Aborting.\n");
  207.         exit(1);
  208.     }
  209.  
  210.     /* now allocate some EMS to test with */
  211.     handle = test_EMMalloc(81920L);
  212.  
  213.     /* fill test buffer with incrementing word pattern */
  214.     farinclongfill(testbuf, 81920L, 0L);
  215.  
  216.     /* fill EMS with a different pattern */
  217.     for (loop = 0; loop < 5; loop++)
  218.     {
  219.         test_EMMmappage(0, handle, loop);
  220.         FMEMSET(frameptr[0], 0, 16384);
  221.     }
  222.  
  223.     /* try a copy off end */
  224.     TESTHEADER();
  225.     printf("Calling EMMcopyto() with offset off end of EMS block.\n");
  226.     printf("Should fail.\n");
  227.     status = EMMcopyto(2L, testbuf, handle, 90000L);
  228.     lnofailcheck("EMMcopyto()", status, testbuf, handle, 0);
  229.     lweirdretchk("EMMcopyto()", status, testbuf, handle, 0);
  230.     lweirdcodechk("EMMcopyto()", EMM_BADOFFSET, testbuf, handle, 0);
  231.     LSRCLONGCHECK(testbuf, 81920L);
  232.     for (loop = 0; loop < 5; loop++)
  233.     {
  234.         test_EMMmappage(0, handle, loop);
  235.         LZEROCHECK(frameptr[0], 16384L);
  236.     }
  237.     TESTTAILER();
  238.  
  239.     /* and another */
  240.     TESTHEADER();
  241.     printf("Calling EMMcopyto() with length that will run off end of block.\n");
  242.     printf("Should fail.\n");
  243.     status = EMMcopyto(30000L, testbuf, handle, 55000L);
  244.     lnofailcheck("EMMcopyto()", status, testbuf, handle, 0);
  245.     lweirdretchk("EMMcopyto()", status, testbuf, handle, 0);
  246.     lweirdcodechk("EMMcopyto()", EMM_BADOFFSET, testbuf, handle, 0);
  247.     LSRCLONGCHECK(testbuf, 81920L);
  248.     for (loop = 0; loop < 5; loop++)
  249.     {
  250.         test_EMMmappage(0, handle, loop);
  251.         LZEROCHECK(frameptr[0], 16384L);
  252.     }
  253.     TESTTAILER();
  254.  
  255.     /* now try copy across page boundary */
  256.     TESTHEADER();
  257.     printf("Calling EMMcopyto() with copy across page boundary.\n");
  258.     printf("Should succeed.\n");
  259.     status = EMMcopyto(10000L, testbuf, handle, 10000L);
  260.     LTRIPLECHECK("EMMcopyto()", status, 0, testbuf, handle, 0);
  261.     LSRCLONGCHECK(testbuf, 81920L);
  262.     test_EMMmappage(0, handle, 0);
  263.     test_EMMmappage(1, handle, 1);
  264.     LCPYLONGCHECK((frameptr[0] + 10000), 10000L);
  265.     LZEROCHECK(frameptr[0], 10000L);
  266.     LZEROCHECK((frameptr[0] + 10000 + 10000), ((32768L - 10000L) - 10000L));
  267.     for (loop = 2; loop < 5; loop++)
  268.     {
  269.         test_EMMmappage(0, handle, loop);
  270.         LZEROCHECK(frameptr[0], 16384L);
  271.     }
  272.     printf("EMMcopyto() succeeded.\n");
  273.     TESTTAILER();
  274.  
  275.     /* restore destination pattern */
  276.     for (loop = 0; loop < 5; loop++)
  277.     {
  278.         test_EMMmappage(0, handle, loop);
  279.         FMEMSET(frameptr[0], 0, 16384);
  280.     }
  281.  
  282.     /* try copy across several page boundaries */
  283.     TESTHEADER();
  284.     printf("Calling EMMcopyto() with copy across several page boundaries.\n");
  285.     printf("Should succeed.\n");
  286.     status = EMMcopyto(50000L, testbuf, handle, 10000L);
  287.     LTRIPLECHECK("EMMcopyto()", status, 0, testbuf, handle, 0);
  288.     LSRCLONGCHECK(testbuf, 81920L);
  289.     for (loop = 0; loop < 4; loop++)
  290.     {
  291.         test_EMMmappage(loop, handle, loop);
  292.     }
  293.     LZEROCHECK(frameptr[0], 10000L);
  294.     LCPYLONGCHECK((frameptr[0] + 10000), 50000L);
  295.     LZEROCHECK((frameptr[0] + 10000U + 50000U), ((65536L - 10000L) - 50000L));
  296.     test_EMMmappage(0, handle, 4);
  297.     LZEROCHECK(frameptr[0], 16384L);
  298.     printf("EMMcopyto() succeeded.\n");
  299.     TESTTAILER();
  300.  
  301.     /* restore destination pattern */
  302.     for (loop = 0; loop < 5; loop++)
  303.     {
  304.         test_EMMmappage(0, handle, loop);
  305.         FMEMSET(frameptr[0], 0, 16384);
  306.     }
  307.  
  308.     /* try copy > 64K */
  309.     TESTHEADER();
  310.     printf("Calling EMMcopyto() with copy length > 64K.\n");
  311.     printf("Should succeed.\n");
  312.     ticks = get_tick();
  313.     status = EMMcopyto(81920L, testbuf, handle, 0L);
  314.     ticks = get_tick() - ticks;
  315.     LTRIPLECHECK("EMMcopyto()", status, 0, testbuf, handle, 0);
  316.     LSRCLONGCHECK(testbuf, 81920L);
  317.     for (loop = 0; loop < 5; loop++)
  318.     {
  319.         test_EMMmappage(0, handle, loop);
  320.         LONGCHECK(frameptr[0], 16384L, "copied bytes", (4096L * loop));
  321.     }
  322.     printf("EMMcopyto() succeeded. 81920 bytes took %lu ticks.\n", ticks);
  323.     TESTTAILER();
  324.  
  325.     /* restore destination pattern */
  326.     for (loop = 0; loop < 5; loop++)
  327.     {
  328.         test_EMMmappage(0, handle, loop);
  329.         FMEMSET(frameptr[0], 0, 16384);
  330.     }
  331.  
  332.     /* do same copy by longwords */
  333.     TESTHEADER();
  334.     printf("Calling EMMcopyto() to copy 81920 bytes by longwords.\n");
  335.     printf("Should succeed, slowly.\n");
  336.     totticks = 0L;
  337.     for (loop2 = 0L; loop2 < 81920L; loop2 += 4L)
  338.     {
  339.         ticks = get_tick();
  340.         status = EMMcopyto(4L, (UCF *)(((UCH *) testbuf) + loop2),
  341.                                                                 handle, loop2);
  342.         totticks += (get_tick() - ticks);
  343.         LTRIPLECHECK("EMMcopyto()", status, 0, testbuf, handle, 0);
  344.     }
  345.     LSRCLONGCHECK(testbuf, 81920L);
  346.     for (loop = 0; loop < 5; loop++)
  347.     {
  348.         test_EMMmappage(0, handle, loop);
  349.         LONGCHECK(frameptr[0], 16384L, "copied bytes", (4096L * loop));
  350.     }
  351.     printf("EMMcopyto() succeeded. 81920 bytes by longwords took %lu ticks.\n",
  352.                                                                      totticks);
  353.     TESTTAILER();
  354.  
  355.  
  356.     /* fill test buffer with zeros */
  357.     LMEMFILL(testbuf, 81920L, '\0');
  358.  
  359.     /* fill EMS with a different pattern */
  360.     for (loop = 0; loop < 5; loop++)
  361.     {
  362.         test_EMMmappage(0, handle, loop);
  363.         farinclongfill(frameptr[0], 16384L, (4096L * loop));
  364.     }
  365.  
  366.     /* try a copy off end */
  367.     TESTHEADER();
  368.     printf("Calling EMMcopyfrom() with offset off end of EMS block.\n");
  369.     printf("Should fail.\n");
  370.     status = EMMcopyfrom(2L, handle, 90000L, testbuf);
  371.     lnofailcheck("EMMcopyfrom()", status, testbuf, handle, 0);
  372.     lweirdretchk("EMMcopyfrom()", status, testbuf, handle, 0);
  373.     lweirdcodechk("EMMcopyfrom()", EMM_BADOFFSET, testbuf, handle, 0);
  374.     LZEROCHECK(testbuf, 81920L);
  375.     for (loop = 0; loop < 5; loop++)
  376.     {
  377.         test_EMMmappage(0, handle, loop);
  378.         LONGCHECK(frameptr[0], 16384L, "source buffer", (4096L * loop));
  379.     }
  380.     TESTTAILER();
  381.  
  382.     /* and another */
  383.     TESTHEADER();
  384.     printf("Calling EMMcopyfrom() with length that will run off end of block.\n");
  385.     printf("Should fail.\n");
  386.     status = EMMcopyfrom(30000L, handle, 55000L, testbuf);
  387.     lnofailcheck("EMMcopyfrom()", status, testbuf, handle, 0);
  388.     lweirdretchk("EMMcopyfrom()", status, testbuf, handle, 0);
  389.     lweirdcodechk("EMMcopyfrom()", EMM_BADOFFSET, testbuf, handle, 0);
  390.     LZEROCHECK(testbuf, 81920L);
  391.     for (loop = 0; loop < 5; loop++)
  392.     {
  393.         test_EMMmappage(0, handle, loop);
  394.         LONGCHECK(frameptr[0], 16384L, "source buffer", (4096L * loop));
  395.     }
  396.     TESTTAILER();
  397.  
  398.     /* now try copy across page boundary */
  399.     TESTHEADER();
  400.     printf("Calling EMMcopyfrom() with copy across page boundary.\n");
  401.     printf("Should succeed.\n");
  402.     status = EMMcopyfrom(10000L, handle, 0L, (testbuf + 10000));
  403.     LTRIPLECHECK("EMMcopyfrom()", status, 0, testbuf, handle, 0);
  404.     LZEROCHECK(testbuf, 10000L);
  405.     LCPYLONGCHECK((testbuf + 10000), 10000L);
  406.     LZEROCHECK((testbuf + 10000 + 10000), ((81920L - 10000L) - 10000L));
  407.     for (loop = 0; loop < 5; loop++)
  408.     {
  409.         test_EMMmappage(0, handle, loop);
  410.         LONGCHECK(frameptr[0], 16384L, "source buffer", (4096L * loop));
  411.     }
  412.     printf("EMMcopyfrom() succeeded.\n");
  413.     TESTTAILER();
  414.  
  415.     /* restore destination pattern */
  416.     LMEMFILL(testbuf, 81920L, '\0');
  417.  
  418.     /* try copy across several page boundaries */
  419.     TESTHEADER();
  420.     printf("Calling EMMcopyfrom() with copy across several page boundaries.\n");
  421.     printf("Should succeed.\n");
  422.     status = EMMcopyfrom(50000L, handle, 0L, (testbuf + 10000));
  423.     LTRIPLECHECK("EMMcopyfrom()", status, 0, testbuf, handle, 0);
  424.     LZEROCHECK(testbuf, 10000L);
  425.     LCPYLONGCHECK((testbuf + 10000), 50000L);
  426.     LZEROCHECK((testbuf + 10000U + 50000U), ((81920L - 10000L) - 50000L));
  427.     for (loop = 0; loop < 5; loop++)
  428.     {
  429.         test_EMMmappage(0, handle, loop);
  430.         LONGCHECK(frameptr[0], 16384L, "source buffer", (4096L * loop));
  431.     }
  432.     printf("EMMcopyfrom() succeeded.\n");
  433.     TESTTAILER();
  434.  
  435.     /* restore destination pattern */
  436.     LMEMFILL(testbuf, 81920L, '\0');
  437.  
  438.     /* try copy > 64K */
  439.     TESTHEADER();
  440.     printf("Calling EMMcopyfrom() with copy length > 64K.\n");
  441.     printf("Should succeed.\n");
  442.     ticks = get_tick();
  443.     status = EMMcopyfrom(81920L, handle, 0L, testbuf);
  444.     ticks = get_tick() - ticks;
  445.     LTRIPLECHECK("EMMcopyfrom()", status, 0, testbuf, handle, 0);
  446.     LCPYLONGCHECK(testbuf, 81920L);
  447.     for (loop = 0; loop < 5; loop++)
  448.     {
  449.         test_EMMmappage(0, handle, loop);
  450.         LONGCHECK(frameptr[0], 16384L, "source buffer", (4096L * loop));
  451.     }
  452.     printf("EMMcopyfrom() succeeded. 81920 bytes took %lu ticks.\n", ticks);
  453.     TESTTAILER();
  454.  
  455.     /* restore destination pattern */
  456.     LMEMFILL(testbuf, 81920L, '\0');
  457.  
  458.     /* do same copy by longwords */
  459.     TESTHEADER();
  460.     printf("Calling EMMcopyfrom() to copy 81920 bytes by longwords.\n");
  461.     printf("Should succeed, slowly.\n");
  462.     totticks = 0L;
  463.     for (loop2 = 0L; loop2 < 81920L; loop2 += 4L)
  464.     {
  465.         ticks = get_tick();
  466.         status = EMMcopyfrom(4L, handle, loop2,
  467.                                            (UCF *)(((UCH *) testbuf) + loop2));
  468.         totticks += (get_tick() - ticks);
  469.         LTRIPLECHECK("EMMcopyfrom()", status, 0, testbuf, handle, 0);
  470.     }
  471.     LCPYLONGCHECK(testbuf, 81920L);
  472.     for (loop = 0; loop < 5; loop++)
  473.     {
  474.         test_EMMmappage(0, handle, loop);
  475.         LONGCHECK(frameptr[0], 16384L, "source buffer", (4096L * loop));
  476.     }
  477.     printf("EMMcopyfrom() succeeded. 81920 bytes by longwords took %lu ticks.\n",
  478.                                                                      totticks);
  479.     TESTTAILER();
  480.  
  481.  
  482.     /* clean up */
  483.     test_EMMfree(handle);
  484.     LFREE(testbuf);
  485.  
  486.     return;
  487. } /* end of do_nlongcopy_tests() */
  488.  
  489.  
  490. /***************************************************************************
  491. *   FUNCTION: DO_ILONGCOPY_TESTS  (STATIC)                                 *
  492. *                                                                          *
  493. *   DESCRIPTION:                                                           *
  494. *                                                                          *
  495. *       Tests EMSLIB functions _EMMicopyto() and _EMMicopyfrom() with      *
  496. *       copies longer than one EMS page ( > 16384 bytes).                  *
  497. *                                                                          *
  498. *   ENTRY:                                                                 *
  499. *                                                                          *
  500. *       Void.                                                              *
  501. *                                                                          *
  502. *   EXIT:                                                                  *
  503. *                                                                          *
  504. *       Void.                                                              *
  505. *                                                                          *
  506. *   CONSTRAINTS/SIDE EFFECTS:                                              *
  507. *                                                                          *
  508. ***************************************************************************/
  509. void do_ilongcopy_tests(void)
  510. {
  511.     unsigned char far *testbuf;
  512.     int handle;
  513.     int status;
  514.     unsigned long ticks, totticks;
  515.     int loop;
  516.  
  517.     /* allocate memory to test against */
  518.     testbuf = (unsigned char far *) LMALLOC(80);
  519.     if (testbuf == (unsigned char far *) NULL)
  520.     {
  521.         printf("Cannot allocate test memory. Aborting.\n");
  522.         exit(1);
  523.     }
  524.  
  525.     /* now allocate some EMS to test with */
  526.     handle = test_EMMalloc(81920L);
  527.  
  528.     /* fill test buffer with incrementing word pattern */
  529.     farinclongfill(testbuf, 81920L, 0L);
  530.  
  531.     /* fill EMS with a different pattern */
  532.     for (loop = 0; loop < 5; loop++)
  533.     {
  534.         test_EMMmappage(0, handle, loop);
  535.         FMEMSET(frameptr[0], 0, 16384);
  536.     }
  537.  
  538.     /* try a copy off end */
  539.     TESTHEADER();
  540.     printf("Calling _EMMicopyto() with offset off end of EMS block.\n");
  541.     printf("Should fail.\n");
  542.     status = EMMicopyto(2L, 2, 2, testbuf, handle, 90000L);
  543.     lnofailcheck("_EMMicopyto()", status, testbuf, handle, 0);
  544.     lweirdretchk("_EMMicopyto()", status, testbuf, handle, 0);
  545.     lweirdcodechk("_EMMicopyto()", EMM_BADOFFSET, testbuf, handle, 0);
  546.     LSRCLONGCHECK(testbuf, 81920L);
  547.     for (loop = 0; loop < 5; loop++)
  548.     {
  549.         test_EMMmappage(0, handle, loop);
  550.         LZEROCHECK(frameptr[0], 16384L);
  551.     }
  552.     TESTTAILER();
  553.  
  554.     /* and another */
  555.     TESTHEADER();
  556.     printf("Calling _EMMicopyto() with length that will run off end of block.\n");
  557.     printf("Should fail.\n");
  558.     status = EMMicopyto(10000L, 2, 2, testbuf, handle, 55000L);
  559.     lnofailcheck("_EMMicopyto()", status, testbuf, handle, 0);
  560.     lweirdretchk("_EMMicopyto()", status, testbuf, handle, 0);
  561.     lweirdcodechk("_EMMicopyto()", EMM_BADOFFSET, testbuf, handle, 0);
  562.     LSRCLONGCHECK(testbuf, 81920L);
  563.     for (loop = 0; loop < 5; loop++)
  564.     {
  565.         test_EMMmappage(0, handle, loop);
  566.         LZEROCHECK(frameptr[0], 16384L);
  567.     }
  568.     TESTTAILER();
  569.  
  570.     /* now try copy across page boundary, aligned */
  571.     TESTHEADER();
  572.     printf(
  573.      "Calling _EMMicopyto() with copy across page boundary, element aligned.\n");
  574.     printf("Should succeed.\n");
  575.     status = EMMicopyto(2500L, 2, 2, testbuf, handle, 10000L);
  576.     LTRIPLECHECK("_EMMicopyto()", status, 0, testbuf, handle, 0);
  577.     status = EMMicopyto(2500L, 2, 2, (testbuf + 2), handle, 10002L);
  578.     LTRIPLECHECK("_EMMicopyto()", status, 0, testbuf, handle, 0);
  579.     LSRCLONGCHECK(testbuf, 81920L);
  580.     test_EMMmappage(0, handle, 0);
  581.     test_EMMmappage(1, handle, 1);
  582.     LCPYLONGCHECK((frameptr[0] + 10000), 10000L);
  583.     LZEROCHECK(frameptr[0], 10000L);
  584.     LZEROCHECK((frameptr[0] + 10000 + 10000), ((32768L - 10000L) - 10000L));
  585.     for (loop = 2; loop < 5; loop++)
  586.     {
  587.         test_EMMmappage(0, handle, loop);
  588.         LZEROCHECK(frameptr[0], 16384L);
  589.     }
  590.     printf("_EMMicopyto() succeeded.\n");
  591.     TESTTAILER();
  592.  
  593.     /* restore destination pattern */
  594.     for (loop = 0; loop < 5; loop++)
  595.     {
  596.         test_EMMmappage(0, handle, loop);
  597.         FMEMSET(frameptr[0], 0, 16384);
  598.     }
  599.  
  600.     /* try copy across several page boundaries, element not aligned */
  601.     TESTHEADER();
  602.     printf("Calling _EMMicopyto() with copy across page boundary, %s\n",
  603.                                                        "element not aligned.");
  604.     printf("Should succeed.\n");
  605.     status = EMMicopyto(5000L, 5, 5, testbuf, handle, 10000L);
  606.     LTRIPLECHECK("_EMMicopyto()", status, 0, testbuf, handle, 0);
  607.     status = EMMicopyto(5000L, 5, 5, (testbuf + 5), handle, 10005L);
  608.     LTRIPLECHECK("_EMMicopyto()", status, 0, testbuf, handle, 0);
  609.     LSRCLONGCHECK(testbuf, 81920L);
  610.     for (loop = 0; loop < 4; loop++)
  611.     {
  612.         test_EMMmappage(loop, handle, loop);
  613.     }
  614.     LZEROCHECK(frameptr[0], 10000L);
  615.     LCPYLONGCHECK((frameptr[0] + 10000), 50000L);
  616.     LZEROCHECK((frameptr[0] + 10000U + 50000U), ((65536L - 10000L) - 50000L));
  617.     test_EMMmappage(0, handle, 4);
  618.     LZEROCHECK(frameptr[0], 16384L);
  619.     printf("_EMMicopyto() succeeded.\n");
  620.     TESTTAILER();
  621.  
  622.     /* restore destination pattern */
  623.     for (loop = 0; loop < 5; loop++)
  624.     {
  625.         test_EMMmappage(0, handle, loop);
  626.         FMEMSET(frameptr[0], 0, 16384);
  627.     }
  628.  
  629.     /* do full copy by longwords */
  630.     TESTHEADER();
  631.     printf(
  632.        "Calling _EMMicopyto() to copy 81920 bytes by longwords, two passes.\n");
  633.     printf("Should succeed.\n");
  634.     ticks = get_tick();
  635.     status = EMMicopyto(10240L, 4, 4, testbuf, handle, 0L);
  636.     totticks = get_tick() - ticks;
  637.     LTRIPLECHECK("_EMMicopyto()", status, 0, testbuf, handle, 0);
  638.     ticks = get_tick();
  639.     status = EMMicopyto(10240L, 4, 4, (testbuf + 4), handle, 4L);
  640.     totticks += (get_tick() - ticks);
  641.     LTRIPLECHECK("_EMMicopyto()", status, 0, testbuf, handle, 0);
  642.     LSRCLONGCHECK(testbuf, 81920L);
  643.     for (loop = 0; loop < 5; loop++)
  644.     {
  645.         test_EMMmappage(0, handle, loop);
  646.         LONGCHECK(frameptr[0], 16384L, "copied bytes", (4096L * loop));
  647.     }
  648.     printf("_EMMicopyto() succeeded. 81920 bytes by longwords took %lu ticks.\n",
  649.                                                                      totticks);
  650.     TESTTAILER();
  651.  
  652.  
  653.     /* restore destination pattern */
  654.     for (loop = 0; loop < 5; loop++)
  655.     {
  656.         test_EMMmappage(0, handle, loop);
  657.         FMEMSET(frameptr[0], 0, 16384);
  658.     }
  659.  
  660.     /* try copy with maximum skip */
  661.     TESTHEADER();
  662.     printf("Calling _EMMicopyto() with skip of 32768.\n");
  663.     printf("Should succeed.\n");
  664.     status = EMMicopyto(2L, 8192, 32768U, testbuf, handle, 0L);
  665.     LTRIPLECHECK("_EMMicopyto()", status, 0, testbuf, handle, 0);
  666.     status = EMMicopyto(2L, 8192, 32768U, (testbuf + 8192), handle, 8192L);
  667.     LTRIPLECHECK("_EMMicopyto()", status, 0, testbuf, handle, 0);
  668.     LSRCLONGCHECK(testbuf, 81920);
  669.     test_EMMmappage(0, handle, 0);
  670.     LONGCHECK(frameptr[0], 16384L, "copied bytes", 0L);
  671.     test_EMMmappage(0, handle, 1);
  672.     LZEROCHECK(frameptr[0], 16384);
  673.     test_EMMmappage(0, handle, 2);
  674.     LZEROCHECK(frameptr[0], 8192);
  675.     LONGCHECK((frameptr[0] + 8192), 8192L, "copied bytes", (2048L * 5L));
  676.     test_EMMmappage(0, handle, 3);
  677.     LONGCHECK(frameptr[0], 8192L, "copied bytes", (4096L * 3L));
  678.     LZEROCHECK((frameptr[0] + 8192), 8192);
  679.     test_EMMmappage(0, handle, 4);
  680.     LZEROCHECK(frameptr[0], 16384);
  681.     printf("_EMMicopyto() succeeded.\n");
  682.     TESTTAILER();
  683.  
  684.     /* restore destination pattern */
  685.     for (loop = 0; loop < 5; loop++)
  686.     {
  687.         test_EMMmappage(0, handle, loop);
  688.         FMEMSET(frameptr[0], 0, 16384);
  689.     }
  690.  
  691.     /* try copy with maximum element size */
  692.     TESTHEADER();
  693.     printf("Calling _EMMicopyto() with element size of 16384.\n");
  694.     printf("Should succeed.\n");
  695.     status = EMMicopyto(3L, 16384, 16384, testbuf, handle, 0L);
  696.     LTRIPLECHECK("_EMMicopyto()", status, 0, testbuf, handle, 0);
  697.     LSRCLONGCHECK(testbuf, 81920);
  698.     test_EMMmappage(0, handle, 0);
  699.     LONGCHECK(frameptr[0], 16384L, "copied bytes", 0L);
  700.     test_EMMmappage(0, handle, 1);
  701.     LZEROCHECK(frameptr[0], 16384);
  702.     test_EMMmappage(0, handle, 2);
  703.     LONGCHECK(frameptr[0], 16384L, "copied bytes", (4096L * 2L));
  704.     test_EMMmappage(0, handle, 3);
  705.     LZEROCHECK(frameptr[0], 16384);
  706.     test_EMMmappage(0, handle, 4);
  707.     LONGCHECK(frameptr[0], 16384L, "copied bytes", (4096L * 4L));
  708.     status = EMMicopyto(2L, 16384, 16384, (testbuf + 16384), handle, 16384L);
  709.     LTRIPLECHECK("_EMMicopyto()", status, 0, testbuf, handle, 0);
  710.     for (loop = 0; loop < 5; loop++)
  711.     {
  712.         test_EMMmappage(0, handle, loop);
  713.         LONGCHECK(frameptr[0], 16384L, "copied bytes", (4096L * loop));
  714.     }
  715.     status = EMMicopyto(2L, 16384, 16384, (testbuf + 8192), handle, 8192L);
  716.     for (loop = 0; loop < 5; loop++)
  717.     {
  718.         test_EMMmappage(0, handle, loop);
  719.         LONGCHECK(frameptr[0], 16384L, "copied bytes", (4096L * loop));
  720.     }
  721.     printf("_EMMicopyto() succeeded.\n");
  722.     TESTTAILER();
  723.  
  724.     /* restore destination pattern */
  725.     for (loop = 0; loop < 5; loop++)
  726.     {
  727.         test_EMMmappage(0, handle, loop);
  728.         FMEMSET(frameptr[0], 0, 16384);
  729.     }
  730.  
  731.     /* try copy with max skip and max element */
  732.     TESTHEADER();
  733.     printf("Calling _EMMicopyto() with skip 32768, element size 16384.\n");
  734.     printf("Should succeed.\n");
  735.     status = EMMicopyto(2L, 16384, 32768U, testbuf, handle, 0L);
  736.     LTRIPLECHECK("_EMMicopyto()", status, 0, testbuf, handle, 0);
  737.     LSRCLONGCHECK(testbuf, 81920L);
  738.     test_EMMmappage(0, handle, 0);
  739.     LONGCHECK(frameptr[0], 16384L, "copied bytes", 0L);
  740.     test_EMMmappage(0, handle, 1);
  741.     LZEROCHECK(frameptr[0], 16384);
  742.     test_EMMmappage(0, handle, 2);
  743.     LZEROCHECK(frameptr[0], 16384);
  744.     test_EMMmappage(0, handle, 3);
  745.     LONGCHECK(frameptr[0], 16384L, "copied bytes", (4096L * 3L));
  746.     test_EMMmappage(0, handle, 4);
  747.     LZEROCHECK(frameptr[0], 16384);
  748.     printf("_EMMicopyto() succeeded.\n");
  749.     TESTTAILER();
  750.  
  751.  
  752.     /* fill test buffer with zeros */
  753.     LMEMFILL(testbuf, 81920L, '\0');
  754.  
  755.     /* fill EMS with a different pattern */
  756.     for (loop = 0; loop < 5; loop++)
  757.     {
  758.         test_EMMmappage(0, handle, loop);
  759.         farinclongfill(frameptr[0], 16384L, (4096L * loop));
  760.     }
  761.  
  762.     /* try a copy off end */
  763.     TESTHEADER();
  764.     printf("Calling _EMMicopyfrom() with offset off end of EMS block.\n");
  765.     printf("Should fail.\n");
  766.     status = EMMicopyfrom(2L, 2, 2, handle, 90000L, testbuf);
  767.     lnofailcheck("_EMMicopyfrom()", status, testbuf, handle, 0);
  768.     lweirdretchk("_EMMicopyfrom()", status, testbuf, handle, 0);
  769.     lweirdcodechk("_EMMicopyfrom()", EMM_BADOFFSET, testbuf, handle, 0);
  770.     LZEROCHECK(testbuf, 81920L);
  771.     for (loop = 0; loop < 5; loop++)
  772.     {
  773.         test_EMMmappage(0, handle, loop);
  774.         LONGCHECK(frameptr[0], 16384L, "source buffer", (4096L * loop));
  775.     }
  776.     TESTTAILER();
  777.  
  778.     /* and another */
  779.     TESTHEADER();
  780.     printf("Calling _EMMicopyfrom() with length that will run off end of block.\n");
  781.     printf("Should fail.\n");
  782.     status = EMMicopyfrom(10000L, 2, 2, handle, 55000L, testbuf);
  783.     lnofailcheck("_EMMicopyfrom()", status, testbuf, handle, 0);
  784.     lweirdretchk("_EMMicopyfrom()", status, testbuf, handle, 0);
  785.     lweirdcodechk("_EMMicopyfrom()", EMM_BADOFFSET, testbuf, handle, 0);
  786.     LZEROCHECK(testbuf, 81920L);
  787.     for (loop = 0; loop < 5; loop++)
  788.     {
  789.         test_EMMmappage(0, handle, loop);
  790.         LONGCHECK(frameptr[0], 16384L, "source buffer", (4096L * loop));
  791.     }
  792.     TESTTAILER();
  793.  
  794.     /* now try copy across page boundary, aligned */
  795.     TESTHEADER();
  796.     printf("Calling _EMMicopyfrom() with copy across page boundary, %s\n",
  797.                                                            "element aligned.");
  798.     printf("Should succeed.\n");
  799.     status = EMMicopyfrom(2500L, 2, 2, handle, 0L, (testbuf + 10000));
  800.     LTRIPLECHECK("_EMMicopyfrom()", status, 0, testbuf, handle, 0);
  801.     status = EMMicopyfrom(2500L, 2, 2, handle, 2L, (testbuf + 10002));
  802.     LTRIPLECHECK("_EMMicopyfrom()", status, 0, testbuf, handle, 0);
  803.     LZEROCHECK(testbuf, 10000L);
  804.     LCPYLONGCHECK((testbuf + 10000), 10000L);
  805.     LZEROCHECK((testbuf + 10000 + 10000), ((81920L - 10000L) - 10000L));
  806.     for (loop = 0; loop < 5; loop++)
  807.     {
  808.         test_EMMmappage(0, handle, loop);
  809.         LONGCHECK(frameptr[0], 16384L, "source buffer", (4096L * loop));
  810.     }
  811.     printf("_EMMicopyfrom() succeeded.\n");
  812.     TESTTAILER();
  813.  
  814.     /* restore destination pattern */
  815.     LMEMFILL(testbuf, 81920L, '\0');
  816.  
  817.     /* try copy across several page boundaries, element not aligned */
  818.     TESTHEADER();
  819.     printf("Calling _EMMicopyfrom() with copy across page boundary, %s\n",
  820.                                                        "element not aligned.");
  821.     printf("Should succeed.\n");
  822.     status = EMMicopyfrom(5000L, 5, 5, handle, 0L, (testbuf + 10000));
  823.     LTRIPLECHECK("_EMMicopyfrom()", status, 0, testbuf, handle, 0);
  824.     status = EMMicopyfrom(5000L, 5, 5, handle, 5L, (testbuf + 10005));
  825.     LTRIPLECHECK("_EMMicopyfrom()", status, 0, testbuf, handle, 0);
  826.     for (loop = 0; loop < 5; loop++)
  827.     {
  828.         test_EMMmappage(0, handle, loop);
  829.         LONGCHECK(frameptr[0], 16384L, "source buffer", (4096L * loop));
  830.     }
  831.     LZEROCHECK(testbuf, 10000L);
  832.     LCPYLONGCHECK((testbuf + 10000), 50000L);
  833.     LZEROCHECK((testbuf + 10000U + 50000U), ((81920L - 10000L) - 50000L));
  834.     printf("_EMMicopyfrom() succeeded.\n");
  835.     TESTTAILER();
  836.  
  837.     /* restore destination pattern */
  838.     LMEMFILL(testbuf, 81920L, '\0');
  839.  
  840.     /* do full copy by longwords */
  841.     TESTHEADER();
  842.     printf(
  843.      "Calling _EMMicopyfrom() to copy 81920 bytes by longwords, two passes.\n");
  844.     printf("Should succeed.\n");
  845.     ticks = get_tick();
  846.     status = EMMicopyfrom(10240L, 4, 4, handle, 0L, testbuf);
  847.     totticks = get_tick() - ticks;
  848.     LTRIPLECHECK("_EMMicopyfrom()", status, 0, testbuf, handle, 0);
  849.     ticks = get_tick();
  850.     status = EMMicopyfrom(10240L, 4, 4, handle, 4L, (testbuf + 4));
  851.     totticks += (get_tick() - ticks);
  852.     LTRIPLECHECK("_EMMicopyfrom()", status, 0, testbuf, handle, 0);
  853.     LCPYLONGCHECK(testbuf, 81920L);
  854.     for (loop = 0; loop < 5; loop++)
  855.     {
  856.         test_EMMmappage(0, handle, loop);
  857.         LONGCHECK(frameptr[0], 16384L, "source buffer", (4096L * loop));
  858.     }
  859.     printf("_EMMicopyfrom() succeeded. 81920 bytes by longwords took %lu ticks.\n",
  860.                                                                      totticks);
  861.     TESTTAILER();
  862.  
  863.     /* restore destination pattern */
  864.     LMEMFILL(testbuf, 81920L, '\0');
  865.  
  866.     /* try copy with maximum skip */
  867.     TESTHEADER();
  868.     printf("Calling _EMMicopyfrom() with skip of 32768.\n");
  869.     printf("Should succeed.\n");
  870.     status = EMMicopyfrom(2L, 8192, 32768U, handle, 0L, testbuf);
  871.     LTRIPLECHECK("_EMMicopyfrom()", status, 0, testbuf, handle, 0);
  872.     status = EMMicopyfrom(2L, 8192, 32768U, handle, 8192L, (testbuf + 8192));
  873.     LTRIPLECHECK("_EMMicopyfrom()", status, 0, testbuf, handle, 0);
  874.     for (loop = 0; loop < 5; loop++)
  875.     {
  876.         test_EMMmappage(0, handle, loop);
  877.         LONGCHECK(frameptr[0], 16384L, "source buffer", (4096L * loop));
  878.     }
  879.     LONGCHECK(testbuf, 16384L, "copied bytes", 0L);
  880.     LZEROCHECK((testbuf + 16384), (16384L + 8192L));
  881.     LONGCHECK((testbuf + (32768U + 8192U)), 16384L, "copied bytes", (2048L*5L));
  882.     LZEROCHECK((testbuf + (8192U * 7U)), (16384 + 8192));
  883.     printf("_EMMicopyfrom() succeeded.\n");
  884.     TESTTAILER();
  885.  
  886.     /* restore destination pattern */
  887.     LMEMFILL(testbuf, 81920L, '\0');
  888.  
  889.     /* try copy with maximum element size */
  890.     TESTHEADER();
  891.     printf("Calling _EMMicopyfrom() with element size of 16384.\n");
  892.     printf("Should succeed.\n");
  893.     status = EMMicopyfrom(3L, 16384, 16384, handle, 0L, testbuf);
  894.     LTRIPLECHECK("_EMMicopyfrom()", status, 0, testbuf, handle, 0);
  895.     for (loop = 0; loop < 5; loop++)
  896.     {
  897.         test_EMMmappage(0, handle, loop);
  898.         LONGCHECK(frameptr[0], 16384L, "source buffer", (4096L * loop));
  899.     }
  900.     LONGCHECK(testbuf, 16384L, "copied bytes", 0L);
  901.     LZEROCHECK((testbuf + 16384), 16384);
  902.     LONGCHECK((testbuf + 32768U), 16384L, "copied bytes", (4096L * 2L));
  903.     LZEROCHECK((testbuf + (16384U * 3U)), 16384);
  904.     LONGCHECK(MK_FP((FP_SEG(testbuf) + 0x1000), FP_OFF(testbuf)), 16384L, "copied bytes", (4096L * 4L));
  905.     status = EMMicopyfrom(2L, 16384, 16384, handle, 16384L, (testbuf + 16384));
  906.     LTRIPLECHECK("_EMMicopyfrom()", status, 0, testbuf, handle, 0);
  907.     LONGCHECK(testbuf, 81920L, "copied bytes", 0L);
  908.     status = EMMicopyfrom(2L, 16384, 16384, handle, 8192L, (testbuf + 8192));
  909.     LTRIPLECHECK("_EMMicopyfrom()", status, 0, testbuf, handle, 0);
  910.     LONGCHECK(testbuf, 81920L, "copied bytes", 0L);
  911.     printf("_EMMicopyfrom() succeeded.\n");
  912.     TESTTAILER();
  913.  
  914.     /* restore destination pattern */
  915.     LMEMFILL(testbuf, 81920L, '\0');
  916.  
  917.     /* try copy with max skip and max element */
  918.     TESTHEADER();
  919.     printf("Calling _EMMicopyfrom() with skip 32768, element size 16384.\n");
  920.     printf("Should succeed.\n");
  921.     status = EMMicopyfrom(2L, 16384, 32768U, handle, 0L, testbuf);
  922.     LTRIPLECHECK("_EMMicopyfrom()", status, 0, testbuf, handle, 0);
  923.     for (loop = 0; loop < 5; loop++)
  924.     {
  925.         test_EMMmappage(0, handle, loop);
  926.         LONGCHECK(frameptr[0], 16384L, "source buffer", (4096L * loop));
  927.     }
  928.     LONGCHECK(testbuf, 16384L, "copied bytes", 0L);
  929.     LZEROCHECK((testbuf + 16384), 32768L);
  930.     LONGCHECK((testbuf + (16384U * 3U)), 16384L, "copied bytes", (4096L * 3L));
  931.     LZEROCHECK(MK_FP((FP_SEG(testbuf) + 0x1000), FP_OFF(testbuf)), 16384);
  932.     printf("_EMMicopyfrom() succeeded.\n");
  933.     TESTTAILER();
  934.  
  935.  
  936.     /* fill test buffer with incrementing word pattern */
  937.     farinclongfill(testbuf, 81920L, 0L);
  938.  
  939.     /* fill EMS with a different pattern */
  940.     for (loop = 0; loop < 5; loop++)
  941.     {
  942.         test_EMMmappage(0, handle, loop);
  943.         FMEMSET(frameptr[0], 0, 16384);
  944.     }
  945.  
  946.     /* try interleaved copy and back */
  947.     TESTHEADER();
  948.     printf("Calling _EMMicopyto() with source and dest skip different.\n");
  949.     printf("Then calling _EMMicopyfrom() to restore interleave.\n");
  950.     printf("Should succeed.\n");
  951.     status = _EMMicopyto(20480L, 2, 2, testbuf, handle, 0L, 0);
  952.     LTRIPLECHECK("_EMMicopyto()", status, 0, testbuf, handle, 0);
  953.     status = _EMMicopyto(20480L, 2, 2, (testbuf + 2), handle, 40960L, 0);
  954.     LTRIPLECHECK("_EMMicopyto()", status, 0, testbuf, handle, 0);
  955.     LSRCLONGCHECK(testbuf, 81920L);
  956.     status = _EMMicopyfrom(20480L, 2, 0, handle, 0L, testbuf, 2);
  957.     LTRIPLECHECK("_EMMicopyfrom()", status, 0, testbuf, handle, 0);
  958.     status = _EMMicopyfrom(20480L, 2, 0, handle, 40960L, (testbuf + 2), 2);
  959.     LTRIPLECHECK("_EMMicopyfrom()", status, 0, testbuf, handle, 0);
  960.     LCPYLONGCHECK(testbuf, 81920);
  961.     TESTTAILER();
  962.  
  963.  
  964.     /* clean up */
  965.     test_EMMfree(handle);
  966.     LFREE(testbuf);
  967.  
  968.     return;
  969. } /* end of do_ilongcopy_tests() */
  970.  
  971.  
  972. /*
  973. ** The following group of functions is essentially the same as the
  974. ** similarly-named functions in EMSTEST.C, but can handle a far pointer.
  975. */
  976.  
  977.  
  978. /***************************************************************************
  979. *   FUNCTION: LWEIRDRETCHK  (STATIC)                                       *
  980. *                                                                          *
  981. *   DESCRIPTION:                                                           *
  982. *                                                                          *
  983. *       This function checks to see if the status value passed to it is    *
  984. *       either 0 or EMMOOPS, and assumes something has gone wrong if it    *
  985. *       is not. If something has gone wrong, does some clean up before     *
  986. *       exiting.                                                           *
  987. *                                                                          *
  988. *   ENTRY:                                                                 *
  989. *                                                                          *
  990. *       function - name of function which may have goofed                  *
  991. *       status   - status value to check                                   *
  992. *       tofree1  - conventional memory block to be freed on exit. Not      *
  993. *                  freed if NULL.                                          *
  994. *       tofree2  - EMS handle to be freed on exit. Not freed if 0.         *
  995. *       tofree2  - another EMS handle to be freed on exit. Not freed if 0. *
  996. *                                                                          *
  997. *   EXIT:                                                                  *
  998. *                                                                          *
  999. *       Void, or may not return.                                           *
  1000. *                                                                          *
  1001. *   CONSTRAINTS/SIDE EFFECTS:                                              *
  1002. *                                                                          *
  1003. ***************************************************************************/
  1004. static void lweirdretchk(char *function, int status, void far *tofree1,
  1005.                                                       int tofree2, int tofree3)
  1006. {
  1007.     if ((status != EMMOOPS) && (status != 0))
  1008.     {
  1009.         printf("%s returned weird value %d, code 0x%X.\n", function, status,
  1010.                                                      (unsigned int) _EMMerror);
  1011.         if (tofree1 != (void *) NULL)
  1012.         {
  1013.             LFREE(tofree1);
  1014.         }
  1015.         if (tofree2 != 0)
  1016.         {
  1017.             EMMfree(tofree2);
  1018.         }
  1019.         if (tofree3 != 0)
  1020.         {
  1021.             EMMfree(tofree3);
  1022.         }
  1023.         exit(3);
  1024.     }
  1025.  
  1026.     return;
  1027. } /* end of lweirdretchk() */
  1028.  
  1029.  
  1030. /***************************************************************************
  1031. *   FUNCTION: LWEIRDCODECHK  (STATIC)                                      *
  1032. *                                                                          *
  1033. *   DESCRIPTION:                                                           *
  1034. *                                                                          *
  1035. *       This function checks to see if the EMSLIB error code value matches *
  1036. *       the expected value, and assumes something has gone wrong if it     *
  1037. *       does not. If something has gone wrong, does some clean up before   *
  1038. *       exiting.                                                           *
  1039. *                                                                          *
  1040. *   ENTRY:                                                                 *
  1041. *                                                                          *
  1042. *       function - name of function which may have goofed                  *
  1043. *       expected - expected value of _EMMerror                             *
  1044. *       tofree1  - conventional memory block to be freed on exit. Not      *
  1045. *                  freed if NULL.                                          *
  1046. *       tofree2  - EMS handle to be freed on exit. Not freed if 0.         *
  1047. *       tofree2  - another EMS handle to be freed on exit. Not freed if 0. *
  1048. *                                                                          *
  1049. *   EXIT:                                                                  *
  1050. *                                                                          *
  1051. *       Void, or may not return.                                           *
  1052. *                                                                          *
  1053. *   CONSTRAINTS/SIDE EFFECTS:                                              *
  1054. *                                                                          *
  1055. ***************************************************************************/
  1056. static void lweirdcodechk(char *function, int expected, void far *tofree1,
  1057.                                                       int tofree2, int tofree3)
  1058. {
  1059.     if ((int) _EMMerror != expected)
  1060.     {
  1061.         printf("%s returned unexpected code 0x%X.\n", function,
  1062.                                                      (unsigned int) _EMMerror);
  1063.         if (tofree1 != (void *) NULL)
  1064.         {
  1065.             LFREE(tofree1);
  1066.         }
  1067.         if (tofree2 != 0)
  1068.         {
  1069.             EMMfree(tofree2);
  1070.         }
  1071.         if (tofree3 != 0)
  1072.         {
  1073.             EMMfree(tofree3);
  1074.         }
  1075.         exit(3);
  1076.     }
  1077.  
  1078.     return;
  1079. } /* end of lweirdcodechk() */
  1080.  
  1081.  
  1082. /***************************************************************************
  1083. *   FUNCTION: LFAILCHECK  (STATIC)                                         *
  1084. *                                                                          *
  1085. *   DESCRIPTION:                                                           *
  1086. *                                                                          *
  1087. *       This function checks to see if the status value passed to it is    *
  1088. *       EMMOOPS and exits if it is. failcheck() is used when a function    *
  1089. *       is expected to succeed. Does some clean up before exiting.         *
  1090. *                                                                          *
  1091. *   ENTRY:                                                                 *
  1092. *                                                                          *
  1093. *       function - name of function which may have goofed                  *
  1094. *       status   - status value to be checked                              *
  1095. *       tofree1  - conventional memory block to be freed on exit. Not      *
  1096. *                  freed if NULL.                                          *
  1097. *       tofree2  - EMS handle to be freed on exit. Not freed if 0.         *
  1098. *       tofree2  - another EMS handle to be freed on exit. Not freed if 0. *
  1099. *                                                                          *
  1100. *   EXIT:                                                                  *
  1101. *                                                                          *
  1102. *       Void, or may not return.                                           *
  1103. *                                                                          *
  1104. *   CONSTRAINTS/SIDE EFFECTS:                                              *
  1105. *                                                                          *
  1106. ***************************************************************************/
  1107. static void lfailcheck(char *function, int status, void far *tofree1,
  1108.                                                       int tofree2, int tofree3)
  1109. {
  1110.     if (status == EMMOOPS)
  1111.     {
  1112.         printf("%s failed, code 0x%X.\n", function, (unsigned int) _EMMerror);
  1113.         if (tofree1 != (void *) NULL)
  1114.         {
  1115.             LFREE(tofree1);
  1116.         }
  1117.         if (tofree2 != 0)
  1118.         {
  1119.             EMMfree(tofree2);
  1120.         }
  1121.         if (tofree3 != 0)
  1122.         {
  1123.             EMMfree(tofree3);
  1124.         }
  1125.         exit(3);
  1126.     }
  1127.  
  1128.     return;
  1129. } /* end of lfailcheck() */
  1130.  
  1131.  
  1132. /***************************************************************************
  1133. *   FUNCTION: LNOFAILCHECK  (STATIC)                                       *
  1134. *                                                                          *
  1135. *   DESCRIPTION:                                                           *
  1136. *                                                                          *
  1137. *       This function checks to see if the status value passed to it is    *
  1138. *       0 and exits if it is. nofailcheck() is used when a function is     *
  1139. *       expected to fail. Does some clean up before exiting.               *
  1140. *                                                                          *
  1141. *   ENTRY:                                                                 *
  1142. *                                                                          *
  1143. *       function - name of function which may have goofed                  *
  1144. *       status   - status value to be checked                              *
  1145. *       tofree1  - conventional memory block to be freed on exit. Not      *
  1146. *                  freed if NULL.                                          *
  1147. *       tofree2  - EMS handle to be freed on exit. Not freed if 0.         *
  1148. *       tofree2  - another EMS handle to be freed on exit. Not freed if 0. *
  1149. *                                                                          *
  1150. *   EXIT:                                                                  *
  1151. *                                                                          *
  1152. *       Void, or may not return.                                           *
  1153. *                                                                          *
  1154. *   CONSTRAINTS/SIDE EFFECTS:                                              *
  1155. *                                                                          *
  1156. ***************************************************************************/
  1157. static void lnofailcheck(char *function, int status, void far *tofree1,
  1158.                                                       int tofree2, int tofree3)
  1159. {
  1160.     if (status == 0)
  1161.     {
  1162.         printf("%s did not fail.\n", function);
  1163.         if (tofree1 != (void *) NULL)
  1164.         {
  1165.             LFREE(tofree1);
  1166.         }
  1167.         if (tofree2 != 0)
  1168.         {
  1169.             EMMfree(tofree2);
  1170.         }
  1171.         if (tofree3 != 0)
  1172.         {
  1173.             EMMfree(tofree3);
  1174.         }
  1175.         exit(3);
  1176.     }
  1177.  
  1178.     return;
  1179. } /* end of lnofailcheck() */
  1180.  
  1181.  
  1182. /***************************************************************************
  1183. *   FUNCTION: LMEMFILL  (STATIC)                                           *
  1184. *                                                                          *
  1185. *   DESCRIPTION:                                                           *
  1186. *                                                                          *
  1187. *       Breaks up fills longer than 64K into fills less than 64K, does     *
  1188. *       fills.                                                             *
  1189. *                                                                          *
  1190. *   ENTRY:                                                                 *
  1191. *                                                                          *
  1192. *       buf - buffer to fill                                               *
  1193. *       len - length of buffer (must be < ~100,000 bytes)                  *
  1194. *       val - value with which to fill                                     *
  1195. *                                                                          *
  1196. *   EXIT:                                                                  *
  1197. *                                                                          *
  1198. *       Void.                                                              *
  1199. *                                                                          *
  1200. *   CONSTRAINTS/SIDE EFFECTS:                                              *
  1201. *                                                                          *
  1202. ***************************************************************************/
  1203. static void LMEMFILL(unsigned char far *buf, unsigned long len,
  1204.                                                              unsigned char val)
  1205. {
  1206.     unsigned int docnt;
  1207.     UCH *temp;
  1208.  
  1209.     docnt = ((len > 65000L) ? 65000U : (unsigned int) len);
  1210.     FMEMSET(buf, (int) (val), docnt);
  1211.     if ((len - docnt) != 0L)
  1212.     {
  1213.         temp = (UCH *) buf;
  1214.         temp += docnt;
  1215.         docnt = (unsigned int)(len - docnt);
  1216.         FMEMSET((UCF *) temp, (int) (val), docnt);
  1217.     }
  1218.  
  1219.     return;
  1220. } /* end of LMEMFILL() */
  1221.  
  1222.  
  1223. /***************************************************************************
  1224. *   FUNCTION: LMEMCHECK  (STATIC)                                          *
  1225. *                                                                          *
  1226. *   DESCRIPTION:                                                           *
  1227. *                                                                          *
  1228. *       Breaks up value checks longer than 64K into checks less than 64K,  *
  1229. *       does checks.                                                       *         *
  1230. *                                                                          *
  1231. *   ENTRY:                                                                 *
  1232. *                                                                          *
  1233. *       buf     - buffer to check                                          *
  1234. *       len     - length of buffer (must be < ~100,000 bytes               *
  1235. *       val     - value that buffer should be                              *
  1236. *       handle  - so that MEMCHECK macro can free EMS if mismatch found    *
  1237. *       testbuf - so that MEMCHECK macro can free conventional             *
  1238. *                                                                          *
  1239. *   EXIT:                                                                  *
  1240. *                                                                          *
  1241. *       Void, or may never return.                                         *
  1242. *                                                                          *
  1243. *   CONSTRAINTS/SIDE EFFECTS:                                              *
  1244. *                                                                          *
  1245. ***************************************************************************/
  1246. static void LMEMCHECK(unsigned char far *buf, unsigned long len,
  1247.                      unsigned char val, int handle, unsigned char far *testbuf)
  1248. {
  1249.     unsigned int docnt;
  1250.     UCH *temp;
  1251.  
  1252.     docnt = ((len > 65000L) ? 65000U : (unsigned int) len);
  1253.     if (farmemcheck(buf, docnt, val) != 0)
  1254.     {
  1255.         printf("Copy corrupted destination.\n");
  1256.         EMMfree(handle);
  1257.         LFREE(testbuf);
  1258.         exit(3);
  1259.     }
  1260.     if ((len - docnt) != 0L)
  1261.     {
  1262.         temp = (UCH *) buf ;
  1263.         temp += docnt;
  1264.         docnt = (unsigned int) (len - docnt);
  1265.         if (farmemcheck((UCF *) temp, docnt, val) != 0)
  1266.         {
  1267.             printf("Copy corrupted destination.\n");
  1268.             EMMfree(handle);
  1269.             LFREE(testbuf);
  1270.             exit(3);
  1271.         }
  1272.     }
  1273.  
  1274.     return;
  1275. } /* end of LMEMCHECK() */
  1276.  
  1277.