|
|
1.1 root 1: #ifndef __RAD__
2: #define __RAD__
3:
4: #define RADCOPYRIGHT "Copyright (c) RAD Software, 1994-95."
5:
6:
7: // __RADDOS__ means DOS code (16 or 32 bit)
8: // __RAD16__ means 16 bit code (Win16)
9: // __RAD32__ means 32 bit code (DOS, Win386, Win32s, Mac)
10: // __RADWIN__ means Windows code (Win16, Win386, Win32s)
11: // __RADWINEXT__ means Windows 386 extender (Win386)
12: // __RADNT__ means Win32s code
13: // __RADMAC__ means Macintosh
14: // __RAD68K__ means 68K Macintosh
15: // __RADPPC__ means PowerMac
16:
17:
18: #if defined(__MWERKS__) || defined(THINK_C) || defined(powerc) || defined(macintosh) || defined(__powerc)
19:
20: #define __RADMAC__
21: #if defined(powerc) || defined(__powerc)
22: #define __RADPPC__
23: #else
24: #define __RAD68K__
25: #endif
26:
27: #define __RAD32__
28:
29: #else
30:
31: #ifdef __DOS__
32: #define __RADDOS__
33: #endif
34:
35: #ifdef __386__
36: #define __RAD32__
37: #endif
38:
39: #ifdef _Windows //For Borland
40: #ifdef __WIN32__
41: #define WIN32
42: #else
43: #define __WINDOWS__
44: #endif
45: #endif
46:
47: #ifdef _WINDOWS //For MS
48: #ifndef _WIN32
49: #define __WINDOWS__
50: #endif
51: #endif
52:
53: #ifdef _WIN32
54: #define __RADWIN__
55: #define __RADNT__
56: #define __RAD32__
57: #else
58: #ifdef __NT__
59: #define __RADNT__
60: #define __RAD32__
61: #define __RADWIN__
62: #else
63: #ifdef __WINDOWS_386__
64: #define __RADWIN__
65: #define __RADWINEXT__
66: #define __RAD32__
67: #else
68: #ifdef __WINDOWS__
69: #define __RADWIN__
70: #define __RAD16__
71: #else
72: #ifdef WIN32
73: #define __RADWIN__
74: #define __RADNT__
75: #define __RAD32__
76: #endif
77: #endif
78: #endif
79: #endif
80: #endif
81:
82: #endif
83:
84: #if !defined(__RADDOS__) && !defined(__RADWIN__) && !defined(__RADMAC__)
85: #error RAD.H didn'y detect your platform. Define __DOS__, __WINDOWS__, WIN32, macintosh, or powerc.
86: #endif
87:
88: #ifdef __RADMAC__
89: #define RADLINK
90: #define RADEXPLINK
91: #define RADASMLINK
92: #else
93:
94: #ifdef __RADNT__
95: #ifndef _WIN32
96: #define _WIN32
97: #endif
98: #endif
99:
100: #define RADDLLIMP
101:
102: #ifdef __RADWIN__
103: #ifdef __RAD32__
104: #ifdef __RADNT__
105: #define RADEXPLINK __cdecl
106: #ifndef __RADINDLL_
107: #undef RADDLLIMP
108: #define RADDLLIMP __declspec(dllimport)
109: #endif
110: #ifdef __WATCOMC__
111: #define RADLINK __pascal
112: #else
113: #define RADLINK
114: #endif
115: #else
116: #define RADLINK __pascal
117: #define RADEXPLINK __far __pascal
118: #endif
119: #else
120: #define RADLINK __far __pascal
121: #define RADEXPLINK __export __far __pascal
122: #endif
123: #else
124: #define RADLINK __pascal
125: #define RADEXPLINK __pascal
126: #endif
127:
128: #define RADASMLINK __cdecl
129:
130: #endif
131:
132: #ifdef __cplusplus
133: #define RCFUNC extern "C"
134: #define RCSTART extern "C" {
135: #define RCEND }
136: #else
137: #define RCFUNC
138: #define RCSTART
139: #define RCEND
140: #endif
141:
142:
143: RCSTART
144:
145: #define s8 signed char
146: #define u8 unsigned char
147: #define u32 unsigned long
148: #define s32 signed long
149:
150: #ifdef __RAD32__
151: #define PTR4
152:
153: #define u16 unsigned short
154: #define s16 signed short
155:
156: #ifdef __RADMAC__
157:
158: #include <string.h>
159: #include <memory.h>
160: #include <OSUtils.h>
161:
162: #define radstrlen strlen
163:
164: #define radmemset memset
165:
166: #define radmemcpy(dest,source,size) BlockMoveData((Ptr)(source),(Ptr)(dest),size)
167:
168: #define radmemcpydb(dest,source,size) BlockMoveData((Ptr)(source),(Ptr)(dest),size)
169:
170: #define radstrcpy strcpy
171:
172: #ifdef __RAD68K__
173:
174: #pragma parameter __D0 mult64anddiv(__D0,__D1,__D2)
175: u32 mult64anddiv(u32 m1,u32 m2,u32 d) FOURWORDINLINE(0x4C01,0x0C01,0x4C42,0x0C01);
176: // muls.l d1,d1:d0 divs.l d2,d1:d0
177:
178: #pragma parameter radconv32a(__A0,__D0)
179: void radconv32a(void* p,u32 n) NINEWORDINLINE(0x4A80,0x600C,0x2210,0xE059,0x4841,0xE059,0x20C1,0x5380,0x6EF2);
180: // tst.l d0 bra.s @loope @loop: move.l (a0),d1 ror.w #8,d1 swap d1 ror.w #8,d1 move.l d1,(a0)+ sub.l #1,d0 bgt.s @loop @loope:
181:
182: #else
183:
184: u32 mult64anddiv(u32 m1,u32 m2,u32 d);
185:
186: void radconv32a(void* p,u32 n);
187:
188: #endif
189:
190: #else
191:
192: #ifdef __WATCOMC__
193:
194: u32 mult64anddiv(u32 m1,u32 m2,u32 d);
195: #pragma aux mult64anddiv = "mul ecx" "div ebx" parm [eax] [ecx] [ebx] modify [EDX eax];
196:
197: s32 radabs(s32 ab);
198: #pragma aux radabs = "test eax,eax" "jge skip" "neg eax" "skip:" parm [eax];
199:
200: #define radabs32 radabs
201:
202: u32 DOSOut(char* str);
203: #pragma aux DOSOut = "cld" "mov ecx,0xffffffff" "xor eax,eax" "mov edx,edi" "repne scasb" "not ecx" "dec ecx" "mov ebx,1" "mov ah,0x40" "int 0x21" parm [EDI] modify [EAX EBX ECX EDX EDI] value [ecx];
204:
205: void DOSOutNum(char* str,u32 len);
206: #pragma aux DOSOutNum = "mov ah,0x40" "mov ebx,1" "int 0x21" parm [edx] [ecx] modify [eax ebx];
207:
208: u32 ErrOut(char* str);
209: #pragma aux ErrOut = "cld" "mov ecx,0xffffffff" "xor eax,eax" "mov edx,edi" "repne scasb" "not ecx" "dec ecx" "xor ebx,ebx" "mov ah,0x40" "int 0x21" parm [EDI] modify [EAX EBX ECX EDX EDI] value [ecx];
210:
211: void ErrOutNum(char* str,u32 len);
212: #pragma aux ErrOutNum = "mov ah,0x40" "xor ebx,ebx" "int 0x21" parm [edx] [ecx] modify [eax ebx];
213:
214: void radmemset16(void* dest,u16 value,u32 size);
215: #pragma aux radmemset16 = "cld" "mov bx,ax" "shl eax,16" "mov ax,bx" "mov bl,cl" "shr ecx,1" "rep stosd" "mov cl,bl" "and cl,1" "rep stosb" parm [EDI] [EAX] [ECX] modify [EAX EDX EBX ECX EDI];
216:
217: void radmemset(void* dest,u8 value,u32 size);
218: #pragma aux radmemset = "cld" "mov ah,al" "mov bx,ax" "shl eax,16" "mov ax,bx" "mov bl,cl" "shr ecx,2" "rep stosd" "mov cl,bl" "and cl,3" "rep stosb" parm [EDI] [AL] [ECX] modify [EAX EDX EBX ECX EDI];
219:
220: void radmemcpy(void* dest,void* source,u32 size);
221: #pragma aux radmemcpy = "cld" "mov bl,cl" "shr ecx,2" "rep movsd" "mov cl,bl" "and cl,3" "rep movsb" parm [EDI] [ESI] [ECX] modify [EBX ECX EDI ESI];
222:
223: void __far *radfmemcpy(void __far* dest,void __far* source,u32 size);
224: #pragma aux radfmemcpy = "cld" "push es" "push ds" "mov es,cx" "mov ds,dx" "mov ecx,eax" "shr ecx,2" "rep movsd" "mov cl,al" "and cl,3" "rep movsb" "pop ds" "pop es" parm [CX EDI] [DX ESI] [EAX] modify [ECX EDI ESI] value [CX EDI];
225:
226: void radmemcpydb(void* dest,void* source,u32 size); //Destination bigger
227: #pragma aux radmemcpydb = "std" "mov bl,cl" "lea esi,[esi+ecx-4]" "lea edi,[edi+ecx-4]" "shr ecx,2" "rep movsd" "and bl,3" "jz dne" "add esi,3" "add edi,3" "mov cl,bl" "rep movsb" "dne:" "cld" parm [EDI] [ESI] [ECX] modify [EBX ECX EDI ESI];
228:
229: char* radstrcpy(void* dest,void* source);
230: #pragma aux radstrcpy = "cld" "mov edx,edi" "lp:" "mov al,[esi]" "inc esi" "mov [edi],al" "inc edi" "cmp al,0" "jne lp" parm [EDI] [ESI] modify [EAX EDX EDI ESI] value [EDX];
231:
232: char __far* radfstrcpy(void __far* dest,void __far* source);
233: #pragma aux radfstrcpy = "cld" "push es" "push ds" "mov es,cx" "mov ds,dx" "mov edx,edi" "lp:" "lodsb" "stosb" "test al,0xff" "jnz lp" "pop ds" "pop es" parm [CX EDI] [DX ESI] modify [EAX EDX EDI ESI] value [CX EDX];
234:
235: char* radstpcpy(void* dest,void* source);
236: #pragma aux radstpcpy = "cld" "lp:" "mov al,[esi]" "inc esi" "mov [edi],al" "inc edi" "cmp al,0" "jne lp" "dec edi" parm [EDI] [ESI] modify [EAX EDI ESI] value [EDI];
237:
238: char* radstpcpyrs(void* dest,void* source);
239: #pragma aux radstpcpyrs = "cld" "lp:" "lodsb" "stosb" "test al,0xff" "jnz lp" "dec edi" parm [EDI] [ESI] modify [EAX EDI ESI] value [ESI];
240:
241: u32 radstrlen(void* dest);
242: #pragma aux radstrlen = "cld" "mov ecx,0xffffffff" "xor eax,eax" "repne scasb" "not ecx" "dec ecx" parm [EDI] modify [EAX ECX EDI] value [ECX];
243:
244: char* radstrcat(void* dest,void* source);
245: #pragma aux radstrcat = "cld" "mov ecx,0xffffffff" "mov edx,edi" "xor eax,eax" "repne scasb" "dec edi" "lp:" "lodsb" "stosb" "test al,0xff" "jnz lp" \
246: parm [EDI] [ESI] modify [EAX ECX EDI ESI] value [EDX];
247:
248: char* radstrchr(void* dest,char chr);
249: #pragma aux radstrchr = "cld" "lp:" "lodsb" "cmp al,dl" "je fnd" "cmp al,0" "jnz lp" "mov esi,1" "fnd:" "dec esi" parm [ESI] [DL] modify [EAX ESI] value [esi];
250:
251: s8 radmemcmp(void* s1,void* s2,u32 len);
252: #pragma aux radmemcmp = "cld" "rep cmpsb" "setne al" "jbe end" "neg al" "end:" parm [EDI] [ESI] [ECX] modify [ECX EDI ESI];
253:
254: s8 radstrcmp(void* s1,void* s2);
255: #pragma aux radstrcmp = "lp:" "mov al,[esi]" "mov ah,[edi]" "cmp al,ah" "jne set" "cmp al,0" "je set" "inc esi" "inc edi" "jmp lp" "set:" "setne al" "jbe end" "neg al" "end:" \
256: parm [EDI] [ESI] modify [EAX EDI ESI];
257:
258: s8 radstricmp(void* s1,void* s2);
259: #pragma aux radstricmp = "lp:" "mov al,[esi]" "mov ah,[edi]" "cmp al,'a'" "jb c1" "cmp al,'z'" "ja c1" "sub al,32" "c1:" "cmp ah,'a'" "jb c2" "cmp ah,'z'" "ja c2" "sub ah,32" "c2:" "cmp al,ah" "jne set" "cmp al,0" "je set" \
260: "inc esi" "inc edi" "jmp lp" "set:" "setne al" "jbe end" "neg al" "end:" \
261: parm [EDI] [ESI] modify [EAX EDI ESI];
262:
263: s8 radstrnicmp(void* s1,void* s2,u32 len);
264: #pragma aux radstrnicmp = "lp:" "mov al,[esi]" "mov ah,[edi]" "cmp al,'a'" "jb c1" "cmp al,'z'" "ja c1" "sub al,32" "c1:" "cmp ah,'a'" "jb c2" "cmp ah,'z'" "ja c2" "sub ah,32" "c2:" "cmp al,ah" "jne set" "cmp al,0" "je set" \
265: "dec ecx" "jz set" "inc esi" "inc edi" "jmp lp" "set:" "setne al" "jbe end" "neg al" "end:" \
266: parm [EDI] [ESI] [ECX] modify [EAX ECX EDI ESI];
267:
268: char* radstrupr(void* s1);
269: #pragma aux radstrupr = "mov ecx,edi" "lp:" "mov al,[edi]" "cmp al,'a'" "jb c1" "cmp al,'z'" "ja c1" "sub [edi],32" "c1:" "inc edi" "cmp al,0" "jne lp" parm [EDI] modify [EAX EDI] value [ecx];
270:
271: char* radstrlwr(void* s1);
272: #pragma aux radstrlwr = "mov ecx,edi" "lp:" "mov al,[edi]" "cmp al,'A'" "jb c1" "cmp al,'Z'" "ja c1" "add [edi],32" "c1:" "inc edi" "cmp al,0" "jne lp" parm [EDI] modify [EAX EDI] value [ecx];
273:
274: u32 radstru32(void* dest);
275: #pragma aux radstru32 = "cld" "xor ecx,ecx" "xor ebx,ebx" "xor edi,edi" "lodsb" "cmp al,45" "jne skip2" "mov edi,1" "jmp skip" "lp:" "mov eax,10" "mul ecx" "lea ecx,[eax+ebx]" \
276: "skip:" "lodsb" "skip2:" "cmp al,0x39" "ja dne" "cmp al,0x30" "jb dne" "mov bl,al" "sub bl,0x30" "jmp lp" "dne:" "test edi,1" "jz pos" "neg ecx" "pos:" \
277: parm [ESI] modify [EAX EBX EDX EDI ESI] value [ecx];
278:
279: u16 GetDS();
280: #pragma aux GetDS = "mov ax,ds" value [ax];
281:
282: #ifdef __RADWINEXT__
283:
284: u32 GetBase(u16 sel);
285: #pragma aux GetBase = "mov bx,ax" "mov ax,6" "int 0x31" "shrd eax,ecx,16" "mov ax,dx" parm [ax] modify [ax bx cx dx] value [eax];
286:
287: #define _16To32(ptr16) ((void*)(((GetBase((u16)(((u32)(ptr16))>>16))+((u16)(u32)(ptr16)))-GetBase(GetDS()))))
288:
289: #endif
290:
291: #ifndef __RADWIN__
292: #define int86 int386
293: #define int86x int386x
294: #endif
295:
296: #define u32regs x
297: #define u16regs w
298:
299: #endif
300:
301: #endif
302:
303: #else
304:
305: #define PTR4 __far
306:
307: #define u16 unsigned int
308: #define s16 signed int
309:
310: #ifdef __WATCOMC__
311:
312: s16 radabs(s16 ab);
313: #pragma aux radabs = "test ax,ax" "jge skip" "neg ax" "skip:" parm [ax] value [ax];
314:
315: s32 radabs32(s32 ab);
316: #pragma aux radabs32 = "test dx,dx" "jge skip" "neg dx" "neg ax" "sbb dx,0" "skip:" parm [dx ax] value [dx ax];
317:
318: u32 DOSOut(char far* dest);
319: #pragma aux DOSOut = "cld" "and edi,0xffff" "mov dx,di" "mov ecx,0xffffffff" "xor eax,eax" 0x67 "repne scasb" "not ecx" "dec ecx" "mov bx,1" "push ds" "push es" "pop ds" "mov ah,0x40" "int 0x21" "pop ds" "movzx eax,cx" "shr ecx,16" \
320: parm [ES DI] modify [AX BX CX DX DI ES] value [CX AX];
321:
322: void DOSOutNum(char far* str,u16 len);
323: #pragma aux DOSOutNum = "push ds" "mov ds,cx" "mov cx,bx" "mov ah,0x40" "mov bx,1" "int 0x21" "pop ds" parm [cx dx] [bx] modify [ax bx cx];
324:
325: u32 ErrOut(char far* dest);
326: #pragma aux ErrOut = "cld" "and edi,0xffff" "mov dx,di" "mov ecx,0xffffffff" "xor eax,eax" 0x67 "repne scasb" "not ecx" "dec ecx" "xor bx,bx" "push ds" "push es" "pop ds" "mov ah,0x40" "int 0x21" "pop ds" "movzx eax,cx" "shr ecx,16" \
327: parm [ES DI] modify [AX BX CX DX DI ES] value [CX AX];
328:
329: void ErrOutNum(char far* str,u16 len);
330: #pragma aux ErrOutNum = "push ds" "mov ds,cx" "mov cx,bx" "mov ah,0x40" "xor bx,bx" "int 0x21" "pop ds" parm [cx dx] [bx] modify [ax bx cx];
331:
332: void radmemset(void far *dest,u8 value,u32 size);
333: #pragma aux radmemset = "cld" "and edi,0ffffh" "shl ecx,16" "mov cx,bx" "mov ah,al" "mov bx,ax" "shl eax,16" "mov ax,bx" "mov bl,cl" "shr ecx,2" 0x67 "rep stosd" "mov cl,bl" "and cl,3" "rep stosb" parm [ES DI] [AL] [CX BX];
334:
335: void radmemcpy(void far* dest,void far* source,u32 size);
336: #pragma aux radmemcpy = "cld" "push ds" "mov ds,dx" "and esi,0ffffh" "and edi,0ffffh" "shl ecx,16" "mov cx,bx" "shr ecx,2" 0x67 "rep movsd" "mov cl,bl" "and cl,3" "rep movsb" "pop ds" parm [ES DI] [DX SI] [CX BX] modify [CX SI DI ES];
337:
338: char far* radstrcpy(void far* dest,void far* source);
339: #pragma aux radstrcpy = "cld" "push ds" "mov ds,dx" "and esi,0xffff" "and edi,0xffff" "mov dx,di" "lp:" "lodsb" "stosb" "test al,0xff" "jnz lp" "pop ds" parm [ES DI] [DX SI] modify [AX DX DI SI ES] value [es dx];
340:
341: char far* radstpcpy(void far* dest,void far* source);
342: #pragma aux radstpcpy = "cld" "push ds" "mov ds,dx" "and esi,0xffff" "and edi,0xffff" "lp:" "lodsb" "stosb" "test al,0xff" "jnz lp" "dec di" "pop ds" parm [ES DI] [DX SI] modify [DI SI ES] value [es di];
343:
344: u32 radstrlen(void far* dest);
345: #pragma aux radstrlen = "cld" "and edi,0xffff" "mov ecx,0xffffffff" "xor eax,eax" 0x67 "repne scasb" "not ecx" "dec ecx" "movzx eax,cx" "shr ecx,16" parm [ES DI] modify [AX CX DI ES] value [CX AX];
346:
347: char far* radstrcat(void far* dest,void far* source);
348: #pragma aux radstrcat = "cld" "and edi,0xffff" "mov ecx,0xffffffff" "and esi,0xffff" "push ds" "mov ds,dx" "mov dx,di" "xor eax,eax" 0x67 "repne scasb" "dec edi" "lp:" "lodsb" "stosb" "test al,0xff" "jnz lp" "pop ds" \
349: parm [ES DI] [DX SI] modify [AX CX DI SI ES] value [es dx];
350:
351: char far* radstrchr(void far* dest,char chr);
352: #pragma aux radstrchr = "cld" "lp:" 0x26 "lodsb" "cmp al,dl" "je fnd" "cmp al,0" "jnz lp" "xor ax,ax" "mov es,ax" "mov si,1" "fnd:" "dec si" parm [ES SI] [DL] modify [AX SI ES] value [es si];
353:
354: s8 radstricmp(void far* s1,void far* s2);
355: #pragma aux radstricmp = "and edi,0xffff" "push ds" "mov ds,dx" "and esi,0xffff" "lp:" "mov al,[esi]" "mov ah,[edi]" "cmp al,'a'" "jb c1" "cmp al,'z'" "ja c1" "sub al,32" "c1:" \
356: "cmp ah,'a'" "jb c2" "cmp ah,'z'" "ja c2" "sub ah,32" "c2:" "cmp al,ah" "jne set" "cmp al,0" "je set" \
357: "inc esi" "inc edi" "jmp lp" "set:" "setne al" "jbe end" "neg al" "end:" "pop ds" \
358: parm [ES DI] [DX SI] modify [AX DI SI];
359:
360: u32 radstru32(void far* dest);
361: #pragma aux radstru32 = "cld" "xor ecx,ecx" "xor ebx,ebx" "xor edi,edi" "lodsb" "cmp al,45" "jne skip2" "mov edi,1" "jmp skip" "lp:" "mov eax,10" "mul ecx" "lea ecx,[eax+ebx]" \
362: "skip:" 0x26 "lodsb" "skip2:" "cmp al,0x39" "ja dne" "cmp al,0x30" "jb dne" "mov bl,al" "sub bl,0x30" "jmp lp" "dne:" "test edi,1" "jz pos" "neg ecx" "pos:" \
363: "movzx eax,cx" "shr ecx,16" parm [ES SI] modify [AX BX DX DI SI] value [cx ax];
364:
365: u32 mult64anddiv(u32 m1,u32 m2,u32 d);
366: #pragma aux mult64anddiv = "shl ecx,16" "mov cx,ax" "shrd eax,edx,16" "mov ax,si" "mul ecx" "shl edi,16" "mov di,bx" "div edi" "shld edx,eax,16" "and edx,0xffff" "and eax,0xffff" parm [cx ax] [dx si] [di bx] \
367: modify [ax bx cx dx si di] value [dx ax];
368:
369: #endif
370:
371: #endif
372:
373: RCEND
374:
375: RCFUNC void PTR4* RADLINK radmalloc(u32 numbytes);
376: RCFUNC void RADLINK radfree(void PTR4* ptr);
377:
378: #ifdef __WATCOMC__
379:
380: char bkbhit();
381: #pragma aux bkbhit = "mov ah,1" "int 0x16" "lahf" "shr eax,14" "and eax,1" "xor al,1" ;
382:
383: char bgetch();
384: #pragma aux bgetch = "xor ah,ah" "int 0x16" "test al,0xff" "jnz done" "mov al,ah" "or al,0x80" "done:" modify [AX];
385:
386: void BreakPoint();
387: #pragma aux BreakPoint = "int 3";
388:
389: u8 radinp(u16 p);
390: #pragma aux radinp = "in al,dx" parm [DX];
391:
392: u8 radtoupper(u8 p);
393: #pragma aux radtoupper = "cmp al,'a'" "jb c1" "cmp al,'z'" "ja c1" "sub al,32" "c1:" parm [al] value [al];
394:
395: void radoutp(u16 p,u8 v);
396: #pragma aux radoutp = "out dx,al" parm [DX] [AL];
397:
398: #endif
399:
400: #endif
401:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.