home *** CD-ROM | disk | FTP | other *** search
- /* callm2.c
- * Purpose: calls real mode program via address
- * Copyright (C) MicroWay, Inc. 1989
- * Usage: run386 -minreal ???? callm2.exp
- * where ???? is the minimum number of paragraphs
- * of conventional memory to be reserved for the
- * real mode program. See appropriate section of
- * Phar Lap manual.
- */
-
- #include <stdio.h>
- #include <dos.h>
-
- #define BUFFSIZE 1
- #define PARASIZE 16
- #define CL_SIZE 80
- #define MSIZE ((BUFFSIZE*PARASIZE)/sizeof(short))
- #define MLIMIT MSIZE-1
- #define NSIZE 4
- #define NLIMIT NSIZE-1
-
- int intnum;
- unsigned buffseg;
- char *physadd;
- short int m[MLIMIT];
- short int n[NLIMIT];
- char commandline[CL_SIZE];
- union REGS inregs, outregs;
-
- main ()
- {
-
- /* INT 21 hexadecimal, service 25C0 hexadecimal
- * is used to allocate BUFFSIZE paragraphs of
- * MS-DOS memory. The segment address of the
- * allocated buffer is stored in buffseg.
- */
- intnum = 0x21;
- inregs.w.bx = BUFFSIZE;
- inregs.w.ax = 0x25c0;
- int386(&intnum,&inregs,&outregs);
- /* Paragraph address of real mode buffer returned in ax */
- buffseg = outregs.w.ax;
-
- sprintf(commandline,"RB.EXE %d", buffseg);
- printf ("%s\n", commandline);
- /* system invokes the real mode program named in commandline */
- system (commandline);
- /* Convert paragraph address in BUFFSEG to 32-bit address */
- physadd = (char *) (buffseg * PARASIZE);
-
- /* In this example, blk_mb() moves 16 bytes of information
- * from offset physadd in conventional memory to the array
- * m(1) in the NDP program's data segment. Conventional memory
- * is accessed by Phar Lap's segment selector 34 hexadecimal.
- * Segment selector 0x34 maps to the first megabyte of memory
- * (real memory), and the offset is calculated by multiplying
- * the real mode segment by 16 (done above) and adding the
- * offset into the segment (in this case, 0).
- */
- blk_mb(&m[0], 0x34, physadd, (BUFFSIZE*PARASIZE));
-
- /* The BASIC program has loaded m(3) with the
- * segment and M(2) with the offset of a data
- * transfer area.
- */
- physadd = (char *) (m[3] << 4) + m[2];
- n[0] = 2;
- n[1] = 3;
- n[2] = 5;
- n[3] = 7;
-
- /* The call to blk_bm() is syntactically similar
- * to the one to blk_mb(). In this case, it loads
- * the BASIC array with the values found in n[0]
- * through n[3].
- */
-
- blk_bm (&n[0], 0x34, physadd, (sizeof(n[0])*NSIZE));
-
- /* This call to INT386 places a call to the entry
- * point BASIC left in the m[] array at segment
- * m[1], offset M[0]
- */
- intnum = 0x21;
- inregs.w.bx = m[0];
- inregs.w.l_bx = m[1];
- inregs.d.ecx = 0;
- inregs.w.ax = 0x250e;
- int386(&intnum,&inregs,&outregs);
-
- /* The array, as altered by BASIC, brought back
- * to protected mode by a last call to blk_mb().
- */
- blk_mb(&n[0], 0x34, physadd, (sizeof(n[0])*NSIZE));
- printf ("%d %d %d %d\n", n[0], n[1], n[2], n[3]);
-
- /* Free MS-DOS memory allocated above */
-
- intnum = 0x21;
- inregs.w.cx = buffseg;
- inregs.w.ax = 0x25c1;
- int386(&intnum,&inregs,&outregs);
-
- } /* end of main */
-