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