home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c329 / 2.img / EXAMPLES / CALLM2.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-10-06  |  3.1 KB  |  106 lines

  1. /* callm2.c
  2.  * Purpose: calls real mode program via address
  3.  * Copyright (C) MicroWay, Inc. 1989
  4.  * Usage: run386 -minreal ???? callm2.exp
  5.  * where ???? is the minimum number of paragraphs
  6.  * of conventional memory to be reserved for the
  7.  * real mode program. See appropriate section of
  8.  * Phar Lap manual.
  9.  */
  10.  
  11. #include <stdio.h>
  12. #include <dos.h>
  13.  
  14. #define BUFFSIZE 1
  15. #define PARASIZE 16
  16. #define CL_SIZE 80
  17. #define MSIZE ((BUFFSIZE*PARASIZE)/sizeof(short))
  18. #define MLIMIT MSIZE-1
  19. #define NSIZE 4
  20. #define NLIMIT NSIZE-1
  21.  
  22. int intnum;
  23. unsigned buffseg;
  24. char *physadd;
  25. short int m[MLIMIT];
  26. short int n[NLIMIT];
  27. char commandline[CL_SIZE];
  28. union REGS inregs, outregs;
  29.         
  30. main ()
  31. {
  32.  
  33. /* INT 21 hexadecimal, service 25C0 hexadecimal
  34.  * is used to allocate BUFFSIZE paragraphs of
  35.  * MS-DOS memory. The segment address of the
  36.  * allocated buffer is stored in buffseg.
  37.  */
  38.         intnum = 0x21;
  39.         inregs.w.bx = BUFFSIZE;
  40.         inregs.w.ax = 0x25c0;
  41.         int386(&intnum,&inregs,&outregs);
  42. /* Paragraph address of real mode buffer returned in ax */
  43.         buffseg = outregs.w.ax;
  44.  
  45.         sprintf(commandline,"RB.EXE %d", buffseg);
  46.         printf ("%s\n", commandline);
  47. /* system invokes the real mode program named in commandline */
  48.         system (commandline);
  49. /* Convert paragraph address in BUFFSEG to 32-bit address */
  50.         physadd = (char *) (buffseg * PARASIZE);
  51.  
  52. /* In this example, blk_mb() moves 16 bytes of information
  53.  * from offset physadd in conventional memory to the array
  54.  * m(1) in the NDP program's data segment. Conventional memory
  55.  * is accessed by Phar Lap's segment selector 34 hexadecimal.
  56.  * Segment selector 0x34 maps to the first megabyte of memory
  57.  * (real memory), and the offset is calculated by multiplying
  58.  * the real mode segment by 16 (done above) and adding the
  59.  * offset into the segment (in this case, 0).
  60.  */
  61.         blk_mb(&m[0], 0x34, physadd, (BUFFSIZE*PARASIZE));
  62.  
  63. /* The BASIC program has loaded m(3) with the
  64.  * segment and M(2) with the offset of a data
  65.  * transfer area.
  66.  */
  67.         physadd = (char *) (m[3] << 4) + m[2];
  68.         n[0] = 2;
  69.         n[1] = 3;
  70.         n[2] = 5;
  71.         n[3] = 7;
  72.  
  73. /* The call to blk_bm() is syntactically similar
  74.  * to the one to blk_mb(). In this case, it loads
  75.  * the BASIC array with the values found in n[0]
  76.  * through n[3].
  77.  */
  78.  
  79.         blk_bm (&n[0], 0x34, physadd, (sizeof(n[0])*NSIZE));
  80.  
  81. /* This call to INT386 places a call to the entry
  82.  * point BASIC left in the m[] array at segment
  83.  * m[1], offset M[0]
  84.  */
  85.         intnum = 0x21;
  86.         inregs.w.bx = m[0];
  87.         inregs.w.l_bx = m[1];
  88.         inregs.d.ecx = 0;
  89.         inregs.w.ax = 0x250e;
  90.         int386(&intnum,&inregs,&outregs);
  91.  
  92. /* The array, as altered by BASIC, brought back
  93.  * to protected mode by a last call to blk_mb().
  94.  */
  95.         blk_mb(&n[0], 0x34, physadd, (sizeof(n[0])*NSIZE));
  96.         printf ("%d %d %d %d\n", n[0], n[1], n[2], n[3]);
  97.  
  98. /* Free MS-DOS memory allocated above */
  99.  
  100.         intnum = 0x21;
  101.         inregs.w.cx = buffseg;
  102.         inregs.w.ax = 0x25c1;
  103.         int386(&intnum,&inregs,&outregs);
  104.  
  105. }        /* end of main */
  106.