DPMI.H 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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.h_v 4.43 05 Jul 1996 17:58:40 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.H *
  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. #ifndef DPMI_Hx
  37. #define DPMI_Hx
  38. #include <dos.h>
  39. #include <stdlib.h>
  40. #include <stdio.h>
  41. #include <mem.h>
  42. extern void output(short port, short data);
  43. class DOSSegmentClass {
  44. /*
  45. ** This is the selector/segment value. In real mode it is the segment, in protected
  46. ** mode it is the selector (also 16 bits). This value is moved into DS or ES when
  47. ** accessing memory.
  48. ** Note: in Watcom flat addressing, Selector == Segment<<4 (ex: 0A0000h)
  49. */
  50. unsigned int Selector;
  51. /*
  52. ** These are C equivalents for pushing and popping the DS segment register. By using
  53. ** these, it is possible to create very small code that uses a segment and
  54. ** offset without damaging the DS register. These are especially useful in protected
  55. ** mode, but they are legal in real mode as well.
  56. */
  57. void Push_DS(void) {/*__emit__(0x1E);*/};
  58. void Pop_DS(void) {/*__emit__(0x1F);*/};
  59. public:
  60. DOSSegmentClass(void);
  61. ~DOSSegmentClass(void);
  62. DOSSegmentClass(unsigned short segment, long size=(1024L*64L));
  63. unsigned int Get_Selector(void);
  64. /*
  65. ** This routine is used to assign where the descriptor actually points to in
  66. ** low DOS memory. In real mode, this is a simple segment assignment and the size
  67. ** is always 64K regardless of what is specified. In protected mode, the segment
  68. ** is used to update the selector and the size can be any length.
  69. ** In Watcom flat mode, it sets Selector == segment<<4
  70. */
  71. void Assign(unsigned short segment, long size=(1024L*64L));
  72. /*
  73. ** These routines will move the data to/from regular memory and the segment/descriptor
  74. ** memory.
  75. */
  76. void Copy_To(void *source, int dest, int size);
  77. void Copy_From(void *dest, int source, int size);
  78. void Copy_Word_To(short data, int dest);
  79. void Copy_Byte_To(char data, int dest);
  80. void Copy_DWord_To(long data, int dest);
  81. short Copy_Word_From(int source);
  82. char Copy_Byte_From(int source);
  83. long Copy_DWord_From(int source);
  84. /*
  85. ** These routines move data around between sections of segmented (descriptor) memory.
  86. ** Typically, this is used when accessing DOS memory in protected mode or when dealing
  87. ** with hard memory areas such as the screen.
  88. */
  89. static void Copy(DOSSegmentClass &src, int soffset, DOSSegmentClass &dest, int doffset, int size);
  90. static void Swap(DOSSegmentClass &src, int soffset, DOSSegmentClass &dest, int doffset, int size);
  91. };
  92. inline DOSSegmentClass::DOSSegmentClass(void)
  93. {
  94. Selector = 0xB0000;
  95. }
  96. inline DOSSegmentClass::~DOSSegmentClass(void)
  97. {
  98. }
  99. inline void DOSSegmentClass::Copy_Word_To(short data, int dest)
  100. {
  101. *(short *)(Selector+dest) = data;
  102. }
  103. inline void DOSSegmentClass::Copy_Byte_To(char data, int dest)
  104. {
  105. *(char *)(Selector+dest) = data;
  106. }
  107. inline void DOSSegmentClass::Copy_DWord_To(long data, int dest)
  108. {
  109. *(long *)(Selector+dest) = data;
  110. }
  111. inline void DOSSegmentClass::Assign(unsigned short segment, long)
  112. {
  113. Selector = (long)(segment)<<4L;
  114. }
  115. inline DOSSegmentClass::DOSSegmentClass(unsigned short segment, long)
  116. {
  117. Assign(segment);
  118. }
  119. inline void DOSSegmentClass::Copy_To(void *source, int dest, int size)
  120. {
  121. memmove((void*)(Selector+dest), source, (unsigned)size);
  122. }
  123. inline void DOSSegmentClass::Copy_From(void *dest, int source, int size)
  124. {
  125. memmove(dest, (void*)(Selector+source), (unsigned)size);
  126. }
  127. inline void DOSSegmentClass::Copy(DOSSegmentClass &src, int soffset, DOSSegmentClass &dest, int doffset, int size) {
  128. memmove((void*)(dest.Selector+doffset), (void*)(src.Selector+soffset), (unsigned)size);
  129. }
  130. inline short DOSSegmentClass::Copy_Word_From(int source)
  131. {
  132. return *(short*)(Selector+source);
  133. }
  134. inline char DOSSegmentClass::Copy_Byte_From(int source)
  135. {
  136. return *(char*)(Selector+source);
  137. }
  138. inline long DOSSegmentClass::Copy_DWord_From(int source)
  139. {
  140. return *(long*)(Selector+source);
  141. }
  142. inline unsigned int DOSSegmentClass::Get_Selector(void)
  143. {
  144. return Selector;
  145. }
  146. #endif