DPMI.H 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. //
  2. // Copyright 2020 Electronic Arts Inc.
  3. //
  4. // TiberianDawn.DLL and RedAlert.dll and corresponding source code is free
  5. // software: you can redistribute it and/or modify it under the terms of
  6. // the GNU General Public License as published by the Free Software Foundation,
  7. // either version 3 of the License, or (at your option) any later version.
  8. // TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed
  9. // in the hope that it will be useful, but with permitted additional restrictions
  10. // under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT
  11. // distributed with this program. You should have received a copy of the
  12. // GNU General Public License along with permitted additional restrictions
  13. // with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection
  14. /* $Header: F:\projects\c&c0\vcs\code\dpmi.h_v 4.43 05 Jul 1996 17:58:40 JOE_BOSTIC $ */
  15. /***********************************************************************************************
  16. *** 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 ***
  17. ***********************************************************************************************
  18. * *
  19. * Project Name : Command & Conquer *
  20. * *
  21. * File Name : DPMI.H *
  22. * *
  23. * Programmer : Joe L. Bostic *
  24. * *
  25. * Start Date : July 2, 1994 *
  26. * *
  27. * Last Update : July 2, 1994 [JLB] *
  28. * *
  29. *---------------------------------------------------------------------------------------------*
  30. * Functions: *
  31. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  32. #ifndef DPMI_Hx
  33. #define DPMI_Hx
  34. #include <dos.h>
  35. #include <stdlib.h>
  36. #include <stdio.h>
  37. //#include <mem.h>
  38. extern void output(short port, short data);
  39. class DOSSegmentClass {
  40. /*
  41. ** This is the selector/segment value. In real mode it is the segment, in protected
  42. ** mode it is the selector (also 16 bits). This value is moved into DS or ES when
  43. ** accessing memory.
  44. ** Note: in Watcom flat addressing, Selector == Segment<<4 (ex: 0A0000h)
  45. */
  46. unsigned int Selector;
  47. /*
  48. ** These are C equivalents for pushing and popping the DS segment register. By using
  49. ** these, it is possible to create very small code that uses a segment and
  50. ** offset without damaging the DS register. These are especially useful in protected
  51. ** mode, but they are legal in real mode as well.
  52. */
  53. void Push_DS(void) {/*__emit__(0x1E);*/};
  54. void Pop_DS(void) {/*__emit__(0x1F);*/};
  55. public:
  56. DOSSegmentClass(void);
  57. ~DOSSegmentClass(void);
  58. DOSSegmentClass(unsigned short segment, long size=(1024L*64L));
  59. unsigned int Get_Selector(void);
  60. /*
  61. ** This routine is used to assign where the descriptor actually points to in
  62. ** low DOS memory. In real mode, this is a simple segment assignment and the size
  63. ** is always 64K regardless of what is specified. In protected mode, the segment
  64. ** is used to update the selector and the size can be any length.
  65. ** In Watcom flat mode, it sets Selector == segment<<4
  66. */
  67. void Assign(unsigned short segment, long size=(1024L*64L));
  68. /*
  69. ** These routines will move the data to/from regular memory and the segment/descriptor
  70. ** memory.
  71. */
  72. void Copy_To(void *source, int dest, int size);
  73. void Copy_From(void *dest, int source, int size);
  74. void Copy_Word_To(short data, int dest);
  75. void Copy_Byte_To(char data, int dest);
  76. void Copy_DWord_To(long data, int dest);
  77. short Copy_Word_From(int source);
  78. char Copy_Byte_From(int source);
  79. long Copy_DWord_From(int source);
  80. /*
  81. ** These routines move data around between sections of segmented (descriptor) memory.
  82. ** Typically, this is used when accessing DOS memory in protected mode or when dealing
  83. ** with hard memory areas such as the screen.
  84. */
  85. static void Copy(DOSSegmentClass &src, int soffset, DOSSegmentClass &dest, int doffset, int size);
  86. static void Swap(DOSSegmentClass &src, int soffset, DOSSegmentClass &dest, int doffset, int size);
  87. };
  88. inline DOSSegmentClass::DOSSegmentClass(void)
  89. {
  90. Selector = 0xB0000;
  91. }
  92. inline DOSSegmentClass::~DOSSegmentClass(void)
  93. {
  94. }
  95. inline void DOSSegmentClass::Copy_Word_To(short data, int dest)
  96. {
  97. *(short *)(Selector+dest) = data;
  98. }
  99. inline void DOSSegmentClass::Copy_Byte_To(char data, int dest)
  100. {
  101. *(char *)(Selector+dest) = data;
  102. }
  103. inline void DOSSegmentClass::Copy_DWord_To(long data, int dest)
  104. {
  105. *(long *)(Selector+dest) = data;
  106. }
  107. inline void DOSSegmentClass::Assign(unsigned short segment, long)
  108. {
  109. Selector = (long)(segment)<<4L;
  110. }
  111. inline DOSSegmentClass::DOSSegmentClass(unsigned short segment, long)
  112. {
  113. Assign(segment);
  114. }
  115. inline void DOSSegmentClass::Copy_To(void *source, int dest, int size)
  116. {
  117. memmove((void*)(Selector+dest), source, (unsigned)size);
  118. }
  119. inline void DOSSegmentClass::Copy_From(void *dest, int source, int size)
  120. {
  121. memmove(dest, (void*)(Selector+source), (unsigned)size);
  122. }
  123. inline void DOSSegmentClass::Copy(DOSSegmentClass &src, int soffset, DOSSegmentClass &dest, int doffset, int size) {
  124. memmove((void*)(dest.Selector+doffset), (void*)(src.Selector+soffset), (unsigned)size);
  125. }
  126. inline short DOSSegmentClass::Copy_Word_From(int source)
  127. {
  128. return *(short*)(Selector+source);
  129. }
  130. inline char DOSSegmentClass::Copy_Byte_From(int source)
  131. {
  132. return *(char*)(Selector+source);
  133. }
  134. inline long DOSSegmentClass::Copy_DWord_From(int source)
  135. {
  136. return *(long*)(Selector+source);
  137. }
  138. inline unsigned int DOSSegmentClass::Get_Selector(void)
  139. {
  140. return Selector;
  141. }
  142. #endif