JSHELL.H (7506B)
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 9 // TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed 10 // in the hope that it will be useful, but with permitted additional restrictions 11 // under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT 12 // distributed with this program. You should have received a copy of the 13 // GNU General Public License along with permitted additional restrictions 14 // with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection 15 16 /* $Header: F:\projects\c&c\vcs\code\jshell.h_v 2.16 16 Oct 1995 16:45:06 JOE_BOSTIC $ */ 17 /*********************************************************************************************** 18 *** 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 *** 19 *********************************************************************************************** 20 * * 21 * Project Name : Command & Conquer * 22 * * 23 * File Name : JSHELL.H * 24 * * 25 * Programmer : Joe L. Bostic * 26 * * 27 * Start Date : 03/13/95 * 28 * * 29 * Last Update : March 13, 1995 [JLB] * 30 * * 31 *---------------------------------------------------------------------------------------------* 32 * Functions: * 33 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 34 35 #ifndef JSHELL_H 36 #define JSHELL_H 37 38 /* 39 ** Interface class to the keyboard. This insulates the game from library vagaries. Most 40 ** notable being the return values are declared as "int" in the library whereas C&C 41 ** expects it to be of KeyNumType. 42 */ 43 class Keyboard 44 { 45 public: 46 static KeyNumType Get(void) {return (KeyNumType)Get_Key_Num();}; 47 static KeyNumType Check(void) {return (KeyNumType)Check_Key_Num();}; 48 static KeyASCIIType To_ASCII(KeyNumType key) {return (KeyASCIIType)KN_To_KA(key);}; 49 static void Clear(void) {Clear_KeyBuffer();}; 50 static void Stuff(KeyNumType key) {Stuff_Key_Num(key);}; 51 static int Down(KeyNumType key) {return Key_Down(key);}; 52 static int Mouse_X(void) {return Get_Mouse_X();}; 53 static int Mouse_Y(void) {return Get_Mouse_Y();}; 54 }; 55 56 57 #ifdef NEVER 58 inline void * operator delete(void * data) 59 { 60 Free(data); 61 } 62 63 inline void * operator delete[] (void * data) 64 { 65 Free(data); 66 } 67 #endif 68 69 70 /* 71 ** These templates allow enumeration types to have simple bitwise 72 ** arithmatic performed. The operators must be instatiated for the 73 ** enumerated types desired. 74 */ 75 template<class T> inline T operator ++(T & a) 76 { 77 a = (T)((int)a + (int)1); 78 return(a); 79 } 80 template<class T> inline T operator ++(T & a, int) 81 { 82 T aa = a; 83 a = (T)((int)a + (int)1); 84 return(aa); 85 } 86 template<class T> inline T operator --(T & a) 87 { 88 a = (T)((int)a - (int)1); 89 return(a); 90 } 91 template<class T> inline T operator --(T & a, int) 92 { 93 T aa = a; 94 a = (T)((int)a - (int)1); 95 return(aa); 96 } 97 template<class T> inline T operator |(T t1, T t2) 98 { 99 return((T)((int)t1 | (int)t2)); 100 } 101 template<class T> inline T operator &(T t1, T t2) 102 { 103 return((T)((int)t1 & (int)t2)); 104 } 105 template<class T> inline T operator ~(T t1) 106 { 107 return((T)(~(int)t1)); 108 } 109 110 111 /* 112 ** The shape flags are likely to be "or"ed together and other such bitwise 113 ** manipulations. These instatiated operator templates allow this. 114 */ 115 //inline ShapeFlags_Type operator |(ShapeFlags_Type, ShapeFlags_Type); 116 //inline ShapeFlags_Type operator &(ShapeFlags_Type, ShapeFlags_Type); 117 //inline ShapeFlags_Type operator ~(ShapeFlags_Type); 118 119 120 121 //#pragma aux Set_Bit parm [esi] [ecx] [eax] 122 void __cdecl Set_Bit(void * array, int bit, int value); 123 124 125 //#pragma aux Get_Bit parm [esi] [eax] 126 int __cdecl Get_Bit(void const * array, int bit); 127 128 //#pragma aux First_True_Bit parm [esi] 129 int __cdecl First_True_Bit(void const * array); 130 131 //#pragma aux First_False_Bit parm [esi] 132 int __cdecl First_False_Bit(void const * array); 133 134 //#pragma aux Bound parm [eax] [ebx] [ecx] 135 int __cdecl Bound(int original, int min, int max); 136 137 138 #if (0) 139 void Set_Bit(void * array, int bit, int value); 140 #pragma aux Set_Bit parm [esi] [ecx] [eax] \ 141 modify [esi ebx] = \ 142 "mov ebx,ecx" \ 143 "shr ebx,5" \ 144 "and ecx,01Fh" \ 145 "btr [esi+ebx*4],ecx" \ 146 "or eax,eax" \ 147 "jz ok" \ 148 "bts [esi+ebx*4],ecx" \ 149 "ok:" 150 151 int Get_Bit(void const * array, int bit); 152 #pragma aux Get_Bit parm [esi] [eax] \ 153 modify [esi ebx] \ 154 value [eax] = \ 155 "mov ebx,eax" \ 156 "shr ebx,5" \ 157 "and eax,01Fh" \ 158 "bt [esi+ebx*4],eax" \ 159 "setc al" 160 161 int First_True_Bit(void const * array); 162 #pragma aux First_True_Bit parm [esi] \ 163 modify [esi ebx] \ 164 value [eax] = \ 165 "mov eax,-32" \ 166 "again:" \ 167 "add eax,32" \ 168 "mov ebx,[esi]" \ 169 "add esi,4" \ 170 "bsf ebx,ebx" \ 171 "jz again" \ 172 "add eax,ebx" 173 174 int First_False_Bit(void const * array); 175 #pragma aux First_False_Bit parm [esi] \ 176 modify [esi ebx] \ 177 value [eax] = \ 178 "mov eax,-32" \ 179 "again:" \ 180 "add eax,32" \ 181 "mov ebx,[esi]" \ 182 "not ebx" \ 183 "add esi,4" \ 184 "bsf ebx,ebx" \ 185 "jz again" \ 186 "add eax,ebx" 187 188 extern int Bound(int original, int min, int max); 189 #pragma aux Bound parm [eax] [ebx] [ecx] \ 190 modify [eax] \ 191 value [eax] = \ 192 "cmp ebx,ecx" \ 193 "jl okorder" \ 194 "xchg ebx,ecx" \ 195 "okorder: cmp eax,ebx" \ 196 "jg okmin" \ 197 "mov eax,ebx" \ 198 "okmin: cmp eax,ecx" \ 199 "jl okmax" \ 200 "mov eax,ecx" \ 201 "okmax:" 202 203 #ifdef NEVER 204 extern unsigned Bound(unsigned original, unsigned min, unsigned max); 205 #pragma aux Bound parm [eax] [ebx] [ecx] \ 206 modify [eax] \ 207 value [eax] = \ 208 "cmp ebx,ecx" \ 209 "jb okorder" \ 210 "xchg ebx,ecx" \ 211 "okorder: cmp eax,ebx" \ 212 "ja okmin" \ 213 "mov eax,ebx" \ 214 "okmin: cmp eax,ecx" \ 215 "jb okmax" \ 216 "mov eax,ecx" \ 217 "okmax:" 218 #endif 219 220 221 unsigned Fixed_To_Cardinal(unsigned base, unsigned fixed); 222 #pragma aux Fixed_To_Cardinal parm [eax] [edx] \ 223 modify [edx] \ 224 value [eax] = \ 225 "mul edx" \ 226 "add eax,080h" \ 227 "test eax,0FF000000h" \ 228 "jz ok" \ 229 "mov eax,000FFFFFFh" \ 230 "ok:" \ 231 "shr eax,8" 232 233 234 unsigned Cardinal_To_Fixed(unsigned base, unsigned cardinal); 235 #pragma aux Cardinal_To_Fixed parm [ebx] [eax] \ 236 modify [edx] \ 237 value [eax] = \ 238 "or ebx,ebx" \ 239 "jz fini" \ 240 "shl eax,8" \ 241 "xor edx,edx" \ 242 "div ebx" \ 243 "fini:" 244 245 #endif //(0) 246 247 248 #endif