1 /* 2 Copyright (C) 1994-1995 Apogee Software, Ltd. 3 4 This program is free software; you can redistribute it and/or 5 modify it under the terms of the GNU General Public License 6 as published by the Free Software Foundation; either version 2 7 of the License, or (at your option) any later version. 8 9 This program is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 13 See the 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, write to the Free Software 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 19 */ 20 //*************************************************************************** 21 // 22 // RT_UTIL.C - various utils palette funcs and modex stuff 23 // 24 //*************************************************************************** 25 26 #ifndef _rt_util_public 27 #define _rt_util_public 28 29 #define ERRORVERSIONROW 1 30 #define ERRORVERSIONCOL 67 31 32 #define LOWMEMORYROW 18 33 #define LOWMEMORYCOL 1 34 35 #include "develop.h" 36 37 extern int egacolor[16]; 38 extern byte * origpal; 39 extern int _argc; 40 extern char ** _argv; 41 42 void markgetch( void ); 43 boolean StringsNotEqual (char * s1, char * s2, int length); 44 void GetPalette(char * pal); 45 void ClearGraphicsScreen( void ); 46 void ClearBuffer( char * buf, int size ); 47 void Error (char *error, ...); 48 void StartupSoftError ( void ); 49 void ShutdownSoftError ( void ); 50 int CheckParm (char *check); 51 int SafeOpenWrite (char *filename); 52 int SafeOpenAppend (char *filename); 53 int SafeOpenRead (char *filename); 54 void SafeRead (int handle, void *buffer, long count); 55 void SafeWrite (int handle, void *buffer, long count); 56 void SafeWriteString (int handle, char * buffer); 57 void *SafeMalloc (long size); 58 void *SafeLevelMalloc (long size); 59 void SafeFree (void * ptr); 60 long LoadFile (char *filename, void **bufferptr); 61 void SaveFile (char *filename, void *buffer, long count); 62 void GetPathFromEnvironment( char *fullname, const char *envname, const char *filename ); 63 void DefaultExtension (char *path, char *extension); 64 void DefaultPath (char *path, char *basepath); 65 void ExtractFileBase (char *path, char *dest); 66 long ParseHex (char *hex); 67 long ParseNum (char *str); 68 short MotoShort (short l); 69 short IntelShort (short l); 70 long MotoLong (long l); 71 long IntelLong (long l); 72 void SwapIntelLong (long *l); 73 void SwapIntelShort(short *s); 74 void SwapIntelLongArray (long *l, int num); 75 void SwapIntelShortArray (short *s, int num); 76 int US_CheckParm (char *parm, char **strings); 77 byte BestColor (int r, int g, int b, byte *palette); 78 int atan2_appx(int,int); 79 int FindDistance(int ix, int iy); 80 int Find_3D_Distance(int ix, int iy, int iz); 81 void SetPalette ( char * pal ); 82 void SetaPalette ( byte * pal ); 83 void FindEGAColors ( void ); 84 void VL_FillPalette (int red, int green, int blue); 85 void VL_SetColor (int color, int red, int green, int blue); 86 void VL_GetColor (int color, int *red, int *green, int *blue); 87 void VL_SetPalette (byte *palette); 88 void VL_GetPalette (byte *palette); 89 void UL_printf (byte *str); 90 void VL_NormalizePalette (byte *palette); 91 void MapDebug (char *error, ...); 92 void OpenMapDebug ( void ); 93 void UL_ColorBox (int x, int y, int w, int h, int color); 94 95 void UL_DisplayMemoryError ( int memneeded ); 96 97 int SideOfLine(int x1, int y1, int x2, int y2, int x3, int y3); 98 99 void hsort(char * base, int nel, int width, int (*compare)(), void (*switcher)()); 100 101 char * UL_GetPath (char * path, char *dir); 102 boolean UL_ChangeDirectory (char *path); 103 boolean UL_ChangeDrive (char *drive); 104 void AbortCheck (char * abortstring); 105 106 void FixFilePath(char *filename); 107 108 109 #if PLATFORM_WIN32 110 #include <io.h> 111 struct find_t 112 { 113 long handle; 114 struct _finddata_t data; 115 char name[MAX_PATH]; 116 }; 117 int _dos_findfirst(char *filename, int x, struct find_t *f); 118 int _dos_findnext(struct find_t *f); 119 120 #elif PLATFORM_UNIX 121 struct find_t 122 { 123 DIR *dir; 124 char pattern[MAX_PATH]; 125 char name[MAX_PATH]; 126 }; 127 int _dos_findfirst(char *filename, int x, struct find_t *f); 128 int _dos_findnext(struct find_t *f); 129 130 #elif PLATFORM_DOS 131 /* no-op */ 132 #else 133 #error please define for your platform. 134 #endif 135 136 137 #if !PLATFORM_DOS 138 struct dosdate_t 139 { 140 unsigned char day; 141 unsigned char month; 142 unsigned int year; 143 unsigned char dayofweek; 144 }; 145 146 void _dos_getdate(struct dosdate_t *date); 147 #endif 148 149 150 #if (SOFTERROR==1) 151 152 void SoftwareError (char *error, ...); 153 #define SoftError SoftwareError 154 155 #else 156 void SoftwareError (char *error, ...); 157 //#define SoftError SoftwareError 158 159 #define SoftError if (1) {} else SoftwareError 160 161 //#define SoftError 162 163 #endif 164 165 #if (DEBUG==1) 166 167 void DebugError (char *error, ...); 168 #define Debug DebugError 169 170 #else 171 172 void DebugError (char *error, ...); 173 #define Debug DebugError 174 //#define Debug 175 176 #endif 177 178 void Square (void); 179 180 #ifdef __WATCOMC__ 181 #pragma aux Square=\ 182 "mov edx,03c4h", \ 183 "mov eax,0100h", \ 184 "out dx,ax", \ 185 "mov eax,0e3h", \ 186 "mov edx,03c2h", \ 187 "out dx,ax", \ 188 "mov eax,0300h", \ 189 "mov edx,03c4h", \ 190 "out dx,ax" \ 191 modify exact [eax edx] 192 #endif 193 194 195 #ifdef DOS 196 void my_outp(int port, int data); 197 #else 198 #define my_outp(a,b) 199 #endif 200 201 #ifdef __WATCOMC__ 202 #pragma aux my_outp = \ 203 "out dx,al", \ 204 parm [edx] [eax] \ 205 modify exact [] 206 #endif 207 208 #define OUTP my_outp 209 210 #endif 211