--- os2sdk/demos/examples/csalias/csalias.c 2018/08/09 12:25:13 1.1.1.1 +++ os2sdk/demos/examples/csalias/csalias.c 2018/08/09 12:26:24 1.1.1.2 @@ -1,28 +1,31 @@ -/* This example illustrates the use of the following 286DOS function: - * DOSCREATECSALIAS +/* This example illustrates the use of the following MS OS/2 function: + * DosCreateCSAlias * - * A data segment is allocated by calling DOSALLOCSEG. A small assembly + * A data segment is allocated by calling DosAllocSeg. A small assembly * language routine is created in this data segment. An alias code selector - * for this data segment is obtained by calling DOSCREATECSALIAS. Using the + * for this data segment is obtained by calling DosCreateCSAlias. Using the * alias code selector, the routine in the data segment is called. After * returning from the routine, the alias code selector and the data segment - * are freed by calling DOSFREESEG. + * are freed by calling DosFreeSeg. * * This program illustrates the function - it does not do anything useful. * A more likely use of aliasing code to data is where the code is actually * generated at run time, rather than statically declared in this example. * - * Copyright (C) Microsoft Corp. 1986 + * Created by Microsoft Corp. 1986 */ -#include /* CP/DOS function declarations */ +#define INCL_DOSMEMMGR + +#include /* SELECTOROF and OFFSETOF macros */ +#include /* MS OS/2 function declarations */ #include /* printf C lib function declaration */ -#include /* FP_OFF and FP_SEG macros */ + #define PRIVATE 0 /* segment will not be shared */ #define SOMENUM 3 /*to be squared by proc in CSAlias'ed segment*/ -unsigned char square[] = { /*a routine that computes the square of an integer*/ +UCHAR square[] = { /*a routine that computes the square of an integer*/ 0x55, /* push bp */ 0x8b, 0xec, /* mov bp,sp */ 0x8b, 0x46, 0x06, /* mov ax,[bp+6] */ @@ -35,36 +38,36 @@ unsigned char square[] = { /*a routine t main () { - unsigned DataSelector, /* selector to data segment */ + SEL DataSelector, /* selector to data segment */ CodeSelector; /* alias code segment selector */ char *DataSeg; /* pointer to data segemnet */ long (*proc)(int); /* pointer to a procedure */ long SquareOfInt; /* to hold square of an integer*/ /* allocate a segment */ - DOSALLOCSEG (sizeof(square), &DataSelector, PRIVATE); + DosAllocSeg (sizeof(square), &DataSelector, PRIVATE); /* construct a far pointer to the data segment */ - FP_SEG(DataSeg) = DataSelector; - FP_OFF(DataSeg) = 0; + SELECTOROF(DataSeg) = DataSelector; + OFFSETOF(DataSeg) = 0; /* copy an assembly language procedure into the data segment */ strcpy(DataSeg, square); /* get a csalias selector for the data segment */ - DOSCREATECSALIAS (DataSelector, &CodeSelector); + DosCreateCSAlias (DataSelector, &CodeSelector); /* construct the address to the procedure in the csalias'ed segment */ - FP_SEG(proc) = CodeSelector; - FP_OFF(proc) = 0; + SELECTOROF(proc) = CodeSelector; + OFFSETOF(proc) = 0; /* execute the code in the csalias'ed data segment */ if ((SquareOfInt = (*proc)(SOMENUM)) != (SOMENUM * SOMENUM)) printf ("*** error: procedure in CSAlias'ed segment failed ***\n"); /* free the alias code selector */ - DOSFREESEG(CodeSelector); + DosFreeSeg(CodeSelector); /* free the data segment */ - DOSFREESEG(DataSelector); + DosFreeSeg(DataSelector); }