|
|
1.1 root 1: /* This example illustrates allocating a huge segment, addressing
2: * the segment, growing & shrinking the segment and freeing the
3: * segment. The following 286DOS functions are illustrated here:
4: * DOSALLOCHUGE, DOSREALLOCHUGE, DOSFREESEG
5: *
6: * This example allocates a huge segment. It writes a value to one of the
7: * words in the huge segment. It grows the segment and then shrinks the
8: * segment back to its original size. It then checks if the segment contains
9: * the value that was written previously. If not, it prints an error message.
10: * It then frees the huge segment. This example is intended to illustrate
11: * how to manage and access huge segments - it doesn't perform any useful
12: * function.
13: *
14: * Copyright (C) Microsoft Corp. 1986
15: */
16:
17: #include <doscalls.h> /* contains CP/DOS function declarations */
18: #include <dos.h> /* contains FP_SEG and FP_OFF macros */
19:
20: /* used in DOSALLOCHUGE call */
21: #define NUMSEGA 3 /* number of segments in huge segment */
22: #define SIZEA 8000 /* number of bytes in last segment */
23: #define PRIVATE 0 /* huge segment will not be shared */
24: #define MAXSEGS 6 /* max number of 64k segments in huge segment*/
25: #define WORDA 35000 /* a word in segment 2 in huge segment */
26: #define VALUEA 15 /* value to write into WORDA */
27:
28: /* used in DOSREALLOCHUGE call (growing the segment) */
29: #define NUMSEGR 5 /* number of segments in huge segment */
30: #define SIZER 12000 /* number of bytes in last segment */
31:
32: main ()
33: {
34: unsigned FirstSelector; /* first selector for huge segment */
35: int /*huge*/ *HugeSeg; /* pointer to a huge segment */
36:
37: /* allocate a huge segment */
38: DOSALLOCHUGE (NUMSEGA, SIZEA, &FirstSelector, MAXSEGS, PRIVATE);
39:
40: /* compute the address to the huge segment */
41: FP_SEG(HugeSeg) = FirstSelector;
42: FP_OFF(HugeSeg) = 0;
43: HugeSeg[WORDA] = VALUEA;
44:
45: /* grow the huge segment */
46: DOSREALLOCHUGE (NUMSEGR, SIZER, FirstSelector);
47:
48: /* shrink the huge segment to its orginal size */
49: DOSREALLOCHUGE (NUMSEGA, SIZEA, FirstSelector);
50:
51: /* WORDA should still contain VALUEA */
52: if (HugeSeg[WORDA] != VALUEA)
53: printf ("*** error: unexpected value in huge segment ***\n");
54:
55: DOSFREESEG (FirstSelector); /* free the huge segment */
56: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.