DPMI.CPP 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. /* $Header: F:\projects\c&c0\vcs\code\dpmi.cpv 4.41 04 Jul 1996 16:12:42 JOE_BOSTIC $ */
  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. * Project Name : Command & Conquer *
  24. * *
  25. * File Name : DPMI.CPP *
  26. * *
  27. * Programmer : Joe L. Bostic *
  28. * *
  29. * Start Date : July 2, 1994 *
  30. * *
  31. * Last Update : July 2, 1994 [JLB] *
  32. * *
  33. *---------------------------------------------------------------------------------------------*
  34. * Functions: *
  35. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  36. #ifdef __FLAT__
  37. #pragma inline
  38. #endif
  39. //#include "function.h"
  40. #include "dpmi.h"
  41. #ifndef __FLAT__
  42. void DOSSegmentClass::Swap(DOSSegmentClass &src, int soffset, DOSSegmentClass &dest, int doffset, int size)
  43. {
  44. if (!size) return;
  45. unsigned short ssel = src.Selector;
  46. unsigned short dsel = dest.Selector;
  47. asm {
  48. push es
  49. push ds
  50. mov si,soffset
  51. mov di,doffset
  52. mov cx,size
  53. mov ax,ssel
  54. mov dx,dsel
  55. mov ds,ax
  56. mov es,dx
  57. }
  58. again:
  59. asm {
  60. mov al,ds:[si]
  61. mov ah,es:[di]
  62. mov ds:[si],ah
  63. mov es:[di],al
  64. inc di
  65. inc si
  66. dec cx
  67. jnz again
  68. pop ds
  69. pop es
  70. }
  71. }
  72. #endif
  73. void DOSSegmentClass::Swap(DOSSegmentClass &src, int soffset, DOSSegmentClass &dest, int doffset, int size)
  74. {
  75. extern void dss_swap(char *src, char *dest, int size);
  76. #pragma aux dss_swap = \
  77. "again: mov al,[esi]" \
  78. "mov ah,[edi]" \
  79. "mov [esi],ah" \
  80. "stosb" \
  81. "inc esi" \
  82. "loop again" \
  83. parm [esi] [edi] [ecx] \
  84. modify [ax];
  85. if (!size) return;
  86. dss_swap((char *)(src.Selector + soffset), (char *)(dest.Selector + doffset), size);
  87. }
  88. #ifdef OBSOLETE
  89. void DOSSegmentClass::Copy(DOSSegmentClass &src, int soffset, DOSSegmentClass &dest, int doffset, int size)
  90. {
  91. extern void dss_copy(char *src, char *dest, int size);
  92. #pragma aux dss_copy = \
  93. "mov ebx,ecx" \
  94. "shr ecx,2" \
  95. "jecxz copskip1" \
  96. "rep movsd" \
  97. "copskip1: mov ecx,ebx" \
  98. "and ecx,3" \
  99. "jecxz copskip2" \
  100. "rep movsb" \
  101. "copskip2:" \
  102. parm [esi edi ecx] \
  103. modify [ebx];
  104. if (!size) return;
  105. dss_copy((char *)(src.Selector + soffset), (char *)(dest.Selector + doffset), size);
  106. }
  107. #endif
  108. #ifdef OBSOLETE
  109. void DOSSegmentClass::Copy_To(void *source, int dest, int size)
  110. {
  111. extern void dss_copy_to(void *src, (void *)dest, int size);
  112. #pragma aux dss_copy_to = \
  113. "mov ebx,ecx" \
  114. "shr ecx,2" \
  115. "jecxz cop2skip1" \
  116. "rep movsd" \
  117. "cop2skip1: mov ecx,ebx" \
  118. "and ecx,3" \
  119. "jecxz cop2skip2" \
  120. "rep movsb" \
  121. "cop2skip2:" \
  122. parm [esi edi ecx] \
  123. modify [ebx];
  124. if (!size) return;
  125. dss_copy_to(src, (void *)(Selector + dest), size);
  126. }
  127. #endif
  128. #ifdef OBSOLETE
  129. void DOSSegmentClass::Copy_From(void *dest, int source, int size)
  130. {
  131. extern void dss_copy_from(void *dest, (void *)source, int size);
  132. #pragma aux dss_copy_from = \
  133. "mov ebx,ecx" \
  134. "shr ecx,2" \
  135. "jecxz copfskip1" \
  136. "rep movsd" \
  137. "copfskip1: mov ecx,ebx" \
  138. "and ecx,3" \
  139. "jecxz copfskip2" \
  140. "rep movsb" \
  141. "copfskip2:" \
  142. parm [edi esi ecx] \
  143. modify [ebx];
  144. if (!size) return;
  145. dss_copy_from(dest, (void *)(Selector + source), size);
  146. }
  147. #endif