MEM.CPP 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. ** Command & Conquer Red Alert(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /****************************************************************************
  19. *
  20. * C O N F I D E N T I A L -- W E S T W O O D S T U D I O S
  21. *
  22. *---------------------------------------------------------------------------
  23. *
  24. * FILE
  25. * mem.c
  26. *
  27. * DESCRIPTION
  28. * Memory management.
  29. *
  30. * PROGRAMMER
  31. * Phil Gorrow
  32. * Denzil E. Long, Jr.
  33. *
  34. * DATE
  35. * July 5, 1995
  36. *
  37. *---------------------------------------------------------------------------
  38. *
  39. * PUBLIC
  40. * DPMI_Lock - Lock a memory page.
  41. * DPMI_Unlock - Unlock a locked memory page.
  42. *
  43. ****************************************************************************/
  44. #ifdef __WATCOMC__
  45. #include <dos.h>
  46. #include <mem.h>
  47. #include <vqm32\mem.h>
  48. /****************************************************************************
  49. *
  50. * NAME
  51. * DPMI_Lock - Lock a memory page.
  52. *
  53. * SYNOPSIS
  54. * DPMI_Lock(Address, Size)
  55. *
  56. * void DPMI_Lock(void *, long);
  57. *
  58. * FUNCTION
  59. *
  60. * INPUTS
  61. * Address - Starting linear address of memory to lock.
  62. * Size - Size of region to lock in bytes.
  63. *
  64. * RESULT
  65. * NONE
  66. *
  67. ****************************************************************************/
  68. void DPMI_Lock(void const *ptr, long const size)
  69. {
  70. union REGS regs;
  71. struct SREGS sregs;
  72. memset(&regs, 0, sizeof(REGS));
  73. segread(&sregs);
  74. /* Lock the memory page.
  75. *
  76. * AX = 0x600
  77. * BX:CX = Starting linear address of memory to lock.
  78. * SI:DI = Size of region to lock in bytes.
  79. */
  80. regs.x.eax = DPMI_LOCK;
  81. regs.x.ebx = ((long)ptr & 0xFFFF0000) >> 16;
  82. regs.x.ecx = ((long)ptr & 0x0000FFFF);
  83. regs.x.esi = ((long)size & 0xFFFF0000) >> 16;
  84. regs.x.edi = ((long)size & 0x0000FFFF);
  85. int386x(DPMI_INT, &regs, &regs, &sregs);
  86. }
  87. /****************************************************************************
  88. *
  89. * NAME
  90. * DPMI_Unlock - Unlock a locked memory page.
  91. *
  92. * SYNOPSIS
  93. * DPMI_Unlock(Address, Size)
  94. *
  95. * void DPMI_Unlock(void *, long);
  96. *
  97. * FUNCTION
  98. *
  99. * INPUTS
  100. * Address - Starting linear address of memory to unlock.
  101. * Size - Size of region to unlock in bytes.
  102. *
  103. * RESULT
  104. * NONE
  105. *
  106. ****************************************************************************/
  107. void DPMI_Unlock(void const *ptr, long const size)
  108. {
  109. union REGS regs;
  110. struct SREGS sregs;
  111. /* Unlock memory page. */
  112. memset(&regs, 0 ,sizeof(REGS));
  113. segread(&sregs);
  114. regs.x.eax = DPMI_UNLOCK;
  115. regs.x.ebx = ((long)ptr & 0xFFFF0000) >> 16;
  116. regs.x.ecx = ((long)ptr & 0x0000FFFF);
  117. regs.x.esi = ((long)size & 0xFFFF0000) >> 16;
  118. regs.x.edi = ((long)size & 0x0000FFFF);
  119. int386x(DPMI_INT, &regs, &regs, &sregs);
  120. }
  121. #endif /* __WATCOMC__ */