mplib.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. /*
  2. Copyright (C) 1996-1997 Id Software, Inc.
  3. This program is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU General Public License
  5. as published by the Free Software Foundation; either version 2
  6. of the License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. See the GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  14. */
  15. #include <dpmi.h>
  16. //#include "types.h"
  17. typedef unsigned char BYTE;
  18. typedef unsigned short WORD;
  19. typedef unsigned long DWORD;
  20. //#include "mgenord.h"
  21. #define MGENVXD_REGISTER_ORD 1
  22. #define MGENVXD_GETMEM_ORD 2
  23. #define MGENVXD_DEREGISTER_ORD 3
  24. #define MGENVXD_WAKEUP_ORD 4
  25. #define MGENVXD_MAKEDQS_ORD 5
  26. // Virtual 8086 API Ordinals
  27. #define V86API_GETSELECTOR16_ORD (1)
  28. #define V86API_GETSELECTOR32_ORD (2)
  29. #define V86API_GETFLAT32_ORD (3)
  30. #define V86API_MOVERP_ORD (6)
  31. #define V86API_MOVEPR_ORD (7)
  32. #define V86API_POST_ORD (8)
  33. #define V86API_INIT_ORD (9)
  34. #define V86API_UNINIT_ORD (10)
  35. #define V86API_INSERTKEY_ORD (11)
  36. #define V86API_REMOVEHOTKEY_ORD (12)
  37. #define V86API_INSTALLHOTKEY_ORD (13)
  38. #define V86API_HOOKINT48_ORD (14)
  39. #define V86API_WAKEUPDLL_ORD (15)
  40. #define DPMIAPI_GETFLAT32_ORD (1)
  41. #define DPMIAPI_POST_WINDOWS_ORD (2)
  42. // these are DPMI functions. Make sure they don't clash with the
  43. // other MGENVXD_XXXX functions above, or the DPMI functions!
  44. #define MGENVXD_GETQUEUECTR_ORD 6
  45. #define MGENVXD_MOVENODE_ORD 7
  46. #define MGENVXD_GETNODE_ORD 8
  47. #define MGENVXD_FLUSHNODE_ORD 9
  48. #define MGENVXD_MCOUNT_ORD 10
  49. #define MGENVXD_MASTERNODE_ORD 11
  50. #define MGENVXD_SANITYCHECK_ORD 12
  51. #define MGENVXD_WAKEUPDLL_ORD 13
  52. #define MGENVXD_WAIT_ORD 14
  53. //
  54. #define HWND_OFFSET (0)
  55. #define UMSG_OFFSET (1)
  56. #define SIZEREQUEST_OFFSET (2)
  57. #define HVXD_OFFSET (3)
  58. #define DATUM_OFFSET (4)
  59. #define SLOT_OFFSET (5)
  60. #define SIZEGIVEN_OFFSET (6)
  61. #define SELECTOR32_OFFSET (7)
  62. #define SELECTOR16_OFFSET (8)
  63. //#include "magic.h"
  64. #define MGENVXD_DEVICE_ID 0x18AA
  65. //#include "rtq.h"
  66. #define RTQ_NODE struct rtq_node
  67. RTQ_NODE
  68. {
  69. RTQ_NODE *self; // Ring zero address of this node
  70. RTQ_NODE *left; // Ring zero address of preceding node
  71. RTQ_NODE *right; // Ring zero address of succeding node
  72. BYTE * rtqDatum; // Ring 3 Datum of Buffer (start of preface)
  73. BYTE * rtqInsert; // Ring 3 insertion position
  74. WORD rtqLen; // Length of buffer, excluding preface
  75. WORD rtqUpCtr; // Up Counter of bytes used so far
  76. WORD rtqQCtr; // number of nodes attached
  77. WORD padding; // DWORD alignment
  78. };
  79. #define RTQ_PARAM_MOVENODE struct rtq_param_movenode
  80. RTQ_PARAM_MOVENODE
  81. {
  82. WORD rtqFromDQ;
  83. WORD rtqToDQ;
  84. };
  85. RTQ_NODE* rtq_fetch(RTQ_NODE*, RTQ_NODE*); // To, From
  86. int _int86(int vector, __dpmi_regs *iregs, __dpmi_regs *oregs);
  87. #define CHUNNEL_INT 0x48
  88. #define int386 _int86
  89. #define REGISTERS __dpmi_regs
  90. void
  91. Yield(void)
  92. {
  93. __dpmi_yield();
  94. }
  95. void
  96. PostWindowsMessage(void)
  97. {
  98. REGISTERS regs;
  99. regs.d.eax = DPMIAPI_POST_WINDOWS_ORD << 16 | MGENVXD_DEVICE_ID;
  100. regs.d.ebx = 0;
  101. regs.d.ecx = 0;
  102. int386(CHUNNEL_INT, &regs, &regs);
  103. }
  104. int
  105. MGenWait(void)
  106. {
  107. REGISTERS regs;
  108. regs.d.eax = MGENVXD_WAIT_ORD << 16 | MGENVXD_DEVICE_ID;
  109. int386(CHUNNEL_INT, &regs, &regs);
  110. return regs.d.eax;
  111. }
  112. int MGenGetQueueCtr(int qNo)
  113. {
  114. REGISTERS regs;
  115. regs.d.eax = MGENVXD_GETQUEUECTR_ORD << 16 | MGENVXD_DEVICE_ID;
  116. regs.d.ebx = qNo;
  117. int386(CHUNNEL_INT, &regs, &regs);
  118. return regs.d.eax;
  119. }
  120. RTQ_NODE *MGenMoveTo(int qFrom, int qTo)
  121. {
  122. REGISTERS regs;
  123. regs.d.eax = MGENVXD_MOVENODE_ORD << 16 | MGENVXD_DEVICE_ID;
  124. regs.d.ebx = qFrom;
  125. regs.d.ecx = qTo;
  126. int386(CHUNNEL_INT, &regs, &regs);
  127. return (RTQ_NODE *) regs.d.eax;
  128. }
  129. RTQ_NODE *MGenGetNode(int q)
  130. {
  131. REGISTERS regs;
  132. regs.d.eax = MGENVXD_GETNODE_ORD << 16 | MGENVXD_DEVICE_ID;
  133. regs.d.ebx = q;
  134. int386(CHUNNEL_INT, &regs, &regs);
  135. return (RTQ_NODE *) regs.d.eax;
  136. }
  137. RTQ_NODE *MGenGetMasterNode(unsigned *size)
  138. {
  139. REGISTERS regs;
  140. regs.d.eax = MGENVXD_MASTERNODE_ORD << 16 | MGENVXD_DEVICE_ID;
  141. int386(CHUNNEL_INT, &regs, &regs);
  142. *size = regs.d.ecx;
  143. return (RTQ_NODE *) regs.d.eax;
  144. }
  145. RTQ_NODE *MGenFlushNodes(int qFrom, int qTo)
  146. {
  147. REGISTERS regs;
  148. regs.d.eax = MGENVXD_FLUSHNODE_ORD << 16 | MGENVXD_DEVICE_ID;
  149. regs.d.ebx = qFrom;
  150. regs.d.ecx = qTo;
  151. int386(CHUNNEL_INT, &regs, &regs);
  152. return (RTQ_NODE *) regs.d.eax;
  153. }
  154. int MGenMCount(unsigned lowerOrderBits, unsigned upperOrderBits)
  155. {
  156. REGISTERS regs;
  157. regs.d.eax = MGENVXD_MCOUNT_ORD << 16 | MGENVXD_DEVICE_ID;
  158. regs.d.ebx = lowerOrderBits;
  159. regs.d.ecx = upperOrderBits;
  160. int386(CHUNNEL_INT, &regs, &regs);
  161. return regs.d.eax;
  162. }
  163. int MGenSanityCheck(void)
  164. {
  165. REGISTERS regs;
  166. regs.d.eax = MGENVXD_SANITYCHECK_ORD << 16 | MGENVXD_DEVICE_ID;
  167. int386(CHUNNEL_INT, &regs, &regs);
  168. return regs.d.eax;
  169. }
  170. void MGenWakeupDll(void)
  171. {
  172. REGISTERS regs;
  173. regs.d.eax = MGENVXD_WAKEUPDLL_ORD << 16 | MGENVXD_DEVICE_ID;
  174. int386(CHUNNEL_INT, &regs, &regs);
  175. }