1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342
|
/*
This file is part of SUPPL - the supplemental library for DOS
Copyright (C) 1996-2000 Steffen Kaiser
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* $Id: SUPPL.H 2.17 2001/10/13 18:45:40 ska Exp ska $
$Locker: ska $ $Name: $ $State: Exp $
Declarations for the supplemental functions.
This header file is part of the "portable" subsystem
and will be removed, or moved to another purpose.
*/
#ifndef __SUPPL_H
#define __SUPPL_H
#include <stdio.h>
#include <supl_def.h>
#include <portable.h>
#define itemsof(array) (sizeof(array) / sizeof(array[0]))
#define NIL(type) ((type)0)
/* length of the longmath numbers. */
#define LSIZE sizeof(dword)
#ifndef _MICROC_
#define longsubi(a,b) ((a) -= (int)(b))
#define longsubu(a,b) ((a) -= (unsigned)(b))
#define longaddi(a,b) ((a) += (int)(b))
#define longaddu(a,b) ((a) += (unsigned)(b))
#define longmuli(a,b) ((a) *= (int)(b))
#define longmulu(a,b) ((a) *= (unsigned)(b))
#define longdivi(a,b) ((a) /= (int)(b))
#define longdivu(a,b) ((a) /= (unsigned)(b))
#define longseti(a,b) ((a) = (int)(b))
#define longsetu(a,b) ((a) = (unsigned)(b))
#define longshln(a,c) ((a) <<= (c))
#define longshrn(a,c) ((a) >>= (c))
int longcmp(long d1, long d2);
#define longcmp_(a,b) ((signed long)(a) - (signed long)(b))
#define longsgn(a) ((signed long)(a))
#define longclr(a) ((a) = 0)
#define poked(seg,ofs,value) (*(dword far*)MK_FP(seg,ofs) = (value))
#define pokedd(seg,ofs,hi,lo) (*(dword far*)MK_FP(seg,ofs) = ((dword)(hi)<<16)|(lo))
#define peekd(segm,ofs,value) ((value) = *(dword far*)MK_FP(segm,ofs))
int peekdd(word segm, word ofs, word *valHi, word *valLo);
typedef char far *fartbl; /* far table */
#define dpeekc(fartable,idx) (*(((char far *)fartable) + (idx)))
#define dpeekb(fartable,idx) (*(((byte far *)fartable) + (idx)))
#define dpeekw(fartable,idx) (*(word far*)(((byte far *)fartable) + (idx)))
#define _fmemcmpi _fmemicmp
#define _fstrcmpi _fstricmp
#define memcmpi memicmp
#ifdef _PAC_NOCLIB_
int memicmp(const void *s1, const void *s2, unsigned len);
void *memccpy(void *s1, const void *s2, int ch, size_t len);
#endif
#else /* defined(_MICROC_) */
#define longcmp_ longcmp
#define longsgn(a) (longtst(a) && ((int*)(a))[1])
#define fartbl dword /* pointer to far table */
//char dpeekc(fartbl fartable, int idx);
#define dpeekc(tbl,idx) (char)dpeekb((tbl), (idx))
int dpeekb(fartbl fartable, int idx);
word dpeekw(fartbl fartable, int idx);
int memicmp(const void *s1, const void *s2, unsigned len);
void *memccpy(void *s1, const void *s2, int ch, size_t len);
#endif /* !defined(_MICROC_) */
#define putcm fputcm
int fputmc(int ch, int cnt, FILE *f);
/* Emit the same character several times into the stream
*/
word DOSalloc(const word length, const int mode);
/* Allocate a chunk of memory directly via the DOS API.
length is the number of paragraphes that shall be allocated.
mode is the allocation strategy to be used.
If mode specifies to use high memory, the high memory will be
automatically made accessable.
If the bit 0x10 of mode is set, length is ignored and the size of
the largest unallocated block is returned, which can be allocated
later.
This function does not alter the allocation strategy permanently.
Return:
0: Allocation failed
else: if 0x10 of mode was clear: segment address of allocated memory
if 0x10 of mode was set: the largest unallocated block
*/
int DOSresize(const word segm, const word length);
/* Resize a chunk of memory directly via the DOS API.
segm is the segment to resize, it must be allocated via the DOS API
or a comparable function, like DOSalloc(), allocBlk().
length is the new number of paragraphes.
If to resize the segment fails, the block of memory is not relocated
into a larger space of the DOS memory.
Return:
0: resize failed
!0: resize OK
*/
int DOSfree(const word segm);
/* Free a chunk of memory directly via the DOS API.
segm is the segment to resize, it must be allocated via the DOS API
or a comparable function, like DOSalloc(), allocBlk().
Return:
0: free OK
!0: DOS error code
*/
//word allocBlk(const unsigned length, const int allocMode);
#define allocBlk(length,allocMode) DOSalloc(BLK_byte2para(length), allocMode)
/* Allocates a block of memory using the DOSalloc() function.
The only difference is the length parameter:
Here it is the requested length of the block in bytes, thus,
the block can contain only 0..65535 bytes (up to 64KB).
*/
#ifdef _MICROC_
word resizeBlk(const word segm, const unsigned length);
#else
#define resizeBlk(segm,length) DOSresize(segm, BLK_byte2para(length))
#endif
/* Resizes the segment using the DOSresize() function.
The only difference is the length parameter:
Here it is the requested length of the block in bytes, thus,
the block can contain only 0..65535 bytes (up to 64KB).
*/
//int freeBlk(const word segm);
#define freeBlk DOSfree
/* Free the segment using the DOSfree() function.
No differences, only for completeness.
*/
unsigned BLK_byte2para(const unsigned bytes);
/* Return the number of paragraphes that will be needed to store bytes
bytes in.
If bytes == 0, the return value is zero, too.
*/
int addu(unsigned *u1, unsigned u2);
/* Performs the operation:
*u1 += u2;
and returns, if an overflow occured.
Return: 0: no overflow
!0: overflow
*/
#ifdef __WATCOMC__
#ifdef FARDATA
#pragma aux addu = \
"add word ptr es:[bx], ax" \
"sbb ax, ax" \
parm [es bx] [ax] \
value [ax] \
modify [es bx]
#else
#pragma aux addu = \
"add word ptr [bx], ax" \
"sbb ax, ax" \
parm [bx] [ax] \
value [ax] \
modify [bx]
#endif
#endif
int invokeDOS(nM(IREGS *prp));
/* Invoke DOS using intr(0x21, prp).
Return:
0: DOS returned with Carry flag cleared
!0: AX value (DOS error code) if DOS returned with Carry flag set
*/
#ifndef _CLIB_
char *stpcat(char * const dst, const char * const src);
/* Append src to dst and return the address of the '\0' character of dst
*/
#endif
#ifdef __WATCOMC__
char *stpcpy(char * const dst, const char * const src);
/* Copy src into dst
Return pointer to '\0' terminator of dst
*/
/* different names */
struct ffblk {
char ff_reserved[21];
byte ff_attrib;
unsigned ff_ftime;
unsigned ff_fdate;
long ff_fsize;
char ff_name[13];
};
#endif /* WATCOMC */
#ifdef _PAC_NOCLIB_
char *stpcpy(char * const dst, const char * const src);
/* Copy src onto dst, Return a pointer to the '\0' character of dst
*/
int getdisk(void);
/* Return the current working drive. 0 == A:, 1 == B: ...
*/
int setdisk(void);
/* Change the current working drive. 0 == A:, 1 == B: ...
Returns the number of available drive letters (not necessary
currently accessable).
*/
/*
* Pacific does not offer any OS version information
*/
unsigned osversion(void);
/* Return: _osmajor | (_osminor << 8)
*/
/*
* No findfirst()
*/
struct ffblk {
char ff_reserved[21];
byte ff_attrib;
unsigned ff_ftime;
unsigned ff_fdate;
long ff_fsize;
char ff_name[13];
};
int findfirst(const char * const pattern, struct ffblk *ff, int attrib);
/* Initiate file search
Return: 0 on success
*/
int findnext(struct ffblk *ff);
/* Next file search
Return: 0 on success
*/
void far *getdta(void);
/* Return current working DTA
*/
void setdta(void far *dta);
/* Set current working DTA
*/
unsigned _psp_(void);
/* Return the current PSP
*/
void ctrlbrk(int (*fct)(void));
/* Set new ^Break handler
*/
#endif /* _PAC_NOCLIB_ */
#ifdef COMPILE
#undef COMPILE
#endif
#ifdef _MICROC_
#define COMPILE
#endif
#ifdef _PAC_NOCLIB_
#define COMPILE
#endif
#ifdef __WATCOMC__
#define COMPILE
#endif
#ifdef _TC_EARLY_
#define COMPILE
#endif
#ifdef COMPILE
#undef COMPILE
char *_getdcwd(int drive, char *buf, unsigned length);
/* Return the fully-qualified path of drive in the format:
?:\...\...\...
If buf == NULL, a buffer of length bytes is allocated.
Return:
NULL: On failure
else: on success (buf or allocated buffer)
*/
#endif
int getbootdisk(void);
/* as getdisk() but returns the boot drive
Return:
1 == A:, 2 == B:
0: failure
*/
#endif
|